Commit db9b35b5 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: minor blockMesh improvements

- avoid potential ambiguities in naming of mesh faces/edges
  vs. block faces/edges

- additional methods characterizing the number of faces
  (internal, boundary, total) associated with a blockDescriptor

- cellLabel() accessor and checkIndex() methods

- restore demand-driven behaviour of block, cache the calculated cells
  and refactor generation of block boundary faces to improve potential
  reuse.
parent 448310ea
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -32,19 +32,12 @@ License
void Foam::blockDescriptor::check(const Istream& is)
{
forAll(blockShape_, pi)
for (const label pointi : blockShape_)
{
if (blockShape_[pi] < 0)
if (pointi < 0 || pointi >= vertices_.size())
{
FatalIOErrorInFunction(is)
<< "Negative point label " << blockShape_[pi]
<< " in block " << *this
<< exit(FatalIOError);
}
else if (blockShape_[pi] >= vertices_.size())
{
FatalIOErrorInFunction(is)
<< "Point label " << blockShape_[pi]
<< "Point label " << pointi
<< " out of range 0.." << vertices_.size() - 1
<< " in block " << *this
<< exit(FatalIOError);
......@@ -108,22 +101,22 @@ void Foam::blockDescriptor::check(const Istream& is)
void Foam::blockDescriptor::findCurvedFaces()
{
const faceList blockFaces(blockShape().faces());
const faceList shapeFaces(blockShape().faces());
forAll(blockFaces, blockFacei)
forAll(shapeFaces, shapeFacei)
{
forAll(faces_, facei)
forAll(blockFaces_, facei)
{
if
(
face::sameVertices
(
faces_[facei].vertices(),
blockFaces[blockFacei]
blockFaces_[facei].vertices(),
shapeFaces[shapeFacei]
)
)
{
curvedFaces_[blockFacei] = facei;
curvedFaces_[shapeFacei] = facei;
nCurvedFaces_++;
break;
}
......@@ -146,8 +139,8 @@ Foam::blockDescriptor::blockDescriptor
)
:
vertices_(vertices),
edges_(edges),
faces_(faces),
blockEdges_(edges),
blockFaces_(faces),
blockShape_(bshape),
density_(density),
expand_(expand),
......@@ -155,7 +148,11 @@ Foam::blockDescriptor::blockDescriptor
curvedFaces_(-1),
nCurvedFaces_(0)
{
if (expand_.size() != 12)
if (expand_.empty())
{
expand_.resize(12, gradingDescriptors());
}
else if (expand_.size() != 12)
{
FatalErrorInFunction
<< "Unknown definition of expansion ratios"
......@@ -177,9 +174,9 @@ Foam::blockDescriptor::blockDescriptor
)
:
vertices_(vertices),
edges_(edges),
faces_(faces),
density_(),
blockEdges_(edges),
blockFaces_(faces),
density_(0, 0, 0),
expand_(12, gradingDescriptors()),
zoneName_(),
curvedFaces_(-1),
......@@ -351,7 +348,7 @@ void Foam::blockDescriptor::correctFacePoints
{
if (curvedFaces_[blockFacei] != -1)
{
faces_[curvedFaces_[blockFacei]].project
blockFaces_[curvedFaces_[blockFacei]].project
(
*this,
blockFacei,
......@@ -381,7 +378,7 @@ void Foam::blockDescriptor::write
}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)
{
......@@ -390,13 +387,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)
os << bshape.model().name() << " (";
forAll(blockLabels, labelI)
forAll(blockLabels, labeli)
{
if (labelI)
if (labeli)
{
os << ' ';
}
os << blockLabels[labelI];
os << blockLabels[labeli];
}
os << ')';
......@@ -409,7 +406,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)
<< " simpleGrading (";
const List<gradingDescriptors>& expand = bd.expand_;
const List<gradingDescriptors>& expand = bd.grading();
// Can we use a compact notation?
if
......@@ -455,4 +452,23 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)
}
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<blockDescriptor>& iproxy
)
{
const blockDescriptor& bd = iproxy.t_;
os << "Dimensions:" << bd.density()
<< " nPoints:" << bd.nPoints()
<< " nCells:" << bd.nCells()
<< " nFaces:" << bd.nFaces()
<< " nInternalFaces:" << bd.nInternalFaces()
<< nl;
return os;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -63,35 +63,29 @@ SourceFiles
#include "blockEdgeList.H"
#include "blockFaceList.H"
#include "gradingDescriptors.H"
#include "InfoProxy.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
class blockDescriptor;
Ostream& operator<<(Ostream&, const blockDescriptor&);
/*---------------------------------------------------------------------------*\
Class blockDescriptor Declaration
\*---------------------------------------------------------------------------*/
class blockDescriptor
{
// Private data
// Private Data
//- Reference to point field defining the block mesh
const pointField& vertices_;
//- Reference to a list of block edges
const blockEdgeList& edges_;
const blockEdgeList& blockEdges_;
//- Reference to the list of curved faces
const blockFaceList& faces_;
const blockFaceList& blockFaces_;
//- Block shape
cellShape blockShape_;
......@@ -131,9 +125,6 @@ class blockDescriptor
void findCurvedFaces();
// Private Member Functions
//- No copy assignment
void operator=(const blockDescriptor&) = delete;
......@@ -145,10 +136,10 @@ public:
//- Construct from components. Optional cellSet/zone name.
blockDescriptor
(
const cellShape&,
const cellShape& bshape,
const pointField& vertices,
const blockEdgeList&,
const blockFaceList&,
const blockEdgeList& edges,
const blockFaceList& faces,
const Vector<label>& density,
const UList<gradingDescriptors>& expand,
const word& zoneName = ""
......@@ -160,9 +151,9 @@ public:
const dictionary& dict,
const label index,
const pointField& vertices,
const blockEdgeList&,
const blockFaceList&,
Istream&
const blockEdgeList& edges,
const blockFaceList& faces,
Istream& is
);
......@@ -172,7 +163,7 @@ public:
inline const pointField& vertices() const;
//- Return reference to the list of curved faces
inline const blockFaceList& faces() const;
inline const blockFaceList& blockFaces() const;
//- Return the block shape
inline const cellShape& blockShape() const;
......@@ -180,15 +171,27 @@ public:
//- Return the mesh density (number of cells) in the i,j,k directions
inline const Vector<label>& density() const;
//- Expansion ratios in all directions
const List<gradingDescriptors>& grading() const;
//- Return the (optional) zone name
inline const word& zoneName() const;
//- Return the number of points
//- The number of meshed points described: (nx+1) * (ny+1) * (nz+1)
inline label nPoints() const;
//- Return the number of cells
//- The number of meshed cells described: (nx * ny * nz)
inline label nCells() const;
//- The number of meshed faces described
inline label nFaces() const;
//- The number of meshed internal faces described
inline label nInternalFaces() const;
//- The number of meshed internal faces described
inline label nBoundaryFaces() const;
//- Curved-face labels for each block-face (-1 for flat faces)
inline const FixedList<label, 6>& curvedFaces() const;
......@@ -198,6 +201,22 @@ public:
//- Return block point for local label i
inline const point& blockPoint(const label i) const;
//- Check indices are within valid range ni,nj,nk
inline void checkIndex
(
const label i,
const label j,
const label k
) const;
//- Cell label offset for a particular i,j,k position
inline label cellLabel
(
const label i,
const label j,
const label k
) const;
//- Vertex label offset for a particular i,j,k position
inline label pointLabel
(
......@@ -246,11 +265,19 @@ public:
//- Write block index with dictionary lookup
static void write(Ostream&, const label blocki, const dictionary&);
//- Return info proxy
inline InfoProxy<blockDescriptor> info() const
{
return *this;
}
};
// IOstream Operators
friend Ostream& operator<<(Ostream&, const blockDescriptor&);
};
//- Output Operator
Ostream& operator<<(Ostream& os, const blockDescriptor& bd);
//- Info output
Ostream& operator<<(Ostream& os, const InfoProxy<blockDescriptor>& info);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -50,10 +50,8 @@ Foam::label Foam::blockDescriptor::edgePointsWeights
// Set the edge points/weights
// The edge is a straight-line if it is not in the list of blockEdges
forAll(edges_, cedgei)
for (const blockEdge& cedge : blockEdges_)
{
const blockEdge& cedge = edges_[cedgei];
const int cmp = cedge.compare(blockLabels[start], blockLabels[end]);
if (cmp)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -33,9 +33,9 @@ inline const Foam::pointField& Foam::blockDescriptor::vertices() const
}
inline const Foam::blockFaceList& Foam::blockDescriptor::faces() const
inline const Foam::blockFaceList& Foam::blockDescriptor::blockFaces() const
{
return faces_;
return blockFaces_;
}
......@@ -51,6 +51,13 @@ inline const Foam::Vector<Foam::label>& Foam::blockDescriptor::density() const
}
inline const Foam::List<Foam::gradingDescriptors>&
Foam::blockDescriptor::grading() const
{
return expand_;
}
inline const Foam::word& Foam::blockDescriptor::zoneName() const
{
return zoneName_;
......@@ -79,6 +86,39 @@ inline Foam::label Foam::blockDescriptor::nCells() const
}
inline Foam::label Foam::blockDescriptor::nFaces() const
{
return
(
((density_.x() + 1) * density_.y() * density_.z())
+ ((density_.y() + 1) * density_.z() * density_.x())
+ ((density_.z() + 1) * density_.x() * density_.y())
);
}
inline Foam::label Foam::blockDescriptor::nInternalFaces() const
{
return
(
((density_.x() - 1) * density_.y() * density_.z())
+ ((density_.y() - 1) * density_.z() * density_.x())
+ ((density_.z() - 1) * density_.x() * density_.y())
);
}
inline Foam::label Foam::blockDescriptor::nBoundaryFaces() const
{
return
(
(2 * density_.y() * density_.z())
+ (2 * density_.z() * density_.x())
+ (2 * density_.x() * density_.y())
);
}
inline const Foam::FixedList<Foam::label, 6>&
Foam::blockDescriptor::curvedFaces() const
{
......@@ -98,6 +138,46 @@ inline const Foam::point& Foam::blockDescriptor::blockPoint(const label i) const
}
inline void Foam::blockDescriptor::checkIndex
(
const label i, const label j, const label k
) const
{
if (i < 0 || i >= density_.x())
{
FatalErrorInFunction
<< "index " << i << " out of range [0," << density_.x() << "]"
<< abort(FatalError);
}
if (j < 0 || j >= density_.y())
{
FatalErrorInFunction
<< "index " << j << " out of range [0," << density_.y() << "]"
<< abort(FatalError);
}
if (k < 0 || k >= density_.z())
{
FatalErrorInFunction
<< "index " << k << " out of range [0," << density_.z() << "]"
<< abort(FatalError);
}
}
inline Foam::label Foam::blockDescriptor::cellLabel
(
const label i,
const label j,
const label k
) const
{
#ifdef FULLDEBUG
checkIndex(i, j, k);
#endif
return (i + j*density_.x() + k*density_.x()*density_.y());
}
inline Foam::label Foam::blockDescriptor::pointLabel
(
const label i,
......@@ -105,12 +185,10 @@ inline Foam::label Foam::blockDescriptor::pointLabel
const label k
) const
{
return
(
i
+ j*(density_.x() + 1)
+ k*(density_.x() + 1)*(density_.y() + 1)
);
#ifdef FULLDEBUG
checkIndex(i, j, k);
#endif
return (i + j*(density_.x()+1) + k*(density_.x()+1)*(density_.y()+1));
}
......@@ -123,6 +201,7 @@ inline Foam::label Foam::blockDescriptor::facePointLabel
{
if (facei == 0 || facei == 1)
{
// x-min, x-max
return
(
i
......@@ -131,6 +210,7 @@ inline Foam::label Foam::blockDescriptor::facePointLabel
}
else if (facei == 2 || facei == 3)
{
// y-min, y-max
return
(
i
......@@ -139,6 +219,7 @@ inline Foam::label Foam::blockDescriptor::facePointLabel
}
else
{
// z-min, z-max
return
(
i
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation
......@@ -86,12 +86,6 @@ Foam::blockEdges::BSplineEdge::BSplineEdge
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::blockEdges::BSplineEdge::~BSplineEdge()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::blockEdges::BSplineEdge::position(const scalar mu) const
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation
......@@ -94,7 +94,7 @@ public:
//- Destructor
virtual ~BSplineEdge();
virtual ~BSplineEdge() = default;
// Member Functions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -68,12 +68,6 @@ Foam::blockEdges::bezier::bezier
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::blockEdges::bezier::~bezier()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::blockEdges::bezier::position(const scalar lambda) const
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -104,8 +104,8 @@ public:
);
//- Destructor
virtual ~bezier();
//- Destructor
virtual ~bezier() = default;
// Member Functions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -66,12 +66,6 @@ Foam::blockEdges::lineEdge::lineEdge
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
Foam::blockEdges::lineEdge::~lineEdge()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::blockEdges::lineEdge::position(const scalar lambda) const
......