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

Add Time-Averaged Field Diagnostics #5285

Merged
merged 26 commits into from
Oct 24, 2024

Conversation

n01r
Copy link
Member

@n01r n01r commented Sep 18, 2024

This PR adds time-averaged field diagnostics to the WarpX output

  • code
  • docs
  • tests
  • example
  • meta-data $\Longrightarrow$ Follow-up PR
  • make compatible with adaptive time stepping $\Longrightarrow$ Follow-up PR

Currently, compiling for GPU creates a linking error. We would like to see the CI output to possibly find the issue.
Hence, we do not flag this as WIP right now.

This PR is based on work performed during the 2024 WarpX Refactoring Hackathon and was created together with @RevathiJambunathan. 🙂

Successfully merging this pull request may close #5165.

@n01r n01r added hackathon Let's address this topic during the GPU hackathon component: diagnostics all types of outputs labels Sep 18, 2024
@archermarx
Copy link
Contributor

Thanks for making this PR! One complication is that with #5176, adaptive timestepping will be possible. This means that the timestep length can change, so simply summing the multifabs and dividing by the period won't be enough for a proper time average. I don't think addressing this will be too hard, however.

@n01r
Copy link
Member Author

n01r commented Sep 18, 2024

Thanks, @archermarx! I wasn't aware of that yet. 🙂 We can do a follow-up and catch if dt_update_interval is set. In that case, we could create a cumulative sum weighted with the time step length and also add up the total time as we go. During the flush, we then divide by the total time.

@archermarx
Copy link
Contributor

Thanks, @archermarx! I wasn't aware of that yet. 🙂 We can do a follow-up and catch if dt_update_interval is set. In that case, we could create a cumulative sum weighted with the time step length and also add up the total time as we go. During the flush, we then divide by the total time.

Yep, my thought exactly. The adaptive timestepping PR was just merged, too.

@EZoni
Copy link
Member

EZoni commented Sep 19, 2024

I think #5296 should fix the clang-tidy errors that remain, which don't seem related to this PR.

@ax3l
Copy link
Member

ax3l commented Sep 23, 2024

We can do a follow-up and catch if dt_update_interval is set
...
Yep, my thought exactly. The adaptive timestepping PR was just merged, too.

Thanks for the catch! Please add a runtime assert in this PR now.

@ax3l ax3l self-assigned this Sep 23, 2024
@n01r
Copy link
Member Author

n01r commented Sep 24, 2024

Added commit that will cause the sim to abort when dt_update_interval is set.

The last thing for this PR that remains from our list is the CI tests.

@ax3l, should we also use the recently merged MultiFabRegister?

@n01r
Copy link
Member Author

n01r commented Oct 2, 2024

Just empirically, I tried this in our Laser-Ion Acceleration example. At step 1000, I compared between the electron density output from the in-situ generated averaged output and a post-processed output that I created from 25 instantaneous outputs. The relative difference is on the order of 1e-16. 🎉
Figure 33

Created with the following input script:
inputs_test_2d_laser_ion_acc.txt

@n01r
Copy link
Member Author

n01r commented Oct 2, 2024

And comparing instantaneous output with averaged output for, e.g. Ez shows the much clearer structure one can see with this diagnostic.
image

@RemiLehe RemiLehe assigned EZoni and unassigned ax3l Oct 16, 2024
@EZoni
Copy link
Member

EZoni commented Oct 16, 2024

@n01r @RevathiJambunathan
After resolving the merge conflicts, do you think the feature added in this PR is complete and ready to go, pending review?

@n01r
Copy link
Member Author

n01r commented Oct 16, 2024

@EZoni, the CI tests are still missing. I was thinking of adding these today since Perlmutter is under maintenance anyway.

@@ -20,3 +30,14 @@ add_warpx_test(
diags/diagInst/ # output
OFF # dependency
)

# We do not have an intervals parser for PICMI yet which would accept more than a single integer for the output period
Copy link
Member Author

Choose a reason for hiding this comment

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

We should think about implementing an intervals parser for our PICMI diagnostics which can handle more than a single integer. It should be able to do the same as our app input: https://warpx.readthedocs.io/en/latest/usage/parameters.html#intervals-parser

