Nektar++
Loading...
Searching...
No Matches
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.
 
 InterfaceExchange (SpatialDomains::MovementSharedPtr movement, const ExpListSharedPtr &trace, const LibUtilities::CommSharedPtr &comm, std::pair< int, std::vector< InterfaceTraceSharedPtr > > rankPair)
 Constructor.
 
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.
 
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.
 
std::map< int, SpatialDomains::ZoneBaseShPtrm_zones
 Map of zone IDs to zone bases.
 
const ExpListSharedPtr m_trace
 Trace expansion list.
 
const LibUtilities::CommSharedPtr m_comm
 Communicator.
 
int m_rank
 Process rank.
 
const std::vector< InterfaceTraceSharedPtrm_interfaceTraces
 Vector of interface traces i.e. every interface side present on m_rank.
 
Array< OneD, NekDoublem_send
 Send buffer for coord exchange.
 
Array< OneD, NekDoublem_recv
 Receive buffer for coord exchange.
 
Array< OneD, NekDoublem_recvTrace
 Receive buffer for trace exchange.
 
Array< OneD, NekDoublem_sendTrace
 Send buffer for trace exchange.
 
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.
 
std::map< int, Array< OneD, int > > m_sendSize
 Map of rank to array of size of send buffer for each interface.
 
std::map< int, Array< OneD, int > > m_recvSize
 Map of rank to array of size of receive buffer for each interface.
 
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 136 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 143 of file InterfaceMapDG.h.

147 : m_movement(movement), m_zones(movement->GetZones()), m_trace(trace),
148 m_comm(comm), m_rank(rankPair.first),
149 m_interfaceTraces(rankPair.second)
150 {
151 }
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 741 of file InterfaceMapDG.cpp.

742{
743 // Clear old found coordinates
744 auto foundRankCoordsCopy = m_foundRankCoords[m_rank];
746 .clear(); // @TODO: This may cause problems with 2 interfaces and one is
747 // fixed? With the skip below.
748
749 Array<OneD, int> disp(m_recvSize[m_rank].size() + 1, 0.0);
750 std::partial_sum(m_recvSize[m_rank].begin(), m_recvSize[m_rank].end(),
751 &disp[1]);
752
753 for (int i = 0; i < m_interfaceTraces.size(); ++i)
754 {
755 if (!m_zones[m_interfaceTraces[i]->GetInterface()->GetId()]->GetMoved())
756 {
757 // If zone is not moved then skip
758 continue;
759 }
760
761 auto localEdge = m_interfaceTraces[i]->GetInterface()->GetEdge();
762
763 for (int j = disp[i]; j < disp[i + 1]; j += 3)
764 {
765 Array<OneD, NekDouble> foundLocCoord;
766 Array<OneD, NekDouble> xs(3);
767 xs[0] = m_recv[j];
768 xs[1] = m_recv[j + 1];
769 xs[2] = m_recv[j + 2];
770
771 // First search the edge the point was found in last timestep
772 if ((foundRankCoordsCopy.find(j / 3) !=
773 foundRankCoordsCopy.end()) &&
774 (foundRankCoordsCopy[j / 3].first.first == i))
775 {
776 auto edge = m_interfaceTraces[i]->GetInterface()->GetEdge(
777 foundRankCoordsCopy[j / 3].first.second);
778 NekDouble dist = edge->FindDistance(xs, foundLocCoord);
779
781 {
782 m_foundRankCoords[m_rank][j / 3] = std::make_pair(
783 std::make_pair(i, edge->GetGlobalID()), foundLocCoord);
784 continue;
785 }
786 }
787
788 for (auto &edge : localEdge)
789 {
790 // First check if inside the edge bounding box
791 if (!edge.second->MinMaxCheck(xs))
792 {
793 continue;
794 }
795
796 NekDouble dist = edge.second->FindDistance(xs, foundLocCoord);
797
799 {
800 m_foundRankCoords[m_rank][j / 3] = std::make_pair(
801 std::make_pair(i, edge.second->GetGlobalID()),
802 foundLocCoord);
803 break;
804 }
805 }
806 }
807 }
808}
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

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

