-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Skew map #6446
Open
knelli2
wants to merge
4
commits into
sxs-collaboration:develop
Choose a base branch
from
knelli2:skew_map
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+904
−0
Open
Add Skew map #6446
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
#include "Framework/TestingFramework.hpp" | ||
|
||
#include <array> | ||
#include <cmath> | ||
#include <cstddef> | ||
#include <limits> | ||
#include <optional> | ||
#include <random> | ||
#include <string> | ||
|
@@ -25,10 +27,12 @@ | |
|
||
namespace domain { | ||
namespace { | ||
constexpr size_t deriv_order = 2; | ||
using Polynomial = domain::FunctionsOfTime::PiecewisePolynomial<deriv_order>; | ||
using FoftPtr = std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>; | ||
|
||
template <typename Generator> | ||
void test(const gsl::not_null<Generator*> generator) { | ||
static constexpr size_t deriv_order = 2; | ||
|
||
const double initial_time = 0.5; | ||
double t = initial_time + 0.05; | ||
const double dt = 0.6; | ||
|
@@ -42,8 +46,6 @@ void test(const gsl::not_null<Generator*> generator) { | |
std::uniform_real_distribution<double> point_dist{-5.0, 5.0}; | ||
// NOLINTEND | ||
|
||
using Polynomial = domain::FunctionsOfTime::PiecewisePolynomial<deriv_order>; | ||
using FoftPtr = std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>; | ||
std::unordered_map<std::string, FoftPtr> f_of_t_list{}; | ||
f_of_t_list[function_of_time_name] = std::make_unique<Polynomial>( | ||
initial_time, | ||
|
@@ -113,11 +115,74 @@ void test(const gsl::not_null<Generator*> generator) { | |
CHECK(skew_map == skew_map_deserialized); | ||
CHECK_FALSE(skew_map != skew_map_deserialized); | ||
} | ||
|
||
void test_specific_points() { | ||
const std::string function_of_time_name{"Skew"}; | ||
const double time = 0.0; | ||
std::unordered_map<std::string, FoftPtr> f_of_t_list{}; | ||
// Use pi/4 so math is easy | ||
f_of_t_list[function_of_time_name] = std::make_unique<Polynomial>( | ||
time, | ||
std::array{DataVector{M_PI_4, M_PI_4}, DataVector{2, 0.0}, | ||
DataVector{2, 0.0}}, | ||
std::numeric_limits<double>::infinity()); | ||
|
||
const std::array<double, 3> center{-1.0, 1.0, 0.0}; | ||
const double outer_radius = 100.0; | ||
|
||
const CoordinateMaps::TimeDependent::Skew skew_map{function_of_time_name, | ||
center, outer_radius}; | ||
|
||
std::array<double, 3> test_point{}; | ||
{ | ||
INFO("Center"); | ||
test_point = center; | ||
CAPTURE(test_point); | ||
|
||
const auto mapped_point = skew_map(test_point, time, f_of_t_list); | ||
CHECK_ITERABLE_APPROX(mapped_point, (std::array{0.0, 1.0, 0.0})); | ||
const auto inverse_point = | ||
skew_map.inverse(mapped_point, time, f_of_t_list); | ||
CHECK(inverse_point.has_value()); | ||
CHECK_ITERABLE_APPROX(inverse_point.value(), test_point); | ||
// Jacobian not defined at the center | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we not need it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear. SpEC didn't handle this specially (and thus would get a division by zero error if the center was passed to the jacobian). |
||
} | ||
{ | ||
INFO("Outer radius"); | ||
test_point = std::array{0.0, 0.0, outer_radius}; | ||
CAPTURE(test_point); | ||
|
||
const auto mapped_point = skew_map(test_point, time, f_of_t_list); | ||
CHECK_ITERABLE_APPROX(mapped_point, test_point); | ||
const auto inverse_point = | ||
skew_map.inverse(mapped_point, time, f_of_t_list); | ||
CHECK(inverse_point.has_value()); | ||
CHECK_ITERABLE_APPROX(inverse_point.value(), test_point); | ||
const auto jacobian = skew_map.jacobian(test_point, time, f_of_t_list); | ||
CHECK_ITERABLE_APPROX(jacobian, identity<3>(0.0)); | ||
} | ||
{ | ||
INFO("Outer radius plus eps"); | ||
const double eps = std::numeric_limits<double>::epsilon(); | ||
test_point = std::array{0.0, 0.0, outer_radius + eps}; | ||
CAPTURE(test_point); | ||
|
||
const auto mapped_point = skew_map(test_point, time, f_of_t_list); | ||
CHECK_ITERABLE_APPROX(mapped_point, test_point); | ||
const auto inverse_point = | ||
skew_map.inverse(mapped_point, time, f_of_t_list); | ||
CHECK(inverse_point.has_value()); | ||
CHECK_ITERABLE_APPROX(inverse_point.value(), test_point); | ||
const auto jacobian = skew_map.jacobian(test_point, time, f_of_t_list); | ||
CHECK_ITERABLE_APPROX(jacobian, identity<3>(0.0)); | ||
} | ||
} | ||
} // namespace | ||
|
||
SPECTRE_TEST_CASE("Unit.Domain.CoordinateMaps.TimeDependent.Skew", | ||
"[Domain][Unit]") { | ||
MAKE_GENERATOR(generator); | ||
test(make_not_null(&generator)); | ||
test_specific_points(); | ||
} | ||
} // namespace domain |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just do this:
Then you don't need any of these const-casts etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: I think in other maps we just do math with
cref(DataVector)
and that seems to work, see Wedge.cpp. Haven't checked the details.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I want to do math with the entire
std::array
, not the individual components. However, that math won't work between astd::array<DataVector>
andstd::array<std::reference_wrapper<const DataVector>>
. That's why I const cast.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok const-casts are pretty dangerous so maybe sprinkle some dereferencing in
StdArrayHelpers.hpp
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
const_cast
in a lot of places for this exact purpose (to set data references). Quick VSCode/git search shows 136 occurrences in 64 files