Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset derived quantity objects data and t at the beginning of a simulation #733

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
Comment on lines +357 to +360
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you parametrise this test to also check for other derived quantities (eg. TotalVolume)


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
Loading