diff --git a/FESTIM/temperature/temperature_from_xdmf.py b/FESTIM/temperature/temperature_from_xdmf.py index 2cb514b21..265358ab4 100644 --- a/FESTIM/temperature/temperature_from_xdmf.py +++ b/FESTIM/temperature/temperature_from_xdmf.py @@ -40,3 +40,9 @@ def create_functions(self, mesh): self.T_n = f.Function(V, name="T_n") self.T_n.assign(self.T) + + def update(self, t): + """Allows for the use of this class in transient h transport cases, + refer to issue #499 + """ + pass diff --git a/Tests/unit/test_temperature.py b/Tests/unit/test_temperature.py index 9e7d13212..954b3262b 100644 --- a/Tests/unit/test_temperature.py +++ b/Tests/unit/test_temperature.py @@ -3,6 +3,7 @@ from ufl.core.multiindex import Index from pathlib import Path import pytest +import numpy as np def test_formulation_heat_transfer_2_ids_per_mat(): @@ -136,3 +137,32 @@ def test_temperature_from_xdmf_label_checker(tmpdir): # read file with wrong label specified with pytest.raises(ValueError): FESTIM.TemperatureFromXDMF(filename=str(Path(T_file)), label="coucou") + + +def test_temperature_from_xdmf_transient_case(tmpdir): + """Test that the TemperatureFromXdmf class works in a transient + h transport case""" + # create temperature field xdmf + my_model = FESTIM.Simulation(log_level=20) + my_model.mesh = FESTIM.MeshFromVertices(vertices=np.linspace(0, 1, num=100)) + my_model.materials = FESTIM.Materials([FESTIM.Material(1, 1, 1)]) + my_model.T = FESTIM.Temperature(value=300) + my_model.settings = FESTIM.Settings( + transient=False, + absolute_tolerance=1e12, + relative_tolerance=1e-08, + ) + my_model.initialise() + T = my_model.T.T + T_file = tmpdir.join("T.xdmf") + fenics.XDMFFile(str(Path(T_file))).write_checkpoint( + T, "T", 0, fenics.XDMFFile.Encoding.HDF5, append=False + ) + + # run transient simulation with TemperatureFromXDMF class + my_model.T = FESTIM.TemperatureFromXDMF(filename=str(Path(T_file)), label="T") + my_model.dt = FESTIM.Stepsize(initial_value=1) + my_model.settings.transient = True + my_model.settings.final_time = 10 + my_model.initialise() + my_model.run()