-
Notifications
You must be signed in to change notification settings - Fork 199
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
Synchronize velocity for diagnostics #1751
base: development
Are you sure you want to change the base?
Synchronize velocity for diagnostics #1751
Conversation
Source/Evolve/WarpXEvolve.cpp
Outdated
(step == numsteps_max-1) || | ||
(synchronize_velocity_for_diagnostics && | ||
(multi_diags->DoComputeAndPack(step) || | ||
reduced_diags->DoDiags(step)))) { |
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.
The above if
condition looks like should not modify the default behavior of the code (which is probably what we want). However, it seems that a lot of automated tests are failing because of checkSum
differences. @dpgrote Do you understand why?
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.
Also, could you explain why this block of code was moved here?
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 @RemiLehe - I moved the block of code to the end of the loop so that the state of the data when the half v push is done is the same as it will be at the start of the next step when the half push will be undone. Ideally, they should exactly cancel each other. This is particularly important when running with electrostatic where the push needs to be done after the new fields are computed. It seems that this block should be here anyway, since the field gather done in the PushP should be done after the particle boundary conditions are applied.
This would explain why some of the CI tests are failing, that something was changed between where this block was and where it is now. I'll look into it to understand what is happening.
Thanks for answering the above question. |
Thanks @ax3l . I need to get back to this one and finish it. There are some CI differences that I need to make sure I understand. |
…velocity_for_diagnostics
…velocity_for_diagnostics
@dpgrote Should we change this to |
…velocity_for_diagnostics
…velocity_for_diagnostics
…velocity_for_diagnostics
…velocity_for_diagnostics
…velocity_for_diagnostics
…velocity_for_diagnostics
0fe6cbe
to
a3a823a
Compare
Source/Evolve/WarpXEvolve.cpp
Outdated
@@ -217,8 +217,16 @@ WarpX::Evolve (int numsteps) | |||
// B : guard cells are NOT up-to-date | |||
} | |||
|
|||
if (cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) { | |||
if ((cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) && |
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.
This is a bit long. Maybe a temporary bool could simplify the logic in the if
?
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.
Thanks for the comments! Do you have a suggestion of how to simplify this?
Source/Evolve/WarpXEvolve.cpp
Outdated
// At the end of last step, push p by 0.5*dt to synchronize | ||
// Note that this is potentially buggy since the PushP will do a field gather |
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.
Do we need a couple of input option asserts to avoid potentially buggy behavior?
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.
The buggy behavior regarding particle bounds is not dependent on input options, but will always happen. For the other, Python with electrostatic, this should just be fixed by removing this block of code and using the one below instead. I can do this in a separate PR because it will break a number of CI tests.
Hi Dave, do you think this is a change that we would still like to merge? I think so, I see it was mentioned from another PR last year. If this is still relevant, do you think it is possible to merge |
@EZoni I would still like to have this PR merged. I can merge in |
I took the liberty to merge |
Thanks. The changes look correct, following the same pattern. |
Thanks for checking, @dpgrote. Note that HIP is failing independently of this PR (due to a new ROCm release) and expected to resolve itself in a few days. |
I saw that the HIP checks were finally fixed, but there was another minor merge conflict, so I merged |
Source/Evolve/WarpXEvolve.cpp
Outdated
if ((cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) && | ||
!synchronize_velocity_for_diagnostics) { |
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.
Can you please add a helper function that returns true/false for if the last step
query of the first part of this if
and then simplify this if
?
Also, you can reuse the logic for the if
below.
makes the if look like
if (end_of_last_step && !synchronize_velocity_for_diagnostics)
// existing if
...
if (end_of_last_step && (other_stuff || synchronize_velocity_for_diagnostics))
// extra if below that was added
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.
Is this better?
Source/Evolve/WarpXEvolve.cpp
Outdated
@@ -309,6 +317,15 @@ WarpX::Evolve (int numsteps) | |||
ExecutePythonCallback("afterEsolve"); | |||
} | |||
|
|||
if (synchronize_velocity_for_diagnostics && | |||
(multi_diags->DoComputeAndPack(step) || reduced_diags->DoDiags(step) || |
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.
Please see suggestion above.
Please assign the logic behind multi_diags->DoComputeAndPack(step) || reduced_diags->DoDiags(step)
to a named boolean as well, because otherwise this if
gets a bit involved to read.
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.
Better?
for more information, see https://pre-commit.ci
uz -= -e / m_e * Ez * dt / 2.0 | ||
|
||
# Leap frog advance | ||
for i in range(5): |
Check notice
Code scanning / CodeQL
Unused global variable Note
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.
To fix CodeQL's issue:
for i in range(5): | |
for _ in range(5): |
This PR allows the synchronization in time of the particle velocities and positions when generating diagnostics. Without this option, the particle velocities will lag behind the position by a half time step. This adds the boolean input parameter
warpx.synchronize_velocity_for_diagnostics
to turn on this option, defaulting to false.There are several pieces to this PR:
MultiDiagnostic
andMultiReducedDiags
adding routines to check if any diagnostics will be donePushP
to just before the diagnostics are done (to get the updated fields from the electrostatic calculation)What
Evolve
does is if the synchronization is to be done, advance the velocity a half step just before the diagnostics and setsis_synchronized=true
. Then at the start of the next step, ifis_synchronized
is true, push the velocities back a half step to be ready for the full leap frog advance.Comments:
m_intervals
in its ComputeDiags.