INT: Integration of Mattijs' collocated parallel IO additions

Original commit message:
------------------------

Parallel IO: New collated file format

When an OpenFOAM simulation runs in parallel, the data for decomposed fields and
mesh(es) has historically been stored in multiple files within separate
directories for each processor.  Processor directories are named 'processorN',
where N is the processor number.

This commit introduces an alternative "collated" file format where the data for
each decomposed field (and mesh) is collated into a single file, which is
written and read on the master processor.  The files are stored in a single
directory named 'processors'.

The new format produces significantly fewer files - one per field, instead of N
per field.  For large parallel cases, this avoids the restriction on the number
of open files imposed by the operating system limits.

The file writing can be threaded allowing the simulation to continue running
while the data is being written to file.  NFS (Network File System) is not
needed when using the the collated format and additionally, there is an option
to run without NFS with the original uncollated approach, known as
"masterUncollated".

The controls for the file handling are in the OptimisationSwitches of
etc/controlDict:

OptimisationSwitches
{
    ...

    //- Parallel IO file handler
    //  uncollated (default), collated or masterUncollated
    fileHandler uncollated;

    //- collated: thread buffer size for queued file writes.
    //  If set to 0 or not sufficient for the file size threading is not used.
    //  Default: 2e9
    maxThreadFileBufferSize 2e9;

    //- masterUncollated: non-blocking buffer size.
    //  If the file exceeds this buffer size scheduled transfer is used.
    //  Default: 2e9
    maxMasterFileBufferSize 2e9;
}

When using the collated file handling, memory is allocated for the data in the
thread.  maxThreadFileBufferSize sets the maximum size of memory in bytes that
is allocated.  If the data exceeds this size, the write does not use threading.

When using the masterUncollated file handling, non-blocking MPI communication
requires a sufficiently large memory buffer on the master node.
maxMasterFileBufferSize sets the maximum size in bytes of the buffer.  If the
data exceeds this size, the system uses scheduled communication.

The installation defaults for the fileHandler choice, maxThreadFileBufferSize
and maxMasterFileBufferSize (set in etc/controlDict) can be over-ridden within
the case controlDict file, like other parameters.  Additionally the fileHandler
can be set by:
- the "-fileHandler" command line argument;
- a FOAM_FILEHANDLER environment variable.

A foamFormatConvert utility allows users to convert files between the collated
and uncollated formats, e.g.
    mpirun -np 2 foamFormatConvert -parallel -fileHandler uncollated

An example case demonstrating the file handling methods is provided in:
$FOAM_TUTORIALS/IO/fileHandling

The work was undertaken by Mattijs Janssens, in collaboration with Henry Weller.
This commit is contained in:
Andrew Heather
2017-07-07 11:39:56 +01:00
parent 03c114010f
commit d8d6030ab6
221 changed files with 11118 additions and 1946 deletions

View File

@ -11,7 +11,7 @@ IOobject turbulencePropertiesHeader
false
);
if (turbulencePropertiesHeader.typeHeaderOk<IOdictionary>(false))
if (turbulencePropertiesHeader.typeHeaderOk<IOdictionary>(true))
{
autoPtr<compressible::turbulenceModel> turbulence
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -87,7 +87,8 @@ int main(int argc, char *argv[])
(
format,
IOstream::currentVersion,
IOstream::UNCOMPRESSED
IOstream::UNCOMPRESSED,
true
);
Info<< "Written old format faceList in = "
@ -149,7 +150,8 @@ int main(int argc, char *argv[])
(
format,
IOstream::currentVersion,
IOstream::UNCOMPRESSED
IOstream::UNCOMPRESSED,
true
);
Info<< "Written new format faceList in = "

View File

@ -0,0 +1,3 @@
Test-IOField.C
EXE = $(FOAM_USER_APPBIN)/Test-IOField

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */

View File

@ -0,0 +1,189 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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/>.
Application
Test-IOField
Description
Test the processor-local reading of IOField (used in the lagrangian libs)
\*---------------------------------------------------------------------------*/
#include "IOField.H"
#include "argList.H"
#include "polyMesh.H"
#include "Time.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void write(const IOobject& io, const label sz)
{
IOField<label> fld(io, sz);
forAll(fld, i)
{
fld[i] = i+1000;
}
Pout<< "writing:" << fld << endl;
fld.write(sz > 0);
}
void read(const IOobject& io, const label sz)
{
bool valid = (sz > 0);
Pout<< " valid:" << valid << endl;
IOField<label> fld(io, valid);
Pout<< " wanted:" << sz << " actually read:" << fld.size() << endl;
if (fld.size() != sz)
{
FatalErrorInFunction<< "io:" << io.objectPath() << exit(FatalError);
}
}
void writeAndRead
(
const IOobject& io,
const label sz,
const word& writeType,
const IOobject::readOption readOpt,
const word& readType
)
{
Pout<< "** Writing:" << writeType
<< " Reading:" << readType << endl;
autoPtr<fileOperation> writeHandler(fileOperation::New(writeType));
fileHandler(writeHandler);
// Delete
Pout<< "Deleting:" << fileHandler().filePath(io.objectPath()) << endl;
fileHandler().rm(fileHandler().filePath(io.objectPath()));
// Write
Pout<< "Writing:" << fileHandler().objectPath(io) << endl;
write(io, sz);
autoPtr<fileOperation> readHandler(fileOperation::New(readType));
fileHandler(readHandler);
// Read
IOobject readIO(io);
readIO.readOpt() = readOpt;
Pout<< "Reading:" << fileHandler().filePath(readIO.objectPath()) << endl;
read(readIO, sz);
Pout<< "** Done writing:" << writeType
<< " Reading:" << readType << endl << endl << endl;
}
void readIfPresent
(
IOobject& io,
const label sz,
const word& readType
)
{
autoPtr<fileOperation> readHandler(fileOperation::New(readType));
fileHandler(readHandler);
// Read
Pout<< "Reading:" << fileHandler().filePath(io.objectPath()) << endl;
io.readOpt() = IOobject::READ_IF_PRESENT;
read(io, sz);
}
// Main program:
int main(int argc, char *argv[])
{
#include "addTimeOptions.H"
#include "setRootCase.H"
#include "createTime.H"
#include "createPolyMesh.H"
label sz = 0;
if (Pstream::myProcNo() % 2)
{
sz = 1;
}
IOobject io
(
"bla",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
);
wordList handlers
(
Foam::fileOperation::wordConstructorTablePtr_->sortedToc()
);
Info<< "Found handlers:" << handlers << endl;
/*
forAll(handlers, readi)
{
const word& readHandler = handlers[readi];
readIfPresent(io, sz, readHandler);
}
*/
forAll(handlers, writei)
{
const word& writeHandler = handlers[writei];
forAll(handlers, readi)
{
const word& readHandler = handlers[readi];
writeAndRead
(
io,
sz,
writeHandler,
IOobject::READ_IF_PRESENT,
readHandler
);
}
}
Pout<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
Test-decomposedBlockData.C
EXE = $(FOAM_USER_APPBIN)/Test-decomposedBlockData

View File

@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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/>.
Application
Test-decomposedBlockData
Description
Convert decomposedBlockData into its components.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "decomposedBlockData.H"
#include "OFstream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::validArgs.append("file");
#include "setRootCase.H"
if (!Pstream::parRun())
{
FatalErrorInFunction
<< "Run in parallel" << exit(FatalError);
}
#include "createTime.H"
const fileName file(args[1]);
Info<< "Reading " << file << nl << endl;
decomposedBlockData data
(
Pstream::worldComm,
IOobject
(
file,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
data.rename(data.name() + "Data");
fileName objPath(data.objectPath());
mkDir(objPath.path());
Info<< "Opening output file " << objPath << nl << endl;
OFstream os
(
objPath,
IOstream::BINARY,
IOstream::currentVersion,
runTime.writeCompression()
);
if (!os.good())
{
FatalErrorInFunction
<< "Failed opening " << objPath << exit(FatalError);
}
if (!data.writeData(os))
{
FatalErrorInFunction
<< "Failed writing " << objPath << exit(FatalError);
}
return 0;
}
// ************************************************************************* //

View File

@ -498,7 +498,9 @@ int main(int argc, char *argv[])
Info<< "surfIn = " << surfIn.size() << endl;
Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
surfIn.write("oldSurfIn.obj");
using Foam::surfMesh;
surfIn.write(fileName("oldSurfIn.obj"));
Info<< "runTime.instance() = " << runTime.instance() << endl;
@ -550,7 +552,7 @@ int main(int argc, char *argv[])
surfOut.write();
// write directly
surfOut.write("someName.ofs");
surfOut.surfMesh::write(fileName("someName.ofs"));
#if 1
const surfZoneList& zones = surfOut.surfZones();

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -64,6 +64,7 @@ Description
#include "globalIndex.H"
#include "topoSet.H"
#include "processorMeshes.H"
#include "IOdictionary.H"
using namespace Foam;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,6 +28,7 @@ License
#include "polyMesh.H"
#include "Ostream.H"
#include "twoDPointCorrector.H"
#include "IOdictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -143,10 +144,8 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
const edgeList& edges = mesh_.edges();
forAll(edges, edgeI)
forAll(const edge& e : edges)
{
const edge& e = edges[edgeI];
vector eVec(e.vec(mesh_.points()));
scalar eMag = mag(eVec);
@ -209,13 +208,5 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -57,6 +57,7 @@ See also
#include "Time.H"
#include "polyMesh.H"
#include "STARCDMeshWriter.H"
#include "IOdictionary.H"
using namespace Foam;
@ -134,4 +135,5 @@ int main(int argc, char *argv[])
return 0;
}
// ************************************************************************* //

View File

@ -47,7 +47,7 @@ Usage
#include "timeSelector.H"
#include "Time.H"
#include "polyMesh.H"
#include "IOdictionary.H"
#include "MeshedSurfaces.H"
using namespace Foam;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -387,7 +387,7 @@ Foam::DelaunayMesh<Triangulation>::createMesh
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
Triangulation::number_of_vertices()
label(Triangulation::number_of_vertices())
);
labelIOField processorIndices
@ -401,7 +401,7 @@ Foam::DelaunayMesh<Triangulation>::createMesh
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
Triangulation::number_of_vertices()
label(Triangulation::number_of_vertices())
);
for

View File

@ -531,6 +531,7 @@ void extractSurface
? runTime.path()/".."/outFileName
: runTime.path()/outFileName
);
globalCasePath.clean();
Info<< "Writing merged surface to " << globalCasePath << endl;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -67,6 +67,7 @@ Usage
#include "globalMeshData.H"
#include "surfaceWriter.H"
#include "vtkSetWriter.H"
#include "IOdictionary.H"
#include "checkTools.H"
#include "checkTopology.H"

View File

@ -281,7 +281,7 @@ void Foam::mergeAndWrite
mesh.points()
);
const fileName outputDir
fileName outputDir
(
set.time().path()
/ (Pstream::parRun() ? ".." : "")
@ -289,6 +289,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
/ set.name()
);
outputDir.clean();
mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
}
@ -374,7 +375,7 @@ void Foam::mergeAndWrite
mesh.points()
);
const fileName outputDir
fileName outputDir
(
set.time().path()
/ (Pstream::parRun() ? ".." : "")
@ -382,6 +383,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
/ set.name()
);
outputDir.clean();
mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
}
@ -477,7 +479,7 @@ void Foam::mergeAndWrite
// Output e.g. pointSet p0 to
// postProcessing/<time>/p0.vtk
const fileName outputDir
fileName outputDir
(
set.time().path()
/ (Pstream::parRun() ? ".." : "")
@ -485,6 +487,7 @@ void Foam::mergeAndWrite
/ mesh.pointsInstance()
// set.name()
);
outputDir.clean();
mkDir(outputDir);
fileName outputFile(outputDir/writer.getFileName(points, wordList()));

View File

