Go to the documentation of this file.
20 #ifndef THUNDEREGG_PATCHINFO_H
21 #define THUNDEREGG_PATCHINFO_H
93 std::array<int, Orthant<D>::num_orthants>
child_ids;
117 std::array<int, D>
ns;
161 for (
size_t i = 0; i < other_pinfo.nbr_infos.size(); i++) {
162 if (other_pinfo.nbr_infos[i] !=
nullptr) {
163 nbr_infos[i] = other_pinfo.nbr_infos[i]->clone();
190 for (
size_t i = 0; i < other_pinfo.nbr_infos.size(); i++) {
191 if (other_pinfo.nbr_infos[i] !=
nullptr) {
192 nbr_infos[i] = other_pinfo.nbr_infos[i]->clone();
194 nbr_infos[i] =
nullptr;
294 nbr_infos.begin(), nbr_infos.end(), [](
const std::unique_ptr<NbrInfoBase>& nbr_info) {
295 return nbr_info != nullptr;
311 for (
size_t i = 0; i < nbr_infos.size(); i++) {
312 if (nbr_infos[i] !=
nullptr) {
313 nbr_infos[i]->setLocalIndexes(id_to_local_index_map);
324 for (
size_t i = 0; i < nbr_infos.size(); i++) {
325 if (nbr_infos[i] !=
nullptr) {
326 nbr_infos[i]->setGlobalIndexes(id_to_global_index_map);
335 std::deque<int> retval;
336 for (
size_t i = 0; i < nbr_infos.size(); i++) {
337 if (nbr_infos[i] !=
nullptr) {
338 nbr_infos[i]->getNbrIds(retval);
348 std::deque<int> retval;
349 for (
size_t i = 0; i < nbr_infos.size(); i++) {
350 if (nbr_infos[i] !=
nullptr) {
351 nbr_infos[i]->getNbrRanks(retval);
359 std::bitset<Face<D, M>::number_of> has_nbr;
382 throw RuntimeError(
"Unsupported NbrType");
386 if constexpr (M > 0) {
387 serializeNeighbors<M - 1>(writer);
391 void deserializeNeighbors(BufferReader& reader)
393 std::bitset<Face<D, M>::number_of> has_nbr;
402 info =
new NormalNbrInfo<M>();
403 reader >> *
static_cast<NormalNbrInfo<M>*
>(info);
406 info =
new FineNbrInfo<M>();
407 reader >> *
static_cast<FineNbrInfo<M>*
>(info);
410 info =
new CoarseNbrInfo<M>();
411 reader >> *
static_cast<CoarseNbrInfo<M>*
>(info);
414 throw RuntimeError(
"Unsupported NbrType");
420 if constexpr (M > 0) {
421 deserializeNeighbors<M - 1>(reader);
439 serializeNeighbors<D - 1>(writer);
458 deserializeNeighbors<D - 1>(reader);
465 to_json(tpl::nlohmann::json& j,
const PatchInfo<D>& pinfo)
468 j[
"parent_id"] = pinfo.parent_id;
469 j[
"parent_rank"] = pinfo.parent_rank;
470 j[
"orth_on_parent"] = pinfo.orth_on_parent;
471 j[
"rank"] = pinfo.rank;
472 j[
"starts"] = pinfo.starts;
473 j[
"lengths"] = pinfo.spacings;
474 j[
"refine_level"] = pinfo.refine_level;
475 for (
int i = 0; i < D; i++) {
476 j[
"lengths"][i] = pinfo.spacings[i] * pinfo.ns[i];
478 j[
"nbrs"] = tpl::nlohmann::json::array();
480 if (pinfo.hasNbr(s)) {
481 switch (pinfo.getNbrType(s)) {
483 j[
"nbrs"].push_back(pinfo.getNormalNbrInfo(s));
486 j[
"nbrs"].push_back(pinfo.getCoarseNbrInfo(s));
489 j[
"nbrs"].push_back(pinfo.getFineNbrInfo(s));
492 throw RuntimeError(
"Unsupported NbrType");
494 j[
"nbrs"].back()[
"type"] = pinfo.getNbrType(s);
495 j[
"nbrs"].back()[
"side"] = s;
498 if constexpr (D == 3) {
499 j[
"edge_nbrs"] = tpl::nlohmann::json::array();
501 if (pinfo.hasNbr(e)) {
502 switch (pinfo.getNbrType(e)) {
504 j[
"edge_nbrs"].push_back(pinfo.getNormalNbrInfo(e));
507 j[
"edge_nbrs"].push_back(pinfo.getCoarseNbrInfo(e));
510 j[
"edge_nbrs"].push_back(pinfo.getFineNbrInfo(e));
513 throw RuntimeError(
"Unsupported NbrType");
515 j[
"edge_nbrs"].back()[
"type"] = pinfo.getNbrType(e);
516 j[
"edge_nbrs"].back()[
"edge"] = e;
520 if constexpr (D >= 2) {
521 j[
"corner_nbrs"] = tpl::nlohmann::json::array();
523 if (pinfo.hasNbr(c)) {
524 switch (pinfo.getNbrType(c)) {
526 j[
"corner_nbrs"].push_back(pinfo.getNormalNbrInfo(c));
529 j[
"corner_nbrs"].push_back(pinfo.getCoarseNbrInfo(c));
532 j[
"corner_nbrs"].push_back(pinfo.getFineNbrInfo(c));
535 throw RuntimeError(
"Unsupported NbrType");
537 j[
"corner_nbrs"].back()[
"type"] = pinfo.getNbrType(c);
538 j[
"corner_nbrs"].back()[
"corner"] = c;
542 if (pinfo.child_ids[0] != -1) {
543 j[
"child_ids"] = pinfo.child_ids;
544 j[
"child_ranks"] = pinfo.child_ranks;
549 from_json(
const tpl::nlohmann::json& j, PatchInfo<D>& pinfo)
552 pinfo.parent_id = j[
"parent_id"];
553 pinfo.parent_rank = j[
"parent_rank"];
554 if (j.contains(
"orth_on_parent")) {
555 j[
"orth_on_parent"].get_to(pinfo.orth_on_parent);
557 if (j.contains(
"refine_level")) {
558 pinfo.refine_level = j[
"refine_level"];
560 pinfo.rank = j[
"rank"];
561 pinfo.starts = j[
"starts"].get<std::array<double, D>>();
562 pinfo.spacings = j[
"lengths"].get<std::array<double, D>>();
564 for (
const auto& nbr_j : j[
"nbrs"]) {
565 Side<D> s = nbr_j[
"side"].get<Side<D>>();
566 switch (nbr_j[
"type"].get<NbrType>()) {
568 pinfo.setNbrInfo(s,
new NormalNbrInfo<D - 1>());
569 pinfo.getNormalNbrInfo(s) = nbr_j.get<NormalNbrInfo<D - 1>>();
572 pinfo.setNbrInfo(s,
new CoarseNbrInfo<D - 1>());
573 pinfo.getCoarseNbrInfo(s) = nbr_j.get<CoarseNbrInfo<D - 1>>();
576 pinfo.setNbrInfo(s,
new FineNbrInfo<D - 1>());
577 pinfo.getFineNbrInfo(s) = nbr_j.get<FineNbrInfo<D - 1>>();
580 throw RuntimeError(
"Unsupported NbrType");
583 if constexpr (D == 3) {
584 if (j.contains(
"edge_nbrs")) {
585 for (
const auto& nbr_j : j[
"edge_nbrs"]) {
587 switch (nbr_j[
"type"].get<NbrType>()) {
589 pinfo.setNbrInfo(e,
new NormalNbrInfo<1>());
590 pinfo.getNormalNbrInfo(e) = nbr_j.get<NormalNbrInfo<1>>();
593 pinfo.setNbrInfo(e,
new CoarseNbrInfo<1>());
594 pinfo.getCoarseNbrInfo(e) = nbr_j.get<CoarseNbrInfo<1>>();
597 pinfo.setNbrInfo(e,
new FineNbrInfo<1>());
598 pinfo.getFineNbrInfo(e) = nbr_j.get<FineNbrInfo<1>>();
601 throw RuntimeError(
"Unsupported NbrType");
606 if constexpr (D >= 2) {
607 if (j.contains(
"corner_nbrs")) {
608 for (
const auto& nbr_j : j[
"corner_nbrs"]) {
609 Corner<D> c = nbr_j[
"corner"].get<Corner<D>>();
610 switch (nbr_j[
"type"].get<NbrType>()) {
612 pinfo.setNbrInfo(c,
new NormalNbrInfo<0>());
613 pinfo.getNormalNbrInfo(c) = nbr_j.get<NormalNbrInfo<0>>();
616 pinfo.setNbrInfo(c,
new CoarseNbrInfo<0>());
617 pinfo.getCoarseNbrInfo(c) = nbr_j.get<CoarseNbrInfo<0>>();
620 pinfo.setNbrInfo(c,
new FineNbrInfo<0>());
621 pinfo.getFineNbrInfo(c) = nbr_j.get<FineNbrInfo<0>>();
624 throw RuntimeError(
"Unsupported NbrType");
629 if (j.contains(
"child_ids")) {
630 pinfo.child_ids = j[
"child_ids"].get<std::array<int, Orthant<D>::num_orthants>>();
631 pinfo.child_ranks = j[
"child_ranks"].get<std::array<int, Orthant<D>::num_orthants>>();
634 extern template class PatchInfo<2>;
635 extern template class PatchInfo<3>;
int serialize(char *buffer) const
Serialize object into buffer.
Definition: PatchInfo.h:424
PatchInfo()
Construct a new Patch Info object starts, ns, and spacings are all set to 0.
Definition: PatchInfo.h:131
FineNbrInfo< M > & getFineNbrInfo(Face< D, M > s) const
Get the FineNbrInfo object.
Definition: PatchInfo.h:272
static Orthant< D > null()
null value
Definition: Orthant.h:68
An enum-style class that represents the octants of a cube.
Definition: Orthant.h:43
Orthant< D > orth_on_parent
The orthant of the parent that this parent resides on.
Definition: PatchInfo.h:113
Class that is used to help serialize objects into a buffer.
Definition: BufferWriter.h:38
std::deque< int > getNbrRanks() const
return a vector of neighbor ranks
Definition: PatchInfo.h:346
bool hasNbr(Face< D, M > s) const
Return whether the patch has a neighbor.
Definition: PatchInfo.h:284
@ Coarse
The neighbor is at a coarser refinement level.
Interface for serializing objects.
Definition: Serializable.h:34
NormalNbrInfo< M > & getNormalNbrInfo(Face< D, M > s) const
Get the NormalNbrInfo object for a side.
Definition: PatchInfo.h:245
std::array< int, D > ns
The number of cells in each direction.
Definition: PatchInfo.h:117
int parent_id
The id of the parent patch.
Definition: PatchInfo.h:83
friend bool operator<(const PatchInfo &l, const PatchInfo &r)
Compare the ids of the patches.
Definition: PatchInfo.h:207
void setNeighborLocalIndexes(const std::map< int, int > &id_to_local_index_map)
Set the local indexes in the NbrInfo objects.
Definition: PatchInfo.h:309
int local_index
The local index of the patch in the Domain.
Definition: PatchInfo.h:69
PatchInfo< D > & operator=(const PatchInfo< D > &other_pinfo)
Copy asisgnment.
Definition: PatchInfo.h:173
NbrType getNbrType(Face< D, M > s) const
Get the NbrType for a side.
Definition: PatchInfo.h:232
Face< 3, 1 > Edge
Edge class.
Definition: Face.h:636
NbrType
The type of neighbor.
Definition: NbrType.h:34
PatchInfo(const PatchInfo< D > &other_pinfo)
Copy constructor.
Definition: PatchInfo.h:145
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
int id
The globally unique ID of the patch This ID only needs to be unique within a Domain.
Definition: PatchInfo.h:65
Represents information about a patch's neighbor.
Definition: NbrInfo.h:36
size_t getIndex() const
Get the index for this Face.
Definition: Face.h:452
Represents a neighbor that is at a coarser refinement level.
Definition: CoarseNbrInfo.h:39
void setNeighborGlobalIndexes(const std::map< int, int > &id_to_global_index_map)
Set the global indexes in the NbrInfo objects.
Definition: PatchInfo.h:322
Contains metadata for a patch.
Definition: PatchInfo.h:51
bool hasNbr() const
Return if this patch has a neighbor.
Definition: PatchInfo.h:291
int deserialize(char *buffer)
Deserialize an object.
Definition: PatchInfo.h:443
std::deque< int > getNbrIds() const
return a vector of neighbor ids
Definition: PatchInfo.h:333
int rank
MPI rank of this patch.
Definition: PatchInfo.h:107
void setNbrInfo(Face< D, M > f, NbrInfo< M > *nbr_info)
Set the Nbr Info object on a given face.
Definition: PatchInfo.h:221
int getPos()
get the current position in the buffer
Definition: BufferReader.h:74
@ Fine
The nighbor is at a finer refinement level.
@ Normal
The neighbor is at the same refinement level.
std::array< double, D > spacings
The cell spacings in each direction.
Definition: PatchInfo.h:125
std::array< int, Orthant< D >::num_orthants > child_ids
The id's of the children.
Definition: PatchInfo.h:93
std::array< double, D > starts
The lower-left-bottom index of the patch.
Definition: PatchInfo.h:121
int refine_level
The refinement level.
Definition: PatchInfo.h:77
int num_ghost_cells
Number of ghost cells on each side of the patch.
Definition: PatchInfo.h:103
int global_index
The global index of the patch in the Domain.
Definition: PatchInfo.h:73
int getPos()
get the current position in the buffer
Definition: BufferWriter.h:80
Class that is used to help read serialized objects from a buffer.
Definition: BufferReader.h:38
Enum-style class for the faces of an n-dimensional cube.
Definition: Face.h:41
std::array< int, Orthant< D >::num_orthants > child_ranks
The ranks of the children.
Definition: PatchInfo.h:99
Represents neighbors that are at a finer refinement level.
Definition: FineNbrInfo.h:39
Represents a neighbor that is at the same refinement level.
Definition: NormalNbrInfo.h:38
int parent_rank
the rank that the parent patch resides on
Definition: PatchInfo.h:87
CoarseNbrInfo< M > & getCoarseNbrInfo(Face< D, M > s) const
Get the CoarseNbrInfo object.
Definition: PatchInfo.h:258
bool hasCoarseParent() const
Return whether the patch has a coarser parent.
Definition: PatchInfo.h:303
static Range getValues()
Get a range of values that can be iterated over.
Definition: Face.h:445