diff --git a/festim/concentration/traps/extrinsic_trap.py b/festim/concentration/traps/extrinsic_trap.py index b6b0c9f27..78a450309 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,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"] = False + 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 e365e3243..c35a635a0 100644 --- a/festim/temperature/temperature_solver.py +++ b/festim/temperature/temperature_solver.py @@ -223,7 +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"] = False + 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/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"