Skip to content

Config

The composed simulation config that ties the mesh, the domain and the Elmer physics together, and the solve frame it maps the authored model into.

femforge.config

The composed simulation config: the composition root that ties the gmsh mesh, the domain and the Elmer physics areas together.

Classes:

  • RunMeta –

    Searchable run metadata: a description and free key=value tags, recorded verbatim in the bundle manifest and

  • SimulationConfig –

    The single config spanning the whole pipeline, one area model per concern; solved_physics / resolved_stack give what the run solves under frame.

RunMeta pydantic-model

Bases: ConfigArea

Searchable run metadata: a description and free key=value tags, recorded verbatim in the bundle manifest and NEVER part of the run identity — editing them re-labels a run without re-solving it.

Config:

  • arbitrary_types_allowed: True
  • use_attribute_docstrings: True

Fields:

description pydantic-field

description: str | None = None

One line on what this run is for (shown in the driver log, searchable via run.find_runs).

tags pydantic-field

tags: TagDict

Free key=value labels (the same tag-dict shape the geometry uses); find_runs matches by subset.

matches

matches(selector: Mapping[str, str]) -> bool

Whether these tags satisfy every selector pair (the same containment rule as EntityTag.matches).

Source code in src/femforge/config.py
def matches(self, selector: Mapping[str, str]) -> bool:
    """Whether these tags satisfy every selector pair (the same containment rule as ``EntityTag.matches``)."""
    return all(self.tags.get(key) == value for key, value in selector.items())

SimulationConfig pydantic-model

Bases: ConfigArea

The single config spanning the whole pipeline, one area model per concern; solved_physics / resolved_stack give what the run solves under frame.

Config:

  • validate_assignment: True

Fields:

Validators:

geometry pydantic-field

geometry: SerializeAsAny[GeometryArea] | None = None

Optional parametric geometry: when set, the driver calls its build_step into the run directory before meshing and repoints mesh.step at it — the STEP is derived output, and the run identity comes from these parameters rather than an authored file.

frame pydantic-field

frame: FrameUnion

How the authored model maps onto the solve; see Frame.

mesh pydantic-field

mesh: MeshConfig

The gmsh mesh settings: STEP source, global element size, gmsh options.

domain pydantic-field

domain: DomainConfig

Materials + per-region tags.

physics pydantic-field

Which physics the Elmer stage solves.

meta pydantic-field

meta: RunMeta

Searchable description + tags; excluded from cache_key, so labeling never re-identifies a run.

frame_fits_inputs pydantic-validator

frame_fits_inputs(frame: Frame, info: ValidationInfo) -> Frame

On reassignment, reject a frame the domain or the physics selection cannot solve.

Source code in src/femforge/config.py
@field_validator("frame")
@classmethod
def frame_fits_inputs(cls, frame: Frame, info: ValidationInfo) -> Frame:
    """On reassignment, reject a ``frame`` the domain or the physics selection cannot solve."""
    domain: object = info.data.get("domain")
    physics: object = info.data.get("physics")

    if isinstance(domain, DomainConfig):
        domain.check_frame(frame)

    if isinstance(physics, PhysicsSelection):
        physics.check_frame(frame)

    return frame

domain_fits_frame pydantic-validator

domain_fits_frame(domain: DomainConfig, info: ValidationInfo) -> DomainConfig

Reject conditions the frame cannot solve.

Source code in src/femforge/config.py
@field_validator("domain")
@classmethod
def domain_fits_frame(cls, domain: DomainConfig, info: ValidationInfo) -> DomainConfig:
    """Reject conditions the frame cannot solve."""
    frame: object = info.data.get("frame")

    if isinstance(frame, Frame):
        domain.check_frame(frame)

    return domain

physics_fits_frame pydantic-validator

physics_fits_frame(physics: PhysicsSelection, info: ValidationInfo) -> PhysicsSelection

Reject a selection the frame cannot solve.

Source code in src/femforge/config.py
@field_validator("physics")
@classmethod
def physics_fits_frame(cls, physics: PhysicsSelection, info: ValidationInfo) -> PhysicsSelection:
    """Reject a selection the frame cannot solve."""
    frame: object = info.data.get("frame")

    if isinstance(frame, Frame):
        physics.check_frame(frame)

    return physics

solved_physics

solved_physics() -> Physics

The physics the selection solves as under frame.

Source code in src/femforge/config.py
def solved_physics(self) -> Physics:
    """The physics the selection solves as under ``frame``."""
    return self.frame.solves(self.physics.selected)

resolved_stack

resolved_stack() -> PhysicsConfig

The solver stack the run solves: the authored physics.overrides, else the solved physics' preset in frame.

Source code in src/femforge/config.py
def resolved_stack(self) -> PhysicsConfig:
    """The solver stack the run solves: the authored ``physics.overrides``, else the solved physics' preset in ``frame``."""
    if self.physics.overrides is not None:
        return self.physics.overrides

    return solved_stack(self.physics.selected, self.frame)

customize_physics

customize_physics() -> PhysicsConfig

Materialize the resolved stack into physics.overrides (idempotent) and return it for typed editing.

Source code in src/femforge/config.py
def customize_physics(self) -> PhysicsConfig:
    """Materialize the resolved stack into ``physics.overrides`` (idempotent) and return it for typed editing."""
    if self.physics.overrides is None:
        self.physics.overrides = solved_stack(self.physics.selected, self.frame)

    return self.physics.overrides

