mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ensightSurfaceReader updates re: replacing file name masks
This commit is contained in:
@ -104,7 +104,8 @@ void surfaceNoise::initialise(const fileName& fName)
|
|||||||
deltaT_ = checkUniformTimeStep(times_);
|
deltaT_ = checkUniformTimeStep(times_);
|
||||||
|
|
||||||
// Read the surface geometry
|
// Read the surface geometry
|
||||||
const meshedSurface& surf = readerPtr_->geometry();
|
// Note: hard-coded to read mesh from first time index
|
||||||
|
const meshedSurface& surf = readerPtr_->geometry(0);
|
||||||
nFace_ = surf.size();
|
nFace_ = surf.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +209,6 @@ void surfaceNoise::readSurfaceData
|
|||||||
|
|
||||||
Info<< " time: " << times_[i] << endl;
|
Info<< " time: " << times_[i] << endl;
|
||||||
const scalarField p(readerPtr_->field(timeI, pIndex_, scalar(0)));
|
const scalarField p(readerPtr_->field(timeI, pIndex_, scalar(0)));
|
||||||
|
|
||||||
forAll(p, faceI)
|
forAll(p, faceI)
|
||||||
{
|
{
|
||||||
pData[faceI][i] = p[faceI]*rhoRef_;
|
pData[faceI][i] = p[faceI]*rhoRef_;
|
||||||
@ -256,7 +256,8 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
|||||||
scalar areaAverage = 0;
|
scalar areaAverage = 0;
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
{
|
{
|
||||||
const meshedSurface& surf = readerPtr_->geometry();
|
// Note: hard-coded to read mesh from first time index
|
||||||
|
const meshedSurface& surf = readerPtr_->geometry(0);
|
||||||
|
|
||||||
scalarField allData(surf.size());
|
scalarField allData(surf.size());
|
||||||
|
|
||||||
@ -298,7 +299,7 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
|||||||
|
|
||||||
// TO BE VERIFIED: area-averaged values
|
// TO BE VERIFIED: area-averaged values
|
||||||
// areaAverage = sum(allData*surf.magSf())/sum(surf.magSf());
|
// areaAverage = sum(allData*surf.magSf())/sum(surf.magSf());
|
||||||
areaAverage = sum(allData)/allData.size();
|
areaAverage = sum(allData)/(allData.size() + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
Pstream::scatter(areaAverage);
|
Pstream::scatter(areaAverage);
|
||||||
|
|
||||||
@ -306,7 +307,8 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const meshedSurface& surf = readerPtr_->geometry();
|
// Note: hard-coded to read mesh from first time index
|
||||||
|
const meshedSurface& surf = readerPtr_->geometry(0);
|
||||||
|
|
||||||
if (writeSurface)
|
if (writeSurface)
|
||||||
{
|
{
|
||||||
@ -329,7 +331,7 @@ Foam::scalar surfaceNoise::writeSurfaceData
|
|||||||
|
|
||||||
// TO BE VERIFIED: area-averaged values
|
// TO BE VERIFIED: area-averaged values
|
||||||
// return sum(data*surf.magSf())/sum(surf.magSf());
|
// return sum(data*surf.magSf())/sum(surf.magSf());
|
||||||
return sum(data)/data.size();
|
return sum(data)/(data.size() + ROOTVSMALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +359,8 @@ Foam::scalar surfaceNoise::surfaceAverage
|
|||||||
scalar areaAverage = 0;
|
scalar areaAverage = 0;
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
{
|
{
|
||||||
const meshedSurface& surf = readerPtr_->geometry();
|
// Note: hard-coded to read mesh from first time index
|
||||||
|
const meshedSurface& surf = readerPtr_->geometry(0);
|
||||||
|
|
||||||
scalarField allData(surf.size());
|
scalarField allData(surf.size());
|
||||||
|
|
||||||
|
|||||||
@ -123,6 +123,25 @@ void Foam::ensightSurfaceReader::debugSection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::ensightSurfaceReader::replaceMask
|
||||||
|
(
|
||||||
|
const fileName& fName,
|
||||||
|
const label timeIndex
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
fileName result(fName);
|
||||||
|
std::ostringstream oss;
|
||||||
|
|
||||||
|
label nMask = stringOps::count(fName, '*');
|
||||||
|
const std::string maskStr(nMask, '*');
|
||||||
|
oss << std::setfill('0') << std::setw(nMask) << timeIndex;
|
||||||
|
const word indexStr = oss.str();
|
||||||
|
result.replace(maskStr, indexStr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Pair<Foam::ensightSurfaceReader::idTypes>
|
Foam::Pair<Foam::ensightSurfaceReader::idTypes>
|
||||||
Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
|
Foam::ensightSurfaceReader::readGeometryHeader(ensightReadFile& is) const
|
||||||
{
|
{
|
||||||
@ -230,6 +249,8 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
|
|||||||
// - use the last entry
|
// - use the last entry
|
||||||
meshFileName_ = stringOps::splitSpace(buffer).last().str();
|
meshFileName_ = stringOps::splitSpace(buffer).last().str();
|
||||||
|
|
||||||
|
DebugInfo << "mesh file:" << meshFileName_ << endl;
|
||||||
|
|
||||||
debugSection("VARIABLE", is);
|
debugSection("VARIABLE", is);
|
||||||
|
|
||||||
// Read the field description
|
// Read the field description
|
||||||
@ -330,13 +351,17 @@ Foam::ensightSurfaceReader::ensightSurfaceReader(const fileName& fName)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
|
const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry
|
||||||
|
(
|
||||||
|
const label timeIndex
|
||||||
|
)
|
||||||
{
|
{
|
||||||
DebugInFunction << endl;
|
DebugInFunction << endl;
|
||||||
|
|
||||||
if (!surfPtr_.valid())
|
if (!surfPtr_.valid())
|
||||||
{
|
{
|
||||||
IFstream isBinary(baseDir_/meshFileName_, IOstream::BINARY);
|
fileName meshInstance(replaceMask(meshFileName_, timeIndex));
|
||||||
|
IFstream isBinary(baseDir_/meshInstance, IOstream::BINARY);
|
||||||
|
|
||||||
if (!isBinary.good())
|
if (!isBinary.good())
|
||||||
{
|
{
|
||||||
@ -391,7 +416,7 @@ const Foam::meshedSurface& Foam::ensightSurfaceReader::geometry()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ensightReadFile is(baseDir_/meshFileName_, streamFormat_);
|
ensightReadFile is(baseDir_/meshInstance, streamFormat_);
|
||||||
|
|
||||||
DebugInfo
|
DebugInfo
|
||||||
<< "File: " << is.name() << nl;
|
<< "File: " << is.name() << nl;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
Copyright (C) 2015-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -112,6 +112,13 @@ protected:
|
|||||||
//- Read and check a section header
|
//- Read and check a section header
|
||||||
void debugSection(const word& expected, IFstream& is) const;
|
void debugSection(const word& expected, IFstream& is) const;
|
||||||
|
|
||||||
|
//- Replace the mask with an 0 padded string
|
||||||
|
fileName replaceMask
|
||||||
|
(
|
||||||
|
const fileName& fName,
|
||||||
|
const label timeIndex
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Read (and discard) geometry file header.
|
//- Read (and discard) geometry file header.
|
||||||
// \return information about node/element id handling
|
// \return information about node/element id handling
|
||||||
Pair<idTypes> readGeometryHeader(ensightReadFile& is) const;
|
Pair<idTypes> readGeometryHeader(ensightReadFile& is) const;
|
||||||
@ -164,7 +171,7 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return a reference to the surface geometry
|
//- Return a reference to the surface geometry
|
||||||
virtual const meshedSurface& geometry();
|
virtual const meshedSurface& geometry(const label timeIndex);
|
||||||
|
|
||||||
//- Return a list of the available times
|
//- Return a list of the available times
|
||||||
virtual instantList times() const;
|
virtual instantList times() const;
|
||||||
|
|||||||
@ -70,24 +70,7 @@ Foam::tmp<Foam::Field<Type>> Foam::ensightSurfaceReader::readField
|
|||||||
const word& fieldName(fieldNames_[fieldIndex]);
|
const word& fieldName(fieldNames_[fieldIndex]);
|
||||||
const label fileIndex = timeStartIndex_ + timeIndex*timeIncrement_;
|
const label fileIndex = timeStartIndex_ + timeIndex*timeIncrement_;
|
||||||
|
|
||||||
fileName fieldFileName(fieldFileNames_[fieldIndex]);
|
fileName fieldFileName(replaceMask(fieldFileNames_[fieldIndex], fileIndex));
|
||||||
|
|
||||||
std::ostringstream oss;
|
|
||||||
label nMask = 0;
|
|
||||||
for (size_t chari = 0; chari < fieldFileName.size(); ++chari)
|
|
||||||
{
|
|
||||||
if (fieldFileName[chari] == '*')
|
|
||||||
{
|
|
||||||
nMask++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string maskStr(nMask, '*');
|
|
||||||
oss << std::setfill('0') << std::setw(nMask) << fileIndex;
|
|
||||||
const word indexStr = oss.str();
|
|
||||||
fieldFileName.replace(maskStr, indexStr);
|
|
||||||
|
|
||||||
|
|
||||||
ensightReadFile is(baseDir_/fieldFileName, streamFormat_);
|
ensightReadFile is(baseDir_/fieldFileName, streamFormat_);
|
||||||
|
|
||||||
if (!is.good())
|
if (!is.good())
|
||||||
|
|||||||
@ -101,7 +101,7 @@ public:
|
|||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- Return a reference to the surface geometry
|
//- Return a reference to the surface geometry
|
||||||
virtual const meshedSurface& geometry() = 0;
|
virtual const meshedSurface& geometry(const label timeIndex) = 0;
|
||||||
|
|
||||||
//- Return a list of the available times
|
//- Return a list of the available times
|
||||||
virtual instantList times() const = 0;
|
virtual instantList times() const = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user