Peano
Loading...
Searching...
No Matches
GridVertex.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include <string>
6
7#ifdef Parallel
8#include <functional>
9#include <mpi.h>
10#endif
11
15#include "tarch/la/Vector.h"
16#include "tarch/mpi/Rank.h"
18
19namespace peano4 {
20 namespace grid {
21 struct GridVertex;
22 } // namespace grid
23} // namespace peano4
24
26public:
27 enum class State : int {
28 HangingVertex = 0,
29 New = 1,
30 Unrefined = 2,
31 Refined = 3,
33 Refining = 5,
35 Erasing = 7,
36 Delete = 8
37 };
38
41 State __state,
43 tarch::la::Vector<TwoPowerD, int> __backupOfAdjacentRanks,
44 bool __hasBeenAntecessorOfRefinedVertexInPreviousTreeSweep,
45 bool __isAntecessorOfRefinedVertexInCurrentTreeSweep,
46 bool __hasBeenParentOfSubtreeVertexInPreviousTreeSweep,
47 bool __isParentOfSubtreeVertexInCurrentTreeSweep,
48 int __numberOfAdjacentRefinedLocalCells,
50 int __level
51 );
52
54 inline void setState(State value);
57 inline int getAdjacentRanks(int index) const;
58 inline void setAdjacentRanks(int index, int value);
61 inline int getBackupOfAdjacentRanks(int index) const;
62 inline void setBackupOfAdjacentRanks(int index, int value);
71 inline int getNumberOfAdjacentRefinedLocalCells() const;
72 inline void setNumberOfAdjacentRefinedLocalCells(int value);
73#if PeanoDebug > 0
74 inline tarch::la::Vector<Dimensions, double> getX() const;
75 inline void setX(const tarch::la::Vector<Dimensions, double>& value);
76 inline double getX(int index) const;
77 inline void setX(int index, double value);
78#endif
79 inline int getLevel() const;
80 inline void setLevel(int value);
81 GridVertex(const GridVertex& copy);
83
84#ifdef Parallel
90 [[clang::map_mpi_datatype]]
91 static MPI_Datatype getForkDatatype();
92
93 [[clang::map_mpi_datatype]]
94 static MPI_Datatype getJoinDatatype();
95
96 [[clang::map_mpi_datatype]]
97 static MPI_Datatype getBoundaryExchangeDatatype();
98
99 [[clang::map_mpi_datatype]]
101
102 [[clang::map_mpi_datatype]]
103 static MPI_Datatype getGlobalCommunciationDatatype();
104
105 [[clang::map_mpi_datatype]]
106 static void freeForkDatatype();
107
108 [[clang::map_mpi_datatype]]
109 static void freeJoinDatatype();
110
111 [[clang::map_mpi_datatype]]
113
114 [[clang::map_mpi_datatype]]
116
117 [[clang::map_mpi_datatype]]
119
124 int
126
131 static void initDatatype();
132
136 static void shutdownDatatype();
137
146 static void send(const peano4::grid::GridVertex& buffer, int destination, int tag, MPI_Comm communicator);
147 static void receive(peano4::grid::GridVertex& buffer, int source, int tag, MPI_Comm communicator);
148
155 static void send(
156 const peano4::grid::GridVertex& buffer,
157 int destination,
158 int tag,
159 std::function<void()> startCommunicationFunctor,
160 std::function<void()> waitFunctor,
161 MPI_Comm communicator
162 );
163 static void receive(
165 int source,
166 int tag,
167 std::function<void()> startCommunicationFunctor,
168 std::function<void()> waitFunctor,
169 MPI_Comm communicator
170 );
171#endif
172
174
177
178#ifdef Parallel
180 const peano4::grid::GridVertex& message,
181 int destination,
182 int tag,
183 MPI_Comm communicator = tarch::mpi::Rank::getInstance().getCommunicator()
184 );
187 int source,
188 int tag,
189 MPI_Comm communicator = tarch::mpi::Rank::getInstance().getCommunicator()
190 );
191#endif
192
193 std::string toString() const;
194
195private:
196 [[clang::pack]] State _state;
197#if defined(__PACKED_ATTRIBUTES_LANGUAGE_EXTENSION__)
198 [[clang::pack_range(-1, std::numeric_limits<int>::max())]] int _adjacentRanks[TwoPowerD];
199#endif
200#if !defined(__PACKED_ATTRIBUTES_LANGUAGE_EXTENSION__)
202#endif
208 [[clang::pack_range(0, TwoPowerD)]] int _numberOfAdjacentRefinedLocalCells;
209#if PeanoDebug > 0
210#if defined(__PACKED_ATTRIBUTES_LANGUAGE_EXTENSION__)
211 [[clang::truncate_mantissa(48)]] double _x[Dimensions];
212#endif
213#if !defined(__PACKED_ATTRIBUTES_LANGUAGE_EXTENSION__)
215#endif
216#endif
217
219
220#ifdef Parallel
221private:
223
224#if !defined(__MPI_ATTRIBUTES_LANGUAGE_EXTENSION__)
231 static MPI_Datatype Datatype;
232#endif
233#endif
234};
235
236
240
241
243 _state = value;
244}
245
246
248
250 for( int i=0; i<TwoPowerD; i++) {
251 result(i) = _adjacentRanks[i];
252 }
253 return result;
254 }
255
256
258
259 for( int i=0; i<TwoPowerD; i++) {
260 _adjacentRanks[i] = value(i);
261 }
262 }
263
264
266 return _adjacentRanks[index];
267}
268
269
271 _adjacentRanks[index] = value;
272}
273
274
278
279
281 _backupOfAdjacentRanks = value;
282}
283
284
286 return _backupOfAdjacentRanks(index);
287}
288
289
291 _backupOfAdjacentRanks(index) = value;
292}
293
294
296 return _hasBeenAntecessorOfRefinedVertexInPreviousTreeSweep;
297}
298
299
301 _hasBeenAntecessorOfRefinedVertexInPreviousTreeSweep = value;
302}
303
304
306 return _isAntecessorOfRefinedVertexInCurrentTreeSweep;
307}
308
309
311 _isAntecessorOfRefinedVertexInCurrentTreeSweep = value;
312}
313
314
316 return _hasBeenParentOfSubtreeVertexInPreviousTreeSweep;
317}
318
319
321 _hasBeenParentOfSubtreeVertexInPreviousTreeSweep = value;
322}
323
324
326 return _isParentOfSubtreeVertexInCurrentTreeSweep;
327}
328
329
331 _isParentOfSubtreeVertexInCurrentTreeSweep = value;
332}
333
334
336 return _numberOfAdjacentRefinedLocalCells;
337}
338
339
341 _numberOfAdjacentRefinedLocalCells = value;
342}
343
344
345#if PeanoDebug>0
346tarch::la::Vector<Dimensions,double> peano4::grid::GridVertex::getX() const {
347
349 for( int i=0; i<Dimensions; i++) {
350 result(i) = _x[i];
351 }
352 return result;
353 }
354
355
356void peano4::grid::GridVertex::setX(const tarch::la::Vector<Dimensions,double>& value) {
357
358 for( int i=0; i<Dimensions; i++) {
359 _x[i] = value(i);
360 }
361 }
362
363
364double peano4::grid::GridVertex::getX(int index) const {
365 return _x[index];
366}
367
368
369void peano4::grid::GridVertex::setX(int index, double value) {
370 _x[index] = value;
371}
372
373
374#endif
375
376
378 return _level;
379}
380
381
383 _level = value;
384}
#define TwoPowerD
Definition Globals.h:19
static Rank & getInstance()
This operation returns the singleton instance.
bool getIsParentOfSubtreeVertexInCurrentTreeSweep() const
Definition GridVertex.h:325
static void freeBoundaryExchangeDatatype()
tarch::la::Vector< TwoPowerD, int > getAdjacentRanks() const
Definition GridVertex.h:247
static void receiveAndPollDanglingMessages(peano4::grid::GridVertex &message, int source, int tag, MPI_Comm communicator=tarch::mpi::Rank::getInstance().getCommunicator())
tarch::la::Vector< TwoPowerD, int > _backupOfAdjacentRanks
Definition GridVertex.h:203
int getNumberOfAdjacentRefinedLocalCells() const
Definition GridVertex.h:335
static MPI_Datatype Datatype
Whenever we use LLVM's MPI extension (DaStGe), we rely on lazy initialisation of the datatype.
Definition GridVertex.h:231
static void send(const peano4::grid::GridVertex &buffer, int destination, int tag, MPI_Comm communicator)
In DaStGen (the first version), I had a non-static version of the send as well as the receive.
void setBackupOfAdjacentRanks(const tarch::la::Vector< TwoPowerD, int > &value)
Definition GridVertex.h:280
void setIsAntecessorOfRefinedVertexInCurrentTreeSweep(bool value)
Definition GridVertex.h:310
bool _hasBeenParentOfSubtreeVertexInPreviousTreeSweep
Definition GridVertex.h:206
static MPI_Datatype getGlobalCommunciationDatatype()
bool getHasBeenAntecessorOfRefinedVertexInPreviousTreeSweep() const
Definition GridVertex.h:295
GridVertex(const GridVertex &copy)
static MPI_Datatype getJoinDatatype()
GridVertex & operator=(const GridVertex &other)
GridVertex(ObjectConstruction)
Definition GridVertex.h:175
tarch::la::Vector< TwoPowerD, int > getBackupOfAdjacentRanks() const
Definition GridVertex.h:275
static void freeMultiscaleDataExchangeDatatype()
static MPI_Datatype getBoundaryExchangeDatatype()
GridVertex(State __state, tarch::la::Vector< TwoPowerD, int > __adjacentRanks, tarch::la::Vector< TwoPowerD, int > __backupOfAdjacentRanks, bool __hasBeenAntecessorOfRefinedVertexInPreviousTreeSweep, bool __isAntecessorOfRefinedVertexInCurrentTreeSweep, bool __hasBeenParentOfSubtreeVertexInPreviousTreeSweep, bool __isParentOfSubtreeVertexInCurrentTreeSweep, int __numberOfAdjacentRefinedLocalCells, tarch::la::Vector< Dimensions, double > __x, int __level)
void setLevel(int value)
Definition GridVertex.h:382
static void shutdownDatatype()
Free the underlying MPI datatype.
static void freeGlobalCommunciationDatatype()
static void receive(peano4::grid::GridVertex &buffer, int source, int tag, std::function< void()> startCommunicationFunctor, std::function< void()> waitFunctor, MPI_Comm communicator)
bool _isParentOfSubtreeVertexInCurrentTreeSweep
Definition GridVertex.h:207
bool _hasBeenAntecessorOfRefinedVertexInPreviousTreeSweep
Definition GridVertex.h:204
bool _isAntecessorOfRefinedVertexInCurrentTreeSweep
Definition GridVertex.h:205
void setNumberOfAdjacentRefinedLocalCells(int value)
Definition GridVertex.h:340
static void sendAndPollDanglingMessages(const peano4::grid::GridVertex &message, int destination, int tag, MPI_Comm communicator=tarch::mpi::Rank::getInstance().getCommunicator())
void setIsParentOfSubtreeVertexInCurrentTreeSweep(bool value)
Definition GridVertex.h:330
std::string toString() const
tarch::la::Vector< TwoPowerD, int > _adjacentRanks
Definition GridVertex.h:201
bool getIsAntecessorOfRefinedVertexInCurrentTreeSweep() const
Definition GridVertex.h:305
void setHasBeenParentOfSubtreeVertexInPreviousTreeSweep(bool value)
Definition GridVertex.h:320
static void send(const peano4::grid::GridVertex &buffer, int destination, int tag, std::function< void()> startCommunicationFunctor, std::function< void()> waitFunctor, MPI_Comm communicator)
Alternative to the other send() where I trigger a non-blocking send an then invoke the functor until ...
void setHasBeenAntecessorOfRefinedVertexInPreviousTreeSweep(bool value)
Definition GridVertex.h:300
void setState(State value)
Definition GridVertex.h:242
static void freeJoinDatatype()
static void initDatatype()
Wrapper around getDatatype() to trigger lazy evaluation if we use the lazy initialisation.
void setAdjacentRanks(const tarch::la::Vector< TwoPowerD, int > &value)
Definition GridVertex.h:257
static void freeForkDatatype()
bool getHasBeenParentOfSubtreeVertexInPreviousTreeSweep() const
Definition GridVertex.h:315
peano4::grid::GridVertex::State getState() const
Definition GridVertex.h:237
static void receive(peano4::grid::GridVertex &buffer, int source, int tag, MPI_Comm communicator)
static MPI_Datatype getForkDatatype()
Hands out MPI datatype if we work without the LLVM MPI extension.
static MPI_Datatype getMultiscaleDataExchangeDatatype()
Simple vector class.
Definition Vector.h:159