From 716e2089f5b6ea9e40fc670be7ee5c6d2c929abe Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Fri, 21 Jun 2024 11:03:34 -0700 Subject: [PATCH] Use common time dep opts in Sphere domain --- .../Creators/TimeDependentOptions/Sphere.cpp | 119 ++++++------------ .../Creators/TimeDependentOptions/Sphere.hpp | 111 ++-------------- ...ahlkorperCoefsInRingdownDistortedFrame.cpp | 11 +- ...ahlkorperCoefsInRingdownDistortedFrame.hpp | 2 +- tests/Unit/Domain/Creators/Test_Sphere.cpp | 13 +- ...ahlkorperCoefsInRingdownDistortedFrame.cpp | 11 +- 6 files changed, 67 insertions(+), 200 deletions(-) diff --git a/src/Domain/Creators/TimeDependentOptions/Sphere.cpp b/src/Domain/Creators/TimeDependentOptions/Sphere.cpp index 69a6863fec10..9bd7d161318c 100644 --- a/src/Domain/Creators/TimeDependentOptions/Sphere.cpp +++ b/src/Domain/Creators/TimeDependentOptions/Sphere.cpp @@ -30,29 +30,6 @@ namespace domain::creators::sphere { -TimeDependentMapOptions::RotationMapOptions::RotationMapOptions() = default; -TimeDependentMapOptions::RotationMapOptions::RotationMapOptions( - const std::array, 3> initial_values_in, - const double decay_timescale_in) - : initial_values(initial_values_in), decay_timescale(decay_timescale_in) {} - -TimeDependentMapOptions::ExpansionMapOptions::ExpansionMapOptions() = default; -TimeDependentMapOptions::ExpansionMapOptions::ExpansionMapOptions( - const std::array initial_values_in, - const double decay_timescale_in, - const std::array initial_values_outer_boundary_in, - const double decay_timescale_outer_boundary_in) - : initial_values(initial_values_in), - decay_timescale(decay_timescale_in), - initial_values_outer_boundary(initial_values_outer_boundary_in), - decay_timescale_outer_boundary(decay_timescale_outer_boundary_in) {} - -TimeDependentMapOptions::TranslationMapOptions::TranslationMapOptions() = - default; -TimeDependentMapOptions::TranslationMapOptions::TranslationMapOptions( - const std::array, 3> initial_values_in) - : initial_values(initial_values_in) {} - TimeDependentMapOptions::TimeDependentMapOptions( const double initial_time, std::optional shape_map_options, std::optional rotation_map_options, @@ -79,6 +56,8 @@ TimeDependentMapOptions::create_functions_of_time( std::unordered_map expiration_times{ {size_name, std::numeric_limits::infinity()}, {shape_name, std::numeric_limits::infinity()}, + {rotation_name, std::numeric_limits::infinity()}, + {expansion_name, std::numeric_limits::infinity()}, {translation_name, std::numeric_limits::infinity()}}; // If we have control systems, overwrite these expiration times with the ones @@ -107,75 +86,57 @@ TimeDependentMapOptions::create_functions_of_time( // ExpansionMap FunctionOfTime if (expansion_map_options_.has_value()) { - result[expansion_name] = - std::make_unique( - std::array{ - {{gsl::at(expansion_map_options_.value().initial_values, 0)}, - {gsl::at(expansion_map_options_.value().initial_values, 1)}, - {gsl::at(expansion_map_options_.value().initial_values, 2)}}}, - initial_time_, expansion_map_options_.value().decay_timescale); + if (expansion_map_options_->decay_timescale.has_value()) { + result[expansion_name] = + std::make_unique( + expansion_map_options_->initial_values, initial_time_, + expansion_map_options_->decay_timescale.value()); + } else { + result[expansion_name] = + std::make_unique>( + initial_time_, expansion_map_options_->initial_values, + expiration_times.at(expansion_name)); + } // ExpansionMap in the Outer regionFunctionOfTime - result[expansion_outer_boundary_name] = std::make_unique< - FunctionsOfTime::SettleToConstant>( - std::array{ - {{gsl::at( - expansion_map_options_.value().initial_values_outer_boundary, - 0)}, - {gsl::at( - expansion_map_options_.value().initial_values_outer_boundary, - 1)}, - {gsl::at( - expansion_map_options_.value().initial_values_outer_boundary, - 2)}}}, - initial_time_, - expansion_map_options_.value().decay_timescale_outer_boundary); + if (expansion_map_options_->asymptotic_velocity_outer_boundary + .has_value()) { + result[expansion_outer_boundary_name] = + std::make_unique( + expansion_map_options_->initial_values[0][0], initial_time_, + expansion_map_options_->asymptotic_velocity_outer_boundary + .value(), + expansion_map_options_->decay_timescale_outer_boundary); + } else { + result[expansion_outer_boundary_name] = + std::make_unique( + expansion_map_options_->initial_values_outer_boundary, + initial_time_, + expansion_map_options_->decay_timescale_outer_boundary); + } } - DataVector initial_quaternion_value{4, 0.0}; - DataVector initial_quaternion_first_derivative_value{4, 0.0}; - DataVector initial_quaternion_second_derivative_value{4, 0.0}; - // RotationMap FunctionOfTime if (rotation_map_options_.has_value()) { - for (size_t i = 0; i < 4; i++) { - initial_quaternion_value[i] = - gsl::at(gsl::at(rotation_map_options_.value().initial_values, 0), i); - initial_quaternion_first_derivative_value[i] = - gsl::at(gsl::at(rotation_map_options_.value().initial_values, 1), i); - initial_quaternion_second_derivative_value[i] = - gsl::at(gsl::at(rotation_map_options_.value().initial_values, 2), i); + if (rotation_map_options_->decay_timescale.has_value()) { + result[rotation_name] = + std::make_unique>( + initial_time_, std::array{rotation_map_options_->quaternions[0]}, + rotation_map_options_->angles, + expiration_times.at(rotation_name)); + } else { + result[rotation_name] = + std::make_unique( + rotation_map_options_->quaternions, initial_time_, + rotation_map_options_->decay_timescale.value()); } - result[rotation_name] = - std::make_unique( - std::array{ - std::move(initial_quaternion_value), - std::move(initial_quaternion_first_derivative_value), - std::move(initial_quaternion_second_derivative_value)}, - initial_time_, rotation_map_options_.value().decay_timescale); } - DataVector initial_translation_center{3, 0.0}; - DataVector initial_translation_velocity{3, 0.0}; - DataVector initial_translation_acceleration{3, 0.0}; - // Translation FunctionOfTime if (translation_map_options_.has_value()) { - for (size_t i = 0; i < 3; i++) { - initial_translation_center[i] = gsl::at( - gsl::at(translation_map_options_.value().initial_values, 0), i); - initial_translation_velocity[i] = gsl::at( - gsl::at(translation_map_options_.value().initial_values, 1), i); - initial_translation_acceleration[i] = gsl::at( - gsl::at(translation_map_options_.value().initial_values, 2), i); - } result[translation_name] = std::make_unique>( - initial_time_, - std::array{ - {std::move(initial_translation_center), - std::move(initial_translation_velocity), - std::move(initial_translation_acceleration)}}, + initial_time_, translation_map_options_->initial_values, expiration_times.at(translation_name)); } diff --git a/src/Domain/Creators/TimeDependentOptions/Sphere.hpp b/src/Domain/Creators/TimeDependentOptions/Sphere.hpp index 84bb62e719af..f52c6f6b6336 100644 --- a/src/Domain/Creators/TimeDependentOptions/Sphere.hpp +++ b/src/Domain/Creators/TimeDependentOptions/Sphere.hpp @@ -16,7 +16,10 @@ #include "Domain/CoordinateMaps/TimeDependent/RotScaleTrans.hpp" #include "Domain/CoordinateMaps/TimeDependent/Shape.hpp" #include "Domain/CoordinateMaps/TimeDependent/Translation.hpp" +#include "Domain/Creators/TimeDependentOptions/ExpansionMap.hpp" +#include "Domain/Creators/TimeDependentOptions/RotationMap.hpp" #include "Domain/Creators/TimeDependentOptions/ShapeMap.hpp" +#include "Domain/Creators/TimeDependentOptions/TranslationMap.hpp" #include "Domain/FunctionsOfTime/FunctionOfTime.hpp" #include "Domain/Structure/ObjectLabel.hpp" #include "Options/Auto.hpp" @@ -88,112 +91,12 @@ struct TimeDependentMapOptions { using ShapeMapOptions = time_dependent_options::ShapeMapOptions; - struct RotationMapOptions { - using type = Options::Auto; - static std::string name() { return "RotationMap"; } - static constexpr Options::String help = { - "Options for a time-dependent rotation map about an arbitrary axis. " - "Specify 'None' to not use this map."}; - - struct InitialValues { - using type = std::array, 3>; - static constexpr Options::String help = { - "The initial values for the quaternion function and its first two " - "derivatives."}; - }; - - struct DecayTimescaleRotation { - using type = double; - static constexpr Options::String help = { - "The timescale for how fast the rotation approaches its asymptotic " - "value."}; - }; - - using options = tmpl::list; - RotationMapOptions(); - RotationMapOptions(std::array, 3> initial_values_in, - double decay_timescale_in); - - std::array, 3> initial_values{}; - double decay_timescale{std::numeric_limits::signaling_NaN()}; - }; - - struct ExpansionMapOptions { - using type = Options::Auto; - static std::string name() { return "ExpansionMap"; } - static constexpr Options::String help = { - "Options for the expansion map. Specify 'None' to not use this map."}; - - struct InitialValues { - using type = std::array; - static constexpr Options::String help = { - "Initial value and first two derivatives of expansion."}; - }; - - struct DecayTimescaleExpansion { - using type = double; - static constexpr Options::String help = { - "The timescale for how fast the expansion approaches " - "its asymptotic value."}; - }; + using RotationMapOptions = time_dependent_options::RotationMapOptions<2>; - struct InitialValuesOuterBoundary { - using type = std::array; - static constexpr Options::String help = { - "Initial value and first two derivatives of expansion outside the " - "transition region."}; - }; + using ExpansionMapOptions = time_dependent_options::ExpansionMapOptions; - struct DecayTimescaleExpansionOuterBoundary { - using type = double; - static constexpr Options::String help = { - "The timescale for how fast the expansion approaches " - "its asymptotic value outside the transition region."}; - }; - - using options = tmpl::list; - ExpansionMapOptions(); - ExpansionMapOptions(std::array initial_values_in, - double decay_timescale_in, - std::array initial_values_outer_boundary_in, - double decay_timescale_outer_boundary_in); - - std::array initial_values{ - std::numeric_limits::signaling_NaN(), - std::numeric_limits::signaling_NaN(), - std::numeric_limits::signaling_NaN()}; - double decay_timescale{std::numeric_limits::signaling_NaN()}; - std::array initial_values_outer_boundary{ - std::numeric_limits::signaling_NaN(), - std::numeric_limits::signaling_NaN(), - std::numeric_limits::signaling_NaN()}; - double decay_timescale_outer_boundary{ - std::numeric_limits::signaling_NaN()}; - }; - - struct TranslationMapOptions { - using type = Options::Auto; - static std::string name() { return "TranslationMap"; } - static constexpr Options::String help = { - "Options for a time-dependent translation map in that keeps the " - "outer boundary fixed. Specify 'None' to not use this map."}; - - struct InitialValues { - using type = std::array, 3>; - static constexpr Options::String help = { - "Initial values for the translation map, its velocity and " - "acceleration."}; - }; - - using options = tmpl::list; - TranslationMapOptions(); - explicit TranslationMapOptions( - std::array, 3> initial_values_in); - - std::array, 3> initial_values{}; - }; + using TranslationMapOptions = + time_dependent_options::TranslationMapOptions<3>; using options = tmpl::list; diff --git a/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.cpp b/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.cpp index 444ad20765a3..b92cfa5958ee 100644 --- a/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.cpp +++ b/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.cpp @@ -26,7 +26,7 @@ std::vector strahlkorper_coefs_in_ringdown_distorted_frame( const double settling_timescale, const std::array& exp_func_and_2_derivs, const std::array& exp_outer_bdry_func_and_2_derivs, - const std::array, 3>& rot_func_and_2_derivs) { + const std::vector>& rot_func_and_2_derivs) { // Read the AhC coefficients from the H5 file const std::vector>& ahc_inertial_h5 = ylm::read_surface_ylm( @@ -52,11 +52,12 @@ std::vector strahlkorper_coefs_in_ringdown_distorted_frame( const domain::creators::sphere::TimeDependentMapOptions::ShapeMapOptions shape_map_options{l_max, std::nullopt, std::nullopt}; const domain::creators::sphere::TimeDependentMapOptions::ExpansionMapOptions - expansion_map_options{exp_func_and_2_derivs, settling_timescale, - exp_outer_bdry_func_and_2_derivs, - settling_timescale}; + expansion_map_options{ + exp_func_and_2_derivs, exp_outer_bdry_func_and_2_derivs, + settling_timescale, settling_timescale, std::nullopt}; const domain::creators::sphere::TimeDependentMapOptions::RotationMapOptions - rotation_map_options{rot_func_and_2_derivs, settling_timescale}; + rotation_map_options{rot_func_and_2_derivs, std::nullopt, + settling_timescale}; const domain::creators::sphere::TimeDependentMapOptions time_dependent_map_options{match_time, shape_map_options, rotation_map_options, expansion_map_options, diff --git a/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.hpp b/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.hpp index 835a1a7ee303..ea6c83b7d109 100644 --- a/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.hpp +++ b/src/Evolution/Ringdown/StrahlkorperCoefsInRingdownDistortedFrame.hpp @@ -39,5 +39,5 @@ std::vector strahlkorper_coefs_in_ringdown_distorted_frame( double settling_timescale, const std::array& exp_func_and_2_derivs, const std::array& exp_outer_bdry_func_and_2_derivs, - const std::array, 3>& rot_func_and_2_derivs); + const std::vector>& rot_func_and_2_derivs); } // namespace evolution::Ringdown diff --git a/tests/Unit/Domain/Creators/Test_Sphere.cpp b/tests/Unit/Domain/Creators/Test_Sphere.cpp index f8f8e30b01f3..48178b985c5b 100644 --- a/tests/Unit/Domain/Creators/Test_Sphere.cpp +++ b/tests/Unit/Domain/Creators/Test_Sphere.cpp @@ -601,10 +601,10 @@ void test_parse_errors() { radial_distribution, which_wedges, TDMO{1.0, TDMO::ShapeMapOptions{5, std::nullopt}, std::nullopt, std::nullopt, - TDMO::TranslationMapOptions{ - {std::array{0.0, 0.0, 0.0}, - std::array{0.001, -0.003, 0.005}, - std::array{0.0, 0.0, 0.0}}}}, + TDMO::TranslationMapOptions{std::array{ + std::array{0.0, 0.0, 0.0}, + std::array{0.001, -0.003, 0.005}, + std::array{0.0, 0.0, 0.0}}}}, nullptr), Catch::Matchers::ContainsSubstring( "Currently cannot use hard-coded time dependent maps with an inner " @@ -712,8 +712,9 @@ void test_sphere(const gsl::not_null gen) { l_max, std::nullopt}, std::nullopt, std::nullopt, creators::sphere::TimeDependentMapOptions::TranslationMapOptions{ - {std::array{0.0, 0.0, 0.0}, translation_velocity, - std::array{0.0, 0.0, 0.0}}}); + std::array{std::array{0.0, 0.0, 0.0}, + translation_velocity, + std::array{0.0, 0.0, 0.0}}}); } else { time_dependent_options = std::make_unique< domain::creators::time_dependence::UniformTranslation<3, 0>>( diff --git a/tests/Unit/Evolution/Ringdown/Test_StrahlkorperCoefsInRingdownDistortedFrame.cpp b/tests/Unit/Evolution/Ringdown/Test_StrahlkorperCoefsInRingdownDistortedFrame.cpp index cd3dcdd678ad..6bff874bdb5f 100644 --- a/tests/Unit/Evolution/Ringdown/Test_StrahlkorperCoefsInRingdownDistortedFrame.cpp +++ b/tests/Unit/Evolution/Ringdown/Test_StrahlkorperCoefsInRingdownDistortedFrame.cpp @@ -86,7 +86,7 @@ SPECTRE_TEST_CASE( for (size_t i = 0; i < 4; ++i) { gsl::at(initial_unit_quaternion, i) /= initial_unit_quaternion_magnitude; } - const std::array, 3> rot_func_and_2_derivs{ + const std::vector> rot_func_and_2_derivs{ initial_unit_quaternion, make_with_random_values>(make_not_null(&generator), make_not_null(&fot_dist)), @@ -99,11 +99,12 @@ SPECTRE_TEST_CASE( const domain::creators::sphere::TimeDependentMapOptions::ShapeMapOptions shape_map_options{l_max, std::nullopt}; const domain::creators::sphere::TimeDependentMapOptions::ExpansionMapOptions - expansion_map_options{exp_func_and_2_derivs, settling_timescale, - exp_outer_bdry_func_and_2_derivs, - settling_timescale}; + expansion_map_options{ + exp_func_and_2_derivs, exp_outer_bdry_func_and_2_derivs, + settling_timescale, settling_timescale, std::nullopt}; const domain::creators::sphere::TimeDependentMapOptions::RotationMapOptions - rotation_map_options{rot_func_and_2_derivs, settling_timescale}; + rotation_map_options{rot_func_and_2_derivs, std::nullopt, + settling_timescale}; const domain::creators::sphere::TimeDependentMapOptions time_dependent_map_options{match_time, shape_map_options, rotation_map_options, expansion_map_options,