Skip to content

Commit 720e7d0

Browse files
authored
Adding method to import nodesets in vtk meshes, convert abaqus meshes to vtu (#1942)
* Adding a prototype method to convert, import nodesets in vtk files
1 parent ed62fa1 commit 720e7d0

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

geosx_mesh_tools_package/geosx_mesh_tools/abaqus_converter.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,49 @@ def convert_abaqus_to_gmsh(input_mesh, output_mesh, logger=None):
123123
return (n_warnings > 0)
124124

125125

126+
def convert_abaqus_to_vtu(input_mesh, output_mesh, logger=None):
127+
"""
128+
@brief Convert an abaqus mesh to vtu format, preserving nodeset information.
129+
@details If the code encounters any issues with region/element indices,
130+
the conversion will attempt to continue, with errors
131+
indicated by -1 values in the output file.
132+
@param input_mesh path of the input abaqus file
133+
@param output_mesh path of the output vtu file
134+
@param logger an instance of logging.Logger
135+
"""
136+
# Initialize the logger if it is empty
137+
if not logger:
138+
logging.basicConfig(level=logging.WARNING)
139+
logger = logging.getLogger(__name__)
140+
141+
# Keep track of the number of warnings
142+
n_warnings = 0
143+
144+
# Load the mesh
145+
logger.info('Reading abaqus mesh...')
146+
mesh = meshio.read(input_mesh, file_format="abaqus")
147+
148+
# Converting nodesets to binary masks
149+
for k, nodeset in mesh.point_sets.items():
150+
mesh.point_data[k] = np.zeros(len(mesh.points), dtype=int)
151+
mesh.point_data[k][nodeset] = 1
152+
153+
# Overwrite point sets to suppress conversion warnings
154+
mesh.point_sets = {}
155+
156+
# Write the final mesh
157+
logger.info('Writing vtu mesh...')
158+
meshio.write(output_mesh, mesh, file_format="vtu")
159+
logger.info('Done!')
160+
161+
return (n_warnings > 0)
162+
163+
126164
def main():
127165
"""
128166
@brief Entry point for the abaqus convertor console script
129167
@arg input_mesh Input abaqus file name
130-
@arg output_mesh Output gmsh file name
168+
@arg output_mesh Output gmsh or vtu file name
131169
"""
132170

133171
# Parse the user arguments
@@ -144,6 +182,10 @@ def main():
144182
logger.setLevel(logging.INFO)
145183

146184
# Call the converter
147-
err = convert_abaqus_to_gmsh(args.input, args.output, logger)
185+
err = 0
186+
if ('.msh' in args.output):
187+
err = convert_abaqus_to_gmsh(args.input, args.output, logger)
188+
else:
189+
err = convert_abaqus_to_vtu(args.input, args.output, logger)
148190
if err:
149191
sys.exit('Warnings detected: check the output file for potential errors!')

0 commit comments

Comments
 (0)