ENH: collective for boundary connections, makes lduAddressing const

- top-level faceCells() on the boundary list simplifies the creation
  of lduAddressing etc, can also be useful on its own

STYLE: replace isA/refCast combination with a single isA
This commit is contained in:
Mark Olesen
2021-10-04 09:51:55 +02:00
parent 674a9a878f
commit 6a3f918827
16 changed files with 181 additions and 127 deletions

View File

@ -504,24 +504,20 @@ template<class Type, template<class> class PatchField, class GeoMesh>
Foam::LduInterfaceFieldPtrsList<Type>
Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary::interfaces() const
{
LduInterfaceFieldPtrsList<Type> interfaces(this->size());
LduInterfaceFieldPtrsList<Type> list(this->size());
forAll(interfaces, patchi)
forAll(list, patchi)
{
if (isA<LduInterfaceField<Type>>(this->operator[](patchi)))
const LduInterfaceField<Type>* lduPtr =
isA<LduInterfaceField<Type>>(this->operator[](patchi));
if (lduPtr)
{
interfaces.set
(
patchi,
&refCast<const LduInterfaceField<Type>>
(
this->operator[](patchi)
)
);
list.set(patchi, lduPtr);
}
}
return interfaces;
return list;
}
@ -530,24 +526,20 @@ Foam::lduInterfaceFieldPtrsList
Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary::
scalarInterfaces() const
{
lduInterfaceFieldPtrsList interfaces(this->size());
lduInterfaceFieldPtrsList list(this->size());
forAll(interfaces, patchi)
forAll(list, patchi)
{
if (isA<lduInterfaceField>(this->operator[](patchi)))
const lduInterfaceField* lduPtr =
isA<lduInterfaceField>(this->operator[](patchi));
if (lduPtr)
{
interfaces.set
(
patchi,
&refCast<const lduInterfaceField>
(
this->operator[](patchi)
)
);
list.set(patchi, lduPtr);
}
}
return interfaces;
return list;
}

View File

@ -114,7 +114,7 @@ namespace Foam
class lduAddressing
{
// Private data
// Private Data
//- Number of equations
label size_;
@ -186,7 +186,7 @@ public:
const label patchNo
) const = 0;
// Return patch field evaluation schedule
//- Return patch field evaluation schedule
virtual const lduSchedule& patchSchedule() const = 0;
//- Clear additional addressing

View File

@ -123,12 +123,18 @@ public:
//- Check for default constructed or global sum == 0
inline bool empty() const;
//- The number of processors covered by the offsets
inline label nProcs() const noexcept;
//- Global sum of localSizes
inline label size() const;
//- The local sizes
labelList sizes() const;
//- The local starts
inline const labelUList localStarts() const;
//- Global max of localSizes
inline label maxSize() const;

View File

@ -73,6 +73,13 @@ inline bool Foam::globalIndex::empty() const
}
inline Foam::label Foam::globalIndex::nProcs() const noexcept
{
const label len = (offsets_.size() - 1);
return (len < 1) ? 0 : len;
}
inline const Foam::labelList& Foam::globalIndex::offsets() const noexcept
{
return offsets_;
@ -85,6 +92,16 @@ inline Foam::labelList& Foam::globalIndex::offsets() noexcept
}
inline const Foam::labelUList Foam::globalIndex::localStarts() const
{
const label len = (offsets_.size() - 1);
if (len < 1) return labelUList::null();
return labelList::subList(offsets_, len);
}
inline Foam::label Foam::globalIndex::size() const
{
return offsets_.empty() ? 0 : offsets_.last();

View File

@ -307,6 +307,22 @@ void Foam::polyBoundaryMesh::calcGeometry()
}
Foam::UPtrList<const Foam::labelUList>
Foam::polyBoundaryMesh::faceCells() const
{
const polyPatchList& patches = *this;
UPtrList<const labelUList> list(patches.size());
forAll(patches, patchi)
{
list.set(patchi, &patches[patchi].faceCells());
}
return list;
}
const Foam::List<Foam::labelPairList>&
Foam::polyBoundaryMesh::neighbourEdges() const
{

View File

@ -155,6 +155,9 @@ public:
return mesh_;
}
//- Return a list of faceCells for each patch
UPtrList<const labelUList> faceCells() const;
//- Per patch the edges on the neighbouring patch.
// Is for every external edge the neighbouring patch and
// neighbouring (external) patch edge label. Note that edge indices

View File

