polyfem_sim — build a PolyFEM simulation.json from a Python config
and run PolyFEM on it. Pairs with the boundary-extraction outputs
(`m_sim.msh` + `m_bdry_selection.txt` + `m_bdry_selection_id_map.txt`):
materials and BCs are given by physical-group / tag NAME (e.g. "tag_0",
"tag_0 & ambient") and resolved to polyfem integer ids via the id_map.
Config (dict):
input_msh : str — boundary-extracted _sim.msh
input_selection : str — boundary selection file (polyfem
surface_selection); default
<stem>_bdry_selection.txt next to input_msh.
`selection_file` is a legacy alias.
id_map : str — default <stem>_bdry_selection_id_map.txt
scale : float — geometry scale (default 0.001); shorthand for
transformation.scale = [scale]*mesh_dim
transformation : dict — polyfem geometry transform, deep-merged over
the scale (so {"scale": [0.001,-0.001,0.001]}
flips y; translation/rotation also allowed)
materials : dict — {tag_name|phys_tag: polyfem material fields}
boundary_conditions: dict — pass-through, except dirichlet/neumann items
may use "selection": "tag_0 & ambient" (or a
list of names) instead of "id"
initial_conditions : dict — pass-through; "id" is the volumetric body id
from the boundary-extraction output_groups
contact / time / solver / output / space : dict — optional pass-through
save_vtu : bool — emit paraview .vtu/.pvd (default True)
save_restart : bool — write state.hdf5/restart.json checkpoints so
a later run can resume (default True)
resume : bool — resume from restart files found in out_dir/sim_output
(default True); set False or delete them to
start fresh
Example:
cfg = {
"input_msh": "output/m_sim.msh",
"materials": {"tag_0": {"type": "NeoHookean", "E": 1e9, "nu": 0.3, "rho": 1000}},
"boundary_conditions": {
"rhs": [0, -9.81, 0],
"dirichlet_boundary": [{"selection": "tag_0 & ambient", "value": [0, 0, 0]}],
},
"time": {"integrator": "ImplicitEuler", "tend": 2.0, "dt": 0.05},
}
polyfem_sim.run(cfg, out_dir=Path("output/sim"))