Add FEM Equation Tutorial/it: Difference between revisions

From FreeCAD Documentation
m (FuzzyBot moved page Add FEM equation tutorial/it to Add FEM Equation Tutorial/it without leaving a redirect: Part of translatable page "Add FEM equation tutorial")
(Created page with "In questo passaggio modificheremo il seguente file:")
 
(12 intermediate revisions by 2 users not shown)
Line 10: Line 10:
}}
}}


== Introduction ==
<span id="Introduction"></span>
== Introduzione ==


In questo tutorial aggiungeremo a FreeCAD l'equazione di flusso e implementeremo il supporto per il risolutore elmer. Prima di leggere questo tutorial è necessario aver letto e compreso il tutorial [[Extend_FEM_Module/it| Estendere il modulo FEM]].
In questo tutorial aggiungeremo a FreeCAD l'equazione di flusso e implementeremo il supporto per il risolutore elmer. Prima di leggere questo tutorial è necessario aver letto e compreso il tutorial [[Extend_FEM_Module/it| Estendere il modulo FEM]].


The task can be split into five parts:
The task can be split into five parts:
* '''New equation type'''. This step must only be done if the equation doesn't exist in FreeCAD yet (as opposed to a equation that is already in FreeCAD but not supported by the target solver).
* '''New equation type'''. This step must only be done if the equation doesn't exist in FreeCAD yet (as opposed to an equation that is already in FreeCAD but not supported by the target solver).
* '''New equation object'''. Adding a concrete document object representing the elmer specific equation.
* '''New equation object'''. Adding a concrete document object representing the Elmer-specific equation.
* '''Extend solver object'''. Adding support for the new equation to the solver object of elmer.
* '''Extend solver object'''. Adding support for the new equation to the solver object of Elmer.
* '''Extend writer object'''. Extending the analysis export of elmer to support the new equation type.
* '''Extend writer object'''. Extending the analysis export of Elmer to support the new equation type.
* '''Gui tool to create a equation'''. Access the new equation function through workbench Gui.
* '''Gui tool to create an equation'''. Access the new equation function through workbench Gui.


<span id="New_equation_type"></span>
== New equation type ==
== Nuovo tipo di equazione ==


In questo passaggio modificheremo il seguente file:
In this step we are going to modify the following file:


* {{FileName|src/Mod/Fem/femsolver/equationbase.py}}
* {{FileName|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.
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 {{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.
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=
{{Code|code=
Line 40: Line 42:
}}
}}


<span id="New_Elmer&#039;s_equation_object"></span>
== New Elmer's equation object ==
== Nuovo oggetto equazione di Elmer ==


In this step we are going to implement the document object. We need to add a new {{Incode|flow.py}} file at:
In questo passaggio implementeremo l'oggetto documento. Dobbiamo aggiungere un nuovo file {{Incode|flow.py}} in:


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


e modificare i seguenti file:
and modify the following files:


* {{FileName|src/Mod/Fem/ObjectsFem.py}}
* {{FileName|src/Mod/Fem/ObjectsFem.py}}
Line 60: Line 63:
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}}.
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}}.


<span id="Editing_files"></span>
=== Editing files ===
=== Modifica dei file ===


