Nektar++
Public Member Functions | Private Attributes | List of all members
Nektar::MultiRegions::InterfaceExchange Class Reference

#include <InterfaceMapDG.h>

Public Member Functions

virtual ~InterfaceExchange ()=default
 Default destructor. More...
 
 InterfaceExchange (SpatialDomains::MovementSharedPtr movement, const ExpListSharedPtr &trace, const LibUtilities::CommSharedPtr &comm, std::pair< int, std::vector< InterfaceTraceSharedPtr > > rankPair)
 Constructor. More...
 
void RankFillSizes (LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum)
 
void SendMissing (LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum)
 
void CalcRankDistances ()
 Populates m_foundRankCoords using the FindDistance function. More...
 
void SendFwdTrace (LibUtilities::CommRequestSharedPtr &requestSend, LibUtilities::CommRequestSharedPtr &requestRecv, int requestNum, Array< OneD, NekDouble > &Fwd)
 
void FillRankBwdTraceExchange (Array< OneD, NekDouble > &Bwd)
 

Private Attributes

SpatialDomains::MovementSharedPtr m_movement
 Movement object associated with the non-conformal interfaces. More...
 
std::map< int, SpatialDomains::ZoneBaseShPtrm_zones
 Map of zone IDs to zone bases. More...
 
const ExpListSharedPtr m_trace
 Trace expansion list. More...
 
const LibUtilities::CommSharedPtr m_comm
 Communicator. More...
 
int m_rank
 Process rank. More...
 
const std::vector< InterfaceTraceSharedPtrm_interfaceTraces
 Vector of interface traces i.e. every interface side present on m_rank. More...
 
Array< OneD, NekDoublem_send
 Send buffer for coord exchange. More...
 
Array< OneD, NekDoublem_recv
 Receive buffer for coord exchange. More...
 
Array< OneD, NekDoublem_recvTrace
 Receive buffer for trace exchange. More...
 
Array< OneD, NekDoublem_sendTrace
 Send buffer for trace exchange. More...
 
std::map< int, int > m_totSendSize
 Map of rank to total size of send buffer for all interfaces. More...
 
std::map< int, int > m_totRecvSize
 Map of rank to total size of receive buffer for all interfaces. More...
 
std::map< int, Array< OneD, int > > m_sendSize
 Map of rank to array of size of send buffer for each interface. More...
 
std::map< int, Array< OneD, int > > m_recvSize
 Map of rank to array of size of receive buffer for each interface. More...
 
std::map< int, std::map< int, std::pair< int, Array< OneD, NekDouble > > > > m_foundRankCoords
 

Detailed Description

Object for one rank-to-rank communication for all interfaces shared between those ranks. e.g. if on rank 1 and there are interfaces shared with rank 2 and 3, there will be two InterfaceExchange objects in m_exchange in InterfaceMapDG. This holds the InterfaceTrace objects in m_interfaceTraces.

Definition at line 109 of file InterfaceMapDG.h.

Constructor & Destructor Documentation

◆ ~InterfaceExchange()

virtual Nektar::MultiRegions::InterfaceExchange::~InterfaceExchange ( )
virtualdefault

Default destructor.

◆ InterfaceExchange()

Nektar::MultiRegions::InterfaceExchange::InterfaceExchange ( SpatialDomains::MovementSharedPtr  movement,
const ExpListSharedPtr trace,
const LibUtilities::CommSharedPtr comm,
std::pair< int, std::vector< InterfaceTraceSharedPtr > >  rankPair 
)
inline

Constructor.

Definition at line 116 of file InterfaceMapDG.h.

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 }
std::map< int, SpatialDomains::ZoneBaseShPtr > m_zones
Map of zone IDs to zone bases.
const ExpListSharedPtr m_trace
Trace expansion list.
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.
SpatialDomains::MovementSharedPtr m_movement
Movement object associated with the non-conformal interfaces.

Member Function Documentation

◆ CalcRankDistances()

void Nektar::MultiRegions::InterfaceExchange::CalcRankDistances ( )

Populates m_foundRankCoords using the FindDistance function.

Check coords in m_recv from other rank to see if present on this rank, and then populates m_foundRankCoords if found.

  • Loops over all interface traces present in the exchange, i.e. every interface needed on this rank-to-rank communication object
  • Then loops over all the quadrature points missing from the other side in that interface using global coordinates
  • Loop over each local edge and use MinMaxCheck on the point as a fast comparison on whether the point lies on the edge
  • If true then use the more expensive FindDistance function to find the closest local coordinate of the global 'missing' point on the local edge and the distance from the edge that corresponds to
  • If distance is less than 5e-5 save found coordinate in m_foundRankCoords

