Skip to content
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

Enable time dependent translation with transition for Sphere domain #5576

Conversation

guilara
Copy link
Contributor

@guilara guilara commented Oct 19, 2023

Proposed changes

Add a translation map acting on the outer most shell of the spherical domain. If there is no radial partition, apply a uniform translation (since the inner boundary of the translation needs to be spherical and the shape map could also be active).

Note: The test Unit.Domain.Creators.Sphere failed because of roundoff error in assets

ASSERT(max(magnitude(result)) <= outer_radius_.value(), "Coordinates translated outside outer radius, This should not " "happen");

in

ASSERT(max(magnitude(result)) <= outer_radius_.value(),

When I printed the values during a test, the assert failed by a factor of order 10e-15 of the outer_radius_ and seemed to remain of the same order in time. Changed the assert to allow for roundoff error.

Update: issue above fixed in #5601

Upgrade instructions

Code review checklist

  • The code is documented and the documentation renders correctly. Run
    make doc to generate the documentation locally into BUILD_DIR/docs/html.
    Then open index.html.
  • The code follows the stylistic and code quality guidelines listed in the
    code review guide.
  • The PR lists upgrade instructions and is labeled bugfix or
    new feature if appropriate.

Further comments

: initial_time_(initial_time),
initial_l_max_(shape_map_options.l_max),
initial_shape_values_(shape_map_options.initial_values) {}
initial_shape_values_(shape_map_options.initial_values),
translation_velocity_(translation_velocity),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial_translation_velocity

@@ -131,15 +139,47 @@ struct TimeDependentMapOptions {
std::optional<std::variant<KerrSchildFromBoyerLindquist>> initial_values{};
};

using options = tmpl::list<InitialTime, ShapeMapOptions>;
struct TranslationMapVelocity {
static std::string name() { return "Velocity"; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitialVelocity

using group = TranslationMapOptions;
};

struct TranslationMapInnerRadius {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't take the inner and outer radii as options. Just apply the transition in the outer shell of the sphere, so inner radius is the last number in radial_partitions and outer radius is the outer radius of the sphere. Add this translation map with the transition only to the blocks that make up the outer shell. Apply a rigid translation (no inner/outer radii) to all other blocks. If there is no partition (just one shell) and the interior of the sphere is filled with a cube then either error out or apply a rigid translation (because the transition only works with spherical inner and outer radii).

@@ -115,17 +133,21 @@ void TimeDependentMapOptions::build_maps(const std::array<double, 3>& center,
shape_map_ = ShapeMap{center, initial_l_max_,
initial_l_max_, std::move(transition_func),
shape_name, size_name};
if (translation_inner_radius == translation_outer_radius) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take the translation radii as std::optional<std::pair<double, double>> then you can either pass std::nullopt or both radii.

You also have to build a second rigid translation map with no radii, which you can apply to the inner blocks. Then you don't need to remove asserts in the Translation map. I think it is necessary to have these two different maps because their Jacobian is discontinuous at the translation_inner_radius.

std::make_unique<FunctionsOfTime::PiecewisePolynomial<2>>(
initial_time_,
std::array<DataVector, 3>{
{{3, 0.0}, initial_velocity_temp, {3, 0.0}}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::move(initial_velocity_temp)

return std::make_unique<
IdentityForComposition<Frame::Distorted, Frame::Inertial>>(
IdentityMap{});
return std::make_unique<DistortedToInertialComposition>(translation_map_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you add the rigid translation (not the transition)

} else {
return std::make_unique<
IdentityForComposition<Frame::Grid, Frame::Inertial>>(IdentityMap{});
return std::make_unique<GridToInertialSimple>(translation_map_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take another bool like transition_translation_map to determine if this block should use the transition or the rigid translation.

@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from fff292d to f090181 Compare October 21, 2023 10:13
@guilara guilara changed the title Add translation to sphere domain time maps Enable time dependent translation with transition for Sphere domain Oct 21, 2023
@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from f090181 to 0f3c17f Compare October 21, 2023 12:10
@guilara guilara marked this pull request as ready for review October 21, 2023 12:57
@guilara
Copy link
Contributor Author

guilara commented Oct 21, 2023

@nilsvu I think addressed all the comments

@knelli2 knelli2 self-requested a review October 26, 2023 16:30
@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from c842318 to e008c93 Compare October 27, 2023 08:45
@guilara guilara mentioned this pull request Nov 1, 2023
3 tasks
Comment on lines 149 to 150
struct InitialVelocity {
static std::string name() { return "InitialVelocity"; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably also want to be able to specify the initial translation itself, not just the initial velocity, so we'll need an option for that. To keep things organized, make the translation options like the shape options. One struct that has

struct TranslationMapOptions {
  using type = TranslationMapOptions;
  static std::string name() { return "TranslationMap"; }

  struct InitialValues {
    using type = std::array<std::array<double, 3>, 2>;
    ...
  };

  ...

  using options = tmpl::list<InitialValues>;
  std::array<std::array<double, 3>, 2> initial_values{};
};

Comment on lines 236 to 237
TranslationMap rigid_translation_map_{};
TranslationMap translation_map_{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use linear_falloff_translation_map_ instead of translation_map_ so it's clear. Or just make it a std::pair of translation maps.

Comment on lines 271 to 274
// The translation map linear transition occurs only in the outer-most
// shell, such that the outer boundary is not translated. If there
// is no radial partition, a uniform translation is applied instead, as
// the transition requires spherical shape.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to allow only a single spherical shell while also having a translation. I don't think we have boundary conditions that can handle that. We should probably just error if that happens and require we have two spherical shells (one radial partition).

Comment on lines 280 to 283
radial_partitioning_.empty()
? std::nullopt
: std::optional<std::pair<double, double>>{
{radial_partitioning_.back(), outer_radius_}});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then these don't have to be optional, but can always be passed.

Comment on lines 141 to 142

if (translation_transition_radii.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then here you just always have a rigid translation map and a falloff translation map.

Comment on lines 537 to 584
"an outflow-type boundary condition, you must use that."));
using TDMO = domain::creators::sphere::TimeDependentMapOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sphere test failed for one of the builds still.

@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch 4 times, most recently from ff9f425 to 4c11784 Compare November 8, 2023 13:10
@guilara
Copy link
Contributor Author

guilara commented Nov 8, 2023

For some reason I am still getting the asserts (in the description) triggered with the Xcts Kerr input file. In particular for the inner shell. Maybe there is still a bug somewhere here or in Translation.

As for the rest, I implemented the changes requested @knelli2

Copy link
Contributor

@knelli2 knelli2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixups look good. You can squash the existing changes plus these new ones. As for the error in the translation map, if the values are really off by 1e-14 then we just need to account for roundoff. Basically do this in two places in the translation map

diff --git a/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp b/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
index de3f73ed2d..debb09ef7a 100644
--- a/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
+++ b/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
@@ -373,7 +373,8 @@ std::array<tt::remove_cvref_wrap_t<T>, Dim> Translation<Dim>::piecewise_helper(
         get_element(gsl::at(result, i), k) +=
             gsl::at(func_or_deriv_of_time, i) * radial_falloff_factor;
       }
-      ASSERT(max(magnitude(result)) <= outer_radius_.value(),
+      const double eps = std::numeric_limits<double>::epsilon() * 100.0;
+      ASSERT(max(magnitude(result)) - eps <= outer_radius_.value(),
              "Coordinates translated outside outer radius, This should not "
              "happen");
     }

If that doesn't work, then we'll need to investigate more. While you're at it, please also print the numbers in that ASSERT message so we can see how off they are.

Also, please fix all clang-tidy errors when squashing.

Comment on lines 394 to 395
const bool use_rigid_translation =
block_id + num_blocks_per_shell_ < num_blocks_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is incorrect if fill_interior_ is true since the central cube is append at the end of the block list

@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from 4c11784 to 046741a Compare November 13, 2023 10:41
@guilara
Copy link
Contributor Author

guilara commented Nov 13, 2023

The fixups look good. You can squash the existing changes plus these new ones. As for the error in the translation map, if the values are really off by 1e-14 then we just need to account for roundoff. Basically do this in two places in the translation map

diff --git a/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp b/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
index de3f73ed2d..debb09ef7a 100644
--- a/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
+++ b/src/Domain/CoordinateMaps/TimeDependent/Translation.cpp
@@ -373,7 +373,8 @@ std::array<tt::remove_cvref_wrap_t<T>, Dim> Translation<Dim>::piecewise_helper(
         get_element(gsl::at(result, i), k) +=
             gsl::at(func_or_deriv_of_time, i) * radial_falloff_factor;
       }
-      ASSERT(max(magnitude(result)) <= outer_radius_.value(),
+      const double eps = std::numeric_limits<double>::epsilon() * 100.0;
+      ASSERT(max(magnitude(result)) - eps <= outer_radius_.value(),
              "Coordinates translated outside outer radius, This should not "
              "happen");
     }

If that doesn't work, then we'll need to investigate more. While you're at it, please also print the numbers in that ASSERT message so we can see how off they are.

Also, please fix all clang-tidy errors when squashing.

Running the Xcts input file with one partition I get:

  1. For the assert checking blocks outside the inner radius I get:
    equal within roundoff (max(magnitude(result)), outer_radius_.value())) = 1 1.0e15*(outer_radius_.value() - max(magnitude(result)))/outer_radius_.value() = -0.177636
    or -0.177636e-15

whereas
2) for the assert checking blocks that have at least one point as falling within the inner radius I get
< inner_radius_value()... get_element(gsl::at(result, index), k) = -0.752477 , get_element(gsl::at(result, index), k) = -2.053507 , get_element(gsl::at(result, index), k) = 2.053507 , get_element(radius, k) = 3.000000 , equal within roundoff (max(magnitude(result)), outer_radius_.value())) = 1 , 1.0e15*(outer_radius_.value() - max(magnitude(result)))/outer_radius_.value() = -0.177636

which is actually the same number -0.177636e-15

@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from 046741a to 066f010 Compare November 13, 2023 15:19
Add options

Add rigid translation

Fix clang tidy

Fix tests

Rename translation map member

Reorganize translation map options

Add initial translation parameter

Fix tests

Forbid single shell with hard coded time dep maps

Fix

Fix

Allow for roundoff in translation asserts
@guilara guilara force-pushed the TimeDepMaps-Translation-Sphere branch from 066f010 to b781510 Compare November 13, 2023 17:41
@guilara
Copy link
Contributor Author

guilara commented Nov 13, 2023

@nilsvu Would it be ok if I set the spin to zero and remove the time dep maps in the Xcts KerrSchild test? In this PR I require at least two shells for hardcoded time dep maps and that test is timing out.

Or how much can I increase the timeout time?

@knelli2
Copy link
Contributor

knelli2 commented Dec 6, 2023

@nilsvu Can you take another look at this?

@nilsvu nilsvu self-requested a review December 9, 2023 01:10
@knelli2
Copy link
Contributor

knelli2 commented Mar 19, 2024

@guilara I believe we can close this because it is superseded by #5758?

@knelli2
Copy link
Contributor

knelli2 commented Jun 11, 2024

Closing because this feature has already been implemented in #5758.

@knelli2 knelli2 closed this Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants