diff --git a/festim/boundary_conditions/dirichlet_bc.py b/festim/boundary_conditions/dirichlet_bc.py index efe4544a8..b1ca05361 100644 --- a/festim/boundary_conditions/dirichlet_bc.py +++ b/festim/boundary_conditions/dirichlet_bc.py @@ -99,8 +99,10 @@ def create_value( if "t" in arguments and "x" not in arguments and "T" not in arguments: # only t is an argument - if isinstance(self.value(t=float(t)), Operator): - raise ValueError("wrong type for temperature") + if not isinstance(self.value(t=float(t)), (float, int)): + raise ValueError( + f"self.value should return a float or an int, not {type(self.value(t=float(t)))} " + ) self.value_fenics = F.as_fenics_constant( mesh=mesh, value=self.value(t=float(t)) ) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 7ff3ddd46..6017307d7 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -197,8 +197,10 @@ def define_temperature(self): elif callable(self.temperature): arguments = self.temperature.__code__.co_varnames if "t" in arguments and "x" not in arguments and "T" not in arguments: - if isinstance(self.temperature(t=float(self.t)), Operator): - raise ValueError("wrong type for temperature") + if not isinstance(self.temperature(t=float(self.t)), (float, int)): + raise ValueError( + f"self.temperature should return a float or an int, not {type(self.temperature(t=float(self.t)))} " + ) # only t is an argument self.temperature_fenics = F.as_fenics_constant( mesh=self.mesh.mesh, value=self.temperature(t=float(self.t)) diff --git a/test/test_dirichlet_bc.py b/test/test_dirichlet_bc.py index e0bbeaf92..ea17569b7 100644 --- a/test/test_dirichlet_bc.py +++ b/test/test_dirichlet_bc.py @@ -304,7 +304,9 @@ def test_define_value_error_if_ufl_conditional_t_only(value): t = fem.Constant(mesh, 0.0) - with pytest.raises(ValueError, match="wrong type for temperature"): + with pytest.raises( + ValueError, match="self.value should return a float or an int, not " + ): bc.create_value(mesh=mesh, function_space=None, temperature=None, t=t) diff --git a/test/test_h_transport_problem.py b/test/test_h_transport_problem.py index 53b308845..09680016e 100644 --- a/test/test_h_transport_problem.py +++ b/test/test_h_transport_problem.py @@ -116,7 +116,9 @@ def test_define_temperature_error_if_ufl_conditional_t_only(input): my_model.temperature = input - with pytest.raises(ValueError, match="wrong type for temperature"): + with pytest.raises( + ValueError, match="self.temperature should return a float or an int, not " + ): my_model.define_temperature()