Skip to content

Commit

Permalink
Clean up Sphere TimeDependentOptions
Browse files Browse the repository at this point in the history
Removes the ability to independently specify size coefficients
because it wasn't used in practice. If we need to specify size
coefficients we should do it from a file.
  • Loading branch information
knelli2 committed Oct 11, 2023
1 parent b6ed934 commit 42393ca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 101 deletions.
27 changes: 6 additions & 21 deletions src/Domain/Creators/SphereTimeDependentMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@

namespace domain::creators::sphere {
TimeDependentMapOptions::TimeDependentMapOptions(
const double initial_time,
const std::optional<std::array<double, 3>>& initial_size_values,
const size_t initial_l_max,
const typename ShapeMapInitialValues::type::value_type&
initial_shape_values)
const double initial_time, const ShapeMapOptions& shape_map_options)
: initial_time_(initial_time),
initial_size_values_(initial_size_values),
initial_l_max_(initial_l_max),
initial_shape_values_(initial_shape_values) {}
initial_l_max_(shape_map_options.l_max),
initial_shape_values_(shape_map_options.initial_values) {}

std::unordered_map<std::string,
std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>
Expand All @@ -62,7 +57,7 @@ TimeDependentMapOptions::create_functions_of_time(
DataVector shape_zeros{
ylm::Spherepack::spectral_size(initial_l_max_, initial_l_max_), 0.0};
DataVector shape_func{};
double size_func_from_shape = std::numeric_limits<double>::signaling_NaN();
DataVector size_func{1, 0.0};

if (initial_shape_values_.has_value()) {
if (std::holds_alternative<KerrSchildFromBoyerLindquist>(
Expand All @@ -77,18 +72,15 @@ TimeDependentMapOptions::create_functions_of_time(
inner_radius;
shape_func = ylm.phys_to_spec(radial_distortion);
// Transform from SPHEREPACK to actual Ylm for size func
size_func_from_shape = shape_func[0] * sqrt(0.5 * M_PI);
size_func[0] = shape_func[0] * sqrt(0.5 * M_PI);
// Set l=0 for shape map to 0 because size is going to be used
shape_func[0] = 0.0;
}
} else {
shape_func = shape_zeros;
size_func_from_shape = 0.0;
size_func[0] = 0.0;
}

ASSERT(not std::isnan(size_func_from_shape),
"Size func value from shape coefficients is NaN.");

// ShapeMap FunctionOfTime
result[shape_name] =
std::make_unique<FunctionsOfTime::PiecewisePolynomial<2>>(
Expand All @@ -97,16 +89,9 @@ TimeDependentMapOptions::create_functions_of_time(
{std::move(shape_func), shape_zeros, shape_zeros}},
expiration_times.at(shape_name));

DataVector size_func{1, size_func_from_shape};
DataVector size_deriv{1, 0.0};
DataVector size_2nd_deriv{1, 0.0};

if (initial_size_values_.has_value()) {
size_func[0] = gsl::at(initial_size_values_.value(), 0);
size_deriv[0] = gsl::at(initial_size_values_.value(), 1);
size_2nd_deriv[0] = gsl::at(initial_size_values_.value(), 2);
}

// Size FunctionOfTime (used in ShapeMap)
result[size_name] = std::make_unique<FunctionsOfTime::PiecewisePolynomial<3>>(
initial_time_,
Expand Down
70 changes: 26 additions & 44 deletions src/Domain/Creators/SphereTimeDependentMaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ struct Spherical {};
* \brief This holds all options related to the time dependent maps of the
* domain::creators::Sphere domain creator.
*
* \details Currently this class will only add a Size and a Shape map (and
* FunctionsOfTime) to the domain. Other maps can be added as needed.
* \details Currently this class will only add a Shape map (and size
* FunctionOfTime) to the domain. Other maps can be added as needed.
*
* \note This struct contains no information about what blocks the time
* dependent maps will go in.
Expand Down Expand Up @@ -104,60 +104,42 @@ struct TimeDependentMapOptions {
"The initial time of the functions of time"};
};

struct SizeMap {
static constexpr Options::String help = {
"Options for a time-dependent size map in the inner-most shell of the "
"domain."};
};

struct SizeMapInitialValues {
static std::string name() { return "InitialValues"; }
using type = Options::Auto<std::array<double, 3>>;
static constexpr Options::String help = {
"Initial value and two derivatives of the size map. Specify 'Auto' to "
"use the l=0 coefficient calculated from the shape map Ylm "
"coefficients (derivs will be zero)."};
using group = SizeMap;
};

struct ShapeMapOptions {
using type = ShapeMapOptions;
static std::string name() { return "ShapeMap"; }
static constexpr Options::String help = {
"Options for a time-dependent size map in the inner-most shell of the "
"Options for a time-dependent shape map in the inner-most shell of the "
"domain."};
};

struct ShapeMapLMax {
static std::string name() { return "LMax"; }
using type = size_t;
static constexpr Options::String help = {"Initial LMax for the shape map."};
using group = ShapeMapOptions;
};
struct LMax {
using type = size_t;
static constexpr Options::String help = {
"Initial LMax for the shape map."};
};

struct ShapeMapInitialValues {
static std::string name() { return "InitialValues"; }
using type =
Options::Auto<std::variant<KerrSchildFromBoyerLindquist>, Spherical>;
static constexpr Options::String help = {
"Initial Ylm coefficients for the shape map. Specify 'Spherical' for "
"all coefficients to be initialized to zero."};
using group = ShapeMapOptions;
struct InitialValues {
using type =
Options::Auto<std::variant<KerrSchildFromBoyerLindquist>, Spherical>;
static constexpr Options::String help = {
"Initial Ylm coefficients for the shape map. Specify 'Spherical' for "
"all coefficients to be initialized to zero."};
};

using options = tmpl::list<LMax, InitialValues>;

size_t l_max{};
std::optional<std::variant<KerrSchildFromBoyerLindquist>> initial_values{};
};

using options = tmpl::list<InitialTime, SizeMapInitialValues, ShapeMapLMax,
ShapeMapInitialValues>;
using options = tmpl::list<InitialTime, ShapeMapOptions>;
static constexpr Options::String help{
"The options for all the hard-coded time dependent maps in the Sphere "
"domain."};

TimeDependentMapOptions() = default;

TimeDependentMapOptions(
double initial_time,
const std::optional<std::array<double, 3>>& initial_size_values,
size_t initial_l_max,
const typename ShapeMapInitialValues::type::value_type&
initial_shape_values);
TimeDependentMapOptions(double initial_time,
const ShapeMapOptions& shape_map_options);

/*!
* \brief Create the function of time map using the options that were
Expand Down Expand Up @@ -220,9 +202,9 @@ struct TimeDependentMapOptions {

private:
double initial_time_{std::numeric_limits<double>::signaling_NaN()};
std::optional<std::array<double, 3>> initial_size_values_{};
size_t initial_l_max_{};
ShapeMap shape_map_{};
typename ShapeMapInitialValues::type::value_type initial_shape_values_{};
std::optional<std::variant<KerrSchildFromBoyerLindquist>>
initial_shape_values_{};
};
} // namespace domain::creators::sphere
22 changes: 10 additions & 12 deletions tests/Unit/Domain/Creators/Test_Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ std::string option_string(
time_dependent ? (hard_coded_time_dependent_maps
? " TimeDependentMaps:\n"
" InitialTime: 1.0\n"
" SizeMap:\n"
" InitialValues: [0.5, -0.04, 0.003]\n"
" ShapeMap:\n"
" LMax: 10\n"
" InitialValues: Spherical\n"
Expand Down Expand Up @@ -535,14 +533,13 @@ void test_parse_errors() {
Catch::Matchers::ContainsSubstring(
"None boundary condition is not supported. If you would like "
"an outflow-type boundary condition, you must use that."));
using TDMO = domain::creators::sphere::TimeDependentMapOptions;
CHECK_THROWS_WITH(
creators::Sphere(inner_radius, outer_radius, inner_cube, refinement,
initial_extents, use_equiangular_map,
equatorial_compression, radial_partitioning,
radial_distribution, which_wedges,
domain::creators::sphere::TimeDependentMapOptions{
1.0, std::nullopt, 5, std::nullopt},
nullptr),
creators::Sphere(
inner_radius, outer_radius, inner_cube, refinement, initial_extents,
use_equiangular_map, equatorial_compression, radial_partitioning,
radial_distribution, which_wedges,
TDMO{1.0, TDMO::ShapeMapOptions{5, std::nullopt}}, nullptr),
Catch::Matchers::ContainsSubstring(
"Currently cannot use hard-coded time dependent maps with an inner "
"cube. Use a TimeDependence instead."));
Expand Down Expand Up @@ -579,7 +576,7 @@ void test_sphere() {
{domain::CoordinateMaps::Distribution::Linear}}};

const std::array<double, 3> velocity{{2.3, -0.3, 0.5}};
const std::array<double, 3> size_values{0.5, -0.04, 0.003};
const std::array<double, 3> size_values{0.0, 0.0, 0.0};
const size_t l_max = 10;
const std::vector<double> times{1., 10.};

Expand Down Expand Up @@ -633,7 +630,8 @@ void test_sphere() {
if (time_dependent) {
if (use_hard_coded_time_dep_options) {
time_dependent_options = creators::sphere::TimeDependentMapOptions(
1.0, size_values, l_max, std::nullopt);
1.0, creators::sphere::TimeDependentMapOptions::ShapeMapOptions{
l_max, std::nullopt});
} else {
time_dependent_options = std::make_unique<
domain::creators::time_dependence::UniformTranslation<3, 0>>(
Expand All @@ -660,7 +658,7 @@ void test_sphere() {
with_boundary_conditions,
time_dependent ? times : std::vector<double>{0.},
time_dependent ? velocity : std::array<double, 3>{{0., 0., 0.}},
time_dependent ? size_values : std::array<double, 3>{{0., 0., 0.}});
size_values);
TestHelpers::domain::creators::test_creation(
option_string(inner_radius, outer_radius, interior, initial_refinement,
initial_extents, equiangular, equatorial_compression,
Expand Down
27 changes: 5 additions & 22 deletions tests/Unit/Domain/Creators/Test_SphereTimeDependentMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,23 @@ struct Inertial;

namespace domain::creators::sphere {
namespace {
std::string create_option_string(const bool use_non_zero_shape,
const bool use_size_from_shape) {
std::string create_option_string(const bool use_non_zero_shape) {
return "InitialTime: 1.5\n"
"SizeMap:\n" +
(use_size_from_shape ? " InitialValues: Auto\n"s
: " InitialValues: [0.9, 0.08, 0.007]\n"s) +
"ShapeMap:\n"
" LMax: 8\n" +
(use_non_zero_shape ? " InitialValues:\n"
" Mass: 1.0\n"
" Spin: [0.0, 0.0, 0.0]\n"s
: " InitialValues: Spherical\n"s);
}
void test(const bool use_non_zero_shape, const bool use_size_from_shape) {
void test(const bool use_non_zero_shape) {
CAPTURE(use_non_zero_shape);
CAPTURE(use_size_from_shape);
const double initial_time = 1.5;
const size_t l_max = 8;
std::optional<std::array<double, 3>> size_values{};

if (not use_size_from_shape) {
size_values = std::array{0.9, 0.08, 0.007};
}

TimeDependentMapOptions time_dep_options =
TestHelpers::test_creation<TimeDependentMapOptions>(
create_option_string(use_non_zero_shape, use_size_from_shape));
create_option_string(use_non_zero_shape));

std::unordered_map<std::string, double> expiration_times{
{TimeDependentMapOptions::shape_name, 15.5},
Expand All @@ -69,11 +59,6 @@ void test(const bool use_non_zero_shape, const bool use_size_from_shape) {
DataVector size_func{1, 0.0};
DataVector size_deriv{1, 0.0};
DataVector size_2nd_deriv{1, 0.0};
if (not use_size_from_shape) {
size_func[0] = gsl::at(size_values.value(), 0);
size_deriv[0] = gsl::at(size_values.value(), 1);
size_2nd_deriv[0] = gsl::at(size_values.value(), 2);
}
PP3 size{
initial_time,
std::array<DataVector, 4>{{size_func, size_deriv, size_2nd_deriv, {0.0}}},
Expand Down Expand Up @@ -150,9 +135,7 @@ SPECTRE_TEST_CASE("Unit.Domain.Creators.SphereTimeDependentMaps",
"[Domain][Unit]") {
test_shape_initial_values();

for (auto& [use_non_zero_shape, use_size_from_shape] :
cartesian_product(make_array(true, false), make_array(true, false))) {
test(use_non_zero_shape, use_size_from_shape);
}
test(true);
test(false);
}
} // namespace domain::creators::sphere
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ template <typename Frame>
void test() {
domain::FunctionsOfTime::register_derived_with_charm();

domain::creators::sphere::TimeDependentMapOptions time_dep_opts{
0.0, std::nullopt, 2, std::nullopt};
using TDMO = domain::creators::sphere::TimeDependentMapOptions;
TDMO time_dep_opts{0.0, TDMO::ShapeMapOptions{2, std::nullopt}};

const auto domain_creator = domain::creators::Sphere(
0.9, 4.9, domain::creators::Sphere::Excision{}, 1_st, 7_st, false, {}, {},
Expand Down

0 comments on commit 42393ca

Please sign in to comment.