Extend FEM Module/de

Tutorium
Thema
FEM
Niveau
fortgeschrittener Anfänger
Zeit zum Abschluss
1 Stunde
Autoren
M42kus
FreeCAD-Version
0.17
Beispieldateien
Siehe auch
None

Der Arbeitsbereich FEM unterstützt schon viele unterschiedliche Randbedingungen und mehrere Berechnungsprogramme (Löser). Trotzdem brauchen Anwender oft Randbedingungen, die noch nicht von FreeCAD unterstützt werden. Diese Seite ist Startpunkt für eine Reihe von Anleitungen und anderen Quellen, die beschreiben, wie der Arbeitsbereich FEM mit dem vorhandenen Framework (<-?) erweitert werden kann. Während diese Reihe auch für Software-Entwickler hilfreich sein kann, ist die Idee dahinter, dass FEM-Anwender mit etwas Interesse für Python-Programmierung ermöglicht wird, selbst hinzuzufügen, was sie brauchen.

Neue Randbedingungen, Gleichungen oder Löser hinzuzufügen ist hauptsächlich Routinearbeit. Aber beim ersten Mal ist es wahrscheinlich nicht so einfach, wie es aussieht. Ein Verständnis für die folgenden Themen wird hilfreich sein:

Build System (cmake)

The build system must be modified regardless of which objects shall be added o the FEM workbench. Every python module (file) must be registered. The FEM workbench requires every new python module to be registered in Mod/Fem/CMakeLists.txt. This is true regardless of the type of the python module (GUI or non-GUI). Where exactly the module must be inserted depends on the role of the module. Solver, equations and constraints all use different lists. Searching for similar files and inserting the new file in the same list works most of the time.

As an example lets add a new constraint called pressure which is related to the flow equation. So, FlowPressure will widely used as <name> for this constraint. A new constraint requires at least the following new modules:

These three files must be added to Mod/Fem/CMakeLists.txt as well as Mod/Fem/App/CMakeLists.txt. All inserted lines of code are indicated by a starting +.

Mod/Fem/CMakeLists.txt

SET(FemObjects_SRCS
    femobjects/__init__.py
    femobjects/base_fempythonobject.py
    femobjects/constraint_bodyheatsource.py
    femobjects/constraint_electrostaticpotential.py
    femobjects/constraint_flowvelocity.py
    femobjects/constraint_initialflowvelocity.py
+   femobjects/constraint_initialflowpressure.py
    femobjects/constraint_selfweight.py
...
    femobjects/solver_ccxtools.py
)
...
SET(FemGuiViewProvider_SRCS
    femviewprovider/__init__.py
    femviewprovider/view_base_femconstraint.py
    femviewprovider/view_base_femobject.py
    femviewprovider/view_constraint_bodyheatsource.py
    femviewprovider/view_constraint_electrostaticpotential.py
    femviewprovider/view_constraint_flowvelocity.py
+   femviewprovider/view_constraint_flowpressure.py
    femviewprovider/view_constraint_initialflowvelocity.py
    femviewprovider/view_constraint_selfweight.py
...
    femviewprovider/view_solver_ccxtools.py
)

Source Organization

For organizing the python code the FEM module uses the following approach. The module is split into the following packages:

One package doesn't follow this pattern: femsolver. It has its place on the same level as femobjects and femguiobjects (src/Mod/Fem/femsolver). The package contains solver and equation related packages and modules and it is organized the following way:

.femsolver
.femsolver.elmer
.femsolver.elmer.equations
.femsolver.calculix
.femsolver.calculix.equations
.femsolver.z88
.femsolver.z88.equations

Löser

In FreeCAD a solver can be split into two parts:

Most files related to a solver reside in a sub-package of the femsolver package (e.g. for Elmer its in femsolver/elmer). The following list enumerates all files related to the implementation of a solver. Those are the files that need to be copied and modified to add support for a new solver to FreeCAD. The given example is taken from the solver implementation of Elmer.

Gleichungen

An equation represents a particular physics that shall be considered when solving the analysis (e.g. Flow, Heat). Not all solver in FreeCAD support (all) equations. Equations are represented by child objects of the corresponding solver object. In the tree-view this looks like this:

Most solver specific options (e.g. max. iterations, method of solving, etc) are set via the equation objects. One consequence of this is that each solver must have it's own implementation of "the same" equation. CalculiX would have a different Heat-object that Elmer. To avoid having multiple buttons for the same physics in the GUI each solver object adds it's equations itself.

The actual implementation can be split into the generic and the solver specific part. The generic part can be found in the femsolver.equationbase module. The solver specific part resides inside individual Equations sub-packages of the solver packages (e.g. femsolver/elmer/equations).

Adding a new equations to Elmer should be very easy. For newcomers there exists a tutorial which shows how to add a new equation to Elmer by adding the existing elasticity solver to FreeCAD: Add FEM Equation Tutorial.

Randbedingungen

Constraints define boundary conditions for the problem that shall be solved. In FreeCAD constraints aren't specific to a particular solver. A problem setup can be solved by all solver that support all conditions in the analysis.

Adding new constraints is quite straight forward. For newcomers there is a tutorial: Add FEM Constraint Tutorial.