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 2 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
4 changes: 3 additions & 1 deletion festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = []
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
# if name of species is given then replace with species object
if isinstance(export.field, list):
for idx, field in enumerate(export.field):
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 @@ -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,
)
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