FaceCellWave: travel through coupled ACMI. See #3139

This commit is contained in:
Mattijs Janssens
2024-05-30 15:15:56 +00:00
committed by Andrew Heather
parent 30d2e2d3cf
commit 056bb4f0a0
14 changed files with 212 additions and 86 deletions

View File

@ -350,13 +350,15 @@ Foam::tmp<Foam::vectorField> Foam::polyPatch::faceCellCentres() const
} }
Foam::tmp<Foam::scalarField> Foam::polyPatch::areaFraction() const Foam::tmp<Foam::scalarField> Foam::polyPatch::areaFraction
(
const pointField& points
) const
{ {
auto tfraction = tmp<scalarField>::New(size()); auto tfraction = tmp<scalarField>::New(size());
auto& fraction = tfraction.ref(); auto& fraction = tfraction.ref();
const vectorField::subField faceAreas = this->faceAreas(); const vectorField::subField faceAreas = this->faceAreas();
const pointField& points = this->points();
forAll(*this, facei) forAll(*this, facei)
{ {
@ -369,6 +371,18 @@ Foam::tmp<Foam::scalarField> Foam::polyPatch::areaFraction() const
} }
const Foam::tmp<Foam::scalarField>& Foam::polyPatch::areaFraction() const
{
return areaFraction_;
}
void Foam::polyPatch::areaFraction(const tmp<scalarField>& fraction)
{
areaFraction_ = fraction;
}
const Foam::labelUList& Foam::polyPatch::faceCells() const const Foam::labelUList& Foam::polyPatch::faceCells() const
{ {
if (!faceCellsPtr_) if (!faceCellsPtr_)

View File

@ -88,6 +88,9 @@ class polyPatch
//- Demand-driven: global edge addressing //- Demand-driven: global edge addressing
mutable std::unique_ptr<labelList> mePtr_; mutable std::unique_ptr<labelList> mePtr_;
//- Cached area fraction
tmp<scalarField> areaFraction_;
protected: protected:
@ -441,9 +444,16 @@ public:
//- Return face cell centres //- Return face cell centres
tmp<vectorField> faceCellCentres() const; tmp<vectorField> faceCellCentres() const;
//- Return the area fraction as the ratio of the stored face area //- Calculate the area fraction as the ratio of the stored face
//- and the area given by the face points // area and the area given by the face points.
tmp<scalarField> areaFraction() const; tmp<scalarField> areaFraction(const pointField& points) const;
//- Return the cached area fraction. Usually only set for the
//- non-overlap patches on ACMI.
const tmp<scalarField>& areaFraction() const;
//- Set cached area fraction
void areaFraction(const tmp<scalarField>&);
// Addressing into mesh // Addressing into mesh

View File

@ -342,6 +342,7 @@ void Foam::activePressureForceBaffleVelocityFvPatchVectorField::updateCoeffs()
).neighbFvPatch().Sf(); ).neighbFvPatch().Sf();
} }
// Update this wall patch // Update this wall patch
vectorField::subField Sfw = patch().patch().faceAreas(); vectorField::subField Sfw = patch().patch().faceAreas();
vectorField newSfw((1 - areaFraction)*initWallSf_); vectorField newSfw((1 - areaFraction)*initWallSf_);
@ -350,16 +351,41 @@ void Foam::activePressureForceBaffleVelocityFvPatchVectorField::updateCoeffs()
Sfw[facei] = newSfw[facei]; Sfw[facei] = newSfw[facei];
} }
const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf()); const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
// Cache fraction
const_cast<polyPatch&>(patch().patch()).areaFraction
(
tmp<scalarField>::New
(
patch().patch().size(),
(1-areaFraction)
)
);
// Update owner side of cyclic // Update owner side of cyclic
const_cast<vectorField&>(cyclicPatch.Sf()) = areaFraction*initCyclicSf_; const_cast<vectorField&>(cyclicPatch.Sf()) = areaFraction*initCyclicSf_;
const_cast<scalarField&>(cyclicPatch.magSf()) = mag(cyclicPatch.Sf()); const_cast<scalarField&>(cyclicPatch.magSf()) = mag(cyclicPatch.Sf());
const_cast<polyPatch&>(cyclicPatch.patch()).areaFraction
(
tmp<scalarField>::New
(
cyclicPatch.patch().size(),
areaFraction
)
);
// Update neighbour side of cyclic // Update neighbour side of cyclic
const_cast<vectorField&>(nbrPatch.Sf()) = areaFraction*nbrCyclicSf_; const_cast<vectorField&>(nbrPatch.Sf()) = areaFraction*nbrCyclicSf_;
const_cast<scalarField&>(nbrPatch.magSf()) = mag(nbrPatch.Sf()); const_cast<scalarField&>(nbrPatch.magSf()) = mag(nbrPatch.Sf());
const_cast<polyPatch&>(cyclicPatch.patch()).areaFraction
(
tmp<scalarField>::New
(
nbrPatch.patch().size(),
areaFraction
)
);
curTimeIndex_ = this->db().time().timeIndex(); curTimeIndex_ = this->db().time().timeIndex();
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd. Copyright (C) 2023-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -146,29 +146,40 @@ void Foam::wallDistAddressing::correct(volScalarField& y)
globalWallsPtr_.reset(new globalIndex(nWalls)); globalWallsPtr_.reset(new globalIndex(nWalls));
const globalIndex& globalWalls = globalWallsPtr_(); const globalIndex& globalWalls = globalWallsPtr_();
labelList seedFaces(nWalls); DynamicList<label> seedFaces(nWalls);
List<wallPointAddressing> seedInfo(nWalls); DynamicList<wallPointAddressing> seedInfo(nWalls);
nWalls = 0; nWalls = 0;
for (const label patchi : patchIDs_) for (const label patchi : patchIDs_)
{ {
const auto& fc = C.boundaryField()[patchi]; const auto& fc = C.boundaryField()[patchi];
const auto& areaFraction = fc.patch().patch().areaFraction();
forAll(fc, patchFacei) forAll(fc, patchFacei)
{ {
seedFaces[nWalls] = fc.patch().start()+patchFacei; if
seedInfo[nWalls] = wallPointAddressing
( (
fc[patchFacei], !areaFraction
gt.encode || (areaFraction()[patchFacei] > 0.5) // mostly wall
)
{
seedFaces.append(fc.patch().start()+patchFacei);
seedInfo.append
( (
Pstream::myProcNo(), wallPointAddressing
nWalls, (
gt.nullTransformIndex() fc[patchFacei],
), gt.encode
scalar(0.0) (
); Pstream::myProcNo(),
nWalls,
gt.nullTransformIndex()
),
scalar(0.0)
)
);
}
nWalls++; nWalls++;
} }
} }

