diff --git a/src/surfMesh/writers/raw/rawSurfaceWriter.C b/src/surfMesh/writers/raw/rawSurfaceWriter.C index d9df17180e..787d733afe 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriter.C +++ b/src/surfMesh/writers/raw/rawSurfaceWriter.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,19 +45,6 @@ namespace surfaceWriters } -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace -{ - // Emit x,y,z - static inline void writePoint(Foam::Ostream& os, const Foam::point& p) - { - os << p.x() << ' ' << p.y() << ' ' << p.z(); - } - -} // End anonymous namespace - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Field writing implementation @@ -73,6 +60,8 @@ Foam::surfaceWriters::rawWriter::rawWriter() : surfaceWriter(), streamOpt_(), + precision_(IOstream::defaultPrecision()), + writeNormal_(false), geometryScale_(1), fieldScale_() {} @@ -89,6 +78,11 @@ Foam::surfaceWriters::rawWriter::rawWriter IOstream::ASCII, IOstream::compressionEnum("compression", options) ), + precision_ + ( + options.getOrDefault("precision", IOstream::defaultPrecision()) + ), + writeNormal_(options.getOrDefault("normal", false)), geometryScale_(options.getOrDefault("scale", 1)), fieldScale_(options.subOrEmptyDict("fieldScale")) {} @@ -151,6 +145,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write() { const pointField& points = surf.points(); const faceList& faces = surf.faces(); + const bool withFaceNormal = writeNormal_; // Even for point data? if (!isDir(outputFile.path())) { @@ -158,17 +153,28 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write() } OFstream os(outputFile, streamOpt_); + os.precision(precision_); // Header { - os << "# geometry NO_DATA " << faces.size() << nl - << "# x y z" << nl; + os << "# geometry NO_DATA " << faces.size() << nl; + writeHeaderXYZ(os); + if (withFaceNormal) + { + writeHeaderArea(os); + } + os << nl; } - // Write faces centres + // Write faces centres (optionally faceArea normals) for (const face& f : faces) { writePoint(os, f.centre(points)*geometryScale_); + if (withFaceNormal) + { + os << ' '; + writePoint(os, f.areaNormal(points)*geometryScale_); + } os << nl; } diff --git a/src/surfMesh/writers/raw/rawSurfaceWriter.H b/src/surfMesh/writers/raw/rawSurfaceWriter.H index f8a00a950a..5e167820ba 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriter.H +++ b/src/surfMesh/writers/raw/rawSurfaceWriter.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +34,10 @@ Description \table Property | Description | Required | Default compression | Use file compression | no | false + precision | Write precision in ascii | no | same as IOstream scale | output geometry scaling | no | 1 fieldScale | output field scaling (dictionary) | no | empty + normal | Write face area normal in output | no | false \endtable For example, @@ -47,6 +49,8 @@ Description compression on; scale 1000; // [m] -> [mm] + normal yes; + precision 10; fieldScale { "p.*" 0.01; // [Pa] -> [mbar] @@ -105,6 +109,12 @@ class rawWriter //- Output stream option IOstreamOption streamOpt_; + //- ASCII write precision + unsigned precision_; + + //- Output face area normal + const bool writeNormal_; + //- Output geometry scaling const scalar geometryScale_; diff --git a/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C b/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C index b968e6106b..928f421231 100644 --- a/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C +++ b/src/surfMesh/writers/raw/rawSurfaceWriterImpl.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,6 +34,12 @@ License namespace Foam { + // Emit x,y,z + static inline void writePoint(Ostream& os, const point& p) + { + os << p.x() << ' ' << p.y() << ' ' << p.z(); + } + // Emit each component template static inline void writeData(Ostream& os, const Type& val) @@ -42,65 +48,58 @@ namespace Foam { os << ' ' << component(val, i); } - os << nl; + } + + // Write x/y/z header. Must be called first + static inline void writeHeaderXYZ(Ostream& os) + { + os << "# x y z"; + } + + // Write area header + static inline void writeHeaderArea(Ostream& os) + { + os << " area_x area_y area_z"; } template - static inline void writeHeader(Ostream& os, const word& fieldName) {} - - template<> - void writeHeader