blockMesh: most mesh data are now demand-driven

- Unless the points(), cells(), patches() methods are called, the classes
  should know maintain a lightweight representation for as long as possible.

- bugfix: old-code used xferMove() instead of xferCopy() when creating the
  topology mesh - causing const pointField& to break if the code order was
  changed

- relocate blockMesh from src/meshing -> src/mesh
This commit is contained in:
Mark Olesen
2009-09-17 23:45:52 +02:00
parent c2ad2d1bd6
commit 897baf81c0
44 changed files with 462 additions and 438 deletions

View File

@ -1,5 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/meshing/blockMesh/lnInclude \
-I$(LIB_SRC)/mesh/blockMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude

View File

@ -203,6 +203,7 @@ int main(int argc, char *argv[])
word defaultFacesType = emptyPolyPatch::typeName;
wordList patchPhysicalTypes = blocks.patchPhysicalTypes();
preservePatchTypes
(
runTime,
@ -338,7 +339,7 @@ int main(int argc, char *argv[])
// Set the precision of the points data to 10
IOstream::defaultPrecision(10);
Info << nl << "Writing polyMesh" << endl;
Info<< nl << "Writing polyMesh" << endl;
mesh.removeFiles();
if (!mesh.write())
{
@ -347,6 +348,38 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
//
// write some information
//
{
const polyPatchList& patches = mesh.boundaryMesh();
Info<< "----------------" << nl
<< "Mesh Information" << nl
<< "----------------" << nl
<< " " << "boundingBox: " << boundBox(mesh.points()) << nl
<< " " << "nPoints: " << mesh.nPoints() << nl
<< " " << "nCells: " << mesh.nCells() << nl
<< " " << "nFaces: " << mesh.nFaces() << nl
<< " " << "nInternalFaces: " << mesh.nInternalFaces() << nl;
Info<< "----------------" << nl
<< "Patches" << nl
<< "----------------" << nl;
forAll(patches, patchI)
{
const polyPatch& p = patches[patchI];
Info<< " " << "patch " << patchI
<< " (start: " << p.start()
<< " size: " << p.size()
<< ") name: " << p.name()
<< nl;
}
}
Info<< nl << "End" << endl;
return 0;

View File

@ -39,4 +39,5 @@ EXE_LIBS = \
-lthermophysicalFunctions \
-ltopoChangerFvMesh \
-ltriSurface \
-lautoMesh
-lautoMesh \
-lblockMesh

View File

@ -51,6 +51,7 @@ lagrangian/Allwmake
postProcessing/Allwmake
conversion/Allwmake
mesh/Allwmake
wmake libso autoMesh
wmake libso errorEstimation

View File

@ -16,12 +16,9 @@ block/block.C
block/blockCreate.C
blockMesh/blockMesh.C
blockMesh/blockMeshCells.C
blockMesh/blockMeshPatches.C
blockMesh/blockMeshPoints.C
blockMesh/blockMeshCreate.C
blockMesh/blockMeshTopology.C
blockMesh/blockMeshCheck.C
blockMesh/blockMeshOffsets.C
blockMesh/blockMeshMergeList.C
blockMesh/blockMeshMerge.C
LIB = $(FOAM_LIBBIN)/libblockMesh

View File

@ -27,52 +27,68 @@ License
#include "error.H"
#include "block.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::block::block
(
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList& edges,
Istream& is
)
:
blockDescriptor(blockMeshPoints, edges, is),
vertices_(nPoints()),
cells_(nCells()),
boundaryPatches_(6)
{
createPrimitives();
}
blockDescriptor(blockPointField, edges, is),
vertices_(0),
cells_(0),
boundaryPatches_(0)
{}
Foam::block::block(const blockDescriptor& definition)
Foam::block::block(const blockDescriptor& blockDesc)
:
blockDescriptor(definition),
vertices_(nPoints()),
cells_(nCells()),
boundaryPatches_(6)
{
createPrimitives();
}
blockDescriptor(blockDesc),
vertices_(0),
cells_(0),
boundaryPatches_(0)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::block::~block()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::pointField& Foam::block::points() const
{
if (vertices_.empty())
{
createPoints();
}
return vertices_;
}
const Foam::labelListList& Foam::block::cells() const
{
if (cells_.empty())
{
createCells();
}
return cells_;
}
const Foam::labelListListList& Foam::block::boundaryPatches() const
{
if (boundaryPatches_.empty())
{
createBoundary();
}
return boundaryPatches_;
}

View File

@ -29,6 +29,9 @@ Description
Creates a single block of cells from point coordinates, numbers of
cells in each direction and an expansion ratio.
Note
The vertices and cells for filling the block are demand-driven.
SourceFiles
block.C
blockCreate.C
@ -51,6 +54,10 @@ namespace Foam
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
class block;
Ostream& operator<<(Ostream&, const block&);
/*---------------------------------------------------------------------------*\
Class block Declaration
\*---------------------------------------------------------------------------*/
@ -62,13 +69,13 @@ class block
// Private data
//- List of vertices
pointField vertices_;
mutable pointField vertices_;
//- List of cells
labelListList cells_;
mutable labelListList cells_;
//- Boundary patches
labelListListList boundaryPatches_;
mutable labelListListList boundaryPatches_;
// Private Member Functions
@ -76,17 +83,14 @@ class block
//- Vertex label offset for a particular i,j,k position
label vtxLabel(label i, label j, label k) const;
//- Creates vertices for cells filling the block.
void createPoints();
//- Creates vertices for cells filling the block
void createPoints() const;
//- Creates cells for the block.
void createCells();
//- Creates cells for filling the block
void createCells() const;
//- Creates boundary patches for the block
void createBoundary();
//- Creates vertices, cells, boundary patches for the block
void createPrimitives();
//- Creates boundary patch faces for the block
void createBoundary() const;
//- Disallow default bitwise copy construct
block(const block&);
@ -101,7 +105,7 @@ public:
//- Construct from components with Istream
block
(
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList&,
Istream&
);
@ -117,6 +121,11 @@ public:
}
//- Destructor
~block();
// Member Functions
// Access
@ -127,13 +136,20 @@ public:
return *this;
}
//- Return the points for filling the block
const pointField& points() const;
//- Return the cells for filling the block
const labelListList& cells() const;
//- Return the boundary patch faces for the block
const labelListListList& boundaryPatches() const;
//- Clear geometry
void clearGeom();
// Ostream Operator
friend Ostream& operator<<(Ostream&, const block&);

