Skip to content

Commit

Permalink
add inverse map
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoo1042 committed Aug 28, 2024
1 parent 13eaa27 commit 829cb25
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/PointwiseFunctions/AnalyticData/GrMhd/SphericalTorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

#include "Options/ParseError.hpp"
#include "Utilities/ErrorHandling/Assert.hpp"
#include "Utilities/Functional.hpp"
#include "Utilities/GenerateInstantiations.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeWithValue.hpp"
#include "Utilities/Math.hpp"

namespace grmhd::AnalyticData {

Expand Down Expand Up @@ -83,6 +85,8 @@ tnsr::I<T, 3> SphericalTorus::operator()(

tnsr::I<double, 3> SphericalTorus::inverse(
const tnsr::I<double, 3>& target_coords) const {
using std::abs;

tnsr::I<double, 3> result;
const double r = std::hypot(get<0>(target_coords), get<1>(target_coords),
get<2>(target_coords));
Expand All @@ -91,7 +95,27 @@ tnsr::I<double, 3> SphericalTorus::inverse(
get<2>(target_coords));
const double phi = std::atan2(get<1>(target_coords), get<0>(target_coords));
get<0>(result) = radius_inverse(r);
get<1>(result) = (M_PI_2 - theta) / pi_over_2_minus_theta_min_;

// if we are using compression (compression_level_ !=0), there is an extra
// step note this is just compressed eta; need to invert the cubic map back to
// eta
if (compression_level_ == 0.0) {
get<1>(result) = (M_PI_2 - theta) / pi_over_2_minus_theta_min_;
} else {
// using p.228 of Numerical Recipe
get<1>(result) = (M_PI_2 - theta) / pi_over_2_minus_theta_min_;
const double Q = (compression_level_ - 1.0) / (3.0 * compression_level_);
const double R = -0.5 * get<1>(result) / (compression_level_);
const double A =
-sgn(R) * pow(abs(R) + sqrt(square(R) - pow<3>(Q)), 1.0 / 3.0);
double B;

Check failure on line 111 in src/PointwiseFunctions/AnalyticData/GrMhd/SphericalTorus.cpp

View workflow job for this annotation

GitHub Actions / Clang-tidy (Debug)

variable 'B' is not initialized

Check failure on line 111 in src/PointwiseFunctions/AnalyticData/GrMhd/SphericalTorus.cpp

View workflow job for this annotation

GitHub Actions / Clang-tidy (Release)

variable 'B' is not initialized
if (A != 0.0) {
B = Q / A;
} else {
B = 0.0;
}
get<1>(result) = A + B;
}
get<2>(result) = phi / (M_PI * fraction_of_torus_);
return result;
}
Expand Down

0 comments on commit 829cb25

Please sign in to comment.