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< std::pair< int, 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 112 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 119 of file InterfaceMapDG.h.

123 : m_movement(movement), m_zones(movement->GetZones()), m_trace(trace),
124 m_comm(comm), m_rank(rankPair.first),
125 m_interfaceTraces(rankPair.second)
126 {
127 }
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 621 of file InterfaceMapDG.cpp.

622{
623 // Clear old found coordinates
624 auto foundRankCoordsCopy = m_foundRankCoords[m_rank];
626 .clear(); // @TODO: This may cause problems with 2 interfaces and one is
627 // fixed? With the skip below.
628
629 Array<OneD, int> disp(m_recvSize[m_rank].size() + 1, 0.0);
630 std::partial_sum(m_recvSize[m_rank].begin(), m_recvSize[m_rank].end(),
631 &disp[1]);
632
633 for (int i = 0; i < m_interfaceTraces.size(); ++i)
634 {
635 if (!m_zones[m_interfaceTraces[i]->GetInterface()->GetId()]->GetMoved())
636 {
637 // If zone is not moved then skip
638 continue;
639 }
640
641 auto localEdge = m_interfaceTraces[i]->GetInterface()->GetEdge();
642
643 for (int j = disp[i]; j < disp[i + 1]; j += 3)
644 {
645 Array<OneD, NekDouble> foundLocCoord;
646 Array<OneD, NekDouble> xs(3);
647 xs[0] = m_recv[j];
648 xs[1] = m_recv[j + 1];
649 xs[2] = m_recv[j + 2];
650
651 // First search the edge the point was found in last timestep
652 if ((foundRankCoordsCopy.find(j / 3) !=
653 foundRankCoordsCopy.end()) &&
654 (foundRankCoordsCopy[j / 3].first.first == i))
655 {
656 auto edge = m_interfaceTraces[i]->GetInterface()->GetEdge(
657 foundRankCoordsCopy[j / 3].first.second);
658 NekDouble dist = edge->FindDistance(xs, foundLocCoord);
659
661 {
662 m_foundRankCoords[m_rank][j / 3] = std::make_pair(
663 std::make_pair(i, edge->GetGlobalID()), foundLocCoord);
664 continue;
665 }
666 }
667
668 for (auto &edge : localEdge)
669 {
670 // First check if inside the edge bounding box
671 if (!edge.second->MinMaxCheck(xs))
672 {
673 continue;
674 }
675
676 NekDouble dist = edge.second->FindDistance(xs, foundLocCoord);
677
679 {
680 m_foundRankCoords[m_rank][j / 3] = std::make_pair(
681 std::make_pair(i, edge.second->GetGlobalID()),
682 foundLocCoord);
683 break;
684 }
685 }
686 }
687 }
688}
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.
std::map< int, std::map< int, std::pair< std::pair< int, int >, Array< OneD, NekDouble > > > > m_foundRankCoords
static const NekDouble kFindDistanceMin
double NekDouble

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

◆ 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 551 of file InterfaceMapDG.cpp.

552{
553 int cnt = 0;
554 for (int i = 0; i < m_interfaceTraces.size(); ++i)
555 {
556 Array<OneD, NekDouble> traceTmp(m_sendSize[m_rank][i] / 3, 0.0);
557 for (int j = 0; j < m_sendSize[m_rank][i] / 3; ++j, ++cnt)
558 {
559 traceTmp[j] = m_recvTrace[cnt];
560 }
561
562 m_interfaceTraces[i]->FillRankBwdTrace(traceTmp, Bwd);
563 }
564}
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 404 of file InterfaceMapDG.cpp.

407{
408
409 // Recalc size is the number of interfaces missing points that need to be
410 // communicated.
411 int recalcSize = 0;
412 for (auto &localInterface : m_interfaceTraces)
413 {
414 recalcSize +=
415 m_zones[localInterface->GetInterface()->GetId()]->GetMoved();
416 }
417
418 m_sendSize[m_rank] = Array<OneD, int>(recalcSize);
419 m_recvSize[m_rank] = Array<OneD, int>(recalcSize);
420
421 int cnt = 0;
422 for (auto &interface : m_interfaceTraces)
423 {
424 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
425 {
426 // Calculates the number of missing coordinates to be communicated
427 // This size is 3 times the number of missing coordinates to allow
428 // for 3D points
429 m_sendSize[m_rank][cnt++] =
430 interface->GetMissingCoords().size() * 3;
431 }
432 }
433
434 // Uses non-blocking send/recvs to send communication sizes to other ranks
436 requestSend, requestNum);
438 requestRecv, requestNum);
439}

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 578 of file InterfaceMapDG.cpp.

582{
584 Array<OneD, NekDouble>(m_totSendSize[m_rank] / 3, std::nan(""));
586 Array<OneD, NekDouble>(m_totRecvSize[m_rank] / 3, std::nan(""));
587
588 for (auto &i : m_foundRankCoords[m_rank])
589 {
590 int traceId = m_trace->GetElmtToExpId(i.second.first.second);
591 Array<OneD, NekDouble> locCoord = i.second.second;
592
593 Array<OneD, NekDouble> edgePhys =
594 Fwd + m_trace->GetPhys_Offset(traceId);
595
596 m_sendTrace[i.first] =
597 m_trace->GetExp(traceId)->StdPhysEvaluate(locCoord, edgePhys);
598 }
599
600 m_comm->Isend(m_rank, m_sendTrace, m_sendTrace.size(), requestSend,
601 requestNum);
602 m_comm->Irecv(m_rank, m_recvTrace, m_recvTrace.size(), requestRecv,
603 requestNum);
604}
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 443 of file InterfaceMapDG.cpp.

446{
447 m_totSendSize[m_rank] = std::accumulate(m_sendSize[m_rank].begin(),
448 m_sendSize[m_rank].end(), 0);
449 m_totRecvSize[m_rank] = std::accumulate(m_recvSize[m_rank].begin(),
450 m_recvSize[m_rank].end(), 0);
451
452 m_send = Array<OneD, NekDouble>(m_totSendSize[m_rank]);
453 m_recv = Array<OneD, NekDouble>(m_totRecvSize[m_rank]);
454
455 int cnt = 0;
456 for (auto &interface : m_interfaceTraces)
457 {
458 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
459 {
460 auto missing = interface->GetMissingCoords();
461 for (auto coord : missing)
462 {
463 // Points are organised in blocks of three
464 // x coord, then y coord, then z coord.
465 for (int k = 0; k < 3; ++k, ++cnt)
466 {
467 m_send[cnt] = coord[k];
468 }
469 }
470 }
471 }
472
473 // Uses non-blocking send/recvs to send missing points to other ranks
474 m_comm->Isend(m_rank, m_send, m_totSendSize[m_rank], requestSend,
475 requestNum);
476 m_comm->Irecv(m_rank, m_recv, m_totRecvSize[m_rank], requestRecv,
477 requestNum);
478}
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 186 of file InterfaceMapDG.h.

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

◆ m_foundRankCoords

std::map< int, std::map<int, std::pair<std::pair<int, 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 216 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 190 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 180 of file InterfaceMapDG.h.

◆ m_rank

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

Process rank.

Definition at line 188 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 194 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 206 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 196 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 192 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 204 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 198 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 202 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 200 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 184 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 182 of file InterfaceMapDG.h.

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