Snap a per-element property field onto a finite set of named materials.
Solvers that describe materials by name rather than by per-element arrays — CalculiX being the case in hand, with its *MATERIAL / *ELSET / *SOLID SECTION triple — cannot represent a continuously blended interface at all. This projects each element onto its nearest reference material in log-property space (properties span many decades, so a relative metric is the only sane one), which is exact wherever the blend is sharp and approximate exactly in the transition band.
Parameters
Name
Type
Description
Default
values
dict[str, Any]
Per-element property arrays keyed by property name, (C,) each (concrete; quantization is not differentiable).
required
references
Sequence[Any]
Reference :class:~cadjoint.render.material.Material objects to snap to.
required
keys
Sequence[str]
Which properties participate in the distance.
required
Returns
Name
Type
Description
tuple[np.ndarray, np.ndarray]
(assignment, error) — assignment is a (C,) int array of indices into references, and error is the (C,) maximum relative property error the snap introduced (0 where an element landed exactly on a reference material).
Raises
Name
Type
Description
ValueError
If references is empty or a reference does not specify one of keys.