From c13943d89ff7342e3f5411ed6653eca9546b03df Mon Sep 17 00:00:00 2001 From: KulaginVladimir Date: Sat, 10 Aug 2024 19:03:31 +0300 Subject: [PATCH 1/2] set error_on_nonconvergence to True and added tests --- festim/concentration/traps/extrinsic_trap.py | 3 +-- festim/temperature/temperature_solver.py | 1 - test/unit/test_temperature.py | 22 +++++++++++++++++++ test/unit/test_traps/test_extrinsic_trap.py | 23 ++++++++++++++++++-- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/festim/concentration/traps/extrinsic_trap.py b/festim/concentration/traps/extrinsic_trap.py index b6b0c9f27..7cc6bf54b 100644 --- a/festim/concentration/traps/extrinsic_trap.py +++ b/festim/concentration/traps/extrinsic_trap.py @@ -15,7 +15,7 @@ def __init__( relative_tolerance=1e-10, maximum_iterations=30, linear_solver=None, - preconditioner=None, + preconditioner="default", **kwargs, ): """Inits ExtrinsicTrap @@ -73,7 +73,6 @@ def newton_solver(self, value): def define_newton_solver(self): """Creates the Newton solver and sets its parameters""" self.newton_solver = NewtonSolver(MPI.comm_world) - self.newton_solver.parameters["error_on_nonconvergence"] = False self.newton_solver.parameters["absolute_tolerance"] = self.absolute_tolerance self.newton_solver.parameters["relative_tolerance"] = self.relative_tolerance self.newton_solver.parameters["maximum_iterations"] = self.maximum_iterations diff --git a/festim/temperature/temperature_solver.py b/festim/temperature/temperature_solver.py index e365e3243..d7a9cf939 100644 --- a/festim/temperature/temperature_solver.py +++ b/festim/temperature/temperature_solver.py @@ -223,7 +223,6 @@ def define_variational_problem(self, materials, mesh, dt=None): def define_newton_solver(self): """Creates the Newton solver and sets its parameters""" self.newton_solver = f.NewtonSolver(f.MPI.comm_world) - self.newton_solver.parameters["error_on_nonconvergence"] = False self.newton_solver.parameters["absolute_tolerance"] = self.absolute_tolerance self.newton_solver.parameters["relative_tolerance"] = self.relative_tolerance self.newton_solver.parameters["maximum_iterations"] = self.maximum_iterations diff --git a/test/unit/test_temperature.py b/test/unit/test_temperature.py index ee1bca53b..ff5a0e946 100644 --- a/test/unit/test_temperature.py +++ b/test/unit/test_temperature.py @@ -262,3 +262,25 @@ def test_temperature_from_xdmf(tmpdir): temperature = festim.TemperatureFromXDMF(T_file, "T") assert temperature.is_steady_state() + + +def test_heat_transfer_default_solver(): + """ + Tests that the default parameters for the Newton solver + of HeatTransferProblem are correct + """ + + heat_solver = festim.HeatTransferProblem() + heat_solver.define_newton_solver() + + default_settings = { + "absolute_tolerance": 1e-3, + "relative_tolerance": 1e-10, + "maximum_iterations": 30, + "linear_solver": None, + "preconditioner": "default", + "error_on_nonconvergence": True, + } + + for key in default_settings.keys(): + assert default_settings[key] == heat_solver.newton_solver.parameters[key] diff --git a/test/unit/test_traps/test_extrinsic_trap.py b/test/unit/test_traps/test_extrinsic_trap.py index 5eb44c92f..d48489c59 100644 --- a/test/unit/test_traps/test_extrinsic_trap.py +++ b/test/unit/test_traps/test_extrinsic_trap.py @@ -79,12 +79,31 @@ def test_create_form_density(self): print(self.my_trap.form_density) assert self.my_trap.form_density.equals(expected_form) + def test_default_solver_parameters(self): + """ + A test to check that the default parameters for the Newton solver + of ExtrinsicTrap are correct + """ + self.my_trap.define_newton_solver() + + default_settings = { + "absolute_tolerance": 1e0, + "relative_tolerance": 1e-10, + "maximum_iterations": 30, + "linear_solver": None, + "preconditioner": "default", + "error_on_nonconvergence": True, + } + + for key in default_settings.keys(): + assert default_settings[key] == self.my_trap.newton_solver.parameters[key] + def test_solver_parameters(self): """ A test to ensure the extrinsic trap solver parameters can be accessed """ - self.my_trap.absolute_tolerance = 1 - self.my_trap.relative_tolerance = 1 + self.my_trap.absolute_tolerance = 1.0 + self.my_trap.relative_tolerance = 1.0 self.my_trap.maximum_iterations = 1 self.my_trap.linear_solver = "mumps" self.my_trap.preconditioner = "icc" From 96d70f82e492f680c0af7c9051553f5829c516fb Mon Sep 17 00:00:00 2001 From: KulaginVladimir Date: Mon, 12 Aug 2024 11:43:46 +0300 Subject: [PATCH 2/2] commit suggestions --- festim/concentration/traps/extrinsic_trap.py | 1 + festim/temperature/temperature_solver.py | 1 + 2 files changed, 2 insertions(+) diff --git a/festim/concentration/traps/extrinsic_trap.py b/festim/concentration/traps/extrinsic_trap.py index 7cc6bf54b..78a450309 100644 --- a/festim/concentration/traps/extrinsic_trap.py +++ b/festim/concentration/traps/extrinsic_trap.py @@ -73,6 +73,7 @@ def newton_solver(self, value): def define_newton_solver(self): """Creates the Newton solver and sets its parameters""" self.newton_solver = NewtonSolver(MPI.comm_world) + self.newton_solver.parameters["error_on_nonconvergence"] = True self.newton_solver.parameters["absolute_tolerance"] = self.absolute_tolerance self.newton_solver.parameters["relative_tolerance"] = self.relative_tolerance self.newton_solver.parameters["maximum_iterations"] = self.maximum_iterations diff --git a/festim/temperature/temperature_solver.py b/festim/temperature/temperature_solver.py index d7a9cf939..c35a635a0 100644 --- a/festim/temperature/temperature_solver.py +++ b/festim/temperature/temperature_solver.py @@ -223,6 +223,7 @@ def define_variational_problem(self, materials, mesh, dt=None): def define_newton_solver(self): """Creates the Newton solver and sets its parameters""" self.newton_solver = f.NewtonSolver(f.MPI.comm_world) + self.newton_solver.parameters["error_on_nonconvergence"] = True self.newton_solver.parameters["absolute_tolerance"] = self.absolute_tolerance self.newton_solver.parameters["relative_tolerance"] = self.relative_tolerance self.newton_solver.parameters["maximum_iterations"] = self.maximum_iterations