remote: Centralised class to replace patchToPatch::procFace

This commit is contained in:
Will Bainbridge
2022-10-07 13:54:30 +01:00
parent bad5bd0bbe
commit 9e9ab2204c
15 changed files with 247 additions and 107 deletions

View File

@ -36,8 +36,7 @@ SourceFiles
#ifndef RemoteData_H
#define RemoteData_H
#include "Istream.H"
#include "Ostream.H"
#include "remote.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -62,17 +61,13 @@ inline Ostream& operator<<(Ostream&, const RemoteData<Type>&);
template<class Type>
class RemoteData
:
public remote
{
public:
// Public Data
//- Processor index
label proci;
//- Element index
label elementi;
//- Data
Type data;

View File

@ -30,8 +30,7 @@ License
template<class Type>
inline Foam::RemoteData<Type>::RemoteData()
:
proci(-1),
elementi(-1),
remote(),
data()
{}
@ -44,8 +43,7 @@ inline Foam::RemoteData<Type>::RemoteData
const Type& d
)
:
proci(p),
elementi(e),
remote(p, e),
data(d)
{}
@ -111,9 +109,8 @@ inline bool Foam::operator==
)
{
return
a.proci == b.proci
&& a.elementi == b.elementi
&& a.data == b.data;
static_cast<const remote&>(a) == static_cast<const remote&>(b)
&& a.data == b.data;
}
@ -133,17 +130,14 @@ inline bool Foam::operator!=
template<class Type>
inline Foam::Ostream& Foam::operator<<(Ostream& os, const RemoteData<Type>& p)
{
return os
<< p.proci << token::SPACE
<< p.elementi << token::SPACE
<< p.data;
return os << static_cast<const remote&>(p) << token::SPACE << p.data;
}
template<class Type>
inline Foam::Istream& Foam::operator>>(Istream& is, RemoteData<Type>& p)
{
return is >> p.proci >> p.elementi >> p.data;
return is >> static_cast<remote&>(p) >> p.data;
}

View File

