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

MultiFabRegister: throw in get #5356

Merged
merged 14 commits into from
Jan 31, 2025
Merged

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Oct 2, 2024

Close #5319
Follow-up to #5230

  • Throw a runtime exception instead of returning a nullptr if a field is requested via the getter.
  • update logic to ensure this passes all tests

@ax3l ax3l added cleaning Clean code, improve readability component: ABLASTR components shared with other PIC codes labels Oct 2, 2024
@ax3l ax3l requested a review from EZoni October 2, 2024 15:54
Throw a runtime exception instead of returning a `nullptr` if a
field is requested via the getter.
@ax3l ax3l force-pushed the mf-register-throw branch from cb253dd to 2c2f48c Compare October 2, 2024 16:07
@ax3l ax3l requested a review from lucafedeli88 October 2, 2024 16:19
@ax3l ax3l changed the title MultiFabRegister: throw in get [WIP] MultiFabRegister: throw in get Oct 2, 2024
@ax3l ax3l added the help wanted Extra attention is needed label Oct 2, 2024
@EZoni
Copy link
Member

EZoni commented Oct 18, 2024

Discussed with @RemiLehe offline:

The functions get_mr_levels and get_mr_levels_alldirs fails by definition when we call it on coarse-patch MultiFabs, e.g., current_cp, because those are allocated only on levels greater than level 0 while the function attempts to return all levels starting from 0.

We will try to add to get_mr_levels and get_mr_levels_alldirs a function argument, e.g., skip_level_0, such that the function returns a nullptr for level 0 instead of calling the internal functions of the MultiFabRegister and throwing an exception.

Source/ablastr/fields/MultiFabRegister.cpp Outdated Show resolved Hide resolved
Source/ablastr/fields/MultiFabRegister.cpp Outdated Show resolved Hide resolved
@EZoni EZoni self-requested a review October 19, 2024 00:54
@EZoni EZoni mentioned this pull request Oct 21, 2024
5 tasks
Source/WarpX.cpp Outdated Show resolved Hide resolved
@EZoni
Copy link
Member

EZoni commented Jan 28, 2025

@ax3l @RemiLehe

Just a heads-up, I rebased and pushed a few more fixes and this might be almost ready. Let's see the latest CI status after the last commit and move from there.

@EZoni EZoni self-requested a review January 28, 2025 23:25
@EZoni
Copy link
Member

EZoni commented Jan 29, 2025

This is the only CI failure left after fb0dc3c:

The following tests FAILED:
	417 - test_3d_effective_potential_electrostatic_picmi.run (Failed)
	418 - test_3d_effective_potential_electrostatic_picmi.analysis (Failed)
	419 - test_3d_effective_potential_electrostatic_picmi.checksum (Failed)

I pushed 57e8e22 to try to fix the test.

@EZoni EZoni changed the title [WIP] MultiFabRegister: throw in get MultiFabRegister: throw in get Jan 29, 2025
@EZoni
Copy link
Member

EZoni commented Jan 29, 2025

@ax3l @lucafedeli88 @RemiLehe

CI is green now and the PR is ready for review.

Copy link
Member Author

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Excellent! Just a small Doxygen update needed and a few ideas for later improvements.

