Add FEM Equation Tutorial/ro: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
Line 116: Line 116:
This is the most demaning part of implementing a new equation. This file contains a Writer class which exports the analysis into elmers sif format.
This is the most demaning part of implementing a new equation. This file contains a Writer class which exports the analysis into elmers sif format.


Pentru fiecare ecuație suportată există o serie de metode de manipulare a exportului ecuației respective. Trebuie doar să copiați toate ecuațiile existente și să le ajustați la nevoile dvs. Ecuația fluxului nostru folosește următoarele metode:
For every supported equation there are a series of methods handling the export of the respective equation. Just copy all of them from an existing equation and adjust them to your needs. Our Flow equation uses the following methods:
* _handleFlow
* _handleFlow
* _getFlowSolver
* _getFlowSolver

Revision as of 08:16, 6 September 2018

Tutorial
Topic
Level
Time to complete
Authors
M42kus
FreeCAD version
Example files
See also
None

În acest tutorial vom adăuga ecuația de flux la FreeCAD și vom implementa suport pentru Elmer FEM Solver. Asigurați-vă că ați citit și ați înțeles Extend FEM Module înainte de a citi acest tutorial.

Sarcina poate fi împărțită în patru părți. Primul pas este de a face bancul de lucru FEM conștient de un nou tip de ecuație. Această etapă ar trebui efectuată numai dacă ecuația nu există în fluxul FreeCAD (spre deosebire de ecuația care există deja în FreeCAD, dar nu este suportată de solverul țintă). Al doilea pas este de a adăuga un obiect tip document concret la ecuația specifică a lui Elmer FEM Solver. Al treilea pas este să adăugăm sprijin pentru noua ecuație obiectului solver al lui Elmer. După ce analiza Elmer trebuie extinsă pentru a susține noul tip de ecuație.

Nou tip de Equation

În acest pas vom modifica următoarele fișiere:

  • src/Mod/Fem/FemSolver/EquationBase.py
  • src/Mod/Fem/PyGui/_CommandFemEquation.py
  • src/Mod/Fem/Workbench.cpp
  • src/Mod/Fem/Gui/Resources/Fem.qrc

Tipul de ecuație este împărțit între toate obiectele de ecuații ale solverului diferit. Fiecare tip are un șir specificat(e.g. "Heat") și o comandă dedicată care adaugă ecuația la solverul selectat. Acest lucru permite o simplă interfață grafică în care avem doar un buton pentru ecuația căldurii, care este folosit pentru toți solverii suportați.

Mai întâi adăugați noua ecuație la modulul EquationBase. Fiecare ecuație necesită două clase. Un document proxy și vizualizare proxy. Doar faceți copy/paste dintr-un tip existent de ecuație și ajustați calea iconiței din interiorul getIcon(self) a proxy-ului de vizualizare.

class FlowProxy(BaseProxy):
    pass

class FlowViewProxy(BaseViewProxy):
    def getIcon(self):
        return ":/icons/fem-equation-flow.svg"

Aceste două clase vor fi folosite pentru clasele de ecuații specifice Elmer FEM Solver. În plus față de aceste clase de bază avem o nouă comandă care adaugă o ecuație de flux la obiectul solver selectat. În plus, noul .svg trebuie să fie înregistrat cu <file>icons/fem-equation-flow.svg</file> in Fem.qrc.

Comanda trebuie adăugată la the_CommandFemEquation module. Trebuie doar să copiați o comandă existentă și să ajustați iconița, textul meniului și butonul de instrucțiuni din GetResources(self) și specificatorul în getSpecifier(self). Va trebui să specificăm din nou mai târziu în tutorial. Nu uitați să înregistrați în josul fișierului modulului utilizând metoda addCommand (...).

class Flow(_Base):

    def getSpecifier(self):
        return "Flow"

    def GetResources(self):
        return {
            'Pixmap': 'fem-equation-flow',
            'MenuText': "Flow Equation",
            'ToolTip': "Add flow equation to selected solver."
        }

Gui.addCommand('FEM_AddEquationFlow', Flow())

Our newly created command still needs to be made accessable via the GUI of the FEM workbench. To add it to the toolbar search for the following code snippet in Workbench.cpp and add the new command to the rest of the equation commands.

 Gui::ToolBarItem* solve = new Gui::ToolBarItem(root);
 solve->setCommand("Solve");
 *solve << "FEM_SolverCalculix"
       << "FEM_AddSolverElmer"
       << "Separator"
       << "FEM_AddEquationHeat"
       << "FEM_AddEquationElasticity"
 +      << "FEM_AddEquationFlow"
       << "Separator"
       << "FEM_SolverControl"
       << "FEM_SolverRun";

We are also going to add the flow equation command to the solve menu of the FEM workbench. To do this insert our equation into the following code snippet in Workbench.cpp.

 Gui::MenuItem* solve = new Gui::MenuItem;
 root->insertItem(item, solve);
 solve->setCommand("&Solve");
 *solve << "FEM_SolverCalculix"
        << "FEM_SolverZ88"
        << "FEM_AddSolverElmer"
        << "Separator"
        << "FEM_AddEquationHeat"
        << "FEM_AddEquationElasticity"
 +       << "FEM_AddEquationFlow"
        << "Separator"
        << "FEM_SolverControl"
        << "FEM_SolverRun";

Elmers Equation Object

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

  • src/Mod/Fem/CMakeLists.txt
  • src/Mod/Fem/App/CMakeLists.txt

and add the following new file:

  • src/Mod/Fem/FemSolver/Elmer/Equations/Flow.py

Lets start with the module that implements the document object. In can be copied from an existing equation. If the new equation only supports keywords for linear systems copy the FemSolver/Elmer/Equations/Elasticity.py module. If it supports non-linear keywords too 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.

After copying Heat.py to Flow.py adjust - the name argument of the create module function, - the Type attribute of the Proxy class, - the base classes of the Proxy and the ViewProxy classes, - and the properties added via the obj.addProperty(..) function to those needed by the equation.

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

class Proxy(Nonlinear.Proxy, FemEquation.FlowProxy):
    Type = "Fem::FemEquationElmerFlow"
    def __init__(self, obj):
        super(Proxy, self).__init__(obj)
        obj.Priority = 10

class ViewProxy(Nonlinear.ViewProxy, FemEquation.FlowViewProxy):
    pass

At the moment of writing this tutorial elmers flow equation doesn't have any special properties. See elmers elasticity equation for an example with properties.

Last but not least register the new module file (Flow.py) in both CMakeLists.txt files the way descripted 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/Object.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 it to make the connection beween elmer and the flow equation. This must be done directely in elmers 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 Proxy._EQUATIONS list in Elmer/Object.py.

_EQUATIONS = {
    "Heat": Equations.Heat,
    "Elasticity": Equations.Elasticity,
+    "Flow": Equations.Flow,
}

Extend Analysis Export

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

  • src/Mod/Fem/FemSolver/Elmer/Writer.py

This is the most demaning part of implementing a new equation. This file contains a Writer class which exports the analysis into elmers sif format.

Pentru fiecare ecuație suportată există o serie de metode de manipulare a exportului ecuației respective. Trebuie doar să copiați toate ecuațiile existente și să le ajustați la nevoile dvs. Ecuația fluxului nostru folosește următoarele metode:

  • _handleFlow
  • _getFlowSolver
  • _handleFlowConstants
  • _handleFlowBndConditions
  • _handleFlowInitial
  • _handleFlowBodyForces
  • _handleFlowMaterial
  • _handleFlowEquation