Skip to content

Commit

Permalink
fvMeshStitcher: Fixes for cases with multiple NCC-s
Browse files Browse the repository at this point in the history
A number of bugs have been fixed relating to cases in which multiple NCC
patches are locally edge-connected, and/or are edge-connected across a
processor boundary.
  • Loading branch information
Will Bainbridge committed Oct 24, 2024
1 parent b390575 commit e971fc5
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ Foam::fvMeshStitcher::calculateOwnerOrigBoundaryEdgeParts
}



void Foam::fvMeshStitcher::applyOwnerOrigBoundaryEdgeParts
(
surfaceVectorField& SfSf,
Expand Down Expand Up @@ -1159,7 +1158,8 @@ void Foam::fvMeshStitcher::applyOwnerOrigBoundaryEdgeParts

const label patchi =
mesh_.isInternalFace(facei)
? -1 : pbMesh.patchIndices()[facei - mesh_.nInternalFaces()];
? -1
: pbMesh.patchIndices()[facei - mesh_.nInternalFaces()];

if (patchi != -1 && patchIsOwnerOrig[patchi])
{
Expand Down Expand Up @@ -1428,6 +1428,8 @@ void Foam::fvMeshStitcher::intersect

const nonConformalBoundary& ncb = nonConformalBoundary::New(mesh_);
const labelList ownerOrigPatchIndices = ncb.ownerOrigPatchIndices();
const edgeList& ownerOrigBoundaryMeshEdges =
ncb.ownerOrigBoundaryMeshEdges();

// Alias the boundary geometry fields
surfaceVectorField::Boundary& SfBf = SfSf.boundaryFieldRef();
Expand Down Expand Up @@ -1562,21 +1564,37 @@ void Foam::fvMeshStitcher::intersect
const label ownerOrigBoundaryEdgei =
origPatchEdgeOwnerOrigBoundaryEdges[origPatchEdgei];

const label sign =
edge::compare
(
meshEdge(origPatch, origPatchEdgei),
ownerOrigBoundaryMeshEdges[ownerOrigBoundaryEdgei]
);

part errorP =
patchEdgeParts[origPatchi][origPatchEdgei];
errorP -= ownerOrigBoundaryEdgeParts[ownerOrigBoundaryEdgei];
errorP -=
sign > 0
? ownerOrigBoundaryEdgeParts[ownerOrigBoundaryEdgei]
: -ownerOrigBoundaryEdgeParts[ownerOrigBoundaryEdgei];

forAll(origPatch.edgeFaces()[origPatchEdgei], patchEdgeFacei)
{
const label patchFacei =
origPatch.edgeFaces()[origPatchEdgei][patchEdgeFacei];

const label sign =
origPatch.localFaces()[patchFacei].edgeDirection
(
origPatch.edges()[origPatchEdgei]
);

part p
(
SfBf[origPatchi][patchFacei],
CfBf[origPatchi][patchFacei]
);
p += errorP;
p += sign > 0 ? errorP : -errorP;

SfBf[origPatchi][patchFacei] = p.area;
CfBf[origPatchi][patchFacei] = p.centre;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ License

#include "processorFvPatch.H"
#include "addToRunTimeSelectionTable.H"
#include "transformField.H"
#include "volFields.H"
#include "surfaceFields.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

Expand All @@ -42,13 +43,26 @@ void Foam::processorFvPatch::makeWeights(scalarField& w) const
{
if (Pstream::parRun())
{
coupledFvPatch::makeWeights
(
w,
procPolyPatch_.neighbFaceAreas(),
procPolyPatch_.neighbFaceCentres()
- procPolyPatch_.neighbFaceCellCentres()
);
if (!boundaryMesh().mesh().conformal())
{
coupledFvPatch::makeWeights
(
w,
- boundaryMesh().mesh().Sf().boundaryField()[index()],
boundaryMesh().mesh().Cf().boundaryField()[index()]
- boundaryMesh().mesh().C().boundaryField()[index()]
);
}
else
{
coupledFvPatch::makeWeights
(
w,
procPolyPatch_.neighbFaceAreas(),
procPolyPatch_.neighbFaceCentres()
- procPolyPatch_.neighbFaceCellCentres()
);
}
}
else
{
Expand All @@ -61,12 +75,24 @@ Foam::tmp<Foam::vectorField> Foam::processorFvPatch::delta() const
{
if (Pstream::parRun())
{
return
coupledFvPatch::delta
(
procPolyPatch_.neighbFaceCentres()
- procPolyPatch_.neighbFaceCellCentres()
);
if (!boundaryMesh().mesh().conformal())
{
return
coupledFvPatch::delta
(
boundaryMesh().mesh().Cf().boundaryField()[index()]
- boundaryMesh().mesh().C().boundaryField()[index()]
);
}
else
{
return
coupledFvPatch::delta
(
procPolyPatch_.neighbFaceCentres()
- procPolyPatch_.neighbFaceCellCentres()
);
}
}
else
{
Expand Down
79 changes: 40 additions & 39 deletions src/meshTools/nonConformal/boundary/nonConformalBoundary.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -179,28 +179,6 @@ void Foam::nonConformalBoundary::nonConformalOtherPatchIndices
{}


const Foam::labelList&
Foam::nonConformalBoundary::meshPointOwnerOrigBoundaryPoint() const
{
if (!meshPointOwnerOrigBoundaryPointPtr_.valid())
{
meshPointOwnerOrigBoundaryPointPtr_.set
(
new labelList(mesh().nPoints(), -1)
);

forAll(ownerOrigBoundary_.meshPoints(), ownerOrigBoundaryPointi)
{
meshPointOwnerOrigBoundaryPointPtr_()
[ownerOrigBoundary_.meshPoints()[ownerOrigBoundaryPointi]] =
ownerOrigBoundaryPointi;
}
}

return meshPointOwnerOrigBoundaryPointPtr_();
}


const Foam::vectorField&
Foam::nonConformalBoundary::ownerOrigBoundaryPointNormals() const
{
Expand Down Expand Up @@ -373,20 +351,30 @@ Foam::nonConformalBoundary::ownerOrigBoundaryPointMeshPoint() const
{
if (!ownerOrigBoundaryPointMeshPointPtr_.valid())
{
// Construct the local maps using the owner-orig primitive patch
ownerOrigBoundaryPointMeshPointPtr_.set
(
new labelList(ownerOrigBoundary_.meshPoints())
);

// ...
meshPointOwnerOrigBoundaryPoint();
labelList& map = meshPointOwnerOrigBoundaryPointPtr_();
meshPointOwnerOrigBoundaryPointPtr_.set
(
new labelList(mesh().nPoints(), -1)
);

// ...
label ownerOrigBoundaryPointi = ownerOrigBoundary_.nPoints();
DynamicList<label> remotePoints;
labelList& meshPointOwnerOrigBoundaryPoint =
meshPointOwnerOrigBoundaryPointPtr_();

forAll(ownerOrigBoundary_.meshPoints(), ownerOrigBoundaryPointi)
{
meshPointOwnerOrigBoundaryPoint
[ownerOrigBoundary_.meshPoints()[ownerOrigBoundaryPointi]] =
ownerOrigBoundaryPointi;
}

// ...
// Construct the remote map by enumerating newly identified points
label ownerOrigBoundaryPointi = ownerOrigBoundary_.nPoints();
DynamicList<label> remoteMeshPoints;
for
(
label ownerOrigBoundaryEdgei = ownerOrigBoundary_.nEdges();
Expand All @@ -403,16 +391,17 @@ Foam::nonConformalBoundary::ownerOrigBoundaryPointMeshPoint() const
{
const label meshPointi = e[i];

if (map[meshPointi] == -1)
if (meshPointOwnerOrigBoundaryPoint[meshPointi] == -1)
{
map[meshPointi] = ownerOrigBoundaryPointi ++;
remotePoints.append(meshPointi);
meshPointOwnerOrigBoundaryPoint[meshPointi] =
ownerOrigBoundaryPointi ++;
remoteMeshPoints.append(meshPointi);
}
}
}

// ...
ownerOrigBoundaryPointMeshPointPtr_->append(remotePoints);
// Append to the point-mesh-point map
ownerOrigBoundaryPointMeshPointPtr_->append(remoteMeshPoints);
}

return ownerOrigBoundaryPointMeshPointPtr_();
Expand Down Expand Up @@ -528,10 +517,11 @@ Foam::nonConformalBoundary::ownerOrigBoundaryEdges() const
new edgeList(ownerOrigBoundary_.edges())
);

const labelList& map = meshPointOwnerOrigBoundaryPoint();
ownerOrigBoundaryPointMeshPoint();
const labelList& meshPointOwnerOrigBoundaryPoint =
meshPointOwnerOrigBoundaryPointPtr_();

DynamicList<edge> remoteEdges;

for
(
label ownerOrigBoundaryEdgei = ownerOrigBoundary_.nEdges();
Expand All @@ -544,7 +534,14 @@ Foam::nonConformalBoundary::ownerOrigBoundaryEdges() const

const edge& e = mesh().edges()[meshEdgei];

remoteEdges.append(edge(map[e.start()], map[e.end()]));
remoteEdges.append
(
edge
(
meshPointOwnerOrigBoundaryPoint[e.start()],
meshPointOwnerOrigBoundaryPoint[e.end()]
)
);
}

ownerOrigBoundaryEdgesPtr_->append(remoteEdges);
Expand Down Expand Up @@ -594,11 +591,15 @@ Foam::nonConformalBoundary::patchPointOwnerOrigBoundaryPoints
{
const polyPatch& pp = mesh().boundaryMesh()[patchi];

ownerOrigBoundaryPointMeshPoint();
const labelList& meshPointOwnerOrigBoundaryPoint =
meshPointOwnerOrigBoundaryPointPtr_();

const faceList patchOwnerOrigBoundaryLocalFaces
(
renumber
(
meshPointOwnerOrigBoundaryPoint(),
meshPointOwnerOrigBoundaryPoint,
static_cast<const faceList&>(pp)
)
);
Expand Down
8 changes: 2 additions & 6 deletions src/meshTools/nonConformal/boundary/nonConformalBoundary.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -65,7 +65,7 @@ class nonConformalBoundary
//- Primitive patch of the owner-orig boundary
indirectPrimitivePatch ownerOrigBoundary_;

//- A map from owner-orig boundary point to mesh point
//- A map from mesh point to owner-orig boundary point
mutable autoPtr<labelList> meshPointOwnerOrigBoundaryPointPtr_;

//- A map from owner-orig boundary point to mesh point
Expand Down Expand Up @@ -135,10 +135,6 @@ class nonConformalBoundary
const label side
) const;

//- Get a map from mesh point to owner-orig boundary points. Non
// owner-orig boundary points are indicated by the value -1.
const labelList& meshPointOwnerOrigBoundaryPoint() const;

//- Get point normals for the owner-orig boundary
const vectorField& ownerOrigBoundaryPointNormals() const;

Expand Down

0 comments on commit e971fc5

Please sign in to comment.