View File

@ -28,7 +28,6 @@ License
#include "inverseDistanceDiffusivity.H" #include "inverseDistanceDiffusivity.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "patchWave.H"
#include "HashSet.H" #include "HashSet.H"
#include "surfaceInterpolate.H" #include "surfaceInterpolate.H"
#include "zeroGradientFvPatchFields.H" #include "zeroGradientFvPatchFields.H"

View File

@ -27,7 +27,6 @@ License
#include "inverseVolumeDiffusivity.H" #include "inverseVolumeDiffusivity.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "patchWave.H"
#include "HashSet.H" #include "HashSet.H"
#include "surfaceInterpolate.H" #include "surfaceInterpolate.H"
#include "zeroGradientFvPatchFields.H" #include "zeroGradientFvPatchFields.H"

View File

@ -299,11 +299,11 @@ void Foam::InteractionLists<ParticleType>::buildInteractionLists()
{ {
if (isA<wallPolyPatch>(patch)) if (isA<wallPolyPatch>(patch))
{ {
const scalarField areaFraction(patch.areaFraction()); const auto& areaFraction = patch.areaFraction();
forAll(areaFraction, facei) forAll(patch, facei)
{ {
if (areaFraction[facei] > 0.5) if (!areaFraction || areaFraction()[facei] > 0.5)
{ {
localWallFaces.append(facei + patch.start()); localWallFaces.append(facei + patch.start());
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2022,2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -217,10 +217,24 @@ void Foam::cyclicACMIPolyPatch::scalePatchFaceAreas
return; return;
} }
forAll(noSf, facei)
{ {
const scalar w = min(maxTol, max(tolerance_, mask[facei])); tmp<scalarField> scale
noSf[facei] = noFaceArea[facei]*(scalar(1) - w); (
scalar(1)
- min
(
max(mask, tolerance_),
maxTol
)
);
// Scale area
forAll(noSf, facei)
{
noSf[facei] = noFaceArea[facei]*scale()[facei];
}
// Cache scaling
const_cast<polyPatch&>(nonOverlapPatch).areaFraction(scale);
} }
if (!createAMIFaces_) if (!createAMIFaces_)
@ -235,10 +249,15 @@ void Foam::cyclicACMIPolyPatch::scalePatchFaceAreas
// Scale the coupled patch face areas // Scale the coupled patch face areas
vectorField::subField Sf = acmipp.faceAreas(); vectorField::subField Sf = acmipp.faceAreas();
tmp<scalarField> scale(max(tolerance_, mask));
// Scale area
forAll(Sf, facei) forAll(Sf, facei)
{ {
Sf[facei] = faceArea[facei]*max(tolerance_, mask[facei]); Sf[facei] = faceArea[facei]*scale()[facei];
} }
// Cache scaling
const_cast<cyclicACMIPolyPatch&>(acmipp).areaFraction(scale);
// Re-normalise the weights since the effect of overlap is already // Re-normalise the weights since the effect of overlap is already
// accounted for in the area // accounted for in the area

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -821,8 +821,17 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
} }
// Merge into global storage // Merge into global storage
const auto& areaFraction = patch.areaFraction();
forAll(receiveInfo, i) forAll(receiveInfo, i)
{ {
if (areaFraction && areaFraction()[i] <= 0.5)
{
// not coupled
continue;
}
const label meshFacei = cycPatch.start()+i; const label meshFacei = cycPatch.start()+i;
const Type& newInfo = receiveInfo[i]; const Type& newInfo = receiveInfo[i];

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020,2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -235,6 +235,8 @@ void Foam::cellDistFuncs::correctBoundaryFaceCells
Map<label>& nearestFace Map<label>& nearestFace
) const ) const
{ {
const auto& pbm = mesh().boundaryMesh();
// Size neighbours array for maximum possible (= size of largest patch) // Size neighbours array for maximum possible (= size of largest patch)
DynamicList<label> neighbours(maxPatchSize(patchIDs)); DynamicList<label> neighbours(maxPatchSize(patchIDs));
@ -242,15 +244,22 @@ void Foam::cellDistFuncs::correctBoundaryFaceCells
const vectorField& cellCentres = mesh().cellCentres(); const vectorField& cellCentres = mesh().cellCentres();
const labelList& faceOwner = mesh().faceOwner(); const labelList& faceOwner = mesh().faceOwner();
forAll(mesh().boundaryMesh(), patchi) forAll(pbm, patchi)
{ {
if (patchIDs.found(patchi)) if (patchIDs.found(patchi))
{ {
const polyPatch& patch = mesh().boundaryMesh()[patchi]; const polyPatch& patch = pbm[patchi];
const auto& areaFraction = patch.areaFraction();
// Check cells with face on wall // Check cells with face on wall
forAll(patch, patchFacei) forAll(patch, patchFacei)
{ {
if (areaFraction && (areaFraction()[patchFacei] <= 0.5))
{
// is mostly coupled
continue;
}
getPointNeighbours(patch, patchFacei, neighbours); getPointNeighbours(patch, patchFacei, neighbours);
label celli = faceOwner[patch.start() + patchFacei]; label celli = faceOwner[patch.start() + patchFacei];
@ -283,20 +292,42 @@ void Foam::cellDistFuncs::correctBoundaryPointCells
{ {
// Correct all (non-visited) cells with point on wall // Correct all (non-visited) cells with point on wall
const auto& pbm = mesh().boundaryMesh();
const vectorField& cellCentres = mesh().cellCentres(); const vectorField& cellCentres = mesh().cellCentres();
forAll(mesh().boundaryMesh(), patchi) forAll(pbm, patchi)
{ {
if (patchIDs.found(patchi)) if (patchIDs.found(patchi))
{ {
const polyPatch& patch = mesh().boundaryMesh()[patchi]; const polyPatch& patch = pbm[patchi];
const auto& localFaces = patch.localFaces();
const labelList& meshPoints = patch.meshPoints(); const labelList& meshPoints = patch.meshPoints();
const labelListList& pointFaces = patch.pointFaces(); const labelListList& pointFaces = patch.pointFaces();
forAll(meshPoints, meshPointi) bitSet isWallPoint(meshPoints.size(), true);
{ {
const label vertI = meshPoints[meshPointi]; const auto& areaFraction = patch.areaFraction();
// Check cells with face on wall
forAll(patch, patchFacei)
{
if (!areaFraction || (areaFraction()[patchFacei] <= 0.5))
{
// face mostly coupled
isWallPoint.unset(localFaces[patchFacei]);
}
}
}
forAll(meshPoints, patchPointi)
{
const label vertI = meshPoints[patchPointi];
if (!isWallPoint[patchPointi])
{
continue;
}
const labelList& neighbours = mesh().pointCells(vertI); const labelList& neighbours = mesh().pointCells(vertI);
@ -304,7 +335,7 @@ void Foam::cellDistFuncs::correctBoundaryPointCells
{ {
if (!nearestFace.found(celli)) if (!nearestFace.found(celli))
{ {
const labelList& wallFaces = pointFaces[meshPointi]; const labelList& wallFaces = pointFaces[patchPointi];
label minFacei = -1; label minFacei = -1;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020,2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,37 +41,45 @@ template<class TransferType, class TrackingData>
void Foam::patchDataWave<TransferType, TrackingData>::setChangedFaces void Foam::patchDataWave<TransferType, TrackingData>::setChangedFaces
( (
const labelHashSet& patchIDs, const labelHashSet& patchIDs,
labelList& changedFaces, DynamicList<label>& changedFaces,
List<TransferType>& faceDist DynamicList<TransferType>& faceDist
) const ) const
{ {
const polyMesh& mesh = cellDistFuncs::mesh(); const polyMesh& mesh = cellDistFuncs::mesh();
label nChangedFaces = 0;
forAll(mesh.boundaryMesh(), patchi) forAll(mesh.boundaryMesh(), patchi)
{ {
if (patchIDs.found(patchi)) if (patchIDs.found(patchi))
{ {
const polyPatch& patch = mesh.boundaryMesh()[patchi]; const polyPatch& patch = mesh.boundaryMesh()[patchi];
const auto& areaFraction = patch.areaFraction();
const auto faceCentres(patch.faceCentres());
const Field<Type>& patchField = initialPatchValuePtrs_[patchi]; const Field<Type>& patchField = initialPatchValuePtrs_[patchi];
forAll(patch.faceCentres(), patchFacei) forAll(faceCentres, patchFacei)
{ {
label meshFacei = patch.start() + patchFacei; if
(
!areaFraction
|| (areaFraction()[patchFacei] > 0.5) // mostly wall
)
{
label meshFacei = patch.start() + patchFacei;
changedFaces.append(meshFacei);
changedFaces[nChangedFaces] = meshFacei; faceDist.append
faceDist[nChangedFaces] =
TransferType
( (
patch.faceCentres()[patchFacei], TransferType
patchField[patchFacei], (
0.0 faceCentres[patchFacei],
patchField[patchFacei],
0.0
)
); );
}
nChangedFaces++;
} }
} }
} }
@ -222,8 +230,8 @@ void Foam::patchDataWave<TransferType, TrackingData>::correct()
// Count walls // Count walls
label nWalls = sumPatchSize(patchIDs_); label nWalls = sumPatchSize(patchIDs_);
List<TransferType> faceDist(nWalls); DynamicList<TransferType> faceDist(nWalls);
labelList changedFaces(nWalls); DynamicList<label> changedFaces(nWalls);
setChangedFaces(patchIDs_, changedFaces, faceDist); setChangedFaces(patchIDs_, changedFaces, faceDist);

View File

@ -115,8 +115,8 @@ private:
void setChangedFaces void setChangedFaces
( (
const labelHashSet& patchIDs, const labelHashSet& patchIDs,
labelList&, DynamicList<label>& changedFaces,
List<TransferType>& DynamicList<TransferType>& faceDist
) const; ) const;
//- Copy MeshWave values into *this //- Copy MeshWave values into *this

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,50 +36,49 @@ License
void Foam::patchWave::setChangedFaces void Foam::patchWave::setChangedFaces
( (
const labelHashSet& patchIDs, const labelHashSet& patchIDs,
labelList& changedFaces, DynamicList<label>& changedFaces,
List<wallPoint>& faceDist DynamicList<wallPoint>& faceDist
) const ) const
{ {
const polyMesh& mesh = cellDistFuncs::mesh(); const polyMesh& mesh = cellDistFuncs::mesh();
label nChangedFaces = 0;
forAll(mesh.boundaryMesh(), patchi) forAll(mesh.boundaryMesh(), patchi)
{ {
if (patchIDs.found(patchi)) if (patchIDs.found(patchi))
{ {
const polyPatch& patch = mesh.boundaryMesh()[patchi]; const polyPatch& patch = mesh.boundaryMesh()[patchi];
forAll(patch.faceCentres(), patchFacei) const auto& areaFraction = patch.areaFraction();
const auto faceCentres(patch.faceCentres());
forAll(faceCentres, patchFacei)
{ {
label meshFacei = patch.start() + patchFacei; if
(
changedFaces[nChangedFaces] = meshFacei; !areaFraction
|| (areaFraction()[patchFacei] > 0.5) // mostly wall
faceDist[nChangedFaces] = )
wallPoint {
( changedFaces.append(patch.start() + patchFacei);
patch.faceCentres()[patchFacei], faceDist.append(wallPoint(faceCentres[patchFacei], 0.0));
0.0 }
);
nChangedFaces++;
} }
} }
} }
for (const label facei : sourceIDs_) for (const label facei : sourceIDs_)
{ {
changedFaces[nChangedFaces] = facei; changedFaces.append(facei);
faceDist[nChangedFaces] = faceDist.append
(
wallPoint wallPoint
( (
mesh.faceCentres()[facei], mesh.faceCentres()[facei],
0.0 0.0
); )
);
nChangedFaces++;
} }
} }
@ -181,8 +181,8 @@ void Foam::patchWave::correct()
label nPatch = sumPatchSize(patchIDs_) + sourceIDs_.size(); label nPatch = sumPatchSize(patchIDs_) + sourceIDs_.size();
List<wallPoint> faceDist(nPatch); DynamicList<wallPoint> faceDist(nPatch);
labelList changedFaces(nPatch); DynamicList<label> changedFaces(nPatch);
// Set to faceDist information to facecentre on walls. // Set to faceDist information to facecentre on walls.
setChangedFaces(patchIDs_, changedFaces, faceDist); setChangedFaces(patchIDs_, changedFaces, faceDist);

View File

@ -89,8 +89,8 @@ class patchWave
void setChangedFaces void setChangedFaces
( (
const labelHashSet& patchIDs, const labelHashSet& patchIDs,
labelList& changedFaces, DynamicList<label>& changedFaces,
List<wallPoint>& changedInfo DynamicList<wallPoint>& faceDist
) const; ) const;
//- Copy MeshWave cell values. Return number of illegal/unset //- Copy MeshWave cell values. Return number of illegal/unset