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

Boundary bugfix(es) and exposing FluxDiv_ interface #558

Merged
merged 24 commits into from Sep 21, 2021

Conversation

pgrete
Copy link
Collaborator

@pgrete pgrete commented Jul 9, 2021

PR Summary

Also adjust dt calc as the original version resulted in a nan when it was initially set to max

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • CI has been triggered on Darwin for performance regression tests.
  • (@lanl.gov employees) Update copyright on changed files

src/driver/driver.cpp Show resolved Hide resolved
src/bvals/boundary_conditions.cpp Outdated Show resolved Hide resolved
@@ -33,6 +33,23 @@ namespace parthenon {

namespace Update {

// Calculate the flux divergence for a specific component l of a variable v
KOKKOS_FORCEINLINE_FUNCTION
Real FluxDiv_(const int l, const int k, const int j, const int i, const int ndim,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should consider renaming FluxDiv_ to FluxDiv or FluxDivHelper or something if it's publicly exposed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

jonahm-LANL and others added 2 commits July 9, 2021 12:47
…ntially repeats work, but is more robust and allows the user to set only the interior in the problem generator
@Yurlungur
Copy link
Collaborator

@pgrete Changing k-bounds initialized the uninitialized variables in the ghost zones at the initial time. I just pushed to your branch.

@pgrete
Copy link
Collaborator Author

pgrete commented Jul 26, 2021

What do you think about updating the advection example so that the background has a value of "1" versus "0" currently and then I'd add a PARTHENON_REQUIRE(advected != 0) to the SquareIt function that is enrolled as FillDerived?
This would mean updating the regression data, but I think it's worth adding as is causes almost no overhead an will increase test coverage (namely, that all cells are always initialized).

@Yurlungur
Copy link
Collaborator

What do you think about updating the advection example so that the background has a value of "1" versus "0" currently and then I'd add a PARTHENON_REQUIRE(advected != 0) to the SquareIt function that is enrolled as FillDerived?
This would mean updating the regression data, but I think it's worth adding as is causes almost no overhead an will increase test coverage (namely, that all cells are always initialized).

I think this is a good idea, so long as the advected field now has whatever form it currently has + 1. ;)

Copy link
Collaborator

@jlippuner jlippuner left a comment

Choose a reason for hiding this comment

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

Looks great and great catch!

Since we're making changes to the boundary conditions file anyway, I thought this would be a good opportunity to reduce some code duplication. I've made one generic boundary condition function covering all 12 cases (X1, X2, X3) x (inner, outer) x (outflow, reflection). Hopefully, this would make it easier to avoid such copy&paste errors in the future (if the boundary condition code needs to change). Please let me know what you think.

@Yurlungur
Copy link
Collaborator

Looks great and great catch!

Since we're making changes to the boundary conditions file anyway, I thought this would be a good opportunity to reduce some code duplication. I've made one generic boundary condition function covering all 12 cases (X1, X2, X3) x (inner, outer) x (outflow, reflection). Hopefully, this would make it easier to avoid such copy&paste errors in the future (if the boundary condition code needs to change). Please let me know what you think.

In principal, I'm in favor of reduced code, but I worry that I can't quite parse whether or not the generic version covers all 12 specialized versions. I'm not sure we have an automated test to catch this. Perhaps we should add one.

@jlippuner
Copy link
Collaborator

Looks great and great catch!
Since we're making changes to the boundary conditions file anyway, I thought this would be a good opportunity to reduce some code duplication. I've made one generic boundary condition function covering all 12 cases (X1, X2, X3) x (inner, outer) x (outflow, reflection). Hopefully, this would make it easier to avoid such copy&paste errors in the future (if the boundary condition code needs to change). Please let me know what you think.

In principal, I'm in favor of reduced code, but I worry that I can't quite parse whether or not the generic version covers all 12 specialized versions. I'm not sure we have an automated test to catch this. Perhaps we should add one.

We should definitely have a test. However, I think it should be relatively straightforward to check. There's only a few lines that were different between the expanded 12 cases. That being said, I'm happy to move the code duplication reduction to a new PR if it would take too long to review as part of this PR.

@Yurlungur
Copy link
Collaborator

That being said, I'm happy to move the code duplication reduction to a new PR if it would take too long to review as part of this PR.

That's up to @pgrete I suppose. My preference would be to add an automated test before merging that ensures these are working as intended. Advecting off of each face in 3d would be a. reasonable regression test, I think. We've clearly just been burned by our lack of testing in this area.

Copy link
Collaborator Author

@pgrete pgrete left a comment

Choose a reason for hiding this comment

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

I like the reduced code (see also comment on readability).
I also think that extending the test coverage is a good idea.
I have an idea to use dc reconstruction with a cfl of 1, so that we an check inflow, outflow, reflect exactly as as there'd be no diffusion.

src/bvals/boundary_conditions.cpp Outdated Show resolved Hide resolved
src/bvals/boundary_conditions.cpp Outdated Show resolved Hide resolved
@jlippuner
Copy link
Collaborator

Waiting on test for boundary condition before merging

@kurtsansom
Copy link
Collaborator

What kind of test are you looking for? simple unit test exercising the templated boundary condition function?

@Yurlungur
Copy link
Collaborator

What kind of test are you looking for? simple unit test exercising the templated boundary condition function?

Yes exactly. Just to make sure it behaves the same as the older non-templated code. (And/or is correct. ;) )

@pgrete
Copy link
Collaborator Author

pgrete commented Sep 12, 2021

This is now ready for new comments/review.
I now added checks for the new infrastructure (though user boundary conditions are not covered yet, see below).
I tried to be least intrusive to the advection example.
The key changes are:

  • the FillDerived function now has a conditional that checks if all values are initialized (i.e., making sure the corners are filled, too)
  • a new regression test, testing periodic, reflecting and outflow conditions enabled
    • by migrating individual cells in all directions

    • through an optional v(elocity) vector (so that reflecting boundaries are covered)

    • a new flux branch in the flux functions that translates cell data for cfl=1.0 (this works as the content of individual cells don't cross)file:///home/pgrete/test_reflect.mp4

    • the reflection test looks like:

test_reflect.mp4

Regarding the user boundary conditions:
In principle, I'd like to test all allowed permutations of boundary conditions as that combination of user and outflow threw me off in first place.
From a design point of view, we'd have to extend the advection example with 6 different user functions.
I imagine those just setting the advected field to a non-zero value and let the now implemented check in FillDerived/SquareIt handle it.
Do you think it's worth adding this change here or should we merge this sooner than later and take care of it in a separate PR?

@pgrete
Copy link
Collaborator Author

pgrete commented Sep 19, 2021

Ping @Yurlungur for final re-review of latest changes as discussed on Thursday.

Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

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

LGTM @pgrete some minor comments below. Really fantastic to have this test in place, along with the reduced code.

if (fill_derived) {
field_name = "one_minus_advected";
m = Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy},
std::vector<int>({num_vars}));
pkg->AddField(field_name, m);
pkg->AllFields();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this line supposed to be doing? Doesn't this return the const reference to the dictionary? Why the empty call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Looks like a debugging leftover. I'm removing it.

Comment on lines +320 to +326
// The following block/logic is also just added for regression testing.
// More specifically, the "smooth_gaussian" profile is initially != 0 everywhere, but
// initialializes IndexDomain::interior.
// FillDerived (here, SquareIt) is called after the ghost cells are exchanged and over
// IndexDomain::entire.
// Thus, no 0 (from initializing Kokkos views) should be left if all faces/corners/edges
// are correct, which is what we check in the loop below.
Copy link
Collaborator

Choose a reason for hiding this comment

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

High value comment 👍

Comment on lines +501 to +504
v.flux(X1DIR, n, k, j, i) =
ql(idx_v, i) > 0.0 ? ql(n, i) * ql(idx_v, i) : 0.0;
v.flux(X1DIR, n, k, j, i) +=
qr(idx_v, i) < 0.0 ? qr(n, i) * qr(idx_v, i) : 0.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the += syntax here. Feels nicer than the if-else block.

// bvals testing.
} else {
v.flux(X2DIR, n, k, j, i) =
ql(idx_v + 1, i) > 0.0 ? ql(n, i) * ql(idx_v + 1, i) : 0.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

rather than +1 or +2, one could do idx_v + XNDIR - 1 which might be a little cleaner. Not a big deal though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -53,7 +58,7 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {

auto profile_str = pin->GetOrAddString("Advection", "profile", "wave");
if (!((profile_str == "wave") || (profile_str == "smooth_gaussian") ||
(profile_str == "hard_sphere"))) {
(profile_str == "hard_sphere") || (profile_str == "block"))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't love the name block for the test profile. But I don't have a better name either.

class TestCase(utils.test_case.TestCaseAbs):
def Prepare(self, parameters, step):

# Step 1 (default vals in parameter file) is reflecting BC
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it's default to reflecting, but I still might be explicit here, in case the parameter file changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Will do.

@pgrete
Copy link
Collaborator Author

pgrete commented Sep 21, 2021

Addressed comment and triggering automerge now.

@pgrete pgrete enabled auto-merge (squash) September 21, 2021 21:06
@pgrete pgrete mentioned this pull request Sep 21, 2021
7 tasks
@pgrete pgrete merged commit d545178 into develop Sep 21, 2021
@pgrete pgrete deleted the pgrete/expose-flux-div branch September 21, 2021 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants