Skip to content

Commit

Permalink
Merge pull request #772 from festim-dev/reset-derived-quantities
Browse files Browse the repository at this point in the history
Reset derived quantities data
  • Loading branch information
RemDelaporteMathurin authored Jun 11, 2024
2 parents 36da67b + 293965d commit 0c88769
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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

0 comments on commit 0c88769

Please sign in to comment.