Definition at line 560 of file InterfaceMapDG.cpp.

561{
562 Array<OneD, int> disp(m_recvSize[m_rank].size() + 1, 0.0);
563 std::partial_sum(m_recvSize[m_rank].begin(), m_recvSize[m_rank].end(),
564 &disp[1]);
565
566 for (int i = 0; i < m_interfaceTraces.size(); ++i)
567 {
568 auto localEdge = m_interfaceTraces[i]->GetInterface()->GetEdge();
569
570 for (int j = disp[i]; j < disp[i + 1]; j += 3)
571 {
572 Array<OneD, NekDouble> foundLocCoord;
573 Array<OneD, NekDouble> xs(3);
574 xs[0] = m_recv[j];
575 xs[1] = m_recv[j + 1];
576 xs[2] = m_recv[j + 2];
577
578 for (auto &edge : localEdge)
579 {
580 // First check if inside the edge bounding box
581 if (!edge.second->MinMaxCheck(xs))
582 {
583 continue;
584 }
585
586 NekDouble dist = edge.second->FindDistance(xs, foundLocCoord);
587
589 {
590 m_foundRankCoords[m_rank][j / 3] = std::make_pair(
591 edge.second->GetGlobalID(), foundLocCoord);
592 break;
593 }
594 }
595 }
596 }
597}
std::map< int, std::map< int, std::pair< int, Array< OneD, NekDouble > > > > m_foundRankCoords
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.
static const NekDouble kFindDistanceMin
double NekDouble

References Nektar::NekConstants::kFindDistanceMin, m_foundRankCoords, m_interfaceTraces, m_rank, m_recv, and m_recvSize.

◆ FillRankBwdTraceExchange()

void Nektar::MultiRegions::InterfaceExchange::FillRankBwdTraceExchange ( Array< OneD, NekDouble > &  Bwd)

Loops over interfaces and partitions out the received trace from the other ranks for insertion into Bwd using FillRankBwdTrace

Parameters
BwdThe Bwd trace to be filled from across the interface

Definition at line 490 of file InterfaceMapDG.cpp.

491{
492 int cnt = 0;
493 for (int i = 0; i < m_interfaceTraces.size(); ++i)
494 {
495 Array<OneD, NekDouble> traceTmp(m_sendSize[m_rank][i] / 3, 0.0);
496 for (int j = 0; j < m_sendSize[m_rank][i] / 3; ++j, ++cnt)
497 {
498 traceTmp[j] = m_recvTrace[cnt];
499 }
500
501 m_interfaceTraces[i]->FillRankBwdTrace(traceTmp, Bwd);
502 }
503}
std::map< int, Array< OneD, int > > m_sendSize
Map of rank to array of size of send buffer for each interface.
Array< OneD, NekDouble > m_recvTrace
Receive buffer for trace exchange.

References m_interfaceTraces, m_rank, m_recvTrace, and m_sendSize.

◆ RankFillSizes()

void Nektar::MultiRegions::InterfaceExchange::RankFillSizes ( LibUtilities::CommRequestSharedPtr requestSend,
LibUtilities::CommRequestSharedPtr requestRecv,
int  requestNum 
)

Communicates with other ranks how many missing coordinates for each interface to expect

Parameters
requestSendList of send requests
requestRecvList of receive requests
requestNumIndex of request in list to use

Definition at line 347 of file InterfaceMapDG.cpp.

350{
351
352 // Recalc size is the number of interfaces missing points that need to be
353 // communicated.
354 int recalcSize = 0;
355 for (auto &localInterface : m_interfaceTraces)
356 {
357 recalcSize +=
358 m_zones[localInterface->GetInterface()->GetId()]->GetMoved();
359 }
360
361 m_sendSize[m_rank] = Array<OneD, int>(recalcSize);
362 m_recvSize[m_rank] = Array<OneD, int>(recalcSize);
363
364 int cnt = 0;
365 for (auto &interface : m_interfaceTraces)
366 {
367 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
368 {
369 // Calculates the number of missing coordinates to be communicated
370 // This size is 3 times the number of missing coordinates to allow
371 // for 3D points
372 m_sendSize[m_rank][cnt++] =
373 interface->GetMissingCoords().size() * 3;
374 }
375 }
376
377 // Uses non-blocking send/recvs to send communication sizes to other ranks
379 requestSend, requestNum);
381 requestRecv, requestNum);
382}