@ -311,7 +311,6 @@ public:
// Member Functions
// Implicit treatment functions
//- Return number of new internal of this polyPatch faces
@ -324,7 +323,7 @@ public:
virtual const labelUList& nbrCells() const
{
NotImplemented
return faceCells();
return labelUList::null();
}
//- Return nbr patchID
@ -338,8 +337,7 @@ public:
virtual refPtr<labelListList> mapCollocatedFaces() const
{
NotImplemented;
refPtr<labelListList> tMap(new labelListList(size()));
return tMap;
return nullptr;
}
//- Return implicit master

View File

@ -142,23 +142,39 @@ void Foam::faBoundaryMesh::calcGeometry()
}
Foam::UPtrList<const Foam::labelUList>
Foam::faBoundaryMesh::edgeFaces() const
{
const faPatchList& patches = *this;
UPtrList<const labelUList> list(patches.size());
forAll(list, patchi)
{
list.set(patchi, &patches[patchi].edgeFaces());
}
return list;
}
Foam::lduInterfacePtrsList Foam::faBoundaryMesh::interfaces() const
{
lduInterfacePtrsList interfaces(size());
const faPatchList& patches = *this;
forAll(interfaces, patchi)
lduInterfacePtrsList list(patches.size());
forAll(list, patchi)
{
if (isA<lduInterface>(this->operator[](patchi)))
const lduInterface* lduPtr = isA<lduInterface>(patches[patchi]);
if (lduPtr)
{
interfaces.set
(
patchi,
&refCast<const lduInterface>(this->operator[](patchi))
);
list.set(patchi, lduPtr);
}
}
return interfaces;
return list;
}

View File

@ -128,6 +128,9 @@ public:
return mesh_;
}
//- Return a list of edgeFaces for each patch
UPtrList<const labelUList> edgeFaces() const;
//- Return a list of pointers for each patch
//- with only those pointing to interfaces being set
lduInterfacePtrsList interfaces() const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,16 +58,16 @@ class faMeshLduAddressing
:
public lduAddressing
{
// Private data
// Private Data
//- Lower as a subList of allOwner
labelList::subList lowerAddr_;
const labelList::subList lowerAddr_;
//- Upper as a reference to neighbour
const labelList& upperAddr_;
//- Patch addressing as a list of sublists
List<const labelUList*> patchAddr_;
const UPtrList<const labelUList> patchAddr_;
//- Patch field evaluation schedule
const lduSchedule& patchSchedule_;
@ -99,14 +99,10 @@ public:
)
),
upperAddr_(mesh.edgeNeighbour()),
patchAddr_(mesh.boundary().size()),
patchAddr_(mesh.boundary().edgeFaces()),
patchSchedule_(mesh.globalData().patchSchedule())
{
forAll(mesh.boundary(), patchI)
{
patchAddr_[patchI] = &mesh.boundary()[patchI].edgeFaces();
}
}
{}
//- Destructor
virtual ~faMeshLduAddressing() = default;
@ -115,31 +111,31 @@ public:
// Member Functions
//- Return number of interfaces
virtual label nPatches() const
virtual label nPatches() const noexcept
{
return patchAddr_.size();
}
//- Return lower addressing (i.e. lower label = upper triangle)
virtual const labelUList& lowerAddr() const
virtual const labelUList& lowerAddr() const noexcept
{
return lowerAddr_;
}
//- Return upper addressing (i.e. upper label)
virtual const labelUList& upperAddr() const
virtual const labelUList& upperAddr() const noexcept
{
return upperAddr_;
}
//- Return patch addressing
virtual const labelUList& patchAddr(const label i) const
virtual const labelUList& patchAddr(const label patchi) const
{
return *patchAddr_[i];
return patchAddr_[patchi];
}
// Return patch field evaluation schedule
virtual const lduSchedule& patchSchedule() const
//- Return patch field evaluation schedule
virtual const lduSchedule& patchSchedule() const noexcept
{
return patchSchedule_;
}

View File

@ -29,7 +29,6 @@ License
#include "fvBoundaryMesh.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fvBoundaryMesh::addPatches(const polyBoundaryMesh& basicBdry)
@ -131,23 +130,39 @@ void Foam::fvBoundaryMesh::movePoints()
}
Foam::UPtrList<const Foam::labelUList>
Foam::fvBoundaryMesh::faceCells() const
{
const fvPatchList& patches = *this;
UPtrList<const labelUList> list(patches.size());
forAll(list, patchi)
{
list.set(patchi, &patches[patchi].faceCells());
}
return list;
}
Foam::lduInterfacePtrsList Foam::fvBoundaryMesh::interfaces() const
{
lduInterfacePtrsList interfaces(size());
const fvPatchList& patches = *this;
forAll(interfaces, patchi)
lduInterfacePtrsList list(patches.size());
forAll(list, patchi)
{
if (isA<lduInterface>(this->operator[](patchi)))
const lduInterface* lduPtr = isA<lduInterface>(patches[patchi]);
if (lduPtr)
{
interfaces.set
(
patchi,
&refCast<const lduInterface>(this->operator[](patchi))
);
list.set(patchi, lduPtr);
}
}
return interfaces;
return list;
}