672{
673 int cnt = 0;
674 for (int i = 0; i < m_interfaceTraces.size(); ++i)
675 {
676 Array<OneD, NekDouble> traceTmp(m_sendSize[m_rank][i] / 3, 0.0);
677 for (int j = 0; j < m_sendSize[m_rank][i] / 3; ++j, ++cnt)
678 {
679 traceTmp[j] = m_recvTrace[cnt];
680 }
681
682 m_interfaceTraces[i]->FillRankBwdTrace(traceTmp, Bwd);
683 }
684}
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 420 of file InterfaceMapDG.cpp.

423{
424
425 // Recalc size is the number of interfaces missing points that need to be
426 // communicated.
427 int recalcSize = 0;
428 for (auto &localInterface : m_interfaceTraces)
429 {
430 recalcSize +=
431 m_zones[localInterface->GetInterface()->GetId()]->GetMoved();
432 }
433
434 m_sendSize[m_rank] = Array<OneD, int>(recalcSize);
435 m_recvSize[m_rank] = Array<OneD, int>(recalcSize);
436
437 int cnt = 0;
438 for (auto &interface : m_interfaceTraces)
439 {
440 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
441 {
442 // Calculates the number of missing coordinates to be communicated
443 // This size is 3 times the number of missing coordinates to allow
444 // for 3D points
445 m_sendSize[m_rank][cnt++] =
446 interface->GetMissingCoords().size() * 3;
447 }
448 }
449
450 // Uses non-blocking send/recvs to send communication sizes to other ranks
452 requestSend, requestNum);
454 requestRecv, requestNum);
455}

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

702{
704 Array<OneD, NekDouble>(m_totSendSize[m_rank] / 3, std::nan(""));
706 Array<OneD, NekDouble>(m_totRecvSize[m_rank] / 3, std::nan(""));
707
708 for (auto &i : m_foundRankCoords[m_rank])
709 {
710 int traceId = m_trace->GetElmtToExpId(i.second.first.second);
711 Array<OneD, NekDouble> locCoord = i.second.second;
712
713 Array<OneD, NekDouble> edgePhys =
714 Fwd + m_trace->GetPhys_Offset(traceId);
715
716 m_sendTrace[i.first] =
717 m_trace->GetExp(traceId)->StdPhysEvaluate(locCoord, edgePhys);
718 }
719
720 m_comm->Isend(m_rank, m_sendTrace, m_sendTrace.size(), requestSend,
721 requestNum);
722 m_comm->Irecv(m_rank, m_recvTrace, m_recvTrace.size(), requestRecv,
723 requestNum);
724}
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 459 of file InterfaceMapDG.cpp.

462{
463 m_totSendSize[m_rank] = std::accumulate(m_sendSize[m_rank].begin(),
464 m_sendSize[m_rank].end(), 0);
465 m_totRecvSize[m_rank] = std::accumulate(m_recvSize[m_rank].begin(),
466 m_recvSize[m_rank].end(), 0);
467
468 m_send = Array<OneD, NekDouble>(m_totSendSize[m_rank]);
469 m_recv = Array<OneD, NekDouble>(m_totRecvSize[m_rank]);
470
471 int cnt = 0;
472 for (auto &interface : m_interfaceTraces)
473 {
474 if (m_zones[interface->GetInterface()->GetId()]->GetMoved())
475 {
476 auto missing = interface->GetMissingCoords();
477 for (auto coord : missing)
478 {
479 // Points are organised in blocks of three
480 // x coord, then y coord, then z coord.
481 for (int k = 0; k < 3; ++k, ++cnt)
482 {
483 m_send[cnt] = coord[k];
484 }
485 }
486 }
487 }
488
489 // Uses non-blocking send/recvs to send missing points to other ranks
490 m_comm->Isend(m_rank, m_send, m_totSendSize[m_rank], requestSend,
491 requestNum);
492 m_comm->Irecv(m_rank, m_recv, m_totRecvSize[m_rank], requestRecv,
493 requestNum);
494}
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 210 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 240 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 214 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 204 of file InterfaceMapDG.h.

◆ m_rank

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

Process rank.

Definition at line 212 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 218 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 230 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 220 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 216 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 228 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 222 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 226 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 224 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 208 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 206 of file InterfaceMapDG.h.

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