@ -53,6 +53,7 @@ Description
#include "polyModifyFace.H"
#include "wordReList.H"
#include "processorMeshes.H"
#include "IOdictionary.H"
using namespace Foam;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -54,6 +54,7 @@ Description
#include "wedgePolyPatch.H"
#include "plane.H"
#include "SubField.H"
#include "IOdictionary.H"
using namespace Foam;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -52,6 +52,7 @@ Description
#include "faceZoneSet.H"
#include "pointZoneSet.H"
#include "timeSelector.H"
#include "collatedFileOperation.H"
#include <stdio.h>
@ -743,6 +744,11 @@ commandStatus parseAction(const word& actionName)
int main(int argc, char *argv[])
{
// Specific to topoSet/setSet: quite often we want to block upon writing
// a set so we can immediately re-read it. So avoid use of threading
// for set writing.
fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0;
timeSelector::addOptions(true, false);
#include "addRegionOption.H"
argList::addBoolOption("noVTK", "do not write VTK files");

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -487,7 +487,8 @@ int main(int argc, char *argv[])
(
runTime.writeFormat(),
IOstream::currentVersion,
runTime.writeCompression()
runTime.writeCompression(),
true
)
)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,6 +42,8 @@ Description
#include "cellZoneSet.H"
#include "faceZoneSet.H"
#include "pointZoneSet.H"
#include "IOdictionary.H"
#include "collatedFileOperation.H"
using namespace Foam;
@ -194,6 +196,11 @@ polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
int main(int argc, char *argv[])
{
// Specific to topoSet/setSet: quite often we want to block upon writing
// a set so we can immediately re-read it. So avoid use of threading
// for set writing.
fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0;
timeSelector::addOptions(true, false);
#include "addDictOption.H"
#include "addRegionOption.H"

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -62,9 +62,19 @@ Usage
#include "cellIOList.H"
#include "IOobjectList.H"
#include "IOPtrList.H"
#include "cloud.H"
#include "labelIOField.H"
#include "scalarIOField.H"
#include "sphericalTensorIOField.H"
#include "symmTensorIOField.H"
#include "tensorIOField.H"
#include "labelFieldIOField.H"
#include "vectorFieldIOField.H"
#include "Cloud.H"
#include "passiveParticle.H"
#include "fieldDictionary.H"
#include "writeMeshObject.H"
#include "fieldDictionary.H"
using namespace Foam;
@ -143,7 +153,8 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
(
IOstream::ASCII,
IOstream::currentVersion,
runTime.writeCompression()
runTime.writeCompression(),
true
);
}
@ -151,6 +162,75 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
}
// Reduction for non-empty strings
class uniqueEqOp
{
public:
void operator()(stringList& x, const stringList& y) const
{
stringList newX(x.size()+y.size());
label n = 0;
forAll(x, i)
{
if (!x[i].empty())
{
newX[n++] = x[i];
}
}
forAll(y, i)
{
if (!y[i].empty() && findIndex(x, y[i]) == -1)
{
newX[n++] = y[i];
}
}
newX.setSize(n);
x.transfer(newX);
}
};
template<class T>
bool writeOptionalMeshObject
(
const word& name,
const fileName& meshDir,
Time& runTime,
const bool valid
)
{
IOobject io
(
name,
runTime.timeName(),
meshDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
bool writeOk = false;
bool haveFile = io.typeHeaderOk<IOField<label>>(false);
// Make sure all know if there is a valid class name
stringList classNames(1, io.headerClassName());
combineReduce(classNames, uniqueEqOp());
// Check for correct type
if (classNames[0] == T::typeName)
{
Info<< " Reading " << classNames[0]
<< " : " << name << endl;
T meshObject(io, valid && haveFile);
Info<< " Writing " << name << endl;
writeOk = meshObject.regIOobject::write(valid && haveFile);
}
return writeOk;
}
int main(int argc, char *argv[])
@ -183,6 +263,8 @@ int main(int argc, char *argv[])
#include "createTime.H"
// Optional mesh (used to read Clouds)
autoPtr<polyMesh> meshPtr;
const bool enableEntries = args.optionFound("enableFunctionEntries");
if (enableEntries)
@ -221,11 +303,24 @@ int main(int argc, char *argv[])
Info<< "Time = " << runTime.timeName() << endl;
// Convert all the standard mesh files
writeMeshObject<cellCompactIOList>("cells", meshDir, runTime);
writeMeshObject<cellCompactIOList, cellIOList>
(
"cells",
meshDir,
runTime
);
writeMeshObject<labelIOList>("owner", meshDir, runTime);
writeMeshObject<labelIOList>("neighbour", meshDir, runTime);
writeMeshObject<faceCompactIOList>("faces", meshDir, runTime);
writeMeshObject<faceCompactIOList, faceIOList>
(
"faces",
meshDir,
runTime
);
writeMeshObject<pointIOField>("points", meshDir, runTime);
// Write boundary in ascii. This is only needed for fileHandler to
// kick in. Should not give problems since always writing ascii.
writeZones("boundary", meshDir, runTime);
writeMeshObject<labelIOList>("pointProcAddressing", meshDir, runTime);
writeMeshObject<labelIOList>("faceProcAddressing", meshDir, runTime);
writeMeshObject<labelIOList>("cellProcAddressing", meshDir, runTime);
@ -279,22 +374,196 @@ int main(int argc, char *argv[])
|| headerClassName == pointSphericalTensorField::typeName
|| headerClassName == pointSymmTensorField::typeName
|| headerClassName == pointTensorField::typeName
|| headerClassName == volScalarField::Internal::typeName
|| headerClassName == volVectorField::Internal::typeName
|| headerClassName == volSphericalTensorField::Internal::typeName
|| headerClassName == volSymmTensorField::Internal::typeName
|| headerClassName == volTensorField::Internal::typeName
)
{
Info<< " Reading " << headerClassName
<< " : " << iter()->name() << endl;
fieldDictionary fDict
(
*iter(),
headerClassName
);
fieldDictionary fDict(*iter(), headerClassName);
Info<< " Writing " << iter()->name() << endl;
fDict.regIOobject::write();
}
}
// Check for lagrangian
stringList lagrangianDirs
(
1,
fileHandler().filePath
(
runTime.timePath()
/ regionPrefix
/ cloud::prefix
)
);
combineReduce(lagrangianDirs, uniqueEqOp());
if (!lagrangianDirs.empty())
{
if (meshPtr.valid())
{
meshPtr().readUpdate();
}
else
{
Info<< " Create polyMesh for time = "
<< runTime.timeName() << endl;
meshPtr.reset
(
new polyMesh
(
IOobject
(
polyMesh::defaultRegion,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
)
)
);
}
stringList cloudDirs
(
fileHandler().readDir
(
lagrangianDirs[0],
fileName::DIRECTORY
)
);
combineReduce(cloudDirs, uniqueEqOp());
forAll(cloudDirs, i)
{
fileName dir(cloud::prefix/cloudDirs[i]);
Cloud<passiveParticle> parcels(meshPtr(), cloudDirs[i], false);
parcels.writeObject
(
runTime.writeFormat(),
IOstream::currentVersion,
runTime.writeCompression(),
parcels.size()
);
// Do local scan for valid cloud objects
IOobjectList sprayObjs(runTime, runTime.timeName(), dir);
// Combine with all other cloud objects
stringList sprayFields(sprayObjs.sortedToc());
combineReduce(sprayFields, uniqueEqOp());
forAll(sprayFields, fieldi)
{
const word& name = sprayFields[fieldi];
// Note: try the various field types. Make sure to
// exit once sucessful conversion to avoid re-read
// converted file.
if
(
name == "positions"
|| name == "origProcId"
|| name == "origId"
)
{
continue;
}
bool writeOk = writeOptionalMeshObject<labelIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<scalarIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<vectorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<sphericalTensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<symmTensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<tensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<labelFieldIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<vectorFieldIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (!writeOk)
{
Info<< " Failed converting " << name << endl;
}
}
}
}
Info<< endl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -39,7 +39,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T>
template<class Type, class CheckType = Type>
inline bool writeMeshObject
(
const word& name,
@ -61,7 +61,7 @@ inline bool writeMeshObject
bool writeOk = false;
if (io.typeHeaderOk<T>(false))
if (io.typeHeaderOk<T>(true, true, false))
{
Info<< " Reading " << io.headerClassName()
<< " : " << name << endl;
@ -71,15 +71,15 @@ inline bool writeMeshObject
word oldTypeName;
if (disableHeaderChecking)
{
oldTypeName = T::typeName;
const_cast<word&>(T::typeName) = word::null;
oldTypeName = Type::typeName;
const_cast<word&>(Type::typeName) = word::null;
}
T meshObject(io);
Type meshObject(io);
if (disableHeaderChecking)
{
const_cast<word&>(T::typeName) = oldTypeName;
const_cast<word&>(Type::typeName) = oldTypeName;
// Fake type back to what was in field
const_cast<word&>(meshObject.type()) = io.headerClassName();
}

View File

@ -104,6 +104,7 @@ Usage
#include "pointFieldDecomposer.H"
#include "lagrangianFieldDecomposer.H"
#include "decompositionModel.H"
#include "collatedFileOperation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -157,13 +158,14 @@ void decomposeUniform
// Any uniform data to copy/link?
const fileName uniformDir(regionDir/"uniform");
if (isDir(runTime.timePath()/uniformDir))
if (fileHandler().isDir(runTime.timePath()/uniformDir))
{
Info<< "Detected additional non-decomposed files in "
<< runTime.timePath()/uniformDir
<< endl;
const fileName timePath = processorDb.timePath();
const fileName timePath =
fileHandler().filePath(processorDb.timePath());
// If no fields have been decomposed the destination
// directory will not have been created so make sure.
@ -171,12 +173,15 @@ void decomposeUniform
if (copyUniform || mesh.distributed())
{
cp
if (!fileHandler().exists(timePath/uniformDir))
{
fileHandler().cp
(
runTime.timePath()/uniformDir,
timePath/uniformDir
);
}
}
else
{
// Link with relative paths
@ -189,11 +194,15 @@ void decomposeUniform
fileName currentDir(cwd());
chDir(timePath);
ln
if (!fileHandler().exists(uniformDir))
{
fileHandler().ln
(
parentPath/runTime.timeName()/uniformDir,
uniformDir
);
}
chDir(currentDir);
}
}
@ -329,24 +338,10 @@ int main(int argc, char *argv[])
Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
// determine the existing processor count directly
label nProcs = 0;
while
(
isDir
(
runTime.path()
/ (word("processor") + name(nProcs))
/ runTime.constant()
/ regionDir
/ polyMesh::meshSubDir
)
)
{
++nProcs;
}
// Determine the existing processor count directly
label nProcs = fileHandler().nProcs(runTime.path(), regionDir);
// get requested numberOfSubdomains. Note: have no mesh yet so
// Get requested numberOfSubdomains. Note: have no mesh yet so
// cannot use decompositionModel::New
const label nDomains = readLabel
(
@ -402,6 +397,8 @@ int main(int argc, char *argv[])
Info<< "Removing " << nProcs
<< " existing processor directories" << endl;
fileHandler().rmDir(runTime.path()/word("processors"));
// remove existing processor dirs
// reverse order to avoid gaps if someone interrupts the process
for (label proci = nProcs-1; proci >= 0; --proci)
@ -411,7 +408,7 @@ int main(int argc, char *argv[])
runTime.path()/(word("processor") + name(proci))
);
rmDir(procDir);
fileHandler().rmDir(procDir);
}
procDirsProblem = false;
@ -448,7 +445,11 @@ int main(int argc, char *argv[])
// Decompose the mesh
if (!decomposeFieldsOnly)
{
mesh.decomposeMesh();
// Disable buffering when writing mesh since we need to read
// it later on when decomposing the fields
float bufSz =
fileOperations::collatedFileOperation::maxThreadFileBufferSize;
fileOperations::collatedFileOperation::maxThreadFileBufferSize = 0;
mesh.writeDecomposition(decomposeSets);
@ -505,12 +506,16 @@ int main(int argc, char *argv[])
<< cellDist.name() << " for use in postprocessing."
<< endl;
}
fileOperations::collatedFileOperation::maxThreadFileBufferSize =
bufSz;
}
if (copyZero)
{
// Link the 0 directory into each of the processor directories
// Copy the 0 directory into each of the processor directories
fileName prevTimePath;
for (label proci = 0; proci < mesh.nProcs(); proci++)
{
Time processorDb
@ -521,14 +526,32 @@ int main(int argc, char *argv[])
);
processorDb.setTime(runTime);
if (isDir(runTime.timePath()))
if (fileHandler().isDir(runTime.timePath()))
{
const fileName timePath = processorDb.timePath();
// Get corresponding directory name (to handle processors/)
const fileName timePath
(
fileHandler().objectPath
(
IOobject
(
"",
processorDb.timeName(),
processorDb
),
word::null
)
);
if (timePath != prevTimePath)
{
Info<< "Processor " << proci
<< ": linking " << runTime.timePath() << nl
<< " to " << processorDb.timePath() << endl;
cp(runTime.timePath(), processorDb.timePath());
<< ": copying " << runTime.timePath() << nl
<< " to " << timePath << endl;
fileHandler().cp(runTime.timePath(), timePath);
prevTimePath = timePath;
}
}
}
}
@ -629,9 +652,10 @@ int main(int argc, char *argv[])
fileNameList cloudDirs
(
readDir
fileHandler().readDir
(
runTime.timePath()/cloud::prefix, fileName::DIRECTORY
runTime.timePath()/cloud::prefix,
fileName::DIRECTORY
)
);

View File

@ -317,9 +317,6 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
time().caseName()/fileName(word("processor") + Foam::name(proci))
);
// make the processor directory
mkDir(time().rootPath()/processorCasePath);
// create a database
Time processorDb
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -188,11 +188,12 @@ void Foam::lagrangianFieldDecomposer::decomposeFields
const PtrList<GeoField>& fields
) const
{
if (particleIndices_.size())
//if (particleIndices_.size())
{
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi)
{
decomposeField(cloudName, fields[fieldi])().write();
decomposeField(cloudName, fields[fieldi])().write(valid);
}
}
}
@ -205,11 +206,12 @@ void Foam::lagrangianFieldDecomposer::decomposeFieldFields
const PtrList<GeoField>& fields
) const
{
if (particleIndices_.size())
//if (particleIndices_.size())
{
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi)
{
decomposeFieldField(cloudName, fields[fieldi])().write();
decomposeFieldField(cloudName, fields[fieldi])().write(valid);
}
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -177,12 +177,43 @@ int main(int argc, char *argv[])
const bool allRegions = args.optionFound("allRegions");
// determine the processor count directly
label nProcs = 0;
while (isDir(args.path()/(word("processor") + name(nProcs))))
wordList regionNames;
wordList regionDirs;
if (allRegions)
{
++nProcs;
Info<< "Reconstructing for all regions in regionProperties" << nl
<< endl;
regionProperties rp(runTime);
forAllConstIter(HashTable<wordList>, rp, iter)
{
const wordList& regions = iter();
forAll(regions, i)
{
if (findIndex(regionNames, regions[i]) == -1)
{
regionNames.append(regions[i]);
}
}
}
regionDirs = regionNames;
}
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
}
else
{
regionNames = wordList(1, fvMesh::defaultRegion);
regionDirs = wordList(1, word::null);
}
}
// Determine the processor count
label nProcs = fileHandler().nProcs(args.path(), regionDirs[0]);
if (!nProcs)
{
@ -225,9 +256,8 @@ int main(int argc, char *argv[])
if (timeDirs.empty())
{
FatalErrorInFunction
<< "No times selected"
<< exit(FatalError);
WarningInFunction << "No times selected";
exit(1);
}
@ -251,42 +281,6 @@ int main(int argc, char *argv[])
}
wordList regionNames;
wordList regionDirs;
if (allRegions)
{
Info<< "Reconstructing for all regions in regionProperties" << nl
<< endl;
regionProperties rp(runTime);
forAllConstIter(HashTable<wordList>, rp, iter)
{
const wordList& regions = iter();
forAll(regions, i)
{
if (findIndex(regionNames, regions[i]) == -1)
{
regionNames.append(regions[i]);
}
}
}
regionDirs = regionNames;
}
else
{
word regionName;
if (args.optionReadIfPresent("region", regionName))
{
regionNames = wordList(1, regionName);
regionDirs = regionNames;
}
else
{
regionNames = wordList(1, fvMesh::defaultRegion);
regionDirs = wordList(1, word::null);
}
}
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
@ -553,17 +547,26 @@ int main(int argc, char *argv[])
forAll(databases, proci)
{
fileNameList cloudDirs
fileName lagrangianDir
(
readDir
fileHandler().filePath
(
databases[proci].timePath()
/ regionDir
/ cloud::prefix,
fileName::DIRECTORY
/ cloud::prefix
)
);
fileNameList cloudDirs;
if (!lagrangianDir.empty())
{
cloudDirs = fileHandler().readDir
(
lagrangianDir,
fileName::DIRECTORY
);
}
forAll(cloudDirs, i)
{
// Check if we already have cloud objects for this
@ -1066,13 +1069,16 @@ int main(int argc, char *argv[])
// directory copy from the master processor
{
fileName uniformDir0
(
fileHandler().filePath
(
databases[0].timePath()/regionDir/"uniform"
)
);
if (isDir(uniformDir0))
if (!uniformDir0.empty() && fileHandler().isDir(uniformDir0))
{
cp(uniformDir0, runTime.timePath()/regionDir);
fileHandler().cp(uniformDir0, runTime.timePath()/regionDir);
}
}
@ -1081,13 +1087,16 @@ int main(int argc, char *argv[])
if (regioni == 0 && regionDir != word::null)
{
fileName uniformDir0
(
fileHandler().filePath
(
databases[0].timePath()/"uniform"
)
);
if (isDir(uniformDir0))
if (!uniformDir0.empty() && fileHandler().isDir(uniformDir0))
{
cp(uniformDir0, runTime.timePath());
fileHandler().cp(uniformDir0, runTime.timePath());
}
}
}

View File

@ -549,20 +549,7 @@ int main(int argc, char *argv[])
bool writeCellDist = args.optionFound("cellDist");
int nProcs = 0;
while
(
isDir
(
args.rootPath()
/ args.caseName()
/ fileName(word("processor") + name(nProcs))
)
)
{
nProcs++;
}
label nProcs = fileHandler().nProcs(args.path());
Info<< "Found " << nProcs << " processor directories" << nl << endl;
@ -610,13 +597,21 @@ int main(int argc, char *argv[])
databases[proci].setTime(timeDirs[timeI], timeI);
}
const fileName meshPath =
databases[0].path()
/databases[0].timeName()
/regionDir
/polyMesh::meshSubDir;
IOobject facesIO
(
"faces",
databases[0].timeName(),
regionDir/polyMesh::meshSubDir,
databases[0],
IOobject::NO_READ,
IOobject::NO_WRITE
);
if (!isFile(meshPath/"faces"))
// Problem: faceCompactIOList recognises both 'faceList' and
// 'faceCompactList' so we should be lenient when doing
// typeHeaderOk
if (!facesIO.typeHeaderOk<faceCompactIOList>(false))
{
Info<< "No mesh." << nl << endl;
continue;

View File

@ -145,13 +145,14 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
// ~~~~~~~~~~~~
// Check who has a mesh
//const bool haveMesh = isDir(io.time().path()/io.instance()/meshSubDir);
const bool haveMesh = isFile
const bool haveMesh = fileHandler().isFile
(
fileHandler().filePath
(
io.time().path()/io.instance()/meshSubDir/"faces"
)
);
if (!haveMesh)
{
bool oldParRun = Pstream::parRun();

View File

@ -1,4 +1,4 @@
// check for "points" in any of the result directories
// Check for "points" in any of the result directories
bool meshMoving = false;

View File

@ -64,7 +64,8 @@ Usage
// Surface writer
writer ensight;
// Collate times for ensight output - ensures geometry is only written once
// Collate times for ensight output
// - ensures geometry is only written once
writeOptions
{
ensight

View File

@ -443,8 +443,25 @@ int main(int argc, char *argv[])
FatalErrorInFunction
<< "No times selected." << exit(FatalError);
}
runTime.setTime(times[0], 0);
word instance = args.optionLookupOrDefault("instance", runTime.timeName());
forAll(times, timei)
{
word instance;
if (args.optionFound("instance"))
{
if (times.size() > 1)
{
FatalErrorInFunction
<< "Multiple times selected with 'instance' option"
<< exit(FatalError);
}
args.optionLookup("instance")() >> instance;
}
else
{
runTime.setTime(times[timei], timei);
instance = runTime.timeName();
}
#include "createNamedMesh.H"
@ -637,7 +654,8 @@ int main(int argc, char *argv[])
(
runTime.writeFormat(),
runTime.writeFormat(),
IOstream::UNCOMPRESSED
IOstream::UNCOMPRESSED,
true
);
}
else
@ -688,9 +706,10 @@ int main(int argc, char *argv[])
<< " does not exist in " << fieldHeader.path() << endl;
}
}
}
entry::disableFunctionEntries = oldFlag;
}
}
Info<< "\nEnd\n" << endl;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,9 +49,7 @@ void MapConsistentVolFields
const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
word fieldClassName(fieldType::typeName);
IOobjectList fields = objects.lookupClass(fieldClassName);
IOobjectList fields = objects.lookupClass(fieldType::typeName);
forAllIter(IOobjectList, fields, fieldIter)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -49,9 +49,7 @@ void MapVolFields
const fvMesh& meshSource = meshToMesh0Interp.fromMesh();
const fvMesh& meshTarget = meshToMesh0Interp.toMesh();
word fieldClassName(fieldType::typeName);
IOobjectList fields = objects.lookupClass(fieldClassName);
IOobjectList fields = objects.lookupClass(fieldType::typeName);
forAllIter(IOobjectList, fields, fieldIter)
{
@ -66,15 +64,10 @@ void MapVolFields
if (fieldTargetIOobject.typeHeaderOk<fieldType>(true))
{
Info<< " interpolating " << fieldIter()->name()
<< endl;
Info<< " interpolating " << fieldIter()->name() << endl;
// Read field fieldSource
fieldType fieldSource
(
*fieldIter(),
meshSource
);
fieldType fieldSource(*fieldIter(), meshSource);
// Read fieldTarget
fieldType fieldTarget

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,6 +44,7 @@ Usage
#include "PackedBoolList.H"
#include "unitConversion.H"
#include "searchableSurfaces.H"
#include "IOdictionary.H"
using namespace Foam;

View File

@ -431,6 +431,7 @@ int main(int argc, char *argv[])
sortedFace.write(globalCasePath);
}
}
Info<< "End\n" << endl;
return 0;

