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 bug in rootfind for enthalpy parametrization #4536

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PointwiseFunctions/Hydro/EquationsOfState/Enthalpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ double Enthalpy<LowDensityEoS>::rest_mass_density_from_enthalpy(
const auto x = x_from_density(density);
return evaluate_coefficients(coefficients_, x) - specific_enthalpy;
};
return RootFinder::toms748(f, reference_density_, maximum_density_, 1.0e-14,
return RootFinder::toms748(f, minimum_density_, maximum_density_, 1.0e-14,
1.0e-15);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Framework/TestingFramework.hpp"

#include <cmath>
#include <limits>
#include <pup.h>
#include <vector>
Expand All @@ -16,7 +17,6 @@
#include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/Factory.hpp"
#include "PointwiseFunctions/Hydro/SpecificEnthalpy.hpp"

namespace EquationsOfState {
namespace {

Expand Down Expand Up @@ -159,6 +159,30 @@ void check_exact() {
hydro::relativistic_specific_enthalpy(rho, eps, p));
CHECK(get(rho) == approx(get(rho_from_enthalpy)));
}
{
// Guarantee that the root find has the correct bracket by explicitly
// nonsensical there, so if the correct braket
Comment on lines +163 to +164
Copy link
Member

Choose a reason for hiding this comment

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

Please fix this sentence

Copy link
Member

Choose a reason for hiding this comment

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

We need this merged ASAP because we are doing large simulations on Wheeler over the break. I think the sentence, while not great, is clear enough that it would be better for our science purposes to not delay this PR. Given some folks (including myself) are already on vacation and only doing this that are needed to do simulations over the break, I'd like to not block this PR on the sentence...

Copy link
Member

Choose a reason for hiding this comment

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

sure, please fix later then

Copy link
Member

Choose a reason for hiding this comment

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

Yep, Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, as a reminder: #4537

const auto oscillating_eos = Enthalpy<Spectral>{
0.5,
2.0,
1.0,
M_PI/log(2.0),
std::vector<double>{3.5},
std::vector<double>{0.0},
std::vector<double>{0.5},
Spectral{.5, .25, std::vector<double>{2.0}, 1.0},
0.0};
//cos(pi)) = -1, so the enthalpy is just 1 at z=log(2.0),
// which is rho =1.0
// If the rootfinder had the wrong braket z in [0, log(4)] it would
// not find the root bracketed, as cos(0) = 1, cos(log(4)*pi/log(2)) =
// cos(2*pi) = 1, so at these bounds h = 2.0 > 1.25
const Scalar<double> target_enthalpy{3.25};
const Scalar<double> target_rho{pow(2.0, 1.0/3.0)};
const auto rho_from_enthalpy =
oscillating_eos.rest_mass_density_from_enthalpy(target_enthalpy);
CHECK(get(target_rho) == approx(get(rho_from_enthalpy)));
}
// Test bounds
CHECK(0.0 == eos.rest_mass_density_lower_bound());
CHECK(0.0 == eos.specific_internal_energy_lower_bound(1.0));
Expand Down