diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 3c61e371b6..c9b26376d0 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -46,14 +46,14 @@ sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C surfWriters = sampledSurface/writers -$(surfWriters)/surfaceWriters.C -$(surfWriters)/dx/dxSurfaceWriterRunTime.C -$(surfWriters)/ensight/ensightSurfaceWriterRunTime.C -$(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C -$(surfWriters)/null/nullSurfaceWriterRunTime.C -$(surfWriters)/proxy/proxySurfaceWriterRunTime.C -$(surfWriters)/raw/rawSurfaceWriterRunTime.C -$(surfWriters)/vtk/vtkSurfaceWriterRunTime.C +$(surfWriters)/surfaceWriter.C +$(surfWriters)/dx/dxSurfaceWriter.C +$(surfWriters)/ensight/ensightSurfaceWriter.C +$(surfWriters)/foamFile/foamFileSurfaceWriter.C +$(surfWriters)/proxy/proxySurfaceWriter.C +$(surfWriters)/raw/rawSurfaceWriter.C +$(surfWriters)/starcd/starcdSurfaceWriter.C +$(surfWriters)/vtk/vtkSurfaceWriter.C graphField/writePatchGraph.C graphField/writeCellGraph.C diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 06b3278489..e44e1f8a46 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -83,7 +83,7 @@ void Foam::sampledSurfaces::writeGeometry() const { if (Pstream::master() && mergeList_[surfI].faces.size()) { - genericFormatter_->write + formatter_->write ( outputDir, s.name(), @@ -94,7 +94,7 @@ void Foam::sampledSurfaces::writeGeometry() const } else if (s.faces().size()) { - genericFormatter_->write + formatter_->write ( outputDir, s.name(), @@ -123,9 +123,8 @@ Foam::sampledSurfaces::sampledSurfaces outputPath_(fileName::null), fieldSelection_(), interpolationScheme_(word::null), - writeFormat_(word::null), mergeList_(), - genericFormatter_(NULL), + formatter_(NULL), scalarFields_(), vectorFields_(), sphericalTensorFields_(), @@ -201,7 +200,7 @@ void Foam::sampledSurfaces::write() // write geometry first if required, // or when no fields would otherwise be written - if (nFields == 0 || genericFormatter_->separateFiles()) + if (nFields == 0 || formatter_->separateGeometry()) { writeGeometry(); } @@ -221,11 +220,11 @@ void Foam::sampledSurfaces::read(const dictionary& dict) clearFieldGroups(); dict.lookup("interpolationScheme") >> interpolationScheme_; - dict.lookup("surfaceFormat") >> writeFormat_; - // define the generic (geometry) writer - genericFormatter_ = surfaceWriter::New(writeFormat_); + word writeFormat(dict.lookup("surfaceFormat")); + // define the surface formatter + formatter_ = surfaceWriter::New(writeFormat); PtrList newList ( diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 0c2084507a..4293cf9e62 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,36 +68,11 @@ class sampledSurfaces { public: - //- The surface formatter - autoPtr< surfaceWriter > formatter; - //- Construct null fieldGroup() : - DynamicList(0), - formatter(NULL) + DynamicList(0) {} - - //- Construct for a particular surface format - fieldGroup(const word& writeFormat) - : - DynamicList(0), - formatter(surfaceWriter::New(writeFormat)) - {} - - //- Reset format and field list - void clear() - { - DynamicList::clear(); - formatter.clear(); - } - - //- Assign a new formatter - void operator=(const word& writeFormat) - { - formatter = surfaceWriter::New(writeFormat); - } - }; @@ -151,10 +126,6 @@ class sampledSurfaces //- Interpolation scheme to use word interpolationScheme_; - //- Output format to use - word writeFormat_; - - // surfaces //- Information for merging surfaces @@ -163,8 +134,8 @@ class sampledSurfaces // Calculated - //- Generic surface formatter - autoPtr< surfaceWriter > genericFormatter_; + //- Surface formatter + autoPtr formatter_; //- Categorized scalar/vector/tensor fields fieldGroup scalarFields_; @@ -190,14 +161,10 @@ class sampledSurfaces //- Sample and write a particular volume field template - void sampleAndWrite - ( - const GeometricField&, - const surfaceWriter& formatter - ); + void sampleAndWrite(const GeometricField&); //- Sample and write all the fields of the given type - template + template void sampleAndWrite(fieldGroup&); //- Disallow default bitwise copy construct and assignment diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 578212ba3f..1351821419 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,8 +32,7 @@ License template void Foam::sampledSurfaces::sampleAndWrite ( - const GeometricField& vField, - const surfaceWriter& formatter + const GeometricField& vField ) { // interpolator for this field @@ -96,7 +95,7 @@ void Foam::sampledSurfaces::sampleAndWrite // skip surface without faces (eg, a failed cut-plane) if (mergeList_[surfI].faces.size()) { - formatter.write + formatter_->write ( outputDir, s.name(), @@ -115,7 +114,7 @@ void Foam::sampledSurfaces::sampleAndWrite // skip surface without faces (eg, a failed cut-plane) if (s.faces().size()) { - formatter.write + formatter_->write ( outputDir, s.name(), @@ -139,12 +138,6 @@ void Foam::sampledSurfaces::sampleAndWrite { if (fields.size()) { - // create or use existing surfaceWriter - if (fields.formatter.empty()) - { - fields.formatter = surfaceWriter::New(writeFormat_); - } - forAll(fields, fieldI) { if (Pstream::master() && verbose_) @@ -168,8 +161,7 @@ void Foam::sampledSurfaces::sampleAndWrite false ), mesh_ - ), - fields.formatter() + ) ); } else @@ -190,8 +182,7 @@ void Foam::sampledSurfaces::sampleAndWrite > ( fields[fieldI] - ), - fields.formatter() + ) ); } } diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C index 6bdb3e63e9..3d477daf9a 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,10 +28,19 @@ License #include "OFstream.H" #include "OSspecific.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(dxSurfaceWriter); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -void Foam::dxSurfaceWriter::writeGeometry +void Foam::dxSurfaceWriter::writeGeometry ( Ostream& os, const pointField& points, @@ -54,7 +63,6 @@ void Foam::dxSurfaceWriter::writeGeometry os << nl; // Write triangles - os << "# The irregular connections (triangles)" << nl << "object 2 class array type int rank 1 shape 3 items " << faces.size() << " data follows" << nl; @@ -80,17 +88,41 @@ void Foam::dxSurfaceWriter::writeGeometry } +void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues) +{ + if (isNodeValues) + { + os << nl << "attribute \"dep\" string \"positions\"" + << nl << nl; + } + else + { + os << nl << "attribute \"dep\" string \"connections\"" + << nl << nl; + } + + os << "# the field, with three components: \"positions\"," + << " \"connections\", and \"data\"" << nl + << "object \"irregular positions irregular " + << "connections\" class field" + << nl + << "component \"positions\" value 1" << nl + << "component \"connections\" value 2" << nl + << "component \"data\" value 3" << nl; + + os << "end" << endl; +} + + namespace Foam { - // Write scalarField in DX format template<> - void Foam::dxSurfaceWriter::writeData + void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 0 items " << values.size() << " data follows" << nl; @@ -101,15 +133,13 @@ namespace Foam } - // Write vectorField in DX format template<> - void Foam::dxSurfaceWriter::writeData + void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 1 shape 3 items " << values.size() << " data follows" << nl; @@ -122,15 +152,13 @@ namespace Foam } - // Write sphericalTensorField in DX format template<> - void Foam::dxSurfaceWriter::writeData + void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 0 items " << values.size() << " data follows" << nl; @@ -141,15 +169,13 @@ namespace Foam } - // Write symmTensorField in DX format template<> - void Foam::dxSurfaceWriter::writeData + void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 2 shape 3 items " << values.size() << " data follows" << nl; @@ -165,15 +191,14 @@ namespace Foam } - // Write tensorField in DX format + // Write Field in DX format template<> - void Foam::dxSurfaceWriter::writeData + inline void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 2 shape 3 items " << values.size() << " data follows" << nl; @@ -189,15 +214,15 @@ namespace Foam } } -// Write tensorField in DX format + +// arbitrary field template -void Foam::dxSurfaceWriter::writeData +inline void Foam::dxSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - // Write data os << "object 3 class array type float rank 0 items " << values.size() << " data follows" << nl; @@ -208,41 +233,8 @@ void Foam::dxSurfaceWriter::writeData } -// Write trailer in DX format template -void Foam::dxSurfaceWriter::writeTrailer(Ostream& os) -{ - os << "# the field, with three components: \"positions\"," - << " \"connections\", and \"data\"" << nl - << "object \"irregular positions irregular " - << "connections\" class field" - << nl - << "component \"positions\" value 1" << nl - << "component \"connections\" value 2" << nl - << "component \"data\" value 3" << nl; -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::dxSurfaceWriter::dxSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::dxSurfaceWriter::~dxSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::dxSurfaceWriter::write +void Foam::dxSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -270,24 +262,29 @@ void Foam::dxSurfaceWriter::write } writeGeometry(os, points, faces); - writeData(os, values); - - if (isNodeValues) - { - os << nl << "attribute \"dep\" string \"positions\"" - << nl << nl; - } - else - { - os << nl << "attribute \"dep\" string \"connections\"" - << nl << nl; - } - - writeTrailer(os); - - os << "end" << nl; + writeTrailer(os, isNodeValues); } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::dxSurfaceWriter::dxSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::dxSurfaceWriter::~dxSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +// create write methods +defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter); + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H index feccf33be1..e4e3af67e6 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ Class Foam::dxSurfaceWriter Description + A surfaceWriter for OpenDX format. SourceFiles dxSurfaceWriter.C @@ -42,22 +43,36 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class dxSurfaceWriter Declaration + Class dxSurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class dxSurfaceWriter : - public surfaceWriter + public surfaceWriter { // Private Member Functions static void writeGeometry(Ostream&, const pointField&, const faceList&); + static void writeTrailer(Ostream&, const bool isNodeValues); - static void writeData(Ostream&, const Field& values); + template + static void writeData(Ostream&, const Field&); + + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; - static void writeTrailer(Ostream&); public: @@ -77,20 +92,76 @@ public: // Member Functions - // Write - - //- Writes single surface to file. + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, - const Field& values, + const word& fieldName, // name of field + const Field& values, const bool isNodeValues, const bool verbose = false ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + }; @@ -100,12 +171,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "dxSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterRunTime.C deleted file mode 100644 index a53ba0f34f..0000000000 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterRunTime.C +++ /dev/null @@ -1,43 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "dxSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriters(dxSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C index cde2d597a8..d705525ebc 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -31,6 +31,16 @@ License #include "ensightGeoFile.H" #include "ensightPartNonMeshFaces.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(ensightSurfaceWriter); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // namespace Foam @@ -38,30 +48,15 @@ namespace Foam // Write scalarField in ensight format template<> - void Foam::ensightSurfaceWriter::writeData + inline void Foam::ensightSurfaceWriter::writeData ( Ostream& os, - const Field& values + const Field& values ) { forAll(values, i) { - os << values[i] << nl; - } - } - - - // Write booField in ensight format - template<> - void Foam::ensightSurfaceWriter::writeData - ( - Ostream& os, - const Field& values - ) - { - forAll(values, i) - { - os << values[i] << nl; + os << values[i] << nl; } } } @@ -69,96 +64,25 @@ namespace Foam // Write generic field in ensight format template -void Foam::ensightSurfaceWriter::writeData +inline void Foam::ensightSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) + for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt) { scalarField v(values.component(cmpt)); forAll(v, i) { - os << v[i] << nl; + os << v[i] << nl; } } } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -// Construct from components template -Foam::ensightSurfaceWriter::ensightSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::ensightSurfaceWriter::~ensightSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::ensightSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - //const scalar timeValue = Foam::name(this->mesh().time().timeValue()); - const scalar timeValue = 0.0; - - - OFstream caseStr(outputDir/surfaceName + ".case"); - ensightGeoFile geomStr - ( - outputDir/surfaceName + ".000.mesh", - IOstream::ASCII - ); - - if (verbose) - { - Info<< "Writing case file to " << caseStr.name() << endl; - } - - caseStr - << "FORMAT" << nl - << "type: ensight gold" << nl - << nl - << "GEOMETRY" << nl - << "model: 1 " << geomStr.name().name() << nl - << nl - << "TIME" << nl - << "time set: 1" << nl - << "number of steps: 1" << nl - << "filename start number: 0" << nl - << "filename increment: 1" << nl - << "time values:" << nl - << timeValue << nl - << nl; - - ensightPartNonMeshFaces faceWriter(0, geomStr.name().name(), faces, points); - faceWriter.writeGeometry(geomStr); -} - - -template -void Foam::ensightSurfaceWriter::write +void Foam::ensightSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -175,10 +99,9 @@ void Foam::ensightSurfaceWriter::write mkDir(outputDir/fieldName); } - //const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); const scalar timeValue = 0.0; - OFstream caseStr(outputDir/fieldName/surfaceName + ".case"); ensightGeoFile geomStr ( @@ -230,8 +153,8 @@ void Foam::ensightSurfaceWriter::write << timeValue << nl << nl; - ensightPartNonMeshFaces faceWriter(0, geomStr.name().name(), faces, points); - faceWriter.writeGeometry(geomStr); + ensightPartNonMeshFaces ensPart(0, geomStr.name().name(), faces, points); + geomStr << ensPart; // Write field fieldStr @@ -246,19 +169,19 @@ void Foam::ensightSurfaceWriter::write } else { - //faceWriter.writeField(fieldStr, values); - forAll(faceWriter.elementTypes(), elemI) + // ensPart.writeField(fieldStr, values); + forAll(ensPart.elementTypes(), elemI) { - if (faceWriter.elemLists()[elemI].size()) + if (ensPart.elemLists()[elemI].size()) { - fieldStr.writeKeyword(faceWriter.elementTypes()[elemI]); + fieldStr.writeKeyword(ensPart.elementTypes()[elemI]); writeData ( fieldStr, Field ( values, - faceWriter.elemLists()[elemI] + ensPart.elemLists()[elemI] ) ); } @@ -267,4 +190,75 @@ void Foam::ensightSurfaceWriter::write } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::ensightSurfaceWriter::ensightSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::ensightSurfaceWriter::~ensightSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::ensightSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + //const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + const scalar timeValue = 0.0; + + + OFstream caseStr(outputDir/surfaceName + ".case"); + ensightGeoFile geomStr + ( + outputDir/surfaceName + ".000.mesh", + IOstream::ASCII + ); + + if (verbose) + { + Info<< "Writing case file to " << caseStr.name() << endl; + } + + caseStr + << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << geomStr.name().name() << nl + << nl + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: 1" << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl + << timeValue << nl + << nl; + + ensightPartNonMeshFaces ensPart(0, geomStr.name().name(), faces, points); + geomStr << ensPart; +} + + +// create write methods +defineSurfaceWriterWriteFields(Foam::ensightSurfaceWriter); + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H index d2f01c6479..4d2bf47b90 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ Class Foam::ensightSurfaceWriter Description + A surfaceWriter for Ensight format. SourceFiles ensightSurfaceWriter.C @@ -41,29 +42,41 @@ SourceFiles namespace Foam { -class ensightGeoFile; - /*---------------------------------------------------------------------------*\ Class ensightSurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class ensightSurfaceWriter : - public surfaceWriter + public surfaceWriter { // Private data - fileName caseFileName_; - fileName surfaceName_; - fileName geomName_; - DynamicList varNames_; - DynamicList varFileNames_; +// fileName caseFileName_; +// fileName surfaceName_; +// fileName geomName_; +// DynamicList varNames_; +// DynamicList varFileNames_; // Private Member Functions - static void writeData(Ostream&, const Field& values); + template + static inline void writeData(Ostream&, const Field&); + + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; public: @@ -84,9 +97,15 @@ public: // Member Functions - // Write + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() + { + return true; + } - //- Write geometry to file. + + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, @@ -97,18 +116,76 @@ public: ) const; - //- Writes single surface to file. + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, - const Field& values, + const word& fieldName, // name of field + const Field& values, const bool isNodeValues, const bool verbose = false ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + }; @@ -118,12 +195,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "ensightSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C deleted file mode 100644 index 8355a6d991..0000000000 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "ensightSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(ensightSurfaceWriter, bool); -makeSurfaceWriters(ensightSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C index 747a79f39a..06005b5c0a 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,67 +28,20 @@ License #include "OFstream.H" #include "OSspecific.H" -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +#include "makeSurfaceWriterMethods.H" -template -Foam::foamFileSurfaceWriter::foamFileSurfaceWriter() -: - surfaceWriter() -{} +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::foamFileSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose -) const +namespace Foam { - fileName surfaceDir(outputDir/surfaceName); - - if (!isDir(surfaceDir)) - { - mkDir(surfaceDir); - } - - if (verbose) - { - Info<< "Writing geometry to " << surfaceDir << endl; - } - - // Points - OFstream(surfaceDir/"points")() << points; - - // Faces - OFstream(surfaceDir/"faces")() << faces; - - // Face centers. Not really necessary but very handy when reusing as inputs - // for e.g. timeVaryingMapped bc. - pointField faceCentres(faces.size(),point::zero); - - forAll (faces, faceI) - { - faceCentres[faceI] = faces[faceI].centre(points); - } - - OFstream(surfaceDir/"faceCentres")() << faceCentres; + makeSurfaceWriterType(foamFileSurfaceWriter); } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + template -void Foam::foamFileSurfaceWriter::write +void Foam::foamFileSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -113,7 +66,6 @@ void Foam::foamFileSurfaceWriter::write } // geometry should already have been written - // Values to separate directory (e.g. "scalarField/p") fileName foamName(pTraits::typeName); @@ -125,8 +77,69 @@ void Foam::foamFileSurfaceWriter::write } // values - OFstream(valuesDir/fieldName)() << values; + OFstream(valuesDir/fieldName)() << values; } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::foamFileSurfaceWriter::foamFileSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::foamFileSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + fileName surfaceDir(outputDir/surfaceName); + + if (!isDir(surfaceDir)) + { + mkDir(surfaceDir); + } + + if (verbose) + { + Info<< "Writing geometry to " << surfaceDir << endl; + } + + + // Points + OFstream(surfaceDir/"points")() << points; + + // Faces + OFstream(surfaceDir/"faces")() << faces; + + // Face centers. Not really necessary but very handy when reusing as inputs + // for e.g. timeVaryingMapped bc. + pointField faceCentres(faces.size(),point::zero); + + forAll(faces, faceI) + { + faceCentres[faceI] = faces[faceI].centre(points); + } + + OFstream(surfaceDir/"faceCentres")() << faceCentres; +} + + +// create write methods +defineSurfaceWriterWriteFields(Foam::foamFileSurfaceWriter); + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H index 0076abdc88..ce19c21455 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,14 +43,29 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class foamFileSurfaceWriter Declaration + Class foamFileSurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class foamFileSurfaceWriter : - public surfaceWriter + public surfaceWriter { + // Private Member Functions + + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; + public: @@ -70,13 +85,14 @@ public: // Member Functions - //- Return true if the surface format supports separate files - virtual bool separateFiles() + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() { return true; } - //- Write geometry to file. + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, @@ -86,18 +102,77 @@ public: const bool verbose = false ) const; - //- Writes single surface to file. + + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, - const Field& values, + const word& fieldName, // name of field + const Field& values, const bool isNodeValues, const bool verbose = false ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + }; @@ -107,12 +182,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "foamFileSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C deleted file mode 100644 index c8a40e736c..0000000000 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "foamFileSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(foamFileSurfaceWriter, bool); -makeSurfaceWriters(foamFileSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H b/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H new file mode 100644 index 0000000000..b748a32c6c --- /dev/null +++ b/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +InClass + Foam::makeSurfaceWriterMethods + +Description + Convenience macros for instantiating writer methods for surfaceWriter + classes. + +\*---------------------------------------------------------------------------*/ + +#ifndef makeSurfaceWriterMethods_H +#define makeSurfaceWriterMethods_H + +#include "surfaceWriter.H" +#include "addToRunTimeSelectionTable.H" + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define makeSurfaceWriterType(ThisClass) \ + defineTypeNameAndDebug(ThisClass, 0); \ + addToRunTimeSelectionTable(surfaceWriter, ThisClass, word) + + +#define defineSurfaceWriterWriteField(ThisClass, FieldType) \ + void ThisClass::write \ + ( \ + const fileName& outputDir, \ + const fileName& surfaceName, \ + const pointField& points, \ + const faceList& faces, \ + const word& fieldName, \ + const Field& values, \ + const bool isNodeValues, \ + const bool verbose \ + ) const \ + { \ + writeTemplate \ + ( \ + outputDir, \ + surfaceName, \ + points, \ + faces, \ + fieldName, \ + values, \ + isNodeValues, \ + verbose \ + ); \ + } + + +#define defineSurfaceWriterWriteFields(ThisClass) \ + defineSurfaceWriterWriteField(ThisClass, scalar); \ + defineSurfaceWriterWriteField(ThisClass, vector); \ + defineSurfaceWriterWriteField(ThisClass, sphericalTensor); \ + defineSurfaceWriterWriteField(ThisClass, symmTensor); \ + defineSurfaceWriterWriteField(ThisClass, tensor) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C deleted file mode 100644 index 85d4fcbb62..0000000000 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C +++ /dev/null @@ -1,63 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "nullSurfaceWriter.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::nullSurfaceWriter::nullSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::nullSurfaceWriter::~nullSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::nullSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose -) const -{} - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H deleted file mode 100644 index aef12a76ce..0000000000 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H +++ /dev/null @@ -1,103 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::nullSurfaceWriter - -Description - -SourceFiles - nullSurfaceWriter.C - -\*---------------------------------------------------------------------------*/ - -#ifndef nullSurfaceWriter_H -#define nullSurfaceWriter_H - -#include "surfaceWriter.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class nullSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -template -class nullSurfaceWriter -: - public surfaceWriter -{ - -public: - - //- Runtime type information - TypeName("null"); - - - // Constructors - - //- Construct null - nullSurfaceWriter(); - - - //- Destructor - virtual ~nullSurfaceWriter(); - - - // Member Functions - - // Write - - //- Writes single surface to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const; -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository -# include "nullSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C deleted file mode 100644 index c9fd6af9d9..0000000000 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "nullSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(nullSurfaceWriter, bool); -makeSurfaceWriters(nullSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index 11990cfd83..d598754b38 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,27 +29,34 @@ License #include "OFstream.H" #include "OSspecific.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(proxySurfaceWriter, 0); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -Foam::proxySurfaceWriter::proxySurfaceWriter(const word& ext) +Foam::proxySurfaceWriter::proxySurfaceWriter(const word& ext) : - surfaceWriter(), + surfaceWriter(), ext_(ext) {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -template -Foam::proxySurfaceWriter::~proxySurfaceWriter() +Foam::proxySurfaceWriter::~proxySurfaceWriter() {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -void Foam::proxySurfaceWriter::write +void Foam::proxySurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -69,19 +76,14 @@ void Foam::proxySurfaceWriter::write mkDir(outputDir); } - fileName fName(outputDir/surfaceName + "." + ext_); + fileName outName(outputDir/surfaceName + "." + ext_); if (verbose) { - Info<< "Writing geometry to " << fName << endl; + Info<< "Writing geometry to " << outName << endl; } - MeshedSurfaceProxy - ( - points, - faces - ).write(fName); - + MeshedSurfaceProxy(points, faces).write(outName); } diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index 2cbc6c30ac..ad134b7b6e 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,8 @@ Class Foam::proxySurfaceWriter Description + A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but + which does not support any fields. SourceFiles proxySurfaceWriter.C @@ -42,13 +44,12 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class proxySurfaceWriter Declaration + Class proxySurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class proxySurfaceWriter : - public surfaceWriter + public surfaceWriter { // Private data @@ -74,15 +75,16 @@ public: // Member Functions - //- Always write separate geometry file - virtual bool separateFiles() + + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() { return true; } - // Write - //- Write geometry to file. + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, @@ -92,20 +94,6 @@ public: const bool verbose = false ) const; - - //- Writes single surface to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose = false - ) const - {} }; @@ -115,12 +103,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "proxySurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C deleted file mode 100644 index 508b41c1b6..0000000000 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriterRunTime.C +++ /dev/null @@ -1,45 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "proxySurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -// create type names, but do not register with run-time tables -makeTypeSurfaceWritersTypeName(proxySurfaceWriter, bool); -makeSurfaceWritersTypeName(proxySurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index 46b8a188ec..90e42c0c07 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,334 +29,187 @@ License #include "OSspecific.H" #include "IOmanip.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(rawSurfaceWriter); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -void Foam::rawSurfaceWriter::writeGeometry +inline void Foam::rawSurfaceWriter::writeLocation ( + Ostream& os, const pointField& points, - const label pointI, - Ostream& os + const label pointI ) { const point& pt = points[pointI]; - - os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' '; + os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << ' '; } -template -void Foam::rawSurfaceWriter::writeGeometry +inline void Foam::rawSurfaceWriter::writeLocation ( + Ostream& os, const pointField& points, const faceList& faces, - const label faceI, - Ostream& os + const label faceI ) { const point& ct = faces[faceI].centre(points); - - os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' '; -} - - -// Write scalarField in raw format -template -void Foam::rawSurfaceWriter::writeData -( - const word& fieldName, - const pointField& points, - const faceList& faces, - const scalarField& values, - const bool isNodeValues, - Ostream& os -) -{ - // header - os << "# x y z " << fieldName << endl; - - // Write data - if (isNodeValues) - { - forAll(values, elemI) - { - writeGeometry(points, elemI, os); - os << values[elemI] << nl; - } - } - else - { - forAll(values, elemI) - { - writeGeometry(points, faces, elemI, os); - os << values[elemI] << nl; - } - } - - os << nl; -} - - -// Write vectorField in raw format -template -void Foam::rawSurfaceWriter::writeData -( - const word& fieldName, - const pointField& points, - const faceList& faces, - const vectorField& values, - const bool isNodeValues, - Ostream& os -) -{ - // header - os << "# x y z " - << fieldName << "_x " - << fieldName << "_y " - << fieldName << "_z " - << endl; - - // Write data - if (isNodeValues) - { - forAll(values, elemI) - { - writeGeometry(points, elemI, os); - - const vector& v = values[elemI]; - os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; - } - } - else - { - forAll(values, elemI) - { - writeGeometry(points, faces, elemI, os); - - const vector& v = values[elemI]; - os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; - } - } - -} - - -// Write sphericalTensorField in raw format -template -void Foam::rawSurfaceWriter::writeData -( - const word& fieldName, - const pointField& points, - const faceList& faces, - const sphericalTensorField& values, - const bool isNodeValues, - Ostream& os -) -{ - // header - os << "# ii "; - os << fieldName << "_ii" << endl; - - // Write data - if (isNodeValues) - { - forAll(values, elemI) - { - writeGeometry(points, elemI, os); - - const sphericalTensor& v = values[elemI]; - os << v[0] << nl; - } - } - else - { - forAll(values, elemI) - { - writeGeometry(points, faces, elemI, os); - - const sphericalTensor& v = values[elemI]; - os << v[0] << nl; - } - } -} - - -// Write symmTensorField in raw format -template -void Foam::rawSurfaceWriter::writeData -( - const word& fieldName, - const pointField& points, - const faceList& faces, - const symmTensorField& values, - const bool isNodeValues, - Ostream& os -) -{ - // header - os << "# xx xy xz yy yz "; - for (int i=0; i<6; i++) - { - os << fieldName << "_" << i << " "; - } - os << endl; - - // Write data - if (isNodeValues) - { - forAll(values, elemI) - { - writeGeometry(points, elemI, os); - - const symmTensor& v = values[elemI]; - - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << nl; - } - } - else - { - forAll(values, elemI) - { - writeGeometry(points, faces, elemI, os); - - const symmTensor& v = values[elemI]; - - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << nl; - } - } -} - - -// Write tensorField in raw format -template -void Foam::rawSurfaceWriter::writeData -( - const word& fieldName, - const pointField& points, - const faceList& faces, - const tensorField& values, - const bool isNodeValues, - Ostream& os -) -{ - // header - os << "# xx xy xz yx yy yz zx zy zz"; - for (int i=0; i<9; ++i) - { - os << fieldName << "_" << i << " "; - } - os << endl; - - // Write data - if (isNodeValues) - { - forAll(values, elemI) - { - writeGeometry(points, elemI, os); - - const tensor& v = values[elemI]; - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << ' ' - << v[6] << ' ' << v[7] << ' ' << v[8] << nl; - } - } - else - { - forAll(values, elemI) - { - writeGeometry(points, faces, elemI, os); - - const tensor& v = values[elemI]; - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << ' ' - << v[6] << ' ' << v[7] << ' ' << v[8] << nl; - } - } -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::rawSurfaceWriter::rawSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::rawSurfaceWriter::~rawSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::rawSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - OFstream os - ( - outputDir/surfaceName + ".raw" - ); - - if (verbose) - { - Info<< "Writing geometry to " << os.name() << endl; - } - - - // header - os << "# geometry NO_DATA " << faces.size() << nl - << "# x y z" << endl; - - // Write faces - forAll(faces, elemI) - { - writeGeometry(points, faces, elemI, os); - os << nl; - } - - os << nl; + os << ct.x() << ' ' << ct.y() << ' ' << ct.z() << ' '; } namespace Foam { - // bool fields aren't supported template<> - void Foam::rawSurfaceWriter::write + void Foam::rawSurfaceWriter::writeHeader ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, + Ostream& os, const word& fieldName, - const Field& values, - const bool isNodeValues, - const bool verbose - ) const - {} + const Field& values + ) + { + os << values.size() << nl + << "# x y z " << fieldName << nl; + } + + + template<> + void Foam::rawSurfaceWriter::writeHeader + ( + Ostream& os, + const word& fieldName, + const Field& values + ) + { + os << values.size() << nl + << "# x y z " + << fieldName << "_x " + << fieldName << "_y " + << fieldName << "_z " + << endl; + } + + + template<> + void Foam::rawSurfaceWriter::writeHeader + ( + Ostream& os, + const word& fieldName, + const Field& values + ) + { + os << values.size() << nl + << "# ii " + << fieldName << "_ii" << nl; + } + + + template<> + void Foam::rawSurfaceWriter::writeHeader + ( + Ostream& os, + const word& fieldName, + const Field& values + ) + { + os << values.size() << nl + << "# xx xy xz yy yz "; + for (int i=0; i<6; ++i) + { + os << fieldName << "_" << i << " "; + } + os << endl; + } + + + template<> + void Foam::rawSurfaceWriter::writeHeader + ( + Ostream& os, + const word& fieldName, + const Field& values + ) + { + os << values.size() << nl + << "# xx xy xz yx yy yz zx zy zz"; + for (int i=0; i<9; ++i) + { + os << fieldName << "_" << i << " "; + } + os << nl; + } + + + template<> + inline void Foam::rawSurfaceWriter::writeData + ( + Ostream& os, + const scalar& v + ) + { + os << v << nl; + } + + + template<> + inline void Foam::rawSurfaceWriter::writeData + ( + Ostream& os, + const vector& v + ) + { + os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; + } + + + template<> + inline void Foam::rawSurfaceWriter::writeData + ( + Ostream& os, + const sphericalTensor& v + ) + { + os << v[0] << nl; + } + + + template<> + inline void Foam::rawSurfaceWriter::writeData + ( + Ostream& os, + const symmTensor& v + ) + { + os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' + << v[3] << ' ' << v[4] << ' ' << v[5] << nl; + } + + + template<> + inline void Foam::rawSurfaceWriter::writeData + ( + Ostream& os, + const tensor& v + ) + { + os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' + << v[3] << ' ' << v[4] << ' ' << v[5] << ' ' + << v[6] << ' ' << v[7] << ' ' << v[8] << nl; + } + } template -void Foam::rawSurfaceWriter::write +void Foam::rawSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -373,17 +226,13 @@ void Foam::rawSurfaceWriter::write mkDir(outputDir); } - OFstream os - ( - outputDir/fieldName + '_' + surfaceName + ".raw" - ); + OFstream os(outputDir/fieldName + '_' + surfaceName + ".raw"); if (verbose) { Info<< "Writing field " << fieldName << " to " << os.name() << endl; } - // header os << "# " << fieldName; if (isNodeValues) @@ -395,10 +244,85 @@ void Foam::rawSurfaceWriter::write os << " FACE_DATA "; } - os << values.size() << nl; + // header + writeHeader(os, fieldName, values); - writeData(fieldName, points, faces, values, isNodeValues, os); + // values + if (isNodeValues) + { + forAll(values, elemI) + { + writeLocation(os, points, elemI); + writeData(os, values[elemI]); + } + } + else + { + forAll(values, elemI) + { + writeLocation(os, points, faces, elemI); + writeData(os, values[elemI]); + } + } } + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::rawSurfaceWriter::rawSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::rawSurfaceWriter::~rawSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::rawSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + OFstream os(outputDir/surfaceName + ".raw"); + + if (verbose) + { + Info<< "Writing geometry to " << os.name() << endl; + } + + + // header + os << "# geometry NO_DATA " << faces.size() << nl + << "# x y z" << nl; + + // Write faces centres + forAll(faces, elemI) + { + writeLocation(os, points, faces, elemI); + os << nl; + } + + os << nl; +} + + +// create write methods +defineSurfaceWriterWriteFields(Foam::rawSurfaceWriter); + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H index 771824bd89..5ec4d1ac30 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ Class Foam::rawSurfaceWriter Description + A surfaceWriter for raw output. SourceFiles rawSurfaceWriter.C @@ -36,86 +37,62 @@ SourceFiles #include "surfaceWriter.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { /*---------------------------------------------------------------------------*\ - Class raw Declaration + Class rawSurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class rawSurfaceWriter : - public surfaceWriter + public surfaceWriter { // Private Member Functions - static void writeGeometry + static inline void writeLocation ( - const pointField& points, - const label pointI, - Ostream& os + Ostream&, + const pointField&, + const label pointI ); - static void writeGeometry + static inline void writeLocation ( - const pointField& points, - const faceList& faces, - const label faceI, - Ostream& os + Ostream&, + const pointField&, + const faceList&, + const label faceI ); - static void writeData + template + static void writeHeader ( + Ostream&, const word& fieldName, - const pointField& points, - const faceList& faces, - const scalarField& values, - const bool isNodeValues, - Ostream& os + const Field& ); - static void writeData - ( - const word& fieldName, - const pointField& points, - const faceList& faces, - const vectorField& values, - const bool isNodeValues, - Ostream& os - ); + template + static inline void writeData(Ostream&, const Type&); - static void writeData - ( - const word& fieldName, - const pointField& points, - const faceList& faces, - const sphericalTensorField& values, - const bool isNodeValues, - Ostream& os - ); - static void writeData + //- Templated write operation + template + void writeTemplate ( - const word& fieldName, + const fileName& outputDir, + const fileName& surfaceName, const pointField& points, const faceList& faces, - const symmTensorField& values, - const bool isNodeValues, - Ostream& os - ); - - static void writeData - ( const word& fieldName, - const pointField& points, - const faceList& faces, - const tensorField& values, + const Field& values, const bool isNodeValues, - Ostream& os - ); + const bool verbose + ) const; public: @@ -136,9 +113,7 @@ public: // Member Functions - // Write - - //- Write geometry to file. + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, @@ -148,18 +123,77 @@ public: const bool verbose = false ) const; - //- Writes single surface to file. + + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, - const Field& values, + const word& fieldName, // name of field + const Field& values, const bool isNodeValues, const bool verbose = false ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + }; @@ -169,12 +203,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "rawSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C deleted file mode 100644 index d6a1a89cc9..0000000000 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "rawSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(rawSurfaceWriter, bool); -makeSurfaceWriters(rawSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C new file mode 100644 index 0000000000..5ab7290218 --- /dev/null +++ b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "starcdSurfaceWriter.H" + +#include "MeshedSurfaceProxy.H" +#include "OFstream.H" +#include "OSspecific.H" + +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(starcdSurfaceWriter); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +namespace Foam +{ + template<> + inline void Foam::starcdSurfaceWriter::writeData + ( + Ostream& os, + const scalar& v + ) + { + os << v << nl; + } + + + template<> + inline void Foam::starcdSurfaceWriter::writeData + ( + Ostream& os, + const vector& v + ) + { + os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; + } + + + template<> + inline void Foam::starcdSurfaceWriter::writeData + ( + Ostream& os, + const sphericalTensor& v + ) + { + os << v[0] << nl; + } + +} + + +template +inline void Foam::starcdSurfaceWriter::writeData +( + Ostream& os, + const Type& v +) +{} + + +template +void Foam::starcdSurfaceWriter::writeTemplate +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + OFstream os(outputDir/fieldName + '_' + surfaceName + ".usr"); + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << os.name() << endl; + } + + // no header, just write values + forAll(values, elemI) + { + os << elemI+1 << ' '; + writeData(os, values[elemI]); + } +} + + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::starcdSurfaceWriter::starcdSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::starcdSurfaceWriter::~starcdSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::starcdSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + fileName outName(outputDir/surfaceName + ".inp"); + + if (verbose) + { + Info<< "Writing geometry to " << outName << endl; + } + + MeshedSurfaceProxy(points, faces).write(outName); +} + + +// create write methods +defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, scalar); +defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, vector); +defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, sphericalTensor); + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H new file mode 100644 index 0000000000..bf0a0eb824 --- /dev/null +++ b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::starcdSurfaceWriter + +Description + A surfaceWriter for STARCD files. + + The geometry is written via the MeshedSurfaceProxy, the fields + are written in a trivial ASCII format with ID and VALUE as + so-called user data. These @c .usr files can be read into proSTAR + with these types of commands. For element data: + @verbatim + getuser FILENAME.usr cell scalar free + getuser FILENAME.usr cell vector free + @endverbatim + and for vertex data: + @verbatim + getuser FILENAME.usr vertex scalar free + getuser FILENAME.usr vertex vector free + @endverbatim + +Note + Only scalar and vector fields are supported directly. + A sphericalTensor is written as a scalar. + Other field types are not written. + +SourceFiles + starcdSurfaceWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef starcdSurfaceWriter_H +#define starcdSurfaceWriter_H + +#include "surfaceWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class starcdSurfaceWriter Declaration +\*---------------------------------------------------------------------------*/ + +class starcdSurfaceWriter +: + public surfaceWriter +{ + // Private Member Functions + + template + static inline void writeData(Ostream&, const Type&); + + + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; + + +public: + + //- Runtime type information + TypeName("starcd"); + + + // Constructors + + //- Construct null + starcdSurfaceWriter(); + + + //- Destructor + virtual ~starcdSurfaceWriter(); + + + // Member Functions + + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() + { + return true; + } + + //- Write single surface geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.C b/src/sampling/sampledSurface/writers/surfaceWriter.C index d4ebc9c222..0f52c6f4aa 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.C +++ b/src/sampling/sampledSurface/writers/surfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,47 +26,43 @@ License #include "surfaceWriter.H" #include "MeshedSurfaceProxy.H" -#include "nullSurfaceWriter.H" #include "proxySurfaceWriter.H" #include "HashTable.H" #include "word.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -template -Foam::autoPtr< Foam::surfaceWriter > -Foam::surfaceWriter::New(const word& writeType) +namespace Foam { - typename wordConstructorTable::iterator cstrIter = + defineTypeNameAndDebug(surfaceWriter, 0); + defineRunTimeSelectionTable(surfaceWriter, word); + addNamedToRunTimeSelectionTable + ( + surfaceWriter, + surfaceWriter, + word, + null + ); +} + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::autoPtr +Foam::surfaceWriter::New(const word& writeType) +{ + wordConstructorTable::iterator cstrIter = wordConstructorTablePtr_->find(writeType); if (cstrIter == wordConstructorTablePtr_->end()) { - // not supported for this data type, but it generally does work - // (it handles the 'bool' specialization - ie, geometry write) - if - ( - Foam::surfaceWriter::wordConstructorTablePtr_->found - ( - writeType - ) - ) - { - // use 'null' handler instead - return autoPtr< surfaceWriter > - ( - new nullSurfaceWriter() - ); - } - else if (MeshedSurfaceProxy::canWriteType(writeType)) + if (MeshedSurfaceProxy::canWriteType(writeType)) { // generally unknown, but can be written via MeshedSurfaceProxy // use 'proxy' handler instead - return autoPtr< surfaceWriter > - ( - new proxySurfaceWriter(writeType) - ); + return autoPtr(new proxySurfaceWriter(writeType)); } if (cstrIter == wordConstructorTablePtr_->end()) @@ -83,24 +79,20 @@ Foam::surfaceWriter::New(const word& writeType) } } - return autoPtr< surfaceWriter >(cstrIter()()); + return autoPtr(cstrIter()()); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -Foam::surfaceWriter::surfaceWriter() +Foam::surfaceWriter::surfaceWriter() {} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -template -Foam::surfaceWriter::~surfaceWriter() +Foam::surfaceWriter::~surfaceWriter() {} -// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index d17db7a3f3..1057a187bd 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,7 +34,7 @@ SourceFiles #ifndef surfaceWriter_H #define surfaceWriter_H -#include "Field.H" +#include "volFields.H" #include "typeInfo.H" #include "autoPtr.H" #include "pointField.H" @@ -48,22 +48,12 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators - -template class surfaceWriter; -template class nullSurfaceWriter; -template class proxySurfaceWriter; - /*---------------------------------------------------------------------------*\ Class surfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class surfaceWriter { - //- friendship between writer data types - template friend class surfaceWriter; - public: //- Runtime type information @@ -99,14 +89,15 @@ public: // Member Functions - //- Return true if the surface format supports separate files - virtual bool separateFiles() + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() { return false; } - //- Writes single surface geometry to file. + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, // //surface/TIME @@ -118,8 +109,8 @@ public: {} - //- Writes single surface to file. Either one value per vertex or - // one value per face (isNodeValues = false) + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( const fileName& outputDir, // //surface/TIME @@ -127,10 +118,73 @@ public: const pointField& points, const faceList& faces, const word& fieldName, // name of field - const Field& values, + const Field& values, const bool isNodeValues, const bool verbose = false - ) const = 0; + ) const + {} + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const + {} + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const + {} + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const + {} + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const + {} + + }; @@ -140,12 +194,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "surfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriters.C b/src/sampling/sampledSurface/writers/surfaceWriters.C deleted file mode 100644 index 5a677c793e..0000000000 --- a/src/sampling/sampledSurface/writers/surfaceWriters.C +++ /dev/null @@ -1,50 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "surfaceWriters.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -#define defineSurfaceWriterType(dataType) \ - defineNamedTemplateTypeNameAndDebug(surfaceWriter< dataType >, 0); \ - defineTemplatedRunTimeSelectionTable(surfaceWriter, word, dataType) - -defineSurfaceWriterType(bool); - -defineSurfaceWriterType(scalar); -defineSurfaceWriterType(vector); -defineSurfaceWriterType(sphericalTensor); -defineSurfaceWriterType(symmTensor); -defineSurfaceWriterType(tensor); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriters.H b/src/sampling/sampledSurface/writers/surfaceWriters.H deleted file mode 100644 index 0369d2e993..0000000000 --- a/src/sampling/sampledSurface/writers/surfaceWriters.H +++ /dev/null @@ -1,76 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - Foam::surfaceWriters - -Description - -\*---------------------------------------------------------------------------*/ - -#ifndef surfaceWriters_H -#define surfaceWriters_H - -#include "surfaceWriter.H" -#include "fieldTypes.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Only used internally -#define makeTypeSurfaceWritersTypeName(typeWriter, dataType) \ - \ - defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0) - -// Sometimes used externally -#define makeSurfaceWritersTypeName(typeWriter) \ - \ - makeTypeSurfaceWritersTypeName(typeWriter, scalar); \ - makeTypeSurfaceWritersTypeName(typeWriter, vector); \ - makeTypeSurfaceWritersTypeName(typeWriter, sphericalTensor); \ - makeTypeSurfaceWritersTypeName(typeWriter, symmTensor); \ - makeTypeSurfaceWritersTypeName(typeWriter, tensor) - -// Define type info for single dataType template instantiation (eg, vector) -#define makeSurfaceWriterType(typeWriter, dataType) \ - \ - defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0); \ - addTemplatedToRunTimeSelectionTable \ - ( \ - surfaceWriter, typeWriter, dataType, word \ - ) - - -// Define type info for scalar, vector etc. instantiations -#define makeSurfaceWriters(typeWriter) \ - \ - makeSurfaceWriterType(typeWriter, scalar); \ - makeSurfaceWriterType(typeWriter, vector); \ - makeSurfaceWriterType(typeWriter, sphericalTensor); \ - makeSurfaceWriterType(typeWriter, symmTensor); \ - makeSurfaceWriterType(typeWriter, tensor) - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index 085dbd67d0..2f333a9515 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,10 +28,19 @@ License #include "OFstream.H" #include "OSspecific.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(vtkSurfaceWriter); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -void Foam::vtkSurfaceWriter::writeGeometry +void Foam::vtkSurfaceWriter::writeGeometry ( Ostream& os, const pointField& points, @@ -71,12 +80,12 @@ void Foam::vtkSurfaceWriter::writeGeometry { const face& f = faces[faceI]; - os << f.size(); + os << f.size(); forAll(f, fp) { - os << ' ' << f[fp]; + os << ' ' << f[fp]; } - os << nl; + os << nl; } } @@ -84,15 +93,14 @@ void Foam::vtkSurfaceWriter::writeGeometry namespace Foam { - // Write scalarField in vtk format template<> - void Foam::vtkSurfaceWriter::writeData + void Foam::vtkSurfaceWriter::writeData ( Ostream& os, - const Field& values + const Field& values ) { - os << "1 " << values.size() << " float" << nl; + os << "1 " << values.size() << " float" << nl; forAll(values, elemI) { @@ -100,29 +108,28 @@ namespace Foam { if (elemI % 10) { - os << ' '; + os << ' '; } else { - os << nl; + os << nl; } } - const scalar v = values[elemI]; - os << float(v); + os << float(values[elemI]); } - os << nl; + os << nl; } - // Write vectorField in vtk format + template<> - void Foam::vtkSurfaceWriter::writeData + void Foam::vtkSurfaceWriter::writeData ( Ostream& os, - const Field& values + const Field& values ) { - os << "3 " << values.size() << " float" << nl; + os << "3 " << values.size() << " float" << nl; forAll(values, elemI) { @@ -133,33 +140,31 @@ namespace Foam } - // Write sphericalTensorField in vtk format template<> - void Foam::vtkSurfaceWriter::writeData + void Foam::vtkSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - os << "1 " << values.size() << " float" << nl; + os << "1 " << values.size() << " float" << nl; forAll(values, elemI) { const sphericalTensor& v = values[elemI]; - os << float(v[0]) << nl; + os << float(v[0]) << nl; } } - // Write symmTensorField in vtk format template<> - void Foam::vtkSurfaceWriter::writeData + void Foam::vtkSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - os << "6 " << values.size() << " float" << nl; + os << "6 " << values.size() << " float" << nl; forAll(values, elemI) { @@ -172,15 +177,14 @@ namespace Foam } - // Write tensorField in vtk format template<> - void Foam::vtkSurfaceWriter::writeData + void Foam::vtkSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - os << "9 " << values.size() << " float" << nl; + os << "9 " << values.size() << " float" << nl; forAll(values, elemI) { @@ -197,69 +201,23 @@ namespace Foam // Write generic field in vtk format template -void Foam::vtkSurfaceWriter::writeData +void Foam::vtkSurfaceWriter::writeData ( Ostream& os, const Field& values ) { - os << "1 " << values.size() << " float" << nl; + os << "1 " << values.size() << " float" << nl; forAll(values, elemI) { - os << float(0) << nl; + os << float(0) << nl; } } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -// Construct from components template -Foam::vtkSurfaceWriter::vtkSurfaceWriter() -: - surfaceWriter() -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::vtkSurfaceWriter::~vtkSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::vtkSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const bool verbose -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - fileName fName(outputDir/surfaceName + ".vtk"); - - if (verbose) - { - Info<< "Writing geometry to " << fName << endl; - } - - OFstream os(fName); - writeGeometry(os, points, faces); -} - - -template -void Foam::vtkSurfaceWriter::write +void Foam::vtkSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -276,10 +234,7 @@ void Foam::vtkSurfaceWriter::write mkDir(outputDir); } - OFstream os - ( - outputDir/fieldName + '_' + surfaceName + ".vtk" - ); + OFstream os(outputDir/fieldName + '_' + surfaceName + ".vtk"); if (verbose) { @@ -304,8 +259,52 @@ void Foam::vtkSurfaceWriter::write // Write data writeData(os, values); - } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::vtkSurfaceWriter::vtkSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::vtkSurfaceWriter::~vtkSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::vtkSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + OFstream os(outputDir/surfaceName + ".vtk"); + + if (verbose) + { + Info<< "Writing geometry to " << os.name() << endl; + } + + writeGeometry(os, points, faces); +} + + +// create write methods +defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter); + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index bc13be23c2..322159094b 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ Class Foam::vtkSurfaceWriter Description + A surfaceWriter for VTK legacy format. SourceFiles vtkSurfaceWriter.C @@ -42,21 +43,35 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class vtkSurfaceWriter Declaration + Class vtkSurfaceWriter Declaration \*---------------------------------------------------------------------------*/ -template class vtkSurfaceWriter : - public surfaceWriter + public surfaceWriter { // Private Member Functions static void writeGeometry(Ostream&, const pointField&, const faceList&); - static void writeData(Ostream&, const Field& values); + template + static void writeData(Ostream&, const Field&); + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; + public: //- Runtime type information @@ -75,9 +90,7 @@ public: // Member Functions - // Write - - //- Write geometry to file. + //- Write single surface geometry to file. virtual void write ( const fileName& outputDir, @@ -88,18 +101,76 @@ public: ) const; - //- Writes single surface to file. + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, - const Field& values, + const word& fieldName, // name of field + const Field& values, const bool isNodeValues, const bool verbose = false ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, // //surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const word& fieldName, // name of field + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + }; @@ -109,12 +180,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "vtkSurfaceWriter.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C deleted file mode 100644 index 1901acfef6..0000000000 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterRunTime.C +++ /dev/null @@ -1,44 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "vtkSurfaceWriter.H" -#include "surfaceWriters.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -makeSurfaceWriterType(vtkSurfaceWriter, bool); -makeSurfaceWriters(vtkSurfaceWriter); - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* //