mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: raw format with optional output for face area normals (#2003)
- the raw surface writer simply outputs x/y/z and field values.
This additional flag allows recovery of some geometric information.
- optional user-specified output precision
Example,
```
formatOptions
{
raw
{
normal yes;
precision 10;
}
}
```
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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
|
// Field writing implementation
|
||||||
@ -73,6 +60,8 @@ Foam::surfaceWriters::rawWriter::rawWriter()
|
|||||||
:
|
:
|
||||||
surfaceWriter(),
|
surfaceWriter(),
|
||||||
streamOpt_(),
|
streamOpt_(),
|
||||||
|
precision_(IOstream::defaultPrecision()),
|
||||||
|
writeNormal_(false),
|
||||||
geometryScale_(1),
|
geometryScale_(1),
|
||||||
fieldScale_()
|
fieldScale_()
|
||||||
{}
|
{}
|
||||||
@ -89,6 +78,11 @@ Foam::surfaceWriters::rawWriter::rawWriter
|
|||||||
IOstream::ASCII,
|
IOstream::ASCII,
|
||||||
IOstream::compressionEnum("compression", options)
|
IOstream::compressionEnum("compression", options)
|
||||||
),
|
),
|
||||||
|
precision_
|
||||||
|
(
|
||||||
|
options.getOrDefault("precision", IOstream::defaultPrecision())
|
||||||
|
),
|
||||||
|
writeNormal_(options.getOrDefault("normal", false)),
|
||||||
geometryScale_(options.getOrDefault<scalar>("scale", 1)),
|
geometryScale_(options.getOrDefault<scalar>("scale", 1)),
|
||||||
fieldScale_(options.subOrEmptyDict("fieldScale"))
|
fieldScale_(options.subOrEmptyDict("fieldScale"))
|
||||||
{}
|
{}
|
||||||
@ -151,6 +145,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
|
|||||||
{
|
{
|
||||||
const pointField& points = surf.points();
|
const pointField& points = surf.points();
|
||||||
const faceList& faces = surf.faces();
|
const faceList& faces = surf.faces();
|
||||||
|
const bool withFaceNormal = writeNormal_; // Even for point data?
|
||||||
|
|
||||||
if (!isDir(outputFile.path()))
|
if (!isDir(outputFile.path()))
|
||||||
{
|
{
|
||||||
@ -158,17 +153,28 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
|
|||||||
}
|
}
|
||||||
|
|
||||||
OFstream os(outputFile, streamOpt_);
|
OFstream os(outputFile, streamOpt_);
|
||||||
|
os.precision(precision_);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
{
|
{
|
||||||
os << "# geometry NO_DATA " << faces.size() << nl
|
os << "# geometry NO_DATA " << faces.size() << nl;
|
||||||
<< "# x y z" << nl;
|
writeHeaderXYZ(os);
|
||||||
|
if (withFaceNormal)
|
||||||
|
{
|
||||||
|
writeHeaderArea(os);
|
||||||
|
}
|
||||||
|
os << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write faces centres
|
// Write faces centres (optionally faceArea normals)
|
||||||
for (const face& f : faces)
|
for (const face& f : faces)
|
||||||
{
|
{
|
||||||
writePoint(os, f.centre(points)*geometryScale_);
|
writePoint(os, f.centre(points)*geometryScale_);
|
||||||
|
if (withFaceNormal)
|
||||||
|
{
|
||||||
|
os << ' ';
|
||||||
|
writePoint(os, f.areaNormal(points)*geometryScale_);
|
||||||
|
}
|
||||||
os << nl;
|
os << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -34,8 +34,10 @@ Description
|
|||||||
\table
|
\table
|
||||||
Property | Description | Required | Default
|
Property | Description | Required | Default
|
||||||
compression | Use file compression | no | false
|
compression | Use file compression | no | false
|
||||||
|
precision | Write precision in ascii | no | same as IOstream
|
||||||
scale | output geometry scaling | no | 1
|
scale | output geometry scaling | no | 1
|
||||||
fieldScale | output field scaling (dictionary) | no | empty
|
fieldScale | output field scaling (dictionary) | no | empty
|
||||||
|
normal | Write face area normal in output | no | false
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
For example,
|
For example,
|
||||||
@ -47,6 +49,8 @@ Description
|
|||||||
compression on;
|
compression on;
|
||||||
|
|
||||||
scale 1000; // [m] -> [mm]
|
scale 1000; // [m] -> [mm]
|
||||||
|
normal yes;
|
||||||
|
precision 10;
|
||||||
fieldScale
|
fieldScale
|
||||||
{
|
{
|
||||||
"p.*" 0.01; // [Pa] -> [mbar]
|
"p.*" 0.01; // [Pa] -> [mbar]
|
||||||
@ -105,6 +109,12 @@ class rawWriter
|
|||||||
//- Output stream option
|
//- Output stream option
|
||||||
IOstreamOption streamOpt_;
|
IOstreamOption streamOpt_;
|
||||||
|
|
||||||
|
//- ASCII write precision
|
||||||
|
unsigned precision_;
|
||||||
|
|
||||||
|
//- Output face area normal
|
||||||
|
const bool writeNormal_;
|
||||||
|
|
||||||
//- Output geometry scaling
|
//- Output geometry scaling
|
||||||
const scalar geometryScale_;
|
const scalar geometryScale_;
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -34,6 +34,12 @@ License
|
|||||||
|
|
||||||
namespace Foam
|
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
|
// Emit each component
|
||||||
template<class Type>
|
template<class Type>
|
||||||
static inline void writeData(Ostream& os, const Type& val)
|
static inline void writeData(Ostream& os, const Type& val)
|
||||||
@ -42,65 +48,58 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
os << ' ' << component(val, i);
|
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<class Type>
|
template<class Type>
|
||||||
static inline void writeHeader(Ostream& os, const word& fieldName) {}
|
static inline void writeHeader(Ostream& os, const word& fieldName)
|
||||||
|
|
||||||
template<>
|
|
||||||
void writeHeader<label>(Ostream& os, const word& fieldName)
|
|
||||||
{
|
{
|
||||||
os << "# x y z"
|
os << " " << fieldName;
|
||||||
<< " " << fieldName << nl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<class Type>
|
||||||
void writeHeader<scalar>(Ostream& os, const word& fieldName)
|
void writeHeaderComponents(Ostream& os, const word& fieldName)
|
||||||
{
|
{
|
||||||
os << "# x y z"
|
os << ' ';
|
||||||
<< " " << fieldName << nl;
|
for (direction i=0; i < pTraits<Type>::nComponents; ++i)
|
||||||
|
{
|
||||||
|
os << ' ' << fieldName << '_' << Type::componentNames[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void writeHeader<vector>(Ostream& os, const word& fieldName)
|
void writeHeader<vector>(Ostream& os, const word& fieldName)
|
||||||
{
|
{
|
||||||
os << "# x y z"
|
writeHeaderComponents<vector>(os, fieldName);
|
||||||
<< " " << fieldName << "_x"
|
|
||||||
<< " " << fieldName << "_y"
|
|
||||||
<< " " << fieldName << "_z"
|
|
||||||
<< nl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void writeHeader<sphericalTensor>(Ostream& os, const word& fieldName)
|
void writeHeader<sphericalTensor>(Ostream& os, const word& fieldName)
|
||||||
{
|
{
|
||||||
os << "# x y z"
|
writeHeaderComponents<sphericalTensor>(os, fieldName);
|
||||||
<< " " << fieldName << "_ii" << nl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void writeHeader<symmTensor>(Ostream& os, const word& fieldName)
|
void writeHeader<symmTensor>(Ostream& os, const word& fieldName)
|
||||||
{
|
{
|
||||||
// This may not be quite right (not sure what people might need)
|
writeHeaderComponents<symmTensor>(os, fieldName);
|
||||||
os << "# xx xy xz yy yz zz";
|
|
||||||
for (direction i=0; i < pTraits<symmTensor>::nComponents; ++i)
|
|
||||||
{
|
|
||||||
os << " " << fieldName << '_' << int(i);
|
|
||||||
}
|
|
||||||
os << nl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void writeHeader<tensor>(Ostream& os, const word& fieldName)
|
void writeHeader<tensor>(Ostream& os, const word& fieldName)
|
||||||
{
|
{
|
||||||
// This may not be quite right (not sure what people might need)
|
writeHeaderComponents<tensor>(os, fieldName);
|
||||||
os << "# xx xy xz yx yy yz zx zy zz";
|
|
||||||
for (direction i=0; i < pTraits<tensor>::nComponents; ++i)
|
|
||||||
{
|
|
||||||
os << " " << fieldName << '_' << int(i);
|
|
||||||
}
|
|
||||||
os << nl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
@ -162,6 +161,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
const auto& values = tfield();
|
const auto& values = tfield();
|
||||||
const pointField& points = surf.points();
|
const pointField& points = surf.points();
|
||||||
const faceList& faces = surf.faces();
|
const faceList& faces = surf.faces();
|
||||||
|
const bool withFaceNormal = (writeNormal_ && !this->isPointData());
|
||||||
|
|
||||||
if (!isDir(outputFile.path()))
|
if (!isDir(outputFile.path()))
|
||||||
{
|
{
|
||||||
@ -169,6 +169,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
OFstream os(outputFile, streamOpt_);
|
OFstream os(outputFile, streamOpt_);
|
||||||
|
os.precision(precision_);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
{
|
{
|
||||||
@ -183,8 +184,13 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
}
|
}
|
||||||
os << values.size() << nl;
|
os << values.size() << nl;
|
||||||
|
|
||||||
// # x y z field
|
writeHeaderXYZ(os);
|
||||||
writeHeader<Type>(os, fieldName);
|
writeHeader<Type>(os, fieldName);
|
||||||
|
if (withFaceNormal)
|
||||||
|
{
|
||||||
|
writeHeaderArea(os);
|
||||||
|
}
|
||||||
|
os << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -195,6 +201,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
{
|
{
|
||||||
writePoint(os, points[elemi]*geometryScale_);
|
writePoint(os, points[elemi]*geometryScale_);
|
||||||
writeData(os, values[elemi]);
|
writeData(os, values[elemi]);
|
||||||
|
os << nl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -202,8 +209,16 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
|
|||||||
// Face values
|
// Face values
|
||||||
forAll(values, elemi)
|
forAll(values, elemi)
|
||||||
{
|
{
|
||||||
writePoint(os, faces[elemi].centre(points)*geometryScale_);
|
const face& f = faces[elemi];
|
||||||
|
|
||||||
|
writePoint(os, f.centre(points)*geometryScale_);
|
||||||
writeData(os, values[elemi]);
|
writeData(os, values[elemi]);
|
||||||
|
if (withFaceNormal)
|
||||||
|
{
|
||||||
|
os << ' ';
|
||||||
|
writePoint(os, f.areaNormal(points)*geometryScale_);
|
||||||
|
}
|
||||||
|
os << nl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ debug
|
|||||||
interpolationScheme cellPoint;
|
interpolationScheme cellPoint;
|
||||||
surfaceFormat ensight;
|
surfaceFormat ensight;
|
||||||
// surfaceFormat vtk;
|
// surfaceFormat vtk;
|
||||||
|
// surfaceFormat raw;
|
||||||
|
|
||||||
formatOptions
|
formatOptions
|
||||||
{
|
{
|
||||||
@ -24,6 +25,11 @@ debug
|
|||||||
collateTimes true;
|
collateTimes true;
|
||||||
// collateTimes false;
|
// collateTimes false;
|
||||||
}
|
}
|
||||||
|
raw
|
||||||
|
{
|
||||||
|
normal true;
|
||||||
|
precision 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_plane
|
_plane
|
||||||
|
|||||||
Reference in New Issue
Block a user