From 0d49e4711c93023f756d5359fa44d15509ab2a4d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 15 Jan 2010 14:35:50 +0100 Subject: [PATCH] Begin code refactoring of third-party file formats. --- .../foamDebugSwitches/Make/options | 1 + .../surface/surfaceSubset/surfaceSubset.C | 30 +-- .../surface/surfaceSubset/surfaceSubsetDict | 2 +- src/Allwmake | 1 + src/edgeMesh/Make/options | 5 + src/edgeMesh/edgeFormats/nas/NASedgeFormat.C | 28 --- src/edgeMesh/edgeFormats/nas/NASedgeFormat.H | 11 +- .../edgeFormats/starcd/STARCDedgeFormat.C | 128 ------------- .../edgeFormats/starcd/STARCDedgeFormat.H | 13 +- src/fileFormats/Make/files | 4 + src/fileFormats/Make/options | 0 .../nas/NASCore.C} | 13 +- .../nas/NASCore.H} | 32 ++-- src/fileFormats/starcd/STARCDCore.C | 173 ++++++++++++++++++ src/fileFormats/starcd/STARCDCore.H | 131 +++++++++++++ src/surfMesh/Make/files | 1 - src/surfMesh/Make/options | 5 + .../surfaceFormats/nas/NASsurfaceFormat.H | 4 +- .../starcd/STARCDsurfaceFormatCore.C | 140 +------------- .../starcd/STARCDsurfaceFormatCore.H | 11 +- src/triSurface/Make/options | 6 +- 21 files changed, 380 insertions(+), 359 deletions(-) create mode 100644 src/fileFormats/Make/files create mode 100644 src/fileFormats/Make/options rename src/{surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.C => fileFormats/nas/NASCore.C} (87%) rename src/{surfMesh/surfaceFormats/nas/NASsurfaceFormatCore.H => fileFormats/nas/NASCore.H} (81%) create mode 100644 src/fileFormats/starcd/STARCDCore.C create mode 100644 src/fileFormats/starcd/STARCDCore.H diff --git a/applications/utilities/miscellaneous/foamDebugSwitches/Make/options b/applications/utilities/miscellaneous/foamDebugSwitches/Make/options index e473b84bb9..7207b53927 100644 --- a/applications/utilities/miscellaneous/foamDebugSwitches/Make/options +++ b/applications/utilities/miscellaneous/foamDebugSwitches/Make/options @@ -18,6 +18,7 @@ EXE_LIBS = \ -lengine \ -lerrorEstimation \ -lfieldFunctionObjects \ + -lfileFormats \ -lfiniteVolume \ -lforces \ -lfvMotionSolvers \ diff --git a/applications/utilities/surface/surfaceSubset/surfaceSubset.C b/applications/utilities/surface/surfaceSubset/surfaceSubset.C index dd8a6ede00..6cc8ee4678 100644 --- a/applications/utilities/surface/surfaceSubset/surfaceSubset.C +++ b/applications/utilities/surface/surfaceSubset/surfaceSubset.C @@ -100,10 +100,8 @@ int main(int argc, char *argv[]) meshSubsetDict.lookup("addFaceNeighbours") ); - Switch invertSelection - ( - meshSubsetDict.lookup("invertSelection") - ); + const bool invertSelection = + meshSubsetDict.lookupOrDefault("invertSelection", false); // Mark the cells for the subset @@ -246,7 +244,7 @@ int main(int argc, char *argv[]) // bb of surface treeBoundBox bb(selectSurf.localPoints()); - // Radnom number generator + // Random number generator Random rndGen(354543); // search engine @@ -269,14 +267,11 @@ int main(int argc, char *argv[]) indexedOctree::volumeType t = selectTree.getVolumeType(fc); - if (t == indexedOctree::INSIDE && !outside) - { - facesToSubset[faceI] = true; - } - else if + if ( - t == indexedOctree::OUTSIDE - && outside + outside + ? (t == indexedOctree::OUTSIDE) + : (t == indexedOctree::INSIDE) ) { facesToSubset[faceI] = true; @@ -346,20 +341,11 @@ int main(int argc, char *argv[]) if (invertSelection) { Info<< "Inverting selection." << endl; - boolList newFacesToSubset(facesToSubset.size()); forAll(facesToSubset, i) { - if (facesToSubset[i]) - { - newFacesToSubset[i] = false; - } - else - { - newFacesToSubset[i] = true; - } + facesToSubset[i] = facesToSubset[i] ? false : true; } - facesToSubset.transfer(newFacesToSubset); } diff --git a/applications/utilities/surface/surfaceSubset/surfaceSubsetDict b/applications/utilities/surface/surfaceSubset/surfaceSubsetDict index 3a8db2cffd..f956a24789 100644 --- a/applications/utilities/surface/surfaceSubset/surfaceSubsetDict +++ b/applications/utilities/surface/surfaceSubset/surfaceSubsetDict @@ -36,7 +36,7 @@ zone surface { name "sphere.stl"; - outside yes; + outside yes; } // Extend selection with edge neighbours diff --git a/src/Allwmake b/src/Allwmake index a91f131e55..f24f2f370d 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -22,6 +22,7 @@ wmake libso OpenFOAM wmake libso lagrangian/basic +wmake libso fileFormats wmake libso edgeMesh wmake libso surfMesh wmake libso triSurface diff --git a/src/edgeMesh/Make/options b/src/edgeMesh/Make/options index e69de29bb2..7e207d0dbe 100644 --- a/src/edgeMesh/Make/options +++ b/src/edgeMesh/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude + +LIB_LIBS = \ + -lfileFormats diff --git a/src/edgeMesh/edgeFormats/nas/NASedgeFormat.C b/src/edgeMesh/edgeFormats/nas/NASedgeFormat.C index 4b178d1dbd..fec0c883a3 100644 --- a/src/edgeMesh/edgeFormats/nas/NASedgeFormat.C +++ b/src/edgeMesh/edgeFormats/nas/NASedgeFormat.C @@ -29,34 +29,6 @@ License #include "IStringStream.H" #include "PackedBoolList.H" -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -// Do weird things to extract a floating point number -Foam::scalar Foam::fileFormats::NASedgeFormat::parseNASCoord -( - const string& s -) -{ - size_t expSign = s.find_last_of("+-"); - - if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1])) - { - scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))()); - scalar exponent = readScalar(IStringStream(s.substr(expSign+1))()); - - if (s[expSign] == '-') - { - exponent = -exponent; - } - return mantissa * pow(10, exponent); - } - else - { - return readScalar(IStringStream(s)()); - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::fileFormats::NASedgeFormat::NASedgeFormat diff --git a/src/edgeMesh/edgeFormats/nas/NASedgeFormat.H b/src/edgeMesh/edgeFormats/nas/NASedgeFormat.H index 600b880cb7..3ccd4397af 100644 --- a/src/edgeMesh/edgeFormats/nas/NASedgeFormat.H +++ b/src/edgeMesh/edgeFormats/nas/NASedgeFormat.H @@ -37,6 +37,7 @@ SourceFiles #define NASedgeFormat_H #include "edgeMesh.H" +#include "NASCore.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -51,7 +52,8 @@ namespace fileFormats class NASedgeFormat : - public edgeMesh + public edgeMesh, + public NASCore { // Private Member Functions @@ -61,13 +63,6 @@ class NASedgeFormat //- Disallow default bitwise assignment void operator=(const NASedgeFormat&); -protected: - - // Protected Member Functions - - //- Do weird things to extract number - static scalar parseNASCoord(const string&); - public: // Constructors diff --git a/src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C b/src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C index b6ecd4d19e..f2fec25cc5 100644 --- a/src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C +++ b/src/edgeMesh/edgeFormats/starcd/STARCDedgeFormat.C @@ -59,134 +59,6 @@ inline void Foam::fileFormats::STARCDedgeFormat::writeLines // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::fileFormats::STARCDedgeFormat::readHeader -( - IFstream& is, - const word& signature -) -{ - if (!is.good()) - { - FatalErrorIn - ( - "fileFormats::STARCDedgeFormat::readHeader(...)" - ) - << "cannot read " << signature << " " << is.name() - << abort(FatalError); - } - - word header; - label majorVersion; - - string line; - - is.getLine(line); - IStringStream(line)() >> header; - - is.getLine(line); - IStringStream(line)() >> majorVersion; - - // add other checks ... - if (header != signature) - { - Info<< "header mismatch " << signature << " " << is.name() - << endl; - } - - return true; -} - - -void Foam::fileFormats::STARCDedgeFormat::writeHeader -( - Ostream& os, - const char* filetype -) -{ - os << "PROSTAR_" << filetype << nl - << 4000 - << " " << 0 - << " " << 0 - << " " << 0 - << " " << 0 - << " " << 0 - << " " << 0 - << " " << 0 - << endl; -} - - -bool Foam::fileFormats::STARCDedgeFormat::readPoints -( - IFstream& is, - pointField& points, - labelList& ids -) -{ - // - // read .vrt file - // ~~~~~~~~~~~~~~ - - if (!is.good()) - { - FatalErrorIn - ( - "fileFormats::STARCDedgeFormat::readPoints(...)" - ) - << "Cannot read file " << is.name() - << exit(FatalError); - } - - readHeader(is, "PROSTAR_VERTEX"); - - DynamicList dynPoints; - DynamicList