-
Notifications
You must be signed in to change notification settings - Fork 117
Refactor time_stepper #1012
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
base: master
Are you sure you want to change the base?
Refactor time_stepper #1012
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
I love a good red line PR! Will review soon |
Some of test suite failed (with the error close to tolerance, though), so set this PR as draft for now |
small errors when refactoring the time steppers was also seen by @danieljvickers... so long as i'm convinced the code is right we might need a new goldenfile that satiates all the time steppers (or figure out the offending case and set looser tolerance). |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Oh I see.. I put it back to ready for review. Please review the change and let me know if you have any question or concerns! |
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.
High-level Suggestion
To improve readability and maintainability, define the Runge-Kutta coefficients as named constants or parameters instead of hardcoding them in a large if-else
block. [High-level, importance: 6]
Solution Walkthrough:
Before:
subroutine s_initialize_time_steppers_module
...
if (any(time_stepper == (/1, 2, 3/))) then
@:ALLOCATE (rk_coef(time_stepper, 3))
if (time_stepper == 1) then
rk_coef(1, 1) = 1._wp
rk_coef(1, 2) = 0._wp
rk_coef(1, 3) = 1._wp
else if (time_stepper == 2) then
rk_coef(1, 1) = 1._wp; rk_coef(1, 2) = 0._wp; rk_coef(1, 3) = 1._wp
rk_coef(2, 1) = 0.5_wp; rk_coef(2, 2) = 0.5_wp; rk_coef(2, 3) = 0.5_wp
else if (time_stepper == 3) then
...
end if
end if
end subroutine
After:
module m_time_steppers
...
real(wp), parameter :: RK1_COEFS(1,3) = reshape((/ 1.0_wp, 0.0_wp, 1.0_wp /), (/1,3/))
real(wp), parameter :: RK2_COEFS(2,3) = reshape((/ 1.0_wp, 0.0_wp, 1.0_wp, &
0.5_wp, 0.5_wp, 0.5_wp /), (/2,3/))
...
contains
subroutine s_initialize_time_steppers_module
...
if (time_stepper == 1) then
rk_coef = RK1_COEFS
else if (time_stepper == 2) then
rk_coef = RK2_COEFS
...
end if
end subroutine
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
Oh yeah, I tried to do something similar a few months ago, but kept getting weird compiler-dependent bugs that I couldn't reproduce locally. I like this PR. Looks like it is reducing a lot of the redundant code in the time_stepper. Seems odd that you are failing so many tests by so little. I would be interested to also see how far off of the golden files you are for the tests that pass, and see if they are similar. |
@hyeoksu-lee status on this? was working i guess, but now everything is failing? |
@sbryngelson All failing CPU tests are due to error of the order of 1e-10, which is tolerance level. I am looking into the code to see if there is any systematic issue. And I am waiting for @wilfonba to review body force input for RK2. In the meantime, I need to fix GPU bug, which seems not a simple tolerance-type issue. |
@sbryngelson @danieljvickers I found the source of the slightly large error in failing cases. The original time-stepper code was updating the conservative variables, for example, by
Previously, I changed this to
where Accordingly, I changed the code to
where |
@sbryngelson MacOS runners fail to build MFC due to cantera version compatibility. But I haven't changed anything about installations, and test suite passed on my MacBook M4 Pro. Do you have any idea?
|
@hyeoksu-lee Look at this commit related to the cantera issue: 9dc62dd |
@danieljvickers Thanks! I updated |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1012 +/- ##
==========================================
+ Coverage 41.75% 41.82% +0.07%
==========================================
Files 70 70
Lines 20126 19921 -205
Branches 2504 2490 -14
==========================================
- Hits 8403 8332 -71
+ Misses 10180 10043 -137
- Partials 1543 1546 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Is this verified to give the correct answer with unified memory? |
We have no tests with unified memory... |
Well, anyone can run |
@wilfonba Can I simply run |
./mfc.sh test -j 8 --unified -- -c frontier after loading modules should do the trick. You'll need a compute node |
@wilfonba |
User description
Description
This PR refactors time_stepper routines by integrating s_1st_order_tvd_rk, s_2nd_order_tvd_rk, s_3rd_order_tvd_rk, s_strang_splitting into a single subroutine s_tvd_rk.
Type of change
Scope
If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.
How Has This Been Tested?
test suite passed on MacBook M4 Pro, NCSA Delta GPU (A100), Frontier GPU
Checklist
docs/
)examples/
that demonstrate my new feature performing as expected.They run to completion and demonstrate "interesting physics"
./mfc.sh format
before committing my codeIf your code changes any code source files (anything in
src/simulation
)To make sure the code is performing as expected on GPU devices, I have:
nvtx
ranges so that they can be identified in profiles./mfc.sh run XXXX --gpu -t simulation --nsys
, and have attached the output file (.nsys-rep
) and plain text results to this PR./mfc.sh run XXXX --gpu -t simulation --rsys --hip-trace
, and have attached the output file and plain text results to this PR.PR Type
Enhancement
Description
Consolidate four separate TVD RK time-stepping subroutines into single unified
s_tvd_rk
Replace conditional calls with unified interface accepting
nstage
parameterAdd Runge-Kutta coefficient matrix for different time-stepping orders
Integrate adaptive time-stepping for bubble dynamics into unified routine
Diagram Walkthrough
File Walkthrough
m_start_up.fpp
Simplify time-stepper invocation logic
src/simulation/m_start_up.fpp
s_tvd_rk
calltime_stepper
parameter to unified routinem_time_steppers.fpp
Consolidate TVD RK time-stepping implementations
src/simulation/m_time_steppers.fpp
s_1st_order_tvd_rk
,s_2nd_order_tvd_rk
,s_3rd_order_tvd_rk
,s_strang_splitting
)s_tvd_rk
subroutine with stage loop and RK coefficientmatrix