View File

@ -46,6 +46,7 @@ Description
#include "absoluteEnthalpy.H"
#include "SLPtrList.H"
#include "IOdictionary.H"
using namespace Foam;

View File

@ -71,6 +71,20 @@ OptimisationSwitches
// - inotifyMaster : do inotify (and file reading) only on master.
fileModificationChecking timeStampMaster;
//- Parallel IO file handler
// uncollated (default), collated or masterUncollated
fileHandler uncollated;
//- collated: thread buffer size for queued file writes.
// If set to 0 or not sufficient for the file size threading is not used.
// Default: 2e9
maxThreadFileBufferSize 2e9;
//- masterUncollated: non-blocking buffer size.
// If the file exceeds this buffer size scheduled transfer is used.
// Default: 2e9
maxMasterFileBufferSize 2e9;
commsType nonBlocking; //scheduled; //blocking;
floatTransfer 0;
nProcsSimpleSum 0;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -40,6 +40,8 @@ Description
#include "DynamicList.H"
#include "CStringList.H"
#include "SubList.H"
#include "IOstreams.H"
#include "Pstream.H"
#include <fstream>
#include <cstdlib>
@ -323,7 +325,17 @@ bool Foam::chDir(const fileName& dir)
bool Foam::mkDir(const fileName& pathName, mode_t mode)
{
// Ignore an empty pathName => always false
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : pathName:" << pathName << " mode:" << mode
<< endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// empty names are meaningless
if (pathName.empty())
{
return false;
@ -469,6 +481,15 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
bool Foam::chMod(const fileName& name, const mode_t m)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name => always false
return !name.empty() && ::chmod(name.c_str(), m) == 0;
}
@ -476,6 +497,11 @@ bool Foam::chMod(const fileName& name, const mode_t m)
mode_t Foam::mode(const fileName& name, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
}
// Ignore an empty name => always 0
if (!name.empty())
{
@ -498,6 +524,15 @@ Foam::fileName::Type Foam::type(const fileName& name, const bool followLink)
return fileName::UNDEFINED;
}
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
mode_t m = mode(name, followLink);
if (S_ISREG(m))
@ -524,6 +559,16 @@ bool Foam::exists
const bool followLink
)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << " checkGzip:" << checkGzip
<< endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name => always false
return
(
@ -535,6 +580,15 @@ bool Foam::exists
bool Foam::isDir(const fileName& name, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name => always false
return !name.empty() && S_ISDIR(mode(name, followLink));
}
@ -547,6 +601,16 @@ bool Foam::isFile
const bool followLink
)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << " checkGzip:" << checkGzip
<< endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name => always false
return
(
@ -561,6 +625,15 @@ bool Foam::isFile
off_t Foam::fileSize(const fileName& name, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name
if (!name.empty())
{
@ -577,6 +650,15 @@ off_t Foam::fileSize(const fileName& name, const bool followLink)
time_t Foam::lastModified(const fileName& name, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name
if (!name.empty())
{
@ -591,8 +673,17 @@ time_t Foam::lastModified(const fileName& name, const bool followLink)
}
double Foam::highResLastModified(const fileName& name)
double Foam::highResLastModified(const fileName& name, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : name:" << name << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name
if (!name.empty())
{
@ -645,8 +736,12 @@ Foam::fileNameList Foam::readDir
if (POSIX::debug)
{
InfoInFunction
<< "reading directory " << directory << endl;
//InfoInFunction
Pout<< FUNCTION_NAME << " : reading directory " << directory << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
label nEntries = 0;
@ -699,16 +794,26 @@ Foam::fileNameList Foam::readDir
bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
{
if (POSIX::debug)
{
Pout<< FUNCTION_NAME << " : src:" << src << " dest:" << dest << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Make sure source exists - this also handles an empty source name
if (!exists(src))
{
return false;
}
const fileName::Type srcType = src.type(followLink);
fileName destFile(dest);
// Check type of source file.
const fileName::Type srcType = src.type(followLink);
if (srcType == fileName::FILE)
{
// If dest is a directory, create the destination file name.
@ -802,6 +907,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
false,
followLink
);
forAll(subdirs, i)
{
if (POSIX::debug)
@ -828,9 +934,13 @@ bool Foam::ln(const fileName& src, const fileName& dst)
{
if (POSIX::debug)
{
InfoInFunction
<< "Create softlink from : " << src << " to " << dst
<< endl;
//InfoInFunction
Pout<< FUNCTION_NAME
<< " : Create softlink from : " << src << " to " << dst << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
if (src.empty())
@ -879,8 +989,12 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
{
if (POSIX::debug)
{
InfoInFunction
<< "Move : " << src << " to " << dst << endl;
//InfoInFunction
Pout<< FUNCTION_NAME << " : Move : " << src << " to " << dst << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty names => always false
@ -910,8 +1024,13 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
{
if (POSIX::debug)
{
InfoInFunction
<< "mvBak : " << src << " to extension " << ext << endl;
//InfoInFunction
Pout<< FUNCTION_NAME
<< " : moving : " << src << " to extension " << ext << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name or extension => always false
@ -952,8 +1071,12 @@ bool Foam::rm(const fileName& file)
{
if (POSIX::debug)
{
InfoInFunction
<< "Removing : " << file << endl;
//InfoInFunction
Pout<< FUNCTION_NAME << " : Removing : " << file << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Ignore an empty name => always false
@ -996,8 +1119,12 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
if (POSIX::debug)
{
InfoInFunction
<< "removing directory " << directory << endl;
//InfoInFunction
Pout<< FUNCTION_NAME << " : removing directory " << directory << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
}
// Process each directory entry, counting any errors encountered
@ -1504,6 +1631,145 @@ Foam::scalar Foam::osRandomDouble(List<char>& buffer)
drand48_r(reinterpret_cast<drand48_data*>(buffer.begin()), &result);
return result;
#endif
}
static Foam::DynamicList<Foam::autoPtr<pthread_t>> threads_;
static Foam::DynamicList<Foam::autoPtr<pthread_mutex_t>> mutexes_;
Foam::label Foam::allocateThread()
{
forAll(threads_, i)
{
if (!threads_[i].valid())
{
if (POSIX::debug)
{
Pout<< "allocateThread : reusing index:" << i << endl;
}
// Reuse entry
threads_[i].reset(new pthread_t());
return i;
}
}
label index = threads_.size();
if (POSIX::debug)
{
Pout<< "allocateThread : new index:" << index << endl;
}
threads_.append(autoPtr<pthread_t>(new pthread_t()));
return index;
}
void Foam::createThread
(
const label index,
void *(*start_routine) (void *),
void *arg
)
{
if (POSIX::debug)
{
Pout<< "createThread : index:" << index << endl;
}
if (pthread_create(&threads_[index](), nullptr, start_routine, arg))
{
FatalErrorInFunction
<< "Failed starting thread " << index << exit(FatalError);
}
}
void Foam::joinThread(const label index)
{
if (POSIX::debug)
{
Pout<< "freeThread : join:" << index << endl;
}
if (pthread_join(threads_[index](), nullptr))
{
FatalErrorInFunction << "Failed freeing thread " << index
<< exit(FatalError);
}
}
void Foam::freeThread(const label index)
{
if (POSIX::debug)
{
Pout<< "freeThread : index:" << index << endl;
}
threads_[index].clear();
}
Foam::label Foam::allocateMutex()
{
forAll(mutexes_, i)
{
if (!mutexes_[i].valid())
{
if (POSIX::debug)
{
Pout<< "allocateMutex : reusing index:" << i << endl;
}
// Reuse entry
mutexes_[i].reset(new pthread_mutex_t());
return i;
}
}
label index = mutexes_.size();
if (POSIX::debug)
{
Pout<< "allocateMutex : new index:" << index << endl;
}
mutexes_.append(autoPtr<pthread_mutex_t>(new pthread_mutex_t()));
return index;
}
void Foam::lockMutex(const label index)
{
if (POSIX::debug)
{
Pout<< "lockMutex : index:" << index << endl;
}
if (pthread_mutex_lock(&mutexes_[index]()))
{
FatalErrorInFunction << "Failed locking mutex " << index
<< exit(FatalError);
}
}
void Foam::unlockMutex(const label index)
{
if (POSIX::debug)
{
Pout<< "unlockMutex : index:" << index << endl;
}
if (pthread_mutex_unlock(&mutexes_[index]()))
{
FatalErrorInFunction << "Failed unlocking mutex " << index
<< exit(FatalError);
}
}
void Foam::freeMutex(const label index)
{
if (POSIX::debug)
{
Pout<< "freeMutex : index:" << index << endl;
}
mutexes_[index].clear();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -9,6 +9,14 @@ global/profiling/profilingSysInfo.C
global/profiling/profilingTrigger.C
global/etcFiles/etcFiles.C
fileOps = global/fileOperations
$(fileOps)/fileOperation/fileOperation.C
$(fileOps)/uncollatedFileOperation/uncollatedFileOperation.C
$(fileOps)/masterUncollatedFileOperation/masterUncollatedFileOperation.C
$(fileOps)/collatedFileOperation/collatedFileOperation.C
$(fileOps)/collatedFileOperation/threadedCollatedOFstream.C
$(fileOps)/collatedFileOperation/OFstreamCollator.C
bools = primitives/bools
$(bools)/bool/bool.C
$(bools)/bool/boolIO.C
@ -169,6 +177,7 @@ $(gzstream)/gzstream.C
Fstreams = $(Streams)/Fstreams
$(Fstreams)/IFstream.C
$(Fstreams)/OFstream.C
$(Fstreams)/masterOFstream.C
Tstreams = $(Streams)/Tstreams
$(Tstreams)/ITstream.C
@ -225,6 +234,9 @@ $(IOdictionary)/localIOdictionary.C
$(IOdictionary)/unwatchedIOdictionary.C
db/IOobjects/IOMap/IOMapName.C
db/IOobjects/decomposedBlockData/decomposedBlockData.C
db/IOobjects/GlobalIOField/GlobalIOFields.C
db/IOobjects/GlobalIOList/globalIOLists.C
@ -639,8 +651,6 @@ $(Fields)/quaternionField/quaternionIOField.C
$(Fields)/triadField/triadIOField.C
$(Fields)/transformField/transformField.C
$(Fields)/globalFields/globalIOFields.C
pointPatchFields = fields/pointPatchFields
$(pointPatchFields)/pointPatchField/pointPatchFields.C

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -426,182 +426,25 @@ Foam::fileName Foam::IOobject::path
}
Foam::fileName Foam::IOobject::localFilePath(const bool search) const
{
if (isOutsideOfCase(instance()))
{
const fileName objectPath = instance()/name();
if (isFile(objectPath))
{
return objectPath;
}
else
{
return fileName::null;
}
}
else
{
const fileName path = this->path();
const fileName objectPath = path/name();
if (isFile(objectPath))
{
return objectPath;
}
else
{
if (!isDir(path) && search)
{
const word newInstancePath = time().findInstancePath
Foam::fileName Foam::IOobject::localFilePath
(
instant(instance())
);
if (newInstancePath.size())
const word& typeName,
const bool search
) const
{
const fileName fName
// Do not check for undecomposed files
return fileHandler().filePath(false, *this, typeName, search);
}
Foam::fileName Foam::IOobject::globalFilePath
(
rootPath()/caseName()
/newInstancePath/db_.dbDir()/local()/name()
);
if (isFile(fName))
const word& typeName,
const bool search
) const
{
return fName;
}
}
}
}
return fileName::null;
}
}
Foam::fileName Foam::IOobject::globalFilePath(const bool search) const
{
if (isOutsideOfCase(instance()))
{
const fileName objectPath = instance()/name();
if (isFile(objectPath))
{
if (objectRegistry::debug)
{
Pout<< "globalFilePath : returning absolute:" << objectPath
<< endl;
}
return objectPath;
}
else
{
if (objectRegistry::debug)
{
Pout<< "globalFilePath : absolute not found:" << objectPath
<< endl;
}
return fileName::null;
}
}
else
{
const fileName path = this->path();
const fileName objectPath = path/name();
if (isFile(objectPath))
{
if (objectRegistry::debug)
{
Pout<< "globalFilePath : returning time:" << objectPath << endl;
}
return objectPath;
}
else
{
if
(
time().processorCase()
&& (
instance() == time().system()
|| instance() == time().constant()
)
)
{
// Constant & system can come from global case
const fileName parentObjectPath =
rootPath()/time().globalCaseName()
/instance()/db().dbDir()/local()/name();
if (isFile(parentObjectPath))
{
if (objectRegistry::debug)
{
Pout<< "globalFilePath : returning parent:"
<< parentObjectPath << endl;
}
return parentObjectPath;
}
}
// Check for approximately same (local) time
if (!isDir(path) && search)
{
const word newInstancePath = time().findInstancePath
(
instant(instance())
);
if (newInstancePath.size())
{
const fileName fName
(
rootPath()/caseName()
/newInstancePath/db().dbDir()/local()/name()
);
if (isFile(fName))
{
if (objectRegistry::debug)
{
Pout<< "globalFilePath : returning similar time:"
<< fName << endl;
}
return fName;
}
}
}
}
if (objectRegistry::debug)
{
Pout<< "globalFilePath : time not found:" << objectPath << endl;
}
return fileName::null;
}
}
Foam::Istream* Foam::IOobject::objectStream(const fileName& fName)
{
if (fName.size())
{
IFstream* isPtr = new IFstream(fName);
if (isPtr->good())
{
return isPtr;
}
else
{
delete isPtr;
return nullptr;
}
}
return nullptr;
// Check for undecomposed files
return fileHandler().filePath(true, *this, typeName, search);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -131,6 +131,7 @@ public:
static const Enum<fileCheckTypes> fileCheckTypesNames;
private:
// Private data
@ -173,14 +174,6 @@ protected:
// Protected Member Functions
//- Construct and return an IFstream for the object.
// \return nullptr if the stream construction failed
Istream* objectStream();
//- Return an IFstream for the object given the exact file.
// \return nullptr if the stream construction failed
Istream* objectStream(const fileName& fName);
//- Set the object state to bad
void setBad(const string& s);
@ -393,12 +386,20 @@ public:
//- Helper for filePath that searches locally.
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName localFilePath(const bool search=true) const;
fileName localFilePath
(
const word& typeName,
const bool search=true
) const;
//- Helper for filePath that searches up if in parallel
// When search is false, simply use the current instance,
// otherwise search previous instances.
fileName globalFilePath(const bool search=true) const;
fileName globalFilePath
(
const word& typeName,
const bool search=true
) const;
// Reading
@ -414,7 +415,8 @@ public:
bool typeHeaderOk
(
const bool checkType = true,
const bool search = true
const bool search = true,
const bool verbose = true
);
//- Helper: warn that type does not support re-reading
@ -475,6 +477,7 @@ inline bool typeGlobal()
return false;
}
//- Template function for obtaining local or global filePath
template<class T>
inline fileName typeFilePath(const IOobject& io, const bool search = true)
@ -482,8 +485,8 @@ inline fileName typeFilePath(const IOobject& io, const bool search=true)
return
(
typeGlobal<T>()
? io.globalFilePath(search)
: io.localFilePath(search)
? io.globalFilePath(T::typeName, search)
: io.localFilePath(T::typeName, search)
);
}

View File

@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,8 +24,8 @@ License
\*---------------------------------------------------------------------------*/
#include "IOobject.H"
#include "fileOperation.H"
#include "Istream.H"
#include "IOstreams.H"
#include "Pstream.H"
@ -35,7 +35,8 @@ template<class Type>
bool Foam::IOobject::typeHeaderOk
(
const bool checkType,
const bool search
const bool search,
const bool verbose
)
{
bool ok = true;
@ -48,56 +49,27 @@ bool Foam::IOobject::typeHeaderOk
|| IOobject::fileModificationChecking == inotifyMaster
);
const fileOperation& fp = Foam::fileHandler();
// Determine local status
if (!masterOnly || Pstream::master())
{
Istream* isPtr = objectStream(typeFilePath<Type>(*this, search));
fileName fName(typeFilePath<Type>(*this, search));
// If the stream has failed return
if (!isPtr)
ok = fp.readHeader(*this, fName, Type::typeName);
if (ok && checkType && headerClassName_ != Type::typeName)
{
if (IOobject::debug)
if (verbose)
{
InfoInFunction
<< "file " << objectPath() << " could not be opened"
<< endl;
}
ok = false;
}
else
{
// Try reading header
if (readHeader(*isPtr))
{
if (checkType && headerClassName_ != Type::typeName)
{
if (debug)
{
IOWarningInFunction(*isPtr)
WarningInFunction
<< "unexpected class name " << headerClassName_
<< " expected " << Type::typeName << endl;
<< " expected " << Type::typeName
<< " when reading " << fName << endl;
}
ok = false;
}
}
else
{
if (IOobject::debug)
{
IOWarningInFunction(*isPtr)
<< "failed to read header of file " << objectPath()
<< endl;
}
ok = false;
}
}
delete isPtr;
}
// If masterOnly make sure all processors know about it
if (masterOnly)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -146,7 +146,7 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
<< " object " << name() << ";\n"
<< "}" << nl;
writeDivider(os) << endl;
writeDivider(os) << nl;
return true;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -141,23 +141,16 @@ Foam::IOobjectList::IOobjectList
:
HashPtrTable<IOobject>()
{
word newInstance = instance;
word newInstance;
fileNameList ObjectNames = fileHandler().readObjects
(
db,
instance,
local,
newInstance
);
if (!isDir(db.path(instance)))
{
newInstance = db.time().findInstancePath(instant(instance));
if (newInstance.empty())
{
return;
}
}
// Create a list of file names in this directory
const auto objNames =
readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
for (const auto& objName : objNames)
for (const auto& objName : ObjectNames)
{
IOobject* objectPtr = new IOobject
(

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -29,10 +29,12 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class T, class BaseType>
void Foam::CompactIOField<T, BaseType>::readFromStream()
void Foam::CompactIOField<T, BaseType>::readFromStream(const bool valid)
{
Istream& is = readStream(word::null);
Istream& is = readStream(word::null, valid);
if (valid)
{
if (headerClassName() == IOField<T>::typeName)
{
is >> static_cast<Field<T>&>(*this);
@ -55,6 +57,7 @@ void Foam::CompactIOField<T, BaseType>::readFromStream()
<< exit(FatalIOError);
}
}
}
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
@ -75,6 +78,27 @@ Foam::CompactIOField<T, BaseType>::CompactIOField(const IOobject& io)
}
template<class T, class BaseType>
Foam::CompactIOField<T, BaseType>::CompactIOField
(
const IOobject& io,
const bool valid
)
:
regIOobject(io)
{
if (io.readOpt() == IOobject::MUST_READ)
{
readFromStream(valid);
}
else if (io.readOpt() == IOobject::READ_IF_PRESENT)
{
bool haveFile = headerOk();
readFromStream(valid && haveFile);
}
}
template<class T, class BaseType>
Foam::CompactIOField<T, BaseType>::CompactIOField
(
@ -160,7 +184,8 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const
{
if (fmt == IOstream::ASCII)
@ -170,7 +195,7 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
const_cast<word&>(typeName) = IOField<T>::typeName;
bool good = regIOobject::writeObject(fmt, ver, cmp);
bool good = regIOobject::writeObject(fmt, ver, cmp, valid);
// Change type back
const_cast<word&>(typeName) = oldTypeName;
@ -179,7 +204,7 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
}
else
{
return regIOobject::writeObject(fmt, ver, cmp);
return regIOobject::writeObject(fmt, ver, cmp, valid);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -75,7 +75,7 @@ class CompactIOField
// Private Member Functions
//- Read according to header type
void readFromStream();
void readFromStream(const bool valid = true);
public:
@ -88,6 +88,9 @@ public:
//- Construct from IOobject
CompactIOField(const IOobject&);
//- Construct from IOobject; does local processor require reading?
CompactIOField(const IOobject&, const bool valid);
//- Construct from IOobject and size
CompactIOField(const IOobject&, const label);
@ -109,7 +112,8 @@ public:
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType
IOstream::compressionType,
const bool valid
) const;
virtual bool writeData(Ostream&) const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -175,7 +175,8 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const
{
if (fmt == IOstream::ASCII)
@ -185,7 +186,26 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
const_cast<word&>(typeName) = IOList<T>::typeName;
bool good = regIOobject::writeObject(fmt, ver, cmp);
bool good = regIOobject::writeObject(fmt, ver, cmp, valid);
// Change type back
const_cast<word&>(typeName) = oldTypeName;
return good;
}
else if (overflows())
{
WarningInFunction
<< "Overall number of elements of CompactIOList of size "
<< this->size() << " overflows the representation of a label"
<< endl << " Switching to ascii writing" << endl;
// Change type to be non-compact format type
const word oldTypeName = typeName;
const_cast<word&>(typeName) = IOList<T>::typeName;
bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, valid);
// Change type back
const_cast<word&>(typeName) = oldTypeName;
@ -213,7 +233,7 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
}
else
{
return regIOobject::writeObject(fmt, ver, cmp);
return regIOobject::writeObject(fmt, ver, cmp, valid);
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -114,7 +114,8 @@ public:
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType
IOstream::compressionType,
const bool valid
) const;
virtual bool writeData(Ostream&) const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -90,7 +90,7 @@ public:
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
return globalFilePath(type());
}
//- ReadData function required for regIOobject read operation

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,22 +23,43 @@ License
\*---------------------------------------------------------------------------*/
#include "globalIOFields.H"
#include "GlobalIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameWithName(labelGlobalIOField, "labelField");
defineTemplateTypeNameWithName(scalarGlobalIOField, "scalarField");
defineTemplateTypeNameWithName(vectorGlobalIOField, "vectorField");
defineTemplateTypeNameWithName
defineTemplateTypeNameAndDebugWithName
(
sphericalTensorGlobalIOField,
"sphericalTensorField"
GlobalIOField<scalar>,
"scalarField",
0
);
defineTemplateTypeNameAndDebugWithName
(
GlobalIOField<vector>,
"vectorField",
0
);
defineTemplateTypeNameAndDebugWithName
(
GlobalIOField<sphericalTensor>,
"sphericalTensorField",
0
);
defineTemplateTypeNameAndDebugWithName
(
GlobalIOField<symmTensor>,
"symmTensorField",
0
);
defineTemplateTypeNameAndDebugWithName
(
GlobalIOField<tensor>,
"tensorField",
0
);
defineTemplateTypeNameWithName(symmTensorGlobalIOField, "symmTensorField");
defineTemplateTypeNameWithName(tensorGlobalIOField, "tensorField");
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -90,7 +90,7 @@ public:
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
return globalFilePath(type());
}
//- ReadData function required for regIOobject read operation

View File

@ -41,4 +41,5 @@ namespace Foam
defineTemplateTypeNameWithName(tensorGlobalIOList, "tensorList");
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,34 +53,39 @@ namespace Foam
{
return true;
}
template<>
inline bool typeGlobal<scalarGlobalIOList>()
{
return true;
}
template<>
inline bool typeGlobal<vectorGlobalIOList>()
{
return true;
}
template<>
inline bool typeGlobal<sphericalTensorGlobalIOList>()
{
return true;
}
template<>
inline bool typeGlobal<symmTensorGlobalIOList>()
{
return true;
}
template<>
inline bool typeGlobal<tensorGlobalIOList>()
{
return true;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -50,6 +50,43 @@ Foam::IOField<Type>::IOField(const IOobject& io)
}
template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, const bool valid)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading<IOField<Type>>();
if
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
)
{
Istream& is = readStream(typeName, valid);
if (valid)
{
is >> *this;
}
close();
}
else if (io.readOpt() == IOobject::READ_IF_PRESENT)
{
bool haveFile = headerOk();
Istream& is = readStream(typeName, haveFile && valid);
if (valid && haveFile)
{
is >> *this;
}
close();
}
}
template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, const label size)
:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -64,6 +64,9 @@ public:
//- Construct from IOobject
IOField(const IOobject&);
//- Construct from IOobject; does local processor require reading?
IOField(const IOobject&, const bool valid);
//- Construct from IOobject and size (does not set values)
IOField(const IOobject&, const label size);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -94,7 +94,7 @@ public:
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
return globalFilePath(type());
}
// Member operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -36,6 +36,14 @@ namespace Foam
{
return true;
}
//- Template specialisation for obtaining filePath
template<>
fileName typeFilePath<IOMap<dictionary>>(const IOobject& io)
{
return io.globalFilePath(IOMap<dictionary>::typeName);
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,9 +85,8 @@ public:
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
return globalFilePath(type());
}
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,9 +27,9 @@ Class
Description
baseIOdictionary is derived from dictionary and IOobject to give the
dictionary automatic IO functionality via the objectRegistry.
To facilitate IO,
baseIOdictionary is provided with a constructor from IOobject and with
readData/writeData functions.
To facilitate IO, baseIOdictionary is provided with a constructor from
IOobject and with readData/writeData functions.
SourceFiles
baseIOdictionary.C

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,6 +38,21 @@ Foam::localIOdictionary::localIOdictionary(const IOobject& io)
}
Foam::localIOdictionary::localIOdictionary
(
const IOobject& io,
const word& wantedType
)
:
baseIOdictionary(io)
{
readHeaderOk(IOstream::ASCII, wantedType);
// For if MUST_READ_IF_MODIFIED
addWatch();
}
Foam::localIOdictionary::localIOdictionary
(
const IOobject& io,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -65,6 +65,10 @@ public:
//- Construct given an IOobject and Istream
localIOdictionary(const IOobject& io, Istream& is);
//- Construct given an IOobject, supply wanted typeName
localIOdictionary(const IOobject& io, const word& wantedType);
//- Destructor
virtual ~localIOdictionary();
@ -82,7 +86,7 @@ public:
virtual fileName filePath() const
{
// Use default (local only) search strategy
return localFilePath();
return localFilePath(type());
}
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,7 +85,7 @@ public:
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
return globalFilePath(type());
}
//- Add file watch on object (READ_IF_MODIFIED)

View File

@ -0,0 +1,921 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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 "decomposedBlockData.H"
#include "OPstream.H"
#include "IPstream.H"
#include "PstreamBuffers.H"
#include "OFstream.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "dictionary.H"
#include <sys/time.h>
#include "objectRegistry.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(decomposedBlockData, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::decomposedBlockData::decomposedBlockData
(
const label comm,
const IOobject& io,
const UPstream::commsTypes commsType
)
:
regIOobject(io),
commsType_(commsType),
comm_(comm)
{
// Temporary warning
if (io.readOpt() == IOobject::MUST_READ_IF_MODIFIED)
{
WarningInFunction
<< "decomposedBlockData " << name()
<< " constructed with IOobject::MUST_READ_IF_MODIFIED"
" but decomposedBlockData does not support automatic rereading."
<< endl;
}
if
(
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
)
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
read();
}
}
Foam::decomposedBlockData::decomposedBlockData
(
const label comm,
const IOobject& io,
const UList<char>& list,
const UPstream::commsTypes commsType
)
:
regIOobject(io),
commsType_(commsType),
comm_(comm)
{
// Temporary warning
if (io.readOpt() == IOobject::MUST_READ_IF_MODIFIED)
{
WarningInFunction
<< "decomposedBlockData " << name()
<< " constructed with IOobject::MUST_READ_IF_MODIFIED"
" but decomposedBlockData does not support automatic rereading."
<< endl;
}
if
(
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
)
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
read();
}
else
{
List<char>::operator=(list);
}
}
Foam::decomposedBlockData::decomposedBlockData
(
const label comm,
const IOobject& io,
const Xfer<List<char>>& list,
const UPstream::commsTypes commsType
)
:
regIOobject(io),
commsType_(commsType),
comm_(comm)
{
// Temporary warning
if (io.readOpt() == IOobject::MUST_READ_IF_MODIFIED)
{
WarningInFunction
<< "decomposedBlockData " << name()
<< " constructed with IOobject::MUST_READ_IF_MODIFIED"
" but decomposedBlockData does not support automatic rereading."
<< endl;
}
List<char>::transfer(list());
if
(
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
)
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
read();
}
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
Foam::decomposedBlockData::~decomposedBlockData()
{}
// * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is)
{
if (debug)
{
Pout<< "decomposedBlockData::readMasterHeader:"
<< " stream:" << is.name() << endl;
}
// Master-only reading of header
is.fatalCheck("read(Istream&)");
List<char> data(is);
is.fatalCheck("read(Istream&) : reading entry");
string buf(data.begin(), data.size());
IStringStream str(is.name(), buf);
return io.readHeader(str);
}
void Foam::decomposedBlockData::writeHeader
(
Ostream& os,
const IOstream::versionNumber version,
const IOstream::streamFormat format,
const word& type,
const string& note,
const fileName& location,
const word& name
)
{
IOobject::writeBanner(os)
<< "FoamFile\n{\n"
<< " version " << version << ";\n"
<< " format " << format << ";\n"
<< " class " << type << ";\n";
if (note.size())
{
os << " note " << note << ";\n";
}
if (location.size())
{
os << " location " << location << ";\n";
}
os << " object " << name << ";\n"
<< "}" << nl;
IOobject::writeDivider(os) << nl;
}
Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
(
const label blocki,
Istream& is,
IOobject& headerIO
)
{
if (debug)
{
Pout<< "decomposedBlockData::readBlock:"
<< " stream:" << is.name() << " attempt to read block " << blocki
<< endl;
}
is.fatalCheck("read(Istream&)");
List<char> data;
autoPtr<ISstream> realIsPtr;
if (blocki == 0)
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(is.name(), buf);
// Read header
if (!headerIO.readHeader(realIsPtr()))
{
FatalIOErrorInFunction(realIsPtr())
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
}
else
{
// Read master for header
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
IOstream::versionNumber ver(IOstream::currentVersion);
IOstream::streamFormat fmt;
{
string buf(data.begin(), data.size());
IStringStream headerStream(is.name(), buf);
// Read header
if (!headerIO.readHeader(headerStream))
{
FatalIOErrorInFunction(headerStream)
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
ver = headerStream.version();
fmt = headerStream.format();
}
for (label i = 1; i < blocki+1; i++)
{
// Read data, override old data
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
}
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(is.name(), buf);
// Apply master stream settings to realIsPtr
realIsPtr().format(fmt);
realIsPtr().version(ver);
}
return realIsPtr;
}
bool Foam::decomposedBlockData::readBlocks
(
const label comm,
autoPtr<ISstream>& isPtr,
List<char>& data,
const UPstream::commsTypes commsType
)
{
if (debug)
{
Pout<< "decomposedBlockData::readBlocks:"
<< " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
<< " commsType:" << Pstream::commsTypeNames[commsType]
<< " comm:" << comm << endl;
}
bool ok = false;
if (commsType == UPstream::commsTypes::scheduled)
{
if (UPstream::master(comm))
{
Istream& is = isPtr();
is.fatalCheck("read(Istream&)");
// Read master data
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
}
// Read slave data
for
(
label proci = 1;
proci < UPstream::nProcs(comm);
proci++
)
{
List<char> elems(is);
is.fatalCheck("read(Istream&) : reading entry");
OPstream os
(
UPstream::commsTypes::scheduled,
proci,
0,
UPstream::msgType(),
comm
);
os << elems;
}
ok = is.good();
}
else
{
IPstream is
(
UPstream::commsTypes::scheduled,
UPstream::masterNo(),
0,
UPstream::msgType(),
comm
);
is >> data;
}
}
else
{
PstreamBuffers pBufs
(
UPstream::commsTypes::nonBlocking,
UPstream::msgType(),
comm
);
if (UPstream::master(comm))
{
Istream& is = isPtr();
is.fatalCheck("read(Istream&)");
// Read master data
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
}
// Read slave data
for
(
label proci = 1;
proci < UPstream::nProcs(comm);
proci++
)
{
List<char> elems(is);
is.fatalCheck("read(Istream&) : reading entry");
UOPstream os(proci, pBufs);
os << elems;
}
}
labelList recvSizes;
pBufs.finishedSends(recvSizes);
if (!UPstream::master(comm))
{
UIPstream is(UPstream::masterNo(), pBufs);
is >> data;
}
}
Pstream::scatter(ok, Pstream::msgType(), comm);
return ok;
}
Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
(
const label comm,
const fileName& fName,
autoPtr<ISstream>& isPtr,
IOobject& headerIO,
const UPstream::commsTypes commsType
)
{
if (debug)
{
Pout<< "decomposedBlockData::readBlocks:"
<< " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
<< " commsType:" << Pstream::commsTypeNames[commsType] << endl;
}
bool ok = false;
List<char> data;
autoPtr<ISstream> realIsPtr;
if (commsType == UPstream::commsTypes::scheduled)
{
if (UPstream::master(comm))
{
Istream& is = isPtr();
is.fatalCheck("read(Istream&)");
// Read master data
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(fName, buf);
// Read header
if (!headerIO.readHeader(realIsPtr()))
{
FatalIOErrorInFunction(realIsPtr())
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
}
// Read slave data
for
(
label proci = 1;
proci < UPstream::nProcs(comm);
proci++
)
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
OPstream os
(
UPstream::commsTypes::scheduled,
proci,
0,
UPstream::msgType(),
comm
);
os << data;
}
ok = is.good();
}
else
{
IPstream is
(
UPstream::commsTypes::scheduled,
UPstream::masterNo(),
0,
UPstream::msgType(),
comm
);
is >> data;
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(fName, buf);
}
}
else
{
PstreamBuffers pBufs
(
UPstream::commsTypes::nonBlocking,
UPstream::msgType(),
comm
);
if (UPstream::master(comm))
{
Istream& is = isPtr();
is.fatalCheck("read(Istream&)");
// Read master data
{
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(fName, buf);
// Read header
if (!headerIO.readHeader(realIsPtr()))
{
FatalIOErrorInFunction(realIsPtr())
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
}
// Read slave data
for
(
label proci = 1;
proci < UPstream::nProcs(comm);
proci++
)
{
List<char> elems(is);
is.fatalCheck("read(Istream&) : reading entry");
UOPstream os(proci, pBufs);
os << elems;
}
ok = is.good();
}
labelList recvSizes;
pBufs.finishedSends(recvSizes);
if (!UPstream::master(comm))
{
UIPstream is(UPstream::masterNo(), pBufs);
is >> data;
string buf(data.begin(), data.size());
realIsPtr = new IStringStream(fName, buf);
}
}
Pstream::scatter(ok, Pstream::msgType(), comm);
// version
string versionString(realIsPtr().version().str());
Pstream::scatter(versionString, Pstream::msgType(), comm);
realIsPtr().version(IStringStream(versionString)());
// stream
{
OStringStream os;
os << realIsPtr().format();
string formatString(os.str());
Pstream::scatter(formatString, Pstream::msgType(), comm);
realIsPtr().format(formatString);
}
word name(headerIO.name());
Pstream::scatter(name, Pstream::msgType(), comm);
headerIO.rename(name);
Pstream::scatter(headerIO.headerClassName(), Pstream::msgType(), comm);
Pstream::scatter(headerIO.note(), Pstream::msgType(), comm);
//Pstream::scatter(headerIO.instance(), Pstream::msgType(), comm);
//Pstream::scatter(headerIO.local(), Pstream::msgType(), comm);
return realIsPtr;
}
bool Foam::decomposedBlockData::writeBlocks
(
const label comm,
autoPtr<OSstream>& osPtr,
List<std::streamoff>& start,
const UList<char>& data,
const UPstream::commsTypes commsType,
const bool syncReturnState
)
{
if (debug)
{
Pout<< "decomposedBlockData::writeBlocks:"
<< " stream:" << (osPtr.valid() ? osPtr().name() : "invalid")
<< " data:" << data.size()
<< " commsType:" << Pstream::commsTypeNames[commsType] << endl;
}
bool ok = true;
labelList recvSizes(Pstream::nProcs(comm));
recvSizes[Pstream::myProcNo(comm)] = data.byteSize();
Pstream::gatherList(recvSizes, Pstream::msgType(), comm);
if (commsType == UPstream::commsTypes::scheduled)
{
if (UPstream::master(comm))
{
start.setSize(UPstream::nProcs(comm));
OSstream& os = osPtr();
// Write master data
{
os << nl << "// Processor" << UPstream::masterNo() << nl;
start[UPstream::masterNo()] = os.stdStream().tellp();
os << data;
}
// Write slaves
List<char> elems;
for (label proci = 1; proci < UPstream::nProcs(comm); proci++)
{
elems.setSize(recvSizes[proci]);
IPstream::read
(
UPstream::commsTypes::scheduled,
proci,
elems.begin(),
elems.size(),
Pstream::msgType(),
comm
);
os << nl << nl << "// Processor" << proci << nl;
start[proci] = os.stdStream().tellp();
os << elems;
}
ok = os.good();
}
else
{
UOPstream::write
(
UPstream::commsTypes::scheduled,
UPstream::masterNo(),
data.begin(),
data.byteSize(),
Pstream::msgType(),
comm
);
}
}
else
{
if (debug)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
Pout<< "Starting sending at:"
<< 1.0*tv.tv_sec+tv.tv_usec/1e6 << " s"
<< Foam::endl;
}
label startOfRequests = Pstream::nRequests();
if (!UPstream::master(comm))
{
UOPstream::write
(
UPstream::commsTypes::nonBlocking,
UPstream::masterNo(),
data.begin(),
data.byteSize(),
Pstream::msgType(),
comm
);
Pstream::waitRequests(startOfRequests);
}
else
{
List<List<char>> recvBufs(Pstream::nProcs(comm));
for (label proci = 1; proci < UPstream::nProcs(comm); proci++)
{
recvBufs[proci].setSize(recvSizes[proci]);
UIPstream::read
(
UPstream::commsTypes::nonBlocking,
proci,
recvBufs[proci].begin(),
recvSizes[proci],
Pstream::msgType(),
comm
);
}
if (debug)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
Pout<< "Starting master-only writing at:"
<< 1.0*tv.tv_sec+tv.tv_usec/1e6 << " s"
<< Foam::endl;
}
start.setSize(UPstream::nProcs(comm));
OSstream& os = osPtr();
// Write master data
{
os << nl << "// Processor" << UPstream::masterNo() << nl;
start[UPstream::masterNo()] = os.stdStream().tellp();
os << data;
}
if (debug)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
Pout<< "Starting slave writing at:"
<< 1.0*tv.tv_sec+tv.tv_usec/1e6 << " s"
<< Foam::endl;
}
// Write slaves
for (label proci = 1; proci < UPstream::nProcs(comm); proci++)
{
os << nl << nl << "// Processor" << proci << nl;
start[proci] = os.stdStream().tellp();
if (Pstream::finishedRequest(startOfRequests+proci-1))
{
os << recvBufs[proci];
}
}
Pstream::resetRequests(startOfRequests);
ok = os.good();
}
}
if (debug)
{
struct timeval tv;
gettimeofday(&tv, nullptr);
Pout<< "Finished master-only writing at:"
<< 1.0*tv.tv_sec+tv.tv_usec/1e6 << " s"
<< Foam::endl;
}
if (syncReturnState)
{
//- Enable to get synchronised error checking. Is the one that keeps
// slaves as slow as the master (which does all the writing)
Pstream::scatter(ok, Pstream::msgType(), comm);
}
return ok;
}
bool Foam::decomposedBlockData::read()
{
autoPtr<ISstream> isPtr;
fileName objPath(fileHandler().filePath(false, *this, word::null));
if (UPstream::master(comm_))
{
isPtr.reset(new IFstream(objPath));
IOobject::readHeader(isPtr());
}
List<char>& data = *this;
return readBlocks(comm_, isPtr, data, commsType_);
}
bool Foam::decomposedBlockData::writeData(Ostream& os) const
{
const List<char>& data = *this;
string str
(
reinterpret_cast<const char*>(data.cbegin()),
data.byteSize()
);
IOobject io(*this);
if (Pstream::master())
{
IStringStream is(name(), str);
io.readHeader(is);
}
// Scatter header information
// version
string versionString(os.version().str());
Pstream::scatter(versionString);
// stream
string formatString;
{
OStringStream os;
os << os.format();
formatString = os.str();
Pstream::scatter(formatString);
}
//word masterName(name());
//Pstream::scatter(masterName);
Pstream::scatter(io.headerClassName());
Pstream::scatter(io.note());
//Pstream::scatter(io.instance(), Pstream::msgType(), comm);
//Pstream::scatter(io.local(), Pstream::msgType(), comm);
fileName masterLocation(instance()/db().dbDir()/local());
Pstream::scatter(masterLocation);
if (!Pstream::master())
{
writeHeader
(
os,
IOstream::versionNumber(IStringStream(versionString)()),
IOstream::formatEnum(formatString),
io.headerClassName(),
io.note(),
masterLocation,
name()
);
}
os.writeQuoted(str, false);
if (!Pstream::master())
{
IOobject::writeEndDivider(os);
}
return os.good();
}
bool Foam::decomposedBlockData::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
const bool valid
) const
{
autoPtr<OSstream> osPtr;
if (UPstream::master(comm_))
{
// Note: always write binary. These are strings so readable
// anyway. They have already be tokenised on the sending side.
osPtr.reset(new OFstream(objectPath(), IOstream::BINARY, ver, cmp));
IOobject::writeHeader(osPtr());
}
List<std::streamoff> start;
return writeBlocks(comm_, osPtr, start, *this, commsType_);
}
Foam::label Foam::decomposedBlockData::numBlocks(const fileName& fName)
{
label nBlocks = 0;
IFstream is(fName);
is.fatalCheck("decomposedBlockData::numBlocks(const fileName&)");
if (!is.good())
{
return nBlocks;
}
// Skip header
token firstToken(is);
if
(
is.good()
&& firstToken.isWord()
&& firstToken.wordToken() == "FoamFile"
)
{
dictionary headerDict(is);
is.version(headerDict.lookup("version"));
is.format(headerDict.lookup("format"));
}
List<char> data;
while (is.good())
{
token sizeToken(is);
if (!sizeToken.isLabel())
{
return nBlocks;
}
is.putBack(sizeToken);
is >> data;
nBlocks++;
}
return nBlocks;
}
// ************************************************************************* //

