Skip to content

Commit

Permalink
Add rigid translation
Browse files Browse the repository at this point in the history
  • Loading branch information
guilara committed Oct 21, 2023
1 parent 7bbe997 commit 0f3c17f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
6 changes: 5 additions & 1 deletion src/Domain/Creators/Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,13 @@ Domain<3> Sphere::create_domain() const {
time_dependent_options_.value());

// First shell gets the distorted maps.
// Last shell gets translation with transition region
for (size_t block_id = 0; block_id < num_blocks_; block_id++) {
const bool include_distorted_map_in_first_shell =
block_id < num_blocks_per_shell_;
// False if block_id is in the last shell
const bool use_rigid_translation =
block_id + num_blocks_per_shell_ < num_blocks_;
block_maps_grid_to_distorted[block_id] =
hard_coded_options.grid_to_distorted_map(
include_distorted_map_in_first_shell);
Expand All @@ -394,7 +398,7 @@ Domain<3> Sphere::create_domain() const {
include_distorted_map_in_first_shell);
block_maps_grid_to_inertial[block_id] =
hard_coded_options.grid_to_inertial_map(
include_distorted_map_in_first_shell);
include_distorted_map_in_first_shell, use_rigid_translation);
}
} else {
const auto& time_dependence = std::get<std::unique_ptr<
Expand Down
11 changes: 8 additions & 3 deletions src/Domain/Creators/SphereTimeDependentMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void TimeDependentMapOptions::build_maps(
initial_l_max_, std::move(transition_func),
shape_name, size_name};

rigid_translation_map_ = TranslationMap{translation_name};

if (translation_transition_radii.has_value()) {
// Uniform translation
translation_map_ = TranslationMap{
Expand All @@ -154,7 +156,8 @@ TimeDependentMapOptions::MapType<Frame::Distorted, Frame::Inertial>
TimeDependentMapOptions::distorted_to_inertial_map(
const bool include_distorted_map) const {
if (include_distorted_map) {
return std::make_unique<DistortedToInertialComposition>(translation_map_);
return std::make_unique<DistortedToInertialComposition>(
rigid_translation_map_);
} else {
return nullptr;
}
Expand All @@ -172,10 +175,12 @@ TimeDependentMapOptions::grid_to_distorted_map(

TimeDependentMapOptions::MapType<Frame::Grid, Frame::Inertial>
TimeDependentMapOptions::grid_to_inertial_map(
const bool include_distorted_map) const {
const bool include_distorted_map, const bool use_rigid_translation) const {
if (include_distorted_map) {
return std::make_unique<GridToInertialComposition>(shape_map_,
translation_map_);
rigid_translation_map_);
} else if (use_rigid_translation) {
return std::make_unique<GridToInertialSimple>(rigid_translation_map_);
} else {
return std::make_unique<GridToInertialSimple>(translation_map_);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Domain/Creators/SphereTimeDependentMaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ struct TimeDependentMapOptions {
* only be an identity map.
*/
MapType<Frame::Grid, Frame::Inertial> grid_to_inertial_map(
bool include_distorted_map) const;
bool include_distorted_map, const bool use_rigid_translation) const;

Check failure on line 226 in src/Domain/Creators/SphereTimeDependentMaps.hpp

View workflow job for this annotation

GitHub Actions / Clang-tidy (Debug)

parameter 'use_rigid_translation' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions

Check failure on line 226 in src/Domain/Creators/SphereTimeDependentMaps.hpp

View workflow job for this annotation

GitHub Actions / Clang-tidy (Release)

parameter 'use_rigid_translation' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions

inline static const std::string size_name{"Size"};
inline static const std::string shape_name{"Shape"};
Expand All @@ -233,6 +233,7 @@ struct TimeDependentMapOptions {
double initial_time_{std::numeric_limits<double>::signaling_NaN()};
size_t initial_l_max_{};
ShapeMap shape_map_{};
TranslationMap rigid_translation_map_{};
TranslationMap translation_map_{};
std::optional<std::variant<KerrSchildFromBoyerLindquist>>
initial_shape_values_{};
Expand Down
72 changes: 37 additions & 35 deletions tests/Unit/Domain/Creators/Test_SphereTimeDependentMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,43 @@ void test(const bool use_non_zero_shape) {
.get()) == translation_non_zero);

for (const bool include_distorted : make_array(true, false)) {
time_dep_options.build_maps(
center, inner_radius, outer_radius,
std::pair<double, double>{translation_inner_radius,
translation_outer_radius});

const auto grid_to_distorted_map =
time_dep_options.grid_to_distorted_map(include_distorted);
const auto grid_to_inertial_map =
time_dep_options.grid_to_inertial_map(include_distorted);
const auto distorted_to_inertial_map =
time_dep_options.distorted_to_inertial_map(include_distorted);

// All of these maps are tested individually. Rather than going through the
// effort of coming up with a source coordinate and calculating analytically
// what we would get after it's mapped, we just check that whether it's
// supposed to be a nullptr and if it's not, if it's the identity and that
// the jacobians are time dependent.
const auto check_map = [](const auto& map, const bool is_null,
const bool is_identity) {
if (is_null) {
CHECK(map == nullptr);
} else {
CHECK(map->is_identity() == is_identity);
CHECK(map->inv_jacobian_is_time_dependent() == not is_identity);
CHECK(map->jacobian_is_time_dependent() == not is_identity);
}
};

// There is no null pointer in the grid to inertial map
check_map(grid_to_inertial_map, false, false);

check_map(grid_to_distorted_map, not include_distorted, false);

// If no shape distortion, there is only the translation
check_map(distorted_to_inertial_map, not include_distorted, false);
for (const bool use_rigid_translation : make_array(true, false)) {
time_dep_options.build_maps(
center, inner_radius, outer_radius,
std::pair<double, double>{translation_inner_radius,
translation_outer_radius});

const auto grid_to_distorted_map =
time_dep_options.grid_to_distorted_map(include_distorted);
const auto grid_to_inertial_map = time_dep_options.grid_to_inertial_map(
include_distorted, use_rigid_translation);
const auto distorted_to_inertial_map =
time_dep_options.distorted_to_inertial_map(include_distorted);

// All of these maps are tested individually. Rather than going through
// the effort of coming up with a source coordinate and calculating
// analytically what we would get after it's mapped, we just check that
// whether it's supposed to be a nullptr and if it's not, if it's the
// identity and that the jacobians are time dependent.
const auto check_map = [](const auto& map, const bool is_null,
const bool is_identity) {
if (is_null) {
CHECK(map == nullptr);
} else {
CHECK(map->is_identity() == is_identity);
CHECK(map->inv_jacobian_is_time_dependent() == not is_identity);
CHECK(map->jacobian_is_time_dependent() == not is_identity);
}
};

// There is no null pointer in the grid to inertial map
check_map(grid_to_inertial_map, false, false);

check_map(grid_to_distorted_map, not include_distorted, false);

// If no shape distortion, there is only the translation
check_map(distorted_to_inertial_map, not include_distorted, false);
}
}
}

Expand Down

0 comments on commit 0f3c17f

Please sign in to comment.