Volume Mesh Operations
Volume Mesh Operations Tutorial.
This tutorial demonstrates operations on tetrahedral volume meshes including import/export, transformations, and conversion to surfaces.
Prerequisites
- Volvicon application must be running
- Volume meshes are typically created by converting surfaces using
Listing Volume Meshes​
all_volume_meshes = app.get_all_volume_mesh_names()
all_volumes = app.get_all_volume_names()
print(f"Available volume meshes: {all_volume_meshes}")
print(f"Available volumes: {all_volumes}")
Importing and Exporting Volume Meshes​
# import_volume_mesh_from_disk auto-detects the format from the file and creates
# a NEW volume mesh object. The same call handles every supported format:
# VTK unstructured grid .......... .vtu, .vtk
# Abaqus / CalculiX .............. .inp
# Nastran ........................ .bdf, .nas
# LS-DYNA ........................ .k, .dyn, .key
# ANSYS .......................... .cdb
# Gmsh ........................... .msh
# Fluent ......................... .msh (told apart from Gmsh by content)
# OpenFOAM ....................... .foam marker file or case directory
#
# Where the solver file provides them, materials, node/element sets, boundary
# surfaces, and parts are attached to the imported mesh's FEM model. Solid and
# shell cells are kept (including hex/wedge/pyramid); higher-order elements are
# imported as their linear equivalents; 1D elements (beams, trusses, rods,
# springs) and contact/target/surface helper elements are skipped.
# Import a single volume mesh file (any supported format)
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\mesh.vtu')
# Import solver files by pointing at the file -- the format is auto-detected.
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\model.inp') # Abaqus
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\model.bdf') # Nastran
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\model.cdb') # ANSYS
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\model.k') # LS-DYNA
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\model.msh') # Gmsh or Fluent
# OpenFOAM: pass the .foam case marker file, OR the case directory itself
# (a folder holding the mesh files, a 'polyMesh' folder, or 'constant/polyMesh').
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\case\case.foam') # marker file
# mesh_name = volume_mesh_operations.import_volume_mesh_from_disk(r'C:\data\case') # case directory
# Import multiple volume mesh files (formats may be mixed)
# mesh_names = volume_mesh_operations.import_volume_meshes_from_disk([
# r'C:\data\mesh1.vtu',
# r'C:\data\part_a.cdb',
# r'C:\data\part_b.bdf'
# ])
# Export to disk writes only the VTK mesh geometry (.vtu / .vtk). It does NOT
# write the attached FEM model (materials, sets, surfaces, parts) as a solver
# model. For solver formats with the FEM model, use the FEM operations group:
# fem_operations = volume_mesh_operations.get_fem_operations()
# fem_operations.export_to_abaqus(...) / export_to_nastran(...) /
# export_to_ls_dyna(...) / export_to_gmsh(...) / export_to_fluent(...) /
# export_to_open_foam(...) (see fem_operations.py for full examples)
# Export a single volume mesh to file (VTK geometry only)
# volume_mesh_operations.export_volume_mesh_to_disk('volume_mesh (1)', r'C:\output\mesh.vtu', False) # isASCII=False (bool)
# Export multiple volume meshes to a directory (VTK geometry only).
# Returns True only when every listed mesh was written, so the result is worth checking.
# if not volume_mesh_operations.export_volume_meshes_to_disk(['volume_mesh (1)', 'volume_mesh (2)'], r'C:\output', 'vtu', False):
# print("One or more volume meshes could not be exported.")
Volume Mesh Geometry Data​
# if all_volume_meshes:
# geometry_data : api.VolumeMeshGeometryData = volume_mesh_operations.get_geometry_data(all_volume_meshes[0])
# print(f"Vertex count: {len(geometry_data.vertices)}")
# print(f"Cell count: {len(geometry_data.cell_sizes)}")
#
# # Replace the mesh using vertices, flat cell connectivity, cell sizes, and cell types.
# new_geometry = api.VolumeMeshGeometryData()
# new_geometry.vertices = [
# [0.0, 0.0, 0.0],
# [1.0, 0.0, 0.0],
# [0.0, 1.0, 0.0],
# [0.0, 0.0, 1.0],
# [1.0, 1.0, 1.0],
# ]
# new_geometry.cell_connectivity = [0, 1, 2, 3, 1, 2, 3, 4]
# new_geometry.cell_sizes = [4, 4]
# new_geometry.cell_types = [
# api.VolumeMeshCellType.Tetrahedron,
# api.VolumeMeshCellType.Tetrahedron,
# ]
# new_geometry.vertex_colors = [
# [1.0, 0.0, 0.0],
# [0.0, 1.0, 0.0],
# [0.0, 0.0, 1.0],
# [1.0, 1.0, 0.0],
# [0.0, 1.0, 1.0],
# ]
# new_geometry.cell_colors = [
# [0.3, 0.5, 0.7],
# [0.7, 0.5, 0.3],
# ]
# volume_mesh_operations.set_geometry_data(all_volume_meshes[0], new_geometry)
Geometric Transformations​
# if all_volume_meshes:
# # Rotate around axis
# volume_mesh_operations.rotate(
# [all_volume_meshes[0]], # volumeMeshNames (list)
# 45.0, # angleDegrees (float)
# [0.0, 0.0, 1.0], # axis [x, y, z]
# [0.0, 0.0, 0.0], # center [x, y, z] (ignored if aroundObjectCentroid=True)
# True # aroundObjectCentroid (bool)
# )
#
# # Reorient with XYZ translation, XYZ Euler rotation angles, and an optional rotation center
# volume_mesh_operations.reorient(
# [all_volume_meshes[0]], # volumeMeshNames (list)
# [10.0, 5.0, 0.0], # translation [x, y, z] in mm
# [0.0, 0.0, 45.0], # rotationAnglesDegrees [x, y, z]
# [0.0, 0.0, 0.0], # rotationCenter [x, y, z] (ignored if aroundObjectCentroid=True)
# True # aroundObjectCentroid (bool)
# )
#
# # Translate
# volume_mesh_operations.translate(
# [all_volume_meshes[0]], # volumeMeshNames (list)
# [10.0, 5.0, 0.0] # translation [x, y, z] in mm
# )
#
# # Scale
# volume_mesh_operations.scale(
# [all_volume_meshes[0]], # volumeMeshNames (list)
# [1.5, 1.5, 1.5] # scaleFactors [x, y, z]
# )
#
# # Mirror across axes
# volume_mesh_operations.mirror(
# [all_volume_meshes[0]], # volumeMeshNames (list)
# True, # mirrorX (bool)
# False, # mirrorY (bool)
# False # mirrorZ (bool)
# )
#
# # Apply 4x4 transformation matrix
# # matrix = [1,0,0,0, 0,1,0,0, 0,0,1,0, 10,20,30,1] # Translation example
# # volume_mesh_operations.transform([all_volume_meshes[0]], matrix)
#
# # Move to center of active volume
# volume_mesh_operations.move_to_active_volume_center([all_volume_meshes[0]])
Convert Volume Mesh to Surfaces​
# if all_volume_meshes:
# surface_names = volume_mesh_operations.convert_to_surfaces([all_volume_meshes[0]])
# print(f"Created surfaces: {surface_names}")
Render Properties​
# volume_mesh_render_properties_operations = volume_mesh_operations.get_render_properties_operations()
# if all_volume_meshes:
# # Set representation mode
# volume_mesh_render_properties_operations.set_representation([all_volume_meshes[0]], api.VolumeMeshRepresentation.Solid) # Points, Wireframe, Solid, SolidEdges
#
# # Set color (RGB values 0.0-1.0)
# volume_mesh_render_properties_operations.set_color([all_volume_meshes[0]], [0.2, 0.6, 0.8]) # Blue
#
# # Set random color
# volume_mesh_render_properties_operations.set_random_color([all_volume_meshes[0]])
#
# # Set opacity (0.0-1.0)
# volume_mesh_render_properties_operations.set_opacity([all_volume_meshes[0]], 0.8)
print("Volume mesh operations tutorial completed successfully.")
Related Resources​
- API Reference - API documentation
- Quick Reference - Common methods at a glance