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 logging
from pathlib import Path
import sgio
logging.basicConfig(level=logging.INFO)
cwd = Path(__file__).resolve().parent
main_msh = cwd / 'sg33_cube_tetra4_min_gmsh41.msh'
sections_json = cwd / 'sections.json'
config_json = cwd / 'config.json'
output_file = cwd / 'sg33_cube_tetra4_min_gmsh41.sg'
sg = sgio.read_sg_from_gmsh_bundle(
main_msh=main_msh,
sections_json=sections_json,
config_json=config_json,
model_type='SD1',
)
print(sg)
sgio.write(
sg=sg,
filename=str(output_file),
file_format='sc',
format_version='2.1',
model_type='SD1',
)
sgio.iofunc.common.material_json.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#
run.py: Main Python script
sg33_cube_tetra4_min_gmsh41.msh: Gmsh mesh file
materials.json: Material database (JSON)