femforge.frames

Solve frames: how an authored model maps onto the coordinates the solve runs in.

Modules:

  • axisymmetric –

    The axisymmetric frame: the r–z half-plane of a model symmetric about an axis.

  • base –

    The solve frame seam: the Frame base class every frame implements, and the axes and planes frames are built from.

  • cartesian_2d –

    The Cartesian 2D frame: the planar section of a prismatic model, solved per metre of depth and scaled by its thickness.

  • solid –

    The solid frame: the authored 3D model solved as-is.

Classes:

  • Axis –

    A line through origin along direction, in the authored model's frame.

  • Axisymmetric –

    Solve the r–z half-plane of a model symmetric about axis: X = radial, Y = along the axis, Z = 0.

  • BodyMismatch –

    How far one body or named face of the authored model is from passing one frame check.

  • Cartesian2D –

    Solve the section of a prismatic model on the plane normal to normal: X = x_dir, Y = normal × X, Z = 0, scaled by thickness.

  • Frame –

    How an authored model maps onto the coordinates the solve runs in; each subclass is one frame.

  • FrameCheck –

    A rule a sectioning frame holds every body and named face of the authored model to.

  • FrameFact –

    One row of the Setup tab's Frame section: a label and the value it reads.

  • FrameGeometryError –

    The authored model does not fit the frame: a body or named face mismatches a frame check beyond its tolerance.

  • GeometryCheck –

    A frame's verdict on an authored model: every measured body and named face, and the tolerance each was held to.

  • PlaneState –

    How a 2D elasticity solve treats the out-of-plane direction.

  • SolvePlane –

    Where a sectioned solve's plane sits in the authored model: its origin and the authored directions of its +X and +Y.

  • Solid –

    Solve the authored 3D model as-is.

Functions:

  • default_frame –

    The first shipped frame, with its default fields, that solves on model_dim dimensions: the frame of a run whose bundle names none; frames with a required field are skipped.

  • shipped_frames –

    The frame classes FrameUnion admits, in its order.

Attributes:

  • FrameUnion –

    Any shipped frame, told apart by its kind; the type of every serialized frame field.

FrameUnion module-attribute

FrameUnion = Solid | Axisymmetric | Cartesian2D

Any shipped frame, told apart by its kind; the type of every serialized frame field.

Axis pydantic-model

Bases: ConfigArea

A line through origin along direction, in the authored model's frame.

Config:

  • frozen: True

Fields:

origin pydantic-field

origin: Vec3Field

[mm]: A point on the axis.

direction pydantic-field

direction: DirectionField

[-]: The axis direction; a scaled direction is the same axis.

label property

label: str

Z or -X for a coordinate axis through the origin, else its direction and origin.

along

along(direction: Vec3) -> float | None

The cosine between direction and this axis (±1), or None when they are not parallel within ALIGNMENT_TOLERANCE.

Source code in src/femforge/frames/base.py
def along(self, direction: Vec3) -> float | None:
    """The cosine between ``direction`` and this axis (±1), or None when they are not parallel within ``ALIGNMENT_TOLERANCE``."""
    unit: Vec3 = direction.normalized()
    cosine: float = unit.dot(self.direction)
    transverse: float = (unit - self.direction * cosine).magnitude()

    if transverse > ALIGNMENT_TOLERANCE:
        return None

    return cosine

Axisymmetric pydantic-model

Bases: Frame

Solve the r–z half-plane of a model symmetric about axis: X = radial, Y = along the axis, Z = 0.

Fields:

Validators:

kind pydantic-field

kind: Literal['axisymmetric'] = 'axisymmetric'

Discriminator that names this frame in a serialized config.

axis pydantic-field

axis: Axis = Axis.Z

The authored model's axis of symmetry.

radial pydantic-field

radial: DirectionField | None = None

[-]: The direction from the axis toward the sectioned half-plane, stored as its unit part perpendicular to the axis; None picks the world axis least aligned with the symmetry axis.

label property

label: str

A short human-readable name.

description property

description: str

One sentence on what the frame solves, for a reader who has not met it.

model_dim property

model_dim: Literal[2, 3]

The mesh dimension this frame solves on.

coordinate_system property

coordinate_system: CoordinateSystem

Elmer's Axi Symmetric system, which integrates per radian.

plane property

plane: SolvePlane

The half-plane through axis toward radial, else toward the world axis least aligned with axis (X first).

lumps_torque property

lumps_torque: bool

False: a torque has no axisymmetric form.

revolves property

revolves: bool

True: the section stands for the model revolved about axis.

perpendicular pydantic-validator

perpendicular(radial: Direction | None, info: ValidationInfo) -> Direction | None

Reject an axis-parallel radial and store its unit component perpendicular to the axis.

Source code in src/femforge/frames/axisymmetric.py
@field_validator("radial")
@classmethod
def perpendicular(cls, radial: Direction | None, info: ValidationInfo) -> Direction | None:
    """Reject an axis-parallel radial and store its unit component perpendicular to the axis."""
    axis: object = info.data.get("axis")

    if radial is None or not isinstance(axis, Axis):
        return radial

    try:
        return in_plane(radial, axis.direction)
    except ValueError:
        raise ValueError(f"The radial direction {radial} is parallel to the symmetry axis {axis.direction}.") from None

face_measure

face_measure(length: float, centroid: Vec3) -> FrameFact | None

The surface a section line of length metres sweeps about the axis, 2π·r̄·L with r̄ the radius of centroid; None for a line on the axis, which sweeps none.

