Extend FEM Module/it: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 9: Line 9:
}}
}}


<div class="mw-translate-fuzzy">
L'ambiente FEM supporta già un sacco di vincoli diversi e alcuni solutori. Nonostante ciò spesso si ha bisogno di vincoli non ancora supportati da FreeCAD. Questa pagina è il punto di partenza per una serie di esercitazioni e di altre risorse che descrivono come estendere l'ambiente FEM utilizzando la struttura esistente. Anche se questa serie può rivelarsi utile per gli sviluppatori di software, l'idea è di permettere agli utenti di FEM che hanno un po' di interesse per la codifica in Python di aggiungere le cose di cui hanno bisogno.
L'ambiente FEM supporta già un sacco di vincoli diversi e alcuni solutori. Nonostante ciò spesso si ha bisogno di vincoli non ancora supportati da FreeCAD. Questa pagina è il punto di partenza per una serie di esercitazioni e di altre risorse che descrivono come estendere l'ambiente FEM utilizzando la struttura esistente. Anche se questa serie può rivelarsi utile per gli sviluppatori di software, l'idea è di permettere agli utenti di FEM che hanno un po' di interesse per la codifica in Python di aggiungere le cose di cui hanno bisogno.
</div>


Aggiungere nuovi vincoli, equazioni o solutori è per lo più un lavoro di routine. Ma farlo per la prima volta non è così facile come potrebbe sembrare. È utile conoscere i seguenti argomenti:
Aggiungere nuovi vincoli, equazioni o solutori è per lo più un lavoro di routine. Ma farlo per la prima volta non è così facile come potrebbe sembrare. È utile conoscere i seguenti argomenti:


<div class="mw-translate-fuzzy">
* Script Python in FreeCAD.
* Script Python in FreeCAD.
** [[Python_scripting_tutorial/it|Tutorial sugli script di FreeCAD]]
** [[Python_scripting_tutorial/it|Tutorial sugli script di FreeCAD]]
Line 20: Line 23:
* Una solida conoscenza del risolutore per il quale devono essere aggiunti nuovi oggetti (ad es. Calculix) è importante.
* Una solida conoscenza del risolutore per il quale devono essere aggiunti nuovi oggetti (ad es. Calculix) è importante.
* Una conoscenza di base dei sistemi di compilazione, in particolare cmake (sistema di compilazione utilizzato da FreeCAD)
* Una conoscenza di base dei sistemi di compilazione, in particolare cmake (sistema di compilazione utilizzato da FreeCAD)
</div>


== Sistema di costruzione (cmake) ==
== Sistema di costruzione (cmake) ==


The build system must be modified regardless of which objects shall be added o the FEM workbench. Every python module (file) must be registerd. The FEM workbench even requries every new python module to be registerd twice. Once in Mod/Fem/CMakeLists.txt and a secound time in Mod/Fem/App/CMakeLists.txt. This is true regaredless of the type of the python module (gui or non-gui). Where exactely the module must be inserted depends on the role of the module. Solver, equations and constraints all use different lists. Searching for similar files and inserting the new file in the same list works most of the time.
The build system must be modified regardless of which objects shall be added o the FEM workbench. Every python module (file) must be registered. The FEM workbench requires every new python module to be registered in {{incode|Mod/Fem/CMakeLists.txt}}. This is true regardless of the type of the python module (GUI or non-GUI). Where exactly the module must be inserted depends on the role of the module. Solver, equations and constraints all use different lists. Searching for similar files and inserting the new file in the same list works most of the time.


<div class="mw-translate-fuzzy">
Ad esempio, proviamo ad aggiungere un nuovo vincolo di pressione. Un nuovo vincolo richiede almeno i seguenti nuovi moduli: FemConstraint<name>.py, ViewProviderFemConstraint<name>.py, CommandFemConstraint<name>.py. Questi tre file devono essere aggiunti a CMakeLists.txt ed anche a App/CMakeLists.txt.
Ad esempio, proviamo ad aggiungere un nuovo vincolo di pressione. Un nuovo vincolo richiede almeno i seguenti nuovi moduli: FemConstraint<name>.py, ViewProviderFemConstraint<name>.py, CommandFemConstraint<name>.py. Questi tre file devono essere aggiunti a CMakeLists.txt ed anche a App/CMakeLists.txt.
</div>


'''Mod/Fem/CMakeLists.txt'''
'''Mod/Fem/CMakeLists.txt'''


