From d4a8d6e010dd6e0deda4151cfffbe91b6b5ffea6 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 30 May 2024 09:56:32 +0200 Subject: [PATCH] added an error message if T attribute is None --- festim/generic_simulation.py | 2 ++ test/simulation/test_initialise.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/festim/generic_simulation.py b/festim/generic_simulation.py index 9efad23c4..805b46911 100644 --- a/festim/generic_simulation.py +++ b/festim/generic_simulation.py @@ -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: diff --git a/test/simulation/test_initialise.py b/test/simulation/test_initialise.py index 83653d93d..f4b5ba1ed 100644 --- a/test/simulation/test_initialise.py +++ b/test/simulation/test_initialise.py @@ -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()