We generated a mesh in SV gui as shown below that has a pretty nice element size around the stenosis. Parameters assigned for this mesh are: We tend to do the same using Python code. Our current code, attached here, generated the mesh that is not desirable. What changes are needed to make to the code to replicate the mesh from gui?
Thank you,
Jimmy
Code: Select all
def create_mesh(directory, model, centerlines, face_names, edge_size, boundary_layer=True):
print("Generating mesh ...")
mesher = sv.meshing.TetGen()
if isinstance(model, type(sv.modeling.OpenCascade())):
polydata = model.get_polydata()
model = sv.modeling.PolyData()
model.set_surface(polydata)
face_ids = model.compute_boundary_faces(60.0)
#caps = model.identify_caps()
#print(caps)
#wall_id = [i + 1 for i in range(len(caps)) if not caps[i]]
inlet_id = [face_id for face_id, face_name in face_names.items() if 'in' in face_name]
outlet_ids = [face_id for face_id, face_name in face_names.items() if 'in' not in face_name]
outlet_names = {face_id:face_name for face_id, face_name in face_names.items() if face_name != 'in'}
wall_id = [i for i in range(1, len(face_names) + 1) if i not in list(face_names.keys())]
print("Face ids:", model.get_face_ids())
print("Wall id {}".format(wall_id))
print("Inlet id {}".format(inlet_id))
print("Outlet ids & names {}".format(outlet_names))
# Set the model for the mesher.
mesher.set_model(model)
mesher.set_walls(wall_id)
# If the model has faces already computed (i.e. has 'ModelFaceID' array) then
# don't call this, the face IDs will no longer match the original face IDs.
#mesher.compute_model_boundary_faces(angle=60.0)
face_ids = mesher.get_model_face_ids()
#print(face_ids)
# Set meshing options.
#mesher.compute_model_boundary_faces(45)
#faces = mesher.get_face_polydata(0)
print("\nSet meshing options ... ")
options = sv.meshing.TetGenOptions(global_edge_size=edge_size, surface_mesh_flag=True, volume_mesh_flag=True)
options.radius_meshing_on = True
options.boundary_layer_inside = True
options.radius_meshing_scale = 0.4
if boundary_layer:
mesher.set_boundary_layer_options(number_of_layers=3, edge_size_fraction=0.5, layer_decreasing_ratio=0.8, constant_thickness=False)
#options.no_bisect = False
# Generate the mesh.
mesher.generate_mesh(options)
# Get the mesh as a vtkUnstructuredGrid.
mesh = mesher.get_mesh()
print("Mesh:")
print(" Number of nodes: {0:d}".format(mesh.GetNumberOfPoints()))
print(" Number of elements: {0:d}".format(mesh.GetNumberOfCells()))
# Write the mesh.
#mesh_series = sv.meshing.Series()
#mesh_series.write(os.path.join(directory, 'Meshes', 'mesh.msh'))
mesh_directory = os.path.join(directory, 'Meshes')
mesh_path = os.path.join(mesh_directory, 'mesh.vtu')
print(mesh_path)
mesher.write_mesh(mesh_path)
model_name = 'mesh'
write_msh(mesh_directory, model_name, options)
write_XML(mesher.get_surface(), os.path.join(mesh_directory, 'mesh.vtp'))
areas = []
for face_id in outlet_ids:
face_poly = mesher.get_face_polydata(face_id)
areas.append(compute_face_area(face_poly))
write_files(mesher, directory, wall_id, inlet_id, outlet_ids, outlet_names)
print("Successully generated the mesh *****\n")
return mesher, areas, wall_id, inlet_id, outlet_ids