2015-05-11 10:41:43 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2015-05-11 10:41:43 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2015-05-17 13:32:07 +00:00
|
|
|
This file is part of foam-extend.
|
2015-05-11 10:41:43 +00:00
|
|
|
|
2015-05-17 13:32:07 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2015-05-11 10:41:43 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2015-05-17 13:32:07 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2015-05-11 10:41:43 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2015-05-17 13:32:07 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2015-05-11 10:41:43 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-05-17 13:32:07 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2015-05-11 10:41:43 +00:00
|
|
|
|
|
|
|
Application
|
|
|
|
writeIbMasks
|
|
|
|
|
|
|
|
Description
|
|
|
|
Calculate and write immersed boundary masks
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
2017-12-06 21:19:44 +00:00
|
|
|
#include "calc.H"
|
|
|
|
#include "fvc.H"
|
|
|
|
#include "fvMatrices.H"
|
2015-05-11 10:41:43 +00:00
|
|
|
#include "immersedBoundaryFvPatch.H"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
2017-12-06 21:19:44 +00:00
|
|
|
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
|
2015-05-11 10:41:43 +00:00
|
|
|
{
|
2017-12-06 21:19:44 +00:00
|
|
|
Info<< nl << "Calculating gamma" << endl;
|
|
|
|
volScalarField gamma
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
"gamma",
|
|
|
|
runTime.timeName(),
|
|
|
|
mesh,
|
|
|
|
IOobject::NO_READ,
|
|
|
|
IOobject::AUTO_WRITE
|
|
|
|
),
|
|
|
|
mesh,
|
2017-12-30 09:32:32 +00:00
|
|
|
dimensionedScalar("one", dimless, 1)
|
2017-12-06 21:19:44 +00:00
|
|
|
);
|
|
|
|
gamma.internalField() = mesh.V()/mesh.cellVolumes();
|
2017-12-30 09:32:32 +00:00
|
|
|
|
|
|
|
// Report minimal live cell volume
|
|
|
|
scalar minLiveGamma = GREAT;
|
|
|
|
label minLiveCell = -1;
|
|
|
|
const scalarField& gammaIn = gamma.internalField();
|
2018-05-29 08:30:29 +00:00
|
|
|
|
2017-12-30 09:32:32 +00:00
|
|
|
forAll (mesh.boundary(), patchI)
|
|
|
|
{
|
|
|
|
if (isA<immersedBoundaryFvPatch>(mesh.boundary()[patchI]))
|
|
|
|
{
|
|
|
|
const immersedBoundaryFvPatch& ibPatch =
|
|
|
|
refCast<const immersedBoundaryFvPatch>
|
|
|
|
(
|
|
|
|
mesh.boundary()[patchI]
|
|
|
|
);
|
|
|
|
|
|
|
|
const labelList& ibCells = ibPatch.ibPolyPatch().ibCells();
|
|
|
|
|
|
|
|
forAll (ibCells, dcI)
|
|
|
|
{
|
|
|
|
if (gammaIn[ibCells[dcI]] < minLiveGamma)
|
|
|
|
{
|
|
|
|
minLiveGamma = gammaIn[ibCells[dcI]];
|
|
|
|
minLiveCell = ibCells[dcI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "Min live cell " << minLiveCell
|
|
|
|
<< " gamma = " << minLiveGamma
|
|
|
|
<< endl;
|
2017-12-06 21:19:44 +00:00
|
|
|
|
|
|
|
Info<< nl << "Calculating sGamma" << endl;
|
|
|
|
surfaceScalarField sGamma
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
"sGamma",
|
|
|
|
runTime.timeName(),
|
|
|
|
mesh,
|
|
|
|
IOobject::NO_READ,
|
|
|
|
IOobject::AUTO_WRITE
|
|
|
|
),
|
|
|
|
mesh,
|
|
|
|
dimensionedScalar("one", dimless, 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
const surfaceScalarField& magSf = mesh.magSf();
|
|
|
|
const scalarField magFaceAreas = mag(mesh.faceAreas());
|
2017-12-30 09:32:32 +00:00
|
|
|
|
2017-12-06 21:19:44 +00:00
|
|
|
sGamma.internalField() =
|
|
|
|
magSf.internalField()/
|
|
|
|
scalarField::subField(magFaceAreas, mesh.nInternalFaces());
|
|
|
|
|
|
|
|
forAll (mesh.boundary(), patchI)
|
|
|
|
{
|
|
|
|
if (!isA<immersedBoundaryFvPatch>(mesh.boundary()[patchI]))
|
|
|
|
{
|
|
|
|
sGamma.boundaryField()[patchI] =
|
|
|
|
magSf.boundaryField()[patchI]/
|
|
|
|
mesh.boundary()[patchI].patchSlice(magFaceAreas);
|
|
|
|
|
|
|
|
gamma.boundaryField()[patchI] =
|
|
|
|
sGamma.boundaryField()[patchI];
|
|
|
|
}
|
|
|
|
}
|
2017-12-30 09:32:32 +00:00
|
|
|
|
2017-12-06 21:19:44 +00:00
|
|
|
sGamma.write();
|
2018-09-06 17:34:14 +00:00
|
|
|
gamma.write();
|
2017-12-06 21:19:44 +00:00
|
|
|
|
|
|
|
// Check consistency of face area vectors
|
|
|
|
|
|
|
|
Info<< nl << "Calculating divSf" << endl;
|
|
|
|
volVectorField divSf
|
|
|
|
(
|
|
|
|
"divSf",
|
2019-03-13 12:17:43 +00:00
|
|
|
fvc::surfaceIntegrate(mesh.Sf())
|
2017-12-06 21:19:44 +00:00
|
|
|
);
|
|
|
|
divSf.write();
|
|
|
|
|
2019-03-13 12:17:43 +00:00
|
|
|
// Check divergence of face area vectors. Note: scale by the volume
|
|
|
|
// to avoid bias towards small cells. HJ, 13/Mar/2019
|
|
|
|
scalarField magDivSf = mag(divSf)().internalField()*mesh.V().field();
|
2017-12-06 21:19:44 +00:00
|
|
|
|
|
|
|
Info<< "Face areas divergence (min, max, average): "
|
|
|
|
<< "(" << min(magDivSf) << " " << max(magDivSf)
|
|
|
|
<< " " << average(magDivSf) << ")"
|
|
|
|
<< endl;
|
|
|
|
|
2019-03-13 12:17:43 +00:00
|
|
|
if (max(magDivSf) > primitiveMesh::closedThreshold_)
|
2017-12-06 21:19:44 +00:00
|
|
|
{
|
|
|
|
WarningIn("writeIbMasks")
|
|
|
|
<< "Possible problem with immersed boundary face area vectors: "
|
|
|
|
<< max(magDivSf)
|
|
|
|
<< endl;
|
2019-03-13 12:17:43 +00:00
|
|
|
|
|
|
|
scalar maxOpenCell = 0;
|
|
|
|
label maxOpenCellIndex = -1;
|
|
|
|
|
|
|
|
forAll (magDivSf, cellI)
|
|
|
|
{
|
|
|
|
if (magDivSf[cellI] > maxOpenCell)
|
|
|
|
{
|
|
|
|
maxOpenCell = magDivSf[cellI];
|
|
|
|
maxOpenCellIndex = cellI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (magDivSf[cellI] > 1e-9)
|
|
|
|
{
|
|
|
|
Info<< "Open cell " << cellI << ": " << magDivSf[cellI]
|
|
|
|
<< " gamma: " << gamma[cellI] << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const surfaceVectorField& Sf = mesh.Sf();
|
|
|
|
|
|
|
|
const labelList& openCellFaces = mesh.cells()[maxOpenCellIndex];
|
|
|
|
|
|
|
|
scalarField openCellFaceGamma(openCellFaces.size(), scalar(-1));
|
|
|
|
|
|
|
|
vectorField openFaceAreas
|
|
|
|
(
|
|
|
|
IndirectList<vector>(mesh.faceAreas(), openCellFaces)()
|
|
|
|
);
|
|
|
|
|
|
|
|
vectorField adjustedFaceAreas(openCellFaces.size());
|
|
|
|
|
|
|
|
forAll (openCellFaces, cfI)
|
|
|
|
{
|
|
|
|
const label& faceI = openCellFaces[cfI];
|
|
|
|
|
|
|
|
if (mesh.isInternalFace(faceI))
|
|
|
|
{
|
|
|
|
openCellFaceGamma[cfI] = sGamma.internalField()[faceI];
|
|
|
|
|
|
|
|
adjustedFaceAreas[cfI] = Sf.internalField()[faceI];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const label patchI = mesh.boundaryMesh().whichPatch(faceI);
|
|
|
|
|
|
|
|
const label patchFaceI =
|
|
|
|
mesh.boundaryMesh()[patchI].whichFace(faceI);
|
|
|
|
|
|
|
|
openCellFaceGamma[cfI] =
|
|
|
|
sGamma.boundaryField()[patchI][patchFaceI];
|
|
|
|
|
|
|
|
adjustedFaceAreas[cfI] = Sf.boundaryField()[patchI][patchFaceI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find faces on IB patches
|
|
|
|
vectorField ibVectors(mesh.boundary().size());
|
|
|
|
label nIbVectors = 0;
|
|
|
|
|
|
|
|
forAll (mesh.boundary(), patchI)
|
|
|
|
{
|
|
|
|
if (isA<immersedBoundaryFvPatch>(mesh.boundary()[patchI]))
|
|
|
|
{
|
|
|
|
const labelList& ibpFC = mesh.boundary()[patchI].faceCells();
|
|
|
|
|
|
|
|
forAll (ibpFC, ibpFCI)
|
|
|
|
{
|
|
|
|
if (ibpFC[ibpFCI] == maxOpenCellIndex)
|
|
|
|
{
|
|
|
|
ibVectors[nIbVectors] =
|
|
|
|
mesh.Sf().boundaryField()[patchI][ibpFCI];
|
|
|
|
|
|
|
|
nIbVectors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ibVectors.setSize(nIbVectors);
|
|
|
|
|
|
|
|
Pout<< "Max open cell index: " << maxOpenCellIndex
|
|
|
|
<< " magDivSf = " << maxOpenCell << nl
|
|
|
|
<< "faces: " << openCellFaces << nl
|
|
|
|
<< " original areas: " << openFaceAreas << nl
|
|
|
|
<< "sGamma: " << openCellFaceGamma << nl
|
|
|
|
<< "adjusted areas: " << adjustedFaceAreas << nl
|
|
|
|
<< "cut face areas: " << ibVectors << nl
|
|
|
|
<< "Sum normal areas: " << sum(openFaceAreas) << nl
|
|
|
|
<< "Sum iB areas: " << sum(ibVectors) << nl
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
2017-12-06 21:19:44 +00:00
|
|
|
}
|
2017-12-30 09:32:32 +00:00
|
|
|
|
|
|
|
Info<< endl;
|
2015-05-11 10:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|