<pre>INSTALL(
<pre>
SET(FemObjects_SRCS
FILES
PyObjects/__init__.py
femobjects/__init__.py
femobjects/base_fempythonobject.py
PyObjects/_FemConstraintSelfWeight.py
femobjects/constraint_bodyheatsource.py
PyObjects/_FemConstraintBodyHeatFlux.py
femobjects/constraint_electrostaticpotential.py
PyObjects/_FemConstraintFlowVelocity.py
femobjects/constraint_flowvelocity.py
+ PyObjects/_FemConstraintFlowPressure.py
femobjects/constraint_initialflowvelocity.py
PyObjects/_FemElementFluid1D.py
+ femobjects/constraint_initialflowpressure.py
PyObjects/_FemElementGeometry1D.py
femobjects/constraint_selfweight.py
PyObjects/_FemElementGeometry2D.py
...
...
femobjects/solver_ccxtools.py
DESTINATION
Mod/Fem/PyObjects
)
)
...

SET(FemGuiViewProvider_SRCS
INSTALL(
femviewprovider/__init__.py
FILES
femviewprovider/view_base_femconstraint.py
PyGui/FemCommands.py
femviewprovider/view_base_femobject.py
PyGui/__init__.py
femviewprovider/view_constraint_bodyheatsource.py
PyGui/_CommandFemSolverElmer.py
femviewprovider/view_constraint_electrostaticpotential.py
PyGui/_CommandFemEquation.py
femviewprovider/view_constraint_flowvelocity.py
PyGui/_CommandFemConstraintBodyHeatFlux.py
+ femviewprovider/view_constraint_flowpressure.py
PyGui/_CommandFemConstraintFlowVelocity.py
femviewprovider/view_constraint_initialflowvelocity.py
+ PyGui/_CommandFemConstraintFlowPressure.py
femviewprovider/view_constraint_selfweight.py
PyGui/_CommandFemAnalysis.py
...
PyGui/_CommandFemElementFluid1D.py
femviewprovider/view_solver_ccxtools.py
PyGui/_CommandFemElementGeometry1D.py
...
PyGui/_ViewProviderFemConstraintSelfWeight.py
PyGui/_ViewProviderFemConstraintBodyHeatFlux.py
PyGui/_ViewProviderFemConstraintFlowVelocity.py
+ PyGui/_ViewProviderFemConstraintFlowPressure.py
PyGui/_ViewProviderFemElementFluid1D.py
PyGui/_ViewProviderFemElementGeometry1D.py
PyGui/_ViewProviderFemElementGeometry2D.py
...
DESTINATION
Mod/Fem/PyGui
)</pre>
'''Mod/Fem/App/CMakeLists.txt'''

<pre>SET(FemObjectsScripts_SRCS
PyObjects/__init__.py
PyObjects/_FemConstraintSelfWeight.py
PyObjects/_FemConstraintBodyHeatFlux.py
PyObjects/_FemConstraintFlowVelocity.py
+ PyObjects/_FemConstraintFlowPressure.py
PyObjects/_FemElementFluid1D.py
PyObjects/_FemElementGeometry1D.py
PyObjects/_FemElementGeometry2D.py
PyObjects/_FemMaterialMechanicalNonlinear.py
PyObjects/_FemMeshBoundaryLayer.py
PyObjects/_FemMeshGmsh.py
PyObjects/_FemMeshGroup.py
PyObjects/_FemMeshResult.py
PyObjects/_FemMeshRegion.py
PyObjects/_FemResultMechanical.py
PyObjects/_FemSolverCalculix.py
PyObjects/_FemMaterial.py
)
)
</pre>


SET(FemGuiScripts_SRCS
PyGui/FemCommands.py
PyGui/__init__.py
PyGui/_CommandFemAnalysis.py
PyGui/_CommandFemConstraintSelfWeight.py
PyGui/_CommandFemConstraintBodyHeatFlux.py
PyGui/_CommandFemConstraintFlowVelocity.py
+ PyGui/_CommandFemConstraintFlowPressure.py
PyGui/_CommandFemElementFluid1D.py
PyGui/_CommandFemElementGeometry1D.py
...
PyGui/_ViewProviderFemConstraintBodyHeatFlux.py
PyGui/_ViewProviderFemConstraintFlowVelocity.py
+ PyGui/_ViewProviderFemConstraintFlowPressure.py
PyGui/_ViewProviderFemElementFluid1D.py
PyGui/_ViewProviderFemElementGeometry1D.py
PyGui/_ViewProviderFemElementGeometry2D.py
...
)</pre>


== Organizzazione del codice sorgente ==
== Organizzazione del codice sorgente ==