View File

@ -0,0 +1,197 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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::decomposedBlockData
Description
decomposedBlockData is a List<char> with IO on the master processor only.
SourceFiles
decomposedBlockData.C
\*---------------------------------------------------------------------------*/
#ifndef decomposedBlockData_H
#define decomposedBlockData_H
#include "IOList.H"
#include "regIOobject.H"
#include "UPstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class decomposedBlockData Declaration
\*---------------------------------------------------------------------------*/
class decomposedBlockData
:
public regIOobject,
public List<char>
{
protected:
// Protected data
//- Type to use for gather
const UPstream::commsTypes commsType_;
//- Communicator for all parallel comms
const label comm_;
// Protected member functions
//- Read data into *this. ISstream is only valid on master.
static bool readBlocks
(
const label comm,
autoPtr<ISstream>& isPtr,
List<char>& data,
const UPstream::commsTypes commsType
);
public:
TypeName("decomposedBlockData");
// Constructors
//- Construct given an IOobject
decomposedBlockData
(
const label comm,
const IOobject&,
const UPstream::commsTypes = UPstream::commsTypes::scheduled
);
//- Construct given an IOobject and for READ_IF_MODIFIED a List<char>
decomposedBlockData
(
const label comm,
const IOobject&,
const UList<char>&,
const UPstream::commsTypes = UPstream::commsTypes::scheduled
);
//- Construct by transferring the IOList contents
decomposedBlockData
(
const label comm,
const IOobject&,
const Xfer<List<char>>&,
const UPstream::commsTypes = UPstream::commsTypes::scheduled
);
//- Destructor
virtual ~decomposedBlockData();
// Member functions
//- Read object
virtual bool read();
//- Write separated content. Assumes content is the serialised data
// and that the master data contains a header
virtual bool writeData(Ostream&) const;
//- Write using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
const bool valid
) const;
// Helpers
//- Read header. Call only on master.
static bool readMasterHeader(IOobject&, Istream&);
//- Helper: write FoamFile IOobject header
static void writeHeader
(
Ostream& os,
const IOstream::versionNumber version,
const IOstream::streamFormat format,
const word& type,
const string& note,
const fileName& location,
const word& name
);
//- Read selected block (non-seeking) + header information
static autoPtr<ISstream> readBlock
(
const label blocki,
Istream& is,
IOobject& headerIO
);
//- Read master header information (into headerIO) and return
// data in stream. Note: isPtr is only valid on master.
static autoPtr<ISstream> readBlocks
(
const label comm,
const fileName& fName,
autoPtr<ISstream>& isPtr,
IOobject& headerIO,
const UPstream::commsTypes commsType
);
//- Write *this. Ostream only valid on master. Returns starts of
// processor blocks
static bool writeBlocks
(
const label comm,
autoPtr<OSstream>& osPtr,
List<std::streamoff>& start,
const UList<char>&,
const UPstream::commsTypes,
const bool syncReturnState = true
);
//- Detect number of blocks in a file
static label numBlocks(const fileName&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -40,7 +40,8 @@ namespace Foam
Foam::OFstreamAllocator::OFstreamAllocator
(
const fileName& pathname,
IOstream::compressionType compression
IOstream::compressionType compression,
const bool append
)
:
allocatedPtr_(nullptr)
@ -52,26 +53,48 @@ Foam::OFstreamAllocator::OFstreamAllocator
InfoInFunction << "Cannot open null file " << endl;
}
}
ofstream::openmode mode(ofstream::out);
if (append)
{
mode |= ofstream::app;
}
if (compression == IOstream::COMPRESSED)
{
// Get identically named uncompressed version out of the way
if (isFile(pathname, false))
fileName::Type pathType = Foam::type(pathname, false);
if (pathType == fileName::FILE || pathType == fileName::LINK)
{
rm(pathname);
}
fileName gzPathName(pathname + ".gz");
allocatedPtr_ = new ogzstream((pathname + ".gz").c_str());
if (!append && Foam::type(gzPathName) == fileName::LINK)
{
// Disallow writing into softlink to avoid any problems with
// e.g. softlinked initial fields
rm(gzPathName);
}
allocatedPtr_ = new ogzstream(gzPathName.c_str(), mode);
}
else
{
// Get identically named compressed version out of the way
if (isFile(pathname + ".gz", false))
// get identically named compressed version out of the way
fileName gzPathName(pathname + ".gz");
fileName::Type gzType = Foam::type(gzPathName, false);
if (gzType == fileName::FILE || gzType == fileName::LINK)
{
rm(pathname + ".gz");
rm(gzPathName);
}
if (!append && Foam::type(pathname, false) == fileName::LINK)
{
// Disallow writing into softlink to avoid any problems with
// e.g. softlinked initial fields
rm(pathname);
}
allocatedPtr_ = new std::ofstream(pathname);
allocatedPtr_ = new std::ofstream(pathname, mode);
}
}
@ -99,11 +122,19 @@ Foam::OFstream::OFstream
const fileName& pathname,
streamFormat format,
versionNumber version,
compressionType compression
compressionType compression,
const bool append
)
:
OFstreamAllocator(pathname, compression),
OSstream(*allocatedPtr_, pathname, format, version, compression)
OFstreamAllocator(pathname, compression, append),
OSstream
(
*allocatedPtr_,
"OFstream.sinkFile_",
format,
version,
compression
)
{
setClosed();
setState(allocatedPtr_->rdstate());

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -68,7 +68,8 @@ protected:
OFstreamAllocator
(
const fileName& pathname,
IOstream::compressionType compression=IOstream::UNCOMPRESSED
IOstream::compressionType compression=IOstream::UNCOMPRESSED,
const bool append = false
);
@ -107,7 +108,8 @@ public:
const fileName& pathname,
streamFormat format=ASCII,
versionNumber version=currentVersion,
compressionType compression=UNCOMPRESSED
compressionType compression=UNCOMPRESSED,
const bool append = false
);

