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 quantities data #772

Merged
merged 3 commits into from
Jun 11, 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 festim/exports/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def initialise_derived_quantities(self, dx, ds, materials):
"""
for export in self:
if isinstance(export, festim.DerivedQuantities):
# reset the data of the derived quantities
export.data = []
export.t = []
for quantity in export:
quantity.t = []
quantity.data = []
export.assign_measures_to_quantities(dx, ds)
export.assign_properties_to_quantities(materials)
27 changes: 27 additions & 0 deletions test/system/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,33 @@ def test_materials_setter():
assert my_model.materials is test_materials


def test_derived_quantities_data_is_reset():
"""
Checks that the data of a derived quantity is reset at each timestep
"""
my_model = F.Simulation()

my_model.mesh = F.MeshFromVertices([0, 1, 2, 3, 4])

my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = F.Temperature(400)

left_flux = F.SurfaceFlux(field="solute", surface=1)

my_model.exports = [F.DerivedQuantities([left_flux])]

my_model.settings = F.Settings(
absolute_tolerance=1e-15,
relative_tolerance=1e-15,
transient=False,
)

for i in range(3):
my_model.initialise()
assert len(left_flux.data) == 0
my_model.run()


class TestFestimProblem:
"""Tests the methods of the festim.Problem class"""

Expand Down
Loading