diff --git a/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C b/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C index b4692d201a..f8fe44f19f 100644 --- a/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C +++ b/applications/utilities/mesh/conversion/foamToStarMesh/foamToStarMesh.C @@ -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) diff --git a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C index af57977d78..65261399d0 100644 --- a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C +++ b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C @@ -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 mesh = reader.mesh(runTime); reader.writeMesh(mesh, format); diff --git a/src/conversion/common/reader/meshReader.C b/src/conversion/common/reader/meshReader.C index c7e2d67980..4a6356910c 100644 --- a/src/conversion/common/reader/meshReader.C +++ b/src/conversion/common/reader/meshReader.C @@ -213,7 +213,13 @@ Foam::meshReader::meshReader baffleFaces_(0), cellTableId_(0), cellTable_() -{} +{ + // Sanity + if (scaleFactor_ <= VSMALL) + { + scaleFactor_ = 1; + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/conversion/common/reader/meshReader.H b/src/conversion/common/reader/meshReader.H index 54d5876e96..b53d0c1e4d 100644 --- a/src/conversion/common/reader/meshReader.H +++ b/src/conversion/common/reader/meshReader.H @@ -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 diff --git a/src/conversion/common/writer/meshWriter.C b/src/conversion/common/writer/meshWriter.C index 36d6426757..760cccea7a 100644 --- a/src/conversion/common/writer/meshWriter.C +++ b/src/conversion/common/writer/meshWriter.C @@ -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 * * * * * * * * * * * * * * * // diff --git a/src/conversion/common/writer/meshWriter.H b/src/conversion/common/writer/meshWriter.H index 51f4c4014a..d17322fde0 100644 --- a/src/conversion/common/writer/meshWriter.H +++ b/src/conversion/common/writer/meshWriter.H @@ -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; }; diff --git a/src/conversion/starcd/STARCDMeshReader.C b/src/conversion/starcd/STARCDMeshReader.C index e5ddc1bcb5..0229eaa0d2 100644 --- a/src/conversion/starcd/STARCDMeshReader.C +++ b/src/conversion/starcd/STARCDMeshReader.C @@ -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: [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