diff --git a/applications/utilities/postProcessing/noise/Allwmake b/applications/utilities/postProcessing/noise/Allwmake
new file mode 100755
index 0000000000..84c6a2ac82
--- /dev/null
+++ b/applications/utilities/postProcessing/noise/Allwmake
@@ -0,0 +1,14 @@
+#!/bin/sh
+cd ${0%/*} || exit 1 # run from this directory
+
+if [ -f "$FFTW_ARCH_PATH/include/fftw3.h" ] || \
+ [ "${FFTW_ARCH_PATH##*-}" = system -a -f "/usr/include/fftw3.h" ]
+then
+ wmake
+else
+ echo
+ echo "Skipping noise utility (no FFTW)"
+ echo
+fi
+
+#------------------------------------------------------------------------------
diff --git a/src/conversion/Make/files b/src/conversion/Make/files
index 7c5a0aa91c..b4a38476a1 100644
--- a/src/conversion/Make/files
+++ b/src/conversion/Make/files
@@ -1,5 +1,6 @@
ensight/file/ensightFile.C
ensight/file/ensightGeoFile.C
+ensight/readFile/ensightReadFile.C
ensight/part/ensightPart.C
ensight/part/ensightPartIO.C
ensight/part/ensightPartCells.C
diff --git a/src/conversion/ensight/readFile/ensightReadFile.C b/src/conversion/ensight/readFile/ensightReadFile.C
new file mode 100644
index 0000000000..f73d95199e
--- /dev/null
+++ b/src/conversion/ensight/readFile/ensightReadFile.C
@@ -0,0 +1,157 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+\*---------------------------------------------------------------------------*/
+
+#include "ensightReadFile.H"
+#include
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+Foam::ensightReadFile::ensightReadFile
+(
+ const fileName& pathname,
+ IOstream::streamFormat format
+)
+:
+ IFstream(pathname, format)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
+
+Foam::ensightReadFile::~ensightReadFile()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+Foam::Istream& Foam::ensightReadFile::read
+(
+ char* buf,
+ std::streamsize count
+)
+{
+ stdStream().read(buf, count);
+ return *this;
+}
+
+
+Foam::Istream& Foam::ensightReadFile::read(string& value)
+{
+ if (format() == IOstream::BINARY)
+ {
+ char buf[80];
+
+ read(reinterpret_cast(buf), sizeof(buf));
+
+ string strBuf(value);
+
+ const size_t iEnd = strBuf.find('\0', 0);
+ if (iEnd == string::npos)
+ {
+ value = buf;
+ }
+ else
+ {
+ value = strBuf.substr(0, iEnd - 1);
+ }
+ }
+ else
+ {
+ value = "";
+ while (value.empty() && !eof())
+ {
+ getLine(value);
+ }
+ }
+
+ return *this;
+}
+
+
+Foam::Istream& Foam::ensightReadFile::read(label& value)
+{
+ int ivalue;
+
+ if (format() == IOstream::BINARY)
+ {
+ read
+ (
+ reinterpret_cast(&ivalue),
+ sizeof(ivalue)
+ );
+ }
+ else
+ {
+ stdStream() >> ivalue;
+ }
+
+ value = ivalue;
+ return *this;
+}
+
+
+Foam::Istream& Foam::ensightReadFile::read(scalar& value)
+{
+ float fvalue;
+
+ if (format() == IOstream::BINARY)
+ {
+ read
+ (
+ reinterpret_cast(&fvalue),
+ sizeof(fvalue)
+ );
+
+ value = fvalue;
+ }
+ else
+ {
+ stdStream() >> value;
+ }
+
+ return *this;
+}
+
+
+Foam::Istream& Foam::ensightReadFile::readKeyword(string& key)
+{
+ read(key);
+ return *this;
+}
+
+
+Foam::Istream& Foam::ensightReadFile::readBinaryHeader()
+{
+ if (format() == IOstream::BINARY)
+ {
+ string buffer;
+ read(buffer);
+ }
+
+ return *this;
+}
+
+
+// ************************************************************************* //
diff --git a/src/conversion/ensight/readFile/ensightReadFile.H b/src/conversion/ensight/readFile/ensightReadFile.H
new file mode 100644
index 0000000000..aa6723352b
--- /dev/null
+++ b/src/conversion/ensight/readFile/ensightReadFile.H
@@ -0,0 +1,110 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+Class
+ Foam::ensightReadFile
+
+Description
+ Ensight output with specialized read() for strings, integers and floats.
+ Correctly handles binary read as well.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef ensightReadFile_H
+#define ensightReadFile_H
+
+#include "IFstream.H"
+#include "IOstream.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+ Class ensightReadFile Declaration
+\*---------------------------------------------------------------------------*/
+
+class ensightReadFile
+:
+ public IFstream
+{
+ // Private Member Functions
+
+ //- Disallow default bitwise assignment
+ void operator=(const ensightReadFile&);
+
+ //- Disallow default copy constructor
+ ensightReadFile(const ensightReadFile&);
+
+
+public:
+
+ // Constructors
+
+ //- Construct from pathname
+ ensightReadFile
+ (
+ const fileName& pathname,
+ IOstream::streamFormat format=IOstream::BINARY
+ );
+
+
+ //- Destructor
+ ~ensightReadFile();
+
+
+ // Output
+
+ //- Inherit read from Istream
+ using Istream::read;
+
+ //- Binary read
+ virtual Istream& read(char* buf, std::streamsize count);
+
+ //- Read string as "%80s" or as binary
+ Istream& read(string& value);
+
+ //- Read integer as "%10d" or as binary
+ Istream& read(label& value);
+
+ //- Read float as "%12.5e" or as binary
+ Istream& read(scalar& value);
+
+ //- Read element keyword
+ virtual Istream& readKeyword(string& key);
+
+ //- Read "C Binary" for binary files (eg, geometry/measured)
+ Istream& readBinaryHeader();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
index 6d17bb5aa0..3e1b422bde 100644
--- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
+++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
@@ -59,6 +59,48 @@ void Foam::ensightSurfaceReader::skip(const label n, IFstream& is) const
}
+void Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
+{
+ // Binary flag string if applicable
+ is.readBinaryHeader();
+
+ string buffer;
+
+ // Ensight Geometry File
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Description - 1
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Node info
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Element info
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Part
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Part number
+ label ibuffer;
+ is.read(ibuffer);
+ if (debug) Info<< "ibuffer: " << ibuffer << endl;
+
+ // Description - 2
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+
+ // Co-ordinates
+ is.read(buffer);
+ if (debug) Info<< "buffer: " << buffer << endl;
+}
+
+
void Foam::ensightSurfaceReader::debugSection
(
const word& expected,
@@ -74,6 +116,11 @@ void Foam::ensightSurfaceReader::debugSection
<< "' but read the word '" << actual << "'"
<< exit(FatalIOError);
}
+
+ if (debug)
+ {
+ Info<< "Read section header: " << expected << endl;
+ }
}
@@ -91,6 +138,8 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
<< exit(FatalError);
}
+ string buffer;
+
// Read the file
debugSection("FORMAT", is);
skip(3, is); // type: ensight gold
@@ -124,8 +173,8 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
if (debug)
{
- Info<< "fieldNames: " << fieldNames << nl
- << "fieldFileNames: " << fieldFileNames << endl;
+ Info<< "fieldNames: " << fieldNames_ << nl
+ << "fieldFileNames: " << fieldFileNames_ << endl;
}
// Start reading time information
@@ -142,7 +191,7 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
}
// Read the time values
- skip(2, is); // time values:
+ skip(2, is);
timeValues_.setSize(nTimeSteps_);
for (label i = 0; i < nTimeSteps_; i++)
{
@@ -161,6 +210,7 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
Foam::ensightSurfaceReader::ensightSurfaceReader(const fileName& fName)
:
surfaceReader(fName),
+ streamFormat_(IOstream::ASCII),
baseDir_(fName.path()),
meshFileName_(),
fieldNames_(),
@@ -193,31 +243,71 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
if (!surfPtr_.valid())
{
- IFstream is(baseDir_/meshFileName_);
+ IFstream isBinary(baseDir_/meshFileName_, IOstream::BINARY);
- if (!is.good())
+ if (!isBinary.good())
{
FatalErrorInFunction
- << "Cannot read file " << is.name()
+ << "Cannot read file " << isBinary.name()
<< exit(FatalError);
}
- token t;
- while (is.good())
+ streamFormat_ = IOstream::BINARY;
{
- is >> t;
+ istream& is = isBinary.stdStream();
- if (t.isWord())
+ char buffer[80];
+ is.read(buffer, 80);
+
+ char test[80];
+ label nChar = 0;
+ for (label i = 0; i < 80; ++i)
{
- word wordToken = t.wordToken();
- if (wordToken == "coordinates")
+ if (buffer[i] == '\0')
{
break;
}
+ test[i] = buffer[i];
+ nChar++;
+ }
+
+ string testStr(test, nChar);
+
+ if
+ (
+ (testStr.find("binary", 0) == string::npos)
+ && (testStr.find("Binary", 0) == string::npos)
+ )
+ {
+ streamFormat_ = IOstream::ASCII;
}
}
- label nPoints(readLabel(is));
+ if (debug)
+ {
+ Info<< "stream format: ";
+ if (streamFormat_ == IOstream::ASCII)
+ {
+ Info<< "ascii" << endl;
+ }
+ else
+ {
+ Info<< "binary" << endl;
+ }
+ }
+
+
+ ensightReadFile is(baseDir_/meshFileName_, streamFormat_);
+
+ if (debug)
+ {
+ Info<< "File: " << is.name() << endl;
+ }
+
+ readGeometryHeader(is);
+
+ label nPoints;
+ is.read(nPoints);
if (debug)
{
@@ -231,7 +321,7 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
{
forAll(points, pointI)
{
- x[pointI] = readScalar(is);
+ is.read(x[pointI]);
}
points.replace(dir, x);
@@ -241,39 +331,34 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
// Read faces - may be a mix of tris, quads and polys
DynamicList faces(ceil(nPoints/3));
-
- while (is.good())
+ DynamicList > schema(faces.size());
+ string faceType = "";
+ label nFace = 0;
+ while (is.good()) // (is.peek() != EOF)
{
- token t(is);
+ is.read(faceType);
- if (is.eof())
+ if (!is.good())
{
break;
}
- word faceType(t.wordToken());
-
if (debug)
{
Info<< "faceType: " << faceType << endl;
}
- label nFace(readLabel(is));
-
- if (debug)
- {
- Info<< "nFace: " << nFace << endl;
- }
-
if (faceType == "tria3")
{
+ is.read(nFace);
+
label np = 3;
- for (label faceI = 0; faceI < nFace; faceI++)
+ for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
for (label fpI = 0; fpI < np; fpI++)
{
- f[fpI] = readLabel(is);
+ is.read(f[fpI]);
}
faces.append(f);
@@ -281,13 +366,15 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
}
else if (faceType == "quad4")
{
+ is.read(nFace);
+
label np = 4;
- for (label faceI = 0; faceI < nFace; faceI++)
+ for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np);
for (label fpI = 0; fpI < np; fpI++)
{
- f[fpI] = readLabel(is);
+ is.read(f[fpI]);
}
faces.append(f);
@@ -295,36 +382,48 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
}
else if (faceType == "nsided")
{
+ is.read(nFace);
+
labelList np(nFace);
- for (label faceI = 0; faceI < nFace; faceI++)
+ for (label faceI = 0; faceI < nFace; ++faceI)
{
- np[faceI] = readLabel(is);
+ is.read(np[faceI]);
}
- for (label faceI = 0; faceI < nFace; faceI++)
+ for (label faceI = 0; faceI < nFace; ++faceI)
{
face f(np[faceI]);
- for (label fpI = 0; fpI < f.size(); fpI++)
+ for (label fpI = 0; fpI < f.size(); ++fpI)
{
- f[fpI] = readLabel(is);
+ is.read(f[fpI]);
}
faces.append(f);
}
}
- else if (faceType != "")
+ else
{
- WarningInFunction
- << "Unknown face type: " << faceType
- << ". Aborting read and continuing with current elements "
- << "only" << endl;
+ if (debug)
+ {
+ WarningInFunction
+ << "Unknown face type: " << faceType
+ << ". Aborting read and continuing with current "
+ << "elements only" << endl;
+ }
+
+ break;
}
+ schema.append(Tuple2(faceType, nFace));
}
+ schema_.transfer(schema);
+
if (debug)
{
- Info<< "read nFaces: " << faces.size() << endl;
+ Info<< "read nFaces: " << faces.size() << nl
+ << "file schema: " << schema_ << endl;
}
+ // Convert from 1-based Ensight addressing to 0-based OF addressing
forAll(faces, faceI)
{
face& f = faces[faceI];
diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H
index e0b9afd453..8c99cfd466 100644
--- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H
+++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -36,6 +36,8 @@ SourceFiles
#define ensightSurfaceReader_H
#include "surfaceReader.H"
+#include "ensightReadFile.H"
+#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -54,6 +56,9 @@ protected:
// Protected Data
+ //- Format flag
+ IOstream::streamFormat streamFormat_;
+
//- Base directory
fileName baseDir_;
@@ -81,6 +86,8 @@ protected:
//- Pointer to the surface
autoPtr surfPtr_;
+ List > schema_;
+
// Protected Member Functions
@@ -93,6 +100,9 @@ protected:
//- Helper function to skip forward n steps in stream
void skip(const label n, IFstream& is) const;
+ //- Read (and throw away) geometry file header
+ void readGeometryHeader(ensightReadFile& is) const;
+
//- Helper function to return Type after skipping n tokens
template
void readSkip(IFstream& is, const label nSkip, Type& value) const;
diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C
index edb89955a5..04a593575a 100644
--- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C
+++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C
@@ -64,7 +64,8 @@ Foam::tmp > Foam::ensightSurfaceReader::readField
const word indexStr = oss.str();
fieldFileName.replace("****", indexStr);
- IFstream is(baseDir_/fieldFileName);
+
+ ensightReadFile is(baseDir_/fieldFileName, streamFormat_);
if (!is.good())
{
@@ -75,7 +76,9 @@ Foam::tmp > Foam::ensightSurfaceReader::readField
}
// Check that data type is as expected
- word primitiveType(is);
+ string primitiveType;
+ is.read(primitiveType);
+
if (debug)
{
@@ -90,52 +93,66 @@ Foam::tmp > Foam::ensightSurfaceReader::readField
<< exit(FatalIOError);
}
- tmp > tField(new Field());
-
- label n;
- if (surfPtr_.valid())
- {
- n = surfPtr_->size();
- }
- else
- {
- n = 1000;
- }
-
- Type value;
- word wValue;
+ scalar value;
+ string strValue;
label iValue;
// Read header info: part index, e.g. part 1
- is >> wValue >> iValue;
+ is.read(strValue);
+ is.read(iValue);
- // Read data file
- // - Assume that file contains a mix of words and numbers, and that all
- // numbers relate to face values, e.g. header comprises of words and
- // element types are also words, e.g. tria3, quad4, nsided
- DynamicList values(n);
- while (is.good())
+ // Allocate storage for data as a list per component
+ List > values(pTraits::nComponents);
+ label n = surfPtr_->size();
+ forAll(values, cmptI)
{
- token t(is);
+ values.setSize(n);
+ }
- if (is.eof())
+ // Read data file using schema generated while reading the surface
+ forAll(schema_, i)
+ {
+ if (debug)
{
- break;
+ const string& faceType = schema_[i].first();
+ Info<< "Reading face type " << faceType << " data" << endl;
}
- if (t.isWord())
+ const label nFace = schema_[i].second();
+
+ if (nFace != 0)
{
- wValue = t.wordToken();
- }
- else
- {
- is.putBack(t);
- is >> value;
- values.append(value);
+ is.read(strValue);
+
+ for
+ (
+ direction cmptI=0;
+ cmptI < pTraits::nComponents;
+ ++cmptI
+ )
+ {
+ for (label faceI = 0; faceI < nFace; ++faceI)
+ {
+ is.read(value);
+ values[cmptI].append(value);
+ }
+ }
}
}
- tField().transfer(values);
+ tmp > tField(new Field(n, pTraits::zero));
+ Field& field = tField.ref();
+
+ for
+ (
+ direction cmptI=0;
+ cmptI < pTraits::nComponents;
+ ++cmptI
+ )
+ {
+ field.replace(cmptI, values[cmptI]);
+ values[cmptI].clear();
+ }
return tField;
}