References m_comm, m_interfaceTraces, m_rank, m_recvSize, m_sendSize, and m_zones.

◆ SendFwdTrace()

void Nektar::MultiRegions::InterfaceExchange::SendFwdTrace ( LibUtilities::CommRequestSharedPtr requestSend,
LibUtilities::CommRequestSharedPtr requestRecv,
int  requestNum,
Array< OneD, NekDouble > &  Fwd 
)

Calculates and sends the trace to other rank from the m_foundRankCoords structure using non-blocking pairwise communication i.e. Isend & Irecv

Parameters
requestSendList of send requests
requestRecvList of receive requests
requestNumIndex of request in list to use
FwdThe values to send across the interface

Definition at line 517 of file InterfaceMapDG.cpp.

521{
523 Array<OneD, NekDouble>(m_totSendSize[m_rank] / 3, std::nan(""));
525 Array<OneD, NekDouble>(m_totRecvSize[m_rank] / 3, std::nan(""));
526
527 for (auto &i : m_foundRankCoords[m_rank])
528 {
529 int traceId = m_trace->GetElmtToExpId(i.second.first);
530 Array<OneD, NekDouble> locCoord = i.second.second;
531
532 Array<OneD, NekDouble> edgePhys =
533 Fwd + m_trace->GetPhys_Offset(traceId);
534
535 m_sendTrace[i.first] =
536 m_trace->GetExp(traceId)->StdPhysEvaluate(locCoord, edgePhys);
537 }
538
539 m_comm->Isend(m_rank, m_sendTrace, m_sendTrace.size(), requestSend,
540 requestNum);
541 m_comm->Irecv(m_rank, m_recvTrace, m_recvTrace.size(), requestRecv,
542 requestNum);
543}
std::map< int, int > m_totSendSize
Map of rank to total size of send buffer for all interfaces.
std::map< int, int > m_totRecvSize
Map of rank to total size of receive buffer for all interfaces.
Array< OneD, NekDouble > m_sendTrace
Send buffer for trace exchange.

References m_comm, m_foundRankCoords, m_rank, m_recvTrace, m_sendTrace, m_totRecvSize, m_totSendSize, and m_trace.

◆ SendMissing()

void Nektar::MultiRegions::InterfaceExchange::SendMissing ( LibUtilities::CommRequestSharedPtr requestSend,
LibUtilities::CommRequestSharedPtr requestRecv,
int  requestNum 
)

Sends/receives the missing coordinates to/from other ranks

Parameters
requestSendList of send requests
requestRecvList of receive requests
requestNumIndex of request in list to use

Definition at line 386 of file InterfaceMapDG.cpp.

389{
390 m_totSendSize[m_rank] = std::accumulate(m_sendSize[m_rank].begin(),
391 m_sendSize[m_rank].end(), 0);
392 m_totRecvSize[m_rank] = std::accumulate(m_recvSize[m_rank].begin(),
393 m_recvSize[m_rank].end(), 0);
394
395 m_send = Array<OneD, NekDouble>(m_totSendSize[m_rank]);
396 m_recv = Array<OneD, NekDouble>(m_totRecvSize[m_rank]);
397
398 int cnt = 0;
399 for (auto &interface : m_interfaceTraces)
400 {
401 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
402 {
403 auto missing = interface->GetMissingCoords();
404 for (auto coord : missing)
405 {
406 // Points are organised in blocks of three
407 // x coord, then y coord, then z coord.
408 for (int k = 0; k < 3; ++k, ++cnt)
409 {
410 m_send[cnt] = coord[k];
411 }
412 }
413 }
414 }
415
416 // Uses non-blocking send/recvs to send missing points to other ranks
417 m_comm->Isend(m_rank, m_send, m_totSendSize[m_rank], requestSend,
418 requestNum);
419 m_comm->Irecv(m_rank, m_recv, m_totRecvSize[m_rank], requestRecv,
420 requestNum);
421}
Array< OneD, NekDouble > m_send
Send buffer for coord exchange.

References m_comm, m_interfaceTraces, m_rank, m_recv, m_recvSize, m_send, m_sendSize, m_totRecvSize, m_totSendSize, and m_zones.

Member Data Documentation

◆ m_comm

const LibUtilities::CommSharedPtr Nektar::MultiRegions::InterfaceExchange::m_comm
private

Communicator.