Parameters:

  • length (float) –

    L [m]: The group's length in the solve plane.

  • centroid (Vec3) –

    [m]: The group's centroid in the solve frame, X radial.

Source code in src/femforge/frames/axisymmetric.py
def face_measure(self, length: float, centroid: Vec3) -> FrameFact | None:
    """The surface a section line of ``length`` metres sweeps about the axis, ``2π·r̄·L`` with ``r̄`` the radius of ``centroid``; None for a line on the axis, which sweeps none.

    Args:
        length: `L` `[m]`: The group's length in the solve plane.
        centroid: `[m]`: The group's centroid in the solve frame, X radial.
    """
    if abs(centroid.x) <= ALIGNMENT_TOLERANCE * length:
        return None

    area = quantity(math.tau * centroid.x * length, "m**2")

    return FrameFact(label="Revolved Area", value=f"2π·r̄·L = {readout(area)}")

measure_geometry

measure_geometry(compound: TaggedCompound) -> GeometryCheck

How far every body and named face of compound changes when turned about axis.

Source code in src/femforge/frames/axisymmetric.py
def measure_geometry(self, compound: TaggedCompound) -> GeometryCheck:
    """How far every body and named face of ``compound`` changes when turned about ``axis``."""
    from femforge.geometry.conformance import MISMATCH_TOLERANCE, revolution_mismatches

    return GeometryCheck(frame=self.label, tolerance=MISMATCH_TOLERANCE, measured=tuple(revolution_mismatches(compound, self.axis)))

prepare_geometry

prepare_geometry(step_in: Path, step_out: Path) -> Path

step_out, written with the section of step_in on plane once the model passes the geometry check; the check and the authored-body tessellation land beside it.

Source code in src/femforge/frames/axisymmetric.py
def prepare_geometry(self, step_in: Path, step_out: Path) -> Path:
    """``step_out``, written with the section of ``step_in`` on ``plane`` once the model passes the geometry check; the check and the authored-body tessellation land beside it."""
    from femforge.common.log import log
    from femforge.geometry.authored import write_authored_geometry
    from femforge.geometry.section import axisymmetric_cross_section, export_section
    from femforge.geometry.step import import_tagged_step

    compound = import_tagged_step(step_in)
    _ = write_authored_geometry(compound, self.plane, authored_path(step_out))
    check: GeometryCheck = self.measure_geometry(compound)
    check.raise_for_mismatch()

    section = axisymmetric_cross_section(compound, self.plane)
    export_section(section, step_out)
    check.write(step_out)
    log.bind(step=str(step_out), axis=self.axis.model_dump(mode="json")).info("Axisymmetric section written.")

    return step_out

solves

solves(physics: Physics) -> Physics

MAGNETOSTATICS_2D for magnetostatics, THERMAL for heat conduction; every other physics raises.

Source code in src/femforge/frames/axisymmetric.py
def solves(self, physics: Physics) -> Physics:
    """``MAGNETOSTATICS_2D`` for magnetostatics, ``THERMAL`` for heat conduction; every other physics raises."""
    match physics:
        case Physics.MAGNETOSTATICS | Physics.MAGNETOSTATICS_2D:
            return Physics.MAGNETOSTATICS_2D
        case Physics.THERMAL:
            return Physics.THERMAL
        case _:
            raise ValueError(f"Physics '{physics.value}' has no axisymmetric form; solve it with frame=Solid().")

solve_vector

solve_vector(authored: Vec3) -> tuple[float, ...]

(0, a) with a the signed length along the axis; a vector off the axis raises.

Source code in src/femforge/frames/axisymmetric.py
def solve_vector(self, authored: Vec3) -> tuple[float, ...]:
    """``(0, a)`` with ``a`` the signed length along the axis; a vector off the axis raises."""
    cosine: float | None = self.axis.along(authored)

    if cosine is None:
        raise ValueError(f"The vector {authored} is not along the symmetry axis {self.axis.label}, so it has no axisymmetric form.")

    return (0.0, cosine * authored.magnitude())

total

total(integrated: Vec3) -> Vec3

The full revolution of a per-radian integral: the axial component times 2π, the radial one zero by symmetry.

Source code in src/femforge/frames/axisymmetric.py
def total(self, integrated: Vec3) -> Vec3:
    """The full revolution of a per-radian integral: the axial component times 2π, the radial one zero by symmetry."""
    return Vec3(0.0, math.tau * integrated.y, 0.0)

solve_share

solve_share(share_of: Vec3) -> Vec3

The per-radian share of a full-revolution solve-frame vector: its axial component over 2π, the radial one zero by symmetry.

Source code in src/femforge/frames/axisymmetric.py
def solve_share(self, share_of: Vec3) -> Vec3:
    """The per-radian share of a full-revolution solve-frame vector: its axial component over 2π, the radial one zero by symmetry."""
    return Vec3(0.0, share_of.y / math.tau, 0.0)

along

along(vector: Vec3, axis: Axis | None) -> float

The axial component of vector along axis, the symmetry axis for None; an axis off the symmetry axis raises.

Source code in src/femforge/frames/axisymmetric.py
def along(self, vector: Vec3, axis: Axis | None) -> float:
    """The axial component of ``vector`` along ``axis``, the symmetry axis for None; an axis off the symmetry axis raises."""
    if axis is None:
        return vector.y

    cosine: float | None = self.axis.along(axis.direction)

    if cosine is None:
        raise ValueError(f"An axisymmetric run has force only along its symmetry axis {self.axis.direction}, not along {axis.direction}.")

    return vector.y * cosine

