Skip to content

Commit

Permalink
Merge pull request #134 from KVSlab/update-probe-import
Browse files Browse the repository at this point in the history
Update probe import
  • Loading branch information
hkjeldsberg authored Nov 10, 2023
2 parents d22c1a2 + 2f3ce40 commit 2d1c05d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
23 changes: 13 additions & 10 deletions src/vampy/automatedPostprocessing/compute_velocity_and_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
pass


def compute_velocity_and_pressure(folder, dt, velocity_degree, pressure_degree, step):
def compute_velocity_and_pressure(folder, dt, save_frequency, velocity_degree, pressure_degree, step):
"""
Loads velocity and pressure from compressed .h5 CFD solution and
converts and saves to .xdmf format for visualization (in e.g. ParaView).
Args:
folder (str): Path to results from simulation
dt (float): Time step of simulation
save_frequency (int): Frequency that velocity and pressure has been stored
velocity_degree (int): Finite element degree of velocity
pressure_degree (int): Finite element degree of pressure
step (int): Step size determining number of times data is sampled
Expand Down Expand Up @@ -74,8 +75,10 @@ def compute_velocity_and_pressure(folder, dt, velocity_degree, pressure_degree,
if MPI.rank(MPI.comm_world) == 0:
print("=" * 10, "Start post processing", "=" * 10)

file_counter = 1
counter = 1
for i in range(len(dataset_u)):
# Set physical time (in [ms])
t = dt * counter * save_frequency

file_u.read(u, dataset_u[i])
file_p.read(p, dataset_p[i])
Expand All @@ -86,31 +89,31 @@ def compute_velocity_and_pressure(folder, dt, velocity_degree, pressure_degree,

# Store velocity
u.rename("velocity", "velocity")
u_writer.write(u, dt * file_counter)
u_writer.write(u, t)

# Store pressure
p.rename("pressure", "pressure")
p_writer.write(p, dt * file_counter)
p_writer.write(p, t)

# Store deformation
# NB: Storing together with velocity.
if file_d is not None:
file_d.read(d, dataset_d[i])
d.rename("deformation", "deformation")
u_writer.write(d, dt * file_counter)
u_writer.write(d, t)

# Update file_counter
file_counter += step
counter += step

print("========== Post processing finished ==========")
print("Results saved to: {}".format(folder))


def main_convert():
folder, _, _, dt, velocity_degree, pressure_degree, _, _, _, _, _, step, _ = read_command_line()
compute_velocity_and_pressure(folder, dt, velocity_degree, pressure_degree, step)
folder, _, _, dt, velocity_degree, pressure_degree, _, _, save_frequency, _, _, step, _ = read_command_line()
compute_velocity_and_pressure(folder, dt, save_frequency, velocity_degree, pressure_degree, step)


if __name__ == '__main__':
folder, _, _, dt, velocity_degree, pressure_degree, _, _, _, _, _, step, _ = read_command_line()
compute_velocity_and_pressure(folder, dt, velocity_degree, pressure_degree, step)
folder, _, _, dt, velocity_degree, pressure_degree, _, _, save_frequency, _, _, step, _ = read_command_line()
compute_velocity_and_pressure(folder, dt, save_frequency, velocity_degree, pressure_degree, step)
2 changes: 1 addition & 1 deletion src/vampy/automatedPostprocessing/postprocessing_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def norm_l2(self, u):
return pow(inner(u, u), 0.5)


def get_dataset_names(data_file, num_files=100000, step=1, start=1, print_info=True,
def get_dataset_names(data_file, num_files=100000, step=1, start=0, print_info=True,
vector_filename="/velocity/vector_%d"):
"""
Read velocity fields datasets and extract names of files
Expand Down
6 changes: 0 additions & 6 deletions src/vampy/simulation/MovingAtrium.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import pickle
from os import makedirs
from pprint import pprint
from dolfin import set_log_level, UserExpression

from oasismove.problems.NSfracStep import *
Expand Down Expand Up @@ -96,11 +95,6 @@ def problem_parameters(commandline_kwargs, scalar_components, NS_parameters, **N
print("-- Computing blood residence time --")
scalar_components += ["blood"]

if MPI.rank(MPI.comm_world) == 0:
print("=== Starting simulation for MovingAtrium.py ===")
print("Running with the following parameters:")
pprint(NS_parameters)


def scalar_source(scalar_components, **NS_namespace):
"""Return a dictionary of scalar sources."""
Expand Down
3 changes: 2 additions & 1 deletion src/vampy/simulation/Probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
ProbeObject = object

try:
probe11 = cppimport.imp('probe.probe11')
probe11 = cppimport.imp('vampy.simulation.probe.probe11')
ProbeObject = probe11.Probes
print("Successfully imported probe.probe11")
except ImportError:
print("Failed to import probe.probe11")

Expand Down
3 changes: 2 additions & 1 deletion tests/test_compute_velocity_and_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ def test_compute_velocity_and_pressure():
# Path to test results and params
results_path = "tests/test_data/results/Solutions"
dt = 0.951
save_frequency = 5
velocity_degree = 1
pressure_degree = 1
step = 1

# Run post-processing
compute_velocity_and_pressure(results_path, dt, velocity_degree, pressure_degree, step)
compute_velocity_and_pressure(results_path, dt, save_frequency, velocity_degree, pressure_degree, step)

# Check that output files exist
metric_names = ["velocity", "pressure"]
Expand Down

0 comments on commit 2d1c05d

Please sign in to comment.