Skip to content

Commit

Permalink
Use common time dep opts in Sphere domain
Browse files Browse the repository at this point in the history
  • Loading branch information
knelli2 committed Jun 25, 2024
1 parent 2199369 commit d576853
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 164 deletions.
96 changes: 40 additions & 56 deletions src/Domain/Creators/TimeDependentOptions/Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ TimeDependentMapOptions::create_functions_of_time(
std::unordered_map<std::string, double> expiration_times{
{size_name, std::numeric_limits<double>::infinity()},
{shape_name, std::numeric_limits<double>::infinity()},
{rotation_name, std::numeric_limits<double>::infinity()},
{expansion_name, std::numeric_limits<double>::infinity()},
{translation_name, std::numeric_limits<double>::infinity()}};

// If we have control systems, overwrite these expiration times with the ones
Expand Down Expand Up @@ -84,75 +86,57 @@ TimeDependentMapOptions::create_functions_of_time(

// ExpansionMap FunctionOfTime
if (expansion_map_options_.has_value()) {
result[expansion_name] =
std::make_unique<FunctionsOfTime::SettleToConstant>(
std::array<DataVector, 3>{
{{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<FunctionsOfTime::SettleToConstant>(
expansion_map_options_->initial_values, initial_time_,
expansion_map_options_->decay_timescale.value());
} else {
result[expansion_name] =
std::make_unique<FunctionsOfTime::PiecewisePolynomial<2>>(
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<DataVector, 3>{
{{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<FunctionsOfTime::FixedSpeedCubic>(
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<FunctionsOfTime::SettleToConstant>(
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<FunctionsOfTime::QuaternionFunctionOfTime<2>>(
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<FunctionsOfTime::SettleToConstantQuaternion>(
rotation_map_options_->quaternions, initial_time_,
rotation_map_options_->decay_timescale.value());
}
result[rotation_name] =
std::make_unique<FunctionsOfTime::SettleToConstantQuaternion>(
std::array<DataVector, 3>{
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<FunctionsOfTime::PiecewisePolynomial<2>>(
initial_time_,
std::array<DataVector, 3>{
{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));
}

Expand Down
100 changes: 7 additions & 93 deletions src/Domain/Creators/TimeDependentOptions/Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -88,101 +91,12 @@ struct TimeDependentMapOptions {
using ShapeMapOptions =
time_dependent_options::ShapeMapOptions<false, domain::ObjectLabel::None>;

struct RotationMapOptions {
using type = Options::Auto<RotationMapOptions, Options::AutoLabel::None>;
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<std::array<double, 4>, 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<InitialValues, DecayTimescaleRotation>;

std::array<std::array<double, 4>, 3> initial_values{};
double decay_timescale{std::numeric_limits<double>::signaling_NaN()};
};

struct ExpansionMapOptions {
using type = Options::Auto<ExpansionMapOptions, Options::AutoLabel::None>;
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<double, 3>;
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<double, 3>;
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<InitialValues, DecayTimescaleExpansion,
InitialValuesOuterBoundary,
DecayTimescaleExpansionOuterBoundary>;

std::array<double, 3> initial_values{
std::numeric_limits<double>::signaling_NaN(),
std::numeric_limits<double>::signaling_NaN(),
std::numeric_limits<double>::signaling_NaN()};
double decay_timescale{std::numeric_limits<double>::signaling_NaN()};
std::array<double, 3> initial_values_outer_boundary{
std::numeric_limits<double>::signaling_NaN(),
std::numeric_limits<double>::signaling_NaN(),
std::numeric_limits<double>::signaling_NaN()};
double decay_timescale_outer_boundary{
std::numeric_limits<double>::signaling_NaN()};
};

struct TranslationMapOptions {
using type = Options::Auto<TranslationMapOptions, Options::AutoLabel::None>;
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<std::array<double, 3>, 3>;
static constexpr Options::String help = {
"Initial values for the translation map, its velocity and "
"acceleration."};
};

using options = tmpl::list<InitialValues>;

std::array<std::array<double, 3>, 3> initial_values{};
};
using TranslationMapOptions =
time_dependent_options::TranslationMapOptions<3>;

using options = tmpl::list<InitialTime, ShapeMapOptions, RotationMapOptions,
ExpansionMapOptions, TranslationMapOptions>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::vector<DataVector> strahlkorper_coefs_in_ringdown_distorted_frame(
const double settling_timescale,
const std::array<double, 3>& exp_func_and_2_derivs,
const std::array<double, 3>& exp_outer_bdry_func_and_2_derivs,
const std::array<std::array<double, 4>, 3>& rot_func_and_2_derivs) {
const std::vector<std::array<double, 4>>& rot_func_and_2_derivs) {
// Read the AhC coefficients from the H5 file
const std::vector<ylm::Strahlkorper<Frame::Inertial>>& ahc_inertial_h5 =
ylm::read_surface_ylm<Frame::Inertial>(
Expand All @@ -52,11 +52,12 @@ std::vector<DataVector> strahlkorper_coefs_in_ringdown_distorted_frame(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ std::vector<DataVector> strahlkorper_coefs_in_ringdown_distorted_frame(
double settling_timescale,
const std::array<double, 3>& exp_func_and_2_derivs,
const std::array<double, 3>& exp_outer_bdry_func_and_2_derivs,
const std::array<std::array<double, 4>, 3>& rot_func_and_2_derivs);
const std::vector<std::array<double, 4>>& rot_func_and_2_derivs);
} // namespace evolution::Ringdown
9 changes: 5 additions & 4 deletions tests/Unit/Domain/Creators/Test_Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
TDMO::TranslationMapOptions{std::array{
std::array<double, 3>{0.0, 0.0, 0.0},
std::array<double, 3>{0.001, -0.003, 0.005},
std::array<double, 3>{0.0, 0.0, 0.0}}},
std::array<double, 3>{0.0, 0.0, 0.0}}}},
nullptr),
Catch::Matchers::ContainsSubstring(
"Currently cannot use hard-coded time dependent maps with an inner "
Expand Down Expand Up @@ -712,8 +712,9 @@ void test_sphere(const gsl::not_null<Generator*> gen) {
l_max, std::nullopt},
std::nullopt, std::nullopt,
creators::sphere::TimeDependentMapOptions::TranslationMapOptions{
std::array<double, 3>{0.0, 0.0, 0.0}, translation_velocity,
std::array<double, 3>{0.0, 0.0, 0.0}});
std::array{std::array<double, 3>{0.0, 0.0, 0.0},
translation_velocity,
std::array<double, 3>{0.0, 0.0, 0.0}}});
} else {
time_dependent_options = std::make_unique<
domain::creators::time_dependence::UniformTranslation<3, 0>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::array<double, 4>, 3> rot_func_and_2_derivs{
const std::vector<std::array<double, 4>> rot_func_and_2_derivs{
initial_unit_quaternion,
make_with_random_values<std::array<double, 4>>(make_not_null(&generator),
make_not_null(&fot_dist)),
Expand All @@ -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,
Expand Down

0 comments on commit d576853

Please sign in to comment.