Add FEM Equation Tutorial/ro: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
 
(37 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>

{{TutorialInfo
{{TutorialInfo/ro
|Topic=
|Topic=
|Level=
|Level=
Line 8: Line 9:
|Files=
|Files=
}}
}}

== Introduction ==


Î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| Extend FEM Module]] înainte de a citi acest tutorial.
Î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| Extend FEM Module]] înainte de a citi acest tutorial.
Line 13: Line 16:
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.
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.


<span id="New_equation_type"></span>
== New Equation Type ==
== Nou tip de Equation ==


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

* src/Mod/Fem/FemSolver/EquationBase.py
* src/Mod/Fem/PyGui/_CommandFemEquation.py
* {{FileName|src/Mod/Fem/femsolver/equationbase.py}}

* src/Mod/Fem/Workbench.cpp
The equation type is shared among all equation objects of the different solvers. 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.
* src/Mod/Fem/Gui/Resources/Fem.qrc

The equation type is shared among all equation objects of the different solver. Each type has a string specifier (e.g. &quot;Heat&quot;) 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 {{Incode|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 {{Incode|getIcon(self)}} of the view proxy.


{{Code|code=
First add the new equation to the EquationBase module. Each equation requires two classes. A document proxy and a view proxy. Just copy-paste them from an existing equation type and adjust the icon path inside getIcon(self) of the view proxy.
<pre>class FlowProxy(BaseProxy):
class FlowProxy(BaseProxy):
pass
pass


class FlowViewProxy(BaseViewProxy):
class FlowViewProxy(BaseViewProxy):
def getIcon(self):
def getIcon(self):
return &quot;:/icons/fem-equation-flow.svg&quot;</pre>
return ":/icons/FEM_EquationFlow.svg"
}}
Those two classes will later be used as base classes for the elmer specific equation classes. In addition to those base classes we have to create a new command class that adds a flow equation to the selected solver object. Additionally, the new .svg has to be registered with <file>icons/fem-equation-flow.svg</file> in Fem.qrc.


<span id="New_Elmer&#039;s_equation_object"></span>
The command should be added to the _CommandFemEquation module. Just copy an existing command and adjust the icon, menu text and tool-tip in GetResources(self) and the specifier in getSpecifier(self). We will need the specifier again later in the tutorial. Don't forget to register the command at the bottom of the module file by using the addCommand(...) method.
== Obiectul Elmers FEM Solver Equation ==
<pre>class Flow(_Base):


În acest pas vom modifica următoarele fișiere:
def getSpecifier(self):
return &quot;Flow&quot;


* {{FileName|src/Mod/Fem/femsolver/elmer/equations/flow.py}}
def GetResources(self):
return {
'Pixmap': 'fem-equation-flow',
'MenuText': &quot;Flow Equation&quot;,
'ToolTip': &quot;Add flow equation to selected solver.&quot;
}


și adăugați următorul fișier nou:
Gui.addCommand('FEM_AddEquationFlow', Flow())</pre>
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.
<pre> Gui::ToolBarItem* solve = new Gui::ToolBarItem(root);
solve-&gt;setCommand(&quot;Solve&quot;);
*solve &lt;&lt; &quot;FEM_SolverCalculix&quot;
&lt;&lt; &quot;FEM_AddSolverElmer&quot;
&lt;&lt; &quot;Separator&quot;
&lt;&lt; &quot;FEM_AddEquationHeat&quot;
&lt;&lt; &quot;FEM_AddEquationElasticity&quot;
+ &lt;&lt; &quot;FEM_AddEquationFlow&quot;
&lt;&lt; &quot;Separator&quot;
&lt;&lt; &quot;FEM_SolverControl&quot;
&lt;&lt; &quot;FEM_SolverRun&quot;;</pre>
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.
<pre> Gui::MenuItem* solve = new Gui::MenuItem;
root-&gt;insertItem(item, solve);
solve-&gt;setCommand(&quot;&amp;Solve&quot;);
*solve &lt;&lt; &quot;FEM_SolverCalculix&quot;
&lt;&lt; &quot;FEM_SolverZ88&quot;
&lt;&lt; &quot;FEM_AddSolverElmer&quot;
&lt;&lt; &quot;Separator&quot;
&lt;&lt; &quot;FEM_AddEquationHeat&quot;
&lt;&lt; &quot;FEM_AddEquationElasticity&quot;
+ &lt;&lt; &quot;FEM_AddEquationFlow&quot;
&lt;&lt; &quot;Separator&quot;
&lt;&lt; &quot;FEM_SolverControl&quot;
&lt;&lt; &quot;FEM_SolverRun&quot;;</pre>


* {{FileName|src/Mod/Fem/ObjectsFem.py}}
== Elmers Equation Object ==
* {{FileName|src/Mod/Fem/CMakeLists.txt}}


Să începem cu modulul care implementează obiectul documentului. In poate fi copiat dintr-o ecuație existentă. Dacă noua ecuație acceptă numai cuvintele cheie pentru sistemele liniare FemSolver/Elmer/Equations/Elasticity.py module. În cazul în care acceptă cuvinte cheie neliniare prea copiate FemSolver/Elmer/Equations/Heat.py. Ecuația de curgere este o posibilă ecuație neliniară. Aceasta înseamnă că ne vom baza munca Heat.py.
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.


=== Keywords ===
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.

<pre>def create(doc, name=&quot;Flow&quot;):
* If the new equation only supports keywords for '''linear''' systems copy the {{Incode|femsolver/elmer/equations/elasticity.py}} module.
return FemMisc.createObject(
* If the new equation supports keywords for both '''linear''' and '''non-linear''' systems, copy {{Incode|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 {{Incode|heat.py}}.

=== Editing files ===

După copiere Heat.py to Flow.py adjust - argumentul de nume al funcției de creare a modulului, - atributul Type al clasei Proxy, - - clasele de bază ale proxy - ului și ale ViewProxy classes, - și proprietățile adăugate prin funcția obj.addProperty(..) de cele necesare ecuației.

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


class Proxy(Nonlinear.Proxy, FemEquation.FlowProxy):
class Proxy(nonlinear.Proxy, equationbase.'''Flow'''Proxy):

Type = &quot;Fem::FemEquationElmerFlow&quot;
Type = "Fem::EquationElmer'''Flow'''"

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


class ViewProxy(Nonlinear.ViewProxy, FemEquation.FlowViewProxy):
class ViewProxy(nonlinear.ViewProxy, equationbase.'''Flow'''ViewProxy):
pass</pre>
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.


Then you need to change the properties added via the {{Incode|obj.addProperty(..)}} function to those needed by the equation.
Last but not least register the new module file (Flow.py) in both CMakeLists.txt files the way descripted in [https://www.freecadweb.org/wiki/Extend_FEM_Module Extend FEM Module]. The suitable lists can be easily found by searching for existing equation modules files of elmer.


În momentul în care scrieți acest tutorial Consultați ecuația de elasticitate Elmer FEM Solver pentru un exemplu cu proprietăți.
== Extend Solver Object ==


Finally one has to register a '''makeEquationFlow''' definition in {{Incode|src/Mod/Fem/ObjectsFem.py}} by duplicating an available entry.
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.


Nu în ultimul rând, înregistrați noul fișier modul (Flow.py) în ambele fișiere CMakeLists.txt modul descris în [https://www.freecadweb.org/wiki/Extend_FEM_Module Extend FEM Module]. Listele potrivite pot fi găsite prin căutarea fișierelor de module de ecuație existente ale lui Elmer FEM Solver.
Register the module in which we just implemented our new equation object (Flow.py) with the equation specifier from step 1 (&quot;Flow&quot;) in the Proxy._EQUATIONS list in Elmer/Object.py.
<pre>_EQUATIONS = {
&quot;Heat&quot;: Equations.Heat,
&quot;Elasticity&quot;: Equations.Elasticity,
+ &quot;Flow&quot;: Equations.Flow,
}</pre>
== Extend Analysis Export ==


<span id="Extend_Solver_Object"></span>
In this step we are going to modify the following file:
== Extinderea Obiectului Solver ==
* 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.
În acest pas vom modifica următorul fișier:

* {{FileName|src/Mod/Fem/femsolver/elmer/solver.py}}

Pentru moment, FreeCAD a realizat că există un nou tip de ecuație și a adăugat o comandă care adaugă această ecuație obiectului solver selectat. Am implementat, de asemenea, un obiect de ecuații concrete pentru Elmer.Ceea ce trebuie să facem acum pentru a face legătura dintre elmer și ecuația de curgere. Acesta trebuie să se facă direct în obeictul Elmer FEM solver.

Înregistrați modulul în care am introdus noul nostru obiect de ecuații (Flow.py) wcu ecuația specificată din pasul 1(&quot;Flow&quot;) în lista Proxy._EQUATIONS în Elmer/Object.py.

{{Code|code=
from .equations import electrostatic
+from .equations import flow

...

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

<span id="Extend_writer_object"></span>
== Extensia Analizei Export ==

În acest pas vom modifica următorul fișier:

* {{FileName|src/Mod/Fem/femsolver/elmer/writer.py}}

Aceasta este cea mai pretențioasă parte a implementării unei noi ecuații. Acest fișier conține o clasă Writer care exportă analiza în format Elmer FEM Solver sif.

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:

* {{Incode|_getFlowSolver}}
* {{Incode|_handleFlow}}

You need to register the {{Incode|_handleFlow}} method inside the {{Incode|Writer}} class:

{{Code|code=
class Writer(object):
...
def write(self):
...
self._handleFlow()

...

}}

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

* {{Incode|_handleFlowConstants}}
* {{Incode|_handleFlowMaterial}}
* {{Incode|_handleFlowInitialVelocity}}
* {{Incode|_handleFlowBndConditions}}
* {{Incode|_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|Add Button to FEM Toolbar Tutorial]].
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
* _getFlowSolver
* _handleFlowConstants
* _handleFlowBndConditions
* _handleFlowInitial
* _handleFlowBodyForces
* _handleFlowMaterial
* _handleFlowEquation


[[Category:FEM{{#translation:}}]]
{{clear}}
[[Category:Developer Documentation{{#translation:}}]]

Latest revision as of 10:07, 13 January 2024

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

Introduction

Î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

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 solvers. 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"

Obiectul Elmers FEM Solver Equation

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

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

și adăugați următorul fișier nou:

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

Să începem cu modulul care implementează obiectul documentului. In poate fi copiat dintr-o ecuație existentă. Dacă noua ecuație acceptă numai cuvintele cheie pentru sistemele liniare FemSolver/Elmer/Equations/Elasticity.py module. În cazul în care acceptă cuvinte cheie neliniare prea copiate FemSolver/Elmer/Equations/Heat.py. Ecuația de curgere este o posibilă ecuație neliniară. Aceasta înseamnă că ne vom baza munca Heat.py.

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

După copiere Heat.py to Flow.py adjust - argumentul de nume al funcției de creare a modulului, - atributul Type al clasei Proxy, - - clasele de bază ale proxy - ului și ale ViewProxy classes, - și proprietățile adăugate prin funcția obj.addProperty(..) de cele necesare ecuației.

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.

În momentul în care scrieți acest tutorial Consultați ecuația de elasticitate Elmer FEM Solver pentru un exemplu cu proprietăți.

Finally one has to register a makeEquationFlow definition in src/Mod/Fem/ObjectsFem.py by duplicating an available entry.

Nu în ultimul rând, înregistrați noul fișier modul (Flow.py) în ambele fișiere CMakeLists.txt modul descris în Extend FEM Module. Listele potrivite pot fi găsite prin căutarea fișierelor de module de ecuație existente ale lui Elmer FEM Solver.

Extinderea Obiectului Solver

În acest pas vom modifica următorul fișier:

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

Pentru moment, FreeCAD a realizat că există un nou tip de ecuație și a adăugat o comandă care adaugă această ecuație obiectului solver selectat. Am implementat, de asemenea, un obiect de ecuații concrete pentru Elmer.Ceea ce trebuie să facem acum pentru a face legătura dintre elmer și ecuația de curgere. Acesta trebuie să se facă direct în obeictul Elmer FEM solver.

Înregistrați modulul în care am introdus noul nostru obiect de ecuații (Flow.py) wcu ecuația specificată din pasul 1("Flow") în lista Proxy._EQUATIONS în Elmer/Object.py.

from .equations import electrostatic
+from .equations import flow

...

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

Extensia Analizei Export

În acest pas vom modifica următorul fișier:

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

Aceasta este cea mai pretențioasă parte a implementării unei noi ecuații. Acest fișier conține o clasă Writer care exportă analiza în format Elmer FEM Solver sif.

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:

  • _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.