Tutorium FEM Gleichung hinzufügen

From FreeCAD Documentation
Revision as of 19:01, 20 August 2021 by FuzzyBot (talk | contribs) (FuzzyBot moved page Add FEM Equation Tutorial/de to Add FEM equation tutorial/de without leaving a redirect: Part of translatable page "Add FEM Equation Tutorial")
Tutorium
Thema
FEM Gleichung hinzufügen
Niveau
Zeit zum Abschluss
Autoren
M42kus
FreeCAD-Version
Beispieldateien
Siehe auch
None

Introduction

In diesem Tutorium werden wir die Fließgeschwindigkeit zu FreeCAD hinzufügen und die Unterstützung für den Elmer Löser einführen. Bitte stelle sicher, dass du Extend FEM Module gelesen und verstanden hast, bevor du dieses Tutorium liest.

Die Aufgabe kann in vier Teile aufgeteilt werden. Der erste Schritt besteht darin, den FEM Arbeitsbereich auf einen neuen Gleichungstyp aufmerksam zu machen. Dieser Schritt muss nur durchgeführt werden, wenn die Gleichung in FreeCAD jetzt nicht existiert (im Gegensatz zu einer Gleichung, die bereits in FreeCAD existiert, aber vom Ziellöser nicht unterstützt wird). Der zweite Schritt besteht darin, ein konkretes Dokumentobjekt hinzuzufügen, das die Elmer spezifische Gleichung repräsentiert. Der dritte Schritt besteht darin, dem Löserobjekt von elmer Unterstützung für die neue Gleichung hinzuzufügen. Danach muss der Analyseexport von elmer erweitert werden, um den neuen Gleichungstyp zu unterstützen.

Neuer Gleichungstyp

In this step we are going to modify the following file:

  • src/Mod/Fem/femsolver/equationbase.py

The equation type is shared among all equation objects of the different solver. Each type has a string specifier (e.g. "Heat") and a dedicated command that adds the equation to the selected solver. This allows for a simpler GUI where we have only one button for the heat equation which is used for all supported solver.

First add the new equation to the equationbase.py module. Each equation requires two classes. A document proxy and a view proxy. Those two classes will later be used as base classes for the Elmer specific equation classes. Just copy-paste them from an existing equation type and adjust the icon path inside getIcon(self) of the view proxy.

class FlowProxy(BaseProxy):
    pass

class FlowViewProxy(BaseViewProxy):
    def getIcon(self):
        return ":/icons/FEM_EquationFlow.svg"

Elmers Gleichungs Objekt

In diesem Schritt werden wir die folgenden Dateien modifizieren:

  • src/Mod/Fem/femsolver/elmer/equations/flow.py

und die folgende neue Datei hinzufügen:

  • src/Mod/Fem/ObjectsFem.py
  • src/Mod/Fem/CMakeLists.txt

Beginnen wir mit dem Modul, das das Dokumentobjekt implementiert. In kann aus einer bestehenden Gleichung kopiert werden. Wenn die neue Gleichung nur Schlüsselwörter für lineare Systeme unterstützt, kopiere das Modul femsolver/elmer/equations/elasticity.py. Wenn es nicht-lineare Schlüsselwörter unterstützt, kopiere auch femsolver/elmer/equations/heat.py. Die Strömungsgleichung in Elmer ist eine potenziell nichtlineare Gleichung. Das bedeutet, dass wir unsere Arbeit auf heat.py stützen werden.

Keywords

  • If the new equation only supports keywords for linear systems copy the femsolver/elmer/equations/elasticity.py module.
  • If the new equation supports keywords for both linear and non-linear systems, copy femsolver/elmer/equations/heat.py.

The flow equation in Elmer is a potentially non-linear equation. This means that we are going to base our work on heat.py.

Editing files