Definition at line 183 of file InterfaceMapDG.h.

Referenced by RankFillSizes(), SendFwdTrace(), and SendMissing().

◆ m_foundRankCoords

std::map<int, std::map<int, std::pair<int, Array<OneD, NekDouble> > > > Nektar::MultiRegions::InterfaceExchange::m_foundRankCoords
private

Caches the found coordinates to reuse when exchanging the trace in a map of integer rank to a map of integer missing coordinate location to a pair of local edge ID and found local coordinate

Definition at line 211 of file InterfaceMapDG.h.

Referenced by CalcRankDistances(), and SendFwdTrace().

◆ m_interfaceTraces

const std::vector<InterfaceTraceSharedPtr> Nektar::MultiRegions::InterfaceExchange::m_interfaceTraces
private

Vector of interface traces i.e. every interface side present on m_rank.

Definition at line 187 of file InterfaceMapDG.h.

Referenced by CalcRankDistances(), FillRankBwdTraceExchange(), RankFillSizes(), and SendMissing().

◆ m_movement

SpatialDomains::MovementSharedPtr Nektar::MultiRegions::InterfaceExchange::m_movement
private

Movement object associated with the non-conformal interfaces.

Definition at line 177 of file InterfaceMapDG.h.

◆ m_rank

int Nektar::MultiRegions::InterfaceExchange::m_rank
private

Process rank.

Definition at line 185 of file InterfaceMapDG.h.

Referenced by CalcRankDistances(), FillRankBwdTraceExchange(), RankFillSizes(), SendFwdTrace(), and SendMissing().

◆ m_recv

Array<OneD, NekDouble> Nektar::MultiRegions::InterfaceExchange::m_recv
private

Receive buffer for coord exchange.

Definition at line 191 of file InterfaceMapDG.h.

Referenced by CalcRankDistances(), and SendMissing().

◆ m_recvSize

std::map<int, Array<OneD, int> > Nektar::MultiRegions::InterfaceExchange::m_recvSize
private

Map of rank to array of size of receive buffer for each interface.

Definition at line 203 of file InterfaceMapDG.h.

Referenced by CalcRankDistances(), RankFillSizes(), and SendMissing().

◆ m_recvTrace

Array<OneD, NekDouble> Nektar::MultiRegions::InterfaceExchange::m_recvTrace
private

Receive buffer for trace exchange.

Definition at line 193 of file InterfaceMapDG.h.

Referenced by FillRankBwdTraceExchange(), and SendFwdTrace().

◆ m_send

Array<OneD, NekDouble> Nektar::MultiRegions::InterfaceExchange::m_send
private

Send buffer for coord exchange.

Definition at line 189 of file InterfaceMapDG.h.

Referenced by SendMissing().

◆ m_sendSize

std::map<int, Array<OneD, int> > Nektar::MultiRegions::InterfaceExchange::m_sendSize
private

Map of rank to array of size of send buffer for each interface.

Definition at line 201 of file InterfaceMapDG.h.

Referenced by FillRankBwdTraceExchange(), RankFillSizes(), and SendMissing().

◆ m_sendTrace

Array<OneD, NekDouble> Nektar::MultiRegions::InterfaceExchange::m_sendTrace
private

Send buffer for trace exchange.

Definition at line 195 of file InterfaceMapDG.h.

Referenced by SendFwdTrace().

◆ m_totRecvSize

std::map<int, int> Nektar::MultiRegions::InterfaceExchange::m_totRecvSize
private

Map of rank to total size of receive buffer for all interfaces.

Definition at line 199 of file InterfaceMapDG.h.

Referenced by SendFwdTrace(), and SendMissing().

◆ m_totSendSize

std::map<int, int> Nektar::MultiRegions::InterfaceExchange::m_totSendSize
private

Map of rank to total size of send buffer for all interfaces.

Definition at line 197 of file InterfaceMapDG.h.

Referenced by SendFwdTrace(), and SendMissing().

◆ m_trace

const ExpListSharedPtr Nektar::MultiRegions::InterfaceExchange::m_trace
private

Trace expansion list.

Definition at line 181 of file InterfaceMapDG.h.

Referenced by SendFwdTrace().

◆ m_zones

std::map<int, SpatialDomains::ZoneBaseShPtr> Nektar::MultiRegions::InterfaceExchange::m_zones
private

Map of zone IDs to zone bases.

Definition at line 179 of file InterfaceMapDG.h.

Referenced by RankFillSizes(), and SendMissing().