BodyMismatch pydantic-model

Bases: BaseModel

How far one body or named face of the authored model is from passing one frame check.

Config:

  • frozen: True
  • use_attribute_docstrings: True

Fields:

body pydantic-field

body: str

The leaf's tags, such as Material=Air.

check pydantic-field

check: FrameCheck

The check the leaf was measured against.

fraction pydantic-field

fraction: float

[-]: The mismatch, a share of the leaf's volume, area or depth.

Cartesian2D pydantic-model

Bases: Frame

Solve the section of a prismatic model on the plane normal to normal: X = x_dir, Y = normal × X, Z = 0, scaled by thickness.

Config:

  • frozen: True

Fields:

Validators:

kind pydantic-field

kind: Literal['cartesian_2d'] = 'cartesian_2d'

Discriminator that names this frame in a serialized config.

normal pydantic-field

normal: Axis = Axis.Z

The section plane: through the axis origin, normal to its direction.

x_dir pydantic-field

x_dir: DirectionField | None = None

[-]: The authored direction of the solve +X, stored as its unit part in the plane; None picks the world axis least aligned with the normal.

thickness pydantic-field

thickness: Length

t [mm]: The depth of the prism along the normal, which turns per-metre results into whole-model totals.

state pydantic-field

How a linear elasticity solve treats the out-of-plane direction.

label property

label: str

A short human-readable name.

description property

description: str

One sentence on what the frame solves, for a reader who has not met it.

model_dim property

model_dim: Literal[2, 3]

The mesh dimension this frame solves on.

coordinate_system property

coordinate_system: CoordinateSystem

Elmer's Cartesian 2D system, which integrates per metre of depth.

plane property

plane: SolvePlane

The plane through the normal's origin: +X toward x_dir, else the world axis least aligned with the normal (X first), and +Y = normal × X.

lumps_torque property

lumps_torque: bool

False: the frame lumps no torque.

plane_stress property

plane_stress: bool

Whether a 2D elasticity solve is plane stress.

thickness_m property

thickness_m: float

t [m]: The thickness in metres, the factor between a per-metre result and its whole-model total.

in_plane_x pydantic-validator

in_plane_x(x_dir: Direction | None, info: ValidationInfo) -> Direction | None

Reject an x_dir along the normal and store its unit part in the plane.

Source code in src/femforge/frames/cartesian_2d.py
@field_validator("x_dir")
@classmethod
def in_plane_x(cls, x_dir: Direction | None, info: ValidationInfo) -> Direction | None:
    """Reject an ``x_dir`` along the normal and store its unit part in the plane."""
    normal: object = info.data.get("normal")

    if x_dir is None or not isinstance(normal, Axis):
        return x_dir

    try:
        return in_plane(x_dir, normal.direction)
    except ValueError:
        raise ValueError(f"The x direction {x_dir} is parallel to the plane normal {normal.direction}.") from None

positive pydantic-validator

positive(thickness: Length) -> Length

Reject a zero or negative thickness.

Source code in src/femforge/frames/cartesian_2d.py
@field_validator("thickness")
@classmethod
def positive(cls, thickness: Length) -> Length:
    """Reject a zero or negative thickness."""
    if thickness.m_as("mm") <= 0.0:
        raise ValueError(f"The thickness {thickness} must be positive.")

    return thickness

facts

facts() -> tuple[FrameFact, ...]

The plane's origin and axes, the thickness, then the plane state.

Source code in src/femforge/frames/cartesian_2d.py
def facts(self) -> tuple[FrameFact, ...]:
    """The plane's origin and axes, the thickness, then the plane state."""
    *placed, state = super().facts()

    return (*placed, FrameFact(label="Thickness", value=readout(self.thickness)), state)

face_measure

face_measure(length: float, centroid: Vec3) -> FrameFact

The face a section line of length metres stands for: its length times the thickness; centroid is ignored.

Parameters:

  • length (float) –

    L [m]: The group's length in the solve plane.

  • centroid (Vec3) –

    [m]: The group's centroid in the solve frame.

Source code in src/femforge/frames/cartesian_2d.py
def face_measure(self, length: float, centroid: Vec3) -> FrameFact:
    """The face a section line of ``length`` metres stands for: its length times the thickness; ``centroid`` is ignored.

    Args:
        length: `L` `[m]`: The group's length in the solve plane.
        centroid: `[m]`: The group's centroid in the solve frame.
    """
    area = quantity(length * self.thickness_m, "m**2")

    return FrameFact(label="Face Area", value=f"{readout(area)} at {readout(self.thickness)} Thickness")

measure_geometry

measure_geometry(compound: TaggedCompound) -> GeometryCheck

How far every body and named face of compound is from a prism through thickness along the normal.

Source code in src/femforge/frames/cartesian_2d.py
def measure_geometry(self, compound: TaggedCompound) -> GeometryCheck:
    """How far every body and named face of ``compound`` is from a prism through ``thickness`` along the normal."""
    from femforge.geometry.conformance import MISMATCH_TOLERANCE, prism_mismatches

    return GeometryCheck(frame=self.label, tolerance=MISMATCH_TOLERANCE, measured=tuple(prism_mismatches(compound, self.plane, self.thickness)))

prepare_geometry

