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

Make GrMhd system compatible with 3D EoS #5479

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

isaaclegred
Copy link
Contributor

Proposed changes

This PR adds support for 3D thermodynamic EoSs in the evolution system. Very little is changed (another instantiation is added) except in primitive recovery, where some logic needed to be added.

Upgrade instructions

Code review checklist

  • The code is documented and the documentation renders correctly. Run
    make doc to generate the documentation locally into BUILD_DIR/docs/html.
    Then open index.html.
  • The code follows the stylistic and code quality guidelines listed in the
    code review guide.
  • The PR lists upgrade instructions and is labeled bugfix or
    new feature if appropriate.

Further comments

@isaaclegred
Copy link
Contributor Author

@nilsvu, @nilsdeppe, (perhaps @ermost should take a look at the modifications to primitive recovery too)

@@ -141,7 +141,12 @@ std::optional<PrimitiveRecoveryData> NewmanHamlin::apply(
return std::nullopt;
}
} else if constexpr (ThermodynamicDim == 3) {
ERROR("3d EOS not implemented");
Scalar<double> local_internal_energy(
Copy link
Member

Choose a reason for hiding this comment

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

const Scalar<double>

rest_mass_density, specific_internal_energy, electron_fraction);
get(sound_speed_squared) =
get(equation_of_state.sound_speed_squared_from_density_and_temperature(
rest_mass_density, temperature, electron_fraction))
Copy link
Member

Choose a reason for hiding this comment

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

Oh, CI is complaining about a missing semicolon on this line :)

@ermost
Copy link
Contributor

ermost commented Sep 21, 2023

Hi @isaaclegred,

this looks great! The Con2Prim changes in Newman and KastaunMHD look good. Do you also want to modify KastaunHydro?
(I think you could just copy the code you changed in the MHD routine.)

@isaaclegred
Copy link
Contributor Author

this looks great! The Con2Prim changes in Newman and KastaunMHD look good. Do you also want to modify KastaunHydro? (I think you could just copy the code you changed in the MHD routine.)

Yep I can definitely do this, @ermost!

@isaaclegred
Copy link
Contributor Author

@nilsdeppe should I rebase on develop and fix the conflict?

@nilsdeppe
Copy link
Member

nilsdeppe commented Sep 25, 2023

Yes, though maybe wait a bit because #5494 will probably also cause a conflict?

Edit: I'm currently rebasing that one

@isaaclegred
Copy link
Contributor Author

@nilsdeppe and @nilsvu any other comments or should I squash?

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

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

Looks good, please squash!

@nilsvu
Copy link
Member

nilsvu commented Sep 27, 2023

And yes please squash

@isaaclegred isaaclegred force-pushed the Add3DEoSSupport branch 2 times, most recently from 29d4ee5 to b4c78a8 Compare September 28, 2023 21:23
Copy link
Member

@nilsvu nilsvu left a comment

Choose a reason for hiding this comment

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

Changes look good, but it looks like none of the ThermodynamicDim=3 code is tested. That seems important since we'll mostly run with 3D EOSs once the other changes to the executables go through. Could you please add tests for the code added here?

@ermost
Copy link
Contributor

ermost commented Oct 3, 2023

For the 3D Primitive recovery test, would it be possible to check what happens when the evolved electron fraction goes out of bounds?

@isaaclegred
Copy link
Contributor Author

For the 3D Primitive recovery test, would it be possible to check what happens when the evolved electron fraction goes out of bounds?

@ermost I can certainly add a test, what is the expected behavior in that case?

@ermost
Copy link
Contributor

ermost commented Oct 4, 2023

That would be great, thank you @isaaclegred!

It should be pushed back to the bounds of the EOS. so if you input ye_star < 0, you should get ye_min, and if you have ye_star > rho*ye_max, you should get ye_max.

The undertermined part is what happens if D <0, but that should be caught in the fix atmosphere, or fix conservative part. i.e., whether you keep ye, or just replace it by the atmospheric value.

@isaaclegred
Copy link
Contributor Author

@ermost, @nilsdeppe, @nilsvu whenever you get a chance this is ready for review! I've also added some potentially unnecessary tests to GhMhd subcell related things with 3d EoSs. Let me know if there's anything else you'd like to see.

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

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

I'm happy for you to squash once @ermost has taken a look :)

(rho_h_w_squared / square(current_lorentz_factor) -
current_pressure) /
current_rest_mass_density -
1.0;
Copy link
Member

Choose a reason for hiding this comment

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