View File

@ -27,7 +27,6 @@ License
#include "error.H"
#include "block.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label Foam::block::vtxLabel(label i, label j, label k) const
@ -41,7 +40,7 @@ Foam::label Foam::block::vtxLabel(label i, label j, label k) const
}
void Foam::block::createPoints()
void Foam::block::createPoints() const
{
// set local variables for mesh specification
const label ni = meshDensity().x();
@ -63,7 +62,11 @@ void Foam::block::createPoints()
const List< List<point> >& p = blockEdgePoints();
const scalarListList& w = blockEdgeWeights();
//
// generate vertices
//
vertices_.clear();
vertices_.setSize(nPoints());
for (label k = 0; k <= nk; k++)
{
@ -71,7 +74,7 @@ void Foam::block::createPoints()
{
for (label i = 0; i <= ni; i++)
{
label vertexNo = vtxLabel(i, j, k);
const label vertexNo = vtxLabel(i, j, k);
// points on edges
vector edgex1 = p000 + (p100 - p000)*w[0][i];
@ -89,6 +92,7 @@ void Foam::block::createPoints()
vector edgez3 = p110 + (p111 - p110)*w[10][k];
vector edgez4 = p010 + (p011 - p010)*w[11][k];
// calculate the importance factors for all edges
// x-direction
@ -110,7 +114,6 @@ void Foam::block::createPoints()
+ w[2][i]*w[6][j]*w[10][k]
);
scalar impx4 =
(
(1.0 - w[3][i])*(1.0 - w[7][j])*w[8][k]
@ -187,6 +190,7 @@ void Foam::block::createPoints()
impz3 /= magImpz;
impz4 /= magImpz;
// calculate the correction vectors
vector corx1 = impx1*(p[0][i] - edgex1);
vector corx2 = impx2*(p[1][i] - edgex2);
@ -226,34 +230,44 @@ void Foam::block::createPoints()
// add the contributions
vertices_[vertexNo] = edgex1 + edgex2 + edgex3 + edgex4;
vertices_[vertexNo] += edgey1 + edgey2 + edgey3 + edgey4;
vertices_[vertexNo] += edgez1 + edgez2 + edgez3 + edgez4;
vertices_[vertexNo] =
(
edgex1 + edgex2 + edgex3 + edgex4
+ edgey1 + edgey2 + edgey3 + edgey4
+ edgez1 + edgez2 + edgez3 + edgez4
) / 3.0;
vertices_[vertexNo] /= 3.0;
vertices_[vertexNo] += corx1 + corx2 + corx3 + corx4;
vertices_[vertexNo] += cory1 + cory2 + cory3 + cory4;
vertices_[vertexNo] += corz1 + corz2 + corz3 + corz4;
vertices_[vertexNo] +=
(
corx1 + corx2 + corx3 + corx4
+ cory1 + cory2 + cory3 + cory4
+ corz1 + corz2 + corz3 + corz4
);
}
}
}
}
void Foam::block::createCells()
void Foam::block::createCells() const
{
const label ni = meshDensity().x();
const label nj = meshDensity().y();
const label nk = meshDensity().z();
//
// generate cells
//
cells_.clear();
cells_.setSize(nCells());
label cellNo = 0;
for (label k = 0; k <= nk - 1; k++)
for (label k = 0; k < nk; k++)
{
for (label j = 0; j <= nj - 1; j++)
for (label j = 0; j < nj; j++)
{
for (label i = 0; i <= ni - 1; i++)
for (label i = 0; i < ni; i++)
{
cells_[cellNo].setSize(8);
@ -272,12 +286,19 @@ void Foam::block::createCells()
}
void Foam::block::createBoundary()
void Foam::block::createBoundary() const
{
const label ni = meshDensity().x();
const label nj = meshDensity().y();
const label nk = meshDensity().z();
//
// generate boundaries on each side of the hex
//
boundaryPatches_.clear();
boundaryPatches_.setSize(6);
// x-direction
label wallLabel = 0;
@ -285,9 +306,9 @@ void Foam::block::createBoundary()
// x-min
boundaryPatches_[wallLabel].setSize(nj*nk);
for (label k = 0; k <= nk - 1; k++)
for (label k = 0; k < nk; k++)
{
for (label j = 0; j <= nj - 1; j++)
for (label j = 0; j < nj; j++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -312,9 +333,9 @@ void Foam::block::createBoundary()
boundaryPatches_[wallLabel].setSize(nj*nk);
for (label k = 0; k <= nk - 1; k++)
for (label k = 0; k < nk; k++)
{
for (label j = 0; j <= nj - 1; j++)
for (label j = 0; j < nj; j++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -340,9 +361,9 @@ void Foam::block::createBoundary()
wallCellLabel = 0;
boundaryPatches_[wallLabel].setSize(ni*nk);
for (label i = 0; i <= ni - 1; i++)
for (label i = 0; i < ni; i++)
{
for (label k = 0; k <= nk - 1; k++)
for (label k = 0; k < nk; k++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -367,9 +388,9 @@ void Foam::block::createBoundary()
boundaryPatches_[wallLabel].setSize(ni*nk);
for (label i = 0; i <= ni - 1; i++)
for (label i = 0; i < ni; i++)
{
for (label k = 0; k <= nk - 1; k++)
for (label k = 0; k < nk; k++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -396,9 +417,9 @@ void Foam::block::createBoundary()
boundaryPatches_[wallLabel].setSize(ni*nj);
for (label i = 0; i <= ni - 1; i++)
for (label i = 0; i < ni; i++)
{
for (label j = 0; j <= nj - 1; j++)
for (label j = 0; j < nj; j++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -423,9 +444,9 @@ void Foam::block::createBoundary()
boundaryPatches_[wallLabel].setSize(ni*nj);
for (label i = 0; i <= ni - 1; i++)
for (label i = 0; i < ni; i++)
{
for (label j = 0; j <= nj - 1; j++)
for (label j = 0; j < nj; j++)
{
boundaryPatches_[wallLabel][wallCellLabel].setSize(4);
@ -446,16 +467,11 @@ void Foam::block::createBoundary()
}
void Foam::block::createPrimitives()
void Foam::block::clearGeom()
{
// create points
createPoints();
// generate internal cells
createCells();
// generate boundary patches
createBoundary();
vertices_.clear();
cells_.clear();
boundaryPatches_.clear();
}

View File

@ -32,14 +32,14 @@ License
Foam::blockDescriptor::blockDescriptor
(
const cellShape& bshape,
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList& edges,
const Vector<label>& meshDensity,
const UList<scalar>& expand,
const word& zoneName
)
:
blockMeshPoints_(blockMeshPoints),
blockPointField_(blockPointField),
curvedEdges_(edges),
blockShape_(bshape),
meshDensity_(meshDensity),
@ -53,7 +53,7 @@ Foam::blockDescriptor::blockDescriptor
FatalErrorIn
(
"blockDescriptor::blockDescriptor"
"(const cellShape&, const pointField& blockMeshPoints, "
"(const cellShape&, const pointField& blockPointField, "
"const curvedEdgeList&, const Vector<label>& meshDensity, "
"const scalarList& expand, const word& zoneName)"
) << "Unknown definition of expansion ratios"
@ -67,12 +67,12 @@ Foam::blockDescriptor::blockDescriptor
Foam::blockDescriptor::blockDescriptor
(
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList& edges,
Istream& is
)
:
blockMeshPoints_(blockMeshPoints),
blockPointField_(blockPointField),
curvedEdges_(edges),
blockShape_(is),
meshDensity_(),
@ -168,11 +168,17 @@ Foam::blockDescriptor::blockDescriptor
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::blockDescriptor::~blockDescriptor()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::pointField& Foam::blockDescriptor::blockPointField() const
{
return blockMeshPoints_;
return blockPointField_;
}
@ -231,11 +237,10 @@ Foam::label Foam::blockDescriptor::nCells() const
const Foam::point& Foam::blockDescriptor::blockPoint(const label i) const
{
return blockMeshPoints_[blockShape_[i]];
return blockPointField_[blockShape_[i]];
}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)

View File

@ -38,8 +38,8 @@ SourceFiles
#ifndef blockDescriptor_H
#define blockDescriptor_H
#include "point.H"
#include "cellShape.H"
#include "pointField.H"
#include "scalarList.H"
#include "curvedEdgeList.H"
@ -51,6 +51,11 @@ namespace Foam
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
class blockMesh;
class blockDescriptor;
Ostream& operator<<(Ostream&, const blockDescriptor&);
/*---------------------------------------------------------------------------*\
Class blockDescriptor Declaration
\*---------------------------------------------------------------------------*/
@ -60,7 +65,7 @@ class blockDescriptor
// Private data
//- Reference to point field defining the block mesh
const pointField& blockMeshPoints_;
const pointField& blockPointField_;
//- Reference to a list of curved edges
const curvedEdgeList& curvedEdges_;
@ -106,7 +111,7 @@ public:
blockDescriptor
(
const cellShape&,
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList&,
const Vector<label>& meshDensity,
const UList<scalar>& expand,
@ -116,7 +121,7 @@ public:
//- Construct from Istream
blockDescriptor
(
const pointField& blockMeshPoints,
const pointField& blockPointField,
const curvedEdgeList&,
Istream&
);
@ -129,6 +134,11 @@ public:
}
// Destructor
~blockDescriptor();
// Member Functions
// Access

View File

@ -26,6 +26,7 @@ License
#include "error.H"
#include "blockDescriptor.H"
#include "lineEdge.H"
#include "lineDivide.H"
@ -86,7 +87,7 @@ void Foam::blockDescriptor::setEdge
const labelList& blockLabels = blockShape_;
// set reference to global list of points
const pointField blockPoints = blockShape_.points(blockMeshPoints_);
const pointField blockPoints = blockShape_.points(blockPointField_);
// Set the edge points/weights
// The edge is a straight-line if it is not in the list of curvedEdges

View File

@ -26,18 +26,16 @@ License
#include "blockMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::blockMesh::blockMesh(IOdictionary& meshDescription)
Foam::blockMesh::blockMesh(IOdictionary& dict)
:
topologyPtr_(createTopology(meshDescription)),
blockOffsets_(createBlockOffsets()),
mergeList_(createMergeList()),
points_(createPoints(meshDescription)),
cells_(createCells()),
patches_(createPatches())
{}
blockPointField_(dict.lookup("vertices")),
scaleFactor_(1.0),
topologyPtr_(createTopology(dict))
{
calcMergeInfo();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -63,45 +61,54 @@ const Foam::polyMesh& Foam::blockMesh::topology() const
}
Foam::wordList Foam::blockMesh::patchNames() const
const Foam::pointField& Foam::blockMesh::points() const
{
const polyPatchList& patchTopologies = topology().boundaryMesh();
wordList names(patchTopologies.size());
forAll(names, patchI)
if (points_.empty())
{
names[patchI] = patchTopologies[patchI].name();
createPoints();
}
return names;
return points_;
}
const Foam::cellShapeList& Foam::blockMesh::cells() const
{
if (cells_.empty())
{
createCells();
}
return cells_;
}
const Foam::faceListList& Foam::blockMesh::patches() const
{
if (patches_.empty())
{
createPatches();
}
return patches_;
}
Foam::wordList Foam::blockMesh::patchNames() const
{
return topology().boundaryMesh().names();
}
Foam::wordList Foam::blockMesh::patchTypes() const
{
const polyPatchList& patchTopologies = topology().boundaryMesh();
wordList types(patchTopologies.size());
forAll(types, patchI)
{
types[patchI] = patchTopologies[patchI].type();
}
return types;
return topology().boundaryMesh().types();
}
Foam::wordList Foam::blockMesh::patchPhysicalTypes() const
{
const polyPatchList& patchTopologies = topology().boundaryMesh();
wordList physicalTypes(patchTopologies.size());
forAll(physicalTypes, patchI)
{
physicalTypes[patchI] = patchTopologies[patchI].physicalType();
}
return physicalTypes;
return topology().boundaryMesh().physicalTypes();
}

View File

@ -26,15 +26,16 @@ Class
Foam::blockMesh
Description
A multi-block mesh generator
Note
The vertices, cells and patches for filling the blocks are demand-driven.
SourceFiles
blockMesh.C
blockMeshCells.C
blockMeshCheck.C
blockMeshMergeList.C
blockMeshOffsets.C
blockMeshPatches.C
blockMeshPoints.C
blockMeshCreate.C
blockMeshMerge.C
blockMeshTopology.C
\*---------------------------------------------------------------------------*/
@ -62,19 +63,34 @@ class blockMesh
{
// Private data
label nPoints_;
label nCells_;
//- Point field defining the block mesh (corners)
pointField blockPointField_;
//- The list of curved edges
curvedEdgeList edges_;
//- The scaling factor to convert to meters
scalar scaleFactor_;
//- The blocks themselves (the topology) as a polyMesh
polyMesh* topologyPtr_;
label nPoints_;
//- The sum of all cells in each block
label nCells_;
//- The point offset added to each block
labelList blockOffsets_;
//- The merge points information
labelList mergeList_;
pointField points_;
cellShapeList cells_;
faceListList patches_;
mutable pointField points_;
mutable cellShapeList cells_;
mutable faceListList patches_;
// Private Member Functions
@ -96,14 +112,14 @@ class blockMesh
polyMesh* createTopology(IOdictionary&);
void checkBlockMesh(const polyMesh&) const;
labelList createBlockOffsets();
labelList createMergeList();
pointField createPoints(const dictionary&) const;
cellShapeList createCells() const;
//- Determine the merge info and the final number of cells/points
void calcMergeInfo();
faceList createPatchFaces(const polyPatch& patchTopologyFaces) const;
faceListList createPatches() const;
void createPoints() const;
void createCells() const;
void createPatches() const;
//- as copy (not implemented)
blockMesh(const blockMesh&);
@ -133,20 +149,11 @@ public:
return edges_;
}
const pointField& points() const
{
return points_;
}
const pointField& points() const;
const cellShapeList& cells() const
{
return cells_;
}
const cellShapeList& cells() const;
const faceListList& patches() const
{
return patches_;
}
const faceListList& patches() const;
wordList patchNames() const;

View File

@ -31,7 +31,7 @@ License
// Check the blockMesh topology
void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const
{
Info<< nl << "Check blockMesh topology" << endl;
Info<< nl << "Check topology" << endl;
bool ok = true;
@ -55,19 +55,19 @@ void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const
}
Info<< nl << tab << "Basic statistics" << endl;
Info<< nl << tab << "Basic statistics" << nl;
Info<< tab << tab << "Number of internal faces : "
<< bm.nInternalFaces() << endl;
<< bm.nInternalFaces() << nl;
Info<< tab << tab << "Number of boundary faces : "
<< nBoundaryFaces << endl;
<< nBoundaryFaces << nl;
Info<< tab << tab << "Number of defined boundary faces : "
<< nDefinedBoundaryFaces << endl;
<< nDefinedBoundaryFaces << nl;
Info<< tab << tab << "Number of undefined boundary faces : "
<< nBoundaryFaces - nDefinedBoundaryFaces << endl;
<< nBoundaryFaces - nDefinedBoundaryFaces << nl;
if ((nBoundaryFaces - nDefinedBoundaryFaces) > 0)
{
@ -76,7 +76,7 @@ void Foam::blockMesh::checkBlockMesh(const polyMesh& bm) const
<< "of 2D planar geometries!)" << endl;
}
Info<< nl << tab << "Checking patch -> block consistency" << endl;
Info<< tab << "Checking patch -> block consistency" << endl;
forAll(patches, patchi)

View File

@ -24,10 +24,84 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "blockMesh.H"
#include "cellModeller.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::blockMesh::createPoints() const
{
const blockMesh& blocks = *this;
Info<< "Creating points with scale " << scaleFactor_ << endl;
//
// generate points
//
points_.clear();
points_.setSize(nPoints_);
forAll(blocks, blockI)
{
const pointField& blockPoints = blocks[blockI].points();
forAll(blockPoints, blockPointI)
{
points_
[
mergeList_
[
blockOffsets_[blockI] + blockPointI
]
] = scaleFactor_ * blockPoints[blockPointI];
}
}
}
void Foam::blockMesh::createCells() const
{
const blockMesh& blocks = *this;
const cellModel& hex = *(cellModeller::lookup("hex"));
Info<< "Creating cells" << endl;
//
// generate cells
//
cells_.clear();
cells_.setSize(nCells_);
label cellLabel = 0;
forAll(blocks, blockI)
{
const labelListList& blockCells = blocks[blockI].cells();
forAll(blockCells, blockCellI)
{
labelList cellPoints(blockCells[blockCellI].size());
forAll(cellPoints, cellPointI)
{
cellPoints[cellPointI] =
mergeList_
[
blockCells[blockCellI][cellPointI]
+ blockOffsets_[blockI]
];
}
// Construct collapsed cell and add to list
cells_[cellLabel] = cellShape(hex, cellPoints, true);
cellLabel++;
}
}
}
Foam::faceList Foam::blockMesh::createPatchFaces
(
const polyPatch& patchTopologyFaces
@ -37,7 +111,7 @@ Foam::faceList Foam::blockMesh::createPatchFaces
labelList blockLabels = patchTopologyFaces.polyPatch::faceCells();
label nFaces=0;
label nFaces = 0;
forAll(patchTopologyFaces, patchTopologyFaceLabel)
{
@ -143,20 +217,24 @@ Foam::faceList Foam::blockMesh::createPatchFaces
}
Foam::faceListList Foam::blockMesh::createPatches() const
void Foam::blockMesh::createPatches() const
{
const polyPatchList& topoPatches = topology().boundaryMesh();
Info<< "Creating patches" << endl;
const polyPatchList& patchTopologies = topology().boundaryMesh();
faceListList patches(patchTopologies.size());
//
// generate points
//
forAll(patchTopologies, patchLabel)
patches_.clear();
patches_.setSize(topoPatches.size());
forAll(topoPatches, patchI)
{
patches[patchLabel] =
createPatchFaces(patchTopologies[patchLabel]);
patches_[patchI] = createPatchFaces(topoPatches[patchI]);
}
return patches;
}
// ************************************************************************* //

View File

@ -28,13 +28,32 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::labelList Foam::blockMesh::createMergeList()
void Foam::blockMesh::calcMergeInfo()
{
const blockMesh& blocks = *this;
Info<< "Creating block offsets" << endl;
blockOffsets_.setSize(blocks.size());
nPoints_ = 0;
nCells_ = 0;
forAll(blocks, blockI)
{
blockOffsets_[blockI] = nPoints_;
nPoints_ += blocks[blockI].nPoints();
nCells_ += blocks[blockI].nCells();
}
Info<< "Creating merge list " << flush;
labelList MergeList(nPoints_, -1);
// set unused to -1
mergeList_.setSize(nPoints_);
mergeList_ = -1;
const blockMesh& blocks = *this;
const pointField& blockPoints = topology().points();
const cellList& blockCells = topology().cells();
@ -46,6 +65,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
const labelList& faceNeighbourBlocks = topology().faceNeighbour();
forAll(blockFaces, blockFaceLabel)
{
label blockPlabel = faceOwnerBlocks[blockFaceLabel];
@ -74,7 +94,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (!foundFace)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Cannot find merge face for block " << blockPlabel
<< exit(FatalError);
};
@ -130,17 +150,17 @@ Foam::labelList Foam::blockMesh::createMergeList()
label minPP2 = min(PpointLabel, PpointLabel2);
if (MergeList[PpointLabel] != -1)
if (mergeList_[PpointLabel] != -1)
{
minPP2 = min(minPP2, MergeList[PpointLabel]);
minPP2 = min(minPP2, mergeList_[PpointLabel]);
}
if (MergeList[PpointLabel2] != -1)
if (mergeList_[PpointLabel2] != -1)
{
minPP2 = min(minPP2, MergeList[PpointLabel2]);
minPP2 = min(minPP2, mergeList_[PpointLabel2]);
}
MergeList[PpointLabel] = MergeList[PpointLabel2]
mergeList_[PpointLabel] = mergeList_[PpointLabel2]
= minPP2;
}
else
@ -183,7 +203,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (!foundFace)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Cannot find merge face for block " << blockNlabel
<< exit(FatalError);
};
@ -193,7 +213,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (blockPfaceFaces.size() != blockNfaceFaces.size())
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Inconsistent number of faces between block pair "
<< blockPlabel << " and " << blockNlabel
<< exit(FatalError);
@ -251,17 +271,17 @@ Foam::labelList Foam::blockMesh::createMergeList()
label minPN = min(PpointLabel, NpointLabel);
if (MergeList[PpointLabel] != -1)
if (mergeList_[PpointLabel] != -1)
{
minPN = min(minPN, MergeList[PpointLabel]);
minPN = min(minPN, mergeList_[PpointLabel]);
}
if (MergeList[NpointLabel] != -1)
if (mergeList_[NpointLabel] != -1)
{
minPN = min(minPN, MergeList[NpointLabel]);
minPN = min(minPN, mergeList_[NpointLabel]);
}
MergeList[PpointLabel] = MergeList[NpointLabel]
mergeList_[PpointLabel] = mergeList_[NpointLabel]
= minPN;
}
}
@ -271,7 +291,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
{
if (cp[blockPfaceFacePointLabel] == -1)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Inconsistent point locations between block pair "
<< blockPlabel << " and " << blockNlabel << nl
<< " probably due to inconsistent grading."
@ -374,18 +394,18 @@ Foam::labelList Foam::blockMesh::createMergeList()
if
(
MergeList[PpointLabel]
!= MergeList[NpointLabel]
mergeList_[PpointLabel]
!= mergeList_[NpointLabel]
)
{
changedPointMerge = true;
MergeList[PpointLabel]
= MergeList[NpointLabel]
mergeList_[PpointLabel]
= mergeList_[NpointLabel]
= min
(
MergeList[PpointLabel],
MergeList[NpointLabel]
mergeList_[PpointLabel],
mergeList_[NpointLabel]
);
}
}
@ -395,7 +415,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (nPasses > 100)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Point merging failed after max number of passes."
<< abort(FatalError);
}
@ -436,7 +456,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (!foundFace)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Cannot find merge face for block " << blockPlabel
<< exit(FatalError);
};
@ -463,7 +483,7 @@ Foam::labelList Foam::blockMesh::createMergeList()
if (!foundFace)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Cannot find merge face for block " << blockNlabel
<< exit(FatalError);
};
@ -485,9 +505,9 @@ Foam::labelList Foam::blockMesh::createMergeList()
blockPfaceFacePoints[blockPfaceFacePointLabel]
+ blockOffsets_[blockPlabel];
if (MergeList[PpointLabel] == -1)
if (mergeList_[PpointLabel] == -1)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "Unable to merge point "
<< blockPfaceFacePointLabel
<< ' ' << blockPpoints[blockPfaceFacePointLabel]
@ -511,9 +531,9 @@ Foam::labelList Foam::blockMesh::createMergeList()
blockNfaceFacePoints[blockNfaceFacePointLabel]
+ blockOffsets_[blockNlabel];
if (MergeList[NpointLabel] == -1)
if (mergeList_[NpointLabel] == -1)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "unable to merge point "
<< blockNfaceFacePointLabel
<< ' ' << blockNpoints[blockNfaceFacePointLabel]
@ -532,33 +552,31 @@ Foam::labelList Foam::blockMesh::createMergeList()
// given old point label
label newPointLabel = 0;
forAll(MergeList, pointLabel)
forAll(mergeList_, pointLabel)
{
if (MergeList[pointLabel] > pointLabel)
if (mergeList_[pointLabel] > pointLabel)
{
FatalErrorIn("blockMesh::createMergeList()")
FatalErrorIn("blockMesh::calcMergeInfo()")
<< "ouch" << exit(FatalError);
}
if
(
(MergeList[pointLabel] == -1)
|| MergeList[pointLabel] == pointLabel
mergeList_[pointLabel] == -1
|| mergeList_[pointLabel] == pointLabel
)
{
MergeList[pointLabel] = newPointLabel;
mergeList_[pointLabel] = newPointLabel;
newPointLabel++;
}
else
{
MergeList[pointLabel] = MergeList[MergeList[pointLabel]];
mergeList_[pointLabel] = mergeList_[mergeList_[pointLabel]];
}
}
nPoints_ = newPointLabel;
return MergeList;
}
// ************************************************************************* //

View File

@ -32,7 +32,7 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& dict)
{
bool topologyOK = true;
@ -44,24 +44,29 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
// get names/types for the unassigned patch faces
// this is a bit heavy handed (and ugly), but there is currently
// no easy way to rename polyMesh patches subsequently
if (const dictionary* dictPtr = meshDescription.subDictPtr("defaultPatch"))
if (const dictionary* dictPtr = dict.subDictPtr("defaultPatch"))
{
dictPtr->readIfPresent("name", defaultPatchName);
dictPtr->readIfPresent("type", defaultPatchType);
}
Info<< "Creating block corners" << endl;
// create blockCorners
pointField tmpBlockPoints(meshDescription.lookup("vertices"));
if (meshDescription.found("edges"))
// optional 'convertToMeters' or 'scale' scaling factor
if (!dict.readIfPresent("convertToMeters", scaleFactor_))
{
dict.readIfPresent("scale", scaleFactor_);
}
//
// get the non-linear edges in mesh
//
if (dict.found("edges"))
{
// read number of non-linear edges in mesh
Info<< "Creating curved edges" << endl;
ITstream& is(meshDescription.lookup("edges"));
ITstream& is(dict.lookup("edges"));
// read number of edges in mesh
label nEdges = 0;
token firstToken(is);
@ -100,7 +105,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
edges_.set
(
nEdges,
curvedEdge::New(tmpBlockPoints, is)
curvedEdge::New(blockPointField_, is)
);
nEdges++;
@ -114,13 +119,16 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
}
else
{
Info<< "No non-linear edges" << endl;
Info<< "No non-linear edges defined" << endl;
}
Info<< "Creating blocks" << endl;
//
// Create the blocks
//
Info<< "Creating topology blocks" << endl;
{
ITstream& is(meshDescription.lookup("blocks"));
ITstream& is(dict.lookup("blocks"));
// read number of blocks in mesh
label nBlocks = 0;
@ -163,7 +171,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
nBlocks,
new block
(
tmpBlockPoints,
blockPointField_,
edges_,
is
)
@ -172,7 +180,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
topologyOK = topologyOK && blockLabelsOK
(
nBlocks,
tmpBlockPoints,
blockPointField_,
blocks[nBlocks].blockShape()
);
@ -187,14 +195,17 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
}
Info<< "Creating patches" << endl;
//
// Create the patches
//
Info<< "Creating topology patches" << endl;
faceListList tmpBlocksPatches;
wordList patchNames;
wordList patchTypes;
{
ITstream& is(meshDescription.lookup("patches"));
ITstream& is(dict.lookup("patches"));
// read number of patches in mesh
label nPatches = 0;
@ -261,7 +272,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
topologyOK = topologyOK && patchLabelsOK
(
nPatches,
tmpBlockPoints,
blockPointField_,
tmpBlocksPatches[nPatches]
);
@ -284,7 +295,10 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
}
Info<< "Creating topology" << endl;
//
// Create the topology
//
Info<< "Creating topology mesh" << endl;
PtrList<cellShape> tmpBlockShapes(blocks.size());
forAll(blocks, blockI)
@ -295,7 +309,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
new cellShape(blocks[blockI].blockShape())
);
if (tmpBlockShapes[blockI].mag(tmpBlockPoints) < 0.0)
if (tmpBlockShapes[blockI].mag(blockPointField_) < 0.0)
{
WarningIn
(
@ -309,8 +323,8 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
preservePatchTypes
(
meshDescription.time(),
meshDescription.time().constant(),
dict.time(),
dict.time().constant(),
polyMesh::meshSubDir,
patchNames,
patchTypes,
@ -319,18 +333,20 @@ Foam::polyMesh* Foam::blockMesh::createTopology(IOdictionary& meshDescription)
patchPhysicalTypes
);
// construct the topology as its own mesh
polyMesh* blockMeshPtr = new polyMesh
(
IOobject
(
"blockMesh",
meshDescription.time().constant(),
meshDescription.time(),
dict.time().constant(),
dict.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
xferMove(tmpBlockPoints),
xferCopy(blockPointField_), // copy these points, do NOT move
tmpBlockShapes,
tmpBlocksPatches,
patchNames,

View File

@ -1,73 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "blockMesh.H"
#include "cellModeller.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::cellShapeList Foam::blockMesh::createCells() const
{
Info<< "Creating cells" << endl;
PtrList<cellShape> cells(nCells_);
const blockMesh& blocks = *this;
const cellModel& hex = *(cellModeller::lookup("hex"));
label cellLabel = 0;
forAll(blocks, blockI)
{
const labelListList& blockCells = blocks[blockI].cells();
forAll(blockCells, blockCellI)
{
labelList cellPoints(blockCells[blockCellI].size());
forAll(cellPoints, cellPointI)
{
cellPoints[cellPointI] =
mergeList_
[
blockCells[blockCellI][cellPointI]
+ blockOffsets_[blockI]
];
}
// Construct collapsed cell and add to list
cells.set(cellLabel, new cellShape(hex, cellPoints, true));
cellLabel++;
}
}
return cells;
}
// ************************************************************************* //

View File

@ -1,57 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "blockMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::labelList Foam::blockMesh::createBlockOffsets()
{
Info<< "Creating block offsets" << endl;
const blockMesh& blocks = *this;
labelList BlockOffsets(blocks.size());
BlockOffsets[0] = 0;
nPoints_ = blocks[0].points().size();
nCells_ = blocks[0].cells().size();
for (label blockI=1; blockI < blocks.size(); blockI++)
{
BlockOffsets[blockI]
= BlockOffsets[blockI-1]
+ blocks[blockI-1].points().size();
nPoints_ += blocks[blockI].points().size();
nCells_ += blocks[blockI].cells().size();
}
return BlockOffsets;
}
// ************************************************************************* //

View File

@ -1,68 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "blockMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::pointField Foam::blockMesh::createPoints(const dictionary& dict) const
{
const blockMesh& blocks = *this;
scalar scaleFactor = 1.0;
// optional 'convertToMeters' (or 'scale'?)
if (!dict.readIfPresent("convertToMeters", scaleFactor))
{
dict.readIfPresent("scale", scaleFactor);
}
Info<< "Creating points with scale " << scaleFactor << endl;
pointField points(nPoints_);
forAll(blocks, blockI)
{
const pointField& blockPoints = blocks[blockI].points();
forAll(blockPoints, blockPointLabel)
{
points
[
mergeList_
[
blockPointLabel
+ blockOffsets_[blockI]
]
] = scaleFactor * blockPoints[blockPointLabel];
}
}
return points;
}
// ************************************************************************* //