prepare_geometry(step_in: Path, step_out: Path) -> Path

step_out, written with the section of step_in on plane once the model passes the geometry check; the check and the authored-body tessellation land beside it.

Source code in src/femforge/frames/cartesian_2d.py
def prepare_geometry(self, step_in: Path, step_out: Path) -> Path:
    """``step_out``, written with the section of ``step_in`` on ``plane`` once the model passes the geometry check; the check and the authored-body tessellation land beside it."""
    from femforge.common.log import log
    from femforge.geometry.authored import write_authored_geometry
    from femforge.geometry.section import export_section, planar_cross_section
    from femforge.geometry.step import import_tagged_step

    compound = import_tagged_step(step_in)
    _ = write_authored_geometry(compound, self.plane, authored_path(step_out))
    check: GeometryCheck = self.measure_geometry(compound)
    check.raise_for_mismatch()

    section = planar_cross_section(compound, self.plane)
    export_section(section, step_out)
    check.write(step_out)
    log.bind(step=str(step_out), normal=self.normal.model_dump(mode="json"), thickness=self.thickness_m).info("Planar section written.")

    return step_out

solves

solves(physics: Physics) -> Physics

MAGNETOSTATICS_2D for magnetostatics, and heat conduction and linear elasticity as themselves; every other physics raises.

Source code in src/femforge/frames/cartesian_2d.py
def solves(self, physics: Physics) -> Physics:
    """``MAGNETOSTATICS_2D`` for magnetostatics, and heat conduction and linear elasticity as themselves; every other physics raises."""
    match physics:
        case Physics.MAGNETOSTATICS | Physics.MAGNETOSTATICS_2D:
            return Physics.MAGNETOSTATICS_2D
        case Physics.THERMAL | Physics.LINEAR_ELASTICITY:
            return physics
        case _:
            raise ValueError(f"Physics '{physics.value}' has no Cartesian 2D form; solve it with frame=Solid().")

solve_vector

solve_vector(authored: Vec3) -> tuple[float, ...]

(v·x, v·y) on the plane basis; a vector with a part along the normal raises.

Source code in src/femforge/frames/cartesian_2d.py
def solve_vector(self, authored: Vec3) -> tuple[float, ...]:
    """``(v·x, v·y)`` on the plane basis; a vector with a part along the normal raises."""
    plane: SolvePlane = self.plane

    if abs(authored.dot(plane.normal)) > ALIGNMENT_TOLERANCE * authored.magnitude():
        raise ValueError(f"The vector {authored} has a part along the plane normal {self.normal.label}, so it has no Cartesian 2D form.")

    return (authored.dot(plane.x_dir), authored.dot(plane.y_dir))

total

total(integrated: Vec3) -> Vec3

The whole prism's total of a per-metre integral: its in-plane components times the thickness.

Source code in src/femforge/frames/cartesian_2d.py
def total(self, integrated: Vec3) -> Vec3:
    """The whole prism's total of a per-metre integral: its in-plane components times the thickness."""
    return Vec3(integrated.x * self.thickness_m, integrated.y * self.thickness_m, 0.0)

solve_share

solve_share(share_of: Vec3) -> Vec3

The per-metre share of a whole-prism solve-frame vector: the vector over the thickness.

Source code in src/femforge/frames/cartesian_2d.py
def solve_share(self, share_of: Vec3) -> Vec3:
    """The per-metre share of a whole-prism solve-frame vector: the vector over the thickness."""
    return share_of / self.thickness_m

along

along(vector: Vec3, axis: Axis | None) -> float

The projection of the solve-frame vector onto the authored axis; None raises, since the frame has no axis of its own.

Source code in src/femforge/frames/cartesian_2d.py
def along(self, vector: Vec3, axis: Axis | None) -> float:
    """The projection of the solve-frame ``vector`` onto the authored ``axis``; None raises, since the frame has no axis of its own."""
    if axis is None:
        raise ValueError("A Cartesian 2D run has no axis of its own; pass the axis to project onto.")

    plane: SolvePlane = self.plane

    return vector.x * axis.direction.dot(plane.x_dir) + vector.y * axis.direction.dot(plane.y_dir)

Frame pydantic-model

Bases: ConfigArea, ABC

How an authored model maps onto the coordinates the solve runs in; each subclass is one frame.

Fields:

kind pydantic-field

kind: str

Discriminator that names this frame in a serialized config.

label abstractmethod property

label: str

A short human-readable name.

description abstractmethod property

description: str

One sentence on what the frame solves, for a reader who has not met it.

model_dim abstractmethod property

model_dim: Literal[2, 3]

The mesh dimension this frame solves on.

coordinate_system abstractmethod property

coordinate_system: CoordinateSystem

The Elmer coordinate system the frame solves in.

plane abstractmethod property

plane: SolvePlane | None

Where the solve plane sits in the authored model; None when the model solves whole.

rewrites_geometry property

rewrites_geometry: bool

Whether the solve meshes a converted STEP rather than the authored one.

lumps_torque abstractmethod property

lumps_torque: bool

Whether Elmer's force lumping yields a torque in this frame.

revolves property

revolves: bool

Whether the solve section stands for a model revolved about an axis.

axis_names property

axis_names: tuple[str, str]

The names of the solve plane's X and Y axes: Radial and Axial for a revolving section, else X and Y.

plane_stress property

plane_stress: bool | None

Whether a 2D elasticity solve is plane stress (True) or plane strain (False); None when the frame poses no plane state.

