From f05c049d43c0918a9287610ff6722b3bafffb265 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 2 Oct 2012 13:16:45 +0100 Subject: [PATCH 1/7] ENH: Enabled valueOutput for surfaces in fieldValues --- .../field/fieldValues/faceSource/faceSource.C | 42 ++++++++++++++++++- .../field/fieldValues/faceSource/faceSource.H | 9 +++- .../faceSource/faceSourceTemplates.C | 10 ++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 600d3d9ecd..2fa6b5c7de 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -31,6 +31,7 @@ License #include "sampledSurface.H" #include "mergePoints.H" #include "indirectPrimitivePatch.H" +#include "PatchTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -224,7 +225,7 @@ void Foam::fieldValues::faceSource::sampledSurfaceFaces(const dictionary& dict) } -void Foam::fieldValues::faceSource::combineSurfaceGeometry +void Foam::fieldValues::faceSource::combineMeshGeometry ( faceList& faces, pointField& points @@ -345,6 +346,45 @@ void Foam::fieldValues::faceSource::combineSurfaceGeometry } +void Foam::fieldValues::faceSource::combineSurfaceGeometry +( + faceList& faces, + pointField& points +) const +{ + if (surfacePtr_.valid()) + { + const sampledSurface& s = surfacePtr_(); + + if (Pstream::parRun()) + { + // dimension as fraction of mesh bounding box + scalar mergeDim = 1e-10*mesh().bounds().mag(); + + labelList pointsMap; + + PatchTools::gatherAndMerge + ( + mergeDim, + primitivePatch + ( + SubList(s.faces(), s.faces().size()), + s.points() + ), + points, + faces, + pointsMap + ); + } + else + { + faces = s.faces(); + points = s.points(); + } + } +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::fieldValues::faceSource::initialise(const dictionary& dict) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index fafedc3a12..6c33df8611 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -204,7 +204,14 @@ private: //- Set faces according to sampledSurface void sampledSurfaceFaces(const dictionary&); - //- Combine faces and points from multiple processors + //- Combine mesh faces and points from multiple processors + void combineMeshGeometry + ( + faceList& faces, + pointField& points + ) const; + + //- Combine surface faces and points from multiple processors void combineSurfaceGeometry ( faceList& faces, diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index cfdcc08d4f..1d58245010 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -259,7 +259,15 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) { faceList faces; pointField points; - combineSurfaceGeometry(faces, points); + + if (surfacePtr_.valid()) + { + combineSurfaceGeometry(faces, points); + } + else + { + combineMeshGeometry(faces, points); + } fileName outputDir; if (Pstream::parRun()) From bd58348f248aab573b095a00949d830106485036 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 2 Oct 2012 14:24:11 +0100 Subject: [PATCH 2/7] ENH: Improved plane select from dict messages --- src/OpenFOAM/meshes/primitiveShapes/plane/plane.C | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index b7efdbb643..c191f44c3e 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -208,7 +208,7 @@ Foam::plane::plane(const dictionary& dict) } else if (planeType == "embeddedPoints") { - const dictionary& subDict = dict.subDict("embeddedPoints"); + const dictionary& subDict = dict.subDict("embeddedPointsDict"); point point1(subDict.lookup("point1")); point point2(subDict.lookup("point2")); @@ -226,11 +226,10 @@ Foam::plane::plane(const dictionary& dict) } else { - FatalIOErrorIn - ( - "plane::plane(const dictionary&)", - dict - ) << "Invalid plane type: " << planeType + FatalIOErrorIn("plane::plane(const dictionary&)", dict) + << "Invalid plane type: " << planeType << nl + << "Valid options include: planeEquation, embeddedPoints and " + << "pointAndNormal" << abort(FatalIOError); } } From cc1e1a725fe62ca98b0632c9ee6d80a288f5f0ec Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 10 Oct 2012 15:04:30 +0100 Subject: [PATCH 3/7] STYLE: minor code formatting --- src/meshTools/meshSearch/meshSearch.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshTools/meshSearch/meshSearch.C b/src/meshTools/meshSearch/meshSearch.C index 9524515531..6ff66755e4 100644 --- a/src/meshTools/meshSearch/meshSearch.C +++ b/src/meshTools/meshSearch/meshSearch.C @@ -799,7 +799,7 @@ Foam::label Foam::meshSearch::findCell } else { - return findCellLinear(location); + return findCellLinear(location); } } else From bc7d36e0ff70374077951df9c37fe373d6e1120f Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 10 Oct 2012 15:05:11 +0100 Subject: [PATCH 4/7] ENH: Create surface writer with additional dictionary options --- .../FacePostProcessing/FacePostProcessing.C | 7 ++++++- .../field/fieldValues/faceSource/faceSource.C | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C index 36fb2aa035..ae02927bbd 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C @@ -191,7 +191,12 @@ void Foam::FacePostProcessing::write() autoPtr writer ( - surfaceWriter::New(surfaceFormat_) + surfaceWriter::New + ( + surfaceFormat_, + this->coeffDict().subOrEmptyDict("formatOptions"). + subOrEmptyDict(surfaceFormat_) + ) ); writer->write diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 2fa6b5c7de..43e3bdc768 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -457,9 +457,16 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) if (valueOutput_) { + const word surfaceFormat(dict.lookup("surfaceFormat")); + surfaceWriterPtr_.reset ( - surfaceWriter::New(dict.lookup("surfaceFormat")).ptr() + surfaceWriter::New + ( + surfaceFormat, + dict.subOrEmptyDict("formatOptions"). + subOrEmptyDict(surfaceFormat) + ).ptr() ); } } From 3c0a1ee5aaa5f97f03037f1a64600a288207ecda Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 10 Oct 2012 15:12:04 +0100 Subject: [PATCH 5/7] STYLE: minor code formatting --- src/sampling/sampledSurface/writers/surfaceWriter.H | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index aa9e8fd095..dd54a756c6 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ Class Foam::surfaceWriter Description + Base class for surface writers SourceFiles surfaceWriter.C @@ -115,7 +116,6 @@ public: return false; } - //- Write single surface geometry to file. virtual void write ( @@ -127,7 +127,6 @@ public: ) const {} - //- Write scalarField for a single surface to file. // One value per face or vertex (isNodeValues = true) virtual void write @@ -202,8 +201,6 @@ public: const bool verbose = false ) const {} - - }; From 643f4cb906ff47ff7717e8994e9134b1dfff71b1 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 12 Oct 2012 15:32:46 +0100 Subject: [PATCH 6/7] ENH: Added initial version of nastran surface writer --- src/sampling/Make/files | 1 + .../writers/nastran/nastranSurfaceWriter.C | 372 ++++++++++++++++++ .../writers/nastran/nastranSurfaceWriter.H | 260 ++++++++++++ .../nastran/nastranSurfaceWriterTemplates.C | 201 ++++++++++ 4 files changed, 834 insertions(+) create mode 100644 src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C create mode 100644 src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H create mode 100644 src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 649f05523d..118a48cab4 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -55,6 +55,7 @@ $(surfWriters)/surfaceWriter.C $(surfWriters)/dx/dxSurfaceWriter.C $(surfWriters)/ensight/ensightSurfaceWriter.C $(surfWriters)/foamFile/foamFileSurfaceWriter.C +$(surfWriters)/nastran/nastranSurfaceWriter.C $(surfWriters)/proxy/proxySurfaceWriter.C $(surfWriters)/raw/rawSurfaceWriter.C $(surfWriters)/starcd/starcdSurfaceWriter.C diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C new file mode 100644 index 0000000000..3a67a8dd23 --- /dev/null +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C @@ -0,0 +1,372 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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 "nastranSurfaceWriter.H" +#include "IOmanip.H" +#include "Tuple2.H" +#include "makeSurfaceWriterMethods.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + makeSurfaceWriterType(nastranSurfaceWriter); + addToRunTimeSelectionTable(surfaceWriter, nastranSurfaceWriter, wordDict); + + // create write methods + defineSurfaceWriterWriteFields(nastranSurfaceWriter); + + template<> + const char* NamedEnum::names[] = + { + "short", + "long", + "free" + }; + + const NamedEnum + nastranSurfaceWriter::writeFormatNames_; +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const +{ + os.setf(ios_base::scientific); + + // capitalise the E marker + os.setf(ios_base::uppercase); + + label prec = 0; + label offset = 7; + switch (writeFormat_) + { + case (wfShort): + case (wfFree): + { + prec = 8 - offset; + break; + } + case (wfLong): + { + prec = 16 - offset; + break; + } + default: + { + } + } + + os.precision(prec); +} + + +void Foam::nastranSurfaceWriter::writeCoord +( + const point& p, + label& nPoint, + label& continuation, + Ostream& os +) const +{ + // Fixed short/long formats: + // 1 GRID + // 2 ID : point ID + // 3 CP : co-ordinate system ID (blank) + // 4 X1 : point x cp-ordinate + // 5 X2 : point x cp-ordinate + // 6 X3 : point x cp-ordinate + // 7 CD : co-ordinate system for displacements (blank) + // 8 PS : single point constraints (blank) + // 9 SEID : super-element ID + + switch (writeFormat_) + { + case wfShort: + { + os << setw(8) << "GRID" + << setw(8) << ++nPoint + << " " + << setw(8) << p.x() + << setw(8) << p.y() + << setw(8) << p.z() + << nl; + + break; + } + case wfLong: + { + os << setw(8) << "GRID*" + << setw(16) << ++nPoint + << " " + << setw(16) << p.x() + << setw(16) << p.y() + << setw(8) << ++continuation + << nl + << setw(8) << continuation + << setw(16) << p.z() + << nl; + + break; + } + case wfFree: + { + os << "GRID" + << ',' << ++nPoint + << ',' + << ',' << p.x() + << ',' << p.y() + << ',' << p.z() + << nl; + + break; + } + default: + { + FatalErrorIn + ( + "void Foam::nastranSurfaceWriter::writeCoord" + "(" + "Ostream&, " + "const point&" + ") const" + ) << "Unknown writeFormat enumeration" << abort(FatalError); + } + } +} + +void Foam::nastranSurfaceWriter::writeFace +( + const word& faceType, + const labelList& facePts, + label& nFace, + Ostream& os +) const +{ + // Only valid surface elements are CTRIA3 and CQUAD4 + + // Fixed short/long formats: + // 1 CQUAD4 + // 2 EID : element ID + // 3 PID : property element ID; default = EID (blank) + // 4 G1 : grid point index + // 5 G2 : grid point index + // 6 G3 : grid point index + // 7 G4 : grid point index + // 8 onwards - not used + + // For CTRIA3 elements, cols 7 onwards are not used + + switch (writeFormat_) + { + case wfShort: + case wfLong: + { + os << setw(8) << faceType + << setw(8) << ++nFace + << " "; + + forAll(facePts, i) + { + os << setw(8) << facePts[i]; + } + + os << nl; + + break; + } + case wfFree: + { + os << faceType << ',' + << ++nFace << ','; + + forAll(facePts, i) + { + os << ',' << facePts[i]; + } + + os << nl; + + break; + } + default: + { + FatalErrorIn + ( + "void Foam::nastranSurfaceWriter::writeFace" + "(" + "const word&" + "const labelList&" + "label&" + "Ostream&, " + ") const" + ) << "Unknown writeFormat enumeration" << abort(FatalError); + } + } + +} + + +void Foam::nastranSurfaceWriter::writeGeometry +( + const pointField& points, + const faceList& faces, + List >& decomposedFaces, + Ostream& os +) const +{ + // write points + + os << "$" << nl + << "$ Points" << nl + << "$" << nl; + + label nPoint = 0; + label continuation = 0; + + forAll(points, pointI) + { + writeCoord(points[pointI], nPoint, continuation, os); + } + + + // write faces + + os << "$" << nl + << "$ Faces" << nl + << "$" << nl; + + label nFace = 0; + + forAll(faces, faceI) + { + const face& f = faces[faceI]; + + if (f.size() == 3) + { + writeFace("CTRIA3", faces[faceI], nFace, os); + decomposedFaces[faceI].append(faces[faceI]); + } + else if (f.size() == 4) + { + writeFace("CQUAD4", faces[faceI], nFace, os); + decomposedFaces[faceI].append(faces[faceI]); + } + else + { + // decompose poly face into tris + label nTri = 0; + faceList triFaces; + f.triangles(points, nTri, triFaces); + + forAll(triFaces, triI) + { + writeFace("CTRIA3", triFaces[triI], nFace, os); + decomposedFaces[faceI].append(triFaces[triI]); + } + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::nastranSurfaceWriter::nastranSurfaceWriter() +: + surfaceWriter(), + writeFormat_(wfShort), + fieldMap_() +{} + + +Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& options) +: + surfaceWriter(), + writeFormat_(wfShort), + fieldMap_() +{ + if (options.found("format")) + { + writeFormat_ = writeFormatNames_.read(options.lookup("format")); + } + + List > fieldSet(options.lookup("fields")); + + forAll(fieldSet, i) + { + fieldMap_.insert(fieldSet[i].first(), fieldSet[i].second()); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::nastranSurfaceWriter::~nastranSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::nastranSurfaceWriter::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + OFstream os(outputDir/surfaceName + ".dat"); + formatOS(os); + + if (verbose) + { + Info<< "Writing nastran file to " << os.name() << endl; + } + + os << "TITLE=OpeNFOAM " << surfaceName.c_str() << " mesh" << nl + << "$" << nl + << "BEGIN BULK" << nl; + + List > decomposedFaces(faces.size()); + + writeGeometry(points, faces, decomposedFaces, os); + + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + os << "ENDDATA" << endl; +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H new file mode 100644 index 0000000000..3667173d65 --- /dev/null +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H @@ -0,0 +1,260 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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::nastranSurfaceWriter + +Description + A surface writer for the Nastran file format - both surface mesh and fields + +SourceFiles + nastranSurfaceWriter.C + nastranSurfaceWriterTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef nastranSurfaceWriter_H +#define nastranSurfaceWriter_H + +#include "surfaceWriter.H" +#include "NamedEnum.H" +#include "OFstream.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class nastranSurfaceWriter Declaration +\*---------------------------------------------------------------------------*/ + +class nastranSurfaceWriter +: + public surfaceWriter +{ +public: + + enum writeFormat + { + wfShort, + wfLong, + wfFree + }; + + static const NamedEnum writeFormatNames_; + + +private: + + // Private data + + //- Write option + writeFormat writeFormat_; + + //- Map of OpenFOAM field name vs nastran field name + HashTable fieldMap_; + + + // Private Member Functions + + //- Initialise the output stream format params + void formatOS(OFstream& os) const; + + //- Write a co-ordinate + void writeCoord + ( + const point& p, + label& nPoint, + label& continuation, + Ostream& os + ) const; + + //- Write a face element (CTRIA3 or CQUAD4) + void writeFace + ( + const word& faceType, + const labelList& facePts, + label& nFace, + Ostream& os + ) const; + + //- Main driver to write the surface mesh geometry + void writeGeometry + ( + const pointField& points, + const faceList& faces, + List >& decomposedFaces, + Ostream& os + ) const; + + //- Write a face-based value + template + void writeFaceValue + ( + const word& nasFieldName, + const Type& value, + const label EID, + Ostream& os + ) const; + + //- Templated write operation + template + void writeTemplate + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose + ) const; + + +public: + + //- Runtime type information + TypeName("nastran"); + + + // Constructors + + //- Construct null + nastranSurfaceWriter(); + + //- Construct with some output options + nastranSurfaceWriter(const dictionary& options); + + + //- Destructor + virtual ~nastranSurfaceWriter(); + + + // Member Functions + + //- True if the surface format supports geometry in a separate file. + // False if geometry and field must be in a single file + virtual bool separateGeometry() + { + return false; + } + + //- Write single surface geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + + //- Write scalarField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write vectorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write sphericalTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write symmTensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; + + //- Write tensorField for a single surface to file. + // One value per face or vertex (isNodeValues = true) + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field& values, + const bool isNodeValues, + const bool verbose = false + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "nastranSurfaceWriterTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C new file mode 100644 index 0000000000..a393a5968b --- /dev/null +++ b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C @@ -0,0 +1,201 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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 "OFstream.H" +#include "IOmanip.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::nastranSurfaceWriter::writeFaceValue +( + const word& nasFieldName, + const Type& value, + const label EID, + 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 + + label SID = 0; + + label w = 16; + switch (writeFormat_) + { + case wfShort: + { + w = 8; + } + case wfLong: + { + os << setw(8) << nasFieldName + << setw(8) << SID + << setw(8) << EID; + + for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) + { + os << setw(w) << component(value, dirI); + } + + break; + } + case wfFree: + { + os << nasFieldName << ',' + << SID << ',' + << EID; + + for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) + { + os << ',' << component(value, dirI); + } + + break; + } + default: + { + } + } + + os << nl; +} + + +template +void Foam::nastranSurfaceWriter::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 (!fieldMap_.found(fieldName)) + { + WarningIn + ( + "void Foam::nastranSurfaceWriter::writeTemplate" + "(" + "const fileName&, " + "const fileName&, " + "const pointField&, " + "const faceList&, " + "const word&, " + "const Field&, " + "const bool, " + "const bool" + ") const" + ) + << "No mapping found between field " << fieldName + << " and corresponding Nastran field. Available types are:" + << fieldMap_ + << exit(FatalError); + + return; + } + + const word& nasFieldName(fieldMap_[fieldName]); + + if (!isDir(outputDir/fieldName)) + { + mkDir(outputDir/fieldName); + } + + // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + const scalar timeValue = 0.0; + + OFstream os(outputDir/fieldName/surfaceName + ".dat"); + formatOS(os); + + if (verbose) + { + Info<< "Writing nastran file to " << os.name() << endl; + } + + os << "TITLE=OpenFOAM " << surfaceName.c_str() << " " << fieldName + << " data" << nl + << "$" << nl + << "TIME " << timeValue << nl + << "$" << nl + << "BEGIN BULK" << nl; + + List > decomposedFaces(faces.size()); + + writeGeometry(points, faces, decomposedFaces, os); + + + os << "$" << nl + << "$ Field data" << nl + << "$" << nl; + + if (isNodeValues) + { + label n = 0; + + forAll(decomposedFaces, i) + { + const DynamicList& dFaces = decomposedFaces[i]; + forAll(dFaces, faceI) + { + Type v = pTraits::zero; + const face& f = dFaces[faceI]; + + forAll(f, fptI) + { + v += values[f[fptI]]; + } + + writeFaceValue(nasFieldName, v, ++n, os); + } + } + } + else + { + label n = 0; + + forAll(decomposedFaces, i) + { + const DynamicList& dFaces = decomposedFaces[i]; + + forAll(dFaces, faceI) + { + writeFaceValue(nasFieldName, values[faceI], ++n, os); + } + } + } + + os << "ENDDATA" << endl; +} + + +// ************************************************************************* // From eab309a838874ca62e9acf72af1e73ed1d59a43d Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 12 Oct 2012 15:47:19 +0100 Subject: [PATCH 7/7] ENH: Updated film radiation model --- .../standardRadiation/standardRadiation.C | 12 ++++++------ .../standardRadiation/standardRadiation.H | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.C b/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.C index ba15857130..6f20f0266a 100644 --- a/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.C +++ b/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.C @@ -57,11 +57,11 @@ standardRadiation::standardRadiation ) : filmRadiationModel(typeName, owner, dict), - QrPrimary_ + QinPrimary_ ( IOobject ( - "Qr", // same name as Qr on primary region to enable mapping + "Qin", // same name as Qin on primary region to enable mapping owner.time().timeName(), owner.regionMesh(), IOobject::NO_READ, @@ -103,7 +103,7 @@ standardRadiation::~standardRadiation() void standardRadiation::correct() { // Transfer Qr from primary region - QrPrimary_.correctBoundaryConditions(); + QinPrimary_.correctBoundaryConditions(); } @@ -128,13 +128,13 @@ tmp standardRadiation::Shs() ); scalarField& Shs = tShs(); - const scalarField& QrP = QrPrimary_.internalField(); + const scalarField& QinP = QinPrimary_.internalField(); const scalarField& delta = delta_.internalField(); - Shs = beta_*(QrP*pos(delta - deltaMin_))*(1.0 - exp(-kappaBar_*delta)); + Shs = beta_*(QinP*pos(delta - deltaMin_))*(1.0 - exp(-kappaBar_*delta)); // Update net Qr on local region - QrNet_.internalField() = QrP - Shs; + QrNet_.internalField() = QinP - Shs; QrNet_.correctBoundaryConditions(); return tShs; diff --git a/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.H b/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.H index b70799aad8..9b96fb60fe 100644 --- a/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.H +++ b/src/regionModels/surfaceFilmModels/submodels/thermo/filmRadiationModel/standardRadiation/standardRadiation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,8 +59,8 @@ private: // Private data - //- Radiative flux mapped from the primary region / [kg/s3] - volScalarField QrPrimary_; + //- Radiative incident flux mapped from the primary region / [kg/s3] + volScalarField QinPrimary_; //- Remaining radiative flux after removing local contribution volScalarField QrNet_;