@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::remote
Description
Struct for keeping processor, element (cell, face, point) index.
SourceFiles
remoteI.H
\*---------------------------------------------------------------------------*/
#ifndef remote_H
#define remote_H
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
class remote;
inline bool operator==(const remote&, const remote&);
inline bool operator!=(const remote&, const remote&);
inline Istream& operator>>(Istream&, remote&);
inline Ostream& operator<<(Ostream&, const remote&);
/*---------------------------------------------------------------------------*\
Class remote Declaration
\*---------------------------------------------------------------------------*/
class remote
{
public:
// Public Data
//- Processor index
label proci;
//- Element index
label elementi;
// Constructors
//- Construct null
inline remote();
//- Construct from components
inline remote(const label, const label);
//- Construct from stream
inline remote(Istream& is);
// Friend Operators
//- Equality comparison
friend bool operator==(const remote& a, const remote& b);
//- Inequality comparison
friend bool operator!=(const remote& a, const remote& b);
// IOstream Operators
//- Write to stream
friend Ostream& operator<<(Ostream& os, const remote& p);
//- Read from stream
friend Istream& operator>>(Istream& is, remote& p);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "remoteI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,78 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "remote.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::remote::remote()
:
proci(-1),
elementi(-1)
{}
inline Foam::remote::remote(const label p, const label e)
:
proci(p),
elementi(e)
{}
inline Foam::remote::remote(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
inline bool Foam::operator==(const remote& a, const remote& b)
{
return a.proci == b.proci && a.elementi == b.elementi;
}
inline bool Foam::operator!=(const remote& a, const remote& b)
{
return !(a == b);
}
// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
inline Foam::Ostream& Foam::operator<<(Ostream& os, const remote& p)
{
return os << p.proci << token::SPACE << p.elementi;
}
inline Foam::Istream& Foam::operator>>(Istream& is, remote& p)
{
return is >> p.proci >> p.elementi;
}
// ************************************************************************* //

View File

@ -120,7 +120,7 @@ void Foam::fvMeshStitcher::intersectNonConformalCyclic
// non-conformal interfaces are ordered.
auto procFacesToIndices = []
(
const List<List<patchToPatch::procFace>>& faceOtherProcFaces,
const List<List<remote>>& faceOtherProcFaces,
const bool owner
)
{
@ -130,8 +130,7 @@ void Foam::fvMeshStitcher::intersectNonConformalCyclic
{
forAll(faceOtherProcFaces[facei], i)
{
const patchToPatch::procFace& otherProcFacei =
faceOtherProcFaces[facei][i];
const remote& otherProcFacei = faceOtherProcFaces[facei][i];
is[otherProcFacei.proci] ++;
}
@ -150,13 +149,12 @@ void Foam::fvMeshStitcher::intersectNonConformalCyclic
{
forAll(faceOtherProcFaces[facei], i)
{
const patchToPatch::procFace& otherProcFacei =
faceOtherProcFaces[facei][i];
const remote& otherProcFacei = faceOtherProcFaces[facei][i];
FixedList<label, 3>& index =
indices[otherProcFacei.proci][is[otherProcFacei.proci] ++];
index = {facei, otherProcFacei.facei, i};
index = {facei, otherProcFacei.elementi, i};
if (!owner) Swap(index[0], index[1]);
}

View File

@ -295,7 +295,7 @@ bool Foam::particle::hitNonConformalCyclicPatch
// Project the particle through the non-conformal patch
point receivePos;
const patchToPatch::procFace receiveProcFace =
const remote receiveProcFace =
nccpp.ray
(
stepFractionSpan(td.mesh)[0]
@ -318,7 +318,7 @@ bool Foam::particle::hitNonConformalCyclicPatch
td.sendFromPatch = nccpp.index();
td.sendToProc = receiveProcFace.proci;
td.sendToPatch = nccpp.nbrPatchID();
td.sendToPatchFace = receiveProcFace.facei;
td.sendToPatchFace = receiveProcFace.elementi;
return true;
}
@ -328,7 +328,7 @@ bool Foam::particle::hitNonConformalCyclicPatch
(
td.mesh,
nccpp.index(),
receiveProcFace.facei
receiveProcFace.elementi
);
correctAfterNonConformalCyclicTransfer
(

View File

@ -318,7 +318,7 @@ Foam::nonConformalCyclicPolyPatch::rays() const
}
Foam::patchToPatch::procFace Foam::nonConformalCyclicPolyPatch::ray
Foam::remote Foam::nonConformalCyclicPolyPatch::ray
(
const scalar fraction,
const label origFacei,

View File

@ -227,7 +227,7 @@ public:
const patchToPatches::rays& rays() const;
//- Compute a ray intersection across the coupling
patchToPatch::procFace ray
remote ray
(
const scalar fraction,
const label origFacei,

View File

@ -161,14 +161,14 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::List<Foam::List<Foam::patchToPatch::procFace>>
Foam::List<Foam::List<Foam::remote>>
Foam::patchToPatch::localFacesToProcFaces
(
const List<DynamicList<label>>& localFaces,
const List<procFace>& map
const List<remote>& map
)
{
List<List<procFace>> result(localFaces.size());
List<List<remote>> result(localFaces.size());
forAll(localFaces, thisFacei)
{
@ -178,7 +178,7 @@ Foam::patchToPatch::localFacesToProcFaces
{
result[thisFacei][i] =
isNull(map)
? procFace({Pstream::myProcNo(), localFaces[thisFacei][i]})
? remote({Pstream::myProcNo(), localFaces[thisFacei][i]})
: map[localFaces[thisFacei][i]];
}
}
@ -190,8 +190,8 @@ Foam::patchToPatch::localFacesToProcFaces
Foam::List<Foam::DynamicList<Foam::label>>
Foam::patchToPatch::procFacesToLocalFaces
(
const List<List<procFace>>& procFaces,
const HashTable<label, procFace, Hash<procFace>>& map
const List<List<remote>>& procFaces,
const HashTable<label, remote, Hash<remote>>& map
)
{
List<DynamicList<label>> result(procFaces.size());
@ -204,7 +204,7 @@ Foam::patchToPatch::procFacesToLocalFaces
{
result[tgtFacei][i] =
isNull(map)
? procFaces[tgtFacei][i].facei
? procFaces[tgtFacei][i].elementi
: map[procFaces[tgtFacei][i]];
}
}
@ -816,7 +816,7 @@ Foam::labelList Foam::patchToPatch::subsetLocalTgt
tgtLocalSrcFaces_ =
List<DynamicList<label>>(tgtLocalSrcFaces_, newToOldLocalTgtFace);
localTgtProcFacesPtr_() =
List<procFace>(localTgtProcFacesPtr_(), newToOldLocalTgtFace);
List<remote>(localTgtProcFacesPtr_(), newToOldLocalTgtFace);
return newToOldLocalTgtFace;
}
@ -834,7 +834,7 @@ void Foam::patchToPatch::distributeSrc
void Foam::patchToPatch::rDistributeTgt(const primitiveOldTimePatch& tgtPatch)
{
// Create a map from source procFace to local source face
HashTable<label, procFace, Hash<procFace>> srcProcFaceToLocal;
HashTable<label, remote, Hash<remote>> srcProcFaceToLocal;
forAll(localSrcProcFacesPtr_(), localSrcFacei)
{
srcProcFaceToLocal.insert
@ -846,7 +846,7 @@ void Foam::patchToPatch::rDistributeTgt(const primitiveOldTimePatch& tgtPatch)
// Collect the source procFaces on the target and convert to local
// source face addressing
List<List<procFace>> tgtSrcProcFaces =
List<List<remote>> tgtSrcProcFaces =
localFacesToProcFaces(tgtLocalSrcFaces_);
rDistributeListList(tgtPatch.size(), tgtMapPtr_(), tgtSrcProcFaces);
@ -892,8 +892,8 @@ Foam::patchToPatch::patchToPatch(const bool reverse)
tgtLocalSrcFaces_(),
srcMapPtr_(nullptr),
tgtMapPtr_(nullptr),
localSrcProcFacesPtr_(new List<procFace>()),
localTgtProcFacesPtr_(new List<procFace>())
localSrcProcFacesPtr_(new List<remote>()),
localTgtProcFacesPtr_(new List<remote>())
{}

View File

@ -39,6 +39,7 @@ SourceFiles
#include "distributionMap.H"
#include "primitivePatch.H"
#include "primitiveOldTimePatch.H"
#include "remote.H"
#include "runTimeSelectionTables.H"
#include "treeBoundBox.H"
@ -53,45 +54,6 @@ namespace Foam
class patchToPatch
{
public:
// Public Structures
//- Structure to conveniently store processor and face indices
struct procFace
{
//- The processor index
label proci;
//- The face index
label facei;
//- Equality comparison
friend bool operator==(const procFace& a, const procFace& b)
{
return a.proci == b.proci && a.facei == b.facei;
}
//- Inequality comparison
friend bool operator!=(const procFace& a, const procFace& b)
{
return !(a == b);
}
//- Output stream operator
friend Ostream& operator<<(Ostream& os, const procFace& p)
{
return os << p.proci << token::SPACE << p.facei;
}
//- Input stream operator
friend Istream& operator>>(Istream& is, procFace& p)
{
return is >> p.proci >> p.facei;
}
};
protected:
// Private Data
@ -118,11 +80,11 @@ protected:
//- When running in parallel, a map from local source face index to
// source processor and face index
autoPtr<List<procFace>> localSrcProcFacesPtr_;
autoPtr<List<remote>> localSrcProcFacesPtr_;
//- When running in parallel, a map from local target face index to
// target processor and face index
autoPtr<List<procFace>> localTgtProcFacesPtr_;
autoPtr<List<remote>> localTgtProcFacesPtr_;
// Private Member Functions
@ -156,17 +118,17 @@ protected:
);
//- Map local faces to proc faces
static List<List<procFace>> localFacesToProcFaces
static List<List<remote>> localFacesToProcFaces
(
const List<DynamicList<label>>& localFaces,
const List<procFace>& map = NullObjectRef<List<procFace>>()
const List<remote>& map = NullObjectRef<List<remote>>()
);
//- Map proc faces to local faces
static List<DynamicList<label>> procFacesToLocalFaces
(
const List<List<procFace>>& procFaces,
const HashTable<label, procFace, Hash<procFace>>& map
const List<List<remote>>& procFaces,
const HashTable<label, remote, Hash<remote>>& map
);
@ -301,7 +263,7 @@ protected:
(
const distributionMap& map,
const primitiveOldTimePatch& patch,
List<procFace>& localProcFaces
List<remote>& localProcFaces
) const;
//- As above, but when you want the proc-faces without the
@ -309,7 +271,7 @@ protected:
void distributePatch
(
const distributionMap& map,
List<procFace>& localProcFaces
List<remote>& localProcFaces
) const;
@ -441,10 +403,10 @@ public:
inline bool isSingleProcess() const;
//- For each source face, the coupled target procs and faces
inline List<List<procFace>> srcTgtProcFaces() const;
inline List<List<remote>> srcTgtProcFaces() const;
//- For each target face, the coupled source procs and faces
inline List<List<procFace>> tgtSrcProcFaces() const;
inline List<List<remote>> tgtSrcProcFaces() const;
// Interpolation

View File

@ -102,7 +102,7 @@ inline bool Foam::patchToPatch::isSingleProcess() const
}
inline Foam::List<Foam::List<Foam::patchToPatch::procFace>>
inline Foam::List<Foam::List<Foam::remote>>
Foam::patchToPatch::srcTgtProcFaces() const
{
return
@ -112,7 +112,7 @@ Foam::patchToPatch::srcTgtProcFaces() const
}
inline Foam::List<Foam::List<Foam::patchToPatch::procFace>>
inline Foam::List<Foam::List<Foam::remote>>
Foam::patchToPatch::tgtSrcProcFaces() const
{
return

View File

@ -222,7 +222,7 @@ Foam::patchToPatch::distributePatch
(
const distributionMap& map,
const primitiveOldTimePatch& patch,
List<procFace>& localProcFaces
List<remote>& localProcFaces
) const
{
static const label thisProci = Pstream::myProcNo();
@ -387,7 +387,7 @@ Foam::patchToPatch::distributePatch
void Foam::patchToPatch::distributePatch
(
const distributionMap& map,
List<procFace>& localProcFaces
List<remote>& localProcFaces
) const
{
static const label thisProci = Pstream::myProcNo();

View File

@ -165,12 +165,12 @@ Foam::label Foam::patchToPatches::rays::finalise
}
Foam::patchToPatch::procFace Foam::patchToPatches::rays::ray
Foam::remote Foam::patchToPatches::rays::ray
(
const primitiveOldTimePatch& outPatch,
const autoPtr<PrimitiveOldTimePatch<faceList, pointField>>&
localOutPatchPtr,
const autoPtr<List<procFace>>& localOutProcFacesPtr,
const autoPtr<List<remote>>& localOutProcFacesPtr,
const List<DynamicList<label>>& inLocalOutFaces,
const scalar fraction,
const label inFacei,
@ -213,12 +213,12 @@ Foam::patchToPatch::procFace Foam::patchToPatches::rays::ray
return
isSingleProcess()
? procFace({Pstream::myProcNo(), localOutFacei})
? remote({Pstream::myProcNo(), localOutFacei})
: localOutProcFacesPtr()[localOutFacei];
}
}
return procFace({-1, -1});
return remote({-1, -1});
}
@ -257,7 +257,7 @@ Foam::patchToPatches::rays::~rays()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::patchToPatch::procFace Foam::patchToPatches::rays::srcToTgtRay
Foam::remote Foam::patchToPatches::rays::srcToTgtRay
(
const primitiveOldTimePatch& tgtPatch,
const scalar fraction,
@ -283,7 +283,7 @@ Foam::patchToPatch::procFace Foam::patchToPatches::rays::srcToTgtRay
}
Foam::patchToPatch::procFace Foam::patchToPatches::rays::tgtToSrcRay
Foam::remote Foam::patchToPatches::rays::tgtToSrcRay
(
const primitiveOldTimePatch& srcPatch,
const scalar fraction,

View File

@ -114,12 +114,12 @@ class rays
);
//- Compute a ray intersection
procFace ray
remote ray
(
const primitiveOldTimePatch& outPatch,
const autoPtr<PrimitiveOldTimePatch<faceList, pointField>>&
localOutPatchPtr,
const autoPtr<List<procFace>>& localOutProcFacesPtr,
const autoPtr<List<remote>>& localOutProcFacesPtr,
const List<DynamicList<label>>& inLocalOutFacesPtr,
const scalar fraction,
const label inFacei,
@ -154,7 +154,7 @@ public:
// Member Functions
//- Compute a ray intersection from the source side to the target
procFace srcToTgtRay
remote srcToTgtRay
(
const primitiveOldTimePatch& tgtPatch,
const scalar fraction,
@ -165,7 +165,7 @@ public:
) const;
//- Compute a ray intersection from the target side to the source
procFace tgtToSrcRay
remote tgtToSrcRay
(
const primitiveOldTimePatch& srcPatch,
const scalar fraction,

View File

@ -93,7 +93,7 @@ public:
size_(-1),
hasUnmapped_(false)
{
const List<List<patchToPatch::procFace>> procFaces =
const List<List<remote>> procFaces =
forward_ ? pToP_.tgtSrcProcFaces() : pToP_.srcTgtProcFaces();
size_ = procFaces.size();