[FEM] Elmer writer: sort out electricforce equation
- sort out electricforce equation - next step to refactor writer.py
This commit is contained in:
@@ -253,6 +253,7 @@ SET(FemSolverElmerEquations_SRCS
|
||||
femsolver/elmer/equations/__init__.py
|
||||
femsolver/elmer/equations/elasticity.py
|
||||
femsolver/elmer/equations/electricforce.py
|
||||
femsolver/elmer/equations/electricforce_writer.py
|
||||
femsolver/elmer/equations/electrostatic.py
|
||||
femsolver/elmer/equations/electrostatic_writer.py
|
||||
femsolver/elmer/equations/equation.py
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2023 Uwe Stöhr <uwestoehr@lyx.org> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * 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__ = "FreeCAD FEM Electricforce Elmer writer"
|
||||
__author__ = "Uwe Stöhr"
|
||||
__url__ = "https://www.freecad.org"
|
||||
|
||||
## \addtogroup FEM
|
||||
# @{
|
||||
|
||||
from .. import sifio
|
||||
from . import electricforce
|
||||
|
||||
class EFwriter:
|
||||
|
||||
def __init__(self, writer, solver):
|
||||
self.write = writer
|
||||
self.solver = solver
|
||||
|
||||
def getElectricforceSolver(self, equation):
|
||||
# check if we need to update the equation
|
||||
self._updateElectricforceSolver(equation)
|
||||
# output the equation parameters
|
||||
s = self.write.createEmptySolver()
|
||||
s["Equation"] = "Electric Force" # equation.Name
|
||||
s["Procedure"] = sifio.FileAttr("ElectricForce/StatElecForce")
|
||||
s["Exec Solver"] = equation.ExecSolver
|
||||
s["Stabilize"] = equation.Stabilize
|
||||
return s
|
||||
|
||||
def _updateElectricforceSolver(self, equation):
|
||||
# updates older Electricforce equations
|
||||
if not hasattr(equation, "ExecSolver"):
|
||||
equation.addProperty(
|
||||
"App::PropertyEnumeration",
|
||||
"ExecSolver",
|
||||
"Electric Force",
|
||||
(
|
||||
"That solver is only executed after solution converged\n"
|
||||
"To execute always, change to 'Always'"
|
||||
)
|
||||
)
|
||||
equation.ExecSolver = electricforce.SOLVER_EXEC_METHODS
|
||||
equation.ExecSolver = "After Timestep"
|
||||
|
||||
## @}
|
||||
@@ -49,7 +49,7 @@ from femtools import constants
|
||||
from femtools import femutils
|
||||
from femtools import membertools
|
||||
from .equations import elasticity
|
||||
from .equations import electricforce
|
||||
from .equations import electricforce_writer as EF_writer
|
||||
from .equations import electrostatic_writer as ES_writer
|
||||
from .equations import flow_writer
|
||||
from .equations import flux_writer
|
||||
@@ -854,6 +854,7 @@ class Writer(object):
|
||||
# Electricforce
|
||||
|
||||
def _handleElectricforce(self):
|
||||
EFW = EF_writer.EFwriter(self, self.solver)
|
||||
activeIn = []
|
||||
for equation in self.solver.Group:
|
||||
if femutils.is_of_type(equation, "Fem::EquationElmerElectricforce"):
|
||||
@@ -861,36 +862,10 @@ class Writer(object):
|
||||
activeIn = equation.References[0][1]
|
||||
else:
|
||||
activeIn = self.getAllBodies()
|
||||
solverSection = self._getElectricforceSolver(equation)
|
||||
solverSection = EFW.getElectricforceSolver(equation)
|
||||
for body in activeIn:
|
||||
self._addSolver(body, solverSection)
|
||||
|
||||
def _getElectricforceSolver(self, equation):
|
||||
# check if we need to update the equation
|
||||
self._updateElectricforceSolver(equation)
|
||||
# output the equation parameters
|
||||
s = self._createEmptySolver()
|
||||
s["Equation"] = "Electric Force" # equation.Name
|
||||
s["Procedure"] = sifio.FileAttr("ElectricForce/StatElecForce")
|
||||
s["Exec Solver"] = equation.ExecSolver
|
||||
s["Stabilize"] = equation.Stabilize
|
||||
return s
|
||||
|
||||
def _updateElectricforceSolver(self, equation):
|
||||
# updates older Electricforce equations
|
||||
if not hasattr(equation, "ExecSolver"):
|
||||
equation.addProperty(
|
||||
"App::PropertyEnumeration",
|
||||
"ExecSolver",
|
||||
"Electric Force",
|
||||
(
|
||||
"That solver is only executed after solution converged\n"
|
||||
"To execute always, change to 'Always'"
|
||||
)
|
||||
)
|
||||
equation.ExecSolver = electricforce.SOLVER_EXEC_METHODS
|
||||
equation.ExecSolver = "After Timestep"
|
||||
|
||||
#-------------------------------------------------------------------------------------------
|
||||
# Flow
|
||||
|
||||
@@ -961,7 +936,7 @@ class Writer(object):
|
||||
#-------------------------------------------------------------------------------------------
|
||||
# Solver handling
|
||||
|
||||
def _createEmptySolver(self):
|
||||
def createEmptySolver(self):
|
||||
s = sifio.createSection(sifio.SOLVER)
|
||||
return s
|
||||
|
||||
|
||||
Reference in New Issue
Block a user