From 348283a7b84491e087b4eff6d14b32f0a0059a2b Mon Sep 17 00:00:00 2001 From: J Dark Date: Thu, 19 Oct 2023 17:14:07 -0400 Subject: [PATCH] use atol and rtol --- festim/hydrogen_transport_problem.py | 4 ++-- festim/settings.py | 16 ++++++++-------- test/test_dirichlet_bc.py | 4 +--- test/test_permeation_problem.py | 8 ++++---- test/test_sievertsbc.py | 4 +--- test/test_vtx.py | 2 +- test/test_xdmf.py | 4 +--- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index c1127d5c9..799eb9aa8 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -258,8 +258,8 @@ def create_solver(self): bcs=self.bc_forms, ) self.solver = NewtonSolver(MPI.COMM_WORLD, problem) - self.solver.atol = self.settings.absolute_tolerance - self.solver.rtol = self.settings.relative_tolerance + self.solver.atol = self.settings.atol + self.solver.rtol = self.settings.rtol self.solver.max_it = self.settings.max_iterations def run(self): diff --git a/festim/settings.py b/festim/settings.py index fbd062299..9becc0c61 100644 --- a/festim/settings.py +++ b/festim/settings.py @@ -2,16 +2,16 @@ class Settings: """Settings for a festim simulation. Args: - absolute_tolerance (float): Absolute tolerance for the solver. - relative_tolerance (float): Relative tolerance for the solver. + atol (float): Absolute tolerance for the solver. + rtol (float): Relative tolerance for the solver. max_iterations (int, optional): Maximum number of iterations for the solver. final_time (float, optional): Final time for a transient simulation. stepsize (festim.Stepsize, optional): stepsize for a transient simulation. Attributes: - absolute_tolerance (float): Absolute tolerance for the solver. - relative_tolerance (float): Relative tolerance for the solver. + atol (float): Absolute tolerance for the solver. + rtol (float): Relative tolerance for the solver. max_iterations (int, optional): Maximum number of iterations for the solver. final_time (float, optional): Final time for a transient simulation. stepsize (festim.Stepsize, optional): stepsize for a transient @@ -20,14 +20,14 @@ class Settings: def __init__( self, - absolute_tolerance, - relative_tolerance, + atol, + rtol, max_iterations=30, final_time=None, stepsize=None, ) -> None: - self.absolute_tolerance = absolute_tolerance - self.relative_tolerance = relative_tolerance + self.atol = atol + self.rtol = rtol self.max_iterations = max_iterations self.final_time = final_time self.stepsize = stepsize diff --git a/test/test_dirichlet_bc.py b/test/test_dirichlet_bc.py index 2b6ac6d66..48e7ac36f 100644 --- a/test/test_dirichlet_bc.py +++ b/test/test_dirichlet_bc.py @@ -281,9 +281,7 @@ def test_integration_with_HTransportProblem(value): my_model.temperature = fem.Constant(my_model.mesh.mesh, 550.0) - my_model.settings = F.Settings( - absolute_tolerance=1, relative_tolerance=0.1, final_time=2 - ) + my_model.settings = F.Settings(atol=1, rtol=0.1, final_time=2) my_model.settings.stepsize = F.Stepsize(initial_value=1) # RUN diff --git a/test/test_permeation_problem.py b/test/test_permeation_problem.py index 631f6cb2f..2e2742e0e 100644 --- a/test/test_permeation_problem.py +++ b/test/test_permeation_problem.py @@ -36,8 +36,8 @@ def test_permeation_problem(mesh_size=1001): my_model.exports = [F.XDMFExport("mobile_concentration.xdmf", field=mobile_H)] my_model.settings = F.Settings( - absolute_tolerance=1e10, - relative_tolerance=1e-10, + atol=1e10, + rtol=1e-10, max_iterations=30, final_time=50, ) @@ -130,8 +130,8 @@ def test_permeation_problem_multi_volume(): my_model.exports = [F.VTXExport("test.bp", field=mobile_H)] my_model.settings = F.Settings( - absolute_tolerance=1e10, - relative_tolerance=1e-10, + atol=1e10, + rtol=1e-10, max_iterations=30, final_time=50, ) diff --git a/test/test_sievertsbc.py b/test/test_sievertsbc.py index 96ed7bc5d..2e73780d5 100644 --- a/test/test_sievertsbc.py +++ b/test/test_sievertsbc.py @@ -93,9 +93,7 @@ def test_integration_with_HTransportProblem(pressure): my_model.temperature = fem.Constant(my_model.mesh.mesh, 550.0) - my_model.settings = F.Settings( - absolute_tolerance=1, relative_tolerance=0.1, final_time=2 - ) + my_model.settings = F.Settings(atol=1, rtol=0.1, final_time=2) my_model.settings.stepsize = F.Stepsize(initial_value=1) # RUN diff --git a/test/test_vtx.py b/test/test_vtx.py index 12b4e5f28..15c7ded6e 100644 --- a/test/test_vtx.py +++ b/test/test_vtx.py @@ -60,7 +60,7 @@ def test_vtx_integration_with_h_transport_problem(tmpdir): filename = str(tmpdir.join("my_export.bp")) my_export = F.VTXExport(filename, field=my_model.species[0]) my_model.exports = [my_export] - my_model.settings = F.Settings(absolute_tolerance=1, relative_tolerance=0.1) + my_model.settings = F.Settings(atol=1, rtol=0.1) my_model.settings.stepsize = F.Stepsize(initial_value=1) my_model.initialise() diff --git a/test/test_xdmf.py b/test/test_xdmf.py index dcc63e7a1..cc1e57a25 100644 --- a/test/test_xdmf.py +++ b/test/test_xdmf.py @@ -47,9 +47,7 @@ def test_integration_with_HTransportProblem(tmp_path): filename = os.path.join(tmp_path, "test.xdmf") my_model.exports = [F.XDMFExport(filename=filename, field=my_model.species)] - my_model.settings = F.Settings( - absolute_tolerance=1, relative_tolerance=0.1, final_time=1 - ) + my_model.settings = F.Settings(atol=1, rtol=0.1, final_time=1) my_model.settings.stepsize = F.Stepsize(initial_value=0.5) my_model.initialise() my_model.run()