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 function to copy mutable creation items from DataBox into a TaggedTuple #4678

Merged
merged 2 commits into from
Feb 2, 2023

Conversation

kidder
Copy link
Member

@kidder kidder commented Feb 1, 2023

Proposed changes

This allows data to be sent to newly created Elements from their parent or children during AMR

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

Copy link
Member

@nilsvu nilsvu left a comment

Choose a reason for hiding this comment

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

This technically adds a cyclic dependency between Parallel and DataStructures. Should probably be resolved by moving PUP things out of Parallel. But I have another suggestion: I have needed a get_items function in some places in the elliptic code (search for "get_items", implemented as a lambda in some places). It gets multiple items from the DataBox and returns a tuple that can be assigned to structured bindings. How about we make that a DataBox function. Then I think you can build the TaggedTuple using get_items and serialize/deserialize where you need it.

@@ -203,6 +204,12 @@ class DataBox<tmpl::list<Tags...>> : private detail::Item<Tags>... {
using mutable_subitem_tags = tmpl::flatten<
tmpl::transform<mutable_item_tags, db::Subitems<tmpl::_1>>>;

/// A list of all the immutable item tags used to create the DataBox
Copy link
Member

Choose a reason for hiding this comment

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

"mutable"?

Copy link
Member Author

Choose a reason for hiding this comment

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

duh 👍

@@ -244,26 +251,28 @@ class DataBox<tmpl::list<Tags...>> : private detail::Item<Tags>... {
std::string print_types() const;

/// Print the items

Copy link
Member

Choose a reason for hiding this comment

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

drop

@kidder
Copy link
Member Author

kidder commented Feb 1, 2023

Yes, I agree we should probably make a Serialization library somewhere and put various things in it to break the dependency.
I don't think it matters whether copy_items returns a tuple or TaggedTuple, it will still need to call deserialize(serialize(item)) in order to obtain a copy of a non-copyable type.

@nilsvu
Copy link
Member

nilsvu commented Feb 1, 2023

Yes to the Serialization lib. We can place it in Utilities/Serialization/, as its own lib (because it's sort of an extension of Charm and has to live at the same low level as Utilities, below DataStructures).

I didn't suggest to switch TaggedTuple -> tuple. My suggestion is to make a get_items function with the same reference semantics as get. I think that would be very useful for things like this:

const auto& [x, y] = db::get_items<Tags::X, Tags::Y>(box);

It replaces long lists of db::get. I thought it could also be useful for copying items, but maybe it's not enough (getting item types for deserialize can be annoying).

@kidder
Copy link
Member Author

kidder commented Feb 1, 2023

Okay, so I'd prefer to refactor in a separate PR. And yes, I see the usefulness of get_items, but I need to know the storage types in order to copy the items, so again, I'd prefer adding that in a future PR.

nilsvu
nilsvu previously approved these changes Feb 1, 2023
Copy link
Member

@nilsvu nilsvu left a comment

Choose a reason for hiding this comment

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

sounds good. please squash the changes above directly.

Also rename some template parameters to match names of type aliases.
This will be used to send data needed to initialize new elements from
their parent or children.
Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

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

LGTM, one question

* the mutable_item_creation_tags of the DataBox
*/
template <typename CopiedItemsTagList, typename DbTagList>
SPECTRE_ALWAYS_INLINE auto copy_items(const DataBox<DbTagList>& box) {
Copy link
Member

Choose a reason for hiding this comment

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

do you only want a copy, or would a move one be useful too? If it's always a copy, that's fine, just asking :)

Copy link
Member Author

Choose a reason for hiding this comment

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

A move could also be useful and might be the right choice; I'll do that in a separate PR as moving an item will need to reset subitems and compute items that depend on the moved item...

@kidder kidder merged commit 5a0dcb6 into sxs-collaboration:develop Feb 2, 2023
@kidder kidder deleted the copy_items_from_box branch February 2, 2023 22:33
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