Wildmeshing Toolkit
Loading...
Searching...
No Matches
Functions | Variables
simwild.polyfem_ops.polyfem_sim Namespace Reference

Functions

list _diff_json_keys (a, b, str path="")
 
list _filter_drift (list diffs)
 
dict parse_id_map (str path)
 
list _resolve_bc_list (list bc_list, dict selection_map)
 
dict build_polyfem_sim_json (dict cfg, Path msh_path, Path sim_out_dir, dict name_to_tag, dict id_map, int mesh_dim)
 
Path run (dict cfg, out_dir=None, str in_dirname="sim_input", str out_dirname="sim_output")
 
 main ()
 

Variables

tuple _RESUME_SAFE_PREFIXES
 
dict SIM_DEFAULTS
 
dict SIM_SECTION_DEFAULTS
 

Detailed Description

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"))

Function Documentation

◆ _diff_json_keys()

list simwild.polyfem_ops.polyfem_sim._diff_json_keys (   a,
  b,
str   path = "" 
)
protected
Return dotted-path strings of fields where two json structures differ.
Recurses into dicts; lists and scalars compared atomically.

◆ _resolve_bc_list()

list simwild.polyfem_ops.polyfem_sim._resolve_bc_list ( list  bc_list,
dict  selection_map 
)
protected
Resolve named surface selections to polyfem ids in a list of BC items.
Items may carry `"selection": {"region": expr, "filter": expr?}` instead
of `"id"`; the pair is matched against the id_map written by
msh_boundary_extractor (exact expression strings).

◆ parse_id_map()

dict simwild.polyfem_ops.polyfem_sim.parse_id_map ( str  path)
Parse the *_id_map.txt written by msh_boundary_extractor. Returns
{"bodies": {phys tag: group name}, "selections": {(region, filter|None):
surface id}} — selections keyed by their exact expression strings.

Variable Documentation

◆ _RESUME_SAFE_PREFIXES

tuple simwild.polyfem_ops.polyfem_sim._RESUME_SAFE_PREFIXES
protected
Initial value:
1= (
2 "time.tend",
3 "output.",
4 "solver.",
5 "initial_conditions.",
6)

◆ SIM_DEFAULTS

dict simwild.polyfem_ops.polyfem_sim.SIM_DEFAULTS
Initial value:
1= {
2 "scale": 0.001,
3 "save_vtu": True,
4 "save_restart": True,
5}