View File

@ -91,8 +91,8 @@ public:
// Constructors
//- Construct with zero size
fvBoundaryMesh(const fvMesh&);
//- Construct zero size with mesh reference
explicit fvBoundaryMesh(const fvMesh&);
//- Construct from polyBoundaryMesh
fvBoundaryMesh(const fvMesh&, const polyBoundaryMesh&);
@ -101,11 +101,14 @@ public:
// Member Functions
//- Return the mesh reference
const fvMesh& mesh() const
const fvMesh& mesh() const noexcept
{
return mesh_;
}
//- Return a list of faceCells for each patch
UPtrList<const labelUList> faceCells() const;
//- Return a list of pointers for each patch
//- with only those pointing to interfaces being set
lduInterfacePtrsList interfaces() const;

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,7 +54,7 @@ class fvMeshLduAddressing
:
public lduAddressing
{
// Private data
// Private Data
//- Lower as a subList of allOwner
const labelList::subList lowerAddr_;
@ -62,7 +63,7 @@ class fvMeshLduAddressing
const labelList& upperAddr_;
//- Patch addressing as a list of sublists
List<const labelUList*> patchAddr_;
const UPtrList<const labelUList> patchAddr_;
//- Patch field evaluation schedule
const lduSchedule& patchSchedule_;
@ -82,7 +83,7 @@ public:
// Constructors
//- Construct from components
fvMeshLduAddressing(const fvMesh& mesh)
explicit fvMeshLduAddressing(const fvMesh& mesh)
:
lduAddressing(mesh.nCells()),
lowerAddr_
@ -94,43 +95,37 @@ public:
)
),
upperAddr_(mesh.faceNeighbour()),
patchAddr_(mesh.boundary().size()),
patchAddr_(mesh.boundary().faceCells()),
patchSchedule_(mesh.globalData().patchSchedule())
{
forAll(mesh.boundary(), patchi)
{
patchAddr_[patchi] = &mesh.boundary()[patchi].faceCells();
}
}
{}
//- Destructor
~fvMeshLduAddressing()
{}
~fvMeshLduAddressing() = default;
// Member Functions
//- Return lower addressing (i.e. lower label = upper triangle)
const labelUList& lowerAddr() const
const labelUList& lowerAddr() const noexcept
{
return lowerAddr_;
}
//- Return upper addressing (i.e. upper label)
const labelUList& upperAddr() const
const labelUList& upperAddr() const noexcept
{
return upperAddr_;
}
//- Return patch addressing
const labelUList& patchAddr(const label i) const
const labelUList& patchAddr(const label patchi) const
{
return *patchAddr_[i];
return patchAddr_[patchi];
}
// Return patch field evaluation schedule
const lduSchedule& patchSchedule() const
//- Return patch field evaluation schedule
const lduSchedule& patchSchedule() const noexcept
{
return patchSchedule_;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014-2020 OpenCFD Ltd.
Copyright (C) 2014-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -275,7 +275,7 @@ bool Foam::dynamicOversetFvMesh::updateAddressing() const
// Get addressing and interfaces of all interfaces
List<const labelUList*> patchAddr;
UPtrList<const labelUList> patchAddr;
{
const fvBoundaryMesh& fvp = boundary();
@ -285,24 +285,24 @@ bool Foam::dynamicOversetFvMesh::updateAddressing() const
allInterfaces_ = dynamicFvMesh::interfaces();
allInterfaces_.setSize(patchAddr.size());
forAll(fvp, patchI)
forAll(fvp, patchi)
{
patchAddr[patchI] = &fvp[patchI].faceCells();
patchAddr.set(patchi, &fvp[patchi].faceCells());
}
forAll(remoteStencilInterfaces_, i)
{
label patchI = fvp.size()+i;
const label patchi = fvp.size()+i;
const lduPrimitiveProcessorInterface& pp =
remoteStencilInterfaces_[i];
//Pout<< "at patch:" << patchI
//Pout<< "at patch:" << patchi
// << " have procPatch:" << pp.type()
// << " from:" << pp.myProcNo()
// << " to:" << pp.neighbProcNo()
// << " with fc:" << pp.faceCells().size() << endl;
patchAddr[patchI] = &pp.faceCells();
allInterfaces_.set(patchI, &pp);
patchAddr.set(patchi, &pp.faceCells());
allInterfaces_.set(patchi, &pp);
}
}
const lduSchedule ps

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,14 +47,9 @@ Foam::fvMeshPrimitiveLduAddressing::fvMeshPrimitiveLduAddressing
)
),
upperAddr_(mesh.faceNeighbour()),
patchAddr_(mesh.boundary().size()),
patchAddr_(mesh.boundary().faceCells()),
patchSchedule_(mesh.globalData().patchSchedule())
{
forAll(mesh.boundary(), patchi)
{
patchAddr_[patchi] = &mesh.boundary()[patchi].faceCells();
}
}
{}
Foam::fvMeshPrimitiveLduAddressing::fvMeshPrimitiveLduAddressing
@ -62,7 +57,7 @@ Foam::fvMeshPrimitiveLduAddressing::fvMeshPrimitiveLduAddressing
const label nCells,
labelList&& lowerAddr,
labelList&& upperAddr,
const List<const labelUList*>& patchAddr,
const UPtrList<const labelUList>& patchAddr,
const lduSchedule& ps
)
:
@ -83,17 +78,15 @@ Foam::label Foam::fvMeshPrimitiveLduAddressing::triIndex
const label b
)
{
label own = min(a, b);
const label own = min(a, b);
const label nbr = max(a, b);
label nbr = max(a, b);
label startLabel = addr.ownerStartAddr()[own];
label endLabel = addr.ownerStartAddr()[own + 1];
const label begLabel = addr.ownerStartAddr()[own];
const label endLabel = addr.ownerStartAddr()[own + 1];
const labelUList& neighbour = addr.upperAddr();
for (label i = startLabel; i < endLabel; i++)
for (label i = begLabel; i < endLabel; ++i)
{
if (neighbour[i] == nbr)
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,7 +59,7 @@ class fvMeshPrimitiveLduAddressing
:
public lduAddressing
{
// Private data
// Private Data
//- Lower (face to owner addressing)
const labelList lowerAddr_;
@ -68,7 +68,7 @@ class fvMeshPrimitiveLduAddressing
const labelList upperAddr_;
//- Patch addressing as a list of sublists
List<const labelUList*> patchAddr_;
const UPtrList<const labelUList> patchAddr_;
//- Patch field evaluation schedule
const lduSchedule patchSchedule_;
@ -91,7 +91,7 @@ public:
// Constructors
//- Construct from mesh
fvMeshPrimitiveLduAddressing(const fvMesh& mesh);
explicit fvMeshPrimitiveLduAddressing(const fvMesh& mesh);
//- Construct from components
fvMeshPrimitiveLduAddressing
@ -99,7 +99,7 @@ public:
const label nCells,
labelList&& lowerAddr,
labelList&& upperAddr,
const List<const labelUList*>& interfaces,
const UPtrList<const labelUList>& patchAddr,
const lduSchedule& ps
);
@ -111,31 +111,32 @@ public:
// Member Functions
//- Return lower addressing (i.e. lower label = upper triangle)
virtual const labelUList& lowerAddr() const
virtual const labelUList& lowerAddr() const noexcept
{
return lowerAddr_;
}
//- Return upper addressing (i.e. upper label)
virtual const labelUList& upperAddr() const
virtual const labelUList& upperAddr() const noexcept
{
return upperAddr_;
}
//- Return patch addressing
virtual const labelUList& patchAddr(const label i) const
//- Return patch addressing for given patch
virtual const labelUList& patchAddr(const label patchi) const
{
return *patchAddr_[i];
return patchAddr_[patchi];
}
// Return patch field evaluation schedule
virtual const lduSchedule& patchSchedule() const
//- Return patch field evaluation schedule
virtual const lduSchedule& patchSchedule() const noexcept
{
return patchSchedule_;
}
//- Given additional addressing (in the form of additional neighbour
// cells, i.e. like cellCells)
//- cells, i.e. like cellCells)
//
// - add any additional faces
// - sort in upper-triangular order
// - construct cell-faces equivalent of given nbrCells
@ -159,8 +160,8 @@ public:
labelListList& remoteFaceCells
);
//- Return off-diagonal index given owner and neighbour label. Return
// -1 if not found
//- Return off-diagonal index given owner and neighbour label.
// \return -1 if not found
static label triIndex(const lduAddressing&, const label, const label);
};