LGTM, this has a catastrophic cancellation, but I don't know what to do about that other than to rework the entire recovery scheme (not worth it!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I would guess we would be using Kastaun most of the time anyway, if this becomes a serious limitation we can take a look at trying to patch it up.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's an intrinsic limitation of the Newman Hamlin scheme in terms of iterating over pressure. For using tabulated EOS the above has always been fine for me, when I was using Newman-Hamlin.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I think the "solution" is "use a better recovery scheme" 😅 Kastaun isn't perfect in this regard, but it isn't obvious to me that a "perfect" scheme is even possible

Copy link
Contributor

Choose a reason for hiding this comment

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

I think something better would probably go towards a physicality preserving evolution scheme, but that is even harder :)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would be the dream... But agreed, very, very difficult :(

@ermost
Copy link
Contributor

ermost commented Oct 10, 2023

Thanks a lot for additional test @isaaclegred . This looks good to me.

@isaaclegred
Copy link
Contributor Author

Just rebased on develop to fix conflicts

@nilsdeppe
Copy link
Member

Uh oh, something went wrong during the rebase :(

@isaaclegred
Copy link
Contributor Author

Yeah Con2Prim is broken now (like after fixing things to make it compile), I'm investigating

@isaaclegred
Copy link
Contributor Author

@nilsdeppe @ermost I think this is ready to be looked at again.

@ermost
Copy link
Contributor

ermost commented Oct 13, 2023

Looks good! Thanks for fixing this!

nilsdeppe
nilsdeppe previously approved these changes Oct 13, 2023
@nilsdeppe
Copy link
Member

LGTM, please squash :D

@isaaclegred
Copy link
Contributor Author

Changed some things to get rid of clang-tidy complaints, should be good to go when CI completes @nilsdeppe and @ermost!

nilsdeppe
nilsdeppe previously approved these changes Oct 14, 2023
Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

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

@nilsvu please take a look again...

@@ -297,15 +323,17 @@ Primitives FunctionOfMu<EnforcePhysicality, ThermodynamicDim>::primitives(
p_hat = get(equation_of_state_.pressure_from_density_and_energy(
Scalar<double>(rho_hat), Scalar<double>(epsilon_hat)));
} else if constexpr (ThermodynamicDim == 3) {
ERROR("3d EOS not implemented");
p_hat = get(equation_of_state_.pressure_from_density_and_energy(
Scalar<double>(rho_hat), Scalar<double>(epsilon_hat),
Copy link
Member

Choose a reason for hiding this comment

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

If you wanted to fix these, I think you need to swap the parens for braces: Scalar<double>{...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nilsvu said to ignore these earlier I think, which is why I didn't change them, but I can change them if that's the way things are going.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

nilsvu
nilsvu previously approved these changes Oct 17, 2023
Copy link
Member

@nilsvu nilsvu left a comment

Choose a reason for hiding this comment

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

Merging as-is is fine, or squash in these things if you want to do them and merge then.

Comment on lines 135 to 143
double eps_min{};
if constexpr (ThermodynamicDim == 3) {
eps_min = equation_of_state_.specific_internal_energy_lower_bound(
rest_mass_density_times_lorentz_factor_ / lorentz_max,
electron_fraction_);
} else {
eps_min = equation_of_state_.specific_internal_energy_lower_bound(
rest_mass_density_times_lorentz_factor_ / lorentz_max);
}
Copy link
Member

Choose a reason for hiding this comment

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

(optional) move this code outside the if because it's repeated in both branches?

eps_min = equation_of_state_.specific_internal_energy_lower_bound(
rest_mass_density_times_lorentz_factor_ / lorentz_max);
}
q_ = tau / rest_mass_density_times_lorentz_factor;
Copy link
Member

Choose a reason for hiding this comment

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

(optional) Move this line outside the if as well, and only do q_ = std::max(q_, eps_min) in the EnforcePhysicality branch? Seems easier to understand that way.

get<hydro::Tags::RestMassDensity<DataVector>>(subcell_prims));
}

else if constexpr (EquationOfStateType::thermodynamic_dim == 2) {
Copy link
Member

Choose a reason for hiding this comment

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

I recommend you build clang-format into your workflow, it makes editing code a lot easier. Try running git-clang-format and/or use your editor's formatting extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clang-format for some reason doesn't remove this whitespace :(

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the extra empty line tells it not to reformat

@isaaclegred
Copy link
Contributor Author

@nilsvu, @nilsdeppe changes fixed and squashed

@nilsvu nilsvu merged commit f9cd99e into sxs-collaboration:develop Oct 19, 2023
20 of 22 checks passed
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.

4 participants