-
Notifications
You must be signed in to change notification settings - Fork 191
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
Make shape map exactly like the one in SpEC #5636
Conversation
* \link | ||
* domain::CoordinateMaps::ShapeMapTransitionFunctions::ShapeMapTransitionFunction::original_radius_over_radius | ||
* ShapeMapTransitionFunction::original_radius_over_radius \endlink. |
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.
Wasn't sure what to do about this. Even without the \link
it would be over 80 characters.
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.
This looks like a good case of a long line. There's a whitelist in tools/FileTestDefs.sh
you can add to. You can either add this file or whitelist \link
in general.
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.
Whitelisting \link
in general seems like the best approach and is helpful in the future as well.
* \link | ||
* domain::CoordinateMaps::ShapeMapTransitionFunctions::ShapeMapTransitionFunction::original_radius_over_radius | ||
* ShapeMapTransitionFunction::original_radius_over_radius \endlink. |
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.
This looks like a good case of a long line. There's a whitelist in tools/FileTestDefs.sh
you can add to. You can either add this file or whitelist \link
in general.
* Evaluate the transition function at the Cartesian coordinates divided by | ||
* the radius. All divisions over the radius which could potentially be zero | ||
* divisions are left to the transition function which uses its knowledge | ||
* of the domain to do this safely or throw an appropriate error. | ||
* the radius to a power. All divisions over the radius which could | ||
* potentially be zero divisions are left to the transition function which | ||
* uses its knowledge of the domain to do this safely or throw an appropriate | ||
* error. |
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.
The general feature isn't new, but it's being significantly expanded upon so I want to understand it.
What is this for? Looking at the math, the place a division-by-zero could potentially be analytically handled is in the shape map, not the transition function (and I don't think it actually gives a usable map even then). All the implementations are just dividing by r, without any of the checks mentioned here.
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.
Yes, there is one place in the shape map where dividing by r could be taken care of, but my best guess as to why the transition function is responsible for checking the 1/r
is because the transition function could be anything and so it may also need to account for a 1/r
somewhere itself. And, I think, because the only place that 1/r
shows up is with the transition function itself, it made sense to just have the transition function do all of the checks.
Both the Wedge
and Sphere
transition functions do check the magnitude of the point (in debug mode) before dividing by it. So these checks do exist.
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.
You're right that I missed the checks in the transition functions, but why not move them to the shape map itself to avoid duplication? The shape map isn't valid at r=0, so there can't be any issues with dividing by r.
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 yeah, I'm convinced this should be in the shape map now. If the transition function itself needs to divide by r it can just assume it's not zero since the shape map took care of it.
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.
If we want to consider using the map in the opposite sense, to remove distortion when going inwards, then you could get a valid map at the origin where I think you might want to remove cancellations in the transition function, but I still don't think you'd want to do it with varying powers in the fetch functions. You'd want the interface to only provide the valid quantities.
} else { | ||
return (outer_distance - radius) / | ||
((outer_distance - inner_surface_.distance(rotated_coords))) * | ||
integer_pow(1.0 / radius, power); |
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.
You're already doing a division. Put the new factors inside the denominator instead of doing another. (Particularly since I'm not sure whether integer_pow(1.0 / radius, 3)
does one division or three.)
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.
I changed this in the commit after, (no clue why) but I'll move it to the shape map edit commit
const auto transition_func_over_radius = | ||
transition_func_->map_over_radius(centered_coords); | ||
transition_func_over_square_radius = | ||
transition_func_->map_over_radius(centered_coords, 2); |
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.
This re-use is not an optimization. It doesn't avoid an allocation and may prevent some form of copy elision.
auto& transition_func_over_cube_radius = get<1>(theta_phis); | ||
|
||
transition_func_over_cube_radius = | ||
transition_func_->map_over_radius(centered_coords, 3); |
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.
Again, not an optimization.
// re-use allocation | ||
auto& transition_func_over_radius = get<1>(theta_phis); | ||
transition_func_over_radius = | ||
transition_func_->map_over_radius(centered_coords); |
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.
Again, not an optimization.
"The Wedge transition map was called with coordinates outside of " | ||
"its wedge. The " | ||
<< (axis.value() == 0_st ? "x" : (axis.value() == 1_st ? "y" : "z")) | ||
<< "-coordinate shouldn't be 0 but it is."); |
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.
Print the coordinate or the index or something.
@wthrowe Pushed some fixups. I'll make the whitelist commit the first commit when I squash. I'll also squash the new changes into the appropriate commits as well since I edited the Wedge transition in both original commits. |
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.
Looks good. Squash (and fix clang-tidy).
T Shape::check_and_compute_one_over_radius( | ||
const std::array<T, 3>& centered_coords) const { | ||
#ifdef SPECTRE_DEBUG | ||
const T radius = magnitude(centered_coords); |
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.
[optional] Move up one line and return 1.0 / radius
.
49387dc
to
b568435
Compare
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.
Looks good. GitHub Actions is having problems (in general, not just for us) at the moment, but they usually resolve that sort of thing quickly.
b568435
to
4f801a5
Compare
Proposed changes
This is a follow up to #5627.
In SpEC, the shape map is (for centered coordinates)
However, in SpECTRE, the shape map currently is
In SpEC, we have that$0 \leq f(r, \theta, \phi) \leq 1$ , while in SpECTRE we have $0 \leq h(r, \theta, \phi) \leq 1$ . This slight difference of a factor of $r$ is a fundamentally different coordinate mapping.
This PR edits the shape map to be identical to the one in SpEC and consequently edits both of the transition functions to be from 1 to 0.
The wedge transition map also has additional edits that fixes some issues it had before.
This PR also fixes #5635.
Upgrade instructions
Code review checklist
make doc
to generate the documentation locally intoBUILD_DIR/docs/html
.Then open
index.html
.code review guide.
bugfix
ornew feature
if appropriate.Further comments