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 & refector: Incorrect v^2 calc in some pgens, and move Reducers out of Driver class. #188

Merged
merged 8 commits into from
Dec 2, 2023

Conversation

AstroBarker
Copy link
Collaborator

The name says it all. When I was trying to test tracers with the 2D advection problem, I eventually found that the vsq calculation was erroneous, showing the following pattern (psueudocode):

SPACELOOP2(ii, jj) { vsq += v(ii) * v(jj); }

Namely, it was either 1) missing the metric (which would collapse the sum in Minkowski or 2) should've been manually collapsed to just SPACELOOP(ii). The result was vsq > 1 and unphysical Lorentz factors. This PR fixes that by pulling in the metric (opting for the more general solution). I noticed the same pattern in the kh and linear_modes problems. kh is fixed the same, while linear_modes I replaced the loop with a 1D SPACELOOP to not fight with the existing metric for when using e.g., snake coordinates.

There's a (somewhat) unrelated refactor in this PR. I was working on adding a Parthenon-style advection regression test #187 but ran into an issue: the reducer objects for e.g., particle_resolution in the Driver class would have their destructors called after MPI/Kokkos finalize and Phoebus would exit with an error code, which caused the regression testing to exit with an error, too. So, this PR also refactors those Reducer objects as mutable params into radiation and fluid, where appropriate. I also split off the Driver creation and execution into its own scope. Not necessary with the refactor, but safer and potentially more future-proof. In a separate PR I'll pull in the regression testing (see #187 ).

@AstroBarker AstroBarker added bug Something isn't working enhancement New feature or request labels Dec 2, 2023
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.

Thanks for the catches! LGTM

@@ -78,6 +80,9 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
const Real P = y < 0.25 ? P1 : P0;
const Real vel = y < 0.25 ? v1 : v0;

Real gcov[4][4];
geom.SpacetimeMetric(0.0, x, y, 0.0, gcov);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not that it matters much, but why set z to zero here? Why not use the z from the coords?

@@ -247,7 +247,7 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
}

Real vsq = 0.;
SPACELOOP2(ii, jj) { vsq += v(ivlo + ii, k, j, i) * v(ivlo + jj, k, j, i); }
SPACELOOP(ii) { vsq += v(ivlo + ii, k, j, i) * v(ivlo + ii, k, j, i); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the metric not needed for this one?

@Yurlungur
Copy link
Collaborator

My comments are non-blockers, so I'm just going to merge. But may be wroth revisiting them at some point.

@Yurlungur Yurlungur merged commit f99b067 into main Dec 2, 2023
2 checks passed
@AstroBarker AstroBarker deleted the blb/vsq_fix branch March 14, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants