ThunderEgg  1.0.0
FineNbrInfo.h
Go to the documentation of this file.
1 /***************************************************************************
2  * ThunderEgg, a library for solvers on adaptively refined block-structured
3  * Cartesian grids.
4  *
5  * Copyright (c) 2020-2021 Scott Aiton
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  ***************************************************************************/
20 #ifndef THUNDEREGG_FINENBRINFO_H
21 #define THUNDEREGG_FINENBRINFO_H
22 
29 #include <ThunderEgg/NbrInfo.h>
30 #include <ThunderEgg/Orthant.h>
31 
32 namespace ThunderEgg {
38 template<int D>
39 class FineNbrInfo : public NbrInfo<D>
40 {
41 public:
45  std::array<int, Orthant<D>::num_orthants> ranks;
49  std::array<int, Orthant<D>::num_orthants> ids;
53  std::array<int, Orthant<D>::num_orthants> global_indexes;
57  std::array<int, Orthant<D>::num_orthants> local_indexes;
62  {
63  ranks.fill(0);
64  ids.fill(0);
65  local_indexes.fill(-1);
66  global_indexes.fill(-1);
67  }
68  ~FineNbrInfo() = default;
75  : ids(ids)
76  {
77  ranks.fill(0);
78  local_indexes.fill(-1);
79  global_indexes.fill(-1);
80  }
81  NbrType getNbrType() const override { return NbrType::Fine; }
82  void getNbrIds(std::deque<int>& nbr_ids) const override
83  {
84  for (size_t i = 0; i < ids.size(); i++) {
85  nbr_ids.push_back(ids[i]);
86  }
87  };
88  void getNbrRanks(std::deque<int>& nbr_ranks) const override
89  {
90  for (size_t i = 0; i < ranks.size(); i++) {
91  nbr_ranks.push_back(ranks[i]);
92  }
93  }
94  void setGlobalIndexes(const std::map<int, int>& id_to_global_index_map) override
95  {
96  for (size_t i = 0; i < global_indexes.size(); i++) {
97  global_indexes[i] = id_to_global_index_map.at(ids[i]);
98  }
99  }
100  void setLocalIndexes(const std::map<int, int>& id_to_local_index_map) override
101  {
102  for (size_t i = 0; i < local_indexes.size(); i++) {
103  auto iter = id_to_local_index_map.find(ids[i]);
104  if (iter != id_to_local_index_map.end()) {
105  local_indexes[i] = iter->second;
106  }
107  }
108  }
109  int serialize(char* buffer) const override
110  {
111  BufferWriter writer(buffer);
112  writer << ranks;
113  writer << ids;
114  return writer.getPos();
115  }
116  int deserialize(char* buffer) override
117  {
118  BufferReader reader(buffer);
119  reader >> ranks;
120  reader >> ids;
121  return reader.getPos();
122  }
123  std::unique_ptr<NbrInfoBase> clone() const override
124  {
125  return std::make_unique<FineNbrInfo<D>>(*this);
126  }
127 };
128 template<int D>
129 void
130 to_json(tpl::nlohmann::json& j, const FineNbrInfo<D>& n)
131 {
132  j["type"] = NbrType::Fine;
133  j["ids"] = n.ids;
134  j["ranks"] = n.ranks;
135 }
136 template<int D>
137 void
138 from_json(const tpl::nlohmann::json& j, FineNbrInfo<D>& n)
139 {
140  n.ids = j["ids"].get<std::array<int, Orthant<D>::num_orthants>>();
141  n.ranks = j["ranks"].get<std::array<int, Orthant<D>::num_orthants>>();
142 }
143 } // namespace ThunderEgg
144 #endif
ThunderEgg::Orthant
An enum-style class that represents the octants of a cube.
Definition: Orthant.h:43
ThunderEgg::BufferWriter
Class that is used to help serialize objects into a buffer.
Definition: BufferWriter.h:38
ThunderEgg::FineNbrInfo::setLocalIndexes
void setLocalIndexes(const std::map< int, int > &id_to_local_index_map) override
Set the global indexes in the NbrInfo objects.
Definition: FineNbrInfo.h:100
ThunderEgg::FineNbrInfo::FineNbrInfo
FineNbrInfo()
Construct a new empty FineNbrInfo object.
Definition: FineNbrInfo.h:61
ThunderEgg::FineNbrInfo::deserialize
int deserialize(char *buffer) override
Deserialize an object.
Definition: FineNbrInfo.h:116
ThunderEgg::FineNbrInfo::getNbrIds
void getNbrIds(std::deque< int > &nbr_ids) const override
Add to a deque of neighbor ids.
Definition: FineNbrInfo.h:82
ThunderEgg::FineNbrInfo::ids
std::array< int, Orthant< D >::num_orthants > ids
The ids of the neighbors.
Definition: FineNbrInfo.h:49
ThunderEgg::NbrType
NbrType
The type of neighbor.
Definition: NbrType.h:34
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
ThunderEgg::NbrInfo
Represents information about a patch's neighbor.
Definition: NbrInfo.h:36
ThunderEgg::FineNbrInfo::clone
std::unique_ptr< NbrInfoBase > clone() const override
get a clone of this object (equivalent to copy constructor)
Definition: FineNbrInfo.h:123
ThunderEgg::FineNbrInfo::global_indexes
std::array< int, Orthant< D >::num_orthants > global_indexes
The global indexes of the neighbors.
Definition: FineNbrInfo.h:53
ThunderEgg::FineNbrInfo::FineNbrInfo
FineNbrInfo(std::array< int, Orthant< D >::num_orthants > ids)
Construct a new FineNbrInfo object.
Definition: FineNbrInfo.h:74
ThunderEgg::FineNbrInfo::getNbrRanks
void getNbrRanks(std::deque< int > &nbr_ranks) const override
Add to a deque of neighbor ranks.
Definition: FineNbrInfo.h:88
ThunderEgg::FineNbrInfo::ranks
std::array< int, Orthant< D >::num_orthants > ranks
The mpi rank that the neighbor resides on.
Definition: FineNbrInfo.h:45
ThunderEgg::FineNbrInfo::local_indexes
std::array< int, Orthant< D >::num_orthants > local_indexes
The local indexes of the neighbors.
Definition: FineNbrInfo.h:57
ThunderEgg::BufferReader::getPos
int getPos()
get the current position in the buffer
Definition: BufferReader.h:74
NbrInfo.h
NbrInfo class.
BufferWriter.h
BufferWriter class.
ThunderEgg::FineNbrInfo::getNbrType
NbrType getNbrType() const override
Get the NbrType.
Definition: FineNbrInfo.h:81
ThunderEgg::NbrType::Fine
@ Fine
The nighbor is at a finer refinement level.
ThunderEgg::BufferWriter::getPos
int getPos()
get the current position in the buffer
Definition: BufferWriter.h:80
ThunderEgg::BufferReader
Class that is used to help read serialized objects from a buffer.
Definition: BufferReader.h:38
BufferReader.h
BufferReader class.
ThunderEgg::FineNbrInfo::setGlobalIndexes
void setGlobalIndexes(const std::map< int, int > &id_to_global_index_map) override
Set the local indexes in the NbrInfo objects.
Definition: FineNbrInfo.h:94
ThunderEgg::FineNbrInfo
Represents neighbors that are at a finer refinement level.
Definition: FineNbrInfo.h:39
Orthant.h
Orthant class.
ThunderEgg::FineNbrInfo::serialize
int serialize(char *buffer) const override
Serialize object into buffer.
Definition: FineNbrInfo.h:109