measure_geometry abstractmethod

measure_geometry(compound: TaggedCompound) -> GeometryCheck | None

How far every body and named face of the authored compound is from fitting this frame; None when the frame takes any model.

Source code in src/femforge/frames/base.py
@abstractmethod
def measure_geometry(self, compound: TaggedCompound) -> GeometryCheck | None:
    """How far every body and named face of the authored ``compound`` is from fitting this frame; None when the frame takes any model."""

check_geometry

check_geometry(compound: TaggedCompound) -> None

Raise FrameGeometryError when a body or named face of the authored compound does not fit this frame.

Source code in src/femforge/frames/base.py
def check_geometry(self, compound: TaggedCompound) -> None:
    """Raise ``FrameGeometryError`` when a body or named face of the authored ``compound`` does not fit this frame."""
    check: GeometryCheck | None = self.measure_geometry(compound)

    if check is not None:
        check.raise_for_mismatch()

prepare_geometry abstractmethod

prepare_geometry(step_in: Path, step_out: Path) -> Path

The STEP the solve meshes: step_in itself, or its conversion written to step_out.

Source code in src/femforge/frames/base.py
@abstractmethod
def prepare_geometry(self, step_in: Path, step_out: Path) -> Path:
    """The STEP the solve meshes: ``step_in`` itself, or its conversion written to ``step_out``."""

solves abstractmethod

solves(physics: Physics) -> Physics

What physics solves as in this frame; raises ValueError when it has no form here.

Source code in src/femforge/frames/base.py
@abstractmethod
def solves(self, physics: Physics) -> Physics:
    """What ``physics`` solves as in this frame; raises ``ValueError`` when it has no form here."""

supports

supports(physics: Physics) -> bool

Whether physics has a form in this frame.

Source code in src/femforge/frames/base.py
def supports(self, physics: Physics) -> bool:
    """Whether ``physics`` has a form in this frame."""
    try:
        _ = self.solves(physics)
    except ValueError:
        return False

    return True

solve_vector abstractmethod

solve_vector(authored: Vec3) -> tuple[float, ...]

The solve-coordinate components of an authored-frame vector; raises ValueError when it has no form here.

Source code in src/femforge/frames/base.py
@abstractmethod
def solve_vector(self, authored: Vec3) -> tuple[float, ...]:
    """The solve-coordinate components of an authored-frame vector; raises ``ValueError`` when it has no form here."""

total abstractmethod

total(integrated: Vec3) -> Vec3

The whole model's total of a vector Elmer integrated over the solve domain.

Source code in src/femforge/frames/base.py
@abstractmethod
def total(self, integrated: Vec3) -> Vec3:
    """The whole model's total of a vector Elmer integrated over the solve domain."""

solve_share abstractmethod

solve_share(share_of: Vec3) -> Vec3

The share the solve domain carries of a whole-model solve-frame vector, the inverse of total.

Source code in src/femforge/frames/base.py
@abstractmethod
def solve_share(self, share_of: Vec3) -> Vec3:
    """The share the solve domain carries of a whole-model solve-frame vector, the inverse of [`total`][femforge.frames.Frame.total]."""

authored_share

authored_share(authored: Vec3) -> Vec3

The solve-frame share the solve domain carries of an authored whole-model vector; raises ValueError when it has no form here.

Source code in src/femforge/frames/base.py
def authored_share(self, authored: Vec3) -> Vec3:
    """The solve-frame share the solve domain carries of an authored whole-model vector; raises ``ValueError`` when it has no form here."""
    components: list[float] = [*self.solve_vector(authored), 0.0, 0.0]

    return self.solve_share(Vec3(components[0], components[1], components[2]))

along abstractmethod

along(vector: Vec3, axis: Axis | None) -> float

The component of a solve-frame vector along an authored axis, or along the frame's own axis for None.

Source code in src/femforge/frames/base.py
@abstractmethod
def along(self, vector: Vec3, axis: Axis | None) -> float:
    """The component of a solve-frame vector along an authored ``axis``, or along the frame's own axis for None."""

facts

facts() -> tuple[FrameFact, ...]

Which way the solve plane faces, where it sits and how its axes run in the authored model, then the plane state when the frame poses one; none for a frame that solves the model whole.

Source code in src/femforge/frames/base.py
def facts(self) -> tuple[FrameFact, ...]:
    """Which way the solve plane faces, where it sits and how its axes run in the authored model, then the plane state when the frame poses one; none for a frame that solves the model whole."""
    plane: SolvePlane | None = self.plane

    if plane is None:
        return ()

    revolves: bool = self.revolves
    pointing = FrameFact(label="Axis" if revolves else "Normal", value=along(plane.y_dir if revolves else plane.normal))
    origin = FrameFact(label="Axis Origin" if revolves else "Plane Origin", value=f"{plane.origin:.3g} mm")
    axes = FrameFact(label="Radial, Axial" if revolves else "Solve X, Y", value=f"{axis_word(plane.x_dir)}, {axis_word(plane.y_dir)}")
    state: bool | None = self.plane_stress

    if state is None:
        return (pointing, origin, axes)

    plane_state = FrameFact(label="Plane State", value="Plane Stress" if state else "Plane Strain", tip=PLANE_STRESS_TIP if state else PLANE_STRAIN_TIP)

    return (pointing, origin, axes, plane_state)

face_measure

face_measure(length: float, centroid: Vec3) -> FrameFact | None

