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 openPMD plotfile output #804

Merged
merged 7 commits into from
Dec 9, 2024
Merged

Conversation

BenWibking
Copy link
Collaborator

@BenWibking BenWibking commented Dec 2, 2024

Description

Fixes a segmentation fault during openPMD plotfile output when face-centered variables are enabled.

There was an implicit assumption in AMRSimulation<problem_t>::AverageFCToCC() that the number of face-centered ghost zones was the same as the number of cell-centered ghost zones. This PR allows the number of ghosts to differ.

I manually tested that this works inside the CUDA dev container by compiling Quokka with -DQUOKKA_OPENPMD=ON, running the HydroBlast3D problem, and then examining the output files with openPMD-viewer.

Related issues

Fixes #742.

Checklist

Before this pull request can be reviewed, all of these tasks should be completed. Denote completed tasks with an x inside the square brackets [ ] in the Markdown source below:

  • I have added a description (see above).
  • I have added a link to any related issues (if applicable; see above).
  • I have read the Contributing Guide.
  • I have added tests for any new physics that this PR adds to the code.
  • (For quokka-astro org members) I have manually triggered the GPU tests with the magic comment /azp run.

@BenWibking BenWibking changed the title [WIP] fix openPMD plotfile output fix openPMD plotfile output Dec 2, 2024
@BenWibking BenWibking marked this pull request as ready for review December 2, 2024 18:58
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Dec 2, 2024
@BenWibking
Copy link
Collaborator Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@BenWibking BenWibking enabled auto-merge December 2, 2024 19:01
@BenWibking
Copy link
Collaborator Author

@BenWibking BenWibking disabled auto-merge December 2, 2024 19:15
@BenWibking
Copy link
Collaborator Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@BenWibking BenWibking changed the title fix openPMD plotfile output [WIP] fix openPMD plotfile output Dec 2, 2024
@BenWibking
Copy link
Collaborator Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 3, 2024
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 3, 2024
@BenWibking
Copy link
Collaborator Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

sonarcloud bot commented Dec 3, 2024

@BenWibking BenWibking changed the title [WIP] fix openPMD plotfile output fix openPMD plotfile output Dec 3, 2024
@BenWibking BenWibking enabled auto-merge December 3, 2024 23:06
@BenWibking
Copy link
Collaborator Author

@markkrumholz Not urgent, but this is now ready for review.

Copy link
Collaborator

@markkrumholz markkrumholz left a comment

Choose a reason for hiding this comment

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

There seems to be a slight inconsistency in the design: as written now, the code will always fail if run for a case with more cell-centered than face-centered ghost zones, due to the AMREX_ALWAYS_ASSERT added to the routine that does the averaging to centers. However, both doDiagnostics and renderAscent seem to support having more cell-centered than face-centered ghost zones, and gracefully use a std::min to handle that. This is confusing. I think we should put similar assertions in every routine if we don't want to support having nghost_cc > nghost_fc, or we should edit the averaging to center routine to also support this case. One possible way to do this would be to have the routine take an optional argument that provides a fill value to add to ghost zones that cannot be filled because the corresponding face-centered cells do not exist. I don't have strong feelings about which of these options we pick, but I think the design should be consistent as to whether we do or don't support the case nghost_cc > nghost_fc.

@BenWibking
Copy link
Collaborator Author

There seems to be a slight inconsistency in the design: as written now, the code will always fail if run for a case with more cell-centered than face-centered ghost zones, due to the AMREX_ALWAYS_ASSERT added to the routine that does the averaging to centers. However, both doDiagnostics and renderAscent seem to support having more cell-centered than face-centered ghost zones, and gracefully use a std::min to handle that. This is confusing. I think we should put similar assertions in every routine if we don't want to support having nghost_cc > nghost_fc, or we should edit the averaging to center routine to also support this case. One possible way to do this would be to have the routine take an optional argument that provides a fill value to add to ghost zones that cannot be filled because the corresponding face-centered cells do not exist. I don't have strong feelings about which of these options we pick, but I think the design should be consistent as to whether we do or don't support the case nghost_cc > nghost_fc.

In the current code, if I am remembering correctly, averaging to centers is only done for outputs. Everywhere an output needs to do that, it provides an appropriate number of ghost zones to use (that may be less than nghost_cc). If we are not doing MHD, then we don't need to carry around extra ghost faces we don't need, and we only need to average them to centers for outputs. I don't see an issue with this design in principle.

I don't think it's a good idea to allow averaging to centers with a fill value. That is almost certain to produce bugs in the future. The assertion just forces anyone who uses the averaging function to specify something sensible upfront. In any case, I don't know where we would need to do this.

@BenWibking
Copy link
Collaborator Author

BenWibking commented Dec 8, 2024

Actually, ghost cells in outputs are only really needed for Ascent, due to the way it uses them to compute surfaces and streamlines in parallel without doing extra communication itself. For all other outputs, we could just get rid of the ghost cells. They are not supported in OpenPMD outputs at all, and in AMReX plotfiles I don't think they are used for anything.

Edit: I need to double check whether they are used by any of the diagnostics.

@BenWibking
Copy link
Collaborator Author

Just to clarify- the case where nghost_cc > nghost_fc is tested as part of the SphericalCollapse test suite problem, since tracer particles without MHD enabled set nghost_fc = 2, while nghost_cc is always 4.

@markkrumholz
Copy link
Collaborator

So my confusion is these lines (2092 - 2096) of Simulation.hpp:

auto const &state_cc = mf_cc.arrays(); auto const &state_fc = mf_fc.const_arrays(); amrex::ParallelFor(mf_cc, amrex::IntVect(AMREX_D_DECL(nGrow, nGrow, nGrow)), [=] AMREX_GPU_DEVICE(int boxidx, int i, int j, int k) { int const ng_cc = mf_cc.nGrow(); int const ng_fc = mf_fc.nGrow(); AMREX_ALWAYS_ASSERT(ng_cc <= ng_fc); // if this is false, we can't fill the ghost cells!

It seems to me like you are grabbing the state vectors, extracting their number of ghost zones, and then throwing an assertion that will fail anytime the cell-centered state variables have more ghost zones than the face-centered ones. So it seems like this should fail any time AverageFCToCC is called, which it always is any time you're writing a plot file, and it seems like it should fail independent of how many cells you're trying to write to that plot file. Am I misunderstanding what this code does?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 9, 2024
@BenWibking BenWibking added this pull request to the merge queue Dec 9, 2024
Merged via the queue into development with commit 214de9d Dec 9, 2024
23 checks passed
@BenWibking BenWibking deleted the BenWibking/fix-openpmd branch December 9, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

openPMD output is broken
2 participants