Skip to content

Commit

Permalink
Merge pull request #768 from festim-dev/error-message-when-no-temp
Browse files Browse the repository at this point in the history
Error message when temperature is not defined
  • Loading branch information
RemDelaporteMathurin authored May 30, 2024
2 parents c061982 + d4a8d6e commit 315aebd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def initialise(self):
raise AttributeError("dt must be None in steady state simulations")
if self.settings.transient and self.dt is None:
raise AttributeError("dt must be provided in transient simulations")
if not self.T:
raise AttributeError("Temperature is not defined")

# initialise dt
if self.settings.transient:
Expand Down
21 changes: 21 additions & 0 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,24 @@ def test_cartesian_and_surface_flux_warning(quantity, sys):
# test
with pytest.warns(UserWarning, match=f"may not work as intended for {sys} meshes"):
my_model.initialise()


def test_error_is_raised_when_no_temp():
"""
Creates a Simulation object and checks that an AttributeError is raised
when .initialise() is called without a Temperature object defined
"""
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.settings = F.Settings(
absolute_tolerance=1e-10,
relative_tolerance=1e-10,
transient=False,
)

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

0 comments on commit 315aebd

Please sign in to comment.