<div class="mw-translate-fuzzy">
Per organizzare il codice Python il modulo FEM usa un approccio simile a quello usato per il codice C++ in FreeCAD. Il modulo è diviso in due pacchetti. PyObjects, che contiene tutti i proxy Python non-gui come gli oggetti del documento e PyGui che contiene tutto ciò che è collegato come proxy python per il provider di visualizzazione, i pannelli delle attività, i file ui e i comandi.
Per organizzare il codice Python il modulo FEM usa un approccio simile a quello usato per il codice C++ in FreeCAD. Il modulo è diviso in due pacchetti. PyObjects, che contiene tutti i proxy Python non-gui come gli oggetti del documento e PyGui che contiene tutto ciò che è collegato come proxy python per il provider di visualizzazione, i pannelli delle attività, i file ui e i comandi.
</div>


<div class="mw-translate-fuzzy">
Un pacchetto non segue questo modello: FemSolver. È posizionato allo stesso livello di PyObjects e PyGui (src/Mod/Fem/FemSolver). Il pacchetto contiene il solutore con i pacchetti relativi all'equazione ed ai moduli ed è organizzato nel seguente modo:
Un pacchetto non segue questo modello: FemSolver. È posizionato allo stesso livello di PyObjects e PyGui (src/Mod/Fem/FemSolver). Il pacchetto contiene il solutore con i pacchetti relativi all'equazione ed ai moduli ed è organizzato nel seguente modo:
</div>
<pre>.FemSolver
<pre>.femsolver
.FemSolver.Elmer
.femsolver.elmer
.FemSolver.Elmer.Equations
.femsolver.elmer.equations
.FemSolver.Calculix
.femsolver.calculix
.FemSolver.Calculix.Equations
.femsolver.calculix.equations
.FemSolver.Z88
.femsolver.z88
.FemSolver.Z88.Equations</pre>
.femsolver.z88.equations</pre>


== Solutore ==
== Solutore ==


In FreeCAD a solver can be split into two parts:
In FreeCAD a solver can be split into two parts. One is the document object used by the user to interact with the solver. Though it solver parameter can be set and it is also used to control the solving process. The other one are the so called tasks of a solver. The solving process is split into those tasks, namely: check, prepare, solve and results. Those do the actual work of exporting the analysis into a format understood by the solver executable, starting the executable and loading the results back into FreeCAD.
* One is the document object used by the user to interact with the solver. Though it solver parameter can be set and it is also used to control the solving process.
* The other one are the so called tasks of a solver. The solving process is split into those tasks, namely: ''check, prepare, solve and results''. Those do the actual work of exporting the analysis into a format understood by the solver executable, starting the executable and loading the results back into FreeCAD.


<div class="mw-translate-fuzzy">
La maggior parte dei file relativi a un solver si trovano in un sottopacchetto del pacchetto FemSolver (e.g. FemSolver.Elmer). La seguente lista elenca tutti i file relativi all'implementazione di un risolutore. Questi sono i file che devono essere copiati e modificati per aggiungere il supporto per un nuovo risolutore in FreeCAD.
La maggior parte dei file relativi a un solver si trovano in un sottopacchetto del pacchetto FemSolver (e.g. FemSolver.Elmer). La seguente lista elenca tutti i file relativi all'implementazione di un risolutore. Questi sono i file che devono essere copiati e modificati per aggiungere il supporto per un nuovo risolutore in FreeCAD.
</div>


* '''FemSolver/Elmer/Object.py:''' Document object visible in the tree-view. Implemented in python via a document proxy and view proxy.
* '''femsolver/elmer/Object.py:''' Document object visible in the tree-view. Implemented in python via a document proxy and view proxy.
* '''FemSolver/Elmer/Tasks.py:''' Module containing one task class per task required for a solver implementation. Those tasks divide the process of solving a analysis into the following steps: check, prepare, solve, results.
* '''femsolver/elmer/Tasks.py:''' Module containing one task class per task required for a solver implementation. Those tasks divide the process of solving a analysis into the following steps: check, prepare, solve, results.
* '''PyGui/_CommandFemElmer.py:''' Adds the solver document object to the active document. Required to access the solver object from the GUI.
* '''femcommands/commands.py:''' Adds the solver document object to the active document. Required to access the solver object from the GUI.


== Equazioni ==
== Equazioni ==