Nach dem Kopieren von heat.py nach flow.py passe - das Namensargument der Funktion create module an, - das Typattribut der Klasse Proxy, - die Basisklassen der Klassen Proxy und ViewProxy, - und die über die Funktion obj.addProperty(..) hinzugefügten Eigenschaften an die von der Gleichung benötigten an.

def create(doc, name="'''Flow'''"):
    return femutils.createObject(
        doc, name, Proxy, ViewProxy)

class Proxy(nonlinear.Proxy, equationbase.'''Flow'''Proxy):

    Type = "Fem::EquationElmer'''Flow'''"

    def __init__(self, obj):
        super(Proxy, self).__init__(obj)
        obj.Priority = 10

class ViewProxy(nonlinear.ViewProxy, equationbase.'''Flow'''ViewProxy):
    pass

Then you need to change the properties added via the obj.addProperty(..) function to those needed by the equation.

Zum Zeitpunkt des Schreibens dieses Tutoriums hat die Elmer Fliessgleichung keine besonderen Eigenschaften. Siehe Elmer Elastizitätsgleichung für ein Beispiel mit Eigenschaften.

Schließlich muss man eine makeEquationStatcurrent Definition in ObjectsFem.py durch Duplizieren eines verfügbaren Eintrags registrieren.

Zu guter Letzt registriere die neue Moduldatei (flow.py) in src/Mod/Fem/CMakeLists.txt auf die in FEM Modul erweitern beschriebene Weise. Die passenden Listen lassen sich leicht finden, indem man nach vorhandenen Gleichungsmoduldateien von Elmer sucht.

Löser Objekt erweitern

In diesem Schritt werden wir die folgenden Dateien modifizieren:

  • src/Mod/Fem/femsolver/elmer/solver.py

Gerade jetzt haben wir FreeCAD darauf aufmerksam gemacht, dass es einen neuen Gleichungstyp gibt, und sogar einen Befehl hinzugefügt, der diese Gleichung dem ausgewählten Löserobjekt hinzufügt. Wir haben auch ein konkretes Gleichungsobjekt für Elmer implementiert. Was jetzt noch zu tun bleibt, ist die Verbindung zwischen Elmer und der Strömungsgleichung herzustellen. Dies muss direkt im Elmer Lösungsobjekt erfolgen.

Registriere das Modul, in dem wir gerade unser neues Gleichungsobjekt (flow.py) implementiert haben, mit dem Gleichungsspezifizierer aus Schritt 1 ("Flow") in der _EQUATIONS Liste in elmer/solver.py.

from .equations import electrostatic
+from .equations import flow

...

_EQUATIONS = {
    "Heat": heat,
    "Elasticity": elasticity,
+    "Flow": flow,
}

Analyse Export erweitern

In diesem Schritt werden wir die folgenden Dateien modifizieren:

  • src/Mod/Fem/femsolver/elmer/writer.py

Dies ist der anspruchsvollste Teil der Umsetzung einer neuen Gleichung. Diese Datei enthält die Klasse Writer, die die Analyse in das Elmer sif Format exportiert.

Für jede unterstützte Gleichung gibt es eine Reihe von Methoden für den Export der jeweiligen Gleichung. Kopiere einfach alle von einer bestehenden Gleichung und passe sie an deine Bedürfnisse an. Unsere Fließgleichung verwendet die folgenden Methoden:

  • _getFlowSolver
  • _handleFlow

You need to register the _handleFlow method inside the Writer class:

class Writer(object):
...
    def write(self):
...
        self._handleFlow()

...

_handleFlow can control a series of other detailed methods. Our flow equation uses the following detailed methods:

  • _handleFlowConstants
  • _handleFlowMaterial
  • _handleFlowInitialVelocity
  • _handleFlowBndConditions
  • _handleFlowEquation

We now finished the function part of the new equation. Next we'll connect the new equation through the GUI.

Gui tool to create an equation

We have just created a new equation class. To access it from the FEM GUI, we need to create a button and link it to the new equation class. Here is a tutorial: Add button to FEM toolbar tutorial.