Commit 897baf81 authored by Mark Olesen's avatar Mark Olesen
Browse files

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
parent c2ad2d1b
EXE_INC = \
-I$(LIB_SRC)/meshing/blockMesh/lnInclude \
-I$(LIB_SRC)/mesh/blockMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude
......
......@@ -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;
......
......@@ -39,4 +39,5 @@ EXE_LIBS = \
-lthermophysicalFunctions \
-ltopoChangerFvMesh \
-ltriSurface \
-lautoMesh
-lautoMesh \
-lblockMesh
......@@ -51,6 +51,7 @@ lagrangian/Allwmake
postProcessing/Allwmake
conversion/Allwmake
mesh/Allwmake
wmake libso autoMesh
wmake libso errorEstimation
......
......@@ -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
......@@ -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_;
}
......
......@@ -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&);
......
......@@ -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] /= 3.0;
vertices_[vertexNo] =
(
edgex1 + edgex2 + edgex3 + edgex4
+ edgey1 + edgey2 + edgey3 + edgey4
+ edgez1 + edgez2 + edgez3 + edgez4
) / 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();
}
......
......@@ -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)
......
......@@ -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
(