From 40629bb2bf4bf8e452a12c4ce6faa0a6847ca98f Mon Sep 17 00:00:00 2001 From: Uwe Date: Sat, 6 Aug 2022 20:01:24 +0200 Subject: [PATCH] [Fem] Elmer: update tolerances - update tolerances also for existing analyses to fix the bug that users see e.g. "0.001" and not the actual used tolerance - also a fix for new stress analyses - also a formatting fix --- .../femsolver/elmer/equations/elasticity.py | 4 ++- .../Fem/femsolver/elmer/equations/linear.py | 4 +-- .../femsolver/elmer/equations/nonlinear.py | 6 ++-- src/Mod/Fem/femsolver/elmer/writer.py | 28 +++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Mod/Fem/femsolver/elmer/equations/elasticity.py b/src/Mod/Fem/femsolver/elmer/equations/elasticity.py index 49b3f58ea9..423b4285be 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/elasticity.py +++ b/src/Mod/Fem/femsolver/elmer/equations/elasticity.py @@ -235,7 +235,9 @@ class Proxy(linear.Proxy, equationbase.ElasticityProxy): obj.EigenSystemSelect = "Smallest Magnitude" # according to Elmer manual default is 100 times the Linear Tolerance # since this is a small value we must set an expression, see linear.py for background - obj.setExpression("EigenSystemTolerance", str(100 * obj.LinearTolerance)) + for (prop, expr) in obj.ExpressionEngine: + if (prop == "LinearTolerance"): + obj.setExpression("EigenSystemTolerance", str(100 * obj.evalExpression(expr))) obj.Variable = "Displacement" diff --git a/src/Mod/Fem/femsolver/elmer/equations/linear.py b/src/Mod/Fem/femsolver/elmer/equations/linear.py index 8cb11eaf72..d19d621111 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/linear.py +++ b/src/Mod/Fem/femsolver/elmer/equations/linear.py @@ -110,7 +110,7 @@ class Proxy(equation.Proxy): # view and edit the tolerance via the property editor and this does not # yet allow to view and edit small numbers in scientific notation # forum thread: https://forum.freecadweb.org/viewtopic.php?p=613897#p613897 - obj.setExpression('LinearTolerance', "1e-8") + obj.setExpression("LinearTolerance", "1e-8") obj.addProperty( "App::PropertyInteger", "LinearIterations", @@ -125,7 +125,7 @@ class Proxy(equation.Proxy): "" ) # same as with LinearTolerance - obj.setExpression('SteadyStateTolerance', "1e-5") + obj.setExpression("SteadyStateTolerance", "1e-5") obj.addProperty( "App::PropertyBool", diff --git a/src/Mod/Fem/femsolver/elmer/equations/nonlinear.py b/src/Mod/Fem/femsolver/elmer/equations/nonlinear.py index 33c7fb3d37..1514036f25 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/nonlinear.py +++ b/src/Mod/Fem/femsolver/elmer/equations/nonlinear.py @@ -76,9 +76,9 @@ class Proxy(linear.Proxy): # the user has to view and edit the tolerance via the property editor and # this does not yet allow to view and edit small numbers in scientific notation # forum thread: https://forum.freecadweb.org/viewtopic.php?p=613897#p613897 - obj.setExpression('NonlinearTolerance', "1e-8") - obj.setExpression('NonlinearNewtonAfterTolerance', "1e-3") - obj.setExpression('RelaxationFactor', "1.0") # must often be < 1 down to 0.01 + obj.setExpression("NonlinearTolerance", "1e-8") + obj.setExpression("NonlinearNewtonAfterTolerance", "1e-3") + obj.setExpression("RelaxationFactor", "1.0") # must often be < 1 down to 0.01 class ViewProxy(linear.ViewProxy): diff --git a/src/Mod/Fem/femsolver/elmer/writer.py b/src/Mod/Fem/femsolver/elmer/writer.py index e963337b1c..88e9a8bdca 100644 --- a/src/Mod/Fem/femsolver/elmer/writer.py +++ b/src/Mod/Fem/femsolver/elmer/writer.py @@ -1223,7 +1223,24 @@ class Writer(object): s = sifio.createSection(sifio.SOLVER) return s + def _hasExpression(self, equation): + obj = None + exp = None + for (obj, exp) in equation.ExpressionEngine: + if obj == equation: + return exp + return None + + def _updateLinearSolver(self, equation): + if self._hasExpression(equation) != equation.LinearTolerance: + equation.setExpression("LinearTolerance", str(equation.LinearTolerance)) + if self._hasExpression(equation) != equation.SteadyStateTolerance: + equation.setExpression("SteadyStateTolerance", str(equation.SteadyStateTolerance)) + def _createLinearSolver(self, equation): + # first check if we have to update + self._updateLinearSolver(equation) + # write the solver s = sifio.createSection(sifio.SOLVER) s.priority = equation.Priority s["Linear System Solver"] = equation.LinearSolverType @@ -1249,8 +1266,19 @@ class Writer(object): s["Linear System Precondition Recompute"] = 1 return s + def _updateNonlinearSolver(self, equation): + if self._hasExpression(equation) != equation.NonlinearTolerance: + equation.setExpression("NonlinearTolerance", str(equation.NonlinearTolerance)) + if self._hasExpression(equation) != equation.NonlinearNewtonAfterTolerance: + equation.setExpression("NonlinearNewtonAfterTolerance",\ + str(equation.NonlinearNewtonAfterTolerance)) + def _createNonlinearSolver(self, equation): + # first check if we have to update + self._updateNonlinearSolver(equation) + # write the linear solver s = self._createLinearSolver(equation) + # write the nonlinear solver s["Nonlinear System Max Iterations"] = \ equation.NonlinearIterations s["Nonlinear System Convergence Tolerance"] = \