ThunderEgg  1.0.0
NormalNbrInfo.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_NORMALNBRINFO_H
21 #define THUNDEREGG_NORMALNBRINFO_H
22 
29 #include <ThunderEgg/NbrInfo.h>
30 
31 namespace ThunderEgg {
37 template<int D>
38 class NormalNbrInfo : public NbrInfo<D>
39 {
40 public:
44  int rank = 0;
48  int id = 0;
52  int local_index = -1;
56  int global_index = -1;
61  ~NormalNbrInfo() = default;
67  NormalNbrInfo(int id) { this->id = id; }
68  NbrType getNbrType() const override { return NbrType::Normal; }
69  void getNbrIds(std::deque<int>& nbr_ids) const override { nbr_ids.push_back(id); }
70  void getNbrRanks(std::deque<int>& nbr_ranks) const override { nbr_ranks.push_back(rank); }
71  void setGlobalIndexes(const std::map<int, int>& id_to_global_index_map) override
72  {
73  global_index = id_to_global_index_map.at(id);
74  }
75  void setLocalIndexes(const std::map<int, int>& id_to_local_index_map) override
76  {
77  auto iter = id_to_local_index_map.find(id);
78  if (iter != id_to_local_index_map.end()) {
79  local_index = iter->second;
80  }
81  }
82  int serialize(char* buffer) const override
83  {
84  BufferWriter writer(buffer);
85  writer << rank;
86  writer << id;
87  return writer.getPos();
88  }
89  int deserialize(char* buffer) override
90  {
91  BufferReader reader(buffer);
92  reader >> rank;
93  reader >> id;
94  return reader.getPos();
95  }
96  std::unique_ptr<NbrInfoBase> clone() const override
97  {
98  return std::make_unique<NormalNbrInfo<D>>(*this);
99  }
100 };
101 template<int D>
102 void
103 to_json(tpl::nlohmann::json& j, const NormalNbrInfo<D>& n)
104 {
105  j["type"] = NbrType::Normal;
106  j["ids"] = { n.id };
107  j["ranks"] = { n.rank };
108 }
109 template<int D>
110 void
111 from_json(const tpl::nlohmann::json& j, NormalNbrInfo<D>& n)
112 {
113  n.id = j["ids"][0];
114  n.rank = j["ranks"][0];
115 }
116 } // namespace ThunderEgg
117 #endif
ThunderEgg::NormalNbrInfo::getNbrType
NbrType getNbrType() const override
Get the NbrType.
Definition: NormalNbrInfo.h:68
ThunderEgg::NormalNbrInfo::getNbrRanks
void getNbrRanks(std::deque< int > &nbr_ranks) const override
Add to a deque of neighbor ranks.
Definition: NormalNbrInfo.h:70
ThunderEgg::BufferWriter
Class that is used to help serialize objects into a buffer.
Definition: BufferWriter.h:38
ThunderEgg::NormalNbrInfo::local_index
int local_index
The local index of the neighbor.
Definition: NormalNbrInfo.h:52
ThunderEgg::NormalNbrInfo::NormalNbrInfo
NormalNbrInfo()
Construct a new empty NormalNbrInfo object.
Definition: NormalNbrInfo.h:60
ThunderEgg::NormalNbrInfo::clone
std::unique_ptr< NbrInfoBase > clone() const override
get a clone of this object (equivalent to copy constructor)
Definition: NormalNbrInfo.h:96
ThunderEgg::NormalNbrInfo::deserialize
int deserialize(char *buffer) override
Deserialize an object.
Definition: NormalNbrInfo.h:89
ThunderEgg::NormalNbrInfo::NormalNbrInfo
NormalNbrInfo(int id)
Construct a new NormalNbrInfo object.
Definition: NormalNbrInfo.h:67
ThunderEgg::NbrType
NbrType
The type of neighbor.
Definition: NbrType.h:34
ThunderEgg::NormalNbrInfo::global_index
int global_index
The global index of the neighbor.
Definition: NormalNbrInfo.h:56
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
ThunderEgg::NbrInfo
Represents information about a patch's neighbor.
Definition: NbrInfo.h:36
ThunderEgg::NormalNbrInfo::serialize
int serialize(char *buffer) const override
Serialize object into buffer.
Definition: NormalNbrInfo.h:82
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::NbrType::Normal
@ Normal
The neighbor is at the same refinement level.
ThunderEgg::NormalNbrInfo::setGlobalIndexes
void setGlobalIndexes(const std::map< int, int > &id_to_global_index_map) override
Set the local indexes in the NbrInfo objects.
Definition: NormalNbrInfo.h:71
ThunderEgg::NormalNbrInfo::setLocalIndexes
void setLocalIndexes(const std::map< int, int > &id_to_local_index_map) override
Set the global indexes in the NbrInfo objects.
Definition: NormalNbrInfo.h:75
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::NormalNbrInfo::id
int id
The id of the neighbor.
Definition: NormalNbrInfo.h:48
ThunderEgg::NormalNbrInfo
Represents a neighbor that is at the same refinement level.
Definition: NormalNbrInfo.h:38
ThunderEgg::NormalNbrInfo::rank
int rank
The mpi rank that the neighbor resides on.
Definition: NormalNbrInfo.h:44
ThunderEgg::NormalNbrInfo::getNbrIds
void getNbrIds(std::deque< int > &nbr_ids) const override
Add to a deque of neighbor ids.
Definition: NormalNbrInfo.h:69