After copying {{Incode|heat.py}} to {{Incode|flow.py}}, adjust {{Incode|flow.py}} in these locations:
After copying {{Incode|heat.py}} to {{Incode|flow.py}}, adjust {{Incode|flow.py}} in these locations:
Line 87: Line 91:
Then you need to change the properties added via the {{Incode|obj.addProperty(..)}} function to those needed by the equation.
Then you need to change the properties added via the {{Incode|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.
At the moment of writing this tutorial Elmer flow equation doesn't have any special properties. See the Elmer elasticity equation for an example with properties.


Finally one has to register a '''makeEquationFlow''' definition in {{Incode|src/Mod/Fem/ObjectsFem.py}} by duplicating an available entry.
Finally one has to register a '''makeEquationFlow''' definition in {{Incode|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 ({{Incode|flow.py}}) in {{Incode|src/Mod/Fem/CMakeLists.txt}} the way described 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.
FreeCAD uses '''make''' to build the program. So we need to register the new module file ({{Incode|flow.py}}) in {{Incode|src/Mod/Fem/CMakeLists.txt}} the way described in [https://www.freecadweb.org/wiki/Extend_FEM_Module Extend FEM Module]. The suitable lists can be easily found by searching for existing equation module files of Elmer.


<span id="Extend_Solver_Object"></span>
== Extend Solver Object ==
== Estendere l'oggetto risolutore ==


In questo passaggio modificheremo il seguente file:
In this step we are going to modify the following file:


* {{FileName|src/Mod/Fem/femsolver/elmer/solver.py}}
* {{FileName|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.
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. What's left to do now is to make the connection between Elmer and the flow equation. This must be done directly in the Elmer solver object.


Register the module in which we just implemented our new equation object ({{Incode|flow.py}}) with the equation specifier from step 1 ("Flow") in the {{Incode|_EQUATIONS}} list in {{Incode|elmer/solver.py}}.
Register the module in which we just implemented our new equation object ({{Incode|flow.py}}) with the equation specifier from step 1 ("Flow") in the {{Incode|_EQUATIONS}} list in {{Incode|elmer/solver.py}}.
Line 116: Line 121:
}}
}}


<span id="Extend_writer_object"></span>
== Extend writer object ==
== Estendere l'oggetto writer ==


In questo passaggio modificheremo il seguente file:
In this step we are going to modify the following file:


* {{FileName|src/Mod/Fem/femsolver/elmer/writer.py}}
* {{FileName|src/Mod/Fem/femsolver/elmer/writer.py}}
Line 124: Line 130:
This file contains the {{Incode|Writer}} class which exports the analysis into Elmer SIF format.
This file contains the {{Incode|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.
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.


* {{Incode|_getFlowSolver}}
* {{Incode|_getFlowSolver}}
Line 150: Line 156:
* {{Incode|_handleFlowEquation}}
* {{Incode|_handleFlowEquation}}


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


<span id="Gui_tool_to_create_an_equation"></span>
== Gui tool to create an equation ==
== Strumento Gui per creare un'equazione ==


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]].
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]].

Latest revision as of 14:00, 28 April 2024

Tutorial
Argomento
Aggiungere equazioni FEM
Livello di difficoltà
Tempo di esecuzione
Autori
M42kus
Versione di FreeCAD
Files di esempio
Vedere anche
Nessuno

Introduzione

In questo tutorial aggiungeremo a FreeCAD l'equazione di flusso e implementeremo il supporto per il risolutore elmer. Prima di leggere questo tutorial è necessario aver letto e compreso il tutorial Estendere il modulo FEM.

The task can be split into five parts:

  • New equation type. This step must only be done if the equation doesn't exist in FreeCAD yet (as opposed to an equation that is already in FreeCAD but not supported by the target solver).
  • New equation object. Adding a concrete document object representing the Elmer-specific equation.
  • Extend solver object. Adding support for the new equation to the solver object of Elmer.
  • Extend writer object. Extending the analysis export of Elmer to support the new equation type.
  • Gui tool to create an equation. Access the new equation function through workbench Gui.

Nuovo tipo di equazione

In questo passaggio modificheremo il seguente 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"

Nuovo oggetto equazione di Elmer

In questo passaggio implementeremo l'oggetto documento. Dobbiamo aggiungere un nuovo file flow.py in:

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

e modificare i seguenti file:

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

Let's start with adding the new flow.py file. This file can be copied from an existing equation.

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.

Modifica dei file

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 the Proxy 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 the 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 module files of Elmer.

Estendere l'oggetto risolutore

In questo passaggio modificheremo il seguente 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. What's left to do now is to make the connection between Elmer and the flow equation. This must be done directly in the 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,
}

Estendere l'oggetto writer

In questo passaggio modificheremo il seguente 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.

Strumento Gui per creare un'equazione

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.