RevathiJambunathan and others added 7 commits October 18, 2024 15:10
- Implement warnings and errors for certain inputs concerning averaging periods
- added first documentation on time averaged diags
- put more operations on summation multifabs into if-environments
Even though the laser ion test is named as a dependency it is running this
test again. That should ideally be avoided. It would be good to just run
the analysis script as test.
@n01r
Copy link
Member Author

n01r commented Oct 18, 2024

@EZoni, feel free to review :)

For PICMI, the TimeAveragedDiag test is automatically disabled because we
cannot simply define the necessary output intervals.
We need to be able to define period=[100,69:100] like for the app input.
n01r and others added 2 commits October 21, 2024 10:59
Modify checksum evaluation call to follow example from PR ECP-WarpX#5297.

Co-authored-by: Edoardo Zoni <[email protected]>
@EZoni
Copy link
Member

EZoni commented Oct 22, 2024

@n01r
If it's okay with you, I will push a fix for the CI tests (bug introduced by the changes I had suggested in my last review), rebase on the latest development, and then proceed with a final review.

@n01r
Copy link
Member Author

n01r commented Oct 22, 2024

Sounds good to me, @EZoni :)

@EZoni EZoni self-requested a review October 22, 2024 21:14
@EZoni
Copy link
Member

EZoni commented Oct 22, 2024

@n01r

I guess this (in the PR description) isn't a problem anymore, right?

Currently, compiling for GPU creates a linking error. We would like to see the CI output to possibly find the issue.
Hence, we do not flag this as WIP right now.

Copy link
Member

@EZoni EZoni left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, looks great to me, and it's being thoroughly tested with your simulations. I left only a few minor comments.

Docs/source/usage/parameters.rst Outdated Show resolved Hide resolved
Docs/source/usage/parameters.rst Outdated Show resolved Hide resolved
Docs/source/usage/parameters.rst Outdated Show resolved Hide resolved
@@ -266,6 +270,12 @@ protected:
* The second vector is loops over the total number of levels.
*/
amrex::Vector< amrex::Vector< amrex::MultiFab > > m_mf_output;
/** summation multifab, where all fields (computed, cell-centered, and stacked)
* are summed for every step in a time averaging period.
* The first vector is for total number of snapshots. (=1 for FullDiagnostics)
Copy link
Member

Choose a reason for hiding this comment

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

Just checking, =1 in this comment means something like "only one element"? If so (that is, if 1 does not refer to the index to be used to access that vector layer), a more verbose description might be clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unsure. I think @RevathiJambunathan may have added/suggested this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, that was copy-pasted and then modified from the comment of the m_mf_output above.
We could consider making this in all the places where it appears in this file.
But a separate PR would probably be better for this.

Source/Diagnostics/Diagnostics.cpp Outdated Show resolved Hide resolved
@n01r
Copy link
Member Author

n01r commented Oct 22, 2024

@n01r

I guess this (in the PR description) isn't a problem anymore, right?

Currently, compiling for GPU creates a linking error. We would like to see the CI output to possibly find the issue.
Hence, we do not flag this as WIP right now.

Oh, yea. That is not a thing anymore.
The CI also does not complain. I could check if locally I can compile for GPU in 3D because I think this was where I had some problems. But that may be my setup.

n01r and others added 2 commits October 22, 2024 15:32
@EZoni EZoni self-requested a review October 23, 2024 00:12
Updating the relative tolerance to 1e-12 to keep it strict because the test compares two diagnostics that come from the same run on the same machine, just that one averaging happens in-situ while the other is done in post-processing.

Co-authored-by: Edoardo Zoni <[email protected]>
@EZoni EZoni enabled auto-merge (squash) October 24, 2024 18:23
@EZoni
Copy link
Member

EZoni commented Oct 24, 2024

@n01r

Thanks! If possible, I would suggest that we track the work planned for follow-up PRs in an issue, just so we don't forget.

@n01r
Copy link
Member Author

n01r commented Oct 24, 2024

Agreed, @EZoni. Would you recommend continuing to use #5165 or opening new ones for individual tasks?

@EZoni
Copy link
Member

EZoni commented Oct 24, 2024

Thanks, as you prefer. I think #5165 will be closed automatically because this PR is linked. You can either reopen that one after the PR is merged or open a new issue for follow-up work, as you prefer.

@EZoni EZoni merged commit a25faff into ECP-WarpX:development Oct 24, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: diagnostics all types of outputs hackathon Let's address this topic during the GPU hackathon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diagnostics: Time-Averaged Fields
5 participants