What a boundary group meshed as a line of length metres at centroid measures in the whole model; None for a frame that meshes faces as faces.

Parameters:

  • length (float) –

    L [m]: The group's length in the solve plane.

  • centroid (Vec3) –

    [m]: The group's centroid in the solve frame.

Source code in src/femforge/frames/base.py
def face_measure(self, length: float, centroid: Vec3) -> FrameFact | None:
    """What a boundary group meshed as a line of ``length`` metres at ``centroid`` measures in the whole model; None for a frame that meshes faces as faces.

    Args:
        length: `L` `[m]`: The group's length in the solve plane.
        centroid: `[m]`: The group's centroid in the solve frame.
    """
    return None

FrameCheck

Bases: StrEnum

A rule a sectioning frame holds every body and named face of the authored model to.

Attributes:

  • TURNED –

    The leaf is unchanged when turned about the symmetry axis.

  • PRISM –

    The leaf is its mid-depth section carried through the model's depth along the normal.

  • DEPTH –

    The body spans the frame's thickness along the normal.

  • failure (str) –

    What a leaf that fails the check does, worded to follow the leaf's name.

  • remedy (str) –

    How to author the model so that it passes the check.

TURNED class-attribute instance-attribute

TURNED = 'turned'

The leaf is unchanged when turned about the symmetry axis.

PRISM class-attribute instance-attribute

PRISM = 'prism'

The leaf is its mid-depth section carried through the model's depth along the normal.

DEPTH class-attribute instance-attribute

DEPTH = 'depth'

The body spans the frame's thickness along the normal.

failure property

failure: str

What a leaf that fails the check does, worded to follow the leaf's name.

remedy property

remedy: str

How to author the model so that it passes the check.

FrameFact pydantic-model

Bases: BaseModel

One row of the Setup tab's Frame section: a label and the value it reads.

Config:

  • frozen: True
  • use_attribute_docstrings: True

Fields:

label pydantic-field

label: str

The row's label, such as Plane Origin.

value pydantic-field

value: str

The row's value, such as (0, 0, 5) mm.

tip pydantic-field

tip: str = ''

What the value means, for a value its name does not explain; empty for none.

FrameGeometryError

FrameGeometryError(check: GeometryCheck)

Bases: ValueError

The authored model does not fit the frame: a body or named face mismatches a frame check beyond its tolerance.

Methods:

  • __reduce__ –

    Rebuild from the check, so the error survives a trip between processes.

Attributes:

Source code in src/femforge/frames/base.py
def __init__(self, check: GeometryCheck) -> None:
    """List every failing leaf of ``check`` with its mismatch, then each remedy once."""
    self.check = check
    self.mismatches = check.mismatches
    failing: set[FrameCheck] = {mismatch.check for mismatch in self.mismatches}
    lines: list[str] = [f"  - {mismatch.body}: {mismatch.check.failure}, mismatch {mismatch.fraction:.2e}" for mismatch in self.mismatches]
    remedies: list[str] = [member.remedy for member in FrameCheck if member in failing]

    super().__init__("\n".join([f"The model does not fit the frame {check.frame}:", *lines, *remedies]))

check instance-attribute

check: GeometryCheck = check

The whole verdict, passing measurements included.

mismatches instance-attribute

mismatches: tuple[BodyMismatch, ...] = check.mismatches

The measurements above the tolerance.

__reduce__

Rebuild from the check, so the error survives a trip between processes.

Source code in src/femforge/frames/base.py
def __reduce__(self) -> tuple[type[FrameGeometryError], tuple[GeometryCheck]]:
    """Rebuild from the check, so the error survives a trip between processes."""
    return (FrameGeometryError, (self.check,))

GeometryCheck pydantic-model

Bases: BaseModel

A frame's verdict on an authored model: every measured body and named face, and the tolerance each was held to.

Config:

  • frozen: True
  • use_attribute_docstrings: True

Fields:

frame pydantic-field

frame: str

The label of the frame that checked the model.

tolerance pydantic-field

tolerance: float

[-]: The largest mismatch fraction that still passes.

measured pydantic-field

measured: tuple[BodyMismatch, ...]

Every measurement, passing ones included.

mismatches property

mismatches: tuple[BodyMismatch, ...]

The measurements above tolerance.

passed property

passed: bool

Whether every measurement is within tolerance.

raise_for_mismatch

raise_for_mismatch() -> None

Raise FrameGeometryError when a measurement is above tolerance.

Source code in src/femforge/frames/base.py
def raise_for_mismatch(self) -> None:
    """Raise [`FrameGeometryError`][femforge.frames.FrameGeometryError] when a measurement is above ``tolerance``."""
    if not self.passed:
        raise FrameGeometryError(self)

write

write(step: Path) -> None

Write the check beside the solve STEP step.

Source code in src/femforge/frames/base.py
def write(self, step: Path) -> None:
    """Write the check beside the solve STEP ``step``."""
    write_atomic(check_path(step), self.model_dump_json())

load classmethod

load(step: Path) -> GeometryCheck | None

The check recorded beside step; None when it has no check file.

Source code in src/femforge/frames/base.py
@classmethod
def load(cls, step: Path) -> GeometryCheck | None:
    """The check recorded beside ``step``; None when it has no check file."""
    path: Path = check_path(step)

    if not path.is_file():
        return None

    return cls.model_validate_json(path.read_text(encoding="utf-8"))

PlaneState

Bases: StrEnum