<div class="mw-translate-fuzzy">
Un'equazione rappresenta una particolare fisica che deve essere considerata quando si risolve l'analisi (ad esempio flusso, calore). Non tutti i solutori in FreeCAD supportano le equazioni. Le equazioni sono rappresentate dagli oggetti figlio del corrispondente oggetto del risolutore. Nella vista ad albero questo assomiglia così:
Un'equazione rappresenta una particolare fisica che deve essere considerata quando si risolve l'analisi (ad esempio flusso, calore). Non tutti i solutori in FreeCAD supportano le equazioni. Le equazioni sono rappresentate dagli oggetti figlio del corrispondente oggetto del risolutore. Nella vista ad albero questo assomiglia così:
</div>


* elmer-solver
* ElmerSolver
** Elasticity
** elasticity
** Heat
** heat
** Flow
** flow
** electrostatics


Most solver specific options (max iterations, method of solving, etc) are set via the equation objects. One consequence of this is that each solver must have it's own implementation of &quot;the same&quot; equation. Calculix would have a different Heat object that Elmer. To avoid having multiple buttons for the same physics in the GUI each solver object adds it's equations itself.
Most solver specific options (e.g. max. iterations, method of solving, etc) are set via the equation objects. One consequence of this is that each solver must have it's own implementation of &quot;the same&quot; equation. CalculiX would have a different Heat-object that Elmer. To avoid having multiple buttons for the same physics in the GUI each solver object adds it's equations itself.


The actual implementation can be split into the generic and the solver specific part. The generic part can be found in the FemSolver.EquationBase module. The solver specific part resides inside individual Equations sub-packages of the solver packages (e.g. FemSolver/Elmer/Equations).
The actual implementation can be split into the generic and the solver specific part. The generic part can be found in the {{incode|femsolver.equationbase}} module. The solver specific part resides inside individual Equations sub-packages of the solver packages (e.g. {{incode|femsolver/elmer/equations}}).


Adding a new equations to elmer should be very easy. For newcomers there exists a tutorial which shows how to add a new equation to elmer by adding the existing elasticity solver to FreeCAD: [[Add_FEM_Equation_Tutorial|Add FEM Equation Tutorial]].
Adding a new equations to Elmer should be very easy. For newcomers there exists a tutorial which shows how to add a new equation to Elmer by adding the existing elasticity solver to FreeCAD: [[Add_FEM_Equation_Tutorial|Add FEM Equation Tutorial]].


== Vincoli ==
== Vincoli ==
Line 152: Line 118:
Constraints define boundary conditions for the problem that shall be solved. In FreeCAD constraints aren't specific to a particular solver. A problem setup can be solved by all solver that support all conditions in the analysis.
Constraints define boundary conditions for the problem that shall be solved. In FreeCAD constraints aren't specific to a particular solver. A problem setup can be solved by all solver that support all conditions in the analysis.


Adding new constraints is quite staight foreward. For newcomers there is a tutorial: [[Add_FEM_Constraint_Tutorial|Add FEM Constraint Tutorial]].
Adding new constraints is quite straight forward. For newcomers there is a tutorial: [[Add_FEM_Constraint_Tutorial|Add FEM Constraint Tutorial]].


