Nektar++
InterfaceMapDG.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File InterfaceMapDG.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: MPI communication for interfaces, header file
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_INTERFACEMAPDG_H
36#define NEKTAR_INTERFACEMAPDG_H
37
40
42{
43
44/**
45 * Object for each interface present between two ranks, which are held in the
46 * InterfaceExchange object.
47 */
48
50{
51public:
52 /// Constructor
54 const ExpListSharedPtr &trace,
55 const SpatialDomains::InterfaceShPtr &interfaceShPtr);
56
57 /// Default destructor
59
60 inline void SetCheckLocal(bool flag)
61 {
62 m_checkLocal = flag;
63 }
64
65 /// Returns the missing coordinates vector
66 inline std::vector<Array<OneD, NekDouble>> GetMissingCoords()
67 {
68 return m_missingCoords;
69 }
70
71 /// Returns the interface object
73 {
74 return m_interface;
75 }
76
77 /// Calculates what coordinates on the interface are missing locally
78 void CalcLocalMissing();
79 /// Fills the Bwd trace by interpolating from the Fwd for local interfaces
82 /// Fills the Bwd trace from partitioned trace
85
86private:
87 /// Trace expansion list
89 /// Local interface object
91 /// Flag whether the opposite side of the interface is present locally
92 bool m_checkLocal = false;
93 /// Vector of coordinates on interface missing from the other side locally
94 std::vector<Array<OneD, NekDouble>> m_missingCoords;
95 /// Map of found coordinates present locally
96 std::map<int, std::pair<int, Array<OneD, NekDouble>>> m_foundLocalCoords;
97 /// Vector of indices corresponding to m_missingCoord locations in trace
98 std::vector<int> m_mapMissingCoordToTrace;
99};
100
101typedef std::shared_ptr<InterfaceTrace> InterfaceTraceSharedPtr;
102
103/**
104 * Object for one rank-to-rank communication for all interfaces shared
105 * between those ranks. e.g. if on rank 1 and there are interfaces shared with
106 * rank 2 and 3, there will be two InterfaceExchange objects in m_exchange in
107 * InterfaceMapDG. This holds the InterfaceTrace objects in m_interfaceTraces.
108 */
110{
111public:
112 /// Default destructor
114
115 /// Constructor
118 const ExpListSharedPtr &trace, const LibUtilities::CommSharedPtr &comm,
119 std::pair<int, std::vector<InterfaceTraceSharedPtr>> rankPair)
120 : m_movement(movement), m_zones(movement->GetZones()), m_trace(trace),
121 m_comm(comm), m_rank(rankPair.first),
122 m_interfaceTraces(rankPair.second)
123 {
124 }
125
126 /**
127 * Communicates with other ranks how many missing coordinates for each
128 * interface to expect
129 *
130 * @param requestSend List of send requests
131 * @param requestRecv List of receive requests
132 * @param requestNum Index of request in list to use
133 */
136 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum);
137
138 /**
139 * Sends/receives the missing coordinates to/from other ranks
140 *
141 * @param requestSend List of send requests
142 * @param requestRecv List of receive requests
143 * @param requestNum Index of request in list to use
144 */
147 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum);
148
149 /// Populates m_foundRankCoords using the FindDistance function
151
152 /**
153 * Calculates and sends the trace to other rank from the m_foundRankCoords
154 * structure using non-blocking pairwise communication i.e. Isend & Irecv
155 *
156 * @param requestSend List of send requests
157 * @param requestRecv List of receive requests
158 * @param requestNum Index of request in list to use
159 * @param Fwd The values to send across the interface
160 */
163 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum,
165
166 /**
167 * Loops over interfaces and partitions out the received trace from the
168 * other ranks for insertion into Bwd using FillRankBwdTrace
169 *
170 * @param Bwd The Bwd trace to be filled from across the interface
171 */
174
175private:
176 /// Movement object associated with the non-conformal interfaces
178 /// Map of zone IDs to zone bases
179 std::map<int, SpatialDomains::ZoneBaseShPtr> m_zones;
180 /// Trace expansion list
182 /// Communicator
184 /// Process rank
186 /// Vector of interface traces i.e. every interface side present on m_rank
187 const std::vector<InterfaceTraceSharedPtr> m_interfaceTraces;
188 /// Send buffer for coord exchange
190 /// Receive buffer for coord exchange
192 /// Receive buffer for trace exchange
194 /// Send buffer for trace exchange
196 /// Map of rank to total size of send buffer for all interfaces
197 std::map<int, int> m_totSendSize;
198 /// Map of rank to total size of receive buffer for all interfaces
199 std::map<int, int> m_totRecvSize;
200 /// Map of rank to array of size of send buffer for each interface
201 std::map<int, Array<OneD, int>> m_sendSize;
202 /// Map of rank to array of size of receive buffer for each interface
203 std::map<int, Array<OneD, int>> m_recvSize;
204
205 /**
206 * Caches the found coordinates to reuse when exchanging the trace in a
207 * map of integer rank to a map of integer missing coordinate location to a
208 * pair of local edge ID and found local coordinate
209 */
210 std::map<int, std::map<int, std::pair<int, Array<OneD, NekDouble>>>>
212};
213
214typedef std::shared_ptr<InterfaceExchange> InterfaceExchangeSharedPtr;
215
216/**
217 * Implements the communication patterns to allow for exchange of information
218 * across non-conformal interfaces and across different partitions. Holds all
219 * the InterfaceExchange objects in m_exchange.
220 */
222{
223public:
224 /// Default destructor
226
227 /**
228 * Sets up the InterfaceExchange objects stored in m_exchange, each object
229 * is rank -> rank and contains a vector of InterfaceTrace objects
230 * corresponding to shared interfaces between those ranks.
231 */
234 const ExpListSharedPtr &trace);
235
236 /**
237 * @brief Perform the trace exchange between processors, given the forwards
238 * and backwards spaces.
239 *
240 * @param Fwd Local forwards space of the trace (which will be sent)
241 * @param Bwd Local backwards space of the trace (which will receive
242 * contributions)
243 */
246 /**
247 * @brief Perform the coordinate exchange between processors. This is where
248 * the missing coordinates on the interface are found and sent to all other
249 * processors on the other side of that interface so the matching ranks can
250 * be found.
251 */
253
254private:
255 /// Mesh associated with this expansion list.
257 /// Movement object associated with the non-conformal interfaces
259 /// Interface sides present on current process
260 std::vector<InterfaceTraceSharedPtr> m_localInterfaces;
261 /// Trace expansion list
263 /// Vector of interface exchanges, i.e. every rank-to-rank comm needed
264 std::vector<InterfaceExchangeSharedPtr> m_exchange;
265};
266
267typedef std::shared_ptr<InterfaceMapDG> InterfaceMapDGSharedPtr;
268
269} // namespace Nektar::MultiRegions
270
271#endif
#define MULTI_REGIONS_EXPORT
std::map< int, Array< OneD, int > > m_sendSize
Map of rank to array of size of send buffer for each interface.
void RankFillSizes(LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum)
std::map< int, SpatialDomains::ZoneBaseShPtr > m_zones
Map of zone IDs to zone bases.
const ExpListSharedPtr m_trace
Trace expansion list.
void FillRankBwdTraceExchange(Array< OneD, NekDouble > &Bwd)
const std::vector< InterfaceTraceSharedPtr > m_interfaceTraces
Vector of interface traces i.e. every interface side present on m_rank.
const LibUtilities::CommSharedPtr m_comm
Communicator.
void SendFwdTrace(LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum, Array< OneD, NekDouble > &Fwd)
Array< OneD, NekDouble > m_send
Send buffer for coord exchange.
std::map< int, std::map< int, std::pair< int, Array< OneD, NekDouble > > > > m_foundRankCoords
InterfaceExchange(SpatialDomains::MovementSharedPtr movement, const ExpListSharedPtr &trace, const LibUtilities::CommSharedPtr &comm, std::pair< int, std::vector< InterfaceTraceSharedPtr > > rankPair)
Constructor.
std::map< int, int > m_totSendSize
Map of rank to total size of send buffer for all interfaces.
void CalcRankDistances()
Populates m_foundRankCoords using the FindDistance function.
std::map< int, int > m_totRecvSize
Map of rank to total size of receive buffer for all interfaces.
virtual ~InterfaceExchange()=default
Default destructor.
SpatialDomains::MovementSharedPtr m_movement
Movement object associated with the non-conformal interfaces.
std::map< int, Array< OneD, int > > m_recvSize
Map of rank to array of size of receive buffer for each interface.
Array< OneD, NekDouble > m_recv
Receive buffer for coord exchange.
void SendMissing(LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum)
Array< OneD, NekDouble > m_recvTrace
Receive buffer for trace exchange.
Array< OneD, NekDouble > m_sendTrace
Send buffer for trace exchange.
~InterfaceMapDG()=default
Default destructor.
SpatialDomains::MeshGraphSharedPtr m_graph
Mesh associated with this expansion list.
const ExpListSharedPtr m_trace
Trace expansion list.
void ExchangeTrace(Array< OneD, NekDouble > &Fwd, Array< OneD, NekDouble > &Bwd)
Perform the trace exchange between processors, given the forwards and backwards spaces.
std::vector< InterfaceExchangeSharedPtr > m_exchange
Vector of interface exchanges, i.e. every rank-to-rank comm needed.
void ExchangeCoords()
Perform the coordinate exchange between processors. This is where the missing coordinates on the inte...
SpatialDomains::MovementSharedPtr m_movement
Movement object associated with the non-conformal interfaces.
InterfaceMapDG(const SpatialDomains::MeshGraphSharedPtr &graph, const ExpListSharedPtr &trace)
std::vector< InterfaceTraceSharedPtr > m_localInterfaces
Interface sides present on current process.
ExpListSharedPtr m_trace
Trace expansion list.
std::vector< Array< OneD, NekDouble > > GetMissingCoords()
Returns the missing coordinates vector.
std::map< int, std::pair< int, Array< OneD, NekDouble > > > m_foundLocalCoords
Map of found coordinates present locally.
std::vector< int > m_mapMissingCoordToTrace
Vector of indices corresponding to m_missingCoord locations in trace.
SpatialDomains::InterfaceShPtr GetInterface()
Returns the interface object.
SpatialDomains::InterfaceShPtr m_interface
Local interface object.
std::vector< Array< OneD, NekDouble > > m_missingCoords
Vector of coordinates on interface missing from the other side locally.
virtual ~InterfaceTrace()=default
Default destructor.
InterfaceTrace(const ExpListSharedPtr &trace, const SpatialDomains::InterfaceShPtr &interfaceShPtr)
Constructor.
void FillRankBwdTrace(Array< OneD, NekDouble > &trace, Array< OneD, NekDouble > &Bwd)
Fills the Bwd trace from partitioned trace.
void CalcLocalMissing()
Calculates what coordinates on the interface are missing locally.
void FillLocalBwdTrace(Array< OneD, NekDouble > &Fwd, Array< OneD, NekDouble > &Bwd)
Fills the Bwd trace by interpolating from the Fwd for local interfaces.
bool m_checkLocal
Flag whether the opposite side of the interface is present locally.
std::shared_ptr< CommRequest > CommRequestSharedPtr
Definition: Comm.h:84
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::shared_ptr< InterfaceTrace > InterfaceTraceSharedPtr
std::shared_ptr< InterfaceMapDG > InterfaceMapDGSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< InterfaceExchange > InterfaceExchangeSharedPtr
std::shared_ptr< Interface > InterfaceShPtr
std::shared_ptr< Movement > MovementSharedPtr
Definition: MeshGraph.h:177
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174