From a1682eec9d878bb0e2b9a236737352a5f7765629 Mon Sep 17 00:00:00 2001 From: Allentro Date: Tue, 2 Apr 2024 23:42:15 +0100 Subject: [PATCH 1/2] Resetting export.t and export.data in initialise_exports() --- festim/hydrogen_transport_problem.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index af0efd000..8ab9a92ea 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -232,6 +232,7 @@ def volume_meshtags(self, value): raise TypeError(f"value must be of type dolfinx.mesh.MeshTags") def initialise(self): + self.create_species_from_traps() self.define_function_spaces() self.define_meshtags_and_measures() @@ -324,8 +325,9 @@ def define_temperature(self): def initialise_exports(self): """Defines the export writers of the model, if field is given as a string, find species object in self.species""" - for export in self.exports: + export.t = [] + export.data = [] # if name of species is given then replace with species object if isinstance(export.field, list): for idx, field in enumerate(export.field): From f08f0b5c83d11b511a129316d040b61d0bf4f3b1 Mon Sep 17 00:00:00 2001 From: Allentro Date: Tue, 2 Apr 2024 23:45:04 +0100 Subject: [PATCH 2/2] Adding a test to check export.t and export.data have been reset. --- test/test_h_transport_problem.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_h_transport_problem.py b/test/test_h_transport_problem.py index 36c484f02..340f9caa1 100644 --- a/test/test_h_transport_problem.py +++ b/test/test_h_transport_problem.py @@ -337,6 +337,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"""