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
41namespace Nektar
42{
43namespace MultiRegions
44{
45
46/**
47 * Object for each interface present between two ranks, which are held in the
48 * InterfaceExchange object.
49 */
50
52{
53public:
54 /// Constructor
56 const ExpListSharedPtr &trace,
57 const SpatialDomains::InterfaceShPtr &interfaceShPtr);
58
59 /// Default destructor
61
62 inline void SetCheckLocal(bool flag)
63 {
64 m_checkLocal = flag;
65 }
66
67 /// Returns the missing coordinates vector
68 inline std::vector<Array<OneD, NekDouble>> GetMissingCoords()
69 {
70 return m_missingCoords;
71 }
72
73 /// Returns the interface object
75 {
76 return m_interface;
77 }
78
79 /// Calculates what coordinates on the interface are missing locally
80 void CalcLocalMissing();
81 /// Fills the Bwd trace by interpolating from the Fwd for local interfaces
84 /// Fills the Bwd trace from partitioned trace
87
88private:
89 /// Trace expansion list
91 /// Local interface object
93 /// Flag whether the opposite side of the interface is present locally
94 bool m_checkLocal = false;
95 /// Vector of coordinates on interface missing from the other side locally
96 std::vector<Array<OneD, NekDouble>> m_missingCoords;
97 /// Map of found coordinates present locally
98 std::map<int, std::pair<int, Array<OneD, NekDouble>>> m_foundLocalCoords;
99 /// Vector of indices corresponding to m_missingCoord locations in trace
100 std::vector<int> m_mapMissingCoordToTrace;
101};
102
103typedef std::shared_ptr<InterfaceTrace> InterfaceTraceSharedPtr;
104
105/**
106 * Object for one rank-to-rank communication for all interfaces shared
107 * between those ranks. e.g. if on rank 1 and there are interfaces shared with
108 * rank 2 and 3, there will be two InterfaceExchange objects in m_exchange in
109 * InterfaceMapDG. This holds the InterfaceTrace objects in m_interfaceTraces.
110 */
112{
113public:
114 /// Default destructor
116
117 /// Constructor
120 const ExpListSharedPtr &trace, const LibUtilities::CommSharedPtr &comm,
121 std::pair<int, std::vector<InterfaceTraceSharedPtr>> rankPair)
122 : m_movement(movement), m_zones(movement->GetZones()), m_trace(trace),
123 m_comm(comm), m_rank(rankPair.first),
124 m_interfaceTraces(rankPair.second)
125 {
126 }
127
128 /**
129 * Communicates with other ranks how many missing coordinates for each
130 * interface to expect
131 *
132 * @param requestSend List of send requests
133 * @param requestRecv List of receive requests
134 * @param requestNum Index of request in list to use
135 */
138 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum);
139
140 /**
141 * Sends/receives the missing coordinates to/from other ranks
142 *
143 * @param requestSend List of send requests
144 * @param requestRecv List of receive requests
145 * @param requestNum Index of request in list to use
146 */
149 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum);
150
151 /// Populates m_foundRankCoords using the FindDistance function
153
154 /**
155 * Calculates and sends the trace to other rank from the m_foundRankCoords
156 * structure using non-blocking pairwise communication i.e. Isend & Irecv
157 *
158 * @param requestSend List of send requests
159 * @param requestRecv List of receive requests
160 * @param requestNum Index of request in list to use
161 * @param Fwd The values to send across the interface
162 */
165 LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum,
167
168 /**
169 * Loops over interfaces and partitions out the received trace from the
170 * other ranks for insertion into Bwd using FillRankBwdTrace
171 *
172 * @param Bwd The Bwd trace to be filled from across the interface
173 */
176
177private:
178 /// Movement object associated with the non-conformal interfaces
180 /// Map of zone IDs to zone bases
181 std::map<int, SpatialDomains::ZoneBaseShPtr> m_zones;
182 /// Trace expansion list
184 /// Communicator
186 /// Process rank
188 /// Vector of interface traces i.e. every interface side present on m_rank
189 const std::vector<InterfaceTraceSharedPtr> m_interfaceTraces;
190 /// Send buffer for coord exchange
192 /// Receive buffer for coord exchange
194 /// Receive buffer for trace exchange
196 /// Send buffer for trace exchange
198 /// Map of rank to total size of send buffer for all interfaces
199 std::map<int, int> m_totSendSize;
200 /// Map of rank to total size of receive buffer for all interfaces
201 std::map<int, int> m_totRecvSize;
202 /// Map of rank to array of size of send buffer for each interface
203 std::map<int, Array<OneD, int>> m_sendSize;
204 /// Map of rank to array of size of receive buffer for each interface
205 std::map<int, Array<OneD, int>> m_recvSize;
206
207 /**
208 * Caches the found coordinates to reuse when exchanging the trace in a
209 * map of integer rank to a map of integer missing coordinate location to a
210 * pair of local edge ID and found local coordinate
211 */
212 std::map<int, std::map<int, std::pair<int, Array<OneD, NekDouble>>>>
214};
215
216typedef std::shared_ptr<InterfaceExchange> InterfaceExchangeSharedPtr;
217
218/**
219 * Implements the communication patterns to allow for exchange of information
220 * across non-conformal interfaces and across different partitions. Holds all
221 * the InterfaceExchange objects in m_exchange.
222 */
224{
225public:
226 /// Default destructor
228
229 /**
230 * Sets up the InterfaceExchange objects stored in m_exchange, each object
231 * is rank -> rank and contains a vector of InterfaceTrace objects
232 * corresponding to shared interfaces between those ranks.
233 */
236 const ExpListSharedPtr &trace);
237
238 /**
239 * @brief Perform the trace exchange between processors, given the forwards
240 * and backwards spaces.
241 *
242 * @param Fwd Local forwards space of the trace (which will be sent)
243 * @param Bwd Local backwards space of the trace (which will receive
244 * contributions)
245 */
248 /**
249 * @brief Perform the coordinate exchange between processors. This is where
250 * the missing coordinates on the interface are found and sent to all other
251 * processors on the other side of that interface so the matching ranks can
252 * be found.
253 */
255
256private:
257 /// Mesh associated with this expansion list.
259 /// Movement object associated with the non-conformal interfaces
261 /// Interface sides present on current process
262 std::vector<InterfaceTraceSharedPtr> m_localInterfaces;
263 /// Trace expansion list
265 /// Vector of interface exchanges, i.e. every rank-to-rank comm needed
266 std::vector<InterfaceExchangeSharedPtr> m_exchange;
267};
268
269typedef std::shared_ptr<InterfaceMapDG> InterfaceMapDGSharedPtr;
270
271} // namespace MultiRegions
272} // namespace Nektar
273
274#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:86
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:57
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:179
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:176
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2