From bc275eb772c631422ba95a464da5b47ea9f439ea Mon Sep 17 00:00:00 2001 From: Uwe Date: Tue, 7 Feb 2023 03:11:29 +0100 Subject: [PATCH] [FEM] Elmer writer: sort out electricforce equation - sort out electricforce equation - next step to refactor writer.py --- src/Mod/Fem/CMakeLists.txt | 1 + .../elmer/equations/electricforce_writer.py | 66 +++++++++++++++++++ src/Mod/Fem/femsolver/elmer/writer.py | 33 ++-------- 3 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 src/Mod/Fem/femsolver/elmer/equations/electricforce_writer.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 735ff3da1c..3a788fdaa2 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -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 diff --git a/src/Mod/Fem/femsolver/elmer/equations/electricforce_writer.py b/src/Mod/Fem/femsolver/elmer/equations/electricforce_writer.py new file mode 100644 index 0000000000..645db2cf1d --- /dev/null +++ b/src/Mod/Fem/femsolver/elmer/equations/electricforce_writer.py @@ -0,0 +1,66 @@ +# *************************************************************************** +# * Copyright (c) 2023 Uwe Stöhr * +# * * +# * 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" + +## @} diff --git a/src/Mod/Fem/femsolver/elmer/writer.py b/src/Mod/Fem/femsolver/elmer/writer.py index 8592bf615c..1b0cdc9abf 100644 --- a/src/Mod/Fem/femsolver/elmer/writer.py +++ b/src/Mod/Fem/femsolver/elmer/writer.py @@ -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