Writing input file for ROM with Python API not working
Posted: Wed Nov 13, 2024 9:02 am
Hi,
I have this code that is a combination of two codes that i found in the git hub repository. First i want to extract the centerline of a given geometry, then i want to buid a 0d model. This is code:
import os
from pathlib import Path
import sv
import sys
import vtk
patient_id = 'AORTA-013'
## Set some directory paths.
script_path = Path(os.path.realpath(__file__)).parent
parent_path = Path(os.path.realpath(__file__)).parent.parent
data_path = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/mesh/lumen_mesh/mesh-surfaces"
mesh_complete_path = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/mesh/lumen_mesh/mesh-complete.exterior.vtp"
## Centerline extration
# Create a modeler.
kernel = sv.modeling.Kernel.POLYDATA
modeler = sv.modeling.Modeler(kernel)
model = modeler.read(mesh_complete_path)
model_polydata = model.get_polydata()
face_id = model_polydata.GetPointData().GetArray('ModelFaceID')
inlet_ids = [1]
outlet_ids = [4,3,2,5]
use_face_ids = False
centerlines = model.compute_centerlines(inlet_ids, outlet_ids, use_face_ids)
print('centerline extraction')
input_dir = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/0D"
file_name = os.path.join(input_dir, 'centerlines.vtp')
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(file_name)
writer.SetInputData(centerlines)
writer.Update()
writer.Write()
## Rom simulation
rom_simulation = sv.simulation.ROM()
## Create ROM simulation parameters.
params = sv.simulation.ROMParameters()
## Mesh parameters.
mesh_params = params.MeshParameters()
## Model parameters.
model_params = params.ModelParameters()
model_params.name = "demo"
model_params.inlet_face_names = ['inlet_aorta' ]
model_params.outlet_face_names = ['aorta_bct', 'aorta_car', 'aorta_suc', 'aorta_outlet']
model_params.centerlines_file_name = input_dir + 'centerlines.vtp'
## Fluid properties.
fluid_props = params.FluidProperties()
## Set wall properties.
print("Set wall properties ...")
material = params.WallProperties.OlufsenMaterial()
print("Material model: {0:s}".format(str(material)))
## Set boundary conditions.
#
inlet_path = "D:/Progetto NIH/Inlet bc/AORTA-013"
bcs = params.BoundaryConditions()
#bcs.add_resistance(face_name='outlet', resistance=1333)
bcs.add_velocities(face_name='inlet', file_name=inlet_path +'flow_inlet_0.flow')
bcs.add_rcr(face_name='aorta_bct', Rp=90.0, C=0.0008, Rd=1200)
bcs.add_rcr(face_name='aorta_car', Rp=100.0, C=0.0004, Rd=1100)
bcs.add_rcr(face_name='aorta_suc', Rp=90.0, C=0.0008, Rd=1200)
bcs.add_rcr(face_name='aorta_outlet', Rp=100.0, C=0.0004, Rd=1100)
## Set solution parameters.
#
solution_params = params.Solution()
solution_params.time_step = 0.001
solution_params.num_time_steps = 1000
## Write a 1D solver input file.
#
output_dir = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/0D/output"
rom_simulation.write_input_file(model_order=0, model=model_params, mesh=mesh_params, fluid=fluid_props,
material=material, boundary_conditions=bcs, solution=solution_params, directory=output_dir)
When i run it from the shell, it doesn't give an error but it doesn't write the input file either. Does somebody know how to fix this problem?
And has the run method been defined?
Thanks,
Ione
I have this code that is a combination of two codes that i found in the git hub repository. First i want to extract the centerline of a given geometry, then i want to buid a 0d model. This is code:
import os
from pathlib import Path
import sv
import sys
import vtk
patient_id = 'AORTA-013'
## Set some directory paths.
script_path = Path(os.path.realpath(__file__)).parent
parent_path = Path(os.path.realpath(__file__)).parent.parent
data_path = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/mesh/lumen_mesh/mesh-surfaces"
mesh_complete_path = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/mesh/lumen_mesh/mesh-complete.exterior.vtp"
## Centerline extration
# Create a modeler.
kernel = sv.modeling.Kernel.POLYDATA
modeler = sv.modeling.Modeler(kernel)
model = modeler.read(mesh_complete_path)
model_polydata = model.get_polydata()
face_id = model_polydata.GetPointData().GetArray('ModelFaceID')
inlet_ids = [1]
outlet_ids = [4,3,2,5]
use_face_ids = False
centerlines = model.compute_centerlines(inlet_ids, outlet_ids, use_face_ids)
print('centerline extraction')
input_dir = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/0D"
file_name = os.path.join(input_dir, 'centerlines.vtp')
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(file_name)
writer.SetInputData(centerlines)
writer.Update()
writer.Write()
## Rom simulation
rom_simulation = sv.simulation.ROM()
## Create ROM simulation parameters.
params = sv.simulation.ROMParameters()
## Mesh parameters.
mesh_params = params.MeshParameters()
## Model parameters.
model_params = params.ModelParameters()
model_params.name = "demo"
model_params.inlet_face_names = ['inlet_aorta' ]
model_params.outlet_face_names = ['aorta_bct', 'aorta_car', 'aorta_suc', 'aorta_outlet']
model_params.centerlines_file_name = input_dir + 'centerlines.vtp'
## Fluid properties.
fluid_props = params.FluidProperties()
## Set wall properties.
print("Set wall properties ...")
material = params.WallProperties.OlufsenMaterial()
print("Material model: {0:s}".format(str(material)))
## Set boundary conditions.
#
inlet_path = "D:/Progetto NIH/Inlet bc/AORTA-013"
bcs = params.BoundaryConditions()
#bcs.add_resistance(face_name='outlet', resistance=1333)
bcs.add_velocities(face_name='inlet', file_name=inlet_path +'flow_inlet_0.flow')
bcs.add_rcr(face_name='aorta_bct', Rp=90.0, C=0.0008, Rd=1200)
bcs.add_rcr(face_name='aorta_car', Rp=100.0, C=0.0004, Rd=1100)
bcs.add_rcr(face_name='aorta_suc', Rp=90.0, C=0.0008, Rd=1200)
bcs.add_rcr(face_name='aorta_outlet', Rp=100.0, C=0.0004, Rd=1100)
## Set solution parameters.
#
solution_params = params.Solution()
solution_params.time_step = 0.001
solution_params.num_time_steps = 1000
## Write a 1D solver input file.
#
output_dir = "D:/Progetto NIH/Simvascular_Simulation/AORTA-013/0D/output"
rom_simulation.write_input_file(model_order=0, model=model_params, mesh=mesh_params, fluid=fluid_props,
material=material, boundary_conditions=bcs, solution=solution_params, directory=output_dir)
When i run it from the shell, it doesn't give an error but it doesn't write the input file either. Does somebody know how to fix this problem?
And has the run method been defined?
Thanks,
Ione