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

Properly extend shape map into interior region #6477

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

knelli2
Copy link
Contributor

@knelli2 knelli2 commented Feb 7, 2025

This is only allowed when the inner surface is spherical and when we are using the "regular" transition (i.e. not reversed).

Proposed changes

Fixes #6451.

A previous PR (#6359) attempted to extend the shape map into the excision, but did so incorrectly. This PR implements this correctly. In order to do this, the meaning of the transition function had to be changed slightly. Previously, the shape map was

$$ \tilde{r} = r \left(1 - \frac{f(r, \theta, \phi)}{r} \sum_{\ell,m} \lambda_{\ell m}Y_{\ell m}(\theta, \phi)\right) $$

and the transition function was $f(r, \theta, \phi)$. The functional form of the shape map hasn't changed, but now it reads

$$ \tilde{r} = r \left(1 - G(r, \theta, \phi) \sum_{\ell,m} \lambda_{\ell m}Y_{\ell m}(\theta, \phi)\right) $$ $$ G(r, \theta, \phi) = \frac{f(r, \theta, \phi)}{r} $$

where $G(r, \theta, \phi)$ is the transition. The $1/r$ factor was just absorbed into the transition function because the full $G$ is different inside the excision, not just $f$.

Also, the transition function inside the excisions is

$$ G(r, \theta, \phi) = \frac{r^2}{r_{\text{min}}^3} $$

which is different than it is in SpEC. The transition defined in SpEC causes the jacobian to be undefined at the center of the shape map, which means the full frame velocity of all the maps can't be computed at the center of the shape map. This new transition inside the excision allows for this and has the correct behavior.

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

@knelli2 knelli2 added this to the BBH larger q & higher spins milestone Feb 7, 2025
@knelli2 knelli2 added the in progress Don't review, used for sharing code and getting feedback label Feb 9, 2025
@knelli2 knelli2 removed the in progress Don't review, used for sharing code and getting feedback label Feb 11, 2025
@knelli2
Copy link
Contributor Author

knelli2 commented Feb 11, 2025

Ok this is ready for review (maybe @nilsvu ?). Just an FYI for @nikwit that this adds the shape map to the ExcisionSpheres, but if you're only evaluating it at the center of the excision, then this shouldn't behave any differently than before when the shape map wasn't included.

interpolation_info);
}

auto transition_func_over_radius =
Copy link
Member

Choose a reason for hiding this comment

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

So this is G or G/r? Because my understanding from the dox change is this is G/r

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, this is G/r. I'll add a small comment here to clarify

@@ -243,26 +276,21 @@ namespace domain::CoordinateMaps::ShapeMapTransitionFunctions {
* \parblock
*
* \note If \p reverse is true, then the value multiplying $\Sigma$ in the
* numerator is now $-|\vec x_0 - \vec P|$ and in the denomintor $\Sigma$ picks
* numerator is now $-|\vec x_0 - \vec P|$ and in the denominator $\Sigma$ picks
Copy link
Member

Choose a reason for hiding this comment

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

demonator? 😅 (JK I'm just teasing!)

if (multiple_real_roots) {
// Numerical Recipes (3rd edition) pg 228, eqs 5.6.11 - 5.6.12
const double theta = acos(R / sqrt(cube(Q)));
std::vector<double> roots{
Copy link
Member

Choose a reason for hiding this comment

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

why not use an array? or a static vector? remove_if returns an iterator to the end, so you can use it on an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had assumed remove_if would resize the container, but I see I was incorrect. I think what I actually want is to use std::erase_if so the vector actually contains the positive roots.

if (multiple_real_roots) {
// Numerical Recipes (3rd edition) pg 228, eqs 5.6.11 - 5.6.12
const double theta = acos(R / sqrt(cube(Q)));
std::vector<double> roots{
Copy link
Member

Choose a reason for hiding this comment

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

same question about array

This is only allowed when the inner surface is spherical and when
we are using the "regular" transition (i.e. not reversed).

// G / r
auto transition_func_over_radius =
transition_func_->operator()(centered_coords, {1});
Copy link
Member

Choose a reason for hiding this comment

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

(optional) don't need the curly braces I think

*/
virtual double operator()(
const std::array<double, 3>& source_coords) const = 0;
const std::array<double, 3>& source_coords,
const std::optional<size_t>& one_over_radius_power) const = 0;
Copy link
Member

Choose a reason for hiding this comment

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

(optional) default to std::nullopt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick google search says having default parameters in pure virtual functions is not recommended so I'll leave it as is.

Copy link
Member

Choose a reason for hiding this comment

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

ok

const std::optional<size_t>& one_over_radius_power) const {
DataVector result = source_coords[0];
// Go point by point
for (size_t i = 0; i < source_coords[0].size(); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

The performance of this might actually be relevant, so if it's easy enough I'd stick with Blaze for this computation instead of doing the loop yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well for each point, I'd still need to do the checks I do in the double implementation since this can be called with any set of points and to ensure everything is consistent which would require this to still be a loop.

Copy link
Member

Choose a reason for hiding this comment

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

Oh hide the checks behind #ifdef SPECTRE_DEBUG then their performance doesn't matter and you can do loops in them

Copy link
Member

@nilsvu nilsvu Mar 7, 2025

Choose a reason for hiding this comment

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

Please do these like the gradient_impl function you did below, that's also how these functions were implemented before you split them into separate double and DataVector overloads in this PR. Otherwise the code can do something different in debug vs release, which seems very hard to debug 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok done

// a_ being positive is a sentinel for reversed.
// If we aren't reversed, check near or within r_min_.
if (a_ < 0.0) {
if (mag + radial_distortion < (1.0 - eps_) * r_min_) {
Copy link
Member

Choose a reason for hiding this comment

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

Why the + radial_distortion here?

I think you have to be careful that you compare r_min and r_max only to the original radius, not the target radius. E.g. in line 157 there's a comparison to the target radius, which I think could be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's undoing the distortion assuming we are at the f=1 surface. Therefore if this condition is true, we are guaranteed to be within the excision and if not, we're outside of it. I ported this check over from SpEC.

Below on 157 should still be the target radius, but I forgot to add the radial distortion since I'm trying to see if we are exactly at the excision (because then the formula is simpler). In the Wedge it is correct

@knelli2
Copy link
Contributor Author

knelli2 commented Mar 6, 2025

@nilsvu Pushed fixups

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.

Shape map incorrect inside excision
3 participants