Convert Gmsh Mesh to SwiftComp#
Problem Description#
Given a 3D tetrahedral mesh generated in Gmsh (.msh format), convert it to a
SwiftComp input file for 3D solid homogenization.
Solution#
The mesh alone does not carry materials or analysis settings, so the example
uses the SG-on-Gmsh bundle convention: the .msh file supplies the mesh and
physical groups, sections.json supplies the section/material payloads, and
config.json supplies the analysis configuration. See
SG-on-Gmsh Serialization Specification for the bundle layout.
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.read_sg_from_gmsh_bundle() assembles the three files into a single
sgio.StructureGene, and model_type='SD1' selects the 3D solid model.
sgio.write() then emits SwiftComp 2.1 input.
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
sections.json: Section and material definitions
config.json: Analysis configuration