Skip to content

Commit

Permalink
Merge pull request #769 from RemDelaporteMathurin/error-message-final…
Browse files Browse the repository at this point in the history
…-time

Add error message when no final time is provided in transient simulations
  • Loading branch information
RemDelaporteMathurin authored May 31, 2024
2 parents 315aebd + 38677a7 commit cc62108
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def initialise(self):
# check that dt attribute is None if the sim is steady state
if not self.settings.transient and self.dt is not None:
raise AttributeError("dt must be None in steady state simulations")
if self.settings.transient and self.settings.final_time is None:
raise AttributeError(
"final_time argument must be provided to settings in transient simulations"
)
if self.settings.transient and self.dt is None:
raise AttributeError("dt must be provided in transient simulations")
if not self.T:
Expand Down
26 changes: 26 additions & 0 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,29 @@ def test_error_is_raised_when_no_temp():

with pytest.raises(AttributeError, match="Temperature is not defined"):
my_model.initialise()


def test_error_raised_when_no_final_time():
"""
Creates a Simulation object and checks that a AttributeError is raised
when .initialise() is called without a final_time argument
"""

my_model = F.Simulation()

my_model.mesh = F.MeshFromVertices([0, 1, 2, 3])

my_model.materials = F.Material(D_0=1, E_D=0, id=1)

my_model.T = F.Temperature(500)

my_model.settings = F.Settings(
absolute_tolerance=1e-10,
relative_tolerance=1e-10,
transient=True,
)

my_model.dt = F.Stepsize(1)

with pytest.raises(AttributeError, match="final_time argument must be provided"):
my_model.initialise()
1 change: 1 addition & 0 deletions test/system/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_error_transient_without_stepsize():
transient=True,
absolute_tolerance=1e-10,
relative_tolerance=1e-10,
final_time=10,
)

my_model.dt = None
Expand Down

0 comments on commit cc62108

Please sign in to comment.