[[Category:FEM{{#translation:}}]]
[[Category:FEM{{#translation:}}]]

Revision as of 06:54, 28 May 2020

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

L'ambiente FEM supporta già un sacco di vincoli diversi e alcuni solutori. Nonostante ciò spesso si ha bisogno di vincoli non ancora supportati da FreeCAD. Questa pagina è il punto di partenza per una serie di esercitazioni e di altre risorse che descrivono come estendere l'ambiente FEM utilizzando la struttura esistente. Anche se questa serie può rivelarsi utile per gli sviluppatori di software, l'idea è di permettere agli utenti di FEM che hanno un po' di interesse per la codifica in Python di aggiungere le cose di cui hanno bisogno.

Aggiungere nuovi vincoli, equazioni o solutori è per lo più un lavoro di routine. Ma farlo per la prima volta non è così facile come potrebbe sembrare. È utile conoscere i seguenti argomenti:

Sistema di costruzione (cmake)

The build system must be modified regardless of which objects shall be added o the FEM workbench. Every python module (file) must be registered. The FEM workbench requires every new python module to be registered in Mod/Fem/CMakeLists.txt. This is true regardless of the type of the python module (GUI or non-GUI). Where exactly the module must be inserted depends on the role of the module. Solver, equations and constraints all use different lists. Searching for similar files and inserting the new file in the same list works most of the time.

Ad esempio, proviamo ad aggiungere un nuovo vincolo di pressione. Un nuovo vincolo richiede almeno i seguenti nuovi moduli: FemConstraint<name>.py, ViewProviderFemConstraint<name>.py, CommandFemConstraint<name>.py. Questi tre file devono essere aggiunti a CMakeLists.txt ed anche a App/CMakeLists.txt.

Mod/Fem/CMakeLists.txt

SET(FemObjects_SRCS
    femobjects/__init__.py
    femobjects/base_fempythonobject.py
    femobjects/constraint_bodyheatsource.py
    femobjects/constraint_electrostaticpotential.py
    femobjects/constraint_flowvelocity.py
    femobjects/constraint_initialflowvelocity.py
+   femobjects/constraint_initialflowpressure.py
    femobjects/constraint_selfweight.py
...
    femobjects/solver_ccxtools.py
)
...
SET(FemGuiViewProvider_SRCS
    femviewprovider/__init__.py
    femviewprovider/view_base_femconstraint.py
    femviewprovider/view_base_femobject.py
    femviewprovider/view_constraint_bodyheatsource.py
    femviewprovider/view_constraint_electrostaticpotential.py
    femviewprovider/view_constraint_flowvelocity.py
+   femviewprovider/view_constraint_flowpressure.py
    femviewprovider/view_constraint_initialflowvelocity.py
    femviewprovider/view_constraint_selfweight.py
...
    femviewprovider/view_solver_ccxtools.py
)


Organizzazione del codice sorgente

Per organizzare il codice Python il modulo FEM usa un approccio simile a quello usato per il codice C++ in FreeCAD. Il modulo è diviso in due pacchetti. PyObjects, che contiene tutti i proxy Python non-gui come gli oggetti del documento e PyGui che contiene tutto ciò che è collegato come proxy python per il provider di visualizzazione, i pannelli delle attività, i file ui e i comandi.

Un pacchetto non segue questo modello: FemSolver. È posizionato allo stesso livello di PyObjects e PyGui (src/Mod/Fem/FemSolver). Il pacchetto contiene il solutore con i pacchetti relativi all'equazione ed ai moduli ed è organizzato nel seguente modo:

.femsolver
.femsolver.elmer
.femsolver.elmer.equations
.femsolver.calculix
.femsolver.calculix.equations
.femsolver.z88
.femsolver.z88.equations

Solutore

In FreeCAD a solver can be split into two parts:

  • One is the document object used by the user to interact with the solver. Though it solver parameter can be set and it is also used to control the solving process.
  • The other one are the so called tasks of a solver. The solving process is split into those tasks, namely: check, prepare, solve and results. Those do the actual work of exporting the analysis into a format understood by the solver executable, starting the executable and loading the results back into FreeCAD.

La maggior parte dei file relativi a un solver si trovano in un sottopacchetto del pacchetto FemSolver (e.g. FemSolver.Elmer). La seguente lista elenca tutti i file relativi all'implementazione di un risolutore. Questi sono i file che devono essere copiati e modificati per aggiungere il supporto per un nuovo risolutore in FreeCAD.

  • femsolver/elmer/Object.py: Document object visible in the tree-view. Implemented in python via a document proxy and view proxy.
  • femsolver/elmer/Tasks.py: Module containing one task class per task required for a solver implementation. Those tasks divide the process of solving a analysis into the following steps: check, prepare, solve, results.
  • femcommands/commands.py: Adds the solver document object to the active document. Required to access the solver object from the GUI.

Equazioni

Un'equazione rappresenta una particolare fisica che deve essere considerata quando si risolve l'analisi (ad esempio flusso, calore). Non tutti i solutori in FreeCAD supportano le equazioni. Le equazioni sono rappresentate dagli oggetti figlio del corrispondente oggetto del risolutore. Nella vista ad albero questo assomiglia così:

  • elmer-solver
    • elasticity
    • heat
    • flow
    • electrostatics

Most solver specific options (e.g. max. iterations, method of solving, etc) are set via the equation objects. One consequence of this is that each solver must have it's own implementation of "the same" equation. CalculiX would have a different Heat-object that Elmer. To avoid having multiple buttons for the same physics in the GUI each solver object adds it's equations itself.

The actual implementation can be split into the generic and the solver specific part. The generic part can be found in the femsolver.equationbase module. The solver specific part resides inside individual Equations sub-packages of the solver packages (e.g. femsolver/elmer/equations).

Adding a new equations to Elmer should be very easy. For newcomers there exists a tutorial which shows how to add a new equation to Elmer by adding the existing elasticity solver to FreeCAD: Add FEM Equation Tutorial.

Vincoli

Constraints define boundary conditions for the problem that shall be solved. In FreeCAD constraints aren't specific to a particular solver. A problem setup can be solved by all solver that support all conditions in the analysis.

Adding new constraints is quite straight forward. For newcomers there is a tutorial: Add FEM Constraint Tutorial.