Commit 93530f17 authored by Henry Weller's avatar Henry Weller
Browse files

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)
        );
    }
parent f066a9b5
......@@ -29,6 +29,25 @@ License
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 faceList faces(blockShape_.faces());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -97,21 +97,16 @@ class blockMesh
// Private Member Functions
bool blockLabelsOK
template<class Source>
void checkPatchLabels
(
const label blockLabel,
const Source& source,
const word& patchName,
const pointField& points,
const cellShape& blockShape
faceList& patchShapes
) const;
bool patchLabelsOK
(
const label patchLabel,
const pointField& points,
const faceList& patchShapes
) const;
bool readPatches
void readPatches
(
const dictionary& meshDescription,
faceListList& tmpBlocksPatches,
......@@ -120,7 +115,7 @@ class blockMesh
wordList& nbrPatchNames
);
bool readBoundary
void readBoundary
(
const dictionary& meshDescription,
wordList& patchNames,
......@@ -131,7 +126,8 @@ class blockMesh
void createCellShapes(cellShapeList& tmpBlockCells);
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
void calcMergeInfo();
......
......@@ -27,7 +27,7 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const
void Foam::blockMesh::check(const polyMesh& bm) const
{
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;
}
// ************************************************************************* //
......@@ -29,8 +29,79 @@ License
#include "emptyPolyPatch.H"
#include "cyclicPolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
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);
}
}
}
}
}
bool Foam::blockMesh::readPatches
void Foam::blockMesh::readPatches
(
const dictionary& meshDescription,
faceListList& tmpBlocksPatches,
......@@ -39,8 +110,6 @@ bool Foam::blockMesh::readPatches
wordList& nbrPatchNames
)
{
bool topologyOK = true;
ITstream& patchStream(meshDescription.lookup("patches"));
// read number of patches in mesh
......@@ -94,22 +163,22 @@ bool Foam::blockMesh::readPatches
patchStream >> tmpBlocksPatches[nPatches];
// Catch multiple patches asap.
// Check for multiple patches
for (label i = 0; i < nPatches; i++)
{
if (patchNames[nPatches] == patchNames[i])
{
FatalErrorInFunction
FatalIOErrorInFunction(patchStream)
<< "Duplicate patch " << patchNames[nPatches]
<< " at line " << patchStream.lineNumber()
<< ". Exiting !" << nl
<< exit(FatalError);
<< exit(FatalIOError);
}
}
topologyOK = topologyOK && patchLabelsOK
checkPatchLabels
(
nPatches,
patchStream,
patchNames[nPatches],
blockPointField_,
tmpBlocksPatches[nPatches]
);
......@@ -124,13 +193,13 @@ bool Foam::blockMesh::readPatches
word halfA = patchNames[nPatches-1] + "_half0";
word halfB = patchNames[nPatches-1] + "_half1";
WarningInFunction
FatalIOErrorInFunction(patchStream)
<< "Old-style cyclic definition."
<< " Splitting patch "
<< patchNames[nPatches-1] << " into two halves "
<< halfA << " and " << halfB << endl
<< " Alternatively use new 'boundary' dictionary syntax."
<< endl;
<< exit(FatalIOError);
// Add extra patch
if (tmpBlocksPatches.size() <= nPatches)
......@@ -152,10 +221,10 @@ bool Foam::blockMesh::readPatches
// Split faces
if ((tmpBlocksPatches[nPatches-1].size() % 2) != 0)
{
FatalErrorInFunction
FatalIOErrorInFunction(patchStream)
<< "Size of cyclic faces is not a multiple of 2 :"
<< tmpBlocksPatches[nPatches-1]
<< exit(FatalError);
<< exit(FatalIOError);
}
label sz = tmpBlocksPatches[nPatches-1].size()/2;
faceList unsplitFaces(tmpBlocksPatches[nPatches-1], true);
......@@ -177,12 +246,10 @@ bool Foam::blockMesh::readPatches
// Read end of blocks
patchStream.readEnd("patches");
return topologyOK;
}
bool Foam::blockMesh::readBoundary
void Foam::blockMesh::readBoundary
(
const dictionary& meshDescription,
wordList& patchNames,
......@@ -190,8 +257,6 @@ bool Foam::blockMesh::readBoundary
PtrList<dictionary>& patchDicts
)
{
bool topologyOK = true;
// Read like boundary file
const PtrList<entry> patchesInfo
(
......@@ -210,24 +275,26 @@ bool Foam::blockMesh::readBoundary
{
FatalIOErrorInFunction(meshDescription)
<< "Entry " << patchInfo << " in boundary section is not a"
<< " valid dictionary." << exit(FatalIOError);
<< " valid dictionary."
<< exit(FatalIOError);
}
patchNames[patchi] = patchInfo.keyword();
// Construct dictionary
// Construct patch dictionary
patchDicts.set(patchi, new dictionary(patchInfo.dict()));
// Read block faces
patchDicts[patchi].lookup("faces") >> tmpBlocksPatches[patchi];
topologyOK = topologyOK && patchLabelsOK
checkPatchLabels
(
patchi,
patchInfo.dict(),
patchNames[patchi],
blockPointField_,
tmpBlocksPatches[patchi]
);
}
return topologyOK;
}
......@@ -241,14 +308,7 @@ void Foam::blockMesh::createCellShapes
tmpBlockCells.setSize(blocks.size());
forAll(blocks, blockI)
{
tmpBlockCells[blockI] = cellShape(blocks[blockI].blockShape());
if (tmpBlockCells[blockI].mag(blockPointField_) < 0.0)
{
WarningInFunction
<< "negative volume block : " << blockI
<< ", probably defined inside-out" << endl;
}
tmpBlockCells[blockI] = blocks[blockI].blockShape();
}
}
......@@ -261,8 +321,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
const word& regionName
)
{
bool topologyOK = true;
blockList& blocks = *this;
word defaultPatchName = "defaultFaces";
......@@ -411,13 +469,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
)
);
topologyOK = topologyOK && blockLabelsOK
(
nBlocks,
blockPointField_,
blocks[nBlocks].blockShape()
);
nBlocks++;
is >> lastToken;
......@@ -448,7 +499,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
wordList patchTypes;
wordList nbrPatchNames;
topologyOK = topologyOK && readPatches
readPatches
(
meshDescription,
tmpBlocksPatches,
......@@ -457,13 +508,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
nbrPatchNames
);
if (!topologyOK)
{
FatalErrorInFunction
<< "Cannot create mesh due to errors in topology, exiting !"
<< nl << exit(FatalError);
}
Info<< nl << "Creating block mesh topology" << endl;
cellShapeList tmpBlockCells(blocks.size());
......@@ -504,14 +548,12 @@ Foam::polyMesh* Foam::blockMesh::createTopology
}
else if (word(dict.lookup("type")) != patchTypes[patchi])
{
IOWarningInFunction
(
meshDescription
) << "For patch " << patchNames[patchi]
FatalIOErrorInFunction(meshDescription)
<< "For patch " << patchNames[patchi]
<< " overriding type '" << patchTypes[patchi]
<< "' with '" << word(dict.lookup("type"))
<< "' (read from boundary file)"
<< endl;
<< exit(FatalIOError);
}
// Override neighbourpatch name
......@@ -521,7 +563,6 @@ Foam::polyMesh* Foam::blockMesh::createTopology
}
}
blockMeshPtr = new polyMesh
(
IOobject
......@@ -548,7 +589,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
faceListList tmpBlocksPatches;
PtrList<dictionary> patchDicts;
topologyOK = topologyOK && readBoundary
readBoundary
(
meshDescription,
patchNames,
......@@ -556,21 +597,11 @@ Foam::polyMesh* Foam::blockMesh::createTopology
patchDicts
);
if (!topologyOK)
{
FatalErrorInFunction
<< "Cannot create mesh due to errors in topology, exiting !"
<< nl << exit(FatalError);
}
Info<< nl << "Creating block mesh topology" << endl;
cellShapeList tmpBlockCells(blocks.size());
createCellShapes(tmpBlockCells);
// Extract
blockMeshPtr = new polyMesh
(
IOobject
......@@ -592,7 +623,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
);
}
checkBlockMesh(*blockMeshPtr);
check(*blockMeshPtr);
return blockMeshPtr;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment