Skip to content

Commit

Permalink
Merge pull request #146 from KVSlab/update-imports
Browse files Browse the repository at this point in the history
Update imports
  • Loading branch information
hkjeldsberg authored Mar 14, 2024
2 parents 3a85be6 + 72114a1 commit 298de3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/check_and_test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ jobs:

- name: Run tests
run: python3 -m pytest tests
env:
OASIS_MODE: TESTING

- name: Upload coverage report to codecov
if: matrix.os == 'ubuntu-latest'
Expand Down
35 changes: 22 additions & 13 deletions src/vampy/simulation/Artery.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import importlib.util
import json
import os
import pickle
from pprint import pprint
import numpy as np
from dolfin import set_log_level

if os.environ.get('OASIS_MODE') == 'TESTING':
from oasismove.problems.NSfracStep import *
else:
from oasis.problems.NSfracStep import *
import numpy as np
from dolfin import set_log_level, MPI

from vampy.simulation.Probe import Probes # type: ignore
from vampy.simulation.Womersley import make_womersley_bcs, compute_boundary_geometry_acrn
from vampy.simulation.simulation_common import get_file_paths, store_u_mean, print_mesh_information, \
store_velocity_and_pressure_h5, dump_probes

# Check for oasis and oasismove
package_name_oasis = 'oasis'
package_name_oasismove = 'oasismove'
oasis_exists = importlib.util.find_spec(package_name_oasis)
oasismove_exists = importlib.util.find_spec(package_name_oasismove)
if oasismove_exists:
from oasismove.problems.NSfracStep import *
elif oasis_exists:
from oasis.problems.NSfracStep import *
else:
print("Neither oasis nor oasismove is installed. Exiting simulation..")

# FEniCS specific command to control the desired level of logging, here set to critical errors
set_log_level(50)
comm = MPI.comm_world


