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

Fix intern time integration method with fixed time step #1919

Merged
merged 14 commits into from
May 6, 2024

Conversation

bennibolm
Copy link
Contributor

@bennibolm bennibolm commented Apr 26, 2024

Save the manually set time step to allow simulations without a stepsize callback. Before it was overwritten within modify_dt_for_tstops!.

Copy link
Contributor

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.10%. Comparing base (cd097fc) to head (9f0d930).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1919      +/-   ##
==========================================
+ Coverage   91.96%   96.10%   +4.13%     
==========================================
  Files         451      451              
  Lines       36218    36241      +23     
==========================================
+ Hits        33307    34826    +1519     
+ Misses       2911     1415    -1496     
Flag Coverage Δ
unittests 96.10% <100.00%> (+4.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bennibolm bennibolm marked this pull request as ready for review April 29, 2024 08:32
@bennibolm bennibolm requested a review from amrueda April 29, 2024 08:32
@DanielDoehring
Copy link
Contributor

You confirmed that one can now set the time step manually, right?

@bennibolm
Copy link
Contributor Author

bennibolm commented Apr 30, 2024

You confirmed that one can now set the time step manually, right?

Basically yes. The time step set was just ignored after #1677.
I just tested all setups again and found a new bug I created when actually using the SaveSolutionCallback with a fixed dt interval. I'll take a look at it and hopefully fix it.

@bennibolm bennibolm marked this pull request as draft April 30, 2024 13:32
@DanielDoehring
Copy link
Contributor

Okay, feel free to notify me when you think this is ready!

@bennibolm
Copy link
Contributor Author

bennibolm commented Apr 30, 2024

I'm a little bit lost right now. The first problem was that if we want to use a fixed time step (so with disabled stepsize callback), the time step is set to tspan[1]-t (or tstop-t when the savesolution callback saves every fixed time interval).
The overwriting process is done in modify_dt_for_tstops!.
So, I added the current dt to each minimum calculation in there (which is by the way not done in OrdinaryDiffEq's modify_dt_for_tstops!).

But now, if we are close to one of these tstops the time step is set to the needed minimum. So, it works to get the correct time step. But after this timestep, dt stays at this small values. This is of course expected since I added the minimum of dt and something bigger the calculation.
For instance: using a fixes dt of dt = 1.0e-3, tspan = (0.0, 1.0) and

save_solution = SaveSolutionCallback(dt = 0.1+1.0e-6,
                                     save_initial_solution = true,
                                     save_final_solution = true,
                                     solution_variables = cons2prim)

The timesteps are

#timesteps:      1 │ Δt: 1.0000e-03 │ sim. time: 1.0000e-03 (0.100%)   │ run time: 8.6168e-03 s
#timesteps:      2 │ Δt: 1.0000e-03 │ sim. time: 2.0000e-03 (0.200%)   │ run time: 1.5407e-02 s
#timesteps:      3 │ Δt: 1.0000e-03 │ sim. time: 3.0000e-03 (0.300%)   │ run time: 2.2556e-02 s
...
#timesteps:     99 │ Δt: 1.0000e-03 │ sim. time: 9.9000e-02 (9.900%)   │ run time: 7.0780e-01 s
#timesteps:    100 │ Δt: 1.0000e-03 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.1488e-01 s
#timesteps:    101 │ Δt: 1.0000e-06 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.2227e-01 s
#timesteps:    102 │ Δt: 1.0000e-06 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.3212e-01 s
#timesteps:    103 │ Δt: 1.0000e-06 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.3887e-01 s
#timesteps:    104 │ Δt: 1.0000e-06 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.5214e-01 s
#timesteps:    105 │ Δt: 1.0000e-06 │ sim. time: 1.0000e-01 (10.000%)  │ run time: 7.7050e-01 s
#timesteps:    106 │ Δt: 1.0000e-06 │ sim. time: 1.0001e-01 (10.001%)  │ run time: 7.9454e-01 s
....

@ranocha Do you have an idea how to fix this or how it is done in OrdinaryDiffEq (as I said, OrdinaryDiffEq uses the same version of modify_dt_for_tstops! as in our main right now, see here).

EDIT: An idea would be to add a variable to the integrator which saves the set time step for the whole simulation and reset dt with it for instance after every time step. But this seems to be a bit ugly. Maybe OrdinaryDiffEq has a better solution for this. Unfortunately, I can't find anything right now.

@ranocha
Copy link
Member

ranocha commented May 1, 2024

OrdinaryDiffEq.jl has a working implementation:

julia> using OrdinaryDiffEq

julia> ode = ODEProblem((du, u, p, t) -> du .= u, [1.0], (0.0, 1.0))
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 1.0)
u0: 1-element Vector{Float64}:
 1.0

julia> sol = solve(ode, Euler(); adaptive = false, dt = 0.11, tstops = (0.5))
retcode: Success
Interpolation: 3rd order Hermite
t: 11-element Vector{Float64}:
 0.0
 0.11
 0.22
 0.33
 0.44
 0.5
 0.61
 0.72
 0.83
 0.94
 1.0
u: 11-element Vector{Vector{Float64}}:
 [1.0]
 [1.11]
 [1.2321000000000002]
 [1.3676310000000003]
 [1.5180704100000002]
 [1.6091546346000003]
 [1.7861616444060002]
 [1.9826394252906603]
 [2.200729762072633]
 [2.4428100359006226]
 [2.58937863805466]

@ranocha
Copy link
Member

ranocha commented May 1, 2024

Note the dtcache in the code you linked above

@bennibolm
Copy link
Contributor Author

Note the dtcache in the code you linked above

Oh yes. Thanks a lot

@bennibolm bennibolm requested review from ranocha and removed request for amrueda May 2, 2024 11:32
@bennibolm bennibolm marked this pull request as ready for review May 2, 2024 11:33
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test for this fix?

ranocha
ranocha previously approved these changes May 3, 2024
@ranocha ranocha enabled auto-merge (squash) May 3, 2024 10:40
@bennibolm bennibolm disabled auto-merge May 3, 2024 10:40
@bennibolm bennibolm enabled auto-merge (squash) May 3, 2024 11:28
@bennibolm bennibolm merged commit 4fe2824 into trixi-framework:main May 6, 2024
37 checks passed
@bennibolm bennibolm deleted the SSPtimemethod-fixedtimestep branch May 6, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants