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

Patch derived quantities not exported at final timestep when stepsize is small #567

Merged
merged 2 commits into from
Aug 22, 2023
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
2 changes: 1 addition & 1 deletion festim/exports/derived_quantities/derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def is_export(self, t, final_time, nb_iterations):
nb_its_between_exports = self.nb_iterations_between_exports
if nb_its_between_exports is None:
# export at the end
return t >= final_time
return np.isclose(t, final_time)
else:
# export every N iterations
return nb_iterations % nb_its_between_exports == 0
Expand Down
33 changes: 33 additions & 0 deletions test/system/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,36 @@ def test_finaltime_overshoot():
my_model.run()

assert np.isclose(my_model.t, my_model.settings.final_time)


def test_derived_quantities_exported_last_timestep_with_small_stepsize(tmp_path):
"""test to catch bug #566"""
my_model = F.Simulation()

my_model.mesh = F.MeshFromVertices(np.linspace(0, 1, num=100))

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

my_model.T = F.Temperature(value=300)

my_model.dt = F.Stepsize(
initial_value=99.9999999,
)

my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=100
)

list_of_derived_quantities = [F.TotalVolume("solute", volume=1)]

derived_quantities = F.DerivedQuantities(
list_of_derived_quantities,
filename=f"{tmp_path}/out.csv",
)

my_model.exports = [derived_quantities]

my_model.initialise()
my_model.run()

assert os.path.exists(f"{tmp_path}/out.csv")
Loading