View File

@ -0,0 +1,168 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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 "masterOFstream.H"
#include "OFstream.H"
#include "OSspecific.H"
#include "PstreamBuffers.H"
#include "masterUncollatedFileOperation.H"
#include "boolList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::masterOFstream::checkWrite
(
const fileName& fName,
const string& str
)
{
mkDir(fName.path());
OFstream os
(
fName,
IOstream::BINARY, //format(),
version(),
compression_,
append_
);
if (!os.good())
{
FatalIOErrorInFunction(os)
<< "Could not open file " << fName
<< exit(FatalIOError);
}
os.writeQuoted(str, false);
if (!os.good())
{
FatalIOErrorInFunction(os)
<< "Failed writing to " << fName
<< exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::masterOFstream::masterOFstream
(
const fileName& pathName,
streamFormat format,
versionNumber version,
compressionType compression,
const bool append,
const bool valid
)
:
OStringStream(format, version),
pathName_(pathName),
compression_(compression),
append_(append),
valid_(valid)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::masterOFstream::~masterOFstream()
{
if (Pstream::parRun())
{
List<fileName> filePaths(Pstream::nProcs());
filePaths[Pstream::myProcNo()] = pathName_;
Pstream::gatherList(filePaths);
bool uniform =
fileOperations::masterUncollatedFileOperation::uniformFile
(
filePaths
);
Pstream::scatter(uniform);
if (uniform)
{
if (Pstream::master() && valid_)
{
checkWrite(pathName_, str());
}
return;
}
boolList valid(Pstream::nProcs());
valid[Pstream::myProcNo()] = valid_;
Pstream::gatherList(valid);
// Different files
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
// Send my buffer to master
if (!Pstream::master())
{
UOPstream os(Pstream::masterNo(), pBufs);
string s(this->str());
os.write(&s[0], s.size());
}
labelList recvSizes;
pBufs.finishedSends(recvSizes);
if (Pstream::master())
{
// Write my own data
{
if (valid[Pstream::myProcNo()])
{
checkWrite(filePaths[Pstream::myProcNo()], str());
}
}
for (label proci = 1; proci < Pstream::nProcs(); proci++)
{
UIPstream is(proci, pBufs);
List<char> buf(recvSizes[proci]);
is.read(buf.begin(), buf.size());
if (valid[proci])
{
checkWrite
(
filePaths[proci],
string(buf.begin(), buf.size())
);
}
}
}
}
else
{
checkWrite(pathName_, str());
}
}
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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::masterOFstream
Description
Master-only drop-in replacement for OFstream.
SourceFiles
masterOFstream.C
\*---------------------------------------------------------------------------*/
#ifndef masterOFstream_H
#define masterOFstream_H
#include "OStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class masterOFstream Declaration
\*---------------------------------------------------------------------------*/
class masterOFstream
:
public OStringStream
{
// Private data
const fileName pathName_;
const IOstream::compressionType compression_;
const bool append_;
//- Should file be written
const bool valid_;
// Private Member Functions
//- Open file with checking
void checkWrite(const fileName& fName, const string& str);
public:
// Constructors
//- Construct and set stream status
masterOFstream
(
const fileName& pathname,
streamFormat format=ASCII,
versionNumber version=currentVersion,
compressionType compression=UNCOMPRESSED,
const bool append = false,
const bool valid = true
);
//- Destructor
~masterOFstream();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,160 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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::dummyISstream
Description
Dummy stream for input. Aborts at any attempt to read from it.
SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef dummyISstream_H
#define dummyISstream_H
#include "IStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dummyISstream Declaration
\*---------------------------------------------------------------------------*/
class dummyISstream
:
public IStringStream
{
public:
// Constructors
//- Construct null
dummyISstream()
:
IStringStream(string::null)
{}
//- Destructor
virtual ~dummyISstream()
{}
// Member functions
// Read functions
//- Return next token from stream
virtual Istream& read(token&)
{
NotImplemented;
return *this;
}
//- Read a character
virtual Istream& read(char&)
{
NotImplemented;
return *this;
}
//- Read a word
virtual Istream& read(word&)
{
NotImplemented;
return *this;
}
// Read a string (including enclosing double-quotes)
virtual Istream& read(string&)
{
NotImplemented;
return *this;
}
//- Read a label
virtual Istream& read(label&)
{
NotImplemented;
return *this;
}
//- Read a floatScalar
virtual Istream& read(floatScalar&)
{
NotImplemented;
return *this;
}
//- Read a doubleScalar
virtual Istream& read(doubleScalar&)
{
NotImplemented;
return *this;
}
//- Read binary block
virtual Istream& read(char*, std::streamsize)
{
NotImplemented;
return *this;
}
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind()
{
NotImplemented;
return *this;
}
//- Return flags of stream
virtual ios_base::fmtflags flags() const
{
NotImplemented;
return ios_base::fmtflags(0);
}
//- Set flags of stream
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
{
NotImplemented;
return f;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,161 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ 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::dummyIstream
Description
Dummy stream for input. Aborts at any attempt to read from it.
SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef dummyIstream_H
#define dummyIstream_H
#include "Istream.H"
//#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dummyIstream Declaration
\*---------------------------------------------------------------------------*/
class dummyIstream
:
public Istream
{
public:
// Constructors
//- Construct null
dummyIstream()
:
Istream()
{}
//- Destructor
~dummyIstream()
{}
// Member functions
// Read functions
//- Return next token from stream
virtual Istream& read(token&)
{
NotImplemented;
return *this;
}
//- Read a character
virtual Istream& read(char&)
{
NotImplemented;
return *this;
}
//- Read a word
virtual Istream& read(word&)
{
NotImplemented;
return *this;
}
// Read a string (including enclosing double-quotes)
virtual Istream& read(string&)
{
NotImplemented;
return *this;
}
//- Read a label
virtual Istream& read(label&)
{
NotImplemented;
return *this;
}
//- Read a floatScalar
virtual Istream& read(floatScalar&)
{
NotImplemented;
return *this;
}
//- Read a doubleScalar
virtual Istream& read(doubleScalar&)
{
NotImplemented;
return *this;
}
//- Read binary block
virtual Istream& read(char*, std::streamsize)
{
NotImplemented;
return *this;
}
//- Rewind and return the stream so that it may be read again
virtual Istream& rewind()
{
NotImplemented;
return *this;
}
//- Return flags of stream
virtual ios_base::fmtflags flags() const
{
NotImplemented;
return ios_base::fmtflags(0);
}
//- Set flags of stream
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
{
NotImplemented;
return f;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -29,6 +29,7 @@ License
#include "HashSet.H"
#include "profiling.H"
#include "demandDrivenData.H"
#include "IOdictionary.H"
#include <sstream>
@ -177,13 +178,12 @@ void Foam::Time::setControls()
// Check if time directory exists
// If not increase time precision to see if it is formatted differently.
if (!exists(timePath(), false))
if (!fileHandler().exists(timePath(), false))
{
int oldPrecision = precision_;
int requiredPrecision = -1;
bool found = false;
word oldTime(timeName());
for
(
precision_ = maxPrecision_;
@ -194,7 +194,6 @@ void Foam::Time::setControls()
// Update the time formatting
setTime(startTime_, 0);
// Check that the time name has changed otherwise exit loop
word newTime(timeName());
if (newTime == oldTime)
{
@ -203,7 +202,7 @@ void Foam::Time::setControls()
oldTime = newTime;
// Check the existence of the time directory with the new format
found = exists(timePath(), false);
found = fileHandler().exists(timePath(), false);
if (found)
{
@ -379,17 +378,8 @@ void Foam::Time::setMonitoring(const bool forceProfiling)
// Time objects not registered so do like objectRegistry::checkIn ourselves.
if (runTimeModifiable_)
{
monitorPtr_.reset
(
new fileMonitor
(
regIOobject::fileModificationChecking == inotify
|| regIOobject::fileModificationChecking == inotifyMaster
)
);
// Monitor all files that controlDict depends on
addWatches(controlDict_, controlDict_.files());
fileHandler().addWatches(controlDict_, controlDict_.files());
}
// Clear dependent files - not needed now
@ -685,7 +675,7 @@ Foam::Time::~Time()
forAllReverse(controlDict_.watchIndices(), i)
{
removeWatch(controlDict_.watchIndices()[i]);
fileHandler().removeWatch(controlDict_.watchIndices()[i]);
}
// Destroy function objects first
@ -698,86 +688,6 @@ Foam::Time::~Time()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::Time::addWatches(regIOobject& rio, const fileNameList& files) const
{
const labelList& watchIndices = rio.watchIndices();
DynamicList<label> newWatchIndices;
labelHashSet removedWatches(watchIndices);
forAll(files, i)
{
const fileName& f = files[i];
label index = findWatch(watchIndices, f);
if (index == -1)
{
newWatchIndices.append(addTimeWatch(f));
}
else
{
// Existing watch
newWatchIndices.append(watchIndices[index]);
removedWatches.erase(index);
}
}
// Remove any unused watches
forAllConstIter(labelHashSet, removedWatches, iter)
{
removeWatch(watchIndices[iter.key()]);
}
rio.watchIndices() = newWatchIndices;
}
Foam::label Foam::Time::findWatch
(
const labelList& watchIndices,
const fileName& fName
) const
{
forAll(watchIndices, i)
{
if (getFile(watchIndices[i]) == fName)
{
return i;
}
}
return -1;
}
Foam::label Foam::Time::addTimeWatch(const fileName& fName) const
{
return monitorPtr_().addWatch(fName);
}
bool Foam::Time::removeWatch(const label watchIndex) const
{
return monitorPtr_().removeWatch(watchIndex);
}
const Foam::fileName& Foam::Time::getFile(const label watchIndex) const
{
return monitorPtr_().getFile(watchIndex);
}
Foam::fileMonitor::fileState Foam::Time::getState(const label watchIndex) const
{
return monitorPtr_().getState(watchIndex);
}
void Foam::Time::setUnmodified(const label watchIndex) const
{
monitorPtr_().setUnmodified(watchIndex);
}
Foam::word Foam::Time::timeName(const scalar t, const int precision)
{
std::ostringstream buf;
@ -806,26 +716,22 @@ Foam::word Foam::Time::findInstancePath
const instant& t
) const
{
// Read directory entries into a list
fileNameList dirEntries(readDir(directory, fileName::DIRECTORY));
// Simplified version: use findTimes (readDir + sort). The expensive
// bit is the readDir, not the sorting. Tbd: avoid calling findInstancePath
// from filePath.
forAll(dirEntries, i)
{
scalar timeValue;
if (readScalar(dirEntries[i].c_str(), timeValue) && t.equal(timeValue))
{
return dirEntries[i];
}
}
instantList timeDirs = findTimes(path(), constant());
// Note:
// - times will include constant (with value 0) as first element.
// For backwards compatibility make sure to find 0 in preference
// to constant.
// - list is sorted so could use binary search
if (t.equal(0.0))
forAllReverse(timeDirs, i)
{
const word& constantName = constant();
// Looking for 0 or constant. 0 already checked above.
if (isDir(directory/constantName))
if (t.equal(timeDirs[i].value()))
{
return constantName;
return timeDirs[i].name();
}
}
@ -1030,6 +936,7 @@ void Foam::Time::setTime(const Time& t)
value() = t.value();
dimensionedScalar::name() = t.dimensionedScalar::name();
timeIndex_ = t.timeIndex_;
fileHandler().setTime(*this);
}
@ -1056,6 +963,7 @@ void Foam::Time::setTime(const instant& inst, const label newIndex)
timeDict.readIfPresent("deltaT", deltaT_);
timeDict.readIfPresent("deltaT0", deltaT0_);
timeDict.readIfPresent("index", timeIndex_);
fileHandler().setTime(*this);
}
@ -1070,6 +978,7 @@ void Foam::Time::setTime(const scalar newTime, const label newIndex)
value() = newTime;
dimensionedScalar::name() = timeName(timeToUserTime(newTime));
timeIndex_ = newIndex;
fileHandler().setTime(*this);
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -51,7 +51,6 @@ SourceFiles
#include "typeInfo.H"
#include "dlLibraryTable.H"
#include "functionObjectList.H"
#include "fileMonitor.H"
#include "sigWriteNow.H"
#include "sigStopAtWriteNow.H"
@ -78,9 +77,6 @@ class Time
{
// Private data
//- file-change monitor for all registered files
mutable autoPtr<fileMonitor> monitorPtr_;
//- Profiling trigger for time-loop (for run, loop)
mutable profilingTrigger* loopProfiling_;
@ -182,6 +178,9 @@ protected:
//- Read the control dictionary and set the write controls etc.
virtual void readDict();
//- Find IOobject in the objectPath
static bool exists(IOobject&);
private:
@ -331,41 +330,9 @@ public:
//- Read control dictionary, update controls and time
virtual bool read();
// Automatic rereading
//- Read the objects that have been modified
void readModifiedObjects();
//- Helper: add watches for list of files
void addWatches
(
regIOobject& rio,
const fileNameList& files
) const;
//- Find index (or -1) of file in list of handles
label findWatch
(
const labelList& watchIndices,
const fileName& fName
) const;
//- Add watching of a file. Returns handle
label addTimeWatch(const fileName& fName) const;
//- Remove watch on a file (using handle)
bool removeWatch(const label watchIndex) const;
//- Get name of file being watched (using handle)
const fileName& getFile(const label watchIndex) const;
//- Get current state of file (using handle)
fileMonitor::fileState getState(const label watchIndex) const;
//- Set current state of file (using handle) to unmodified
void setUnmodified(const label watchIndex) const;
//- Return the location of "dir" containing the file "name".
// (eg, used in reading mesh data)
// If name is null, search for the directory "dir" only.
@ -410,9 +377,10 @@ public:
//- Write using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
const bool valid
) const;
//- Write the objects now (not at end of iteration) and continue

View File

@ -28,6 +28,8 @@ License
#include "simpleObjectRegistry.H"
#include "dimensionedConstants.H"
#include "profiling.H"
#include "IOdictionary.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -127,6 +129,43 @@ void Foam::Time::readDict()
}
}
}
// Handle fileHandler override explicitly since interacts with
// local dictionary monitoring.
word fileHandlerName;
if
(
localSettings.readIfPresent("fileHandler", fileHandlerName)
&& fileHandler().type() != fileHandlerName
)
{
// Remove the old watches since destroying the file
fileNameList oldWatchedFiles(controlDict_.watchIndices());
forAllReverse(controlDict_.watchIndices(), i)
{
label watchi = controlDict_.watchIndices()[i];
oldWatchedFiles[i] = fileHandler().getFile(watchi);
fileHandler().removeWatch(watchi);
}
controlDict_.watchIndices().clear();
// Installing the new handler
Info<< "Overriding fileHandler to " << fileHandlerName << endl;
autoPtr<fileOperation> handler
(
fileOperation::New
(
fileHandlerName,
true
)
);
Foam::fileHandler(handler);
// Reinstall old watches
fileHandler().addWatches(controlDict_, oldWatchedFiles);
}
}
@ -368,11 +407,12 @@ void Foam::Time::readDict()
controlDict_.readIfPresent("graphFormat", graphFormat_);
controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
if (!runTimeModifiable_ && controlDict_.watchIndices().size())
{
forAllReverse(controlDict_.watchIndices(), i)
{
removeWatch(controlDict_.watchIndices()[i]);
fileHandler().removeWatch(controlDict_.watchIndices()[i]);
}
controlDict_.watchIndices().clear();
}
@ -393,7 +433,7 @@ bool Foam::Time::read()
// already updated all the watchIndices via the addWatch but
// controlDict_ is an unwatchedIOdictionary so will only have
// stored the dependencies as files.
addWatches(controlDict_, controlDict_.files());
fileHandler().addWatches(controlDict_, controlDict_.files());
}
controlDict_.files().clear();
@ -414,7 +454,7 @@ void Foam::Time::readModifiedObjects()
// valid filePath).
// Note: requires same ordering in objectRegistries on different
// processors!
monitorPtr_().updateStates
fileHandler().updateStates
(
(
regIOobject::fileModificationChecking == inotifyMaster
@ -437,7 +477,7 @@ void Foam::Time::readModifiedObjects()
// controlDict_ is an unwatchedIOdictionary so will only have
// stored the dependencies as files.
addWatches(controlDict_, controlDict_.files());
fileHandler().addWatches(controlDict_, controlDict_.files());
}
controlDict_.files().clear();
}
@ -482,7 +522,8 @@ bool Foam::Time::writeTimeDict() const
(
IOstream::ASCII,
IOstream::currentVersion,
IOstream::UNCOMPRESSED
IOstream::UNCOMPRESSED,
true
);
}
@ -491,7 +532,8 @@ bool Foam::Time::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const
{
if (writeTime())
@ -500,7 +542,7 @@ bool Foam::Time::writeObject
if (writeOK)
{
writeOK = objectRegistry::writeObject(fmt, ver, cmp);
writeOK = objectRegistry::writeObject(fmt, ver, cmp, valid);
}
if (writeOK)

View File

@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,6 +35,49 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool Foam::Time::exists(IOobject& io)
{
// Generate filename for object
fileName objPath(fileHandler().objectPath(io, word::null));
// Test for either directory or a (valid) file & IOobject
bool ok;
if (io.name().empty())
{
ok = fileHandler().isDir(objPath);
}
else
{
ok =
fileHandler().isFile(objPath)
&& io.typeHeaderOk<IOList<label>>(false);// object with local scope
}
if (!ok)
{
// Re-test with raw objectPath. This is for backwards
// compatibility
fileName originalPath(io.objectPath());
if (originalPath != objPath)
{
// Test for either directory or a (valid) file & IOobject
if (io.name().empty())
{
ok = fileHandler().isDir(originalPath);
}
else
{
ok =
fileHandler().isFile(originalPath)
&& io.typeHeaderOk<IOList<label>>(false);
}
}
}
return ok;
}
Foam::word Foam::Time::findInstance
(
const fileName& dir,
@ -44,40 +87,33 @@ Foam::word Foam::Time::findInstance
) const
{
// Note: - if name is empty, just check the directory itself
// - check both for isFile and headerOk since the latter does a
// filePath so searches for the file.
// - check for an object with local file scope (so no looking up in
// parent directory in case of parallel)
const fileName tPath(path());
const fileName dirPath(tPath/timeName()/dir);
// check the current time directory
if
{
IOobject io
(
name.empty()
? isDir(dirPath)
:
(
isFile(dirPath/name)
&& IOobject
(
name,
name, // name might be empty!
timeName(),
dir,
*this
).typeHeaderOk<IOList<label>>(false) // use object with local scope
)
)
);
if (exists(io))
{
if (debug)
{
InfoInFunction
<< "Found \"" << name
<< "Found exact match for \"" << name
<< "\" in " << timeName()/dir
<< endl;
}
return timeName();
}
}
// Search back through the time directories to find the time
// closest to and lower than current time
@ -96,27 +132,20 @@ Foam::word Foam::Time::findInstance
// continue searching from here
for (; instanceI >= 0; --instanceI)
{
if
IOobject io
(
name.empty()
? isDir(tPath/ts[instanceI].name()/dir)
:
(
isFile(tPath/ts[instanceI].name()/dir/name)
&& IOobject
(
name,
name, // name might be empty!
ts[instanceI].name(),
dir,
*this
).typeHeaderOk<IOList<label>>(false)
)
)
);
if (exists(io))
{
if (debug)
{
InfoInFunction
<< "Found \"" << name
<< "Found instance match for \"" << name
<< "\" in " << ts[instanceI].name()/dir
<< endl;
}
@ -129,7 +158,8 @@ Foam::word Foam::Time::findInstance
{
if (debug)
{
InfoInFunction
//InfoInFunction
Pout<< "findInstance : "
<< "Hit stopInstance " << stopInstance
<< endl;
}
@ -169,27 +199,20 @@ Foam::word Foam::Time::findInstance
// constant function of the time, because the latter points to
// the case constant directory in parallel cases
if
(
name.empty()
? isDir(tPath/constant()/dir)
:
(
isFile(tPath/constant()/dir/name)
&& IOobject
IOobject io
(
name,
constant(),
dir,
*this
).typeHeaderOk<IOList<label>>(false)
)
)
);
if (exists(io))
{
if (debug)
{
InfoInFunction
<< "Found \"" << name
<< "Found constant match for \"" << name
<< "\" in " << constant()/dir
<< endl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -40,62 +40,8 @@ Foam::instantList Foam::Time::findTimes
const word& constantName
)
{
if (debug)
{
InfoInFunction << "Finding times in directory " << directory << endl;
return fileHandler().findTimes(directory, constantName);
}
// Read directory entries into a list
fileNameList dirEntries(readDir(directory, fileName::DIRECTORY));
// Initialise instant list
instantList Times(dirEntries.size() + 1);
label nTimes = 0;
// Check for "constant"
bool haveConstant = false;
forAll(dirEntries, i)
{
if (dirEntries[i] == constantName)
{
Times[nTimes].value() = 0;
Times[nTimes].name() = dirEntries[i];
nTimes++;
haveConstant = true;
break;
}
}
// Read and parse all the entries in the directory
forAll(dirEntries, i)
{
IStringStream timeStream(dirEntries[i]);
token timeToken(timeStream);
if (timeToken.isNumber() && timeStream.eof())
{
Times[nTimes].value() = timeToken.number();
Times[nTimes].name() = dirEntries[i];
nTimes++;
}
}
// Reset the length of the times list
Times.setSize(nTimes);
if (haveConstant)
{
if (nTimes > 2)
{
std::sort(&Times[1], Times.end(), instant::less());
}
}
else if (nTimes > 1)
{
std::sort(&Times[0], Times.end(), instant::less());
}
return Times;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -76,6 +76,18 @@ bool Foam::operator!=(const instant& a, const instant& b)
}
bool Foam::operator<(const instant& a, const instant& b)
{
return a.value_ < b.value_;
}
bool Foam::operator>(const instant& a, const instant& b)
{
return a.value_ > b.value_;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, instant& I)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -51,6 +51,8 @@ class instant;
bool operator==(const instant&, const instant&);
bool operator!=(const instant&, const instant&);
bool operator<(const instant&, const instant&);
bool operator>(const instant&, const instant&);
// IOstream Operators
@ -141,6 +143,8 @@ public:
friend bool operator==(const instant&, const instant&);
friend bool operator!=(const instant&, const instant&);
friend bool operator<(const instant&, const instant&);
friend bool operator>(const instant&, const instant&);
// IOstream Operators

View File

@ -325,7 +325,12 @@ Foam::instantList Foam::timeSelector::select
forAll(timeDirs, timeI)
{
selectTimes[timeI] =
!exists(runTime.path()/timeDirs[timeI].name()/fName);
!fileHandler().exists
(
runTime.path()
/timeDirs[timeI].name()
/fName
);
}
return subset(selectTimes, timeDirs);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -25,6 +25,7 @@ License
#include "dictionary.H"
#include "IFstream.H"
#include "regExp.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,6 +28,8 @@ License
#include "addToMemberFunctionSelectionTable.H"
#include "stringOps.H"
#include "Time.H"
#include "IOstreams.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -113,10 +115,8 @@ bool Foam::functionEntries::includeEntry::execute
{
const fileName rawName(is);
const fileName fName = resolveFile(is.name().path(), rawName, parentDict);
// Read contents of file into parentDict
IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{
@ -166,9 +166,8 @@ bool Foam::functionEntries::includeEntry::execute
{
const fileName rawName(is);
const fileName fName = resolveFile(is.name().path(), rawName, parentDict);
// Read contents of file into parentDict
IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,9 +25,10 @@ License
#include "includeEtcEntry.H"
#include "etcFiles.H"
#include "IFstream.H"
#include "stringOps.H"
#include "addToMemberFunctionSelectionTable.H"
#include "IOstreams.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -92,7 +93,10 @@ bool Foam::functionEntries::includeEtcEntry::execute
{
const fileName rawName(is);
const fileName fName(resolveFile(rawName, parentDict));
IFstream ifs(fName);
//IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{
@ -127,7 +131,10 @@ bool Foam::functionEntries::includeEtcEntry::execute
{
const fileName rawName(is);
const fileName fName(resolveFile(rawName, parentDict));
IFstream ifs(fName);
//IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -28,6 +28,7 @@ License
#include "IFstream.H"
#include "regIOobject.H"
#include "addToMemberFunctionSelectionTable.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -64,7 +65,8 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
)
{
const fileName fName(resolveFile(is, parentDict));
IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{
@ -99,7 +101,8 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
)
{
const fileName fName(resolveFile(is, parentDict));
IFstream ifs(fName);
autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
ISstream& ifs = ifsPtr();
if (ifs)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -65,7 +65,11 @@ Foam::dlLibraryTable::~dlLibraryTable()
<< "Closing " << libNames_[i]
<< " with handle " << uintptr_t(libPtrs_[i]) << endl;
}
dlClose(libPtrs_[i]);
if (!dlClose(libPtrs_[i]))
{
WarningInFunction<< "Failed closing " << libNames_[i]
<< " with handle " << uintptr_t(libPtrs_[i]) << endl;
}
}
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -29,11 +29,12 @@ License
#include "profiling.H"
#include "argList.H"
#include "timeControlFunctionObject.H"
#include "IFstream.H"
//#include "IFstream.H"
#include "dictionaryEntry.H"
#include "stringOps.H"
#include "Tuple2.H"
#include "etcFiles.H"
#include "IOdictionary.H"
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
@ -103,7 +104,7 @@ void Foam::functionObjectList::listDir
{
// Search specified directory for functionObject configuration files
{
fileNameList foFiles(readDir(dir));
fileNameList foFiles(fileHandler().readDir(dir));
forAll(foFiles, f)
{
if (foFiles[f].ext().empty())
@ -115,7 +116,7 @@ void Foam::functionObjectList::listDir
// Recurse into sub-directories
{
fileNameList foDirs(readDir(dir, fileName::DIRECTORY));
fileNameList foDirs(fileHandler().readDir(dir, fileName::DIRECTORY));
forAll(foDirs, fd)
{
listDir(dir/foDirs[fd], foMap);
@ -278,7 +279,10 @@ bool Foam::functionObjectList::readFunctionObject
}
// Read the functionObject dictionary
IFstream fileStream(path);
//IFstream fileStream(path);
autoPtr<ISstream> fileStreamPtr(fileHandler().NewIFstream(path));
ISstream& fileStream = fileStreamPtr();
dictionary funcsDict(fileStream);
dictionary* funcDictPtr = &funcsDict;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -73,6 +73,9 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
}
}
// Remove any ".."
baseDir.clean();
return baseDir;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
@ -354,7 +354,8 @@ bool Foam::objectRegistry::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const
{
bool ok = true;
@ -374,7 +375,7 @@ bool Foam::objectRegistry::writeObject
if (iter()->writeOpt() != NO_WRITE)
{
ok = iter()->writeObject(fmt, ver, cmp) && ok;
ok = iter()->writeObject(fmt, ver, cmp, valid) && ok;
}
}

View File

@ -333,7 +333,8 @@ public:
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const;
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,6 +27,7 @@ License
#include "Time.H"
#include "polyMesh.H"
#include "registerSwitch.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -46,6 +47,7 @@ registerOptSwitch
Foam::regIOobject::fileModificationSkew
);
bool Foam::regIOobject::masterOnlyReading = false;
@ -62,8 +64,7 @@ Foam::regIOobject::regIOobject(const IOobject& io, const bool isTime)
isTime
? 0
: db().getEvent()
),
isPtr_(nullptr)
)
{
// Register with objectRegistry if requested
if (registerObject())
@ -156,12 +157,6 @@ Foam::regIOobject::~regIOobject()
<< endl;
}
if (isPtr_)
{
delete isPtr_;
isPtr_ = nullptr;
}
// Check out of objectRegistry if not owned by the registry
if (!ownedByRegistry_)
{
@ -216,7 +211,7 @@ bool Foam::regIOobject::checkOut()
forAllReverse(watchIndices_, i)
{
time().removeWatch(watchIndices_[i]);
fileHandler().removeWatch(watchIndices_[i]);
}
watchIndices_.clear();
return db().checkOut(*this);
@ -237,12 +232,12 @@ Foam::label Foam::regIOobject::addWatch(const fileName& f)
&& time().runTimeModifiable()
)
{
index = time().findWatch(watchIndices_, f);
index = fileHandler().findWatch(watchIndices_, f);
if (index == -1)
{
index = watchIndices_.size();
watchIndices_.append(time().addTimeWatch(f));
watchIndices_.append(fileHandler().addWatch(f));
}
}
return index;
@ -266,7 +261,7 @@ void Foam::regIOobject::addWatch()
f = objectPath();
}
label index = time().findWatch(watchIndices_, f);
label index = fileHandler().findWatch(watchIndices_, f);
if (index != -1)
{
FatalErrorInFunction
@ -293,7 +288,7 @@ void Foam::regIOobject::addWatch()
watchFiles.setSize(watchIndices_.size());
forAll(watchIndices_, i)
{
watchFiles[i] = time().getFile(watchIndices_[i]);
watchFiles[i] = fileHandler().getFile(watchIndices_[i]);
}
}
Pstream::scatter(watchFiles);
@ -303,18 +298,18 @@ void Foam::regIOobject::addWatch()
// unregister current ones
forAllReverse(watchIndices_, i)
{
time().removeWatch(watchIndices_[i]);
fileHandler().removeWatch(watchIndices_[i]);
}
watchIndices_.clear();
forAll(watchFiles, i)
{
watchIndices_.append(time().addTimeWatch(watchFiles[i]));
watchIndices_.append(fileHandler().addWatch(watchFiles[i]));
}
}
}
addWatch(f);
watchIndices_.append(fileHandler().addWatch(f));
}
}
@ -416,64 +411,35 @@ void Foam::regIOobject::rename(const word& newName)
Foam::fileName Foam::regIOobject::filePath() const
{
return localFilePath();
}
Foam::Istream* Foam::regIOobject::objectStream()
{
return IOobject::objectStream(filePath());
return localFilePath(type());
}
bool Foam::regIOobject::headerOk()
{
// Note: Should be consistent with IOobject::typeHeaderOk(false)
bool ok = true;
Istream* isPtr = objectStream();
fileName fName(filePath());
// If the stream has failed return
if (!isPtr)
{
if (objectRegistry::debug)
{
Info
<< "regIOobject::headerOk() : "
<< "file " << objectPath() << " could not be opened"
<< endl;
}
ok = Foam::fileHandler().readHeader(*this, fName, type());
ok = false;
}
else
if (!ok && IOobject::debug)
{
// Try reading header
if (!readHeader(*isPtr))
{
if (objectRegistry::debug)
{
IOWarningInFunction(*isPtr)
IOWarningInFunction(fName)
<< "failed to read header of file " << objectPath()
<< endl;
}
ok = false;
}
}
delete isPtr;
return ok;
}
void Foam::regIOobject::operator=(const IOobject& io)
{
if (isPtr_)
{
delete isPtr_;
isPtr_ = nullptr;
}
// Close any file
isPtr_.clear();
// Check out of objectRegistry
checkOut();

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -52,6 +52,11 @@ namespace functionEntries
{
class codeStream;
}
namespace fileOperations
{
class uncollatedFileOperation;
class masterUncollatedFileOperation;
}
/*---------------------------------------------------------------------------*\
Class regIOobject Declaration
@ -61,25 +66,14 @@ class regIOobject
:
public IOobject
{
protected:
//- Read everywhere or only on master and scatter
bool read
(
const bool masterOnly,
const IOstream::streamFormat PstreamFormat,
const word& typeName
);
public:
//- Check readOpt flags and read if necessary. Uses above read
//- Helper: check readOpt flags and read if necessary
bool readHeaderOk
(
const IOstream::streamFormat PstreamFormat,
const word& typeName
);
protected:
//- Construct and return an IFstream for the object.
// The results is NULL if the stream construction failed
@ -106,13 +100,13 @@ private:
label eventNo_;
//- Istream for reading
Istream* isPtr_;
autoPtr<ISstream> isPtr_;
// Private Member Functions
//- Return Istream
Istream& readStream();
Istream& readStream(const bool valid = true);
//- Dissallow assignment
void operator=(const regIOobject&);
@ -123,6 +117,8 @@ public:
//- Declare friendship with any classes that need access to
// masterOnlyReading
friend class functionEntries::codeStream;
friend class fileOperations::uncollatedFileOperation;
friend class fileOperations::masterUncollatedFileOperation;
// Static data
@ -252,7 +248,7 @@ public:
bool headerOk();
//- Return Istream and check object type against that given
Istream& readStream(const word&);
Istream& readStream(const word&, const bool valid = true);
//- Close Istream
void close();
@ -294,11 +290,12 @@ public:
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType
IOstream::compressionType,
const bool valid
) const;
//- Write using setting from DB
virtual bool write() const;
virtual bool write(const bool valid = true) const;
// Other

View File

@ -28,112 +28,10 @@ License
#include "Time.H"
#include "Pstream.H"
#include "HashSet.H"
#include "fileOperation.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::regIOobject::read
(
const bool masterOnly,
const IOstream::streamFormat format,
const word& typeName
)
{
bool ok = true;
if (Pstream::master() || !masterOnly)
{
if (IFstream::debug)
{
Pout<< "regIOobject::read() : "
<< "reading object " << name()
<< " from file " << endl;
}
// Set flag for e.g. codeStream
const bool oldGlobal = globalObject();
globalObject() = masterOnly;
// If codeStream originates from dictionary which is
// not IOdictionary we have a problem so use global
const bool oldFlag = regIOobject::masterOnlyReading;
regIOobject::masterOnlyReading = masterOnly;
// Read file
ok = readData(readStream(typeName));
close();
// Restore flags
globalObject() = oldGlobal;
regIOobject::masterOnlyReading = oldFlag;
}
if (masterOnly && Pstream::parRun())
{
// Scatter master data using communication scheme
const List<Pstream::commsStruct>& comms =
(
(Pstream::nProcs() < Pstream::nProcsSimpleSum)
? Pstream::linearCommunication()
: Pstream::treeCommunication()
);
// Master reads headerclassname from file. Make sure this gets
// transfered as well as contents.
Pstream::scatter
(
comms,
const_cast<word&>(headerClassName()),
Pstream::msgType(),
Pstream::worldComm
);
Pstream::scatter(comms, note(), Pstream::msgType(), Pstream::worldComm);
// Get my communication order
const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()];
// Reveive from up
if (myComm.above() != -1)
{
if (IFstream::debug)
{
Pout<< "regIOobject::read() : "
<< "reading object " << name()
<< " from processor " << myComm.above()
<< endl;
}
IPstream fromAbove
(
Pstream::commsTypes::scheduled,
myComm.above(),
0,
Pstream::msgType(),
Pstream::worldComm,
format
);
ok = readData(fromAbove);
}
// Send to my downstairs neighbours
forAllReverse(myComm.below(), belowI)
{
OPstream toBelow
(
Pstream::commsTypes::scheduled,
myComm.below()[belowI],
0,
Pstream::msgType(),
Pstream::worldComm,
format
);
bool okWrite = writeData(toBelow);
ok = ok && okWrite;
}
}
return ok;
}
bool Foam::regIOobject::readHeaderOk
(
const IOstream::streamFormat format,
@ -176,7 +74,7 @@ bool Foam::regIOobject::readHeaderOk
|| isHeaderOk
)
{
return regIOobject::read(masterOnly, format, typeName);
return fileHandler().read(*this, masterOnly, format, typeName);
}
else
{
@ -184,9 +82,10 @@ bool Foam::regIOobject::readHeaderOk
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::Istream& Foam::regIOobject::readStream()
Foam::Istream& Foam::regIOobject::readStream(const bool valid)
{
if (IFstream::debug)
{
@ -206,13 +105,13 @@ Foam::Istream& Foam::regIOobject::readStream()
}
// Construct object stream and read header if not already constructed
if (!isPtr_)
if (!isPtr_.valid())
{
fileName objPath;
if (watchIndices_.size())
{
// File is being watched. Read exact file that is being watched.
objPath = time().getFile(watchIndices_.last());
objPath = fileHandler().getFile(watchIndices_.last());
}
else
{
@ -227,72 +126,47 @@ Foam::Istream& Foam::regIOobject::readStream()
<< " in file " << objPath
<< endl;
}
}
if (!objPath.size())
{
FatalIOError
isPtr_ = fileHandler().readStream(*this, objPath, type(), valid);
}
return isPtr_();
}
Foam::Istream& Foam::regIOobject::readStream
(
"regIOobject::readStream()",
__FILE__,
__LINE__,
objectPath(),
0
) << "cannot find file"
<< exit(FatalIOError);
}
}
if (!(isPtr_ = IOobject::objectStream(objPath)))
{
FatalIOError
(
"regIOobject::readStream()",
__FILE__,
__LINE__,
objPath,
0
) << "cannot open file"
<< exit(FatalIOError);
}
else if (!readHeader(*isPtr_))
{
FatalIOErrorInFunction(*isPtr_)
<< "problem while reading header for object " << name()
<< exit(FatalIOError);
}
}
return *isPtr_;
}
Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
const word& expectName,
const bool valid
)
{
if (IFstream::debug)
{
Pout<< "regIOobject::readStream(const word&) : "
<< "reading object " << name()
<< " of type " << type()
<< " from file " << objectPath()
<< " from file " << filePath()
<< endl;
}
// Construct IFstream if not already constructed
if (!isPtr_)
if (!isPtr_.valid())
{
readStream();
readStream(valid);
// Check the className of the regIOobject
// dictionary is an allowable name in case the actual class
// instantiated is a dictionary
if
(
expectName.size()
valid
&& expectName.size()
&& headerClassName() != expectName
&& headerClassName() != "dictionary"
)
{
FatalIOErrorInFunction(*isPtr_)
FatalIOErrorInFunction(isPtr_())
<< "unexpected class name " << headerClassName()
<< " expected " << expectName << endl
<< " while reading object " << name()
@ -300,7 +174,7 @@ Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
}
}
return *isPtr_;
return isPtr_();
}
@ -309,15 +183,11 @@ void Foam::regIOobject::close()
if (IFstream::debug)
{
Pout<< "regIOobject::close() : "
<< "finished reading " << filePath()
<< "finished reading " << isPtr_().name()
<< endl;
}
if (isPtr_)
{
delete isPtr_;
isPtr_ = nullptr;
}
isPtr_.clear();
}
@ -341,11 +211,11 @@ bool Foam::regIOobject::read()
oldWatchFiles.setSize(watchIndices_.size());
forAll(watchIndices_, i)
{
oldWatchFiles[i] = time().getFile(watchIndices_[i]);
oldWatchFiles[i] = fileHandler().getFile(watchIndices_[i]);
}
forAllReverse(watchIndices_, i)
{
time().removeWatch(watchIndices_[i]);
fileHandler().removeWatch(watchIndices_[i]);
}
watchIndices_.clear();
}
@ -359,7 +229,9 @@ bool Foam::regIOobject::read()
|| regIOobject::fileModificationChecking == inotifyMaster
);
bool ok = read(masterOnly, IOstream::BINARY, type());
// Note: IOstream::binary flag is for all the processor comms. (Only for
// dictionaries should it be ascii)
bool ok = fileHandler().read(*this, masterOnly, IOstream::BINARY, type());
if (oldWatchFiles.size())
{
@ -375,7 +247,7 @@ bool Foam::regIOobject::modified() const
{
forAllReverse(watchIndices_, i)
{
if (time().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
if (fileHandler().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
{
return true;
}
@ -392,7 +264,7 @@ bool Foam::regIOobject::readIfModified()
label modified = -1;
forAllReverse(watchIndices_, i)
{
if (time().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
if (fileHandler().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
{
modified = watchIndices_[i];
break;
@ -401,7 +273,7 @@ bool Foam::regIOobject::readIfModified()
if (modified != -1)
{
const fileName& fName = time().getFile(watchIndices_.last());
const fileName fName = fileHandler().getFile(watchIndices_.last());
if (modified == watchIndices_.last())
{
@ -414,7 +286,8 @@ bool Foam::regIOobject::readIfModified()
InfoInFunction
<< " Re-reading object " << name()
<< " from file " << fName
<< " because of modified file " << time().getFile(modified)
<< " because of modified file "
<< fileHandler().getFile(modified)
<< endl;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,7 +37,8 @@ bool Foam::regIOobject::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::compressionType cmp,
const bool valid
) const
{
if (!good())
@ -113,33 +114,34 @@ bool Foam::regIOobject::writeObject
if (Pstream::master() || !masterOnly)
{
if (mkDir(path()))
{
// Try opening an OFstream for object
OFstream os(objectPath(), fmt, ver, cmp);
// If any of these fail, return (leave error handling to Ostream
// class)
if (!os.good())
{
return false;
}
if (!writeHeader(os))
{
return false;
}
// Write the data to the Ostream
if (!writeData(os))
{
return false;
}
writeEndDivider(os);
osGood = os.good();
}
//if (mkDir(path()))
//{
// // Try opening an OFstream for object
// OFstream os(objectPath(), fmt, ver, cmp);
//
// // If any of these fail, return (leave error handling to Ostream
// // class)
// if (!os.good())
// {
// return false;
// }
//
// if (!writeHeader(os))
// {
// return false;
// }
//
// // Write the data to the Ostream
// if (!writeData(os))
// {
// return false;
// }
//
// writeEndDivider(os);
//
// osGood = os.good();
//}
osGood = fileHandler().writeObject(*this, fmt, ver, cmp, valid);
}
else
{
@ -156,20 +158,21 @@ bool Foam::regIOobject::writeObject
// i.e. lastModified_ is already set
if (watchIndices_.size())
{
time().setUnmodified(watchIndices_.last());
fileHandler().setUnmodified(watchIndices_.last());
}
return osGood;
}
bool Foam::regIOobject::write() const
bool Foam::regIOobject::write(const bool valid) const
{
return writeObject
(
time().writeFormat(),
IOstream::currentVersion,
time().writeCompression()
time().writeCompression(),
valid
);
}

View File

@ -26,6 +26,7 @@ License
#include "GeometricField.H"
#include "Time.H"
#include "demandDrivenData.H"
#include "dictionary.H"
#include "localIOdictionary.H"
#include "data.H"
@ -76,13 +77,14 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::readFields()
IOobject
(
this->name(),
this->time().timeName(),
this->instance(),
this->local(),
this->db(),
IOobject::NO_READ,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
this->readStream(typeName)
typeName
);
this->close();

Some files were not shown because too many files have changed in this diff Show More