How a 2D elasticity solve treats the out-of-plane direction.

Attributes:

  • STRESS –

    No out-of-plane stress: a thin plate loaded in its plane.

  • STRAIN –

    No out-of-plane strain: a long prism held between rigid ends.

STRESS class-attribute instance-attribute

STRESS = 'plane_stress'

No out-of-plane stress: a thin plate loaded in its plane.

STRAIN class-attribute instance-attribute

STRAIN = 'plane_strain'

No out-of-plane strain: a long prism held between rigid ends.

SolvePlane pydantic-model

Bases: ConfigArea

Where a sectioned solve's plane sits in the authored model: its origin and the authored directions of its +X and +Y.

Config:

  • frozen: True

Fields:

origin pydantic-field

origin: Vec3Field

[mm]: The authored point at the plane's origin.

x_dir pydantic-field

[-]: The authored direction of the plane's +X, the radial direction at θ = 0 of an axisymmetric section.

y_dir pydantic-field

[-]: The authored direction of the plane's +Y, the symmetry axis of an axisymmetric section.

normal property

normal: Direction

The authored direction of the solve +Z, x_dir × y_dir.

Solid pydantic-model

Bases: Frame

Solve the authored 3D model as-is.

Fields:

kind pydantic-field

kind: Literal['solid'] = 'solid'

Discriminator that names this frame in a serialized config.

label property

label: str

A short human-readable name.

description property

description: str

One sentence on what the frame solves, for a reader who has not met it.

model_dim property

model_dim: Literal[2, 3]

The mesh dimension this frame solves on.

coordinate_system property

coordinate_system: CoordinateSystem

Cartesian coordinates.

plane property

plane: None

None: the model solves whole.

lumps_torque property

lumps_torque: bool

True: Elmer lumps a torque about any authored axis.

measure_geometry

measure_geometry(compound: TaggedCompound) -> GeometryCheck | None

None: the solve meshes the model as authored.

Source code in src/femforge/frames/solid.py
def measure_geometry(self, compound: TaggedCompound) -> GeometryCheck | None:
    """None: the solve meshes the model as authored."""
    return None

prepare_geometry

prepare_geometry(step_in: Path, step_out: Path) -> Path

step_in itself: nothing is converted.

Source code in src/femforge/frames/solid.py
def prepare_geometry(self, step_in: Path, step_out: Path) -> Path:
    """``step_in`` itself: nothing is converted."""
    return step_in

solves

solves(physics: Physics) -> Physics

physics itself, except the 2D magnetostatic stack, which raises.

Source code in src/femforge/frames/solid.py
def solves(self, physics: Physics) -> Physics:
    """``physics`` itself, except the 2D magnetostatic stack, which raises."""
    if physics is Physics.MAGNETOSTATICS_2D:
        raise ValueError(f"Physics '{physics.value}' is the 2D magnetostatic stack: select '{Physics.MAGNETOSTATICS.value}' with a 2D frame (Axisymmetric() or Cartesian2D()).")

    return physics

solve_vector

solve_vector(authored: Vec3) -> tuple[float, ...]

The authored components unchanged.

Source code in src/femforge/frames/solid.py
def solve_vector(self, authored: Vec3) -> tuple[float, ...]:
    """The authored components unchanged."""
    return authored.to_tuple()

total

total(integrated: Vec3) -> Vec3

integrated itself: the solve domain is the whole model.

Source code in src/femforge/frames/solid.py
def total(self, integrated: Vec3) -> Vec3:
    """``integrated`` itself: the solve domain is the whole model."""
    return integrated

solve_share

solve_share(share_of: Vec3) -> Vec3

share_of itself: the solve domain is the whole model.

Source code in src/femforge/frames/solid.py
def solve_share(self, share_of: Vec3) -> Vec3:
    """``share_of`` itself: the solve domain is the whole model."""
    return share_of

along

along(vector: Vec3, axis: Axis | None) -> float

The projection of vector onto axis; None raises, since a solid has no axis of its own.

Source code in src/femforge/frames/solid.py
def along(self, vector: Vec3, axis: Axis | None) -> float:
    """The projection of ``vector`` onto ``axis``; None raises, since a solid has no axis of its own."""
    if axis is None:
        raise ValueError("A solid run has no symmetry axis; pass the axis to project onto.")

    return vector.dot(axis.direction)

default_frame

default_frame(model_dim: int) -> Frame

The first shipped frame, with its default fields, that solves on model_dim dimensions: the frame of a run whose bundle names none; frames with a required field are skipped.

Source code in src/femforge/frames/__init__.py
def default_frame(model_dim: int) -> Frame:
    """The first shipped frame, with its default fields, that solves on ``model_dim`` dimensions: the frame of a run whose bundle names none; frames with a required field are skipped."""
    for kind in shipped_frames():
        try:
            frame: Frame = kind.model_validate({})
        except ValidationError:
            continue

        if frame.model_dim == model_dim:
            return frame

    raise ValueError(f"no shipped frame solves on {model_dim} dimensions")

shipped_frames

shipped_frames() -> tuple[type[Frame], ...]

The frame classes FrameUnion admits, in its order.

Source code in src/femforge/frames/__init__.py
def shipped_frames() -> tuple[type[Frame], ...]:
    """The frame classes ``FrameUnion`` admits, in its order."""
    parts: tuple[object, ...] = get_args(FrameUnion)

    return cast("tuple[type[Frame], ...]", get_args(parts[0]))