mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Added surfaceReaders from old internal development line
This commit is contained in:
@ -0,0 +1,416 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ensightSurfaceReader.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(ensightSurfaceReader, 0);
|
||||
addToRunTimeSelectionTable(surfaceReader, ensightSurfaceReader, fileName);
|
||||
}
|
||||
|
||||
|
||||
void Foam::ensightSurfaceReader::skip(const label n, IFstream& is) const
|
||||
{
|
||||
label i = 0;
|
||||
token t;
|
||||
while (is.good() && (i < n))
|
||||
{
|
||||
is >> t;
|
||||
i++;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Skipping token " << t << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != n)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Requested to skip " << n << "tokens, but stream exited after "
|
||||
<< i << " tokens. Last token read: " << t
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::ensightSurfaceReader::debugSection
|
||||
(
|
||||
const word& expected,
|
||||
IFstream& is
|
||||
) const
|
||||
{
|
||||
word actual(is);
|
||||
|
||||
if (expected != actual)
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "Expected section header '" << expected
|
||||
<< "' but read the word '" << actual << "'"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::ensightSurfaceReader::readCase(IFstream& is)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction<< endl;
|
||||
}
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFile
|
||||
<< "Cannot read file " << is.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Read the file
|
||||
debugSection("FORMAT", is);
|
||||
skip(3, is); // type: ensight gold
|
||||
|
||||
debugSection("GEOMETRY", is);
|
||||
readSkip(is, 2, meshFileName_);
|
||||
|
||||
debugSection("VARIABLE", is);
|
||||
|
||||
DynamicList<word> fieldNames(10);
|
||||
DynamicList<word> fieldFileNames(10);
|
||||
word fieldName;
|
||||
word fieldFileName;
|
||||
while (is.good())
|
||||
{
|
||||
word primitiveType(is); // scalar, vector
|
||||
|
||||
if (primitiveType == "TIME")
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
readSkip(is, 3, fieldName); // p, U etc
|
||||
fieldNames.append(fieldName);
|
||||
|
||||
is >> fieldFileName; // surfaceName.****.fieldName
|
||||
fieldFileNames.append(fieldFileName);
|
||||
}
|
||||
fieldNames_.transfer(fieldNames);
|
||||
fieldFileNames_.transfer(fieldFileNames);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "fieldNames: " << fieldNames << nl
|
||||
<< "fieldFileNames: " << fieldFileNames << endl;
|
||||
}
|
||||
|
||||
// Start reading time information
|
||||
skip(3, is); // time set: 1
|
||||
readSkip(is, 3, nTimeSteps_);
|
||||
readSkip(is, 3, timeStartIndex_);
|
||||
readSkip(is, 2, timeIncrement_);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "nTimeSteps: " << nTimeSteps_ << nl
|
||||
<< "timeStartIndex: " << timeStartIndex_ << nl
|
||||
<< "timeIncrement: " << timeIncrement_ << endl;
|
||||
}
|
||||
|
||||
// Read the time values
|
||||
skip(2, is); // time values:
|
||||
timeValues_.setSize(nTimeSteps_);
|
||||
for (label i = 0; i < nTimeSteps_; i++)
|
||||
{
|
||||
scalar t(readScalar(is));
|
||||
|
||||
timeValues_[i].value() = t;
|
||||
// TODO: use character representation of t directly instead of
|
||||
// regenerating from scalar value
|
||||
timeValues_[i].name() = Foam::name(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::ensightSurfaceReader::ensightSurfaceReader(const fileName& fName)
|
||||
:
|
||||
surfaceReader(fName),
|
||||
baseDir_(fName.path()),
|
||||
meshFileName_(),
|
||||
fieldNames_(),
|
||||
fieldFileNames_(),
|
||||
nTimeSteps_(0),
|
||||
timeStartIndex_(0),
|
||||
timeIncrement_(1),
|
||||
timeValues_(),
|
||||
surfPtr_(NULL)
|
||||
{
|
||||
IFstream is(fName);
|
||||
readCase(is);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::ensightSurfaceReader::~ensightSurfaceReader()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction<< endl;
|
||||
}
|
||||
|
||||
if (!surfPtr_.valid())
|
||||
{
|
||||
IFstream is(baseDir_/meshFileName_);
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFile
|
||||
<< "Cannot read file " << is.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
token t;
|
||||
while (is.good())
|
||||
{
|
||||
is >> t;
|
||||
|
||||
if (t.isWord())
|
||||
{
|
||||
word wordToken = t.wordToken();
|
||||
if (wordToken == "coordinates")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
label nPoints(readLabel(is));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "nPoints: " << nPoints << endl;
|
||||
}
|
||||
|
||||
pointField points(nPoints);
|
||||
{
|
||||
scalarField x(nPoints);
|
||||
for (label dir = 0; dir < 3; dir++)
|
||||
{
|
||||
forAll(points, pointI)
|
||||
{
|
||||
x[pointI] = readScalar(is);
|
||||
}
|
||||
|
||||
points.replace(dir, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Read faces - may be a mix of tris, quads and polys
|
||||
DynamicList<face> faces(ceil(nPoints/3));
|
||||
|
||||
while (is.good())
|
||||
{
|
||||
token t(is);
|
||||
|
||||
if (is.eof())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
word faceType(t.wordToken());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "faceType: " << faceType << endl;
|
||||
}
|
||||
|
||||
label nFace(readLabel(is));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "nFace: " << nFace << endl;
|
||||
}
|
||||
|
||||
if (faceType == "tria3")
|
||||
{
|
||||
label np = 3;
|
||||
for (label faceI = 0; faceI < nFace; faceI++)
|
||||
{
|
||||
face f(np);
|
||||
for (label fpI = 0; fpI < np; fpI++)
|
||||
{
|
||||
f[fpI] = readLabel(is);
|
||||
}
|
||||
|
||||
faces.append(f);
|
||||
}
|
||||
}
|
||||
else if (faceType == "quad4")
|
||||
{
|
||||
label np = 4;
|
||||
for (label faceI = 0; faceI < nFace; faceI++)
|
||||
{
|
||||
face f(np);
|
||||
for (label fpI = 0; fpI < np; fpI++)
|
||||
{
|
||||
f[fpI] = readLabel(is);
|
||||
}
|
||||
|
||||
faces.append(f);
|
||||
}
|
||||
}
|
||||
else if (faceType == "nsided")
|
||||
{
|
||||
labelList np(nFace);
|
||||
for (label faceI = 0; faceI < nFace; faceI++)
|
||||
{
|
||||
np[faceI] = readLabel(is);
|
||||
}
|
||||
for (label faceI = 0; faceI < nFace; faceI++)
|
||||
{
|
||||
face f(np[faceI]);
|
||||
for (label fpI = 0; fpI < f.size(); fpI++)
|
||||
{
|
||||
f[fpI] = readLabel(is);
|
||||
}
|
||||
|
||||
faces.append(f);
|
||||
}
|
||||
}
|
||||
else if (faceType != "")
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unknown face type: " << faceType
|
||||
<< ". Aborting read and continuing with current elements "
|
||||
<< "only" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "read nFaces: " << faces.size() << endl;
|
||||
}
|
||||
|
||||
forAll(faces, faceI)
|
||||
{
|
||||
face& f = faces[faceI];
|
||||
|
||||
forAll(f, fpI)
|
||||
{
|
||||
f[fpI]--;
|
||||
}
|
||||
}
|
||||
|
||||
surfPtr_.reset(new meshedSurface(xferMove(points), faces.xfer()));
|
||||
}
|
||||
|
||||
return surfPtr_();
|
||||
}
|
||||
|
||||
|
||||
Foam::instantList Foam::ensightSurfaceReader::times() const
|
||||
{
|
||||
return timeValues_;
|
||||
}
|
||||
|
||||
|
||||
Foam::wordList Foam::ensightSurfaceReader::fieldNames
|
||||
(
|
||||
const label timeIndex
|
||||
) const
|
||||
{
|
||||
return fieldNames_;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::Field<Foam::scalar> > Foam::ensightSurfaceReader::field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const scalar& refValue
|
||||
) const
|
||||
{
|
||||
return readField<scalar>(timeIndex, fieldIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::Field<Foam::vector> > Foam::ensightSurfaceReader::field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const vector& refValue
|
||||
) const
|
||||
{
|
||||
return readField<vector>(timeIndex, fieldIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::Field<Foam::sphericalTensor> >
|
||||
Foam::ensightSurfaceReader::field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const sphericalTensor& refValue
|
||||
) const
|
||||
{
|
||||
return readField<sphericalTensor>(timeIndex, fieldIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::Field<Foam::symmTensor> > Foam::ensightSurfaceReader::field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const symmTensor& refValue
|
||||
) const
|
||||
{
|
||||
return readField<symmTensor>(timeIndex, fieldIndex);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::Field<Foam::tensor> > Foam::ensightSurfaceReader::field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const tensor& refValue
|
||||
) const
|
||||
{
|
||||
return readField<tensor>(timeIndex, fieldIndex);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,191 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::ensightensightSurfaceReader
|
||||
|
||||
Description
|
||||
Ensight format surface reader
|
||||
|
||||
SourceFiles
|
||||
ensightSurfaceReader.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef ensightSurfaceReader_H
|
||||
#define ensightSurfaceReader_H
|
||||
|
||||
#include "surfaceReader.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class ensightSurfaceReader Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class ensightSurfaceReader
|
||||
:
|
||||
public surfaceReader
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Base directory
|
||||
fileName baseDir_;
|
||||
|
||||
//- Name of mesh file
|
||||
word meshFileName_;
|
||||
|
||||
//- Field names
|
||||
List<word> fieldNames_;
|
||||
|
||||
//- Field file names
|
||||
List<word> fieldFileNames_;
|
||||
|
||||
//- Number of time steps
|
||||
label nTimeSteps_;
|
||||
|
||||
//- Start time index
|
||||
label timeStartIndex_;
|
||||
|
||||
//- Time increment
|
||||
label timeIncrement_;
|
||||
|
||||
//- Times
|
||||
instantList timeValues_;
|
||||
|
||||
//- Pointer to the surface
|
||||
autoPtr<meshedSurface> surfPtr_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read and check a section header
|
||||
void debugSection(const word& expected, IFstream& is) const;
|
||||
|
||||
//- Read the case file
|
||||
void readCase(IFstream& is);
|
||||
|
||||
//- Helper function to skip forward n steps in stream
|
||||
void skip(const label n, IFstream& is) const;
|
||||
|
||||
//- Helper function to return Type after skipping n tokens
|
||||
template<class Type>
|
||||
void readSkip(IFstream& is, const label nSkip, Type& value) const;
|
||||
|
||||
//- Helper function to return a field
|
||||
template<class Type>
|
||||
tmp<Field<Type> > readField
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("ensight");
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from fileName
|
||||
ensightSurfaceReader(const fileName& fName);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~ensightSurfaceReader();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return a reference to the surface geometry
|
||||
virtual const meshedSurface& geometry();
|
||||
|
||||
//- Return a list of the available times
|
||||
virtual instantList times() const;
|
||||
|
||||
//- Return a list of the available fields at a given time
|
||||
virtual wordList fieldNames(const label timeIndex) const;
|
||||
|
||||
//- Return a scalar field at a given time
|
||||
virtual tmp<Field<scalar> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const scalar& refValue = pTraits<scalar>::zero
|
||||
) const;
|
||||
|
||||
//- Return a scalar field at a given time
|
||||
virtual tmp<Field<vector> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const vector& refValue = pTraits<vector>::zero
|
||||
) const;
|
||||
|
||||
//- Return a sphericalTensor field at a given time
|
||||
virtual tmp<Field<sphericalTensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const sphericalTensor& reValue = pTraits<sphericalTensor>::zero
|
||||
) const;
|
||||
|
||||
//- Return a symmTensor field at a given time
|
||||
virtual tmp<Field<symmTensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const symmTensor& reValue = pTraits<symmTensor>::zero
|
||||
) const;
|
||||
|
||||
//- Return a tensor field at a given time
|
||||
virtual tmp<Field<tensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const tensor& reValue = pTraits<tensor>::zero
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "ensightSurfaceReaderTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,144 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::ensightSurfaceReader::readSkip
|
||||
(
|
||||
IFstream& is,
|
||||
const label nSkip,
|
||||
Type& value
|
||||
) const
|
||||
{
|
||||
skip(nSkip, is);
|
||||
|
||||
is >> value;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type> > Foam::ensightSurfaceReader::readField
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex
|
||||
) const
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
InfoInFunction<< endl;
|
||||
}
|
||||
|
||||
const word& fieldName(fieldNames_[fieldIndex]);
|
||||
const label fileIndex = timeStartIndex_ + timeIndex*timeIncrement_;
|
||||
|
||||
fileName fieldFileName(fieldFileNames_[fieldIndex]);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << std::setfill('0') << std::setw(4) << fileIndex;
|
||||
const word indexStr = oss.str();
|
||||
fieldFileName.replace("****", indexStr);
|
||||
|
||||
IFstream is(baseDir_/fieldFileName);
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Cannot read file " << is.name()
|
||||
<< " for field " << fieldName
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// Check that data type is as expected
|
||||
word primitiveType(is);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "primitiveType: " << primitiveType << endl;
|
||||
}
|
||||
|
||||
if (primitiveType != pTraits<Type>::typeName)
|
||||
{
|
||||
FatalIOErrorInFunction(is)
|
||||
<< "Expected " << pTraits<Type>::typeName << "values "
|
||||
<< "but found type " << primitiveType
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
tmp<Field<Type> > tField(new Field<Type>());
|
||||
|
||||
label n;
|
||||
if (surfPtr_.valid())
|
||||
{
|
||||
n = surfPtr_->size();
|
||||
}
|
||||
else
|
||||
{
|
||||
n = 1000;
|
||||
}
|
||||
|
||||
Type value;
|
||||
word wValue;
|
||||
label iValue;
|
||||
|
||||
// Read header info: part index, e.g. part 1
|
||||
is >> wValue >> 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<Type> values(n);
|
||||
while (is.good())
|
||||
{
|
||||
token t(is);
|
||||
|
||||
if (is.eof())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (t.isWord())
|
||||
{
|
||||
wValue = t.wordToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
is.putBack(t);
|
||||
is >> value;
|
||||
values.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
tField().transfer(values);
|
||||
|
||||
return tField;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
51
src/sampling/sampledSurface/readers/surfaceReader.C
Normal file
51
src/sampling/sampledSurface/readers/surfaceReader.C
Normal file
@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "surfaceReader.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(surfaceReader, 0);
|
||||
defineRunTimeSelectionTable(surfaceReader, fileName);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::surfaceReader::surfaceReader(const fileName& fName)
|
||||
:
|
||||
fileName_(fName)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::surfaceReader::~surfaceReader()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
161
src/sampling/sampledSurface/readers/surfaceReader.H
Normal file
161
src/sampling/sampledSurface/readers/surfaceReader.H
Normal file
@ -0,0 +1,161 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::surfaceReader
|
||||
|
||||
Description
|
||||
Base class for surface readers
|
||||
|
||||
SourceFiles
|
||||
surfaceReader.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef surfaceReader_H
|
||||
#define surfaceReader_H
|
||||
|
||||
#include "typeInfo.H"
|
||||
#include "autoPtr.H"
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surfaceReader Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class surfaceReader
|
||||
{
|
||||
protected:
|
||||
|
||||
//- File name
|
||||
fileName fileName_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("surfaceReader");
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
surfaceReader,
|
||||
fileName,
|
||||
(
|
||||
const fileName& fName
|
||||
),
|
||||
(fName)
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return a reference to the selected surfaceReader
|
||||
static autoPtr<surfaceReader> New
|
||||
(
|
||||
const word& readType,
|
||||
const fileName& fName
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from fileName
|
||||
surfaceReader(const fileName& fName);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~surfaceReader();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return a reference to the surface geometry
|
||||
virtual const meshedSurface& geometry() = 0;
|
||||
|
||||
//- Return a list of the available times
|
||||
virtual instantList times() const = 0;
|
||||
|
||||
//- Return a list of the available fields at a given time
|
||||
virtual wordList fieldNames(const label timeIndex) const = 0;
|
||||
|
||||
//- Return a scalar field at a given time
|
||||
virtual tmp<Field<scalar> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const scalar& refValue = pTraits<scalar>::zero
|
||||
) const = 0;
|
||||
|
||||
//- Return a vector field at a given time
|
||||
virtual tmp<Field<vector> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const vector& refValue = pTraits<vector>::zero
|
||||
) const = 0;
|
||||
|
||||
//- Return a sphericalTensor field at a given time
|
||||
virtual tmp<Field<sphericalTensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const sphericalTensor& reValue = pTraits<sphericalTensor>::zero
|
||||
) const = 0;
|
||||
|
||||
//- Return a symmTensor field at a given time
|
||||
virtual tmp<Field<symmTensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const symmTensor& reValue = pTraits<symmTensor>::zero
|
||||
) const = 0;
|
||||
|
||||
//- Return a tensor field at a given time
|
||||
virtual tmp<Field<tensor> > field
|
||||
(
|
||||
const label timeIndex,
|
||||
const label fieldIndex,
|
||||
const tensor& reValue = pTraits<tensor>::zero
|
||||
) const = 0;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
52
src/sampling/sampledSurface/readers/surfaceReaderNew.C
Normal file
52
src/sampling/sampledSurface/readers/surfaceReaderNew.C
Normal file
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "surfaceReader.H"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::surfaceReader> Foam::surfaceReader::New
|
||||
(
|
||||
const word& readerType,
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
fileNameConstructorTable::iterator cstrIter =
|
||||
fileNameConstructorTablePtr_->find(readerType);
|
||||
|
||||
if (cstrIter == fileNameConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown reader type \"" << readerType << "\"\n\n"
|
||||
<< "Valid reader types: "
|
||||
<< fileNameConstructorTablePtr_->sortedToc() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<surfaceReader>(cstrIter()(fName));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user