mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup starcd (prostar) mesh conversion (issue #204)
- Reduce code duplication by moving out common functionality into STARCDCore.
This commit is contained in:
@ -94,15 +94,9 @@ int main(int argc, char *argv[])
|
||||
exportName += '-' + args.globalCaseName();
|
||||
}
|
||||
|
||||
// default: rescale from [m] to [mm]
|
||||
scalar scaleFactor = 1000;
|
||||
if (args.optionReadIfPresent("scale", scaleFactor))
|
||||
{
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
scaleFactor = 1;
|
||||
}
|
||||
}
|
||||
// Default rescale from [m] to [mm]
|
||||
const scalar scaleFactor = args.optionLookupOrDefault("scale", 1000.0);
|
||||
const bool writeBndFile = !args.optionFound("noBnd");
|
||||
|
||||
#include "createPolyMesh.H"
|
||||
|
||||
@ -116,12 +110,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!timeI || state != polyMesh::UNCHANGED)
|
||||
{
|
||||
fileFormats::STARCDMeshWriter writer(mesh, scaleFactor);
|
||||
|
||||
if (args.optionFound("noBnd"))
|
||||
{
|
||||
writer.noBoundary();
|
||||
}
|
||||
fileFormats::STARCDMeshWriter writer
|
||||
(
|
||||
mesh,
|
||||
scaleFactor,
|
||||
writeBndFile
|
||||
);
|
||||
|
||||
fileName meshName(exportName);
|
||||
if (state != polyMesh::UNCHANGED)
|
||||
|
||||
@ -48,7 +48,7 @@ Usage
|
||||
Note
|
||||
Baffles are written as interfaces for later use
|
||||
|
||||
See Also
|
||||
See also
|
||||
Foam::cellTable, Foam::meshReader and Foam::fileFormats::STARCDMeshReader
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -88,32 +88,35 @@ int main(int argc, char *argv[])
|
||||
"retain solid cells and treat them like fluid cells"
|
||||
);
|
||||
|
||||
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
|
||||
// default rescale from [mm] to [m]
|
||||
scalar scaleFactor = args.optionLookupOrDefault("scale", 0.001);
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
scaleFactor = 1;
|
||||
}
|
||||
// Binary output, unless otherwise specified
|
||||
const IOstream::streamFormat format =
|
||||
(
|
||||
args.optionFound("ascii")
|
||||
? IOstream::ASCII
|
||||
: IOstream::BINARY
|
||||
);
|
||||
|
||||
fileFormats::STARCDMeshReader::keepSolids = args.optionFound("solids");
|
||||
|
||||
// default to binary output, unless otherwise specified
|
||||
IOstream::streamFormat format = IOstream::BINARY;
|
||||
if (args.optionFound("ascii"))
|
||||
{
|
||||
format = IOstream::ASCII;
|
||||
}
|
||||
|
||||
// increase the precision of the points data
|
||||
// Increase the precision of the points data
|
||||
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
|
||||
|
||||
// remove extensions and/or trailing '.'
|
||||
|
||||
// Remove extensions and/or trailing '.'
|
||||
const fileName prefix = fileName(args[1]).lessExt();
|
||||
|
||||
fileFormats::STARCDMeshReader reader(prefix, runTime, scaleFactor);
|
||||
|
||||
fileFormats::STARCDMeshReader reader
|
||||
(
|
||||
prefix,
|
||||
runTime,
|
||||
// Default rescale from [mm] to [m]
|
||||
args.optionLookupOrDefault("scale", 0.001),
|
||||
args.optionFound("solids")
|
||||
);
|
||||
|
||||
|
||||
autoPtr<polyMesh> mesh = reader.mesh(runTime);
|
||||
reader.writeMesh(mesh, format);
|
||||
|
||||
@ -213,7 +213,13 @@ Foam::meshReader::meshReader
|
||||
baffleFaces_(0),
|
||||
cellTableId_(0),
|
||||
cellTable_()
|
||||
{}
|
||||
{
|
||||
// Sanity
|
||||
if (scaleFactor_ <= VSMALL)
|
||||
{
|
||||
scaleFactor_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -275,7 +275,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from fileName
|
||||
meshReader(const fileName&, const scalar scaleFactor = 1.0);
|
||||
meshReader(const fileName&, const scalar scaling = 1.0);
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -68,15 +68,24 @@ lookup
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::meshWriter::meshWriter(const polyMesh& mesh, const scalar scaleFactor)
|
||||
Foam::meshWriter::meshWriter
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const scalar scaling
|
||||
)
|
||||
:
|
||||
mesh_(mesh),
|
||||
scaleFactor_(scaleFactor),
|
||||
writeBoundary_(true),
|
||||
scaleFactor_(scaling),
|
||||
boundaryRegion_(),
|
||||
cellTable_(),
|
||||
cellTableId_()
|
||||
{}
|
||||
{
|
||||
// Sanity
|
||||
if (scaleFactor_ <= VSMALL)
|
||||
{
|
||||
scaleFactor_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -98,9 +98,6 @@ protected:
|
||||
//- Scaling factor for points (eg, [m] -> [mm])
|
||||
scalar scaleFactor_;
|
||||
|
||||
//- Write bnd file
|
||||
bool writeBoundary_;
|
||||
|
||||
//- boundaryRegion persistent data saved as a dictionary
|
||||
boundaryRegion boundaryRegion_;
|
||||
|
||||
@ -125,13 +122,14 @@ public:
|
||||
//- Specify a default mesh name
|
||||
static string defaultMeshName;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Create a writer object
|
||||
//- Create a writer object with given output scaling
|
||||
meshWriter
|
||||
(
|
||||
const polyMesh&,
|
||||
const scalar scaleFactor = 1.0
|
||||
const scalar scaling = 1.0
|
||||
);
|
||||
|
||||
|
||||
@ -141,28 +139,13 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Edit
|
||||
// Write
|
||||
|
||||
//- Set points scaling
|
||||
void scaleFactor(const scalar scaling)
|
||||
{
|
||||
scaleFactor_ = scaling;
|
||||
}
|
||||
|
||||
//- Suppress writing boundary (bnd) file
|
||||
void noBoundary()
|
||||
{
|
||||
writeBoundary_ = false;
|
||||
}
|
||||
|
||||
|
||||
// Write
|
||||
|
||||
//- Write volume mesh. Subclass must supply this method
|
||||
virtual bool write
|
||||
(
|
||||
const fileName& timeName = fileName::null
|
||||
) const = 0;
|
||||
//- Write volume mesh. Subclass must supply this method
|
||||
virtual bool write
|
||||
(
|
||||
const fileName& timeName = fileName::null
|
||||
) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -35,26 +35,9 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* const Foam::fileFormats::STARCDMeshReader::defaultBoundaryName =
|
||||
"Default_Boundary_Region";
|
||||
|
||||
const char* const Foam::fileFormats::STARCDMeshReader::defaultSolidBoundaryName =
|
||||
"Default_Boundary_Solid";
|
||||
|
||||
bool Foam::fileFormats::STARCDMeshReader::keepSolids = false;
|
||||
|
||||
const int Foam::fileFormats::STARCDMeshReader::starToFoamFaceAddr[4][6] =
|
||||
{
|
||||
{ 4, 5, 2, 3, 0, 1 }, // 11 = pro-STAR hex
|
||||
{ 0, 1, 4, -1, 2, 3 }, // 12 = pro-STAR prism
|
||||
{ 3, -1, 2, -1, 1, 0 }, // 13 = pro-STAR tetra
|
||||
{ 0, -1, 4, 2, 1, 3 } // 14 = pro-STAR pyramid
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::STARCDMeshReader::readToNewline(IFstream& is)
|
||||
//! \cond fileScope
|
||||
//- Read and discard to newline
|
||||
static void readToNewline(Foam::IFstream& is)
|
||||
{
|
||||
char ch = '\n';
|
||||
do
|
||||
@ -63,34 +46,7 @@ void Foam::fileFormats::STARCDMeshReader::readToNewline(IFstream& is)
|
||||
}
|
||||
while ((is) && ch != '\n');
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::STARCDMeshReader::readHeader(IFstream& is, word fileSignature)
|
||||
{
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
word header;
|
||||
label majorVersion;
|
||||
|
||||
is >> header;
|
||||
is >> majorVersion;
|
||||
|
||||
// skip the rest of the line
|
||||
readToNewline(is);
|
||||
|
||||
// add other checks ...
|
||||
if (header != fileSignature)
|
||||
{
|
||||
Info<< "header mismatch " << fileSignature << " " << is.name()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//! \endcond
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
@ -118,20 +74,19 @@ Body:
|
||||
<vertexId> <x> <y> <z> [newline]
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
void Foam::fileFormats::STARCDMeshReader::readPoints
|
||||
Foam::label Foam::fileFormats::STARCDMeshReader::readPoints
|
||||
(
|
||||
const fileName& inputName,
|
||||
const scalar scaleFactor
|
||||
)
|
||||
{
|
||||
const word fileSignature = "PROSTAR_VERTEX";
|
||||
label nPoints = 0, maxId = 0;
|
||||
|
||||
// Pass 1:
|
||||
// get # points and maximum vertex label
|
||||
{
|
||||
IFstream is(inputName);
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_VRT);
|
||||
|
||||
label lineLabel;
|
||||
scalar x, y, z;
|
||||
@ -164,7 +119,7 @@ void Foam::fileFormats::STARCDMeshReader::readPoints
|
||||
if (nPoints > 0)
|
||||
{
|
||||
IFstream is(inputName);
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_VRT);
|
||||
|
||||
label lineLabel;
|
||||
|
||||
@ -200,6 +155,8 @@ void Foam::fileFormats::STARCDMeshReader::readPoints
|
||||
<< "no points in file " << inputName
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
return maxId;
|
||||
}
|
||||
|
||||
|
||||
@ -245,7 +202,6 @@ Strictly speaking, we only need the cellModeller for adding boundaries.
|
||||
|
||||
void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
{
|
||||
const word fileSignature = "PROSTAR_CELL";
|
||||
label nFluids = 0, nSolids = 0, nBaffles = 0, nShells = 0;
|
||||
label maxId = 0;
|
||||
|
||||
@ -257,7 +213,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
// also see if polyhedral cells were used
|
||||
{
|
||||
IFstream is(inputName);
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_CEL);
|
||||
|
||||
label lineLabel, shapeId, nLabels, cellTableId, typeId;
|
||||
|
||||
@ -279,7 +235,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
nLabels -= 8;
|
||||
}
|
||||
|
||||
if (typeId == starcdFluidType)
|
||||
if (typeId == STARCDCore::starcdFluidType)
|
||||
{
|
||||
nFluids++;
|
||||
maxId = max(maxId, starCellId);
|
||||
@ -290,10 +246,10 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
cellTable_.setMaterial(cellTableId, "fluid");
|
||||
}
|
||||
}
|
||||
else if (typeId == starcdSolidType)
|
||||
else if (typeId == STARCDCore::starcdSolidType)
|
||||
{
|
||||
nSolids++;
|
||||
if (keepSolids)
|
||||
if (keepSolids_)
|
||||
{
|
||||
maxId = max(maxId, starCellId);
|
||||
}
|
||||
@ -305,13 +261,13 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
}
|
||||
|
||||
}
|
||||
else if (typeId == starcdBaffleType)
|
||||
else if (typeId == STARCDCore::starcdBaffleType)
|
||||
{
|
||||
// baffles have no cellTable entry
|
||||
nBaffles++;
|
||||
maxId = max(maxId, starCellId);
|
||||
}
|
||||
else if (typeId == starcdShellType)
|
||||
else if (typeId == STARCDCore::starcdShellType)
|
||||
{
|
||||
nShells++;
|
||||
if (!cellTable_.found(cellTableId))
|
||||
@ -326,7 +282,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
|
||||
Info<< "Number of fluids = " << nFluids << nl
|
||||
<< "Number of baffles = " << nBaffles << nl;
|
||||
if (keepSolids)
|
||||
if (keepSolids_)
|
||||
{
|
||||
Info<< "Number of solids = " << nSolids << nl;
|
||||
}
|
||||
@ -338,7 +294,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
|
||||
|
||||
label nCells;
|
||||
if (keepSolids)
|
||||
if (keepSolids_)
|
||||
{
|
||||
nCells = nFluids + nSolids;
|
||||
}
|
||||
@ -374,7 +330,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
else
|
||||
{
|
||||
IFstream is(inputName);
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_CEL);
|
||||
|
||||
labelList starLabels(64);
|
||||
label lineLabel, shapeId, nLabels, cellTableId, typeId;
|
||||
@ -407,7 +363,11 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
}
|
||||
|
||||
// skip solid cells
|
||||
if (typeId == starcdSolidType && !keepSolids)
|
||||
if
|
||||
(
|
||||
typeId == STARCDCore::starcdSolidType
|
||||
&& !keepSolids_
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -418,16 +378,16 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
// fluid/solid cells
|
||||
switch (shapeId)
|
||||
{
|
||||
case starcdHex:
|
||||
case STARCDCore::starcdHex:
|
||||
curModelPtr = hexModel;
|
||||
break;
|
||||
case starcdPrism:
|
||||
case STARCDCore::starcdPrism:
|
||||
curModelPtr = prismModel;
|
||||
break;
|
||||
case starcdTet:
|
||||
case STARCDCore::starcdTet:
|
||||
curModelPtr = tetModel;
|
||||
break;
|
||||
case starcdPyr:
|
||||
case STARCDCore::starcdPyr:
|
||||
curModelPtr = pyrModel;
|
||||
break;
|
||||
}
|
||||
@ -471,7 +431,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
cellFaces_[celli] = cellShapes_[celli].faces();
|
||||
celli++;
|
||||
}
|
||||
else if (shapeId == starcdPoly)
|
||||
else if (shapeId == STARCDCore::starcdPoly)
|
||||
{
|
||||
// polyhedral cell
|
||||
label nFaces = starLabels[0] - 1;
|
||||
@ -548,7 +508,7 @@ void Foam::fileFormats::STARCDMeshReader::readCells(const fileName& inputName)
|
||||
cellFaces_[celli] = faces;
|
||||
celli++;
|
||||
}
|
||||
else if (typeId == starcdBaffleType)
|
||||
else if (typeId == STARCDCore::starcdBaffleType)
|
||||
{
|
||||
// baffles
|
||||
|
||||
@ -639,7 +599,6 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
const fileName& inputName
|
||||
)
|
||||
{
|
||||
const word fileSignature = "PROSTAR_BOUNDARY";
|
||||
label nPatches = 0, nFaces = 0, nBafflePatches = 0, maxId = 0;
|
||||
label lineLabel, starCellId, cellFaceId, starRegion, configNumber;
|
||||
word patchType;
|
||||
@ -649,15 +608,17 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
labelList origRegion(1000, label(0));
|
||||
patchTypes_.setSize(1000);
|
||||
|
||||
// this is what we seem to need
|
||||
// these MUST correspond to starToFoamFaceAddr
|
||||
//
|
||||
Map<label> faceLookupIndex;
|
||||
|
||||
faceLookupIndex.insert(hexModel->index(), 0);
|
||||
faceLookupIndex.insert(prismModel->index(), 1);
|
||||
faceLookupIndex.insert(tetModel->index(), 2);
|
||||
faceLookupIndex.insert(pyrModel->index(), 3);
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
// - needed for face mapping
|
||||
//
|
||||
const Map<label> prostarShapeLookup =
|
||||
{
|
||||
{ hexModel->index(), STARCDCore::starcdHex },
|
||||
{ prismModel->index(), STARCDCore::starcdPrism },
|
||||
{ tetModel->index(), STARCDCore::starcdTet },
|
||||
{ pyrModel->index(), STARCDCore::starcdPyr }
|
||||
};
|
||||
|
||||
// Pass 1:
|
||||
// collect
|
||||
@ -675,7 +636,7 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
|
||||
if (is.good())
|
||||
{
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_BND);
|
||||
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
@ -863,7 +824,7 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
if (nPatches > 1 && mapToFoamCellId_.size() > 1)
|
||||
{
|
||||
IFstream is(inputName);
|
||||
readHeader(is, fileSignature);
|
||||
readHeader(is, STARCDCore::HEADER_BND);
|
||||
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
@ -899,11 +860,11 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
|
||||
// restrict lookup to volume cells (no baffles)
|
||||
if (cellId < cellShapes_.size())
|
||||
{
|
||||
label index = cellShapes_[cellId].model().index();
|
||||
if (faceLookupIndex.found(index))
|
||||
label mapIndex = cellShapes_[cellId].model().index();
|
||||
if (prostarShapeLookup.found(mapIndex))
|
||||
{
|
||||
index = faceLookupIndex[index];
|
||||
cellFaceId = starToFoamFaceAddr[index][cellFaceId];
|
||||
mapIndex = prostarShapeLookup[mapIndex];
|
||||
cellFaceId = STARCDCore::starToFoamFaceAddr[mapIndex][cellFaceId];
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1046,10 +1007,20 @@ void Foam::fileFormats::STARCDMeshReader::cullPoints()
|
||||
|
||||
bool Foam::fileFormats::STARCDMeshReader::readGeometry(const scalar scaleFactor)
|
||||
{
|
||||
readPoints(geometryFile_ + ".vrt", scaleFactor);
|
||||
readCells(geometryFile_ + ".cel");
|
||||
readPoints
|
||||
(
|
||||
starFileName(geometryFile_, STARCDCore::VRT_FILE),
|
||||
scaleFactor
|
||||
);
|
||||
readCells
|
||||
(
|
||||
starFileName(geometryFile_, STARCDCore::CEL_FILE)
|
||||
);
|
||||
cullPoints();
|
||||
readBoundary(geometryFile_ + ".bnd");
|
||||
readBoundary
|
||||
(
|
||||
starFileName(geometryFile_, STARCDCore::BND_FILE)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1061,10 +1032,12 @@ Foam::fileFormats::STARCDMeshReader::STARCDMeshReader
|
||||
(
|
||||
const fileName& prefix,
|
||||
const objectRegistry& registry,
|
||||
const scalar scaleFactor
|
||||
const scalar scaleFactor,
|
||||
const bool keepSolids
|
||||
)
|
||||
:
|
||||
meshReader(prefix, scaleFactor),
|
||||
keepSolids_(keepSolids),
|
||||
cellShapes_(0),
|
||||
mapToFoamPointId_(0),
|
||||
mapToFoamCellId_(0)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,6 +43,7 @@ SourceFiles
|
||||
#define STARCDMeshReader_H
|
||||
|
||||
#include "meshReader.H"
|
||||
#include "STARCDCore.H"
|
||||
#include "boundaryRegion.H"
|
||||
#include "cellShape.H"
|
||||
#include "IFstream.H"
|
||||
@ -61,19 +62,28 @@ namespace fileFormats
|
||||
|
||||
class STARCDMeshReader
|
||||
:
|
||||
public meshReader
|
||||
public meshReader,
|
||||
protected STARCDCore
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Retain solid cell types
|
||||
bool keepSolids_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDMeshReader(const STARCDMeshReader&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDMeshReader&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
static const char* const defaultBoundaryName;
|
||||
static const char* const defaultSolidBoundaryName;
|
||||
|
||||
//- Face addressing from pro-STAR faces -> OpenFOAM faces
|
||||
static const int starToFoamFaceAddr[4][6];
|
||||
|
||||
//- Cell shapes
|
||||
cellShapeList cellShapes_;
|
||||
|
||||
@ -92,8 +102,8 @@ protected:
|
||||
//- Read the mesh from the file(s)
|
||||
virtual bool readGeometry(const scalar scaleFactor = 1.0);
|
||||
|
||||
//- Read points from file
|
||||
void readPoints(const fileName&, const scalar scaleFactor);
|
||||
//- Read points from file, return the max prostar id used.
|
||||
label readPoints(const fileName&, const scalar scaleFactor);
|
||||
|
||||
//- Read cell connectivities from file
|
||||
virtual void readCells(const fileName&);
|
||||
@ -107,57 +117,9 @@ protected:
|
||||
//- Read auxiliary data from constant/{boundaryRegion,cellTable}
|
||||
void readAux(const objectRegistry&);
|
||||
|
||||
//- Read and discard to newline
|
||||
static void readToNewline(IFstream&);
|
||||
|
||||
//- Read header
|
||||
static bool readHeader(IFstream&, word fileSignature);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDMeshReader(const STARCDMeshReader&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDMeshReader&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
enum cellType
|
||||
{
|
||||
starcdFluidType = 1,
|
||||
starcdSolidType = 2,
|
||||
starcdBaffleType = 3,
|
||||
starcdShellType = 4,
|
||||
starcdLineType = 5,
|
||||
starcdPointType = 6
|
||||
};
|
||||
|
||||
enum shapeType
|
||||
{
|
||||
starcdPoint = 1,
|
||||
starcdLine = 2,
|
||||
starcdShell = 3,
|
||||
starcdHex = 11,
|
||||
starcdPrism = 12,
|
||||
starcdTet = 13,
|
||||
starcdPyr = 14,
|
||||
starcdPoly = 255
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data
|
||||
|
||||
//- Keep solids (default false)
|
||||
static bool keepSolids;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from case name
|
||||
@ -165,12 +127,14 @@ public:
|
||||
(
|
||||
const fileName& prefix,
|
||||
const objectRegistry&,
|
||||
const scalar scaleFactor = 1.0
|
||||
const scalar scaleFactor = 1.0,
|
||||
const bool keepSolids = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~STARCDMeshReader();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,20 +29,6 @@ License
|
||||
#include "SortableList.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const char* Foam::fileFormats::STARCDMeshWriter::defaultBoundaryName =
|
||||
"Default_Boundary_Region";
|
||||
|
||||
const Foam::label Foam::fileFormats::STARCDMeshWriter::foamToStarFaceAddr[4][6] =
|
||||
{
|
||||
{ 4, 5, 2, 3, 0, 1 }, // 11 = pro-STAR hex
|
||||
{ 0, 1, 4, 5, 2, -1 }, // 12 = pro-STAR prism
|
||||
{ 5, 4, 2, 0, -1, -1 }, // 13 = pro-STAR tetra
|
||||
{ 0, 4, 3, 5, 2, -1 } // 14 = pro-STAR pyramid
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::fileFormats::STARCDMeshWriter::findDefaultBoundary() const
|
||||
@ -171,66 +157,37 @@ void Foam::fileFormats::STARCDMeshWriter::getCellTable()
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDMeshWriter::writeHeader(Ostream& os, const char* filetype)
|
||||
{
|
||||
os << "PROSTAR_" << filetype << nl
|
||||
<< 4000
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDMeshWriter::writePoints(const fileName& prefix) const
|
||||
{
|
||||
OFstream os(prefix + ".vrt");
|
||||
writeHeader(os, "VERTEX");
|
||||
|
||||
// Set the precision of the points data to 10
|
||||
os.precision(10);
|
||||
|
||||
// force decimal point for Fortran input
|
||||
os.setf(std::ios::showpoint);
|
||||
|
||||
const pointField& points = mesh_.points();
|
||||
|
||||
Info<< "Writing " << os.name() << " : "
|
||||
<< points.size() << " points" << endl;
|
||||
|
||||
forAll(points, ptI)
|
||||
{
|
||||
// convert [m] -> [mm]
|
||||
os
|
||||
<< ptI + 1 << " "
|
||||
<< scaleFactor_ * points[ptI].x() << " "
|
||||
<< scaleFactor_ * points[ptI].y() << " "
|
||||
<< scaleFactor_ * points[ptI].z() << nl;
|
||||
}
|
||||
os.flush();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDMeshWriter::writeCells
|
||||
(
|
||||
const fileName& prefix
|
||||
) const
|
||||
{
|
||||
OFstream os(prefix + ".cel");
|
||||
writeHeader(os, "CELL");
|
||||
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(), 11);
|
||||
shapeLookupIndex.insert(prismModel->index(), 12);
|
||||
shapeLookupIndex.insert(tetModel->index(), 13);
|
||||
shapeLookupIndex.insert(pyrModel->index(), 14);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
hexModel->index(),
|
||||
STARCDCore::starcdHex
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
prismModel->index(),
|
||||
STARCDCore::starcdPrism
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
tetModel->index(),
|
||||
STARCDCore::starcdTet
|
||||
);
|
||||
shapeLookupIndex.insert
|
||||
(
|
||||
pyrModel->index(),
|
||||
STARCDCore::starcdPyr
|
||||
);
|
||||
|
||||
const cellShapeList& shapes = mesh_.cellShapes();
|
||||
const cellList& cells = mesh_.cells();
|
||||
@ -242,30 +199,30 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
|
||||
|
||||
forAll(cells, cellId)
|
||||
{
|
||||
label tableId = cellTableId_[cellId];
|
||||
label materialType = 1; // 1(fluid)
|
||||
const label tableId = cellTableId_[cellId];
|
||||
label materialType = STARCDCore::starcdFluidType; // 1(fluid)
|
||||
if (cellTable_.found(tableId))
|
||||
{
|
||||
const dictionary& dict = cellTable_[tableId];
|
||||
if (dict.found("MaterialType"))
|
||||
{
|
||||
word matType;
|
||||
dict.lookup("MaterialType") >> matType;
|
||||
if (matType == "solid")
|
||||
{
|
||||
materialType = 2;
|
||||
}
|
||||
word matType;
|
||||
|
||||
if
|
||||
(
|
||||
dict.readIfPresent("MaterialType", matType)
|
||||
&& matType == "solid"
|
||||
)
|
||||
{
|
||||
materialType = STARCDCore::starcdSolidType; // 2(solid)
|
||||
}
|
||||
}
|
||||
|
||||
const cellShape& shape = shapes[cellId];
|
||||
label mapIndex = shape.model().index();
|
||||
const label mapIndex = shape.model().index();
|
||||
|
||||
// a registered primitive type
|
||||
if (shapeLookupIndex.found(mapIndex))
|
||||
{
|
||||
label shapeId = shapeLookupIndex[mapIndex];
|
||||
const label shapeId = shapeLookupIndex[mapIndex];
|
||||
const labelList& vrtList = shapes[cellId];
|
||||
|
||||
os << cellId + 1
|
||||
@ -288,11 +245,11 @@ void Foam::fileFormats::STARCDMeshWriter::writeCells
|
||||
count++;
|
||||
}
|
||||
os << endl;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
label shapeId = 255; // treat as general polyhedral
|
||||
// treat as general polyhedral
|
||||
const label shapeId = STARCDCore::starcdPoly;
|
||||
const labelList& cFaces = cells[cellId];
|
||||
|
||||
// create (beg,end) indices
|
||||
@ -366,8 +323,8 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
const fileName& prefix
|
||||
) const
|
||||
{
|
||||
OFstream os(prefix + ".bnd");
|
||||
writeHeader(os, "BOUNDARY");
|
||||
OFstream os(starFileName(prefix, STARCDCore::BND_FILE));
|
||||
writeHeader(os, STARCDCore::HEADER_BND);
|
||||
|
||||
const cellShapeList& shapes = mesh_.cellShapes();
|
||||
const cellList& cells = mesh_.cells();
|
||||
@ -375,20 +332,23 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
const labelList& owner = mesh_.faceOwner();
|
||||
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
|
||||
|
||||
// this is what we seem to need
|
||||
// these MUST correspond to foamToStarFaceAddr
|
||||
//
|
||||
Map<label> faceLookupIndex;
|
||||
faceLookupIndex.insert(hexModel->index(), 0);
|
||||
faceLookupIndex.insert(prismModel->index(), 1);
|
||||
faceLookupIndex.insert(tetModel->index(), 2);
|
||||
faceLookupIndex.insert(pyrModel->index(), 3);
|
||||
// Mapping between OpenFOAM and PROSTAR primitives
|
||||
// - needed for face mapping
|
||||
//
|
||||
const Map<label> prostarShapeLookup =
|
||||
{
|
||||
{ hexModel->index(), STARCDCore::starcdHex },
|
||||
{ prismModel->index(), STARCDCore::starcdPrism },
|
||||
{ tetModel->index(), STARCDCore::starcdTet },
|
||||
{ pyrModel->index(), STARCDCore::starcdPyr }
|
||||
};
|
||||
|
||||
Info<< "Writing " << os.name() << " : "
|
||||
<< (mesh_.nFaces() - patches[0].start()) << " boundaries" << endl;
|
||||
|
||||
|
||||
label defaultId = findDefaultBoundary();
|
||||
const label defaultId = findDefaultBoundary();
|
||||
|
||||
//
|
||||
// write boundary faces - skip Default_Boundary_Region entirely
|
||||
@ -435,8 +395,8 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
|
||||
label mapIndex = shape.model().index();
|
||||
|
||||
// a registered primitive type
|
||||
if (faceLookupIndex.found(mapIndex))
|
||||
// A registered primitive type
|
||||
if (prostarShapeLookup.found(mapIndex))
|
||||
{
|
||||
const faceList sFaces = shape.faces();
|
||||
forAll(sFaces, sFacei)
|
||||
@ -448,8 +408,8 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
}
|
||||
}
|
||||
|
||||
mapIndex = faceLookupIndex[mapIndex];
|
||||
cellFaceId = foamToStarFaceAddr[mapIndex][cellFaceId];
|
||||
mapIndex = prostarShapeLookup[mapIndex];
|
||||
cellFaceId = STARCDCore::foamToStarFaceAddr[mapIndex][cellFaceId];
|
||||
}
|
||||
// Info<< endl;
|
||||
|
||||
@ -473,10 +433,12 @@ void Foam::fileFormats::STARCDMeshWriter::writeBoundary
|
||||
Foam::fileFormats::STARCDMeshWriter::STARCDMeshWriter
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const scalar scaleFactor
|
||||
const scalar scaleFactor,
|
||||
const bool writeBndFile
|
||||
)
|
||||
:
|
||||
meshWriter(mesh, scaleFactor)
|
||||
meshWriter(mesh, scaleFactor),
|
||||
writeBoundary_(writeBndFile)
|
||||
{
|
||||
boundaryRegion_.readDict(mesh_);
|
||||
cellTable_.readDict(mesh_);
|
||||
@ -492,15 +454,6 @@ Foam::fileFormats::STARCDMeshWriter::~STARCDMeshWriter()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::fileFormats::STARCDMeshWriter::rmFiles(const fileName& baseName) const
|
||||
{
|
||||
rm(baseName + ".vrt");
|
||||
rm(baseName + ".cel");
|
||||
rm(baseName + ".bnd");
|
||||
rm(baseName + ".inp");
|
||||
}
|
||||
|
||||
|
||||
bool Foam::fileFormats::STARCDMeshWriter::write(const fileName& meshName) const
|
||||
{
|
||||
fileName baseName(meshName);
|
||||
@ -519,10 +472,25 @@ bool Foam::fileFormats::STARCDMeshWriter::write(const fileName& meshName) const
|
||||
}
|
||||
}
|
||||
|
||||
rmFiles(baseName);
|
||||
writePoints(baseName);
|
||||
STARCDCore::removeFiles(baseName);
|
||||
|
||||
// points
|
||||
{
|
||||
OFstream os
|
||||
(
|
||||
starFileName(baseName, STARCDCore::VRT_FILE)
|
||||
);
|
||||
|
||||
Info<< "Writing " << os.name() << " : "
|
||||
<< mesh_.nPoints() << " points" << endl;
|
||||
|
||||
writePoints(os, mesh_.points(), scaleFactor_);
|
||||
}
|
||||
|
||||
// cells
|
||||
writeCells(baseName);
|
||||
|
||||
// boundaries
|
||||
if (writeBoundary_)
|
||||
{
|
||||
writeBoundary(baseName);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,6 +39,7 @@ SourceFiles
|
||||
#define STARCDMeshWriter_H
|
||||
|
||||
#include "meshWriter.H"
|
||||
#include "STARCDCore.H"
|
||||
#include "IOstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -55,27 +56,17 @@ namespace fileFormats
|
||||
|
||||
class STARCDMeshWriter
|
||||
:
|
||||
public meshWriter
|
||||
public meshWriter,
|
||||
protected STARCDCore
|
||||
{
|
||||
// Private Data
|
||||
// Private data
|
||||
|
||||
static const char* defaultBoundaryName;
|
||||
//- Write boundary (bnd) file - default true
|
||||
bool writeBoundary_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDMeshWriter(const STARCDMeshWriter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDMeshWriter&) = delete;
|
||||
|
||||
//- Pro-STAR 4+ header format
|
||||
static void writeHeader(Ostream&, const char* filetype);
|
||||
|
||||
//- Write points
|
||||
void writePoints(const fileName& baseName) const;
|
||||
|
||||
//- Write cells
|
||||
void writeCells(const fileName& baseName) const;
|
||||
|
||||
@ -87,18 +78,24 @@ class STARCDMeshWriter
|
||||
label findDefaultBoundary() const;
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDMeshWriter(const STARCDMeshWriter&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDMeshWriter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
//- Face addressing from OpenFOAM faces -> pro-STAR faces
|
||||
static const label foamToStarFaceAddr[4][6];
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Write mesh files in PROSTAR format
|
||||
STARCDMeshWriter(const polyMesh&, const scalar scaleFactor = 1.0);
|
||||
STARCDMeshWriter
|
||||
(
|
||||
const polyMesh&,
|
||||
const scalar scaleFactor = 1.0,
|
||||
const bool writeBndFile = true
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -107,19 +104,13 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Edit
|
||||
// Write
|
||||
|
||||
//- Remove STAR-CD files for the baseName
|
||||
void rmFiles(const fileName& baseName) const;
|
||||
|
||||
|
||||
// Write
|
||||
|
||||
//- Write volume mesh
|
||||
virtual bool write
|
||||
(
|
||||
const fileName& meshName = fileName::null
|
||||
) const;
|
||||
//- Write volume mesh
|
||||
virtual bool write
|
||||
(
|
||||
const fileName& meshName = fileName::null
|
||||
) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,7 +37,7 @@ inline void Foam::fileFormats::STARCDedgeFormat::writeLines
|
||||
const edgeList& edges
|
||||
)
|
||||
{
|
||||
writeHeader(os, "CELL");
|
||||
writeHeader(os, STARCDCore::HEADER_CEL);
|
||||
|
||||
forAll(edges, edgeI)
|
||||
{
|
||||
@ -45,10 +45,10 @@ inline void Foam::fileFormats::STARCDedgeFormat::writeLines
|
||||
const label cellId = edgeI + 1;
|
||||
|
||||
os << cellId // includes 1 offset
|
||||
<< ' ' << starcdLineShape_ // 2(line) shape
|
||||
<< ' ' << starcdLine // 2(line) shape
|
||||
<< ' ' << e.size()
|
||||
<< ' ' << 401 // arbitrary value
|
||||
<< ' ' << starcdLineType_; // 5(line)
|
||||
<< ' ' << starcdLineType; // 5(line)
|
||||
|
||||
os << nl << " " << cellId << " "
|
||||
<< (e[0]+1) << " " << (e[1]+1) << nl;
|
||||
@ -118,7 +118,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
|
||||
// read points from .vrt file
|
||||
readPoints
|
||||
(
|
||||
IFstream(baseName + ".vrt")(),
|
||||
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
|
||||
storedPoints(),
|
||||
pointId
|
||||
);
|
||||
@ -137,7 +137,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
|
||||
//
|
||||
// read .cel file
|
||||
// ~~~~~~~~~~~~~~
|
||||
IFstream is(baseName + ".cel");
|
||||
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -145,7 +145,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
readHeader(is, "PROSTAR_CELL");
|
||||
readHeader(is, STARCDCore::HEADER_CEL);
|
||||
|
||||
DynamicList<edge> dynEdges;
|
||||
|
||||
@ -173,7 +173,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
|
||||
vertexLabels.append(mapPointId[vrtId]);
|
||||
}
|
||||
|
||||
if (typeId == starcdLineType_)
|
||||
if (typeId == starcdLineType)
|
||||
{
|
||||
if (vertexLabels.size() >= 2)
|
||||
{
|
||||
@ -239,13 +239,21 @@ void Foam::fileFormats::STARCDedgeFormat::write
|
||||
|
||||
fileName baseName = filename.lessExt();
|
||||
|
||||
writePoints(OFstream(baseName + ".vrt")(), pointLst);
|
||||
writeLines(OFstream(baseName + ".cel")(), edgeLst);
|
||||
writePoints
|
||||
(
|
||||
OFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
|
||||
pointLst
|
||||
);
|
||||
writeLines
|
||||
(
|
||||
OFstream(starFileName(baseName, STARCDCore::CEL_FILE))(),
|
||||
edgeLst
|
||||
);
|
||||
|
||||
// write a simple .inp file
|
||||
writeCase
|
||||
(
|
||||
OFstream(baseName + ".inp")(),
|
||||
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),
|
||||
pointLst,
|
||||
edgeLst.size()
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -62,30 +62,18 @@ namespace fileFormats
|
||||
class STARCDedgeFormat
|
||||
:
|
||||
public edgeMesh,
|
||||
public STARCDCore
|
||||
protected STARCDCore
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- STAR-CD identifier for line shapes (1d elements)
|
||||
static const int starcdLineShape_ = 2;
|
||||
|
||||
//- STAR-CD identifier for line type
|
||||
static const int starcdLineType_ = 5;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static inline void writeLines
|
||||
(
|
||||
Ostream&,
|
||||
const edgeList&
|
||||
);
|
||||
static inline void writeLines(Ostream&, const edgeList&);
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDedgeFormat(const STARCDedgeFormat&);
|
||||
STARCDedgeFormat(const STARCDedgeFormat&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDedgeFormat&);
|
||||
void operator=(const STARCDedgeFormat&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,6 +28,72 @@ License
|
||||
#include "clock.H"
|
||||
#include "PackedBoolList.H"
|
||||
#include "IStringStream.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::NamedEnum<Foam::fileFormats::STARCDCore::fileHeader, 3>
|
||||
Foam::fileFormats::STARCDCore::fileHeaders_;
|
||||
|
||||
const Foam::NamedEnum<Foam::fileFormats::STARCDCore::fileExt, 4>
|
||||
Foam::fileFormats::STARCDCore::fileExtensions_;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::fileFormats::STARCDCore::fileHeader,
|
||||
3
|
||||
>::names[] =
|
||||
{
|
||||
"PROSTAR_CELL",
|
||||
"PROSTAR_VERTEX",
|
||||
"PROSTAR_BOUNDARY"
|
||||
};
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::fileFormats::STARCDCore::fileExt,
|
||||
4
|
||||
>::names[] =
|
||||
{
|
||||
"cel",
|
||||
"vrt",
|
||||
"bnd",
|
||||
"inp"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const char* const Foam::fileFormats::STARCDCore::defaultBoundaryName =
|
||||
"Default_Boundary_Region";
|
||||
|
||||
const char* const Foam::fileFormats::STARCDCore::defaultSolidBoundaryName =
|
||||
"Default_Boundary_Solid";
|
||||
|
||||
|
||||
const Foam::Map<Foam::FixedList<int, 6>>
|
||||
Foam::fileFormats::STARCDCore::foamToStarFaceAddr =
|
||||
{
|
||||
{ starcdHex, { 4, 5, 2, 3, 0, 1 } },
|
||||
{ starcdPrism, { 0, 1, 4, 5, 2, -1 } },
|
||||
{ starcdTet, { 5, 4, 2, 0, -1, -1 } },
|
||||
{ starcdPyr, { 0, 4, 3, 5, 2, -1 } }
|
||||
};
|
||||
|
||||
|
||||
const Foam::Map<Foam::FixedList<int, 6>>
|
||||
Foam::fileFormats::STARCDCore::starToFoamFaceAddr =
|
||||
{
|
||||
{ starcdHex, { 4, 5, 2, 3, 0, 1 } },
|
||||
{ starcdPrism, { 0, 1, 4, -1, 2, 3 } },
|
||||
{ starcdTet, { 3, -1, 2, -1, 1, 0 } },
|
||||
{ starcdPyr, { 0, -1, 4, 2, 1, 3 } }
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -40,7 +106,7 @@ Foam::fileFormats::STARCDCore::STARCDCore()
|
||||
bool Foam::fileFormats::STARCDCore::readHeader
|
||||
(
|
||||
IFstream& is,
|
||||
const word& signature
|
||||
const enum fileHeader header
|
||||
)
|
||||
{
|
||||
if (!is.good())
|
||||
@ -49,22 +115,25 @@ bool Foam::fileFormats::STARCDCore::readHeader
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
word header;
|
||||
word magic;
|
||||
label majorVersion;
|
||||
|
||||
string line;
|
||||
|
||||
is.getLine(line);
|
||||
IStringStream(line)() >> header;
|
||||
IStringStream(line)() >> magic;
|
||||
|
||||
is.getLine(line);
|
||||
IStringStream(line)() >> majorVersion;
|
||||
|
||||
// add other checks ...
|
||||
if (header != signature)
|
||||
if (magic != fileHeaders_[header])
|
||||
{
|
||||
Info<< "header mismatch " << signature << " " << is.name()
|
||||
Info<< "header mismatch " << fileHeaders_[header]
|
||||
<< " " << is.name()
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -74,10 +143,10 @@ bool Foam::fileFormats::STARCDCore::readHeader
|
||||
void Foam::fileFormats::STARCDCore::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const word& filetype
|
||||
const enum fileHeader header
|
||||
)
|
||||
{
|
||||
os << "PROSTAR_" << filetype << nl
|
||||
os << fileHeaders_[header] << nl
|
||||
<< 4000
|
||||
<< " " << 0
|
||||
<< " " << 0
|
||||
@ -92,13 +161,34 @@ void Foam::fileFormats::STARCDCore::writeHeader
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::fileFormats::STARCDCore::readPoints
|
||||
Foam::fileName Foam::fileFormats::STARCDCore::starFileName
|
||||
(
|
||||
const fileName& base,
|
||||
const enum fileExt ext
|
||||
)
|
||||
{
|
||||
return base + '.' + fileExtensions_[ext];
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDCore::removeFiles(const fileName& base)
|
||||
{
|
||||
Foam::rm(starFileName(base, VRT_FILE));
|
||||
Foam::rm(starFileName(base, CEL_FILE));
|
||||
Foam::rm(starFileName(base, BND_FILE));
|
||||
Foam::rm(starFileName(base, INP_FILE));
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::fileFormats::STARCDCore::readPoints
|
||||
(
|
||||
IFstream& is,
|
||||
pointField& points,
|
||||
labelList& ids
|
||||
)
|
||||
{
|
||||
label maxId = 0;
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -106,8 +196,7 @@ bool Foam::fileFormats::STARCDCore::readPoints
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
readHeader(is, "PROSTAR_VERTEX");
|
||||
|
||||
readHeader(is, HEADER_VRT);
|
||||
|
||||
// reuse memory if possible
|
||||
DynamicList<point> dynPoints(points.xfer());
|
||||
@ -116,31 +205,35 @@ bool Foam::fileFormats::STARCDCore::readPoints
|
||||
dynPoints.clear();
|
||||
dynPointId.clear();
|
||||
|
||||
label lineLabel;
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
label lineLabel;
|
||||
scalar x, y, z;
|
||||
|
||||
is >> x >> y >> z;
|
||||
while ((is >> lineLabel).good())
|
||||
{
|
||||
maxId = max(maxId, lineLabel);
|
||||
is >> x >> y >> z;
|
||||
|
||||
dynPoints.append(point(x, y, z));
|
||||
dynPointId.append(lineLabel);
|
||||
dynPoints.append(point(x, y, z));
|
||||
dynPointId.append(lineLabel);
|
||||
}
|
||||
}
|
||||
|
||||
points.transfer(dynPoints);
|
||||
ids.transfer(dynPointId);
|
||||
|
||||
return true;
|
||||
return maxId;
|
||||
}
|
||||
|
||||
|
||||
void Foam::fileFormats::STARCDCore::writePoints
|
||||
(
|
||||
Ostream& os,
|
||||
const pointField& pointLst
|
||||
const pointField& points,
|
||||
const double scaleFactor
|
||||
)
|
||||
{
|
||||
writeHeader(os, "VERTEX");
|
||||
writeHeader(os, HEADER_VRT);
|
||||
|
||||
// Set the precision of the points data to 10
|
||||
os.precision(10);
|
||||
@ -148,18 +241,17 @@ void Foam::fileFormats::STARCDCore::writePoints
|
||||
// force decimal point for Fortran input
|
||||
os.setf(std::ios::showpoint);
|
||||
|
||||
forAll(pointLst, ptI)
|
||||
forAll(points, ptI)
|
||||
{
|
||||
// convert [m] -> [mm] etc
|
||||
os
|
||||
<< ptI + 1 << " "
|
||||
<< pointLst[ptI].x() << " "
|
||||
<< pointLst[ptI].y() << " "
|
||||
<< pointLst[ptI].z() << nl;
|
||||
<< ptI + 1 << ' '
|
||||
<< scaleFactor * points[ptI].x() << ' '
|
||||
<< scaleFactor * points[ptI].y() << ' '
|
||||
<< scaleFactor * points[ptI].z() << '\n';
|
||||
}
|
||||
os.flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,7 +36,10 @@ SourceFiles
|
||||
#define STARCDCore_H
|
||||
|
||||
#include "IFstream.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "pointField.H"
|
||||
#include "Map.H"
|
||||
#include "FixedList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -52,20 +55,29 @@ namespace fileFormats
|
||||
|
||||
class STARCDCore
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
|
||||
// Protected Member Functions
|
||||
// Public Data, Declarations
|
||||
|
||||
//- Read header
|
||||
static bool readHeader(IFstream&, const word& fileSignature);
|
||||
//- Enumeration defining the file headers
|
||||
enum fileHeader
|
||||
{
|
||||
HEADER_CEL,
|
||||
HEADER_VRT,
|
||||
HEADER_BND
|
||||
};
|
||||
|
||||
//- Write header for fileType (CELL|VERTEX|BOUNDARY)
|
||||
static void writeHeader(Ostream&, const word& fileType);
|
||||
//- Enumeration defining the file extensions
|
||||
enum fileExt
|
||||
{
|
||||
CEL_FILE,
|
||||
VRT_FILE,
|
||||
BND_FILE,
|
||||
INP_FILE
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
enum cellType
|
||||
//- Basic material type for STARCD/PROSTAR files
|
||||
enum matlType
|
||||
{
|
||||
starcdFluidType = 1,
|
||||
starcdSolidType = 2,
|
||||
@ -75,6 +87,7 @@ protected:
|
||||
starcdPointType = 6
|
||||
};
|
||||
|
||||
//- Shape-Type for STARCD/PROSTAR files
|
||||
enum shapeType
|
||||
{
|
||||
starcdPoint = 1,
|
||||
@ -88,11 +101,61 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
//- The name for default (unassigned) boundaries
|
||||
static const char* const defaultBoundaryName;
|
||||
|
||||
//- The name we have chosen for default (unassigned) solid boundaries.
|
||||
// Slightly distinguished from the regular default name.
|
||||
static const char* const defaultSolidBoundaryName;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Data
|
||||
|
||||
static const NamedEnum<fileHeader, 3> fileHeaders_;
|
||||
static const NamedEnum<fileExt, 4> fileExtensions_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Face addressing from pro-STAR faces to OpenFOAM faces.
|
||||
// For hex, prism, tet, pyr primitive shapes.
|
||||
static const Map<FixedList<int, 6>> starToFoamFaceAddr;
|
||||
|
||||
//- Face addressing from OpenFOAM faces to pro-STAR faces.
|
||||
// For hex, prism, tet, pyr primitive shapes.
|
||||
static const Map<FixedList<int, 6>> foamToStarFaceAddr;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
STARCDCore();
|
||||
|
||||
//- Read header and check signature PROSTAR_(CELL|VERTEX|BOUNDARY)
|
||||
static bool readHeader(IFstream&, const enum fileHeader);
|
||||
|
||||
//- Write header for fileType (CELL|VERTEX|BOUNDARY)
|
||||
static void writeHeader(Ostream&, const enum fileHeader);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Read points from a (.vrt) file
|
||||
//- Resolve base file-name for the given file-type
|
||||
static fileName starFileName(const fileName& baseName, const enum fileExt);
|
||||
|
||||
|
||||
//- Remove existing PROSTAR files for the given base file-name
|
||||
static void removeFiles(const fileName& baseName);
|
||||
|
||||
|
||||
//- Read points from a (.vrt) file, return the max prostar id used.
|
||||
//
|
||||
// The file format is as follows:
|
||||
// \verbatim
|
||||
// Line 1:
|
||||
@ -104,16 +167,20 @@ public:
|
||||
// Body:
|
||||
// {vertexId} {x} {y} {z} newline
|
||||
// \endverbatim
|
||||
static bool readPoints(IFstream&, pointField&, labelList& ids);
|
||||
static label readPoints
|
||||
(
|
||||
IFstream&,
|
||||
pointField&,
|
||||
labelList& ids
|
||||
);
|
||||
|
||||
//- Write header and points to (.vrt) file
|
||||
static void writePoints(Ostream&, const pointField&);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
STARCDCore();
|
||||
//- Write header and points to (.vrt) file, optionally with scaling
|
||||
static void writePoints
|
||||
(
|
||||
Ostream&,
|
||||
const pointField&,
|
||||
const scalar scaleFactor = 1.0
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -38,10 +38,10 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
|
||||
)
|
||||
{
|
||||
os << cellId // includes 1 offset
|
||||
<< ' ' << starcdShellShape_ // 3(shell) shape
|
||||
<< ' ' << starcdShell // 3(shell) shape
|
||||
<< ' ' << f.size()
|
||||
<< ' ' << cellTableId
|
||||
<< ' ' << starcdShellType_; // 4(shell)
|
||||
<< ' ' << starcdShellType; // 4(shell)
|
||||
|
||||
// primitives have <= 8 vertices, but prevent overrun anyhow
|
||||
// indent following lines for ease of reading
|
||||
@ -85,15 +85,10 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
fileName baseName = filename.lessExt();
|
||||
|
||||
// read cellTable names (if possible)
|
||||
Map<word> cellTableLookup;
|
||||
|
||||
{
|
||||
IFstream is(baseName + ".inp");
|
||||
if (is.good())
|
||||
{
|
||||
cellTableLookup = readInpCellTable(is);
|
||||
}
|
||||
}
|
||||
Map<word> cellTableLookup = readInpCellTable
|
||||
(
|
||||
IFstream(starFileName(baseName, STARCDCore::INP_FILE))()
|
||||
);
|
||||
|
||||
|
||||
// STAR-CD index of points
|
||||
@ -102,7 +97,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
// read points from .vrt file
|
||||
readPoints
|
||||
(
|
||||
IFstream(baseName + ".vrt")(),
|
||||
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
|
||||
this->storedPoints(),
|
||||
pointId
|
||||
);
|
||||
@ -115,10 +110,10 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
}
|
||||
pointId.clear();
|
||||
|
||||
//
|
||||
|
||||
// read .cel file
|
||||
// ~~~~~~~~~~~~~~
|
||||
IFstream is(baseName + ".cel");
|
||||
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
@ -126,7 +121,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
readHeader(is, "PROSTAR_CELL");
|
||||
readHeader(is, STARCDCore::HEADER_CEL);
|
||||
|
||||
DynamicList<Face> dynFaces;
|
||||
DynamicList<label> dynZones;
|
||||
@ -162,7 +157,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
|
||||
vertexLabels.append(mapPointId[vrtId]);
|
||||
}
|
||||
|
||||
if (typeId == starcdShellType_)
|
||||
if (typeId == starcdShellType)
|
||||
{
|
||||
// Convert groupID into zoneID
|
||||
Map<label>::const_iterator fnd = lookup.find(cellTableId);
|
||||
@ -262,9 +257,13 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
|
||||
|
||||
fileName baseName = filename.lessExt();
|
||||
|
||||
writePoints(OFstream(baseName + ".vrt")(), pointLst);
|
||||
OFstream os(baseName + ".cel");
|
||||
writeHeader(os, "CELL");
|
||||
writePoints
|
||||
(
|
||||
OFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
|
||||
pointLst
|
||||
);
|
||||
OFstream os(starFileName(baseName, STARCDCore::CEL_FILE));
|
||||
writeHeader(os, STARCDCore::HEADER_CEL);
|
||||
|
||||
label faceIndex = 0;
|
||||
forAll(zones, zoneI)
|
||||
@ -292,7 +291,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
|
||||
// write simple .inp file
|
||||
writeCase
|
||||
(
|
||||
OFstream(baseName + ".inp")(),
|
||||
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),
|
||||
pointLst,
|
||||
faceLst.size(),
|
||||
zones
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -63,15 +63,6 @@ class STARCDsurfaceFormat
|
||||
public MeshedSurface<Face>,
|
||||
public STARCDsurfaceFormatCore
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- STAR-CD identifier for shell shapes (2d elements)
|
||||
static const int starcdShellShape_ = 3;
|
||||
|
||||
//- STAR-CD identifier for shell type (shells vs. baffles)
|
||||
static const int starcdShellType_ = 4;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
static inline void writeShell
|
||||
@ -83,10 +74,10 @@ class STARCDsurfaceFormat
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&);
|
||||
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const STARCDsurfaceFormat<Face>&);
|
||||
void operator=(const STARCDsurfaceFormat<Face>&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -42,6 +42,11 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
|
||||
{
|
||||
Map<word> lookup;
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
return lookup;
|
||||
}
|
||||
|
||||
regExp ctnameRE
|
||||
(
|
||||
" *CTNA[^ ]*" // keyword - min 4 chars
|
||||
|
||||
Reference in New Issue
Block a user