@@ -1298,16 +1298,16 @@ PML::PushPSATD (ablastr::fields::MultiFabRegister& fields, const int lev)
{
ablastr::fields::VectorField pml_E_fp = fields.get_alldirs(FieldType::pml_E_fp, lev);
ablastr::fields::VectorField pml_B_fp = fields.get_alldirs(FieldType::pml_B_fp, lev);
ablastr::fields::ScalarField pml_F_fp = fields.get(FieldType::pml_F_fp, lev);
ablastr::fields::ScalarField pml_G_fp = fields.get(FieldType::pml_G_fp, lev);
ablastr::fields::ScalarField pml_F_fp = (fields.has(FieldType::pml_F_fp, lev)) ? fields.get(FieldType::pml_F_fp, lev) : nullptr;
Copy link
Member Author

Choose a reason for hiding this comment

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

hehe, that's one way to quickly get the behavior in without changing downstream :D okok, nice idea and we can make this more robust later.

Source/ablastr/fields/MultiFabRegister.H Show resolved Hide resolved
Source/ablastr/fields/MultiFabRegister.H Show resolved Hide resolved
field_on_level.push_back(internal_get(name, lvl));
if (lvl == 0 && skip_level_0)
{
field_on_level.push_back(nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

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

Is pushing back a nullptr the clean approach or not pushing back anything (skip might imply either).
Then on the other hand, I assume if we move the level indexing on skip that can cause a lot of confusion, too (one argument to not use a Vector for the list of pointers.)

Thus, ok for me to keep as you suggest for 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.

@ax3l

Thanks for reviewing my changes.

Yes, in some corner cases (e.g., F in the PML) I just pushed the issue to the next "layer". Those were changes that date back to last year, I might have been unsure about how to resolve those at the time.

I'll approve on my end and let @roelof-groenewald or @lucafedeli88 chime in further.

I would make sure that people have enough time to look at this PR and double check the changes, since they are not trivial.

Copy link
Member

@roelof-groenewald roelof-groenewald left a comment

Choose a reason for hiding this comment

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

The changes are fine, but I wonder if we can rename the skip_level_0 variable to something else, maybe skip_level_0_for_coarse_patch. The reason I say that is if someone reads the code in the future, seeing just skip_level_0 = true, in something like ComputeSpaceChargeField() it could seem like the potential is not calculated for level 0 at all. Does that make sense?

@EZoni
Copy link
Member

EZoni commented Jan 30, 2025

Thanks, @roelof-groenewald. I renamed the variable to skip_lev0_coarse_patch, just to shorten the name as much as possible without missing any crucial component.

@ax3l
Copy link
Member Author

ax3l commented Jan 31, 2025

I think renaming in the usage "usage" code constants to skip_lev0_coarse_patch made sense.

In the MultiFabRegister class it does not make sense to me: this flag works for any MF (any patch, fine or coarse), if you pass it level 0 is skipped. I would thus suggest to keep skip_level_0 as the argument name in MultiFabRegister.H/.cpp if that makes sense @EZoni @roelof-groenewald

(Alternatively, do not add the new arg to the API at all and instead in user-code zero-out the 0-level coarse patch component on your skip_lev0_coarse_patch variable or even better, pass skip_lev0_coarse_patch to the call that should not process the level to be explicit. I am not sure how universally useful this argument addition in MultiFabRegister truly is, looks a bit hacky to me.)

@EZoni
Copy link
Member

EZoni commented Jan 31, 2025

Thanks, @ax3l.

My bad, I went through the renaming too fast. I agree that it would make sense to use two different names.

As for this,

(Alternatively, do not add the new arg to the API at all and instead in user-code zero-out the 0-level coarse patch component on your skip_lev0_coarse_patch variable or even better, pass skip_lev0_coarse_patch to the call that should not process the level to be explicit. I am not sure how universally useful this argument addition in MultiFabRegister truly is, looks a bit hacky to me.)

I think I don't understand the suggestion. The reason for introducing the variable was that we have two methods, get_mr_levels and get_mr_levels_alldirs, that loop over all MR levels, and therefore we cannot call those methods on any coarse-patch MultiFab, e.g., rho_cp, because nothing is allocated for those MultiFabs on level 0. I think what I don't understand in the suggestion is what data we would "zero out": my understanding is that there would be no data to zero out because the underlying allocation is missing, since coarse-patch data is not allocated on level 0. I think this was @RemiLehe's and my understanding when we discussed what is summarized in #5356 (comment) and came up with the skip_level_0 workaround.

@ax3l
Copy link
Member Author

ax3l commented Jan 31, 2025

Perfect.

Per last suggestion: oh yes, you are absolutely right that would not work 😂 ok, yes since this applies actually to all our cp, let's have it in the API (with the name back to the original).

@ax3l ax3l enabled auto-merge (squash) January 31, 2025 18:10
@ax3l ax3l merged commit 3092d26 into ECP-WarpX:development Jan 31, 2025
35 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Clean code, improve readability component: ABLASTR components shared with other PIC codes help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw error in MultiFabRegister.get when a field does not exist
3 participants