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

View File

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

View File

@ -1,3 +1,3 @@
Test-syncTools.C
Test-syncTools.cxx
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"
<< " with shared points." << endl;
primitivePatch allBoundary
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
primitivePatch allBoundary(mesh.boundaryMesh().faces(), mesh.points());
const pointField& localPoints = allBoundary.localPoints();

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016,2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -137,16 +137,7 @@ void simpleMarkFeatures
// multiple 'half' cells.
// Addressing for all outside faces
primitivePatch allBoundary
(
SubList<face>
(
mesh.faces(),
mesh.nBoundaryFaces(),
mesh.nInternalFaces()
),
mesh.points()
);
primitivePatch allBoundary(patches.faces(), mesh.points());
// Check for non-manifold points (surface pinched at point)
allBoundary.checkPointManifold(false, &singleCellFeaturePointSet);
@ -240,7 +231,9 @@ void simpleMarkFeatures
// ~~~~~~~~~~~~~~~~~~~~~~~~~
// Face centres that need inclusion in the dual mesh
labelHashSet featureFaceSet(mesh.nBoundaryFaces());
labelHashSet featureFaceSet;
featureFaceSet.reserve(mesh.nBoundaryFaces());
// A. boundary faces.
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
//if (owner())
//{
// const SubList<face> subFaces
// (
// mesh.faces(),
// mesh.nBoundaryFaces(),
// mesh.nInternalFaces()
// );
// const primitivePatch pp(subFaces, mesh.points());
//
// const primitivePatch pp(mesh.boundaryMesh().faces(), mesh.points());
//
// for (const label pointi : meshPoints())
// {
@ -180,9 +173,8 @@ void Foam::meshPointPatch::movePoints(PstreamBuffers&, const pointField& p)
// const auto& point
//
//
}
void Foam::meshPointPatch::updateMesh(PstreamBuffers&)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2024 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -91,7 +91,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, index),
primitivePatch
(
faceSubList(bm.mesh().faces(), size, start),
SubList<face>(bm.mesh().faces(), size, start),
bm.mesh().points()
),
start_(start),
@ -118,7 +118,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, index, physicalType, inGroups),
primitivePatch
(
faceSubList(bm.mesh().faces(), size, start),
SubList<face>(bm.mesh().faces(), size, start),
bm.mesh().points()
),
start_(start),
@ -138,7 +138,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(name, dict, index),
primitivePatch
(
faceSubList
SubList<face>
(
bm.mesh().faces(),
dict.get<label>("nFaces"),
@ -165,7 +165,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp),
primitivePatch
(
faceSubList
SubList<face>
(
bm.mesh().faces(),
pp.size(),
@ -190,7 +190,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp, index),
primitivePatch
(
faceSubList
SubList<face>
(
bm.mesh().faces(),
newSize,
@ -215,7 +215,7 @@ Foam::polyPatch::polyPatch
patchIdentifier(pp, index),
primitivePatch
(
faceSubList
SubList<face>
(
bm.mesh().faces(),
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
{
return patchSlice(boundaryMesh().mesh().faceCentres());

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2024 OpenCFD Ltd.
Copyright (C) 2015-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -435,6 +435,12 @@ public:
// 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
const vectorField::subField faceCentres() const;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -375,46 +375,20 @@ Foam::MeshedSurface<Face>::MeshedSurface(const surfMesh& mesh)
template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface
(
const polyBoundaryMesh& bMesh,
const polyBoundaryMesh& pbm,
const bool useGlobalPoints
)
:
MeshedSurface<Face>()
{
const polyMesh& mesh = bMesh.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()
);
const polyMesh& mesh = pbm.mesh();
// create zone list
surfZoneList newZones(bPatches.size());
surfZoneList newZones(pbm.size());
label startFacei = 0;
label nZone = 0;
for (const polyPatch& p : bPatches)
for (const polyPatch& p : pbm)
{
if (p.size())
{
@ -433,8 +407,27 @@ Foam::MeshedSurface<Face>::MeshedSurface
newZones.setSize(nZone);
// Get a single patch for all boundaries
primitivePatch allBoundary(pbm.faces(), mesh.points());
// 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);
}

View File

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