FEM Architecture & Solvers
Relevant source files
The following files were used as context for generating this wiki page:
- src/Mod/Fem/coding_conventions.md
- src/Mod/Fem/femsolver/elmer/sifio.py
- src/Mod/Fem/femsolver/calculix/writer.py
- src/Mod/Fem/femexamples/manager.py
- src/Mod/Fem/femtest/test_information.md
- src/Mod/Fem/femexamples/elmer_nonguitutorial01_eigenvalue_of_elastic_beam.py
- src/Mod/Fem/Gui/Resources/translations/Fem.ts
The Finite Element Method (FEM) module provides a robust framework for performing mechanical, thermal, and fluid simulations. It serves as a bridge between geometric models and external numerical solvers such as CalculiX, Elmer, and Z88. The architecture is designed to handle mesh generation, constraint definition, solver input writing, and post-processing of results within a unified Analysis container.
Sources: src/Mod/Fem/coding_conventions.md, src/Mod/Fem/femexamples/manager.py:126-140
Module Architecture and Conventions
The FEM module follows strict coding conventions to maintain a separation between the application logic (App) and the graphical user interface (Gui). The core logic is often implemented in Python for solver interfacing and C++ for performance-critical data structures.
Component Structure
- Analysis Container: The
Fem::FemAnalysisobject acts as the primary parent for all simulation-related objects, including meshes, solver settings, and material properties. - Naming Policies: Python code utilizes
snake_casefor modules and functions, whileCamelCaseis used for classes. C++ code exclusively usesCamelCase. - Type Checking: The module avoids
hasattr(obj, "Proxy")in favor of specialized utility methods likeis_of_type(obj, "TypeString")from thefemtool.femutilsmodule.
Sources: src/Mod/Fem/coding_conventions.md:58-94
General Simulation Workflow
The following diagram illustrates the standard data flow from geometric model to simulation results.
Solver Interfacing
The FEM module uses dedicated "Writer" classes to translate FreeCAD internal data into solver-specific input files.
CalculiX Solver (Ccx)
The CalculiX writer translates analysis data into .inp files. It enforces a consistent unit system (mm, N, s, K) because the underlying solver is unit-agnostic.
| Parameter | Unit Used in .inp |
|---|---|
| Length | mm |
| Mass | t (tonnes) |
| Force | N |
| Pressure | MPa (N/mm²) |
| Temperature | K |
The FemInputWriterCcx class manages the export of node sets, element sets, and steps (Static, Frequency, Buckling, or Thermomech).
Sources: src/Mod/Fem/femsolver/calculix/writer.py:59-100
Elmer Solver
For the Elmer solver, the module utilizes a Builder class to construct the Solver Input File (SIF). The SIF is organized into logical sections.
Valid SIF Sections
The Elmer interface recognizes specific sections required by the ElmerSolver:
Simulation,ConstantsBody,Material,Body ForceEquation,SolverBoundary Condition,Initial Condition
Sources: src/Mod/Fem/femsolver/elmer/sifio.py:34-58
Constraints and Boundary Conditions
Constraints define the physical environment of the simulation. They are mapped from geometric references (faces, edges, vertices) to mesh nodes or surfaces during the input writing phase.
Supported Constraint Types
The FEM workbench supports a wide range of physical constraints identified in the GUI and translation resources:
| Category | Specific Types |
|---|---|
| Mechanical | Fixed, Displacement, Force, Pressure, Bearing, Gear, Pulley, Spring |
| Thermal | Initial Temperature, Heat Flux, Temperature Boundary |
| Fluid | Fluid Boundary Condition (for CFD) |
| Numerical | Tie Constraint, Plane Multi-Point Constraint (MPC) |
Sources: src/Mod/Fem/Gui/Resources/translations/Fem.ts:10-1043
Testing and Example Management
The femexamples.manager provides a programmatic interface to set up and validate simulation scenarios.
- Example Setup: Uses
ObjectsFem.makeAnalysisand specialized factory methods likeObjectsFem.makeSolverCalculiXCcxToolsto build test documents. - Automated Execution: The
run_analysisfunction handles document recomputation, mesh generation (via Gmsh or Netgen), and solver execution. - Unit Testing: Tests are organized by solver and object type. Documentation specifies that standard test files are located in
Mod/Fem/femtest/data/.
Sources: src/Mod/Fem/femexamples/manager.py:126-212, src/Mod/Fem/femtest/test_information.md:89-102, src/Mod/Fem/femexamples/elmer_nonguitutorial01_eigenvalue_of_elastic_beam.py:61-118
Mesh Generation Flow
When running an automated analysis, the system identifies mesh generators within the analysis group and invokes the appropriate tools.
Summary
The FEM module architecture emphasizes a structured translation of geometric and physical data into solver-specific formats. By utilizing a common Analysis container and specialized input writers for CalculiX and Elmer, it ensures that complex multi-physics simulations can be defined once and executed across different numerical engines. The system is supported by an extensive example management framework that validates solver integration and architectural consistency.