From 11c3654a268e250363eb4ef452624d7c17aa7910 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Wed, 11 Nov 2015 12:50:16 +0000 Subject: [PATCH] ENH: Updates to set and surface writers - New boundaryData surface writer - Moved templated code into separate files - Output filenames written to functionObjectState dictionary - Ensight surface writer now supports a 'collate times' option [mattijs] - Nastran surface writer updated based on user feedback --- src/sampling/Make/files | 1 + .../sampledSet/sampledSets/sampledSets.C | 4 +- .../sampledSet/sampledSets/sampledSets.H | 14 +- .../sampledSets/sampledSetsTemplates.C | 15 +- .../sampledSurfaces/sampledSurfaces.C | 46 ++- .../sampledSurfaces/sampledSurfaces.H | 18 +- .../sampledSurfaces/sampledSurfacesGrouping.C | 4 +- .../sampledSurfacesTemplates.C | 28 +- .../boundaryData/boundaryDataSurfaceWriter.C | 117 ++++++ .../boundaryData/boundaryDataSurfaceWriter.H | 222 ++++++++++++ .../boundaryDataSurfaceWriterTemplates.C | 146 ++++++++ .../writers/dx/dxSurfaceWriter.C | 58 +-- .../writers/dx/dxSurfaceWriter.H | 21 +- .../writers/dx/dxSurfaceWriterTemplates.C | 81 +++++ .../writers/ensight/ensightSurfaceWriter.C | 89 +---- .../writers/ensight/ensightSurfaceWriter.H | 57 ++- .../ensight/ensightSurfaceWriterTemplates.C | 339 ++++++++++++++++++ .../writers/foamFile/foamFileSurfaceWriter.C | 53 +-- .../writers/foamFile/foamFileSurfaceWriter.H | 25 +- .../foamFile/foamFileSurfaceWriterTemplates.C | 74 ++++ .../writers/makeSurfaceWriterMethods.H | 6 +- .../writers/nastran/nastranSurfaceWriter.C | 221 ++++++++---- .../writers/nastran/nastranSurfaceWriter.H | 62 +++- .../nastran/nastranSurfaceWriterTemplates.C | 172 ++++++--- .../writers/proxy/proxySurfaceWriter.C | 8 +- .../writers/proxy/proxySurfaceWriter.H | 7 +- .../writers/raw/rawSurfaceWriter.C | 71 +--- .../writers/raw/rawSurfaceWriter.H | 23 +- .../writers/raw/rawSurfaceWriterTemplates.C | 93 +++++ .../writers/starcd/starcdSurfaceWriter.C | 54 +-- .../writers/starcd/starcdSurfaceWriter.H | 21 +- .../starcd/starcdSurfaceWriterTemplates.C | 76 ++++ .../sampledSurface/writers/surfaceWriter.H | 40 ++- .../writers/vtk/vtkSurfaceWriter.C | 73 +--- .../writers/vtk/vtkSurfaceWriter.H | 23 +- .../writers/vtk/vtkSurfaceWriterTemplates.C | 95 +++++ 36 files changed, 1813 insertions(+), 644 deletions(-) create mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.C create mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.H create mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/raw/rawSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriterTemplates.C create mode 100644 src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterTemplates.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 8bbc898dda..d5e75fd2ce 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -50,6 +50,7 @@ $(surfWriters)/proxy/proxySurfaceWriter.C $(surfWriters)/raw/rawSurfaceWriter.C $(surfWriters)/starcd/starcdSurfaceWriter.C $(surfWriters)/vtk/vtkSurfaceWriter.C +$(surfWriters)/boundaryData/boundaryDataSurfaceWriter.C graphField/writePatchGraph.C graphField/writeCellGraph.C diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C index 0286e54877..38fb6a40c8 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.C +++ b/src/sampling/sampledSet/sampledSets/sampledSets.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -136,8 +136,8 @@ Foam::sampledSets::sampledSets const bool loadFromFiles ) : + functionObjectState(obr, name), PtrList(), - name_(name), mesh_(refCast(obr)), loadFromFiles_(loadFromFiles), outputPath_(fileName::null), diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.H b/src/sampling/sampledSet/sampledSets/sampledSets.H index 430039a2ce..a9cac56d0b 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.H +++ b/src/sampling/sampledSet/sampledSets/sampledSets.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +36,7 @@ SourceFiles #ifndef sampledSets_H #define sampledSets_H +#include "functionObjectState.H" #include "sampledSet.H" #include "volFieldsFwd.H" #include "meshSearch.H" @@ -59,6 +60,7 @@ class fvMesh; class sampledSets : + public functionObjectState, public PtrList { // Private classes @@ -153,10 +155,6 @@ class sampledSets // Private data - //- Name of this set of sets, - // Also used as the name of the sampledSets directory. - word name_; - //- Const reference to fvMesh const fvMesh& mesh_; @@ -273,12 +271,6 @@ public: // Member Functions - //- Return name of the set of probes - virtual const word& name() const - { - return name_; - } - //- Set verbosity level void verbose(const bool verbosity = true); diff --git a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C index a646a8c7c3..78ded3125d 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C +++ b/src/sampling/sampledSet/sampledSets/sampledSetsTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -155,6 +155,14 @@ void Foam::sampledSets::writeSampleFile valueSets, ofs ); + + forAll(masterFields, fieldi) + { + dictionary propsDict; + propsDict.add("file", fName); + const word& fieldName = masterFields[fieldi].name(); + setProperty(fieldName, propsDict); + } } else { @@ -226,10 +234,7 @@ void Foam::sampledSets::combineSampledValues template -void Foam::sampledSets::sampleAndWrite -( - fieldGroup& fields -) +void Foam::sampledSets::sampleAndWrite(fieldGroup& fields) { if (fields.size()) { diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 220a61baee..47a9f9ebbc 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,7 +49,7 @@ void Foam::sampledSurfaces::writeGeometry() const // Write to time directory under outputPath_ // Skip surface without faces (eg, a failed cut-plane) - const fileName outputDir = outputPath_/mesh_.time().timeName(); + const fileName outputDir = outputPath_/obr_.time().timeName(); forAll(*this, surfI) { @@ -92,9 +92,9 @@ Foam::sampledSurfaces::sampledSurfaces const bool loadFromFiles ) : + functionObjectState(obr, name), PtrList(), - name_(name), - mesh_(refCast(obr)), + obr_(obr), loadFromFiles_(loadFromFiles), outputPath_(fileName::null), fieldSelection_(), @@ -102,13 +102,19 @@ Foam::sampledSurfaces::sampledSurfaces mergeList_(), formatter_(NULL) { + // Only active if a fvMesh is available + if (setActive()) + { + read(dict); + } + if (Pstream::parRun()) { - outputPath_ = mesh_.time().path()/".."/"postProcessing"/name_; + outputPath_ = obr_.time().path()/".."/"postProcessing"/name_; } else { - outputPath_ = mesh_.time().path()/"postProcessing"/name_; + outputPath_ = obr_.time().path()/"postProcessing"/name_; } read(dict); @@ -161,11 +167,11 @@ void Foam::sampledSurfaces::write() if (debug) { Pout<< "Creating directory " - << outputPath_/mesh_.time().timeName() << nl << endl; + << outputPath_/obr_.time().timeName() << nl << endl; } - mkDir(outputPath_/mesh_.time().timeName()); + mkDir(outputPath_/obr_.time().timeName()); } // Write geometry first if required, @@ -175,7 +181,7 @@ void Foam::sampledSurfaces::write() writeGeometry(); } - const IOobjectList objects(mesh_, mesh_.time().timeName()); + const IOobjectList objects(obr_, obr_.time().timeName()); sampleAndWrite(objects); sampleAndWrite(objects); @@ -211,10 +217,12 @@ void Foam::sampledSurfaces::read(const dictionary& dict) dict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType) ); + const fvMesh& mesh = refCast(obr_); + PtrList newList ( dict.lookup("surfaces"), - sampledSurface::iNew(mesh_) + sampledSurface::iNew(mesh) ); transfer(newList); @@ -334,8 +342,10 @@ bool Foam::sampledSurfaces::update() return updated; } + const fvMesh& mesh = refCast(obr_); + // Dimension as fraction of mesh bounding box - scalar mergeDim = mergeTol_ * mesh_.bounds().mag(); + scalar mergeDim = mergeTol_*mesh.bounds().mag(); if (Pstream::master() && debug) { @@ -374,4 +384,18 @@ bool Foam::sampledSurfaces::update() } +Foam::scalar Foam::sampledSurfaces::mergeTol() +{ + return mergeTol_; +} + + +Foam::scalar Foam::sampledSurfaces::mergeTol(const scalar tol) +{ + scalar oldTol = mergeTol_; + mergeTol_ = tol; + return oldTol; +} + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 5957d1398d..3958c7f538 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,6 +37,7 @@ SourceFiles #ifndef sampledSurfaces_H #define sampledSurfaces_H +#include "functionObjectState.H" #include "sampledSurface.H" #include "surfaceWriter.H" #include "volFieldsFwd.H" @@ -58,6 +59,7 @@ class dictionary; class sampledSurfaces : + public functionObjectState, public PtrList { // Private classes @@ -92,12 +94,8 @@ class sampledSurfaces // Private data - //- Name of this set of surfaces, - // Also used as the name of the sampledSurfaces directory. - const word name_; - - //- Const reference to fvMesh - const fvMesh& mesh_; + //- Const reference to database + const objectRegistry& obr_; //- Load fields from files (not from objectRegistry) const bool loadFromFiles_; @@ -238,6 +236,12 @@ public: //- Update for changes of mesh due to readUpdate - expires the surfaces virtual void readUpdate(const polyMesh::readUpdateState state); + + //- Get merge tolerance + static scalar mergeTol(); + + //- Set tolerance (and return old tolerance) + static scalar mergeTol(const scalar); }; diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C index 27b4d63d60..ff2aaf3c99 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C @@ -37,7 +37,7 @@ Foam::label Foam::sampledSurfaces::classifyFields() if (loadFromFiles_) { // Check files for a particular time - IOobjectList objects(mesh_, mesh_.time().timeName()); + IOobjectList objects(obr_, obr_.time().timeName()); wordList allFields = objects.sortedNames(); forAll(fieldSelection_, i) @@ -59,7 +59,7 @@ Foam::label Foam::sampledSurfaces::classifyFields() else { // Check currently available fields - wordList allFields = mesh_.sortedNames(); + wordList allFields = obr_.sortedNames(); labelList indices = findStrings(fieldSelection_, allFields); forAll(fieldSelection_, i) diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 8683e320dc..88718cf62d 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,7 +72,7 @@ void Foam::sampledSurfaces::writeSurface // skip surface without faces (eg, a failed cut-plane) if (mergeList_[surfI].faces.size()) { - formatter_->write + fileName fName = formatter_->write ( outputDir, s.name(), @@ -82,6 +82,10 @@ void Foam::sampledSurfaces::writeSurface allValues, s.interpolate() ); + + dictionary propsDict; + propsDict.add("file", fName); + setProperty(fieldName, propsDict); } } } @@ -91,7 +95,7 @@ void Foam::sampledSurfaces::writeSurface // skip surface without faces (eg, a failed cut-plane) if (s.faces().size()) { - formatter_->write + fileName fName = formatter_->write ( outputDir, s.name(), @@ -101,6 +105,10 @@ void Foam::sampledSurfaces::writeSurface values, s.interpolate() ); + + dictionary propsDict; + propsDict.add("file", fName); + setProperty(fieldName, propsDict); } } } @@ -153,7 +161,7 @@ void Foam::sampledSurfaces::sampleAndWrite const GeometricField& sField ) { - const word& fieldName = sField.name(); + const word& fieldName = sField.name(); const fileName outputDir = outputPath_/sField.time().timeName(); forAll(*this, surfI) @@ -169,6 +177,8 @@ template void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects) { wordList names; + const fvMesh& mesh = refCast(obr_); + if (loadFromFiles_) { IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); @@ -176,7 +186,7 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects) } else { - names = mesh_.thisDb().names(); + names = mesh.thisDb().names(); } labelList nameIDs(findStrings(fieldSelection_, names)); @@ -199,11 +209,11 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects) IOobject ( fieldName, - mesh_.time().timeName(), - mesh_, + mesh.time().timeName(), + mesh, IOobject::MUST_READ ), - mesh_ + mesh ); sampleAndWrite(fld); @@ -212,7 +222,7 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects) { sampleAndWrite ( - mesh_.thisDb().lookupObject(fieldName) + mesh.thisDb().lookupObject(fieldName) ); } } diff --git a/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.C b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.C new file mode 100644 index 0000000000..076a9a4226 --- /dev/null +++ b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.C @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ 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 "boundaryDataSurfaceWriter.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(boundaryDataSurfaceWriter); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::boundaryDataSurfaceWriter::boundaryDataSurfaceWriter() +: + surfaceWriter() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::boundaryDataSurfaceWriter::~boundaryDataSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::fileName Foam::boundaryDataSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + const fileName baseDir(outputDir.path()/surfaceName); + const fileName timeName(outputDir.name()); + + + // Construct dummy time to use as an objectRegistry + const fileName caseDir(getEnv("FOAM_CASE")); + Time dummyTime + ( + caseDir.path(), //rootPath, + caseDir.name(), //caseName, + "system", //systemName, + "constant", //constantName, + false //enableFunctionObjects + ); + + + // Write points + if (verbose) + { + Info<< "Writing points to " << baseDir/"points" << endl; + } + + pointIOField pts + ( + IOobject + ( + baseDir/"points", + dummyTime, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + points + ); + + { + // Do like regIOobject::writeObject but don't do instance() adaptation + // since this would write to e.g. 0/ instead of postProcessing/ + + // Try opening an OFstream for object + mkDir(pts.path()); + OFstream os(pts.objectPath()); + + pts.writeHeader(os); + pts.writeData(os); + pts.writeEndDivider(os); + } + + return baseDir; +} + + +// create write methods +defineSurfaceWriterWriteFields(Foam::boundaryDataSurfaceWriter); + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.H b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.H new file mode 100644 index 0000000000..c58e073f36 --- /dev/null +++ b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.H @@ -0,0 +1,222 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ 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::boundaryDataSurfaceWriter + +Description + A surfaceWriter for outputting to a form useable for the + timeVaryingMapped boundary condition. This reads the data from + constant/boundaryData/ + + Typical way of working: + - use a sampledSurface of type 'patch' (to sample a patch): + surfaces + { + type surfaces; + surfaceFormat boundaryData; + fields ( p ); + surfaces + ( + outlet + { + type patch; + patches (outlet); + interpolate false; + } + ); + + - write using this writer. + - move postProcessing/surfaces/outlet to constant/boundaryData/outlet + in your destination case. + - use a timeVaryingMappedFixedValue bc to read&interpolate + the profile: + type timeVaryingMappedFixedValue; + setAverage false; // do not use read average + offset 0; // do not apply offset to values + + Note: + - with 'interpolate false' the data is on the face centres of the + patch. Take care that a 2D geometry will only have a single row + of face centres so might not provide a valid triangulation + (this is what timeVaryingMappedFixedValue uses to do interpolation) + (Alternatively use timeVaryingMappedFixedValue with mapMethod 'nearest') + + +SourceFiles + boundaryDataSurfaceWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef boundaryDataSurfaceWriter_H +#define boundaryDataSurfaceWriter_H + +#include "surfaceWriter.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class boundaryDataSurfaceWriter Declaration +\*---------------------------------------------------------------------------*/ + +class boundaryDataSurfaceWriter +: + public surfaceWriter +{ + // Private Member Functions + + //- Templated write operation + template + fileName 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("boundaryData"); + + + // Constructors + + //- Construct null + boundaryDataSurfaceWriter(); + + + //- Destructor + virtual ~boundaryDataSurfaceWriter(); + + + // Member Functions + + //- Write single surface geometry to file. + virtual fileName 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 fileName 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 fileName 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 fileName 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 fileName 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 fileName 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 + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "boundaryDataSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriterTemplates.C new file mode 100644 index 0000000000..dd2edd5d93 --- /dev/null +++ b/src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriterTemplates.C @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify i + 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 "OFstream.H" +#include "OSspecific.H" +#include "IOmanip.H" +#include "Time.H" +#include "pointIOField.H" +#include "AverageIOField.H" +#include "primitivePatch.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::fileName Foam::boundaryDataSurfaceWriter::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 +{ + const fileName baseDir(outputDir.path()/surfaceName); + const fileName timeName(outputDir.name()); + + + // Construct dummy time to use as an objectRegistry + const fileName caseDir(getEnv("FOAM_CASE")); + Time dummyTime + ( + caseDir.path(), //rootPath, + caseDir.name(), //caseName, + "system", //systemName, + "constant", //constantName, + false //enableFunctionObjects + ); + + + // Write points + + pointIOField pts + ( + IOobject + ( + baseDir/"points", + dummyTime, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + 0 + ); + + if (isNodeValues) + { + if (verbose) + { + Info<< "Writing points to " << baseDir/"points" << endl; + } + pts = points; + } + else + { + if (verbose) + { + Info<< "Writing face centres to " << baseDir/"points" << endl; + } + + primitivePatch pp(SubList(faces, faces.size()), points); + + pts = pp.faceCentres(); + } + + { + // Do like regIOobject::writeObject but don't do instance() adaptation + // since this would write to e.g. 0/ instead of postProcessing/ + + // Try opening an OFstream for object + mkDir(pts.path()); + OFstream os(pts.objectPath()); + + pts.writeHeader(os); + pts.writeData(os); + pts.writeEndDivider(os); + } + + + // Write field + { + AverageIOField vals + ( + IOobject + ( + baseDir/timeName/fieldName, + dummyTime, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + pTraits::zero, + values + ); + + // Do like regIOobject::writeObject but don't do instance() adaptation + // since this would write to e.g. 0/ instead of postProcessing/ + + // Try opening an OFstream for object + mkDir(vals.path()); + OFstream os(vals.objectPath()); + + vals.writeHeader(os); + vals.writeData(os); + vals.writeEndDivider(os); + } + + return baseDir; +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C index c95a7aed65..05029018d4 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,10 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "dxSurfaceWriter.H" - -#include "OFstream.H" -#include "OSspecific.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -215,58 +211,6 @@ namespace Foam } -// arbitrary field -template -inline void Foam::dxSurfaceWriter::writeData -( - Ostream& os, - const Field& values -) -{ - os << "object 3 class array type float rank 0 items " - << values.size() << " data follows" << nl; - - forAll(values, elemI) - { - os << float(0.0) << nl; - } -} - - -template -void Foam::dxSurfaceWriter::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 + ".dx" - ); - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - writeGeometry(os, points, faces); - writeData(os, values); - writeTrailer(os, isNodeValues); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dxSurfaceWriter::dxSurfaceWriter() diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H index 3b4f2fd6d1..047c3d6517 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,7 +61,7 @@ class dxSurfaceWriter //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -94,7 +94,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -108,7 +108,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -122,7 +122,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -136,7 +136,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -150,7 +150,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -161,7 +161,6 @@ public: const bool isNodeValues, const bool verbose = false ) const; - }; @@ -171,6 +170,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "dxSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C new file mode 100644 index 0000000000..cd3c11a04c --- /dev/null +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriterTemplates.C @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "OFstream.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +inline void Foam::dxSurfaceWriter::writeData +( + Ostream& os, + const Field& values +) +{ + os << "object 3 class array type float rank 0 items " + << values.size() << " data follows" << nl; + + forAll(values, elemI) + { + os << float(0.0) << nl; + } +} + + +template +Foam::fileName Foam::dxSurfaceWriter::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 + ".dx"); + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << os.name() << endl; + } + + writeGeometry(os, points, faces); + writeData(os, values); + writeTrailer(os, isNodeValues); + + return os.name(); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C index 5e2ab17114..0df2913efc 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,13 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "ensightSurfaceWriter.H" - -#include "OFstream.H" -#include "OSspecific.H" -#include "IOmanip.H" #include "ensightPartFaces.H" -#include "ensightPTraits.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -42,83 +36,13 @@ namespace Foam } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::ensightSurfaceWriter::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/fieldName)) - { - mkDir(outputDir/fieldName); - } - - // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); - const scalar timeValue = 0.0; - - OFstream osCase(outputDir/fieldName/surfaceName + ".case"); - ensightGeoFile osGeom - ( - outputDir/fieldName/surfaceName + ".000.mesh", - writeFormat_ - ); - ensightFile osField - ( - outputDir/fieldName/surfaceName + ".000." + fieldName, - writeFormat_ - ); - - if (verbose) - { - Info<< "Writing case file to " << osCase.name() << endl; - } - - osCase - << "FORMAT" << nl - << "type: ensight gold" << nl - << nl - << "GEOMETRY" << nl - << "model: 1 " << osGeom.name().name() << nl - << nl - << "VARIABLE" << nl - << ensightPTraits::typeName << " per " - << word(isNodeValues ? "node:" : "element:") << setw(10) << 1 - << " " << fieldName - << " " << surfaceName.c_str() << ".***." << fieldName << 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; - - ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true); - osGeom << ensPart; - - // Write field - osField.writeKeyword(ensightPTraits::typeName); - ensPart.writeField(osField, values, isNodeValues); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::ensightSurfaceWriter::ensightSurfaceWriter() : surfaceWriter(), - writeFormat_(IOstream::ASCII) + writeFormat_(IOstream::ASCII), + collateTimes_(false) {} @@ -132,6 +56,7 @@ Foam::ensightSurfaceWriter::ensightSurfaceWriter(const dictionary& options) { writeFormat_ = IOstream::formatEnum(options.lookup("format")); } + options.readIfPresent("collateTimes", collateTimes_); } @@ -143,7 +68,7 @@ Foam::ensightSurfaceWriter::~ensightSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::ensightSurfaceWriter::write +Foam::fileName Foam::ensightSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -163,7 +88,7 @@ void Foam::ensightSurfaceWriter::write OFstream osCase(outputDir/surfaceName + ".case"); ensightGeoFile osGeom ( - outputDir/surfaceName + ".000.mesh", + outputDir/surfaceName + ".0000.mesh", writeFormat_ ); @@ -190,6 +115,8 @@ void Foam::ensightSurfaceWriter::write ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true); osGeom << ensPart; + + return osCase.name(); } diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H index b1cd9d019f..773a86ee55 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,12 +55,42 @@ class ensightSurfaceWriter //- Write option (default is IOstream::ASCII IOstream::streamFormat writeFormat_; + bool collateTimes_; + // Private Member Functions + //- Templated write operation - one file per timestep + template + fileName writeCollated + ( + 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; + + //- Templated write operation - all time steps in single file + template + fileName writeUncollated + ( + 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; + //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -96,14 +126,14 @@ public: //- 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() + virtual bool separateGeometry() const { - return true; + return !collateTimes_; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -115,7 +145,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -129,7 +159,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -143,7 +173,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -157,7 +187,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -171,7 +201,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -182,7 +212,6 @@ public: const bool isNodeValues, const bool verbose = false ) const; - }; @@ -192,6 +221,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "ensightSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterTemplates.C new file mode 100644 index 0000000000..2a1fea5413 --- /dev/null +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterTemplates.C @@ -0,0 +1,339 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "IOmanip.H" +#include "IFstream.H" +#include "OFstream.H" +#include "OSspecific.H" +#include "ensightPartFaces.H" +#include "ensightPTraits.H" +#include "OStringStream.H" +#include "regExp.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::fileName Foam::ensightSurfaceWriter::writeUncollated +( + 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/fieldName)) + { + mkDir(outputDir/fieldName); + } + + // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + const scalar timeValue = 0.0; + + OFstream osCase(outputDir/fieldName/surfaceName + ".case"); + ensightGeoFile osGeom + ( + outputDir/fieldName/surfaceName + ".0000.mesh", + writeFormat_ + ); + ensightFile osField + ( + outputDir/fieldName/surfaceName + ".0000." + fieldName, + writeFormat_ + ); + + if (verbose) + { + Info<< "Writing case file to " << osCase.name() << endl; + } + + osCase + << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << osGeom.name().name() << nl + << nl + << "VARIABLE" << nl + << ensightPTraits::typeName << " per " + << word(isNodeValues ? "node:" : "element:") << setw(10) << 1 + << " " << fieldName + << " " << surfaceName.c_str() << ".****." << fieldName << 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; + + ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true); + osGeom << ensPart; + + // Write field + osField.writeKeyword(ensightPTraits::typeName); + ensPart.writeField(osField, values, isNodeValues); + + return osCase.name(); +} + + +template +Foam::fileName Foam::ensightSurfaceWriter::writeCollated +( + 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 +{ + + const fileName baseDir = outputDir.path()/surfaceName; + const fileName timeDir = outputDir.name(); + + if (!isDir(baseDir)) + { + mkDir(baseDir); + } + + const fileName meshFile(baseDir/surfaceName + ".0000.mesh"); + const scalar timeValue = readScalar(IStringStream(timeDir)()); + label timeIndex = 0; + + + // Do case file + { + dictionary dict; + scalarList times; + bool stateChanged = false; + + if (isFile(baseDir/"fieldsDict")) + { + IFstream is(baseDir/"fieldsDict"); + if (is.good() && dict.read(is)) + { + dict.lookup("times") >> times; + const scalar timeValue = readScalar(IStringStream(timeDir)()); + label index = findLower(times, timeValue); + timeIndex = index+1; + } + } + + + // Update stored times list + times.setSize(timeIndex+1, -1); + + if (times[timeIndex] != timeValue) + { + stateChanged = true; + } + times[timeIndex] = timeValue; + + + // Add my information to dictionary + { + dict.set("times", times); + if (dict.found("fields")) + { + dictionary& fieldsDict = dict.subDict("fields"); + if (!fieldsDict.found(fieldName)) + { + dictionary fieldDict; + fieldDict.set("type", ensightPTraits::typeName); + fieldsDict.set(fieldName, fieldDict); + + stateChanged = true; + } + } + else + { + dictionary fieldDict; + fieldDict.set("type", ensightPTraits::typeName); + + dictionary fieldsDict; + fieldsDict.set(fieldName, fieldDict); + + dict.set("fields", fieldsDict); + + stateChanged = true; + } + } + + + if (stateChanged) + { + if (verbose) + { + Info<< "Writing state file to fieldsDict" << endl; + } + OFstream os(baseDir/"fieldsDict"); + os << dict; + + + OFstream osCase(baseDir/surfaceName + ".case"); + + if (verbose) + { + Info<< "Writing case file to " << osCase.name() << endl; + } + + osCase + << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << meshFile.name() << nl + << nl + << "VARIABLE" << nl; + const dictionary& fieldsDict = dict.subDict("fields"); + forAllConstIter(dictionary, fieldsDict, iter) + { + const word& fieldName = iter().keyword(); + const word fieldType(iter().dict().lookup("type")); + + osCase + << fieldType << " per " + << word(isNodeValues ? "node:" : "element:") + << setw(10) << 1 + << setw(15) << fieldName + << " " << surfaceName.c_str() << ".****." << fieldName + << nl; + } + osCase << nl; + + osCase + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: " << timeIndex+1 << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl; + forAll(times, timeI) + { + osCase << setw(12) << times[timeI] << " "; + + if (timeI != 0 && (timeI % 6) == 0) + { + osCase << nl; + } + } + osCase << nl; + } + } + + + // Write geometry + ensightPartFaces ensPart(0, meshFile.name(), points, faces, true); + if (!exists(meshFile)) + { + if (verbose) + { + Info<< "Writing mesh file to " << meshFile.name() << endl; + } + ensightGeoFile osGeom(meshFile, writeFormat_); + osGeom << ensPart; + } + + + // Get string representation + string timeString; + { + OStringStream os; + os.stdStream().fill('0'); + os << setw(4) << timeIndex; + timeString = os.str(); + } + + // Write field + ensightFile osField + ( + baseDir/surfaceName + "." + timeString + "." + fieldName, + writeFormat_ + ); + if (verbose) + { + Info<< "Writing field file to " << osField.name() << endl; + } + osField.writeKeyword(ensightPTraits::typeName); + ensPart.writeField(osField, values, isNodeValues); + + return baseDir/surfaceName + ".case"; +} + + +template +Foam::fileName Foam::ensightSurfaceWriter::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 (collateTimes_) + { + return writeCollated + ( + outputDir, + surfaceName, + points, + faces, + fieldName, + values, + isNodeValues, + verbose + ); + } + else + { + return writeUncollated + ( + outputDir, + surfaceName, + points, + faces, + fieldName, + values, + isNodeValues, + verbose + ); + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C index e85450dce5..fbff527c52 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,10 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "foamFileSurfaceWriter.H" - -#include "OFstream.H" -#include "OSspecific.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -38,49 +34,6 @@ namespace Foam } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::foamFileSurfaceWriter::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 -{ - fileName surfaceDir(outputDir/surfaceName); - - if (!isDir(surfaceDir)) - { - mkDir(surfaceDir); - } - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << surfaceDir << endl; - } - - // geometry should already have been written - // Values to separate directory (e.g. "scalarField/p") - - fileName foamName(pTraits::typeName); - fileName valuesDir(surfaceDir / (foamName + Field::typeName)); - - if (!isDir(valuesDir)) - { - mkDir(valuesDir); - } - - // values - OFstream(valuesDir/fieldName)() << values; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::foamFileSurfaceWriter::foamFileSurfaceWriter() @@ -97,7 +50,7 @@ Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::foamFileSurfaceWriter::write +Foam::fileName Foam::foamFileSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -135,6 +88,8 @@ void Foam::foamFileSurfaceWriter::write } OFstream(surfaceDir/"faceCentres")() << faceCentres; + + return surfaceDir; } diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H index 254dadcb44..1149091771 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -54,7 +54,7 @@ class foamFileSurfaceWriter //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -87,13 +87,13 @@ public: //- 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() + virtual bool separateGeometry() const { return true; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -105,7 +105,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -119,7 +119,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -133,7 +133,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -147,7 +147,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -161,7 +161,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -172,7 +172,6 @@ public: const bool isNodeValues, const bool verbose = false ) const; - }; @@ -182,6 +181,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "foamFileSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterTemplates.C new file mode 100644 index 0000000000..f87b2591d9 --- /dev/null +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriterTemplates.C @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "OFstream.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::fileName Foam::foamFileSurfaceWriter::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 +{ + fileName surfaceDir(outputDir/surfaceName); + + if (!isDir(surfaceDir)) + { + mkDir(surfaceDir); + } + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << surfaceDir << endl; + } + + // geometry should already have been written + // Values to separate directory (e.g. "scalarField/p") + + fileName foamName(pTraits::typeName); + fileName valuesDir(surfaceDir/(foamName + Field::typeName)); + + if (!isDir(valuesDir)) + { + mkDir(valuesDir); + } + + // values + OFstream(valuesDir/fieldName)() << values; + + return valuesDir/fieldName; +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H b/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H index 2f640fc2e0..16236bb8bf 100644 --- a/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H +++ b/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,7 +47,7 @@ namespace Foam #define defineSurfaceWriterWriteField(ThisClass, FieldType) \ - void ThisClass::write \ + Foam::fileName ThisClass::write \ ( \ const fileName& outputDir, \ const fileName& surfaceName, \ @@ -59,7 +59,7 @@ namespace Foam const bool verbose \ ) const \ { \ - writeTemplate \ + return writeTemplate \ ( \ outputDir, \ surfaceName, \ diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C index eaa16feb6b..8f5e0c8a79 100644 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,7 +35,7 @@ namespace Foam makeSurfaceWriterType(nastranSurfaceWriter); addToRunTimeSelectionTable(surfaceWriter, nastranSurfaceWriter, wordDict); - // create write methods + // Create write methods defineSurfaceWriterWriteFields(nastranSurfaceWriter); template<> @@ -46,8 +46,19 @@ namespace Foam "free" }; + const NamedEnum nastranSurfaceWriter::writeFormatNames_; + + template<> + const char* NamedEnum::names[] = + { + "PLOAD2", + "PLOAD4" + }; + + const NamedEnum + nastranSurfaceWriter::dataFormatNames_; } @@ -57,7 +68,7 @@ void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const { os.setf(ios_base::scientific); - // capitalise the E marker + // Capitalise the E marker os.setf(ios_base::uppercase); label prec = 0; @@ -65,11 +76,11 @@ void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const switch (writeFormat_) { case (wfShort): - case (wfFree): { prec = 8 - offset; break; } + case (wfFree): case (wfLong): { prec = 16 - offset; @@ -84,6 +95,37 @@ void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const } +void Foam::nastranSurfaceWriter::writeKeyword +( + const word& keyword, + Ostream& os +) const +{ + os.setf(ios_base::left); + + switch (writeFormat_) + { + case wfShort: + { + os << setw(8) << keyword; + break; + } + case wfLong: + { + os << setw(8) << word(keyword + '*'); + break; + } + case wfFree: + { + os << keyword; + break; + } + } + + os.unsetf(ios_base::left); +} + + void Foam::nastranSurfaceWriter::writeCoord ( const point& p, @@ -102,19 +144,27 @@ void Foam::nastranSurfaceWriter::writeCoord // 8 PS : single point constraints (blank) // 9 SEID : super-element ID + + writeKeyword("GRID", os); + + os << separator_; + + os.setf(ios_base::right); + + writeValue(pointI + 1, os); + os << separator_; + writeValue("", os); + os << separator_; + writeValue(p.x(), os); + os << separator_; + writeValue(p.y(), os); + os << separator_; + switch (writeFormat_) { case wfShort: { - os.setf(ios_base::left); - os << setw(8) << "GRID"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << pointI + 1 - << " " - << setw(8) << p.x() - << setw(8) << p.y() - << setw(8) << p.z() + os << setw(8) << p.z() << nl; os.unsetf(ios_base::right); @@ -122,35 +172,19 @@ void Foam::nastranSurfaceWriter::writeCoord } case wfLong: { - os.setf(ios_base::left); - os << setw(8) << "GRID*"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << pointI + 1 - << " " - << setw(16) << p.x() - << setw(16) << p.y() - << nl; + os << nl; os.unsetf(ios_base::right); - os.setf(ios_base::left); - os << setw(8) << "*"; - os.unsetf(ios_base::left); + writeKeyword("", os); os.setf(ios_base::right); - os << setw(16) << p.z() - << nl; - os.unsetf(ios_base::right); + writeValue(p.z(), os); + os << nl; break; } case wfFree: { - os << "GRID" - << ',' << pointI + 1 - << ',' - << ',' << p.x() - << ',' << p.y() - << ',' << p.z() - << nl; + writeValue(p.z(), os); + os << nl; break; } @@ -166,8 +200,11 @@ void Foam::nastranSurfaceWriter::writeCoord ) << "Unknown writeFormat enumeration" << abort(FatalError); } } + + os.unsetf(ios_base::right); } + void Foam::nastranSurfaceWriter::writeFace ( const word& faceType, @@ -190,67 +227,55 @@ void Foam::nastranSurfaceWriter::writeFace // For CTRIA3 elements, cols 7 onwards are not used + label PID = 1; + + writeKeyword(faceType, os); + + os << separator_; + + os.setf(ios_base::right); + + writeValue(nFace++, os); + + os << separator_; + + writeValue(PID, os); + switch (writeFormat_) { case wfShort: { - os.setf(ios_base::left); - os << setw(8) << faceType; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << nFace++ - << " "; - forAll(facePts, i) { - os << setw(8) << facePts[i] + 1; + writeValue(facePts[i] + 1, os); } - os << nl; - os.unsetf(ios_base::right); - break; } case wfLong: { - os.setf(ios_base::left); - os << setw(8) << word(faceType + "*"); - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << nFace++ - << " "; - forAll(facePts, i) { - os << setw(16) << facePts[i] + 1; + writeValue(facePts[i] + 1, os); if (i == 1) { os << nl; os.unsetf(ios_base::right); - os.setf(ios_base::left); - os << setw(8) << "*"; - os.unsetf(ios_base::left); + writeKeyword("", os); os.setf(ios_base::right); } } - os << nl; - os.unsetf(ios_base::right); - break; } case wfFree: { - os << faceType << ',' - << ++nFace << ','; - forAll(facePts, i) { - os << ',' << facePts[i] + 1; + os << separator_; + writeValue(facePts[i] + 1, os); } - os << nl; - break; } default: @@ -268,6 +293,8 @@ void Foam::nastranSurfaceWriter::writeFace } } + os << nl; + os.unsetf(ios_base::right); } @@ -279,7 +306,7 @@ void Foam::nastranSurfaceWriter::writeGeometry OFstream& os ) const { - // write points + // Write points os << "$" << nl << "$ Points" << nl @@ -291,7 +318,7 @@ void Foam::nastranSurfaceWriter::writeGeometry } - // write faces + // Write faces os << "$" << nl << "$ Faces" << nl @@ -315,7 +342,7 @@ void Foam::nastranSurfaceWriter::writeGeometry } else { - // decompose poly face into tris + // Decompose poly face into tris label nTri = 0; faceList triFaces; f.triangles(points, nTri, triFaces); @@ -330,6 +357,42 @@ void Foam::nastranSurfaceWriter::writeGeometry } +void Foam::nastranSurfaceWriter::writeFooter(Ostream& os) const +{ + label PID = 1; + + writeKeyword("PSHELL", os); + + os << separator_; + + writeValue(PID, os); + + for (label i = 0; i < 7; i++) + { + // Dummy values + os << separator_; + writeValue(1, os); + } + + os << nl; + writeKeyword("MAT1", os); + os << separator_; + + label MID = 1; + + writeValue(MID, os); + + for (label i = 0; i < 7; i++) + { + // Dummy values + os << separator_; + writeValue("", os); + } + + os << nl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::nastranSurfaceWriter::nastranSurfaceWriter() @@ -346,18 +409,26 @@ Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& options) surfaceWriter(), writeFormat_(wfLong), fieldMap_(), - scale_(options.lookupOrDefault("scale", 1.0)) + scale_(options.lookupOrDefault("scale", 1.0)), + separator_("") { if (options.found("format")) { writeFormat_ = writeFormatNames_.read(options.lookup("format")); } + if (writeFormat_ == wfFree) + { + separator_ = ","; + } + List > fieldSet(options.lookup("fields")); forAll(fieldSet, i) { - fieldMap_.insert(fieldSet[i].first(), fieldSet[i].second()); + dataFormat format = dataFormatNames_[fieldSet[i].second()]; + + fieldMap_.insert(fieldSet[i].first(), format); } } @@ -370,7 +441,7 @@ Foam::nastranSurfaceWriter::~nastranSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::nastranSurfaceWriter::write +Foam::fileName Foam::nastranSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -384,7 +455,7 @@ void Foam::nastranSurfaceWriter::write mkDir(outputDir); } - OFstream os(outputDir/surfaceName + ".dat"); + OFstream os(outputDir/surfaceName + ".nas"); formatOS(os); if (verbose) @@ -405,7 +476,11 @@ void Foam::nastranSurfaceWriter::write mkDir(outputDir); } + writeFooter(os); + os << "ENDDATA" << endl; + + return os.name(); } diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H index e80383a303..0d8f23fae8 100644 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,7 +32,11 @@ Description nastran { // From OpenFOAM field name to Nastran field name - fields ((pMean PLOAD2)); + fields + ( + (pMean PLOAD2) + (p PLOAD4) + ); // Optional scale scale 2.0; // Optional format @@ -52,6 +56,7 @@ SourceFiles #include "surfaceWriter.H" #include "NamedEnum.H" #include "OFstream.H" +#include "HashTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -77,6 +82,14 @@ public: static const NamedEnum writeFormatNames_; + enum dataFormat + { + dfPLOAD2, + dfPLOAD4 + }; + + static const NamedEnum dataFormatNames_; + private: @@ -85,12 +98,15 @@ private: //- Write option writeFormat writeFormat_; - //- Map of OpenFOAM field name vs nastran field name - HashTable fieldMap_; + //- Mapping from field name to data format enumeration + HashTable fieldMap_; //- Scale to apply to values (default = 1.0) scalar scale_; + //- Separator used for free format + word separator_; + // Private Member Functions @@ -123,19 +139,37 @@ private: OFstream& os ) const; + //- Write the formatted keyword to the output stream + void writeKeyword + ( + const word& keyword, + Ostream& os + ) const; + + //- Write the footer information + void writeFooter(Ostream& os) const; + + //- Write a formatted value to the output stream + template + void writeValue + ( + const Type& value, + Ostream& os + ) const; + //- Write a face-based value template void writeFaceValue ( - const word& nasFieldName, + const dataFormat& format, const Type& value, const label EID, - OFstream& os + Ostream& os ) const; //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -171,13 +205,13 @@ public: //- 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() + virtual bool separateGeometry() const { return false; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -188,7 +222,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -202,7 +236,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -216,7 +250,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -230,7 +264,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -244,7 +278,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C index fe1e6a998a..b4cc3d464d 100644 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,92 +30,141 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::nastranSurfaceWriter::writeFaceValue +void Foam::nastranSurfaceWriter::writeValue ( - const word& nasFieldName, const Type& value, - const label EID, - OFstream& os + Ostream& os ) const { - // Fixed short/long formats: - // 1 Nastran distributed load type, e.g. PLOAD4 - // 2 SID : load set ID - // 3 EID : element ID - // 4 onwards: load values + switch (writeFormat_) + { + case wfShort: + { + os << setw(8) << value; + break; + } + case wfLong: + { + os << setw(16) << value; + break; + } + case wfFree: + { + os << value; + break; + } + } +} + + +template +void Foam::nastranSurfaceWriter::writeFaceValue +( + const dataFormat& format, + const Type& value, + const label EID, + Ostream& os +) const +{ + // Fixed short/long formats supporting PLOAD2 and PLOAD4: + + // PLOAD2: + // 1 descriptor : PLOAD2 + // 2 SID : load set ID + // 3 data value : load value - MUST be singular + // 4 EID : element ID + + // PLOAD4: + // 1 descriptor : PLOAD4 + // 2 SID : load set ID + // 3 EID : element ID + // 4 onwards : load values label SID = 1; Type scaledValue = scale_*value; - switch (writeFormat_) + // Write Keyword + writeKeyword(dataFormatNames_[format], os); + + os << separator_; + + // Write load set ID + os.setf(ios_base::right); + writeValue(SID, os); + + os << separator_; + + switch (format) { - case wfShort: + case dfPLOAD2: { - os.setf(ios_base::left); - os << setw(8) << nasFieldName; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << SID - << setw(8) << EID; - - for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) + if (pTraits::nComponents == 1) { - os << setw(8) << component(scaledValue, dirI); + writeValue(scaledValue, os); + } + else + { + WarningIn + ( + "template" + "void Foam::nastranSurfaceWriter::writeNodeValue" + "(" + "const dataFormat&, " + "const Type&, " + "const label, " + "OFstream&" + ") const" + ) + << dataFormatNames_[format] << " requires scalar values " + << "and cannot be used for higher rank values" + << endl; + + writeValue(scalar(0), os); } - os.unsetf(ios_base::right); + os << separator_; + writeValue(EID, os); break; } - case wfLong: + case dfPLOAD4: { - os.setf(ios_base::left); - os << setw(8) << word(nasFieldName + "*"); - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << SID - << setw(16) << EID; + writeValue(EID, os); for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) { - os << setw(16) << component(scaledValue, dirI); + os << separator_; + writeValue(component(scaledValue, dirI), os); } - - os.unsetf(ios_base::right); - - os << nl; - - os.setf(ios_base::left); - os << '*'; - os.unsetf(ios_base::left); - - break; - } - case wfFree: - { - os << nasFieldName << ',' - << SID << ',' - << EID; - - for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) - { - os << ',' << component(scaledValue, dirI); - } - break; } default: { + WarningIn + ( + "template" + "void Foam::nastranSurfaceWriter::writeNodeValue" + "(" + "const dataFormat&, " + "const Type&, " + "const label, " + "OFstream&" + ") const" + ) + << "Unhandled enumeration " << dataFormatNames_[format] + << endl; } } + os.unsetf(ios_base::right); + os << nl; } template -void Foam::nastranSurfaceWriter::writeTemplate +Foam::fileName Foam::nastranSurfaceWriter::writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -127,6 +176,7 @@ void Foam::nastranSurfaceWriter::writeTemplate const bool verbose ) const { + if (!fieldMap_.found(fieldName)) { WarningIn @@ -148,10 +198,10 @@ void Foam::nastranSurfaceWriter::writeTemplate << fieldMap_ << exit(FatalError); - return; + return fileName::null; } - const word& nasFieldName(fieldMap_[fieldName]); + const dataFormat& format(fieldMap_[fieldName]); if (!isDir(outputDir/fieldName)) { @@ -161,7 +211,7 @@ void Foam::nastranSurfaceWriter::writeTemplate // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); const scalar timeValue = 0.0; - OFstream os(outputDir/fieldName/surfaceName + ".dat"); + OFstream os(outputDir/fieldName/surfaceName + ".nas"); formatOS(os); if (verbose) @@ -203,7 +253,7 @@ void Foam::nastranSurfaceWriter::writeTemplate } v /= f.size(); - writeFaceValue(nasFieldName, v, ++n, os); + writeFaceValue(format, v, ++n, os); } } } @@ -217,12 +267,16 @@ void Foam::nastranSurfaceWriter::writeTemplate forAll(dFaces, faceI) { - writeFaceValue(nasFieldName, values[faceI], ++n, os); + writeFaceValue(format, values[faceI], ++n, os); } } } + writeFooter(os); + os << "ENDDATA" << endl; + + return os.name(); } diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index 780e25b568..33dc3263d4 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,7 +56,7 @@ Foam::proxySurfaceWriter::~proxySurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::proxySurfaceWriter::write +Foam::fileName Foam::proxySurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -68,7 +68,7 @@ void Foam::proxySurfaceWriter::write // avoid bad values if (ext_.empty()) { - return; + return fileName::null; } if (!isDir(outputDir)) @@ -84,6 +84,8 @@ void Foam::proxySurfaceWriter::write } MeshedSurfaceProxy(points, faces).write(outName); + + return outName; } diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index 89ec6429f4..7dc6e52a7d 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,14 +78,14 @@ public: //- 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() + virtual bool separateGeometry() const { return true; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -93,7 +93,6 @@ public: const faceList& faces, const bool verbose = false ) const; - }; diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index 1899b1212a..4447a16b93 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,11 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "rawSurfaceWriter.H" - -#include "OFstream.H" -#include "OSspecific.H" -#include "IOmanip.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -208,66 +203,6 @@ namespace Foam } -template -void Foam::rawSurfaceWriter::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 + ".raw"); - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - // header - os << "# " << fieldName; - if (isNodeValues) - { - os << " POINT_DATA "; - } - else - { - os << " FACE_DATA "; - } - - // header - writeHeader(os, fieldName, values); - - // 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() @@ -284,7 +219,7 @@ Foam::rawSurfaceWriter::~rawSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::rawSurfaceWriter::write +Foam::fileName Foam::rawSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -318,6 +253,8 @@ void Foam::rawSurfaceWriter::write } os << nl; + + return os.name(); } diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H index 6a3b3c2ee2..8cb999dac6 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,7 +82,7 @@ class rawSurfaceWriter //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -114,7 +114,7 @@ public: // Member Functions //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -126,7 +126,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -140,7 +140,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -154,7 +154,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -168,7 +168,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -182,7 +182,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -193,7 +193,6 @@ public: const bool isNodeValues, const bool verbose = false ) const; - }; @@ -203,6 +202,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "rawSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterTemplates.C new file mode 100644 index 0000000000..59b15c59b9 --- /dev/null +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriterTemplates.C @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "OFstream.H" +#include "OSspecific.H" +#include "IOmanip.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::fileName Foam::rawSurfaceWriter::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 + ".raw"); + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << os.name() << endl; + } + + // header + os << "# " << fieldName; + if (isNodeValues) + { + os << " POINT_DATA "; + } + else + { + os << " FACE_DATA "; + } + + // header + writeHeader(os, fieldName, values); + + // 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]); + } + } + + return os.name(); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C index 86fb4b1c17..a22f5a49ea 100644 --- a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,11 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "starcdSurfaceWriter.H" - #include "MeshedSurfaceProxy.H" -#include "OFstream.H" -#include "OSspecific.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -78,50 +74,6 @@ namespace Foam } -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() @@ -138,7 +90,7 @@ Foam::starcdSurfaceWriter::~starcdSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::starcdSurfaceWriter::write +Foam::fileName Foam::starcdSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -160,6 +112,8 @@ void Foam::starcdSurfaceWriter::write } MeshedSurfaceProxy(points, faces).write(outName); + + return outName; } diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H index 13444367fc..9341f9816b 100644 --- a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,7 +77,7 @@ class starcdSurfaceWriter //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -110,13 +110,13 @@ public: //- 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() + virtual bool separateGeometry() const { return true; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -127,7 +127,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -141,7 +141,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -155,7 +155,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -166,7 +166,6 @@ public: const bool isNodeValues, const bool verbose = false ) const; - }; @@ -176,6 +175,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "starcdSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriterTemplates.C new file mode 100644 index 0000000000..08733bb5a2 --- /dev/null +++ b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriterTemplates.C @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "OFstream.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +inline void Foam::starcdSurfaceWriter::writeData +( + Ostream& os, + const Type& v +) +{} + + +template +Foam::fileName 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]); + } + + return os.name(); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 84ca3cdf5d..7fd2af4a09 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -110,13 +110,13 @@ public: //- 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() + virtual bool separateGeometry() const { return false; } //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -124,11 +124,13 @@ public: const faceList& faces, const bool verbose = false ) const - {} + { + return fileName::null; + } //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -139,11 +141,13 @@ public: const bool isNodeValues, const bool verbose = false ) const - {} + { + return fileName::null; + } //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -154,11 +158,13 @@ public: const bool isNodeValues, const bool verbose = false ) const - {} + { + return fileName::null; + } //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -169,11 +175,13 @@ public: const bool isNodeValues, const bool verbose = false ) const - {} + { + return fileName::null; + } //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -184,11 +192,13 @@ public: const bool isNodeValues, const bool verbose = false ) const - {} + { + return fileName::null; + } //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -199,7 +209,9 @@ public: const bool isNodeValues, const bool verbose = false ) const - {} + { + return fileName::null; + } }; diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index 5e6c38045b..41cf0f5617 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,10 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "vtkSurfaceWriter.H" - -#include "OFstream.H" -#include "OSspecific.H" - #include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -202,69 +198,6 @@ namespace Foam } -// Write generic field in vtk format -template -void Foam::vtkSurfaceWriter::writeData -( - Ostream& os, - const Field& values -) -{ - os << "1 " << values.size() << " float" << nl; - - forAll(values, elemI) - { - os << float(0) << nl; - } -} - - -template -void Foam::vtkSurfaceWriter::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 + ".vtk"); - - if (verbose) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - writeGeometry(os, points, faces); - - // start writing data - if (isNodeValues) - { - os << "POINT_DATA "; - } - else - { - os << "CELL_DATA "; - } - - os << values.size() << nl - << "FIELD attributes 1" << nl - << fieldName << " "; - - // Write data - writeData(os, values); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::vtkSurfaceWriter::vtkSurfaceWriter() @@ -281,7 +214,7 @@ Foam::vtkSurfaceWriter::~vtkSurfaceWriter() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::vtkSurfaceWriter::write +Foam::fileName Foam::vtkSurfaceWriter::write ( const fileName& outputDir, const fileName& surfaceName, @@ -303,6 +236,8 @@ void Foam::vtkSurfaceWriter::write } writeGeometry(os, points, faces); + + return os.name(); } diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index e6a6a91c01..6e648086e1 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,7 +60,7 @@ class vtkSurfaceWriter //- Templated write operation template - void writeTemplate + fileName writeTemplate ( const fileName& outputDir, const fileName& surfaceName, @@ -72,6 +72,7 @@ class vtkSurfaceWriter const bool verbose ) const; + public: //- Runtime type information @@ -91,7 +92,7 @@ public: // Member Functions //- Write single surface geometry to file. - virtual void write + virtual fileName write ( const fileName& outputDir, const fileName& surfaceName, @@ -103,7 +104,7 @@ public: //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -117,7 +118,7 @@ public: //- Write vectorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -131,7 +132,7 @@ public: //- Write sphericalTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -145,7 +146,7 @@ public: //- Write symmTensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -159,7 +160,7 @@ public: //- Write tensorField for a single surface to file. // One value per face or vertex (isNodeValues = true) - virtual void write + virtual fileName write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface @@ -180,6 +181,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "vtkSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterTemplates.C new file mode 100644 index 0000000000..819dd567f8 --- /dev/null +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterTemplates.C @@ -0,0 +1,95 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd +------------------------------------------------------------------------------- +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 "OFstream.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::vtkSurfaceWriter::writeData +( + Ostream& os, + const Field& values +) +{ + os << "1 " << values.size() << " float" << nl; + + forAll(values, elemI) + { + os << float(0) << nl; + } +} + + +template +Foam::fileName Foam::vtkSurfaceWriter::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 + ".vtk"); + + if (verbose) + { + Info<< "Writing field " << fieldName << " to " << os.name() << endl; + } + + writeGeometry(os, points, faces); + + // start writing data + if (isNodeValues) + { + os << "POINT_DATA "; + } + else + { + os << "CELL_DATA "; + } + + os << values.size() << nl + << "FIELD attributes 1" << nl + << fieldName << " "; + + // Write data + writeData(os, values); + + return os.name(); +} + + +// ************************************************************************* //