Convert Gmsh Mesh to SwiftComp#
Problem Description#
Given a 3D tetrahedral mesh generated in Gmsh (.msh format) and a JSON material database, convert the mesh to a SwiftComp input file for 3D solid homogenization.
Solution#
import sgio
fn = 'sg33_cube_tetra4_min_gmsh41.msh'
sg = sgio.read(fn, 'gmsh')
sg.materials = sgio.read_materials_from_json('materials.json')
print(sg)
sgio.write(
sg=sg,
filename=fn.replace('.msh', '.sg'),
file_format='sc',
format_version='2.1',
model_type='sd1',
)
sgio.read_materials_from_json() loads the material definitions from materials.json and assigns them to the structure gene. model_type='sd1' selects the 3D solid model.
Result#
A SwiftComp 2.1 input file sg33_cube_tetra4_min_gmsh41.sg is written and ready for homogenization.
File List#
convert_gmsh_to_sc.py: Main Python script
sg33_cube_tetra4_min_gmsh41.msh: Gmsh mesh file
materials.json: Material database (JSON)