ENH: extend patch/boundary methods: faces(), faceOwner()

- similar to polyBoundaryMesh
This commit is contained in:
Mark Olesen
2025-04-10 16:44:43 +02:00
parent 2d77f7ae26
commit 91e7870ee8
18 changed files with 112 additions and 232 deletions

View File

@ -1,3 +1,3 @@
Test-globalMeshData.C Test-globalMeshData.cxx
EXE = $(FOAM_USER_APPBIN)/Test-globalMeshData EXE = $(FOAM_USER_APPBIN)/Test-globalMeshData

View File

@ -182,18 +182,11 @@ int main(int argc, char *argv[])
const labelListList& transformedSlaves = const labelListList& transformedSlaves =
globalData.globalPointTransformedBoundaryFaces(); globalData.globalPointTransformedBoundaryFaces();
const label nBnd = mesh.nBoundaryFaces();
pointField fc(globalPointBoundaryFacesMap.constructSize()); pointField fc(globalPointBoundaryFacesMap.constructSize());
SubList<point>(fc, nBnd) = pointField::subList(fc, mesh.nBoundaryFaces()) =
primitivePatch primitivePatch
( (
SubList<face> mesh.boundaryMesh().faces(),
(
mesh.faces(),
nBnd,
mesh.nInternalFaces()
),
mesh.points() mesh.points()
).faceCentres(); ).faceCentres();

View File

@ -1,3 +1,3 @@
Test-syncTools.C Test-syncTools.cxx
EXE = $(FOAM_USER_APPBIN)/Test-syncTools EXE = $(FOAM_USER_APPBIN)/Test-syncTools

View File

@ -195,16 +195,7 @@ void testSparseData(const polyMesh& mesh, Random& rndGen)
<< "Position test of sparse data only correct for cases without cyclics" << "Position test of sparse data only correct for cases without cyclics"
<< " with shared points." << endl; << " with shared points." << endl;
primitivePatch allBoundary primitivePatch allBoundary(mesh.boundaryMesh().faces(), mesh.points());
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
const pointField& localPoints = allBoundary.localPoints(); const pointField& localPoints = allBoundary.localPoints();

View File

@ -417,14 +417,7 @@ int main(int argc, char *argv[])
// Get calculating engine for all of outside // Get calculating engine for all of outside
const SubList<face> outsideFaces primitivePatch allBoundary(mesh.boundaryMesh().faces(), mesh.points());
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
);
primitivePatch allBoundary(outsideFaces, mesh.points());
// Look up mesh labels and convert to input for boundaryCutter. // Look up mesh labels and convert to input for boundaryCutter.

View File

