mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- more dictionary-like methods, enforce keyType::LITERAL for all
lookups to avoid any spurious keyword matching.
- new readEntry, readIfPresent methods
- The get() method replaces the now deprecate lookup() method.
- Deprecate lookupOrFailsafe()
Failsafe behaviour is now an optional parameter for lookupOrDefault,
which makes it easier to tailor behaviour at runtime.
- output of the names is now always flatted without line-breaks.
Thus,
os << flatOutput(someEnumNames.names()) << nl;
os << someEnumNames << nl;
both generate the same output.
- Constructor now uses C-string (const char*) directly instead of
Foam::word in its initializer_list.
- Remove special enum + initializer_list constructor form since
it can create unbounded lookup indices.
- Removd old hasEnum, hasName forms that were provided during initial
transition from NamedEnum.
- Added static_assert on Enum contents to restrict to enum or
integral values. Should not likely be using this class to enumerate
other things since it internally uses an 'int' for its values.
Changed volumeType accordingly to enumerate on its type (enum),
not the class itself.
287 lines
7.4 KiB
C
287 lines
7.4 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OpenFOAM 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.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "channelIndex.H"
|
|
#include "boolList.H"
|
|
#include "syncTools.H"
|
|
#include "OFstream.H"
|
|
#include "meshTools.H"
|
|
#include "Time.H"
|
|
#include "SortableList.H"
|
|
|
|
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
|
|
|
|
const Foam::Enum
|
|
<
|
|
Foam::vector::components
|
|
>
|
|
Foam::channelIndex::vectorComponentsNames_
|
|
({
|
|
{ vector::components::X, "x" },
|
|
{ vector::components::Y, "y" },
|
|
{ vector::components::Z, "z" },
|
|
});
|
|
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
// Determines face blocking
|
|
void Foam::channelIndex::walkOppositeFaces
|
|
(
|
|
const polyMesh& mesh,
|
|
const labelList& startFaces,
|
|
boolList& blockedFace
|
|
)
|
|
{
|
|
const cellList& cells = mesh.cells();
|
|
const faceList& faces = mesh.faces();
|
|
const label nBnd = mesh.nBoundaryFaces();
|
|
|
|
DynamicList<label> frontFaces(startFaces);
|
|
forAll(frontFaces, i)
|
|
{
|
|
label facei = frontFaces[i];
|
|
blockedFace[facei] = true;
|
|
}
|
|
|
|
while (returnReduce(frontFaces.size(), sumOp<label>()) > 0)
|
|
{
|
|
// Transfer across.
|
|
boolList isFrontBndFace(nBnd, false);
|
|
forAll(frontFaces, i)
|
|
{
|
|
label facei = frontFaces[i];
|
|
|
|
if (!mesh.isInternalFace(facei))
|
|
{
|
|
isFrontBndFace[facei-mesh.nInternalFaces()] = true;
|
|
}
|
|
}
|
|
syncTools::swapBoundaryFaceList(mesh, isFrontBndFace);
|
|
|
|
// Add
|
|
forAll(isFrontBndFace, i)
|
|
{
|
|
label facei = mesh.nInternalFaces()+i;
|
|
if (isFrontBndFace[i] && !blockedFace[facei])
|
|
{
|
|
blockedFace[facei] = true;
|
|
frontFaces.append(facei);
|
|
}
|
|
}
|
|
|
|
// Transfer across cells
|
|
DynamicList<label> newFrontFaces(frontFaces.size());
|
|
|
|
forAll(frontFaces, i)
|
|
{
|
|
label facei = frontFaces[i];
|
|
|
|
{
|
|
const cell& ownCell = cells[mesh.faceOwner()[facei]];
|
|
|
|
label oppositeFacei = ownCell.opposingFaceLabel(facei, faces);
|
|
|
|
if (oppositeFacei == -1)
|
|
{
|
|
FatalErrorInFunction
|
|
<< "Face:" << facei << " owner cell:" << ownCell
|
|
<< " is not a hex?" << abort(FatalError);
|
|
}
|
|
else
|
|
{
|
|
if (!blockedFace[oppositeFacei])
|
|
{
|
|
blockedFace[oppositeFacei] = true;
|
|
newFrontFaces.append(oppositeFacei);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mesh.isInternalFace(facei))
|
|
{
|
|
const cell& neiCell = mesh.cells()[mesh.faceNeighbour()[facei]];
|
|
|
|
label oppositeFacei = neiCell.opposingFaceLabel(facei, faces);
|
|
|
|
if (oppositeFacei == -1)
|
|
{
|
|
FatalErrorInFunction
|
|
<< "Face:" << facei << " neighbour cell:" << neiCell
|
|
<< " is not a hex?" << abort(FatalError);
|
|
}
|
|
else
|
|
{
|
|
if (!blockedFace[oppositeFacei])
|
|
{
|
|
blockedFace[oppositeFacei] = true;
|
|
newFrontFaces.append(oppositeFacei);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
frontFaces.transfer(newFrontFaces);
|
|
}
|
|
}
|
|
|
|
|
|
// Calculate regions.
|
|
void Foam::channelIndex::calcLayeredRegions
|
|
(
|
|
const polyMesh& mesh,
|
|
const labelList& startFaces
|
|
)
|
|
{
|
|
boolList blockedFace(mesh.nFaces(), false);
|
|
walkOppositeFaces
|
|
(
|
|
mesh,
|
|
startFaces,
|
|
blockedFace
|
|
);
|
|
|
|
|
|
if (false)
|
|
{
|
|
OFstream str(mesh.time().path()/"blockedFaces.obj");
|
|
label vertI = 0;
|
|
forAll(blockedFace, facei)
|
|
{
|
|
if (blockedFace[facei])
|
|
{
|
|
const face& f = mesh.faces()[facei];
|
|
forAll(f, fp)
|
|
{
|
|
meshTools::writeOBJ(str, mesh.points()[f[fp]]);
|
|
}
|
|
str<< 'f';
|
|
forAll(f, fp)
|
|
{
|
|
str << ' ' << vertI+fp+1;
|
|
}
|
|
str << nl;
|
|
vertI += f.size();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Do analysis for connected regions
|
|
cellRegion_.reset(new regionSplit(mesh, blockedFace));
|
|
|
|
Info<< "Detected " << cellRegion_().nRegions() << " layers." << nl << endl;
|
|
|
|
// Sum number of entries per region
|
|
regionCount_ = regionSum(scalarField(mesh.nCells(), 1.0));
|
|
|
|
// Average cell centres to determine ordering.
|
|
pointField regionCc
|
|
(
|
|
regionSum(mesh.cellCentres())
|
|
/ regionCount_
|
|
);
|
|
|
|
SortableList<scalar> sortComponent(regionCc.component(dir_));
|
|
|
|
sortMap_ = sortComponent.indices();
|
|
|
|
y_ = sortComponent;
|
|
|
|
if (symmetric_)
|
|
{
|
|
y_.setSize(cellRegion_().nRegions()/2);
|
|
}
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
Foam::channelIndex::channelIndex
|
|
(
|
|
const polyMesh& mesh,
|
|
const dictionary& dict
|
|
)
|
|
:
|
|
symmetric_(dict.get<bool>("symmetric")),
|
|
dir_(vectorComponentsNames_.get("component", dict))
|
|
{
|
|
const polyBoundaryMesh& patches = mesh.boundaryMesh();
|
|
|
|
const wordList patchNames(dict.get<wordList>("patches"));
|
|
|
|
label nFaces = 0;
|
|
|
|
forAll(patchNames, i)
|
|
{
|
|
const label patchi = patches.findPatchID(patchNames[i]);
|
|
|
|
if (patchi == -1)
|
|
{
|
|
FatalErrorInFunction
|
|
<< "Illegal patch " << patchNames[i]
|
|
<< ". Valid patches are " << patches.name()
|
|
<< exit(FatalError);
|
|
}
|
|
|
|
nFaces += patches[patchi].size();
|
|
}
|
|
|
|
labelList startFaces(nFaces);
|
|
nFaces = 0;
|
|
|
|
forAll(patchNames, i)
|
|
{
|
|
const polyPatch& pp = patches[patchNames[i]];
|
|
|
|
forAll(pp, j)
|
|
{
|
|
startFaces[nFaces++] = pp.start()+j;
|
|
}
|
|
}
|
|
|
|
// Calculate regions.
|
|
calcLayeredRegions(mesh, startFaces);
|
|
}
|
|
|
|
|
|
Foam::channelIndex::channelIndex
|
|
(
|
|
const polyMesh& mesh,
|
|
const labelList& startFaces,
|
|
const bool symmetric,
|
|
const direction dir
|
|
)
|
|
:
|
|
symmetric_(symmetric),
|
|
dir_(dir)
|
|
{
|
|
// Calculate regions.
|
|
calcLayeredRegions(mesh, startFaces);
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|