def problem_parameters(commandline_kwargs, NS_parameters, NS_expressions, **NS_namespace):
Expand Down Expand Up @@ -75,7 +84,7 @@ def problem_parameters(commandline_kwargs, NS_parameters, NS_expressions, **NS_n
case_name = mesh_file.split(".")[0]
NS_parameters["folder"] = path.join(NS_parameters["folder"], case_name)

if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
print("=== Starting simulation for case: {} ===".format(case_name))
print("Running with the following parameters:")
pprint(NS_parameters)
Expand Down Expand Up @@ -131,7 +140,7 @@ def create_bcs(t, NS_expressions, V, Q, area_ratio, area_inlet, mesh, mesh_path,
area_out.append(assemble(Constant(1.0) * dsi))

bc_p = []
if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
print("=== Initial pressure and area fraction ===")

for i, ID in enumerate(id_out):
Expand All @@ -140,7 +149,7 @@ def create_bcs(t, NS_expressions, V, Q, area_ratio, area_inlet, mesh, mesh_path,
bc = DirichletBC(Q, outflow, boundary, ID)
bc_p.append(bc)
NS_expressions[ID] = outflow
if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
print(f"Boundary ID={ID}, pressure: {p_initial:.5f}, area fraction: {area_ratio[i]:0.5f}")

# No slip condition at wall
Expand Down Expand Up @@ -171,7 +180,7 @@ def pre_solve_hook(mesh, V, Q, newfolder, mesh_path, restart_folder, velocity_de
probe_points = np.array(json.load(infile))

# Store points file in checkpoint
if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
probe_points.dump(path.join(newfolder, "Checkpoint", "points"))

eval_dict["centerline_u_x_probes"] = Probes(probe_points.flatten(), V)
Expand All @@ -187,7 +196,7 @@ def pre_solve_hook(mesh, V, Q, newfolder, mesh_path, restart_folder, velocity_de
files = NS_namespace["files"]

# Save mesh as HDF5 file for post-processing
with HDF5File(MPI.comm_world, files["mesh"], "w") as mesh_file:
with HDF5File(comm, files["mesh"], "w") as mesh_file:
mesh_file.write(mesh, "mesh")

# Create vector function for storing velocity
Expand Down Expand Up @@ -219,7 +228,7 @@ def temporal_hook(u_, p_, mesh, tstep, dump_probe_frequency, eval_dict, newfolde
tstep, u_)

# Compute flow rates and updated pressure at outlets, and mean velocity and Reynolds number at inlet
if MPI.rank(MPI.comm_world) == 0 and tstep % 10 == 0:
if MPI.rank(comm) == 0 and tstep % 10 == 0:
U_mean = Q_in / area_inlet[0]
diam_inlet = np.sqrt(4 * area_inlet[0] / np.pi)
Re = U_mean * diam_inlet / nu
Expand Down
29 changes: 19 additions & 10 deletions src/vampy/simulation/Atrium.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import importlib.util
import json
import os
import pickle
from pprint import pprint
from dolfin import set_log_level, MPI

if os.environ.get('OASIS_MODE') == 'TESTING':
from oasismove.problems.NSfracStep import *
else:
from oasis.problems.NSfracStep import *
import numpy as np
from dolfin import set_log_level, MPI

from vampy.simulation.Probe import Probes # type: ignore
from vampy.simulation.Womersley import make_womersley_bcs, compute_boundary_geometry_acrn
from vampy.simulation.simulation_common import store_u_mean, get_file_paths, print_mesh_information, \
store_velocity_and_pressure_h5, dump_probes

# Check for oasis and oasismove
package_name_oasis = 'oasis'
package_name_oasismove = 'oasismove'
oasis_exists = importlib.util.find_spec(package_name_oasis)
oasismove_exists = importlib.util.find_spec(package_name_oasismove)
if oasismove_exists:
from oasismove.problems.NSfracStep import *
elif oasis_exists:
from oasis.problems.NSfracStep import *
else:
print("Neither oasis nor oasismove is installed. Exiting simulation..")

# FEniCS specific command to control the desired level of logging, here set to critical errors
set_log_level(50)
comm = MPI.comm_world
Expand Down Expand Up @@ -74,7 +83,7 @@ def problem_parameters(commandline_kwargs, NS_parameters, scalar_components, Sch
case_name = mesh_file.split(".")[0]
NS_parameters["folder"] = path.join(NS_parameters["folder"], case_name)

if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
print("=== Starting simulation for Atrium.py ===")
print("Running with the following parameters:")
pprint(NS_parameters)
Expand Down Expand Up @@ -165,7 +174,7 @@ def pre_solve_hook(V, Q, cardiac_cycle, dt, save_solution_after_cycle, mesh_path
probe_points = np.array(json.load(infile))

# Store points file in checkpoint
if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
probe_points.dump(path.join(newfolder, "Checkpoint", "points"))

eval_dict["centerline_u_x_probes"] = Probes(probe_points.flatten(), V)
Expand All @@ -181,7 +190,7 @@ def pre_solve_hook(V, Q, cardiac_cycle, dt, save_solution_after_cycle, mesh_path
files = NS_namespace["files"]

# Save mesh as HDF5 file for post-processing
with HDF5File(MPI.comm_world, files["mesh"], "w") as mesh_file:
with HDF5File(comm, files["mesh"], "w") as mesh_file:
mesh_file.write(mesh, "mesh")

# Create vector function for storing velocity
Expand Down Expand Up @@ -221,7 +230,7 @@ def temporal_hook(mesh, dt, t, save_solution_frequency, u_, NS_expressions, id_i
U_mean = comm.gather(local_U_mean, 0)
U_max = comm.gather(local_U_max, 0)

if MPI.rank(MPI.comm_world) == 0:
if MPI.rank(comm) == 0:
u_mean = np.mean(U_mean)
u_max = max(U_max)

Expand Down

0 comments on commit 298de3d

Please sign in to comment.