@ -104,18 +104,13 @@ const polyMesh& topoMesh = topoMeshPtr();
// Block boundary faces // Block boundary faces
{ {
const label nIntFaces = topoMesh.nInternalFaces(); const auto& patches = topoMesh.boundaryMesh();
const label nBndFaces = topoMesh.nBoundaryFaces(); const label nBndFaces = topoMesh.nBoundaryFaces();
faceList bndFaces
(
faceList::subList(topoMesh.faces(), nBndFaces, nIntFaces)
);
vtk::surfaceWriter writer vtk::surfaceWriter writer
( (
topoMesh.points(), topoMesh.points(),
bndFaces, faceList(patches.faces()),
vtk::formatType::INLINE_ASCII, vtk::formatType::INLINE_ASCII,
runTime.path()/"blockFaces" runTime.path()/"blockFaces"
); );
@ -132,7 +127,7 @@ const polyMesh& topoMesh = topoMeshPtr();
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
label bndFacei = pp.start() - nIntFaces; label bndFacei = pp.offset();
label meshFacei = pp.start(); label meshFacei = pp.start();
forAll(pp, bfacei) forAll(pp, bfacei)

View File

@ -608,12 +608,7 @@ void Foam::backgroundMeshDecomposition::buildPatchAndTree()
{ {
primitivePatch tmpBoundaryFaces primitivePatch tmpBoundaryFaces
( (
SubList<face> mesh_.boundaryMesh().faces(),
(
mesh_.faces(),
mesh_.nBoundaryFaces(),
mesh_.nInternalFaces()
),
mesh_.points() mesh_.points()
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd. Copyright (C) 2016,2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -137,16 +137,7 @@ void simpleMarkFeatures
// multiple 'half' cells. // multiple 'half' cells.
// Addressing for all outside faces // Addressing for all outside faces
primitivePatch allBoundary primitivePatch allBoundary(patches.faces(), mesh.points());
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
// Check for non-manifold points (surface pinched at point) // Check for non-manifold points (surface pinched at point)
allBoundary.checkPointManifold(false, &singleCellFeaturePointSet); allBoundary.checkPointManifold(false, &singleCellFeaturePointSet);
@ -240,7 +231,9 @@ void simpleMarkFeatures
// ~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~
// Face centres that need inclusion in the dual mesh // Face centres that need inclusion in the dual mesh
labelHashSet featureFaceSet(mesh.nBoundaryFaces()); labelHashSet featureFaceSet;
featureFaceSet.reserve(mesh.nBoundaryFaces());
// A. boundary faces. // A. boundary faces.
for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); facei++) for (label facei = mesh.nInternalFaces(); facei < mesh.nFaces(); facei++)
{ {

View File

@ -160,14 +160,7 @@ void Foam::meshPointPatch::movePoints(PstreamBuffers&, const pointField& p)
// Recalculate the point normals? Something like // Recalculate the point normals? Something like
//if (owner()) //if (owner())
//{ //{
// const SubList<face> subFaces // const primitivePatch pp(mesh.boundaryMesh().faces(), mesh.points());
// (
// mesh.faces(),
// mesh.nBoundaryFaces(),
// mesh.nInternalFaces()
// );
// const primitivePatch pp(subFaces, mesh.points());
//
// //
// for (const label pointi : meshPoints()) // for (const label pointi : meshPoints())
// { // {
@ -180,9 +173,8 @@ void Foam::meshPointPatch::movePoints(PstreamBuffers&, const pointField& p)
// const auto& point // const auto& point
// //
// //
} }
void Foam::meshPointPatch::updateMesh(PstreamBuffers&) void Foam::meshPointPatch::updateMesh(PstreamBuffers&)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2024 OpenCFD Ltd. Copyright (C) 2018-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -91,7 +91,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, index), patchIdentifier(name, index),
primitivePatch primitivePatch
( (
faceSubList(bm.mesh().faces(), size, start), SubList<face>(bm.mesh().faces(), size, start),
bm.mesh().points() bm.mesh().points()
), ),
start_(start), start_(start),
@ -118,7 +118,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, index, physicalType, inGroups), patchIdentifier(name, index, physicalType, inGroups),
primitivePatch primitivePatch
( (
faceSubList(bm.mesh().faces(), size, start), SubList<face>(bm.mesh().faces(), size, start),
bm.mesh().points() bm.mesh().points()
), ),
start_(start), start_(start),
@ -138,7 +138,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, dict, index), patchIdentifier(name, dict, index),
primitivePatch primitivePatch
( (
faceSubList SubList<face>
( (
bm.mesh().faces(), bm.mesh().faces(),
dict.get<label>("nFaces"), dict.get<label>("nFaces"),
@ -165,7 +165,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp), patchIdentifier(pp),
primitivePatch primitivePatch
( (
faceSubList SubList<face>
( (
bm.mesh().faces(), bm.mesh().faces(),
pp.size(), pp.size(),
@ -190,7 +190,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp, index), patchIdentifier(pp, index),
primitivePatch primitivePatch
( (
faceSubList SubList<face>
( (
bm.mesh().faces(), bm.mesh().faces(),
newSize, newSize,
@ -215,7 +215,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp, index), patchIdentifier(pp, index),
primitivePatch primitivePatch
( (
faceSubList SubList<face>
( (
bm.mesh().faces(), bm.mesh().faces(),
mapAddressing.size(), mapAddressing.size(),
@ -305,6 +305,25 @@ const Foam::polyBoundaryMesh& Foam::polyPatch::boundaryMesh() const noexcept
} }
const Foam::faceList::subList Foam::polyPatch::faces() const
{
return patchSlice(boundaryMesh().mesh().faces());
}
const Foam::labelList::subList Foam::polyPatch::faceOwner() const
{
return patchSlice(boundaryMesh().mesh().faceOwner());
}
// Potentially useful to simplify logic elsewhere?
// const Foam::labelList::subList Foam::polyPatch::faceNeighbour() const
// {
// return labelList::subList();
// }
const Foam::vectorField::subField Foam::polyPatch::faceCentres() const const Foam::vectorField::subField Foam::polyPatch::faceCentres() const
{ {
return patchSlice(boundaryMesh().mesh().faceCentres()); return patchSlice(boundaryMesh().mesh().faceCentres());

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2024 OpenCFD Ltd. Copyright (C) 2015-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -435,6 +435,12 @@ public:
// Geometric data; point list required // Geometric data; point list required
//- Return mesh faces for the patch
const faceList::subList faces() const;
//- Return face owner for the patch
const labelList::subList faceOwner() const;
//- Return face centres //- Return face centres
const vectorField::subField faceCentres() const; const vectorField::subField faceCentres() const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022,2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -723,16 +723,7 @@ void Foam::polyDualMesh::calcDual
// Get patch for all of outside // Get patch for all of outside
primitivePatch allBoundary primitivePatch allBoundary(patches.faces(), mesh.points());
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
// Correspondence from patch edge to mesh edge. // Correspondence from patch edge to mesh edge.
labelList meshEdges labelList meshEdges
@ -1467,31 +1458,19 @@ void Foam::polyDualMesh::calcFeatures
labelList& featurePoints labelList& featurePoints
) )
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Create big primitivePatch for all outside. // Create big primitivePatch for all outside.
primitivePatch allBoundary primitivePatch allBoundary(patches.faces(), mesh.points());
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
// For ease of use store patch number per face in allBoundary. // For ease of use store patch number per face in allBoundary.
labelList allRegion(allBoundary.size()); labelList allRegion(allBoundary.size());
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll(patches, patchi) forAll(patches, patchi)
{ {
const polyPatch& pp = patches[patchi]; const polyPatch& pp = patches[patchi];
forAll(pp, i) allRegion.slice(pp.offset(), pp.size()) = patchi;
{
allRegion[i + pp.start() - mesh.nInternalFaces()] = patchi;
}
} }

View File

@ -372,7 +372,7 @@ void Foam::turbulence::IntegralScaleBox<Type>::calcPatch()
( (
new primitivePatch new primitivePatch
( (
SubList<face>(patchFaces_, patchFaces_.size()), SubList<face>(patchFaces_),
patchPoints_ patchPoints_
) )
); );

View File

@ -71,22 +71,12 @@ void Foam::volPointInterpolation::calcBoundaryAddressing()
<< endl; << endl;
} }
boundaryPtr_.reset const polyBoundaryMesh& pbm = mesh().boundaryMesh();
(
new primitivePatch
(
SubList<face>
(
mesh().faces(),
mesh().nBoundaryFaces(),
mesh().nInternalFaces()
),
mesh().points()
)
);
const primitivePatch& boundary = boundaryPtr_();
boundaryIsPatchFace_.setSize(boundary.size()); boundaryPtr_.reset(new primitivePatch(pbm.faces(), mesh().points()));
const auto& boundary = *boundaryPtr_;
boundaryIsPatchFace_.resize_nocopy(boundary.size());
boundaryIsPatchFace_ = false; boundaryIsPatchFace_ = false;
// Store per mesh point whether it is on any 'real' patch. Currently // Store per mesh point whether it is on any 'real' patch. Currently
@ -94,8 +84,6 @@ void Foam::volPointInterpolation::calcBoundaryAddressing()
// bitSet. Tbd) // bitSet. Tbd)
boolList isPatchPoint(mesh().nPoints(), false); boolList isPatchPoint(mesh().nPoints(), false);
const polyBoundaryMesh& pbm = mesh().boundaryMesh();
// Get precalculated volField only so we can use coupled() tests for // Get precalculated volField only so we can use coupled() tests for
// cyclicAMI // cyclicAMI
const surfaceScalarField& magSf = mesh().magSf(); const surfaceScalarField& magSf = mesh().magSf();
@ -110,18 +98,11 @@ void Foam::volPointInterpolation::calcBoundaryAddressing()
&& !magSf.boundaryField()[patchi].coupled() && !magSf.boundaryField()[patchi].coupled()
) )
{ {
label bFacei = pp.start()-mesh().nInternalFaces(); boundaryIsPatchFace_.set(labelRange(pp.offset(), pp.size()));
forAll(pp, i) for (const auto& f : pp.faces())
{ {
boundaryIsPatchFace_[bFacei] = true; UIndirectList<bool>(isPatchPoint, f) = true;
const face& f = boundary[bFacei++];
forAll(f, fp)
{
isPatchPoint[f[fp]] = true;
}
} }
} }
} }
@ -136,27 +117,15 @@ void Foam::volPointInterpolation::calcBoundaryAddressing()
); );
// Convert to bitSet // Convert to bitSet
isPatchPoint_.setSize(mesh().nPoints()); isPatchPoint_.reset();
isPatchPoint_.resize(mesh().nPoints());
isPatchPoint_.assign(isPatchPoint); isPatchPoint_.assign(isPatchPoint);
if (debug) if (debug)
{ {
label nPatchFace = 0; label nPatchFace = boundaryIsPatchFace_.count();
forAll(boundaryIsPatchFace_, i) label nPatchPoint = isPatchPoint_.count();
{
if (boundaryIsPatchFace_[i])
{
nPatchFace++;
}
}
label nPatchPoint = 0;
forAll(isPatchPoint_, i)
{
if (isPatchPoint_[i])
{
nPatchPoint++;
}
}
Pout<< "boundary:" << nl Pout<< "boundary:" << nl
<< " faces :" << boundary.size() << nl << " faces :" << boundary.size() << nl
<< " of which on proper patch:" << nPatchFace << nl << " of which on proper patch:" << nPatchFace << nl

View File

@ -235,11 +235,7 @@ void Foam::lumpedPointMovement::writeZonesVTP
{ {
const labelList& faceToPoint = patchControls_[patchi].faceToPoint_; const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
primitivePatch pp primitivePatch pp(patches[patchi].faces(), points0);
(
SubList<face>(mesh.faces(), patches[patchi].range()),
points0
);
writer.piece(pp.localPoints(), pp.localFaces()); writer.piece(pp.localPoints(), pp.localFaces());

View File

@ -55,22 +55,12 @@ void Foam::volPointInterpolationAdjoint::calcBoundaryAddressing()
<< endl; << endl;
} }
boundaryPtr_.reset const polyBoundaryMesh& pbm = mesh().boundaryMesh();
(
new primitivePatch
(
SubList<face>
(
mesh().faces(),
mesh().nBoundaryFaces(),
mesh().nInternalFaces()
),
mesh().points()
)
);
const primitivePatch& boundary = boundaryPtr_();
boundaryIsPatchFace_.setSize(boundary.size()); boundaryPtr_.reset(new primitivePatch(pbm.faces(), mesh().points()));
const auto& boundary = *boundaryPtr_;
boundaryIsPatchFace_.resize_nocopy(boundary.size());
boundaryIsPatchFace_ = false; boundaryIsPatchFace_ = false;
// Store per mesh point whether it is on any 'real' patch. Currently // Store per mesh point whether it is on any 'real' patch. Currently
@ -79,8 +69,6 @@ void Foam::volPointInterpolationAdjoint::calcBoundaryAddressing()
boolList isPatchPoint(mesh().nPoints(), false); boolList isPatchPoint(mesh().nPoints(), false);
boolList isSymmetryPoint(mesh().nPoints(), false); boolList isSymmetryPoint(mesh().nPoints(), false);
const polyBoundaryMesh& pbm = mesh().boundaryMesh();
// Get precalculated volField only so we can use coupled() tests for // Get precalculated volField only so we can use coupled() tests for
// cyclicAMI // cyclicAMI
const surfaceScalarField& magSf = mesh().magSf(); const surfaceScalarField& magSf = mesh().magSf();
@ -97,27 +85,16 @@ void Foam::volPointInterpolationAdjoint::calcBoundaryAddressing()
&& !isA<symmetryPlanePolyPatch>(pp) && !isA<symmetryPlanePolyPatch>(pp)
) )
{ {
label bFacei = pp.start()-mesh().nInternalFaces(); boundaryIsPatchFace_.set(labelRange(pp.offset(), pp.size()));
forAll(pp, i) for (const auto& f : pp.faces())
{ {
boundaryIsPatchFace_[bFacei] = true; UIndirectList<bool>(isPatchPoint, f) = true;
const face& f = boundary[bFacei++];
forAll(f, fp)
{
isPatchPoint[f[fp]] = true;
}
} }
} }
else if (isA<symmetryPolyPatch>(pp) || isA<symmetryPlanePolyPatch>(pp)) else if (isA<symmetryPolyPatch>(pp) || isA<symmetryPlanePolyPatch>(pp))
{ {
const labelList& meshPoints = pp.meshPoints(); UIndirectList<bool>(isSymmetryPoint, pp.meshPoints()) = true;
for (const label pointI : meshPoints)
{
isSymmetryPoint[pointI] = true;
}
} }
} }
@ -131,30 +108,19 @@ void Foam::volPointInterpolationAdjoint::calcBoundaryAddressing()
); );
// Convert to bitSet // Convert to bitSet
isPatchPoint_.setSize(mesh().nPoints()); isPatchPoint_.reset();
isPatchPoint_.resize(mesh().nPoints());
isPatchPoint_.assign(isPatchPoint); isPatchPoint_.assign(isPatchPoint);
isSymmetryPoint_.setSize(mesh().nPoints()); isSymmetryPoint_.reset();
isSymmetryPoint_.resize(mesh().nPoints());
isSymmetryPoint_.assign(isSymmetryPoint); isSymmetryPoint_.assign(isSymmetryPoint);
if (debug) if (debug)
{ {
label nPatchFace = 0; label nPatchFace = boundaryIsPatchFace_.count();
forAll(boundaryIsPatchFace_, i) label nPatchPoint = isPatchPoint_.count();
{
if (boundaryIsPatchFace_[i])
{
nPatchFace++;
}
}
label nPatchPoint = 0;
forAll(isPatchPoint_, i)
{
if (isPatchPoint_[i])
{
nPatchPoint++;
}
}
Pout<< "boundary:" << nl Pout<< "boundary:" << nl
<< " faces :" << boundary.size() << nl << " faces :" << boundary.size() << nl
<< " of which on proper patch:" << nPatchFace << nl << " of which on proper patch:" << nPatchFace << nl

View File

@ -375,46 +375,20 @@ Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh)
template<class Face> template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface Foam::MeshedSurface<Face>::MeshedSurface
( (
const polyBoundaryMesh& bMesh, const polyBoundaryMesh& pbm,
const bool useGlobalPoints const bool useGlobalPoints
) )
: :
MeshedSurface<Face>() MeshedSurface<Face>()
{ {
const polyMesh& mesh = bMesh.mesh(); const polyMesh& mesh = pbm.mesh();
const polyPatchList& bPatches = bMesh;
// Get a single patch for all boundaries
primitivePatch allBoundary
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
// use global/local points:
const pointField& bPoints =
(
useGlobalPoints ? mesh.points() : allBoundary.localPoints()
);
// global/local face addressing:
const List<Face>& bFaces =
(
useGlobalPoints ? allBoundary : allBoundary.localFaces()
);
// create zone list // create zone list
surfZoneList newZones(bPatches.size()); surfZoneList newZones(pbm.size());
label startFacei = 0; label startFacei = 0;
label nZone = 0; label nZone = 0;
for (const polyPatch& p : bPatches) for (const polyPatch& p : pbm)
{ {
if (p.size()) if (p.size())
{ {
@ -433,8 +407,27 @@ Foam::MeshedSurface<Face>::MeshedSurface
newZones.setSize(nZone); newZones.setSize(nZone);
// Get a single patch for all boundaries
primitivePatch allBoundary(pbm.faces(), mesh.points());
// Face type as per polyBoundaryMesh // Face type as per polyBoundaryMesh
MeshedSurface<face> surf(bPoints, bFaces, newZones); MeshedSurface<face> surf;
if (useGlobalPoints)
{
// use global points, global face addressing
surf = MeshedSurface<face>(mesh.points(), allBoundary, newZones);
}
else
{
// use local points, local face addressing
surf = MeshedSurface<face>
(
allBoundary.localPoints(),
allBoundary.localFaces(),
newZones
);
}
this->transcribe(surf); this->transcribe(surf);
} }

View File

@ -288,7 +288,7 @@ public:
//- Construct from a boundary mesh with local points/faces //- Construct from a boundary mesh with local points/faces
MeshedSurface MeshedSurface
( (
const polyBoundaryMesh& bMesh, const polyBoundaryMesh& pbm,
const bool globalPoints = false const bool globalPoints = false
); );