Add FEM Equation Tutorial/it: Difference between revisions
(Created page with "Dopo aver copiato {{Incode|heat.py}} in {{Incode|flow.py}}, modificare {{Incode|flow.py}} in queste posizioni: * l'argomento del nome della funzione del modulo {{Incode|create}}, * le classi base della classe {{Incode|Proxy}}, * l'attributo {{Incode|Type}} della classe {{Incode|Proxy}}, * le classi {{Incode|ViewProxy}}.") |
(Created page with "Quindi è necessario modificare le proprietà aggiunte tramite la funzione {{Incode|obj.addProperty(..)}} con quelle richieste dall'equazione.") |
||
Line 89: | Line 89: | ||
}} |
}} |
||
Quindi è necessario modificare le proprietà aggiunte tramite la funzione {{Incode|obj.addProperty(..)}} con quelle richieste dall'equazione. |
|||
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. |
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. |
Revision as of 14:44, 12 May 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.
L'operazione può essere suddivisa in cinque parti:
- Nuovo tipo di equazione. Questo passaggio deve essere eseguito solo se l'equazione non esiste ancora in FreeCAD (al contrario di un'equazione già presente in FreeCAD ma non supportata dal risolutore di destinazione).
- Nuovo oggetto equazione. Aggiunta di un oggetto documento concreto che rappresenta l'equazione specifica di Elmer.
- Estendere l'oggetto risolutore. Aggiungere il supporto per la nuova equazione all'oggetto risolutore di Elmer.
- Estendere l'oggetto scrittore. Estensione dell'esportazione dell'analisi di Elmer per supportare il nuovo tipo di equazione.
- Strumento GUI per creare un'equazione. Accedere alla nuova funzione dell'equazione tramite la GUI dell'ambiente.
Nuovo tipo di equazione
In questo passaggio modificheremo il seguente file:
- src/Mod/Fem/femsolver/equationbase.py
Il tipo di equazione è condiviso tra tutti gli oggetti dell'equazione dei diversi solutori. Ogni tipo ha uno specificatore di stringa (ad esempio "Heat") e un comando dedicato che aggiunge l'equazione al risolutore selezionato. Ciò consente una GUI più semplice in cui si ha un solo pulsante per l'equazione del calore che viene utilizzata per tutti i solutori supportati.
Innanzitutto, aggiungere la nuova equazione al modulo equationbase.py
. Ogni equazione richiede due classi. Un proxy di documento e un proxy di visualizzazione. Queste due classi verranno successivamente utilizzate come classi base per le classi di equazioni specifiche di Elmer. Basta copiarle ed incollarle da un tipo di equazione esistente e regolare il percorso dell'icona all'interno di getIcon(self)
del proxy di visualizzazione.
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
Si inizi aggiungendo il nuovo file flow.py
. Questo file può essere copiato da un'equazione esistente.
Keywords
- Se la nuova equazione supporta solo parole chiave per sistemi lineari copiare il modulo
femsolver/elmer/equations/elasticity.py
. - Se la nuova equazione supporta parole chiave sia per i sistemi lineari che non lineari, copiare
femsolver/elmer/equations/heat.py
.
L'equazione del flusso in Elmer è un'equazione potenzialmente non lineare. Ciò significa che si baserà il lavoro su heat.py
.
Modifica dei file
Dopo aver copiato heat.py
in flow.py
, modificare flow.py
in queste posizioni:
- l'argomento del nome della funzione del modulo
create
, - le classi base della classe
Proxy
, - l'attributo
Type
della classeProxy
, - le classi
ViewProxy
.
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
Quindi è necessario modificare le proprietà aggiunte tramite la funzione obj.addProperty(..)
con quelle richieste dall'equazione.
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.