From 39213c5fcb573674743429328cd680d1eade11f2 Mon Sep 17 00:00:00 2001 From: Sarah Habib Date: Tue, 21 May 2024 00:02:25 -0700 Subject: [PATCH] Add VelocityPerturbation option for TovStar --- .../AnalyticData/GrMhd/MagnetizedTovStar.cpp | 6 +-- .../AnalyticData/GrMhd/MagnetizedTovStar.hpp | 7 ++- .../RelativisticEuler/TovStar.cpp | 26 +++++++++-- .../RelativisticEuler/TovStar.hpp | 46 +++++++++++++++---- .../AnalyticSolutions/Xcts/TovStar.hpp | 6 +-- .../Systems/Xcts/Test_HydroQuantities.cpp | 5 +- .../RelativisticEuler/Test_TovStar.cpp | 5 +- 7 files changed, 75 insertions(+), 26 deletions(-) diff --git a/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.cpp b/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.cpp index 91df10162ea82..b6a71d76b864e 100644 --- a/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.cpp +++ b/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.cpp @@ -32,15 +32,15 @@ MagnetizedTovStar& MagnetizedTovStar::operator=(MagnetizedTovStar&& /*rhs*/) = MagnetizedTovStar::~MagnetizedTovStar() = default; MagnetizedTovStar::MagnetizedTovStar( - const double central_rest_mass_density, + const double central_rest_mass_density, const double velocity_perturbation, std::unique_ptr equation_of_state, const RelativisticEuler::Solutions::TovCoordinates coordinate_system, std::vector> magnetic_fields) - : tov_star(central_rest_mass_density, std::move(equation_of_state), - coordinate_system), + : tov_star(central_rest_mass_density, velocity_perturbation, + std::move(equation_of_state), coordinate_system), magnetic_fields_(std::move(magnetic_fields)) {} MagnetizedTovStar::MagnetizedTovStar(const MagnetizedTovStar& rhs) diff --git a/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.hpp b/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.hpp index 5a887b40ac0c4..91fe536d584bd 100644 --- a/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.hpp +++ b/src/PointwiseFunctions/AnalyticData/GrMhd/MagnetizedTovStar.hpp @@ -41,6 +41,7 @@ struct MagnetizedTovVariables using Base::operator(); using Base::coords; using Base::eos; + using Base::perturbation; using Base::radial_solution; using Base::radius; @@ -52,10 +53,12 @@ struct MagnetizedTovVariables const tnsr::I& local_x, const DataType& local_radius, const RelativisticEuler::Solutions::TovSolution& local_radial_solution, const EquationsOfState::EquationOfState& local_eos, + const double perturbation, const std::vector>& mag_fields) - : Base(local_x, local_radius, local_radial_solution, local_eos), + : Base(local_x, local_radius, local_radial_solution, local_eos, + perturbation), magnetic_fields(mag_fields) {} void operator()( @@ -145,7 +148,7 @@ class MagnetizedTovStar : public virtual evolution::initial_data::InitialData, ~MagnetizedTovStar() override; MagnetizedTovStar( - double central_rest_mass_density, + double central_rest_mass_density, double velocity_perturbation, std::unique_ptr> equation_of_state, RelativisticEuler::Solutions::TovCoordinates coordinate_system, diff --git a/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.cpp b/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.cpp index 828e280060fec..cc07c004fc8d7 100644 --- a/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.cpp +++ b/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.cpp @@ -20,11 +20,12 @@ namespace RelativisticEuler::Solutions { TovStar::TovStar(CkMigrateMessage* msg) : InitialData(msg) {} TovStar::TovStar( - const double central_rest_mass_density, + const double central_rest_mass_density, const double velocity_perturbation, std::unique_ptr> equation_of_state, const RelativisticEuler::Solutions::TovCoordinates coordinate_system) : central_rest_mass_density_(central_rest_mass_density), + velocity_perturbation_(velocity_perturbation), equation_of_state_(std::move(equation_of_state)), coordinate_system_(coordinate_system), radial_solution_(*equation_of_state_, central_rest_mass_density_, @@ -33,6 +34,7 @@ TovStar::TovStar( TovStar::TovStar(const TovStar& rhs) : evolution::initial_data::InitialData(rhs), central_rest_mass_density_(rhs.central_rest_mass_density_), + velocity_perturbation_(rhs.velocity_perturbation_), equation_of_state_(rhs.equation_of_state_->get_clone()), coordinate_system_(rhs.coordinate_system_), radial_solution_(*equation_of_state_, central_rest_mass_density_, @@ -40,6 +42,7 @@ TovStar::TovStar(const TovStar& rhs) TovStar& TovStar::operator=(const TovStar& rhs) { central_rest_mass_density_ = rhs.central_rest_mass_density_; + velocity_perturbation_ = rhs.velocity_perturbation_; equation_of_state_ = rhs.equation_of_state_->get_clone(); coordinate_system_ = rhs.coordinate_system_; radial_solution_ = RelativisticEuler::Solutions::TovSolution( @@ -55,6 +58,7 @@ std::unique_ptr TovStar::get_clone() void TovStar::pup(PUP::er& p) { InitialData::pup(p); p | central_rest_mass_density_; + p | velocity_perturbation_; p | equation_of_state_; p | coordinate_system_; p | radial_solution_; @@ -514,11 +518,23 @@ void TovVariables::operator()( template void TovVariables::operator()( const gsl::not_null*> spatial_velocity, - const gsl::not_null /*cache*/, + const gsl::not_null cache, hydro::Tags::SpatialVelocity /*meta*/) const { - get<0>(*spatial_velocity) = 0.; - get<1>(*spatial_velocity) = 0.; - get<2>(*spatial_velocity) = 0.; + if constexpr (Region == StarRegion::Center or + Region == StarRegion::Exterior) { + get<0>(*spatial_velocity) = 0.; + get<1>(*spatial_velocity) = 0.; + get<2>(*spatial_velocity) = 0.; + } else { + const auto& areal_radius = + radial_solution.coordinate_system() == + RelativisticEuler::Solutions::TovCoordinates::Isotropic + ? get(cache->get_var(*this, Tags::ArealRadius{})) + : radius; + get<0>(*spatial_velocity) = perturbation * coords.get(0) / areal_radius; + get<1>(*spatial_velocity) = perturbation * coords.get(1) / areal_radius; + get<2>(*spatial_velocity) = perturbation * coords.get(2) / areal_radius; + } } template diff --git a/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.hpp b/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.hpp index bc62a6c66ac40..d30cd48f34b5e 100644 --- a/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.hpp +++ b/src/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/TovStar.hpp @@ -139,16 +139,19 @@ struct TovVariables { TovVariables( const tnsr::I& local_coords, const DataType& local_radius, const RelativisticEuler::Solutions::TovSolution& local_radial_solution, - const EquationsOfState::EquationOfState& local_eos) + const EquationsOfState::EquationOfState& local_eos, + const double perturb) : coords(local_coords), radius(local_radius), radial_solution(local_radial_solution), - eos(local_eos) {} + eos(local_eos), + perturbation(perturb) {} const tnsr::I& coords; const DataType& radius; const RelativisticEuler::Solutions::TovSolution& radial_solution; const EquationsOfState::EquationOfState& eos; + const double perturbation; void operator()(gsl::not_null*> mass_over_radius, gsl::not_null cache, @@ -336,6 +339,13 @@ class TovStar : public virtual evolution::initial_data::InitialData, static type lower_bound() { return 0.; } }; + struct VelocityPerturbation { + using type = double; + static constexpr Options::String help = { + "Magnitude of radially symmetric velocity perturbation for driving " + "oscillations."}; + }; + /// Areal (Schwarzschild) or isotropic coordinates struct Coordinates { using type = RelativisticEuler::Solutions::TovCoordinates; @@ -346,7 +356,7 @@ class TovStar : public virtual evolution::initial_data::InitialData, static constexpr size_t volume_dim = 3_st; using options = - tmpl::list, Coordinates>; @@ -361,7 +371,7 @@ class TovStar : public virtual evolution::initial_data::InitialData, TovStar(TovStar&& /*rhs*/) = default; TovStar& operator=(TovStar&& /*rhs*/) = default; ~TovStar() override = default; - TovStar(double central_rest_mass_density, + TovStar(double central_rest_mass_density, double velocity_perturbation, std::unique_ptr> equation_of_state, const RelativisticEuler::Solutions::TovCoordinates coordinate_system = @@ -420,7 +430,11 @@ class TovStar : public virtual evolution::initial_data::InitialData, VarsComputer; typename ExteriorVarsComputer::Cache cache{get_size(radius)}; ExteriorVarsComputer computer{ - x, radius, radial_solution_, *equation_of_state_, + x, + radius, + radial_solution_, + *equation_of_state_, + velocity_perturbation_, std::forward(vars_computer_args)...}; return {cache.get_var(computer, Tags{})...}; } else if (max(radius) <= outer_radius and @@ -430,7 +444,11 @@ class TovStar : public virtual evolution::initial_data::InitialData, VarsComputer; typename InteriorVarsComputer::Cache cache{get_size(radius)}; InteriorVarsComputer computer{ - x, radius, radial_solution_, *equation_of_state_, + x, + radius, + radial_solution_, + *equation_of_state_, + velocity_perturbation_, std::forward(vars_computer_args)...}; return {cache.get_var(computer, Tags{})...}; } else { @@ -472,22 +490,31 @@ class TovStar : public virtual evolution::initial_data::InitialData, if (get_element(radius, i) > outer_radius) { typename ExteriorVarsComputer::Cache cache{1}; ExteriorVarsComputer computer{ - x_i, get_element(radius, i), radial_solution_, + x_i, + get_element(radius, i), + radial_solution_, *equation_of_state_, + velocity_perturbation_, std::forward(vars_computer_args)...}; expand_pack(get_var(i, cache, computer, Tags{})...); } else if (get_element(radius, i) > center_radius_cutoff) { typename InteriorVarsComputer::Cache cache{1}; InteriorVarsComputer computer{ - x_i, get_element(radius, i), radial_solution_, + x_i, + get_element(radius, i), + radial_solution_, *equation_of_state_, + velocity_perturbation_, std::forward(vars_computer_args)...}; expand_pack(get_var(i, cache, computer, Tags{})...); } else { typename CenterVarsComputer::Cache cache{1}; CenterVarsComputer computer{ - x_i, get_element(radius, i), radial_solution_, + x_i, + get_element(radius, i), + radial_solution_, *equation_of_state_, + velocity_perturbation_, std::forward(vars_computer_args)...}; expand_pack(get_var(i, cache, computer, Tags{})...); } @@ -521,6 +548,7 @@ class TovStar : public virtual evolution::initial_data::InitialData, double central_rest_mass_density_ = std::numeric_limits::signaling_NaN(); + double velocity_perturbation_ = std::numeric_limits::signaling_NaN(); std::unique_ptr equation_of_state_; RelativisticEuler::Solutions::TovCoordinates coordinate_system_{}; RelativisticEuler::Solutions::TovSolution radial_solution_{}; diff --git a/src/PointwiseFunctions/AnalyticSolutions/Xcts/TovStar.hpp b/src/PointwiseFunctions/AnalyticSolutions/Xcts/TovStar.hpp index 5da1c9eeb347a..d50bc81d5be0e 100644 --- a/src/PointwiseFunctions/AnalyticSolutions/Xcts/TovStar.hpp +++ b/src/PointwiseFunctions/AnalyticSolutions/Xcts/TovStar.hpp @@ -195,12 +195,12 @@ class TovStar : public elliptic::analytic_data::AnalyticSolution { TovStar& operator=(TovStar&&) = default; ~TovStar() = default; - TovStar(double central_rest_mass_density, + TovStar(double central_rest_mass_density, double velocity_perturbation, std::unique_ptr> equation_of_state, const RelativisticEuler::Solutions::TovCoordinates coordinate_system) - : tov_star(central_rest_mass_density, std::move(equation_of_state), - coordinate_system) {} + : tov_star(central_rest_mass_density, velocity_perturbation, + std::move(equation_of_state), coordinate_system) {} const EquationsOfState::EquationOfState& equation_of_state() const { return tov_star.equation_of_state(); diff --git a/tests/Unit/Elliptic/Systems/Xcts/Test_HydroQuantities.cpp b/tests/Unit/Elliptic/Systems/Xcts/Test_HydroQuantities.cpp index 9f0f428829f93..4fe4c8ab37edf 100644 --- a/tests/Unit/Elliptic/Systems/Xcts/Test_HydroQuantities.cpp +++ b/tests/Unit/Elliptic/Systems/Xcts/Test_HydroQuantities.cpp @@ -17,8 +17,8 @@ #include "PointwiseFunctions/AnalyticSolutions/Xcts/Factory.hpp" #include "PointwiseFunctions/AnalyticSolutions/Xcts/TovStar.hpp" #include "PointwiseFunctions/Hydro/EquationsOfState/PolytropicFluid.hpp" -#include "PointwiseFunctions/Hydro/Tags.hpp" #include "PointwiseFunctions/Hydro/LowerSpatialFourVelocity.hpp" +#include "PointwiseFunctions/Hydro/Tags.hpp" #include "PointwiseFunctions/InitialDataUtilities/AnalyticSolution.hpp" #include "PointwiseFunctions/InitialDataUtilities/Background.hpp" #include "Utilities/ProtocolHelpers.hpp" @@ -47,7 +47,8 @@ SPECTRE_TEST_CASE("Unit.Elliptic.Systems.Xcts.HydroQuantities", using hydro_tags = AnalyticData::hydro_tags; using spatial_metric_tag = gr::Tags::SpatialMetric; const Solutions::TovStar tov_star{ - 1.e-3, std::make_unique>(1., 2.), + 1.e-3, 0.0, + std::make_unique>(1., 2.), RelativisticEuler::Solutions::TovCoordinates::Schwarzschild}; const double outer_radius = tov_star.radial_solution().outer_radius(); const tnsr::I x{ diff --git a/tests/Unit/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/Test_TovStar.cpp b/tests/Unit/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/Test_TovStar.cpp index f85d6da700c47..c045f355eb1c7 100644 --- a/tests/Unit/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/Test_TovStar.cpp +++ b/tests/Unit/PointwiseFunctions/AnalyticSolutions/RelativisticEuler/Test_TovStar.cpp @@ -77,6 +77,7 @@ void test_tov_star(const TovCoordinates coord_system) { RelativisticEuler::Solutions::TovStar>( "TovStar:\n" " CentralDensity: 1.0e-3\n" + " VelocityPerturbation: 0.0\n" " EquationOfState:\n" " PolytropicFluid:\n" " PolytropicConstant: 100.0\n" @@ -92,7 +93,7 @@ void test_tov_star(const TovCoordinates coord_system) { { INFO("Semantics"); CHECK(solution == - TovStar{1.0e-3, + TovStar{1.0e-3, 0, std::make_unique>( 100.0, 2.0), coord_system}); @@ -110,7 +111,7 @@ void test_tov_star(const TovCoordinates coord_system) { custom_approx(10.0473500683)); // Check a second solution TovStar second_solution{ - 1.0e-3, + 1.0e-3, 0, std::make_unique>(8.0, 2.0)}; CHECK(second_solution.radial_solution().outer_radius() == custom_approx(3.4685521362));