Skip to content

Commit

Permalink
Merge pull request #733 from Allentro/reset_quantities
Browse files Browse the repository at this point in the history
Reset derived quantity objects data and t at the beginning of a simulation
  • Loading branch information
RemDelaporteMathurin authored Nov 4, 2024
2 parents db4ad6f + e26c4f3 commit ed67331
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit ed67331

Please sign in to comment.