Poradnik: Dodawanie równań w środowisku MES
Ćwiczenie |
Temat |
---|
Dodawanie równań MES |
Poziom trudności |
Zaawansowany |
Czas wykonania |
1 dzień |
Autorzy |
JohnWang |
Wersja FreeCAD |
0.19 |
Pliki z przykładami |
Nie dołączono |
Zobacz również |
- |
Wprowadzenie
W tym poradniku dodamy równanie Flow (przepływu) do FreeCAD i zaimplementujemy wsparcie dla solvera Elmer. Upewnij się, że przeczytałeś i zrozumiałeś stronę Rozszerzenie modułu MES przed przejściem do tego poradnika.
Zadanie można podzielić na pięć części:
- Nowy typ równania. Ten krok musi być wykonany tylko jeśli równanie nie istnieje jeszcze we FreeCAD (w przeciwieństwie do równania, które jest już we FreeCAD, ale nie jest wspierane przez docelowy solver).
- Nowy obiekt równania. Dodawanie konkretnego obiektu dokumentu reprezentującego konkretne równanie solvera Elmer.
- Rozszerz obiekt solvera. Dodawanie wsparcia dla nowego równania do obiektu solvera Elmer.
- Rozszerz obiekt zapisujący równania. Rozszerzenie eksportu do solvera Elmer o wsparcie dla nowego typu równania.
- Narzędzie w GUI do tworzenia równania. Dostęp do funkcji nowego równania z poziomu GUI środowiska pracy MES.
Nowy typ równania
W tym kroku zmodyfikujemy następujący plik:
- src/Mod/Fem/femsolver/equationbase.py
Typ równania jest dzielony przez wszystkie obiekty równań różnych solverów. Każdy typ ma ciąg określający (np. "Heat" - ciepło) i dedykowane polecenie dodające równanie do wybranego solvera. To upraszcza GUI, ponieważ mamy tylko jeden przycisk dla równania ciepła, z którego korzystają wszystkie wspierane solvery.
Najpierw dodaj nowe równanie do modułu equationbase.py
. Każde równanie wymaga dwóch klas. Proxy dokumentu i proxy widoku. Te dwie klasy będą później używane jako klasy bazowe dla konkretnych klas równania Elmer. Po prostu skopiuj i wklej je z istniejącego typu równania i dostosuj ścieżkę ikony w getIcon(self)
proxy widoku.
class FlowProxy(BaseProxy):
pass
class FlowViewProxy(BaseViewProxy):
def getIcon(self):
return ":/icons/FEM_EquationFlow.svg"
Nowy obiekt równania solvera Elmer
W tym kroku zaimplementujemy obiekt dokumentu. Musimy dodać nowy plik flow.py
w:
- src/Mod/Fem/femsolver/elmer/equations/flow.py
i zmodyfikować następujące pliki:
- src/Mod/Fem/ObjectsFem.py
- src/Mod/Fem/CMakeLists.txt
Zacznijmy od dodania nowego pliku flow.py
. Ten plik można skopiować z istniejącego równania.
Słowa kluczowe
- Jeśli nowe równanie wspiera tylko słowa kluczowe dla układów liniowych (linear) to skopiuj moduł
femsolver/elmer/equations/elasticity.py
. - Jeśli nowe równanie wspiera słowa kluczowe dla układów liniowych (linear) i nieliniowych (non-linear) to skopiuj
femsolver/elmer/equations/heat.py
.
Równanie przepływu w Elmer jest potencjalnie nieliniowym równanie. Oznacza to, że oprzemy naszą pracę na heat.py
.
Editing files
After copying heat.py
to flow.py
, adjust flow.py
in these locations:
- the name argument of the
create
module function, - the base classes of the
Proxy
class, - the
Type
attribute of theProxy
class, - the
ViewProxy
classes.
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.
At the moment of writing this tutorial Elmer flow equation doesn't have any special properties. See Elmer elasticity equation for an example with properties.
Finally one has to register a makeEquationFlow definition in src/Mod/Fem/ObjectsFem.py
by duplicating an available entry.
FreeCAD uses make to build the program. So we need to register the new module file (flow.py
) in src/Mod/Fem/CMakeLists.txt
the way described in Extend FEM Module. The suitable lists can be easily found by searching for existing equation modules files of Elmer.
Extend Solver Object
In this step we are going to modify the following file:
- src/Mod/Fem/femsolver/elmer/solver.py
Right now we made FreeCAD aware that there is a new type of equation and even added a command that adds this equation to the selected solver object. We also implemented a concrete equation object for Elmer. Whats left to do now is to make the connection between Elmer and the flow equation. This must be done directly in Elmer solver object.
Register the module in which we just implemented our new equation object (flow.py
) with the equation specifier from step 1 ("Flow") in the _EQUATIONS
list in elmer/solver.py
.
from .equations import electrostatic
+from .equations import flow
...
_EQUATIONS = {
"Heat": heat,
"Elasticity": elasticity,
+ "Flow": flow,
}
Extend writer object
In this step we are going to modify the following file:
- src/Mod/Fem/femsolver/elmer/writer.py
This file contains the Writer
class which exports the analysis into Elmer SIF format.
For every supported equation there are two main methods handling the export of the respective equation. Just copy all of them from an existing equation and adjust them to your needs.
_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.