-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix bug with calculations on small timescales #682
Conversation
Very nice MWE @KulaginVladimir , would you mind making use of it in a test that catches the bug? I think you can do something like: def test_small_timesteps_final_time_bug():
"""Some description"""
my_model = F.Simulation(log_level = 40)
my_model.mesh = F.MeshFromVertices(np.linspace(0, 1, 10))
my_model.materials = F.Material(
id=1,
D_0=1,
E_D=0.1,
)
my_model.T = F.Temperature(1000)
my_model.settings = F.Settings(
absolute_tolerance=1e-10,
relative_tolerance=1e-10,
final_time=1e-7,
)
my_model.dt = F.Stepsize(
initial_value=1e-10,
)
my_model.initialise()
my_model.run()
assert np.isclose(my_model.t, my_model.settings.final_time, atol=0.0) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #682 +/- ##
=======================================
Coverage 98.93% 98.93%
=======================================
Files 57 57
Lines 2154 2154
=======================================
Hits 2131 2131
Misses 23 23 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @KulaginVladimir just a small comment on my side, Thanks for this fix! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me thanks @KulaginVladimir
Proposed changes
When performing simulations on small timescales (e.g.,
final_time=1e-7
), some bugs appear due to the use ofnp.isclose
with the default parameters (atol, rtol). For example (see below), computation stops without reaching the final time. As @RemDelaporteMathurin suggested, the current PR attempts to fix the bug by settingatol=0
innp.isclose
.Types of changes
What types of changes does your code introduce to FESTIM?
Checklist
Further comments
MWE:
Stops at 90%: