blockMesh: Added support for (<block> <face>) specification of patch faces

e.g. for the cavity tutorial the moving wall patch can be specified in
terms of the block vertices as before:

boundary
(
    movingWall
    {
        type wall;
        faces
        (
            (3 7 6 2)
        );
    }
    .
    .
    .

or the new specification of the face as block 0, block face 3:

boundary
(
    movingWall
    {
        type wall;
        faces
        (
            (0 3)
        );
    }
This commit is contained in:
Henry Weller
2016-09-24 08:40:13 +01:00
parent f066a9b54e
commit 93530f1747
4 changed files with 128 additions and 160 deletions

View File

@ -29,6 +29,25 @@ License
void Foam::blockDescriptor::check(const Istream& is) void Foam::blockDescriptor::check(const Istream& is)
{ {
forAll(blockShape_, pi)
{
if (blockShape_[pi] < 0)
{
FatalIOErrorInFunction(is)
<< "Negative point label " << blockShape_[pi]
<< " in block " << *this
<< exit(FatalIOError);
}
else if (blockShape_[pi] >= blockPointField_.size())
{
FatalIOErrorInFunction(is)
<< "Point label " << blockShape_[pi]
<< " out of range 0.." << blockPointField_.size() - 1
<< " in block " << *this
<< exit(FatalIOError);
}
}
const point blockCentre(blockShape_.centre(blockPointField_)); const point blockCentre(blockShape_.centre(blockPointField_));
const faceList faces(blockShape_.faces()); const faceList faces(blockShape_.faces());

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -97,21 +97,16 @@ class blockMesh
// Private Member Functions // Private Member Functions
bool blockLabelsOK template<class Source>
void checkPatchLabels
( (
const label blockLabel, const Source& source,
const word& patchName,
const pointField& points, const pointField& points,
const cellShape& blockShape faceList& patchShapes
) const; ) const;
bool patchLabelsOK void readPatches
(
const label patchLabel,
const pointField& points,
const faceList& patchShapes
) const;
bool readPatches
( (
const dictionary& meshDescription, const dictionary& meshDescription,
faceListList& tmpBlocksPatches, faceListList& tmpBlocksPatches,
@ -120,7 +115,7 @@ class blockMesh
wordList& nbrPatchNames wordList& nbrPatchNames
); );
bool readBoundary void readBoundary
( (
const dictionary& meshDescription, const dictionary& meshDescription,
wordList& patchNames, wordList& patchNames,
@ -131,7 +126,8 @@ class blockMesh
void createCellShapes(cellShapeList& tmpBlockCells); void createCellShapes(cellShapeList& tmpBlockCells);
polyMesh* createTopology(const IOdictionary&, const word& regionName); polyMesh* createTopology(const IOdictionary&, const word& regionName);
void checkBlockMesh(const polyMesh&) const;
void check(const polyMesh&) const;
//- Determine the merge info and the final number of cells/points //- Determine the merge info and the final number of cells/points
void calcMergeInfo(); void calcMergeInfo();

View File

@ -27,7 +27,7 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const void Foam::blockMesh::check(const polyMesh& bm) const
{ {
if (verboseOutput) if (verboseOutput)
{ {
@ -146,82 +146,4 @@ void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const
} }
bool Foam::blockMesh::blockLabelsOK
(
const label blockLabel,
const pointField& points,
const cellShape& blockShape
) const
{
bool ok = true;
forAll(blockShape, blockI)
{
if (blockShape[blockI] < 0)
{
ok = false;
WarningInFunction
<< "out-of-range point label " << blockShape[blockI]
<< " (min = 0"
<< ") in block " << blockLabel << endl;
}
else if (blockShape[blockI] >= points.size())
{
ok = false;
WarningInFunction
<< "out-of-range point label " << blockShape[blockI]
<< " (max = " << points.size() - 1
<< ") in block " << blockLabel << endl;
}
}
return ok;
}
bool Foam::blockMesh::patchLabelsOK
(
const label patchLabel,
const pointField& points,
const faceList& patchFaces
) const
{
bool ok = true;
forAll(patchFaces, facei)
{
const labelList& f = patchFaces[facei];
forAll(f, fp)
{
if (f[fp] < 0)
{
ok = false;
WarningInFunction
<< "out-of-range point label " << f[fp]
<< " (min = 0"
<< ") on patch " << patchLabel
<< ", face " << facei << endl;
}
else if (f[fp] >= points.size())
{
ok = false;
WarningInFunction
<< "out-of-range point label " << f[fp]
<< " (max = " << points.size() - 1
<< ") on patch " << patchLabel
<< ", face " << facei << endl;
}
}
}
return ok;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -29,8 +29,79 @@ License
#include "emptyPolyPatch.H" #include "emptyPolyPatch.H"
#include "cyclicPolyPatch.H" #include "cyclicPolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::blockMesh::readPatches template<class Source>
void Foam::blockMesh::checkPatchLabels
(
const Source& source,
const word& patchName,
const pointField& points,
faceList& patchFaces
) const
{
forAll(patchFaces, facei)
{
face& f = patchFaces[facei];
// Replace (<block> <face>) face description
// with the corresponding block face
if (f.size() == 2)
{
const label bi = f[0];
const label fi = f[1];
if (bi >= size())
{
FatalIOErrorInFunction(source)
<< "Block index out of range for patch face " << f << nl
<< " Number of blocks = " << size()
<< ", index = " << f[0] << nl
<< " on patch " << patchName << ", face " << facei
<< exit(FatalIOError);
}
else if (fi >= operator[](bi).blockShape().faces().size())
{
FatalIOErrorInFunction(source)
<< "Block face index out of range for patch face " << f
<< nl
<< " Number of block faces = "
<< operator[](bi).blockShape().faces().size()
<< ", index = " << f[1] << nl
<< " on patch " << patchName << ", face " << facei
<< exit(FatalIOError);
}
else
{
f = operator[](bi).blockShape().faces()[fi];
}
}
else
{
forAll(f, fp)
{
if (f[fp] < 0)
{
FatalIOErrorInFunction(source)
<< "Negative point label " << f[fp] << nl
<< " on patch " << patchName << ", face " << facei
<< exit(FatalIOError);
}
else if (f[fp] >= points.size())
{
FatalIOErrorInFunction(source)
<< "Point label " << f[fp]
<< " out of range 0.." << points.size() - 1 << nl
<< " on patch " << patchName << ", face " << facei
<< exit(FatalIOError);
}
}
}
}
}
void Foam::blockMesh::readPatches
( (
const dictionary& meshDescription, const dictionary& meshDescription,
faceListList& tmpBlocksPatches, faceListList& tmpBlocksPatches,
@ -39,8 +110,6 @@ bool Foam::blockMesh::readPatches
wordList& nbrPatchNames wordList& nbrPatchNames
) )
{ {
bool topologyOK = true;
ITstream& patchStream(meshDescription.lookup("patches")); ITstream& patchStream(meshDescription.lookup("patches"));
// read number of patches in mesh // read number of patches in mesh
@ -94,22 +163,22 @@ bool Foam::blockMesh::readPatches
patchStream >> tmpBlocksPatches[nPatches]; patchStream >> tmpBlocksPatches[nPatches];
// Catch multiple patches asap. // Check for multiple patches
for (label i = 0; i < nPatches; i++) for (label i = 0; i < nPatches; i++)
{ {
if (patchNames[nPatches] == patchNames[i]) if (patchNames[nPatches] == patchNames[i])
{ {
FatalErrorInFunction FatalIOErrorInFunction(patchStream)
<< "Duplicate patch " << patchNames[nPatches] << "Duplicate patch " << patchNames[nPatches]
<< " at line " << patchStream.lineNumber() << " at line " << patchStream.lineNumber()
<< ". Exiting !" << nl << exit(FatalIOError);
<< exit(FatalError);
} }
} }
topologyOK = topologyOK && patchLabelsOK checkPatchLabels
( (
nPatches, patchStream,
patchNames[nPatches],
blockPointField_, blockPointField_,
tmpBlocksPatches[nPatches] tmpBlocksPatches[nPatches]
); );
@ -124,13 +193,13 @@ bool Foam::blockMesh::readPatches
word halfA = patchNames[nPatches-1] + "_half0"; word halfA = patchNames[nPatches-1] + "_half0";
word halfB = patchNames[nPatches-1] + "_half1"; word halfB = patchNames[nPatches-1] + "_half1";
WarningInFunction FatalIOErrorInFunction(patchStream)
<< "Old-style cyclic definition." << "Old-style cyclic definition."
<< " Splitting patch " << " Splitting patch "
<< patchNames[nPatches-1] << " into two halves " << patchNames[nPatches-1] << " into two halves "
<< halfA << " and " << halfB << endl << halfA << " and " << halfB << endl
<< " Alternatively use new 'boundary' dictionary syntax." << " Alternatively use new 'boundary' dictionary syntax."
<< endl; << exit(FatalIOError);
// Add extra patch // Add extra patch
if (tmpBlocksPatches.size() <= nPatches) if (tmpBlocksPatches.size() <= nPatches)
@ -152,10 +221,10 @@ bool Foam::blockMesh::readPatches
// Split faces // Split faces
if ((tmpBlocksPatches[nPatches-1].size() % 2) != 0) if ((tmpBlocksPatches[nPatches-1].size() % 2) != 0)
{ {
FatalErrorInFunction FatalIOErrorInFunction(patchStream)
<< "Size of cyclic faces is not a multiple of 2 :" << "Size of cyclic faces is not a multiple of 2 :"
<< tmpBlocksPatches[nPatches-1] << tmpBlocksPatches[nPatches-1]
<< exit(FatalError); << exit(FatalIOError);
} }
label sz = tmpBlocksPatches[nPatches-1].size()/2; label sz = tmpBlocksPatches[nPatches-1].size()/2;
faceList unsplitFaces(tmpBlocksPatches[nPatches-1], true); faceList unsplitFaces(tmpBlocksPatches[nPatches-1], true);
@ -177,12 +246,10 @@ bool Foam::blockMesh::readPatches
// Read end of blocks // Read end of blocks
patchStream.readEnd("patches"); patchStream.readEnd("patches");
return topologyOK;
} }
bool Foam::blockMesh::readBoundary void Foam::blockMesh::readBoundary
( (
const dictionary& meshDescription, const dictionary& meshDescription,
wordList& patchNames, wordList& patchNames,
@ -190,8 +257,6 @@ bool Foam::blockMesh::readBoundary
PtrList<dictionary>& patchDicts PtrList<dictionary>& patchDicts
) )
{ {
bool topologyOK = true;
// Read like boundary file // Read like boundary file
const PtrList<entry> patchesInfo const PtrList<entry> patchesInfo
( (
@ -210,24 +275,26 @@ bool Foam::blockMesh::readBoundary
{ {
FatalIOErrorInFunction(meshDescription) FatalIOErrorInFunction(meshDescription)
<< "Entry " << patchInfo << " in boundary section is not a" << "Entry " << patchInfo << " in boundary section is not a"
<< " valid dictionary." << exit(FatalIOError); << " valid dictionary."
<< exit(FatalIOError);
} }
patchNames[patchi] = patchInfo.keyword(); patchNames[patchi] = patchInfo.keyword();
// Construct dictionary
// Construct patch dictionary
patchDicts.set(patchi, new dictionary(patchInfo.dict())); patchDicts.set(patchi, new dictionary(patchInfo.dict()));
// Read block faces // Read block faces
patchDicts[patchi].lookup("faces") >> tmpBlocksPatches[patchi]; patchDicts[patchi].lookup("faces") >> tmpBlocksPatches[patchi];
topologyOK = topologyOK && patchLabelsOK checkPatchLabels
( (
patchi, patchInfo.dict(),
patchNames[patchi],
blockPointField_, blockPointField_,
tmpBlocksPatches[patchi] tmpBlocksPatches[patchi]
); );
} }
return topologyOK;
} }
@ -241,14 +308,7 @@ void Foam::blockMesh::createCellShapes
tmpBlockCells.setSize(blocks.size()); tmpBlockCells.setSize(blocks.size());
forAll(blocks, blockI) forAll(blocks, blockI)
{ {
tmpBlockCells[blockI] = cellShape(blocks[blockI].blockShape()); tmpBlockCells[blockI] = blocks[blockI].blockShape();
if (tmpBlockCells[blockI].mag(blockPointField_) < 0.0)
{
WarningInFunction
<< "negative volume block : " << blockI
<< ", probably defined inside-out" << endl;
}
} }
} }
@ -261,8 +321,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
const word& regionName const word& regionName
) )
{ {
bool topologyOK = true;
blockList& blocks = *this; blockList& blocks = *this;
word defaultPatchName = "defaultFaces"; word defaultPatchName = "defaultFaces";
@ -411,13 +469,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
) )
); );
topologyOK = topologyOK && blockLabelsOK
(
nBlocks,
blockPointField_,
blocks[nBlocks].blockShape()
);
nBlocks++; nBlocks++;
is >> lastToken; is >> lastToken;
@ -448,7 +499,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
wordList patchTypes; wordList patchTypes;
wordList nbrPatchNames; wordList nbrPatchNames;
topologyOK = topologyOK && readPatches readPatches
( (
meshDescription, meshDescription,
tmpBlocksPatches, tmpBlocksPatches,
@ -457,13 +508,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
nbrPatchNames nbrPatchNames
); );
if (!topologyOK)
{
FatalErrorInFunction
<< "Cannot create mesh due to errors in topology, exiting !"
<< nl << exit(FatalError);
}
Info<< nl << "Creating block mesh topology" << endl; Info<< nl << "Creating block mesh topology" << endl;
cellShapeList tmpBlockCells(blocks.size()); cellShapeList tmpBlockCells(blocks.size());
@ -504,14 +548,12 @@ Foam::polyMesh* Foam::blockMesh::createTopology
} }
else if (word(dict.lookup("type")) != patchTypes[patchi]) else if (word(dict.lookup("type")) != patchTypes[patchi])
{ {
IOWarningInFunction FatalIOErrorInFunction(meshDescription)
( << "For patch " << patchNames[patchi]
meshDescription
) << "For patch " << patchNames[patchi]
<< " overriding type '" << patchTypes[patchi] << " overriding type '" << patchTypes[patchi]
<< "' with '" << word(dict.lookup("type")) << "' with '" << word(dict.lookup("type"))
<< "' (read from boundary file)" << "' (read from boundary file)"
<< endl; << exit(FatalIOError);
} }
// Override neighbourpatch name // Override neighbourpatch name
@ -521,7 +563,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
} }
} }
blockMeshPtr = new polyMesh blockMeshPtr = new polyMesh
( (
IOobject IOobject
@ -548,7 +589,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
faceListList tmpBlocksPatches; faceListList tmpBlocksPatches;
PtrList<dictionary> patchDicts; PtrList<dictionary> patchDicts;
topologyOK = topologyOK && readBoundary readBoundary
( (
meshDescription, meshDescription,
patchNames, patchNames,
@ -556,21 +597,11 @@ Foam::polyMesh* Foam::blockMesh::createTopology
patchDicts patchDicts
); );
if (!topologyOK)
{
FatalErrorInFunction
<< "Cannot create mesh due to errors in topology, exiting !"
<< nl << exit(FatalError);
}
Info<< nl << "Creating block mesh topology" << endl; Info<< nl << "Creating block mesh topology" << endl;
cellShapeList tmpBlockCells(blocks.size()); cellShapeList tmpBlockCells(blocks.size());
createCellShapes(tmpBlockCells); createCellShapes(tmpBlockCells);
// Extract
blockMeshPtr = new polyMesh blockMeshPtr = new polyMesh
( (
IOobject IOobject
@ -592,7 +623,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
); );
} }
checkBlockMesh(*blockMeshPtr); check(*blockMeshPtr);
return blockMeshPtr; return blockMeshPtr;
} }