diff --git a/src/festim/hydrogen_transport_problem.py b/src/festim/hydrogen_transport_problem.py index ae7762470..ed9c265b8 100644 --- a/src/festim/hydrogen_transport_problem.py +++ b/src/festim/hydrogen_transport_problem.py @@ -400,6 +400,11 @@ def initialise_exports(self): export.D = D export.D_expr = D_expr + # reset the data and time for SurfaceQuantity and VolumeQuantity + if isinstance(export, (exports.SurfaceQuantity, exports.VolumeQuantity)): + export.t = [] + export.data = [] + def define_D_global(self, species): """Defines the global diffusion coefficient for a given species diff --git a/test/test_h_transport_problem.py b/test/test_h_transport_problem.py index ee64ba876..b6639d8a4 100644 --- a/test/test_h_transport_problem.py +++ b/test/test_h_transport_problem.py @@ -348,6 +348,35 @@ def test_initialise_exports_multiple_exports_same_species(): assert Ds[0].x.array[0] == Ds[1].x.array[0] +def test_export_resets_quantities(): + """Test that the export.data and export.t are correctly reset every time a simulation is initiated.""" + my_mat = F.Material(D_0=1, E_D=0) + H = F.Species("H") + surf = F.SurfaceSubdomain1D(id=1, x=4) + + my_export = F.SurfaceFlux( + field=H, + surface=surf, + ) + + my_model = F.HydrogenTransportProblem( + mesh=F.Mesh1D([0, 1, 2, 3, 4]), + subdomains=[F.VolumeSubdomain1D(id=1, borders=[0, 4], material=my_mat), surf], + species=[H], + temperature=400, + exports=[my_export], + ) + + my_model.settings = F.Settings(atol=1e-15, rtol=1e-15, transient=False) + + for i in range(3): + my_model.initialise() + my_model.run() + + assert my_model.exports[0].t == [0.0] + assert my_model.exports[0].data == [0.0] + + def test_define_D_global_multispecies(): """Test that the D_global object is correctly defined when there are multiple species in one subdomain"""