-
Notifications
You must be signed in to change notification settings - Fork 37
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
Provide more flexible ways to add subset MeshBlockData objects to DataCollections #921
Conversation
@pdmullen @bprather @Yurlungur @lroberts36 @pgrete I think this one is ready to review. I'm going to leave Draft in place until I do a bit more testing downstream, but so far things look good so I suspect I'll be removing Draft very soon. |
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.
LGTM, comments aren't blocking.
Co-authored-by: Luke Roberts <lfroberts@lanl.gov>
Co-authored-by: Luke Roberts <lfroberts@lanl.gov>
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.
LGTM. This will be a nice improvement. Do you need changelog + formatting? Also remove the draft prefix?
// Constructor for getting sub-containers | ||
// the variables returned are all shallow copies of the src container. | ||
// Optionally extract only some of the sparse ids of src variable. | ||
template <typename T> | ||
MeshBlockData<T>::MeshBlockData(const MeshBlockData<T> &src, | ||
const std::vector<std::string> &names, | ||
const std::vector<int> &sparse_ids) { | ||
CopyFrom(src, true, names, {}, sparse_ids); | ||
} | ||
|
||
// TODO(JMM): Add constructor that takes unique IDs | ||
template <typename T> | ||
MeshBlockData<T>::MeshBlockData(const MeshBlockData<T> &src, | ||
const std::vector<MetadataFlag> &flags, | ||
const std::vector<int> &sparse_ids) { | ||
CopyFrom(src, true, {}, flags, sparse_ids); | ||
} | ||
|
||
// provides a container that has a single sparse slice | ||
template <typename T> | ||
std::shared_ptr<MeshBlockData<T>> | ||
MeshBlockData<T>::SparseSlice(const std::vector<int> &sparse_ids) const { | ||
auto c = std::make_shared<MeshBlockData<T>>(); | ||
c->CopyFrom(*this, true, {}, {}, sparse_ids); | ||
return c; | ||
} |
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.
No constructor overloads, always use copy now? That's cleaner from a self-describing interface point of view I think
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.
LGTM!
@pgrete I think this one is ready to go. Did you want to look through it first or should I just pull the trigger. I'm pretty sure this won't break anything for you downstream. |
After pulling and fiddling a bunch I like all this as is too. It's prompted me to dump some more of the other functionality I was duplicating in KHARMA into Parthenon too, I'll open a separate PR with the additions. |
@pgrete didn't give you much time to respond, but I'm going to pull the trigger. We have a least two separate codes that have confirmed backwards compatibility, so I'm pretty confident this won't break anything for you. Obviously, if you have comments on anything in this after it's merged, we can work on getting them addressed. |
PR Summary
There are lots of examples where it would be useful to have more flexibility in adding new
MeshBlockData
objects toDataCollection
s that are slices of otherMeshBlockData
objects (like "base"). We already sort of support this via the overload toDataCollection::Add
that includes a list of names of variables, but in its current form this is of limited use in practice. This PR attempts to make this much more flexible and useful.The main features included in this PR are:
MeshBlockData
orMeshData
objects toDataCollection
s. The preexisting versions that take (label, source) or (label, source, var_names) still exist and function as before. In addition, anAddShallow
function (with the same overloads) was added that yields a shallow copy, even for non-Metadata::OneCopy
fields.Add
directly to theMesh
-levelDataCollection
. WhenAdd
is called with aMeshData
source object, the newMeshBlockData
objects that get created get added to theMeshBlock
levelDataCollection
s. The implementation is a bit of a hack, but it works for now and makes things much cleaner downstream.StateDescriptor
now has an overloadedGetVariablesNames
member function that returns astd::vector<std::string>
of variable names given a list of names,Metadata::FlagCollectoin
, and/or a list of sparse ids. This is meant to produce the names that get passed into theDataCollection::Add*
calls, so provides the means of creating newMesh*Data
objects that are filtered on, for example,Metadata
and/or sparse ids.GetVariableNames
overloads were also added toMesh
, which just forwards the call on to theresolved_state
StateDescriptor
functions. This again is for convenience so that downstream codes don't have to pull out theresolved_state
when they just want a list of names from the simulation state as a whole.Metadata
flag with the same name as theStateDescriptor
the field is added to every field, sparse pool, and swarm.StateDescriptor
stashes the new flag in aParam
and provides a function to retrieve the flag for convenient access later.Metadata::FlagCollection
, and/or sparse ids, there are new functions that additionally take twoMeshBlockData
pointers or twoMeshData
pointers and return the unique ids of the variables that satisfy the filters and exist in both objects. This is required when trying to work withMesh*Data
objects that may have different fields present. With just the intersection of unique ids, you can write functions that can, for example, add values from oneMeshData
object into the corresponding fields in anotherMeshData
object quite straightforwardly.PackDescriptor
code that allows you to produce aSparsePack
given a list of unique ids.With all this stuff in place, you can do things like make registers for the RHSs of subsets of equations. We have integrated this branch into our downstream code and successfully make use of all these features.
PR Checklist