FEM: Potential-boundary constraint and elmerflux-solver, add objects and implement them in elmer

This commit is contained in:
Wilfried Hortschitz
2017-12-01 19:44:28 +01:00
committed by wmayer
parent fc9350f2a0
commit f0a33ddb30
14 changed files with 498 additions and 2 deletions

View File

@@ -103,6 +103,7 @@ SET(FemObjectsScripts_SRCS
PyObjects/_FemConstraintBodyHeatSource.py
PyObjects/_FemConstraintFlowVelocity.py
PyObjects/_FemConstraintInitialFlowVelocity.py
PyObjects/_FemConstraintElectrostaticPotential.py
PyObjects/_FemElementFluid1D.py
PyObjects/_FemElementGeometry1D.py
PyObjects/_FemElementGeometry2D.py
@@ -144,6 +145,7 @@ SET(FemEquationsElmer_SRCS
femsolver/elmer/equations/nonlinear.py
femsolver/elmer/equations/elasticity.py
femsolver/elmer/equations/electrostatic.py
femsolver/elmer/equations/fluxsolver.py
femsolver/elmer/equations/heat.py
femsolver/elmer/equations/flow.py
)
@@ -172,6 +174,7 @@ SET(FemGuiScripts_SRCS
PyGui/_CommandFemConstraintBodyHeatSource.py
PyGui/_CommandFemConstraintFlowVelocity.py
PyGui/_CommandFemConstraintInitialFlowVelocity.py
PyGui/_CommandFemConstraintElectrostaticPotential.py
PyGui/_CommandFemElementFluid1D.py
PyGui/_CommandFemElementGeometry1D.py
PyGui/_CommandFemElementGeometry2D.py
@@ -209,6 +212,7 @@ SET(FemGuiScripts_SRCS
PyGui/_ViewProviderFemConstraintBodyHeatSource.py
PyGui/_ViewProviderFemConstraintFlowVelocity.py
PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py
PyGui/_ViewProviderFemConstraintElectrostaticPotential.py
PyGui/_ViewProviderFemElementFluid1D.py
PyGui/_ViewProviderFemElementGeometry1D.py
PyGui/_ViewProviderFemElementGeometry2D.py
@@ -234,6 +238,7 @@ SET(FemGuiScripts_SRCS
PyGui/TaskPanelFemSolverCalculix.ui
PyGui/TaskPanelFemFlowVelocity.ui
PyGui/TaskPanelFemInitialFlowVelocity.ui
PyGui/TaskPanelFemElectrostaticPotential.ui
)
SET(FemTests_SRCS

View File

@@ -53,6 +53,7 @@ INSTALL(
PyObjects/_FemConstraintBodyHeatSource.py
PyObjects/_FemConstraintFlowVelocity.py
PyObjects/_FemConstraintInitialFlowVelocity.py
PyObjects/_FemConstraintElectrostaticPotential.py
PyObjects/_FemElementFluid1D.py
PyObjects/_FemElementGeometry1D.py
PyObjects/_FemElementGeometry2D.py
@@ -103,6 +104,7 @@ INSTALL(
femsolver/elmer/equations/nonlinear.py
femsolver/elmer/equations/elasticity.py
femsolver/elmer/equations/electrostatic.py
femsolver/elmer/equations/fluxsolver.py
femsolver/elmer/equations/heat.py
femsolver/elmer/equations/flow.py
DESTINATION
@@ -140,6 +142,7 @@ INSTALL(
PyGui/_CommandFemConstraintBodyHeatSource.py
PyGui/_CommandFemConstraintFlowVelocity.py
PyGui/_CommandFemConstraintInitialFlowVelocity.py
PyGui/_CommandFemConstraintElectrostaticPotential.py
PyGui/_CommandFemAnalysis.py
PyGui/_CommandFemConstraintSelfWeight.py
PyGui/_CommandFemElementFluid1D.py
@@ -177,6 +180,7 @@ INSTALL(
PyGui/_ViewProviderFemConstraintBodyHeatSource.py
PyGui/_ViewProviderFemConstraintFlowVelocity.py
PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py
PyGui/_ViewProviderFemConstraintElectrostaticPotential.py
PyGui/_ViewProviderFemElementFluid1D.py
PyGui/_ViewProviderFemElementGeometry1D.py
PyGui/_ViewProviderFemElementGeometry2D.py
@@ -202,6 +206,7 @@ INSTALL(
PyGui/TaskPanelFemSolverCalculix.ui
PyGui/TaskPanelFemFlowVelocity.ui
PyGui/TaskPanelFemInitialFlowVelocity.ui
PyGui/TaskPanelFemElectrostaticPotential.ui
DESTINATION
Mod/Fem/PyGui
)

View File

@@ -109,6 +109,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "FEM_ConstraintFluidBoundary"
<< "FEM_ConstraintFlowVelocity";
Gui::ToolBarItem* electrostat = new Gui::ToolBarItem(root);
electrostat->setCommand("Electrostatic Constraints");
*electrostat << "FEM_ConstraintElectrostaticPotential";
Gui::ToolBarItem* solve = new Gui::ToolBarItem(root);
solve->setCommand("Solve");
*solve << "FEM_SolverCalculix"
@@ -116,6 +120,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Separator"
<< "FEM_EquationHeat"
<< "FEM_EquationElasticity"
<< "FEM_EquationFluxsolver"
<< "FEM_EquationElectrostatic"
<< "FEM_EquationFlow"
<< "Separator"
@@ -220,6 +225,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "FEM_EquationHeat"
<< "FEM_EquationElasticity"
<< "FEM_EquationElectrostatic"
<< "FEM_EquationFluxsolver"
<< "FEM_EquationFlow"
<< "Separator"
<< "FEM_SolverControl"

View File

@@ -50,6 +50,7 @@ class FemWorkbench (Workbench):
import PyGui._CommandFemConstraintBodyHeatSource
import PyGui._CommandFemConstraintFlowVelocity
import PyGui._CommandFemConstraintInitialFlowVelocity
import PyGui._CommandFemConstraintElectrostaticPotential
import PyGui._CommandFemElementFluid1D
import PyGui._CommandFemElementGeometry1D
import PyGui._CommandFemElementGeometry2D

View File

@@ -67,6 +67,17 @@ def makeConstraintDisplacement(doc, name="ConstraintDisplacement"):
return obj
def makeConstraintElectrostaticPotential(doc, name="ConstraintElectrostaticPotential"):
'''makeConstraintElectrostaticPotential(document, [name]): makes a Fem ElectrostaticPotential object'''
obj = doc.addObject("Fem::ConstraintPython", name)
import PyObjects._FemConstraintElectrostaticPotential
PyObjects._FemConstraintElectrostaticPotential.Proxy(obj)
if FreeCAD.GuiUp:
import PyGui._ViewProviderFemConstraintElectrostaticPotential
PyGui._ViewProviderFemConstraintElectrostaticPotential.ViewProxy(obj.ViewObject)
return obj
def makeConstraintFixed(doc, name="ConstraintFixed"):
'''makeConstraintFixed(document, [name]): makes a Fem ConstraintFixed object'''
obj = doc.addObject("Fem::ConstraintFixed", name)

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Constraint Properties</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="potentialLbl">
<property name="text">
<string>Potential:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="Gui::InputField" name="potentialTxt">
<property name="enabled">
<bool>false</bool>
</property>
<property name="singleStep" stdset="0">
<double>1.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string>V</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="potentialBox">
<property name="text">
<string>unspecified</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="potentialConstantBox">
<property name="text">
<string>Potential Constant</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>potentialBox</sender>
<signal>toggled(bool)</signal>
<receiver>potentialTxt</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>230</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>230</x>
<y>18</y>
</hint>
</hints>
</connection>
<connection>
<sender>potentialBox</sender>
<signal>toggled(bool)</signal>
<receiver>potentialTxt</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>230</x>
<y>44</y>
</hint>
<hint type="destinationlabel">
<x>230</x>
<y>18</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,60 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Markus Hovorka <m.hovorka@live.de> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "AddConstraintElectrostaticPotential"
__author__ = "Markus Hovorka"
__url__ = "http://www.freecadweb.org"
## @package CommandFemConstraintElectrostaticPotential
# \ingroup FEM
import FreeCAD
from .FemCommands import FemCommands
import FreeCADGui
from PySide import QtCore
class _CommandFemConstraintElectrostaticPotential(FemCommands):
"The FEM_ConstraintElectrostaticPotential command definition"
def __init__(self):
super(_CommandFemConstraintElectrostaticPotential, self).__init__()
self.resources = {
'Pixmap': 'fem-constraint-electrostatic-potential',
'MenuText': QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintElectrostaticPotential",
"Constraint Potenial"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintElectrostaticPotential",
"Creates a FEM constraint electrostatic potential")}
self.is_active = 'with_analysis'
def Activated(self):
FreeCAD.ActiveDocument.openTransaction(
"Create FemConstraintElectrostaticPotential")
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.doCommand(
"FemGui.getActiveAnalysis().Member += "
"[ObjectsFem.makeConstraintElectrostaticPotential(FreeCAD.ActiveDocument)]")
FreeCADGui.addCommand('FEM_ConstraintElectrostaticPotential', _CommandFemConstraintElectrostaticPotential())

View File

@@ -96,6 +96,18 @@ class Electrostatic(_Base):
'ToolTip': "Creates a FEM equation for electrostatic"
}
class Fluxsolver(_Base):
def getSpecifier(self):
return "Fluxsolver"
def GetResources(self):
return {
'Pixmap': 'fem-equation-fluxsolver',
'MenuText': "Flux Solver Equation",
'ToolTip': "Creates a FEM equation for solving the flux or gradient"
}
class Flow(_Base):
@@ -113,4 +125,5 @@ class Flow(_Base):
Gui.addCommand('FEM_EquationHeat', Heat())
Gui.addCommand('FEM_EquationElasticity', Elasticity())
Gui.addCommand('FEM_EquationElectrostatic', Electrostatic())
Gui.addCommand('FEM_EquationFluxsolver', Fluxsolver())
Gui.addCommand('FEM_EquationFlow', Flow())

View File

@@ -0,0 +1,121 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Markus Hovorka <m.hovorka@live.de> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "Elmer Solver Object"
__author__ = "Markus Hovorka, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
import FreeCAD as App
import FemUtils
import FemConstraint
from FreeCAD import Units
import FreeCADGui as Gui
from . import FemSelectionWidgets
class ViewProxy(FemConstraint.ViewProxy):
def getIcon(self):
return ":/icons/fem-constraint-electrostatic-potential.svg"
def setEdit(self, vobj, mode=0):
task = _TaskPanel(vobj.Object)
Gui.Control.showDialog(task)
def unsetEdit(self, vobj, mode=0):
Gui.Control.closeDialog()
def doubleClicked(self, vobj):
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
Gui.ActiveDocument.setEdit(vobj.Object.Name)
return True
class _TaskPanel(object):
def __init__(self, obj):
self._obj = obj
self._refWidget = FemSelectionWidgets.BoundarySelector()
self._refWidget.setReferences(obj.References)
self._paramWidget = Gui.PySideUic.loadUi(
App.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemElectrostaticPotential.ui")
self._initParamWidget()
self.form = [self._refWidget, self._paramWidget]
analysis = FemUtils.findAnalysisOfMember(obj)
self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject")
self._part = self._mesh.Part if self._mesh is not None else None
self._partVisible = None
self._meshVisible = None
def open(self):
if self._mesh is not None and self._part is not None:
self._meshVisible = self._mesh.ViewObject.isVisible()
self._partVisible = self._part.ViewObject.isVisible()
self._mesh.ViewObject.hide()
self._part.ViewObject.show()
def reject(self):
self._restoreVisibility()
return True
def accept(self):
if self._obj.References != self._refWidget.references():
self._obj.References = self._refWidget.references()
self._applyWidgetChanges()
self._obj.Document.recompute()
self._restoreVisibility()
return True
def _restoreVisibility(self):
if self._mesh is not None and self._part is not None:
if self._meshVisible:
self._mesh.ViewObject.show()
else:
self._mesh.ViewObject.hide()
if self._partVisible:
self._part.ViewObject.show()
else:
self._part.ViewObject.hide()
def _initParamWidget(self):
unit = "V"
q = Units.Quantity("{} {}".format(self._obj.Potential, unit))
self._paramWidget.potentialTxt.setText(
q.UserString)
self._paramWidget.potentialBox.setChecked(
not self._obj.PotentialEnabled)
self._paramWidget.potentialConstantBox.setChecked(
self._obj.PotentialConstant)
def _applyWidgetChanges(self):
unit = "V"
self._obj.PotentialEnabled = \
not self._paramWidget.potentialBox.isChecked()
if self._obj.PotentialEnabled:
quantity = Units.Quantity(self._paramWidget.potentialTxt.text())
self._obj.Potential = float(quantity.getValueAs(unit))
self._obj.PotentialConstant = self._paramWidget.potentialConstantBox.isChecked()

View File

@@ -0,0 +1,46 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Markus Hovorka <m.hovorka@live.de> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "Elmer Solver Object"
__author__ = "Markus Hovorka, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
import FemConstraint
class Proxy(FemConstraint.Proxy):
Type = "Fem::ConstraintElectrostaticPotential"
def __init__(self, obj):
super(Proxy, self).__init__(obj)
obj.addProperty(
"App::PropertyFloat", "Potential",
"Parameter", "Potential"),
obj.addProperty(
"App::PropertyBool", "PotentialEnabled",
"Parameter", "Potential Enabled"),
obj.addProperty(
"App::PropertyBool", "PotentialConstant",
"Parameter", "Potential Constant")

View File

@@ -0,0 +1,74 @@
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Markus Hovorka <m.hovorka@live.de> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "Fluxsolver"
__author__ = "Markus Hovorka"
__url__ = "http://www.freecadweb.org"
import FemUtils
from ... import equationbase
from . import linear
def create(doc, name="Fluxsolver"):
return FemUtils.createObject(
doc, name, Proxy, ViewProxy)
class Proxy(linear.Proxy, equationbase.FluxsolverProxy):
Type = "Fem::FemEquationElmerFluxsolver"
def __init__(self, obj):
super(Proxy, self).__init__(obj)
obj.addProperty(
"App::PropertyBool", "CalculateFlux",
"Fluxsolver", "Select type of solver for linear system")
obj.addProperty(
"App::PropertyString", "FluxVariable",
"Fluxsolver", "Insert variable name for flux calculation")
#obj.addProperty(
#"App::PropertyBool", "CalculateFluxAbs",
#"Fluxsolver", "Select calculation of abs of flux")
#obj.addProperty(
#"App::PropertyBool", "CalculateFluxMagnitude",
#"Fluxsolver", "Select calculation of magnitude of flux")
obj.addProperty(
"App::PropertyBool", "CalculateGrad",
"Fluxsolver", "Select calculation of gradient")
#obj.addProperty(
#"App::PropertyBool", "CalculateGradAbs",
#"Fluxsolver", "Select calculation of abs of gradient")
#obj.addProperty(
#"App::PropertyBool", "CalculateGradMagnitude",
#"Fluxsolver", "Select calculation of magnitude of gradient")
#obj.addProperty(
#"App::PropertyBool", "EnforcePositiveMagnitude",
#"Fluxsolver", "Select calculation of positive magnitude")
obj.Priority = 5
class ViewProxy(linear.ViewProxy, equationbase.FluxsolverViewProxy):
pass

View File

@@ -35,6 +35,7 @@ from . import tasks
from .equations import heat
from .equations import elasticity
from .equations import electrostatic
from .equations import fluxsolver
from .equations import flow
@@ -52,6 +53,7 @@ class Proxy(solverbase.Proxy):
"Heat": heat,
"Elasticity": elasticity,
"Electrostatic": electrostatic,
"Fluxsolver": fluxsolver,
"Flow": flow,
}

View File

@@ -107,6 +107,7 @@ class Writer(object):
self._handleHeat()
self._handleElasticity()
self._handleElectrostatic()
self._handleFluxsolver()
self._handleFlow()
self._addOutputSolver()
@@ -294,7 +295,7 @@ class Writer(object):
self._addSolver(body, solverSection)
if activeIn:
self._handleElectrostaticConstants()
#self._handleElectrostaticBndConditions()
self._handleElectrostaticBndConditions()
#self._handleElectrostaticInitial(activeIn)
#self._handleElectrostaticBodyForces(activeIn)
self._handleElectrostaticMaterial(activeIn)
@@ -306,7 +307,7 @@ class Writer(object):
s["Variable"] = self._getUniqueVarName("Potential")
s["Variable DOFs"] = 1
s["Calculate Electric Field"] = equation.CalculateElectricField
s["Calculate Electric Flux"] = equation.CalculateElectricFlux
#s["Calculate Electric Flux"] = equation.CalculateElectricFlux
s["Calculate Electric Energy"] = equation.CalculateElectricEnergy
s["Calculate Surface Charge"] = equation.CalculateSurfaceCharge
s["Displace mesh"] = False
@@ -334,6 +335,42 @@ class Writer(object):
name, "Relative Permittivity",
float(m["RelativePermittivity"]))
def _handleElectrostaticBndConditions(self):
for obj in self._getMember("Fem::ConstraintElectrostaticPotential"):
if obj.References:
for name in obj.References[0][1]:
if obj.Potential:
potential = getFromUi(obj.Potential, "V", "M*L^2/(T^3 * I)")
self._boundary(name, "Potential", potential)
if obj.PotentialConstant:
self._boundary(name, "Potential Constant", True)
self._handled(obj)
def _handleFluxsolver(self):
activeIn = []
for equation in self.solver.Group:
if FemUtils.isOfType(equation, "Fem::FemEquationElmerFluxsolver"):
if equation.References:
activeIn = equation.References[0][1]
else:
activeIn = self._getAllBodies()
solverSection = self._getFluxsolverSolver(equation)
for body in activeIn:
self._addSolver(body, solverSection)
def _getFluxsolverSolver(self, equation):
s = self._createLinearSolver(equation)
s["Equation"] = "Flux Solver" # equation.Name
s["Procedure"] = sifio.FileAttr("FluxSolver/FluxSolver")
s["Flux Variable"] = equation.FluxVariable
s["Calculate Flux"] = equation.CalculateFlux
s["Calculate Grad"] = equation.CalculateGrad
return s
def _handleElasticity(self):
activeIn = []
for equation in self.solver.Group:

View File

@@ -96,6 +96,16 @@ class ElectrostaticProxy(BaseProxy):
pass
class FluxsolverViewProxy(BaseViewProxy):
def getIcon(self):
return ":/icons/fem-equation-fluxsolver.svg"
class FluxsolverProxy(BaseProxy):
pass
class FlowProxy(BaseProxy):
pass