Skip to content

Commit

Permalink
use atol and rtol
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Oct 19, 2023
1 parent e557fa8 commit 348283a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions festim/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 1 addition & 3 deletions test/test_dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/test_permeation_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
4 changes: 1 addition & 3 deletions test/test_sievertsbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_vtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions test/test_xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 348283a

Please sign in to comment.