Commit 8730a762 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: enumerations for known cell models in cellModel, ptr/ref lookups

- this provides a better typesafe means of locating predefined cell
  models than relying on strings. The lookup is now ptr() or ref()
  directly. The lookup functions behave like on-demand singletons when
  loading "etc/cellModels".

  Functionality is now located entirely in cellModel but a forwarding
  version of cellModeller is provided for API (but not ABI) compatibility
  with older existing user code.

STYLE: use constexpr for cellMatcher constants
parent 810d090e
......@@ -42,7 +42,7 @@ Description
#include "OFstream.H"
#include "thermoPhysicsTypes.H"
#include "basicMultiComponentMixture.H"
#include "cellModeller.H"
#include "cellModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -13,8 +13,7 @@ points[5] = vector(1, 0, 1);
points[6] = vector(1, 1, 1);
points[7] = vector(0, 1, 1);
const cellModel& hexa = *(cellModeller::lookup("hex"));
faceList faces = hexa.modelFaces();
faceList faces = cellModel::ref(cellModel::HEX).modelFaces();
fvMesh mesh
(
......@@ -25,7 +24,7 @@ fvMesh mesh
runTime,
IOobject::READ_IF_PRESENT
),
xferMove<Field<vector>>(points),
xferMove<pointField>(points),
faces.xfer(),
owner.xfer(),
neighbour.xfer()
......
......@@ -31,7 +31,7 @@ Description
#include "polyMesh.H"
#include "boundBox.H"
#include "treeBoundBox.H"
#include "cellModeller.H"
#include "cellModel.H"
using namespace Foam;
......@@ -52,15 +52,11 @@ boundBox cube(scalar start, scalar width)
int main(int argc, char *argv[])
{
#include "setRootCase.H"
// #include "createTime.H"
// #include "createMesh.H"
const cellModel& hex = *(cellModeller::lookup("hex"));
Info<<"boundBox faces: " << boundBox::faces << endl;
Info<<"hex faces: " << hex.modelFaces() << endl;
Info<<"tree-bb faces: " << treeBoundBox::faces << endl;
Info<<"tree-bb edges: " << treeBoundBox::edges << endl;
Info<<"boundBox faces: " << boundBox::faces << nl
<<"hex faces: " << cellModel::ref(cellModel::HEX).modelFaces() << nl
<<"tree-bb faces: " << treeBoundBox::faces << nl
<<"tree-bb edges: " << treeBoundBox::edges << endl;
boundBox bb = boundBox::greatBox;
Info<<"great box: " << bb << endl;
......
Test-cellModels.C
EXE = $(FOAM_USER_APPBIN)/Test-cellModels
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -21,34 +21,77 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Test-cellModels
Description
cellModeller global initializations
Print information about known cellModels
\*---------------------------------------------------------------------------*/
#include "cellModel.H"
#include "cellModeller.H"
#include "etcFiles.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * Static data * * * * * * * * * * * * * * * * //
using namespace Foam;
Foam::PtrList<Foam::cellModel> Foam::cellModeller::models_
(
IFstream(findEtcFile("cellModels", true))()
);
void printInfo(const cellModel* mdl)
{
if (mdl)
{
Info<< *mdl << endl;
}
else
{
Info<< "nullptr" << endl;
}
}
Foam::List<Foam::cellModel*> Foam::cellModeller::modelPtrs_;
Foam::HashTable<const Foam::cellModel*> Foam::cellModeller::modelDictionary_;
void printInfo(const cellModel::modelType type)
{
Info<< cellModel::modelNames[type] << " = ";
printInfo(cellModel::ptr(type));
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
namespace Foam
int main(int argc, char *argv[])
{
// Construct a dummy cellModeller which reads the models and fills
// the above tables
cellModeller globalCellModeller_;
Info<<"lookup by enum" << nl
<<"=========================" << endl;
printInfo(cellModel::UNKNOWN);
printInfo(cellModel::HEX);
printInfo(cellModel::WEDGE);
printInfo(cellModel::PRISM);
printInfo(cellModel::PYR);
printInfo(cellModel::TET);
printInfo(cellModel::SPLITHEX);
printInfo(cellModel::TETWEDGE);
Info<<"lookup by name" << nl
<<"=========================" << endl;
printInfo(cellModel::ptr("tet"));
Info<<"lookup by index" << nl
<<"=========================" << endl;
printInfo(cellModel::ptr(7));
// Compatibility mode
Info<<"cellModeller::lookup (compatibility)" << nl
<<"=========================" << endl;
printInfo(cellModeller::lookup("tet"));
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
......@@ -52,7 +52,7 @@ Description
#include "polyMesh.H"
#include "cellCuts.H"
#include "cellSet.H"
#include "cellModeller.H"
#include "cellModel.H"
#include "meshCutter.H"
#include "unitConversion.H"
#include "geomCellLooper.H"
......@@ -387,7 +387,7 @@ void collectCuts
const vectorField& faceAreas = mesh.faceAreas();
// Hex shape
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
// cut handling functions
edgeVertex ev(mesh);
......
......@@ -56,7 +56,6 @@ using namespace Foam;
#include "emptyPolyPatch.H"
#include "preservePatchTypes.H"
#include "cellShape.H"
#include "cellModeller.H"
#include "SLList.H"
#include "SLPtrList.H"
......@@ -363,10 +362,10 @@ int main(int argc, char *argv[])
}
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
const cellModel& prism = cellModel::ref(cellModel::PRISM);
const cellModel& pyr = cellModel::ref(cellModel::PYR);
const cellModel& tet = cellModel::ref(cellModel::TET);
labelList labelsHex(8);
labelList labelsPrism(6);
......
......@@ -41,7 +41,6 @@ Description
#include "symmetryPolyPatch.H"
#include "preservePatchTypes.H"
#include "cellShape.H"
#include "cellModeller.H"
using namespace Foam;
......@@ -545,7 +544,7 @@ int main(int argc, char *argv[])
cellShapeList cellShapes(nMeshCells);
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
label nCreatedCells = 0;
......
......@@ -32,7 +32,6 @@ Description
#define cellShapeRecognition_H
#include "cellShape.H"
#include "cellModeller.H"
#include "faceList.H"
#include "PtrList.H"
......
......@@ -50,13 +50,13 @@ cellShape create3DCellShape
static List<const cellModel*> fluentCellModelLookup
(
7,
reinterpret_cast<const cellModel*>(0)
nullptr
);
fluentCellModelLookup[2] = cellModeller::lookup("tet");
fluentCellModelLookup[4] = cellModeller::lookup("hex");
fluentCellModelLookup[5] = cellModeller::lookup("pyr");
fluentCellModelLookup[6] = cellModeller::lookup("prism");
fluentCellModelLookup[2] = cellModel::ptr(cellModel::TET);
fluentCellModelLookup[4] = cellModel::ptr(cellModel::HEX);
fluentCellModelLookup[5] = cellModel::ptr(cellModel::PYR);
fluentCellModelLookup[6] = cellModel::ptr(cellModel::PRISM);
static label faceMatchingOrder[7][6] =
{
......
......@@ -51,7 +51,7 @@ cellShape extrudedQuadCellShape
if (!hexModelPtr_)
{
hexModelPtr_ = cellModeller::lookup("hex");
hexModelPtr_ = cellModel::ptr(cellModel::HEX);
}
const cellModel& hex = *hexModelPtr_;
......
......@@ -28,7 +28,7 @@ Description
#include "cellShapeRecognition.H"
#include "labelList.H"
#include "cellModeller.H"
#include "cellModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -52,7 +52,7 @@ cellShape extrudedTriangleCellShape
if (!prismModelPtr_)
{
prismModelPtr_ = cellModeller::lookup("prism");
prismModelPtr_ = cellModel::ptr(cellModel::PRISM);
}
const cellModel& prism = *prismModelPtr_;
......
......@@ -34,7 +34,7 @@ using std::ios;
#include "wallFvPatch.H"
#include "symmetryPlaneFvPatch.H"
#include "symmetryFvPatch.H"
#include "cellModeller.H"
#include "cellModel.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -218,10 +218,10 @@ void Foam::fluentFvMesh::writeFluentMesh() const
<< "(12 (1 1 "
<< nCells() << " 1 0)(" << std::endl;
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
const cellModel& prism = cellModel::ref(cellModel::PRISM);
const cellModel& pyr = cellModel::ref(cellModel::PYR);
const cellModel& tet = cellModel::ref(cellModel::TET);
const cellShapeList& cells = cellShapes();
......
......@@ -28,7 +28,7 @@ Group
grpMeshConversionUtilities
Description
Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
Reads an OpenFOAM mesh and writes a STARCD/PROSTAR (v4) bnd/cel/vrt format.
Usage
\b foamToStarMesh [OPTION]
......@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
{
argList::addNote
(
"read OpenFOAM mesh and write a pro-STAR (v4) bnd/cel/vrt format"
"read OpenFOAM mesh and write a STARCD/PROSTAR (v4) bnd/cel/vrt format"
);
argList::noParallel();
timeSelector::addOptions();
......
......@@ -53,7 +53,6 @@ using namespace Foam;
#include "polyMesh.H"
#include "emptyPolyPatch.H"
#include "preservePatchTypes.H"
#include "cellModeller.H"
#include "cellShape.H"
#include "SLList.H"
#include "SLPtrList.H"
......@@ -699,10 +698,10 @@ int main(int argc, char *argv[])
cellLookup[cellMap[celli] ] = celli;
}
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
const cellModel& prism = cellModel::ref(cellModel::PRISM);
const cellModel& pyr = cellModel::ref(cellModel::PYR);
const cellModel& tet = cellModel::ref(cellModel::TET);
labelList labelsHex(8);
labelList labelsPrism(6);
......
......@@ -52,7 +52,7 @@ Description
#include "Time.H"
#include "polyMesh.H"
#include "IFstream.H"
#include "cellModeller.H"
#include "cellModel.H"
#include "repatchPolyTopoChanger.H"
#include "cellSet.H"
#include "faceSet.H"
......@@ -435,10 +435,10 @@ void readCells
Info<< "Starting to read cells at line " << inFile.lineNumber() << endl;
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
const cellModel& prism = cellModel::ref(cellModel::PRISM);
const cellModel& pyr = cellModel::ref(cellModel::PYR);
const cellModel& tet = cellModel::ref(cellModel::TET);
face triPoints(3);
face quadPoints(4);
......
......@@ -42,7 +42,7 @@ Description
#include "polyMesh.H"
#include "Time.H"
#include "IFstream.H"
#include "cellModeller.H"
#include "cellModel.H"
#include "cellSet.H"
#include "faceSet.H"
#include "DynamicList.H"
......@@ -291,9 +291,9 @@ void readCells
labelList unvToFoam(invert(maxUnvPoint+1, unvPointID));
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
const cellModel& prism = cellModel::ref(cellModel::PRISM);
const cellModel& tet = cellModel::ref(cellModel::TET);
labelHashSet skippedElements;
......
......@@ -37,7 +37,6 @@ Description
#include "polyMesh.H"
#include "Fstream.H"
#include "cellShape.H"
#include "cellModeller.H"
#include "preservePatchTypes.H"
#include "emptyPolyPatch.H"
#include "wallPolyPatch.H"
......
......@@ -102,7 +102,7 @@ cellShapeList cellShapes(nPoints);
labelList cellZoning(nPoints, -1);
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellModel& hex = cellModel::ref(cellModel::HEX);
labelList hexLabels(8);
label activeCells = 0;
......
Markdown is supported
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