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

Add wedge transition for shape map #5616

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

knelli2
Copy link
Contributor

@knelli2 knelli2 commented Nov 7, 2023

Proposed changes

A new transition function for the shape map that is to be used in concentric wedge blocks. The inner and outer boundaries of these wedges can be spherical, flat, or in-between just like the Wedge coordinate map. This transition will mostly be used for the rectangular BinaryCompactObject domain for the shells and cubes around each object (PR to come for that).

Needed for #5600.

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

Comment on lines 84 to 85
// class is not to be used otherwise.
class SphereTransition : public Sphere {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not super happy about this, but I would like to rename the class because the original name is redundant. If reviewers are strongly against this, I can forgo the name change

Copy link
Member

Choose a reason for hiding this comment

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

Renaming seems fine. We could add a way to override the name used for the charm registration if we hit this often.

That said, are you sure this doesn't need its own my_PUP_ID and similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I added this was because of the versioning test in Test_Domain where we deserialize a BCO domain from H5 that was serialized with the old transition function name. Not sure if there's a good way to override charm registration name when reading something in that was already written. Open to suggestions

Copy link
Member

Choose a reason for hiding this comment

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

I meant we could provide a way to override the second argument in

    PUPable_reg2(class_to_register,
                 registration_name<class_to_register>().c_str());

but if it's only for one thing probably not worth it.

Ping on the question about my_PUP_ID.

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 tried compiling with

class SphereTransition : public Sphere {};
PUP::able::PUP_ID SphereTransition::my_PUP_ID = 0;

and got an error about no member named 'my_PUP_ID'. The goal is to have the SphereTransition class be identical to the Sphere class in every way except name, so I think it makes sense to not give it its own PUP_ID.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you'd need to add the stuff in the class body as well.

I think it makes sense to not give it its own PUP_ID.

But you are assigning two PUP_IDs, since you register twice, just one is overwriting the other. Looking through the charm code I think this has the effect that you cannot serialize the first one registered through a base class pointer. Or maybe you can but it is recorded as being the other type, not sure. If you want to do this you definitely need tests that the serialization works the way you expect it to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm ok. This is getting too complicated and I'd rather not run the risk of breaking serialization things like this, so I'll just forgo the name change. It's not a huge deal, I'll just name future transition functions properly. If there ever comes a time where we drop support for certain versions of maps, then we can revisit this.

@@ -95,6 +95,11 @@ class OrientationMap {
/// The corresponding Orientation of the host in the frame of the neighbor.
OrientationMap<VolumeDim> inverse_map() const;

/// The stored map directions
const std::array<Direction<VolumeDim>, VolumeDim>& mapped_directions() const {
Copy link
Member

Choose a reason for hiding this comment

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

If you're exposing this, document what it means. I think dropping this commit and using operator() is clearer, though.

Comment on lines 84 to 85
// class is not to be used otherwise.
class SphereTransition : public Sphere {};
Copy link
Member

Choose a reason for hiding this comment

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

Renaming seems fine. We could add a way to override the name used for the charm registration if we hit this often.

That said, are you sure this doesn't need its own my_PUP_ID and similar?

@@ -0,0 +1,7 @@
# Distributed under the MIT License.
Copy link
Member

Choose a reason for hiding this comment

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

Add directory to parent CMakeLists.txt. Looks like done in wrong commit.

Surface this_wedge_outer_surface_{};
OrientationMap<3> orientation_map_{};
Direction<3> direction_{};
static constexpr double eps_ = std::numeric_limits<double>::epsilon() * 100;
Copy link
Member

Choose a reason for hiding this comment

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

Include <limits>.

double radius{};
double sphericity{};
template <typename T>
T distance(const std::array<T, 3>& coords) const;
Copy link
Member

Choose a reason for hiding this comment

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

Distance to what?

// can be rotated from their original orientation to now "aligned" with +z.
// Therefore we can continue with computing the original radius.
const std::array<double, 3> rotated_coords =
discrete_rotation(orientation_map_.inverse_map(), target_coords);
Copy link
Member

Choose a reason for hiding this comment

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

You could rotate first, and then you only have to check if you're in the +z wedge.

CAPTURE_FOR_ERROR(rotated_coords);

// If distorted radius is 0, this means the map is the identity so the radius
// and the original radius are equal. Also we don't want to divide by 0 below
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused about how the radius can be 0 inside a wedge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this is a poor name for the variable then. The "distorted radius" is $\sum_{lm} \lambda_{lm}(t)Y_{lm}$. It's documented in the base class. So if this quantity is 0, then there is no distortion.

// because of the above check.
if (overall_outer_surface_.sphericity == 1.0) {
const T total_factor = one_over_denom * outer_distance_minus_radius *
make_factor(overall_inner_surface_);
Copy link
Member

Choose a reason for hiding this comment

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

Since you seem concerned with such things in this function, pretty sure T total_factor = make_factor(...); total_factor *= ...; saves you an allocation.

result[2] += total_factor * (square(radius) - square(rotated_coords[2]));
} else if (overall_inner_surface_.sphericity == 1.0) {
std::array<T, 3> outer_deriv_distance =
make_array<3>(make_factor(overall_outer_surface_));
Copy link
Member

Choose a reason for hiding this comment

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

Rewriting this like the previous case where you compute an overall factor instead of an array will save allocations and FLOPs.

Probably also for the case below, but I haven't worked that one out in enough detail to be sure.

// checks that the magnitudes are all between `r_min_` and `r_max_`
template <typename T>
void Wedge::check_distances([
[maybe_unused]] const std::array<T, 3>& coords) const {
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually what clang-format wants? Yuck.

@knelli2
Copy link
Contributor Author

knelli2 commented Nov 8, 2023

@wthrowe Pushed a fixup. I'll remove that one commit and fix the wrong commit CMakeLists.txt thing when I squash

Copy link
Member

@wthrowe wthrowe left a comment

Choose a reason for hiding this comment

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

Pinged on one thing. You can squash the current fixup.

Comment on lines 84 to 85
// class is not to be used otherwise.
class SphereTransition : public Sphere {};
Copy link
Member

Choose a reason for hiding this comment

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

I meant we could provide a way to override the second argument in

    PUPable_reg2(class_to_register,
                 registration_name<class_to_register>().c_str());

but if it's only for one thing probably not worth it.

Ping on the question about my_PUP_ID.

wthrowe
wthrowe previously approved these changes Nov 8, 2023
@wthrowe
Copy link
Member

wthrowe commented Nov 9, 2023

Please don't squash fixups before I have a chance to look at them.

@knelli2
Copy link
Contributor Author

knelli2 commented Nov 10, 2023

Oh sorry @wthrowe that's totally my bad. I can git reflog and re-push the fixup if that'd be easier for you?

@wthrowe wthrowe merged commit d96f219 into sxs-collaboration:develop Nov 10, 2023
19 of 22 checks passed
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