mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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
This commit is contained in:
@ -24,7 +24,7 @@ License
|
||||
\*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "ccmWriter.H"
|
||||
#include "cellModeller.H"
|
||||
#include "cellModel.H"
|
||||
#include "demandDrivenData.H"
|
||||
#include "ccmInternal.H" // include last to avoid any strange interactions
|
||||
|
||||
@ -304,12 +304,12 @@ Foam::ccm::writer::writer
|
||||
mesh_(mesh),
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
prostarShapeLookup_
|
||||
({
|
||||
{ cellModeller::lookup("hex")->index(), STARCDCore::starcdHex },
|
||||
{ cellModeller::lookup("prism")->index(), STARCDCore::starcdPrism },
|
||||
{ cellModeller::lookup("tet")->index(), STARCDCore::starcdTet },
|
||||
{ cellModeller::lookup("pyr")->index(), STARCDCore::starcdPyr }
|
||||
}),
|
||||
{
|
||||
{ cellModel::ref(cellModel::HEX).index(), STARCDCore::starcdHex },
|
||||
{ cellModel::ref(cellModel::PRISM).index(), STARCDCore::starcdPrism },
|
||||
{ cellModel::ref(cellModel::TET).index(), STARCDCore::starcdTet },
|
||||
{ cellModel::ref(cellModel::PYR).index(), STARCDCore::starcdPyr }
|
||||
},
|
||||
boundaryRegion_(mesh),
|
||||
cellTable_(mesh)
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
With pro-STAR version v4, the input formats have changed radically.
|
||||
With PROSTAR version v4, the input formats have changed radically.
|
||||
* Easier to parse space-delimited input formats
|
||||
* No arbitrary or integral couples
|
||||
* No trimmed or degenerate cells
|
||||
@ -11,7 +11,7 @@ incorrect lookup.
|
||||
Fortunately, there are only 4 primitive shapes to be concerned with.
|
||||
|
||||
Hexa:
|
||||
Foam pro-STAR
|
||||
OpenFOAM PROSTAR
|
||||
~~~~~~~~~~~~~~ ~~~~~~~~~~~
|
||||
Face 0 (0 4 7 3) -> F5: (0 4 7 3)
|
||||
Face 1 (1 2 6 5) -> F6: (1 2 6 5)
|
||||
@ -22,7 +22,7 @@ Hexa:
|
||||
|
||||
|
||||
Prism:
|
||||
Foam pro-STAR
|
||||
OpenFOAM PROSTAR
|
||||
~~~~~~~~~~~~~~ ~~~~~~~~~~~
|
||||
Face 0 (0 2 1) -> F1: (0 2 1)
|
||||
Face 1 (3 4 5) -> F2: (3 4 5)
|
||||
@ -32,7 +32,7 @@ Prism:
|
||||
|
||||
|
||||
Tetra:
|
||||
Foam pro-STAR
|
||||
OpenFOAM PROSTAR
|
||||
~~~~~~~~~~~~~~ ~~~~~~~~~~~
|
||||
Face 0 (1 2 3) -> F6: (1 2 3)
|
||||
Face 1 (0 3 2) -> F5: (0 3 2)
|
||||
@ -41,7 +41,7 @@ Tetra:
|
||||
|
||||
|
||||
Pyramid:
|
||||
Foam pro-STAR
|
||||
OpenFOAM PROSTAR
|
||||
~~~~~~~~~~~~~~ ~~~~~~~~~~~
|
||||
Face 0 (0 3 2 1) -> F1: (0 3 2 1)
|
||||
Face 1 (0 4 3) -> F5: (0 4 3)
|
||||
@ -49,12 +49,12 @@ Pyramid:
|
||||
Face 3 (1 2 4) -> F6: (1 2 4)
|
||||
Face 4 (0 1 4) -> F3: (0 1 4)
|
||||
|
||||
Noting that several faces are skipped over in the pro-STAR definitions,
|
||||
Noting that several faces are skipped over in the PROSTAR definitions,
|
||||
simply introducing a new cell modeller will be a problem.
|
||||
Instead, subtract 1 from the pro-STAR faces and use lookup tables.
|
||||
Instead, subtract 1 from the PROSTAR faces and use lookup tables.
|
||||
|
||||
|
||||
Here are the pro-STAR macro snippets used for creating the primitive cells:
|
||||
Here are the PROSTAR macro snippets used for creating the primitive cells:
|
||||
|
||||
! hexa
|
||||
v 10 0 0 0
|
||||
|
||||
@ -28,42 +28,8 @@ License
|
||||
#include "polyMesh.H"
|
||||
#include "faceSet.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "cellModeller.H"
|
||||
#include "demandDrivenData.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"unknown"
|
||||
);
|
||||
|
||||
const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"tet"
|
||||
);
|
||||
|
||||
const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"pyr"
|
||||
);
|
||||
|
||||
const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"prism"
|
||||
);
|
||||
|
||||
const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"hex"
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::meshReader::addCellZones(polyMesh& mesh) const
|
||||
|
||||
@ -30,7 +30,7 @@ Description
|
||||
The derived classes are responsible for providing the protected data.
|
||||
This implementation is somewhat messy, but could/should be restructured
|
||||
to provide a more generalized reader (at the moment it has been written
|
||||
for converting pro-STAR data).
|
||||
for converting PROSTAR data).
|
||||
|
||||
The meshReader supports cellTable information (see new user's guide entry).
|
||||
|
||||
@ -204,13 +204,6 @@ protected:
|
||||
|
||||
// Protected member data
|
||||
|
||||
//- Pointers to cell shape models
|
||||
static const cellModel* unknownModel;
|
||||
static const cellModel* tetModel;
|
||||
static const cellModel* pyrModel;
|
||||
static const cellModel* prismModel;
|
||||
static const cellModel* hexModel;
|
||||
|
||||
//- Referenced filename
|
||||
fileName geometryFile_;
|
||||
|
||||
|
||||
@ -24,48 +24,12 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "meshWriter.H"
|
||||
#include "cellModeller.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::string Foam::meshWriter::defaultMeshName = "meshExport";
|
||||
|
||||
|
||||
const Foam::cellModel* Foam::meshWriter::unknownModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"unknown"
|
||||
);
|
||||
|
||||
|
||||
const Foam::cellModel* Foam::meshWriter::tetModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"tet"
|
||||
);
|
||||
|
||||
|
||||
const Foam::cellModel* Foam::meshWriter::pyrModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"pyr"
|
||||
);
|
||||
|
||||
|
||||
const Foam::cellModel* Foam::meshWriter::prismModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"prism"
|
||||
);
|
||||
|
||||
|
||||
const Foam::cellModel* Foam::meshWriter::hexModel = Foam::cellModeller::
|
||||
lookup
|
||||
(
|
||||
"hex"
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::meshWriter::meshWriter
|
||||
|
||||
@ -107,14 +107,6 @@ protected:
|
||||
//- cellTable IDs for each cell
|
||||
labelList cellTableId_;
|
||||
|
||||
//- Pointers to cell shape models
|
||||
static const cellModel* unknownModel;
|
||||
static const cellModel* tetModel;
|
||||
static const cellModel* pyrModel;
|
||||
static const cellModel* prismModel;
|
||||
static const cellModel* hexModel;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
@ -28,7 +28,7 @@ License
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "wallPolyPatch.H"
|
||||
#include "symmetryPolyPatch.H"
|
||||
#include "cellModeller.H"
|
||||
#include "cellModel.H"
|
||||
#include "ListOps.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOMap.H"
|
||||
@ -317,7 +317,10 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
|
||||
|
||||
// avoid undefined shapes for polyhedra
|
||||
cellShape genericShape(*unknownModel, labelList(0));
|
||||
cellShape genericShape
|
||||
(
|
||||
cellModel::ref(cellModel::UNKNOWN), labelList()
|
||||
);
|
||||
|
||||
// Pass 2:
|
||||
// construct cellFaces_ and possibly cellShapes_
|
||||
@ -372,23 +375,23 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
continue;
|
||||
}
|
||||
|
||||
// determine the foam cell shape
|
||||
// determine the OpenFOAM cell shape
|
||||
const cellModel* curModelPtr = nullptr;
|
||||
|
||||
// fluid/solid cells
|
||||
switch (shapeId)
|
||||
{
|
||||
case STARCDCore::starcdHex:
|
||||
curModelPtr = hexModel;
|
||||
curModelPtr = cellModel::ptr(cellModel::HEX);
|
||||
break;
|
||||
case STARCDCore::starcdPrism:
|
||||
curModelPtr = prismModel;
|
||||
curModelPtr = cellModel::ptr(cellModel::PRISM);
|
||||
break;
|
||||
case STARCDCore::starcdTet:
|
||||
curModelPtr = tetModel;
|
||||
curModelPtr = cellModel::ptr(cellModel::TET);
|
||||
break;
|
||||
case STARCDCore::starcdPyr:
|
||||
curModelPtr = pyrModel;
|
||||
curModelPtr = cellModel::ptr(cellModel::PYR);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -612,12 +615,12 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
// - needed for face mapping
|
||||
//
|
||||
const Map<label> prostarShapeLookup =
|
||||
const Map<label> shapeLookup =
|
||||
{
|
||||
{ hexModel->index(), STARCDCore::starcdHex },
|
||||
{ prismModel->index(), STARCDCore::starcdPrism },
|
||||
{ tetModel->index(), STARCDCore::starcdTet },
|
||||
{ pyrModel->index(), STARCDCore::starcdPyr }
|
||||
{ cellModel::ref(cellModel::HEX).index(), STARCDCore::starcdHex },
|
||||
{ cellModel::ref(cellModel::PRISM).index(), STARCDCore::starcdPrism },
|
||||
{ cellModel::ref(cellModel::TET).index(), STARCDCore::starcdTet },
|
||||
{ cellModel::ref(cellModel::PYR).index(), STARCDCore::starcdPyr },
|
||||
};
|
||||
|
||||
// Pass 1:
|
||||
@ -861,9 +864,9 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
if (cellId < cellShapes_.size())
|
||||
{
|
||||
label mapIndex = cellShapes_[cellId].model().index();
|
||||
if (prostarShapeLookup.found(mapIndex))
|
||||
if (shapeLookup.found(mapIndex))
|
||||
{
|
||||
mapIndex = prostarShapeLookup[mapIndex];
|
||||
mapIndex = shapeLookup[mapIndex];
|
||||
cellFaceId =
|
||||
STARCDCore::starToFoamFaceAddr
|
||||
[mapIndex][cellFaceId];
|
||||
|
||||
@ -25,10 +25,10 @@ Class
|
||||
Foam::fileFormats::STARCDMeshReader
|
||||
|
||||
Description
|
||||
Read pro-STAR vrt/cel/bnd files.
|
||||
Read PROSTAR vrt/cel/bnd files.
|
||||
The protected data in meshReader are filled.
|
||||
|
||||
Starting with pro-STAR version 4, the files have become easier to read.
|
||||
Starting with PROSTAR version 4, the files have become easier to read.
|
||||
- vertices are space-delimited.
|
||||
- the cell format is logical.
|
||||
- trimmed and degenerate cells are saved as polyhedral.
|
||||
|
||||
@ -35,18 +35,17 @@ Foam::label Foam::fileFormats::STARCDMeshWriter::findDefaultBoundary() const
|
||||
{
|
||||
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
|
||||
|
||||
label id = -1;
|
||||
|
||||
// find Default_Boundary_Region if it exists
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (defaultBoundaryName == patches[patchi].name())
|
||||
{
|
||||
id = patchi;
|
||||
return patchi;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -165,29 +164,16 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
|
||||
OFstream os(starFileName(prefix, STARCDCore::CEL_FILE));
|
||||
writeHeader(os, STARCDCore::HEADER_CEL);
|
||||
|
||||
// this is what we seem to need
|
||||
// map foam cellModeller index -> star shape
|
||||
Map<label> shapeLookupIndex;
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
hexModel->index(),
|
||||
STARCDCore::starcdHex
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
prismModel->index(),
|
||||
STARCDCore::starcdPrism
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
tetModel->index(),
|
||||
STARCDCore::starcdTet
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
pyrModel->index(),
|
||||
STARCDCore::starcdPyr
|
||||
);
|
||||
//
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
//
|
||||
const Map<label> shapeLookupIndex
|
||||
{
|
||||
{ cellModel::ref(cellModel::HEX).index(), STARCDCore::starcdHex },
|
||||
{ cellModel::ref(cellModel::PRISM).index(), STARCDCore::starcdPrism },
|
||||
{ cellModel::ref(cellModel::TET).index(), STARCDCore::starcdTet },
|
||||
{ cellModel::ref(cellModel::PYR).index(), STARCDCore::starcdPyr },
|
||||
};
|
||||
|
||||
const cellShapeList& shapes = mesh_.cellShapes();
|
||||
const cellList& cells = mesh_.cells();
|
||||
@ -336,12 +322,12 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
// - needed for face mapping
|
||||
//
|
||||
const Map<label> prostarShapeLookup =
|
||||
const Map<label> shapeLookupIndex =
|
||||
{
|
||||
{ hexModel->index(), STARCDCore::starcdHex },
|
||||
{ prismModel->index(), STARCDCore::starcdPrism },
|
||||
{ tetModel->index(), STARCDCore::starcdTet },
|
||||
{ pyrModel->index(), STARCDCore::starcdPyr }
|
||||
{ cellModel::ref(cellModel::HEX).index(), STARCDCore::starcdHex },
|
||||
{ cellModel::ref(cellModel::PRISM).index(), STARCDCore::starcdPrism },
|
||||
{ cellModel::ref(cellModel::TET).index(), STARCDCore::starcdTet },
|
||||
{ cellModel::ref(cellModel::PYR).index(), STARCDCore::starcdPyr },
|
||||
};
|
||||
|
||||
Info<< "Writing " << os.name() << " : "
|
||||
@ -396,7 +382,7 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
label mapIndex = shape.model().index();
|
||||
|
||||
// A registered primitive type
|
||||
if (prostarShapeLookup.found(mapIndex))
|
||||
if (shapeLookupIndex.found(mapIndex))
|
||||
{
|
||||
const faceList sFaces = shape.faces();
|
||||
forAll(sFaces, sFacei)
|
||||
@ -408,7 +394,7 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
}
|
||||
}
|
||||
|
||||
mapIndex = prostarShapeLookup[mapIndex];
|
||||
mapIndex = shapeLookupIndex[mapIndex];
|
||||
cellFaceId =
|
||||
STARCDCore::foamToStarFaceAddr[mapIndex][cellFaceId];
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ Class
|
||||
Foam::fileFormats::STARCDMeshWriter
|
||||
|
||||
Description
|
||||
Writes polyMesh in pro-STAR (v4) bnd/cel/vrt format
|
||||
Writes polyMesh in PROSTAR (v4) bnd/cel/vrt format
|
||||
|
||||
The cellTableId and cellTable information are used (if available).
|
||||
Otherwise the cellZones are used (if available).
|
||||
|
||||
@ -27,7 +27,6 @@ License
|
||||
#include "foamVtkCore.H"
|
||||
#include "polyMesh.H"
|
||||
#include "cellShape.H"
|
||||
#include "cellModeller.H"
|
||||
|
||||
// Only used in this file
|
||||
#include "foamVtuSizingTemplates.C"
|
||||
@ -74,12 +73,12 @@ void Foam::vtk::vtuSizing::reset
|
||||
const bool decompose
|
||||
)
|
||||
{
|
||||
const cellModel& tet = *(cellModeller::lookup("tet"));
|
||||
const cellModel& pyr = *(cellModeller::lookup("pyr"));
|
||||
const cellModel& prism = *(cellModeller::lookup("prism"));
|
||||
const cellModel& wedge = *(cellModeller::lookup("wedge"));
|
||||
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
|
||||
const cellModel& hex = *(cellModeller::lookup("hex"));
|
||||
const cellModel& tet = cellModel::ref(cellModel::TET);
|
||||
const cellModel& pyr = cellModel::ref(cellModel::PYR);
|
||||
const cellModel& prism = cellModel::ref(cellModel::PRISM);
|
||||
const cellModel& wedge = cellModel::ref(cellModel::WEDGE);
|
||||
const cellModel& tetWedge = cellModel::ref(cellModel::TETWEDGE);
|
||||
const cellModel& hex = cellModel::ref(cellModel::HEX);
|
||||
|
||||
const cellShapeList& shapes = mesh.cellShapes();
|
||||
|
||||
|
||||
@ -27,7 +27,6 @@ License
|
||||
#include "foamVtkCore.H"
|
||||
#include "polyMesh.H"
|
||||
#include "cellShape.H"
|
||||
#include "cellModeller.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -212,12 +211,12 @@ void Foam::vtk::vtuSizing::populateArrays
|
||||
|
||||
faceOffset = -1;
|
||||
|
||||
const cellModel& tet = *(cellModeller::lookup("tet"));
|
||||
const cellModel& pyr = *(cellModeller::lookup("pyr"));
|
||||
const cellModel& prism = *(cellModeller::lookup("prism"));
|
||||
const cellModel& wedge = *(cellModeller::lookup("wedge"));
|
||||
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
|
||||
const cellModel& hex = *(cellModeller::lookup("hex"));
|
||||
const cellModel& tet = cellModel::ref(cellModel::TET);
|
||||
const cellModel& pyr = cellModel::ref(cellModel::PYR);
|
||||
const cellModel& prism = cellModel::ref(cellModel::PRISM);
|
||||
const cellModel& wedge = cellModel::ref(cellModel::WEDGE);
|
||||
const cellModel& tetWedge = cellModel::ref(cellModel::TETWEDGE);
|
||||
const cellModel& hex = cellModel::ref(cellModel::HEX);
|
||||
|
||||
const cellShapeList& shapes = mesh.cellShapes();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user