Skip to content

Commit

Permalink
FEM: elmer, add electrostatic equation
Browse files Browse the repository at this point in the history
  • Loading branch information
HoWil authored and berndhahnebach committed Sep 10, 2017
1 parent 05142b5 commit 78470fd
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Mod/Fem/App/CMakeLists.txt
Expand Up @@ -147,6 +147,7 @@ SET(FemEquationsElmer_SRCS
FemSolver/Elmer/Equations/Linear.py
FemSolver/Elmer/Equations/Nonlinear.py
FemSolver/Elmer/Equations/Elasticity.py
FemSolver/Elmer/Equations/Electrostatic.py
FemSolver/Elmer/Equations/Heat.py
FemSolver/Elmer/Equations/Flow.py
)
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Fem/CMakeLists.txt
Expand Up @@ -106,6 +106,7 @@ INSTALL(
FemSolver/Elmer/Equations/Linear.py
FemSolver/Elmer/Equations/Nonlinear.py
FemSolver/Elmer/Equations/Elasticity.py
FemSolver/Elmer/Equations/Electrostatic.py
FemSolver/Elmer/Equations/Heat.py
FemSolver/Elmer/Equations/Flow.py
DESTINATION
Expand Down
68 changes: 68 additions & 0 deletions src/Mod/Fem/FemSolver/Elmer/Equations/Electrostatic.py
@@ -0,0 +1,68 @@
# ***************************************************************************
# * *
# * 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__ = "Electrostatic"
__author__ = "Markus Hovorka"
__url__ = "http://www.freecadweb.org"


import FemMisc
import FemSolver.EquationBase
import Linear


def create(doc, name="Electrostatic"):
return FemMisc.createObject(
doc, name, Proxy, ViewProxy)


class Proxy(Linear.Proxy, FemSolver.EquationBase.ElectrostaticProxy):

Type = "Fem::FemEquationElmerElectrostatic"

def __init__(self, obj):
super(Proxy, self).__init__(obj)
obj.addProperty(
"App::PropertyBool", "CalculateElectricField",
"Electrostatic", "Select type of solver for linear system")
obj.addProperty(
"App::PropertyBool", "CalculateElectricFlux",
"Electrostatic", "Select type of solver for linear system")
obj.addProperty(
"App::PropertyBool", "CalculateElectricEnergy",
"Electrostatic", "Select type of solver for linear system")
obj.addProperty(
"App::PropertyBool", "CalculateSurfaceCharge",
"Electrostatic", "Select type of solver for linear system")
#obj.addProperty(
#"App::PropertyBool", "CalculateCapacitanceMatrix",
#"Electrostatic", "Select type of solver for linear system")
#obj.addProperty(
#"App::PropertyInteger", "CapacitanceBodies",
#"Electrostatic", "Select type of solver for linear system")

obj.Priority = 10


class ViewProxy(Linear.ViewProxy, FemSolver.EquationBase.ElectrostaticViewProxy):
pass
2 changes: 2 additions & 0 deletions src/Mod/Fem/FemSolver/Elmer/Object.py
Expand Up @@ -33,6 +33,7 @@
import Tasks
import Equations.Heat
import Equations.Elasticity
import Equations.Electrostatic
import Equations.Flow


Expand All @@ -49,6 +50,7 @@ class Proxy(FemSolver.SolverBase.Proxy):
_EQUATIONS = {
"Heat": Equations.Heat,
"Elasticity": Equations.Elasticity,
"Electrostatic": Equations.Electrostatic,
"Flow": Equations.Flow,
}

Expand Down
55 changes: 55 additions & 0 deletions src/Mod/Fem/FemSolver/Elmer/Writer.py
Expand Up @@ -106,6 +106,7 @@ def write(self):
self._handleSimulation()
self._handleHeat()
self._handleElasticity()
self._handleElectrostatic()
self._handleFlow()
self._addOutputSolver()

Expand Down Expand Up @@ -280,6 +281,60 @@ def _handleHeatMaterial(self, bodies):
name, "Heat Capacity",
convert(m["SpecificHeat"], "L^2/(T^2*O)"))

def _handleElectrostatic(self):
activeIn = []
for equation in self.solver.Group:
if FemMisc.isOfType(equation, "Fem::FemEquationElmerElectrostatic"):
if equation.References:
activeIn = equation.References[0][1]
else:
activeIn = self._getAllBodies()
solverSection = self._getElectrostaticSolver(equation)
for body in activeIn:
self._addSolver(body, solverSection)
if activeIn:
self._handleElectrostaticConstants()
#self._handleElectrostaticBndConditions()
#self._handleElectrostaticInitial(activeIn)
#self._handleElectrostaticBodyForces(activeIn)
self._handleElectrostaticMaterial(activeIn)

def _getElectrostaticSolver(self, equation):
s = self._createLinearSolver(equation)
s["Equation"] = "Stat Elec Solver" # equation.Name
s["Procedure"] = sifio.FileAttr("StatElecSolve/StatElecSolver")
s["Variable"] = self._getUniqueVarName("Potential")
s["Variable DOFs"] = 1
s["Calculate Electric Field"] = equation.CalculateElectricField
s["Calculate Electric Flux"] = equation.CalculateElectricFlux
s["Calculate Electric Energy"] = equation.CalculateElectricEnergy
s["Calculate Surface Charge"] = equation.CalculateSurfaceCharge
s["Displace mesh"] = False
s["Exec Solver"] = "Always"
s["Stabilize"] = equation.Stabilize
s["Bubbles"] = equation.Bubbles
s["Optimize Bandwidth"] = True
return s

def _handleElectrostaticConstants(self):
self._constant(
"Permittivity Of Vacuum",
getConstant("PermittivityOfVacuum", "T^4*I^2/(L*M)"))

def _handleElectrostaticMaterial(self, bodies):
for obj in self._getMember("App::MaterialObject"):
m = obj.Material
refs = (
obj.References[0][1]
if obj.References
else self._getAllBodies())
for name in (n for n in refs if n in bodies):
if "RelativePermittivity" in m:
self._material(
name, "Relative Permittivity",
float(m["RelativePermittivity"]))


def _handleElasticity(self):
activeIn = []
for equation in self.solver.Group:
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/Fem/FemSolver/EquationBase.py
Expand Up @@ -86,6 +86,15 @@ def getIcon(self):
return ":/icons/fem-equation-elasticity.svg"


class ElectrostaticViewProxy(BaseViewProxy):

def getIcon(self):
return ":/icons/fem-equation-electrostatic.svg"

class ElectrostaticProxy(BaseProxy):
pass


class FlowProxy(BaseProxy):
pass

Expand Down
1 change: 1 addition & 0 deletions src/Mod/Fem/Gui/Resources/Fem.qrc
Expand Up @@ -58,6 +58,7 @@
<file>icons/fem-sphere.svg</file>
<file>icons/fem-equation-heat.svg</file>
<file>icons/fem-equation-elasticity.svg</file>
<file>icons/fem-equation-electrostatic.svg</file>
<file>icons/fem-equation-flow.svg</file>
<file>icons/fem-static-analysis.svg</file>
<file>icons/fem-thermomechanical-analysis.svg</file>
Expand Down

0 comments on commit 78470fd

Please sign in to comment.