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

@ -9,7 +9,7 @@ IOobject phiBHeader
surfaceScalarField* phiBPtr = nullptr; surfaceScalarField* phiBPtr = nullptr;
if (phiBHeader.typeHeaderOk<surfaceScalarField>(true)) if (phiBHeader.typeHeaderOk<surfaceScalarField>(true))
{ {
Info<< "Reading face flux "; Info<< "Reading face flux ";

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -87,7 +87,8 @@ int main(int argc, char *argv[])
( (
format, format,
IOstream::currentVersion, IOstream::currentVersion,
IOstream::UNCOMPRESSED IOstream::UNCOMPRESSED,
true
); );
Info<< "Written old format faceList in = " Info<< "Written old format faceList in = "
@ -149,7 +150,8 @@ int main(int argc, char *argv[])
( (
format, format,
IOstream::currentVersion, IOstream::currentVersion,
IOstream::UNCOMPRESSED IOstream::UNCOMPRESSED,
true
); );
Info<< "Written new format faceList in = " 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<< "surfIn = " << surfIn.size() << endl;
Info<< "writing surfMesh as obj = oldSurfIn.obj" << 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; Info<< "runTime.instance() = " << runTime.instance() << endl;
@ -550,7 +552,7 @@ int main(int argc, char *argv[])
surfOut.write(); surfOut.write();
// write directly // write directly
surfOut.write("someName.ofs"); surfOut.surfMesh::write(fileName("someName.ofs"));
#if 1 #if 1
const surfZoneList& zones = surfOut.surfZones(); const surfZoneList& zones = surfOut.surfZones();

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -28,6 +28,7 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "Ostream.H" #include "Ostream.H"
#include "twoDPointCorrector.H" #include "twoDPointCorrector.H"
#include "IOdictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -143,10 +144,8 @@ Foam::scalar Foam::edgeStats::minLen(Ostream& os) const
const edgeList& edges = mesh_.edges(); const edgeList& edges = mesh_.edges();
forAll(edges, edgeI) forAll(const edge& e : edges)
{ {
const edge& e = edges[edgeI];
vector eVec(e.vec(mesh_.points())); vector eVec(e.vec(mesh_.points()));
scalar eMag = mag(eVec); 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -57,6 +57,7 @@ See also
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "STARCDMeshWriter.H" #include "STARCDMeshWriter.H"
#include "IOdictionary.H"
using namespace Foam; using namespace Foam;
@ -134,4 +135,5 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
// ************************************************************************* // // ************************************************************************* //

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -52,6 +52,7 @@ Description
#include "faceZoneSet.H" #include "faceZoneSet.H"
#include "pointZoneSet.H" #include "pointZoneSet.H"
#include "timeSelector.H" #include "timeSelector.H"
#include "collatedFileOperation.H"
#include <stdio.h> #include <stdio.h>
@ -743,6 +744,11 @@ commandStatus parseAction(const word& actionName)
int main(int argc, char *argv[]) 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); timeSelector::addOptions(true, false);
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addBoolOption("noVTK", "do not write VTK files"); argList::addBoolOption("noVTK", "do not write VTK files");

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -42,6 +42,8 @@ Description
#include "cellZoneSet.H" #include "cellZoneSet.H"
#include "faceZoneSet.H" #include "faceZoneSet.H"
#include "pointZoneSet.H" #include "pointZoneSet.H"
#include "IOdictionary.H"
#include "collatedFileOperation.H"
using namespace Foam; using namespace Foam;
@ -194,6 +196,11 @@ polyMesh::readUpdateState meshReadUpdate(polyMesh& mesh)
int main(int argc, char *argv[]) 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); timeSelector::addOptions(true, false);
#include "addDictOption.H" #include "addDictOption.H"
#include "addRegionOption.H" #include "addRegionOption.H"

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,9 +62,19 @@ Usage
#include "cellIOList.H" #include "cellIOList.H"
#include "IOobjectList.H" #include "IOobjectList.H"
#include "IOPtrList.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 "writeMeshObject.H"
#include "fieldDictionary.H"
using namespace Foam; using namespace Foam;
@ -143,7 +153,8 @@ bool writeZones(const word& name, const fileName& meshDir, Time& runTime)
( (
IOstream::ASCII, IOstream::ASCII,
IOstream::currentVersion, 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[]) int main(int argc, char *argv[])
@ -183,6 +263,8 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
// Optional mesh (used to read Clouds)
autoPtr<polyMesh> meshPtr;
const bool enableEntries = args.optionFound("enableFunctionEntries"); const bool enableEntries = args.optionFound("enableFunctionEntries");
if (enableEntries) if (enableEntries)
@ -221,11 +303,24 @@ int main(int argc, char *argv[])
Info<< "Time = " << runTime.timeName() << endl; Info<< "Time = " << runTime.timeName() << endl;
// Convert all the standard mesh files // Convert all the standard mesh files
writeMeshObject<cellCompactIOList>("cells", meshDir, runTime); writeMeshObject<cellCompactIOList, cellIOList>
(
"cells",
meshDir,
runTime
);
writeMeshObject<labelIOList>("owner", meshDir, runTime); writeMeshObject<labelIOList>("owner", meshDir, runTime);
writeMeshObject<labelIOList>("neighbour", meshDir, runTime); writeMeshObject<labelIOList>("neighbour", meshDir, runTime);
writeMeshObject<faceCompactIOList>("faces", meshDir, runTime); writeMeshObject<faceCompactIOList, faceIOList>
(
"faces",
meshDir,
runTime
);
writeMeshObject<pointIOField>("points", 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>("pointProcAddressing", meshDir, runTime);
writeMeshObject<labelIOList>("faceProcAddressing", meshDir, runTime); writeMeshObject<labelIOList>("faceProcAddressing", meshDir, runTime);
writeMeshObject<labelIOList>("cellProcAddressing", meshDir, runTime); writeMeshObject<labelIOList>("cellProcAddressing", meshDir, runTime);
@ -279,22 +374,196 @@ int main(int argc, char *argv[])
|| headerClassName == pointSphericalTensorField::typeName || headerClassName == pointSphericalTensorField::typeName
|| headerClassName == pointSymmTensorField::typeName || headerClassName == pointSymmTensorField::typeName
|| headerClassName == pointTensorField::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 Info<< " Reading " << headerClassName
<< " : " << iter()->name() << endl; << " : " << iter()->name() << endl;
fieldDictionary fDict fieldDictionary fDict(*iter(), headerClassName);
(
*iter(),
headerClassName
);
Info<< " Writing " << iter()->name() << endl; Info<< " Writing " << iter()->name() << endl;
fDict.regIOobject::write(); 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; Info<< endl;
} }

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -188,11 +188,12 @@ void Foam::lagrangianFieldDecomposer::decomposeFields
const PtrList<GeoField>& fields const PtrList<GeoField>& fields
) const ) const
{ {
if (particleIndices_.size()) //if (particleIndices_.size())
{ {
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi) 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 PtrList<GeoField>& fields
) const ) const
{ {
if (particleIndices_.size()) //if (particleIndices_.size())
{ {
bool valid = particleIndices_.size() > 0;
forAll(fields, fieldi) 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -177,12 +177,43 @@ int main(int argc, char *argv[])
const bool allRegions = args.optionFound("allRegions"); const bool allRegions = args.optionFound("allRegions");
// determine the processor count directly wordList regionNames;
label nProcs = 0; wordList regionDirs;
while (isDir(args.path()/(word("processor") + name(nProcs)))) 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) if (!nProcs)
{ {
@ -225,9 +256,8 @@ int main(int argc, char *argv[])
if (timeDirs.empty()) if (timeDirs.empty())
{ {
FatalErrorInFunction WarningInFunction << "No times selected";
<< "No times selected" exit(1);
<< exit(FatalError);
} }
@ -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) forAll(regionNames, regioni)
{ {
const word& regionName = regionNames[regioni]; const word& regionName = regionNames[regioni];
@ -553,17 +547,26 @@ int main(int argc, char *argv[])
forAll(databases, proci) forAll(databases, proci)
{ {
fileNameList cloudDirs fileName lagrangianDir
( (
readDir fileHandler().filePath
( (
databases[proci].timePath() databases[proci].timePath()
/ regionDir / regionDir
/ cloud::prefix, / cloud::prefix
fileName::DIRECTORY
) )
); );
fileNameList cloudDirs;
if (!lagrangianDir.empty())
{
cloudDirs = fileHandler().readDir
(
lagrangianDir,
fileName::DIRECTORY
);
}
forAll(cloudDirs, i) forAll(cloudDirs, i)
{ {
// Check if we already have cloud objects for this // 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 // directory copy from the master processor
{ {
fileName uniformDir0 fileName uniformDir0
(
fileHandler().filePath
( (
databases[0].timePath()/regionDir/"uniform" 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) if (regioni == 0 && regionDir != word::null)
{ {
fileName uniformDir0 fileName uniformDir0
(
fileHandler().filePath
( (
databases[0].timePath()/"uniform" 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"); bool writeCellDist = args.optionFound("cellDist");
int nProcs = 0; label nProcs = fileHandler().nProcs(args.path());
while
(
isDir
(
args.rootPath()
/ args.caseName()
/ fileName(word("processor") + name(nProcs))
)
)
{
nProcs++;
}
Info<< "Found " << nProcs << " processor directories" << nl << endl; Info<< "Found " << nProcs << " processor directories" << nl << endl;
@ -610,13 +597,21 @@ int main(int argc, char *argv[])
databases[proci].setTime(timeDirs[timeI], timeI); databases[proci].setTime(timeDirs[timeI], timeI);
} }
const fileName meshPath = IOobject facesIO
databases[0].path() (
/databases[0].timeName() "faces",
/regionDir databases[0].timeName(),
/polyMesh::meshSubDir; 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; Info<< "No mesh." << nl << endl;
continue; continue;

View File

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

View File

@ -64,7 +64,8 @@ Usage
// Surface writer // Surface writer
writer ensight; 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 writeOptions
{ {
ensight ensight

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -71,6 +71,20 @@ OptimisationSwitches
// - inotifyMaster : do inotify (and file reading) only on master. // - inotifyMaster : do inotify (and file reading) only on master.
fileModificationChecking timeStampMaster; 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; commsType nonBlocking; //scheduled; //blocking;
floatTransfer 0; floatTransfer 0;
nProcsSimpleSum 0; nProcsSimpleSum 0;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -40,6 +40,8 @@ Description
#include "DynamicList.H" #include "DynamicList.H"
#include "CStringList.H" #include "CStringList.H"
#include "SubList.H" #include "SubList.H"
#include "IOstreams.H"
#include "Pstream.H"
#include <fstream> #include <fstream>
#include <cstdlib> #include <cstdlib>
@ -323,7 +325,17 @@ bool Foam::chDir(const fileName& dir)
bool Foam::mkDir(const fileName& pathName, mode_t mode) 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()) if (pathName.empty())
{ {
return false; 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) 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 // Ignore an empty name => always false
return !name.empty() && ::chmod(name.c_str(), m) == 0; 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) 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 // Ignore an empty name => always 0
if (!name.empty()) if (!name.empty())
{ {
@ -498,6 +524,15 @@ Foam::fileName::Type Foam::type(const fileName& name, const bool followLink)
return fileName::UNDEFINED; 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); mode_t m = mode(name, followLink);
if (S_ISREG(m)) if (S_ISREG(m))
@ -524,6 +559,16 @@ bool Foam::exists
const bool followLink 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 // Ignore an empty name => always false
return return
( (
@ -535,6 +580,15 @@ bool Foam::exists
bool Foam::isDir(const fileName& name, const bool followLink) 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 // Ignore an empty name => always false
return !name.empty() && S_ISDIR(mode(name, followLink)); return !name.empty() && S_ISDIR(mode(name, followLink));
} }
@ -547,6 +601,16 @@ bool Foam::isFile
const bool followLink 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 // Ignore an empty name => always false
return return
( (
@ -561,6 +625,15 @@ bool Foam::isFile
off_t Foam::fileSize(const fileName& name, const bool followLink) 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 // Ignore an empty name
if (!name.empty()) 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) 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 // Ignore an empty name
if (!name.empty()) 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 // Ignore an empty name
if (!name.empty()) if (!name.empty())
{ {
@ -645,8 +736,12 @@ Foam::fileNameList Foam::readDir
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "reading directory " << directory << endl; Pout<< FUNCTION_NAME << " : reading directory " << directory << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
} }
label nEntries = 0; label nEntries = 0;
@ -699,16 +794,26 @@ Foam::fileNameList Foam::readDir
bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink) 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 // Make sure source exists - this also handles an empty source name
if (!exists(src)) if (!exists(src))
{ {
return false; return false;
} }
const fileName::Type srcType = src.type(followLink);
fileName destFile(dest); fileName destFile(dest);
// Check type of source file. // Check type of source file.
const fileName::Type srcType = src.type(followLink);
if (srcType == fileName::FILE) if (srcType == fileName::FILE)
{ {
// If dest is a directory, create the destination file name. // 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, false,
followLink followLink
); );
forAll(subdirs, i) forAll(subdirs, i)
{ {
if (POSIX::debug) if (POSIX::debug)
@ -828,9 +934,13 @@ bool Foam::ln(const fileName& src, const fileName& dst)
{ {
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "Create softlink from : " << src << " to " << dst Pout<< FUNCTION_NAME
<< endl; << " : Create softlink from : " << src << " to " << dst << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
} }
if (src.empty()) if (src.empty())
@ -879,8 +989,12 @@ bool Foam::mv(const fileName& src, const fileName& dst, const bool followLink)
{ {
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "Move : " << src << " to " << dst << endl; Pout<< FUNCTION_NAME << " : Move : " << src << " to " << dst << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
} }
// Ignore an empty names => always false // Ignore an empty names => always false
@ -910,8 +1024,13 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
{ {
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "mvBak : " << src << " to extension " << ext << endl; 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 // Ignore an empty name or extension => always false
@ -952,8 +1071,12 @@ bool Foam::rm(const fileName& file)
{ {
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "Removing : " << file << endl; Pout<< FUNCTION_NAME << " : Removing : " << file << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
} }
// Ignore an empty name => always false // Ignore an empty name => always false
@ -996,8 +1119,12 @@ bool Foam::rmDir(const fileName& directory, const bool silent)
if (POSIX::debug) if (POSIX::debug)
{ {
InfoInFunction //InfoInFunction
<< "removing directory " << directory << endl; Pout<< FUNCTION_NAME << " : removing directory " << directory << endl;
if ((POSIX::debug & 2) && !Pstream::master())
{
error::printStack(Pout);
}
} }
// Process each directory entry, counting any errors encountered // 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); drand48_r(reinterpret_cast<drand48_data*>(buffer.begin()), &result);
return result; return result;
#endif #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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -426,182 +426,25 @@ Foam::fileName Foam::IOobject::path
} }
Foam::fileName Foam::IOobject::localFilePath(const bool search) const Foam::fileName Foam::IOobject::localFilePath
(
const word& typeName,
const bool search
) const
{ {
if (isOutsideOfCase(instance())) // Do not check for undecomposed files
{ return fileHandler().filePath(false, *this, typeName, search);
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
(
instant(instance())
);
if (newInstancePath.size())
{
const fileName fName
(
rootPath()/caseName()
/newInstancePath/db_.dbDir()/local()/name()
);
if (isFile(fName))
{
return fName;
}
}
}
}
return fileName::null;
}
} }
Foam::fileName Foam::IOobject::globalFilePath(const bool search) const Foam::fileName Foam::IOobject::globalFilePath
(
const word& typeName,
const bool search
) const
{ {
if (isOutsideOfCase(instance())) // Check for undecomposed files
{ return fileHandler().filePath(true, *this, typeName, search);
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;
} }

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -141,23 +141,16 @@ Foam::IOobjectList::IOobjectList
: :
HashPtrTable<IOobject>() HashPtrTable<IOobject>()
{ {
word newInstance = instance; word newInstance;
fileNameList ObjectNames = fileHandler().readObjects
(
db,
instance,
local,
newInstance
);
if (!isDir(db.path(instance))) for (const auto& objName : ObjectNames)
{
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)
{ {
IOobject* objectPtr = new IOobject IOobject* objectPtr = new IOobject
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,10 +29,12 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class T, class BaseType> 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) if (headerClassName() == IOField<T>::typeName)
{ {
is >> static_cast<Field<T>&>(*this); is >> static_cast<Field<T>&>(*this);
@ -54,6 +56,7 @@ void Foam::CompactIOField<T, BaseType>::readFromStream()
<< " while reading object " << name() << " while reading object " << name()
<< exit(FatalIOError); << exit(FatalIOError);
} }
}
} }
@ -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> template<class T, class BaseType>
Foam::CompactIOField<T, BaseType>::CompactIOField Foam::CompactIOField<T, BaseType>::CompactIOField
( (
@ -160,7 +184,8 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat fmt,
IOstream::versionNumber ver, IOstream::versionNumber ver,
IOstream::compressionType cmp IOstream::compressionType cmp,
const bool valid
) const ) const
{ {
if (fmt == IOstream::ASCII) if (fmt == IOstream::ASCII)
@ -170,7 +195,7 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
const_cast<word&>(typeName) = IOField<T>::typeName; 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 // Change type back
const_cast<word&>(typeName) = oldTypeName; const_cast<word&>(typeName) = oldTypeName;
@ -179,7 +204,7 @@ bool Foam::CompactIOField<T, BaseType>::writeObject
} }
else 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -75,7 +75,7 @@ class CompactIOField
// Private Member Functions // Private Member Functions
//- Read according to header type //- Read according to header type
void readFromStream(); void readFromStream(const bool valid = true);
public: public:
@ -88,6 +88,9 @@ public:
//- Construct from IOobject //- Construct from IOobject
CompactIOField(const IOobject&); CompactIOField(const IOobject&);
//- Construct from IOobject; does local processor require reading?
CompactIOField(const IOobject&, const bool valid);
//- Construct from IOobject and size //- Construct from IOobject and size
CompactIOField(const IOobject&, const label); CompactIOField(const IOobject&, const label);
@ -109,7 +112,8 @@ public:
( (
IOstream::streamFormat, IOstream::streamFormat,
IOstream::versionNumber, IOstream::versionNumber,
IOstream::compressionType IOstream::compressionType,
const bool valid
) const; ) const;
virtual bool writeData(Ostream&) const; virtual bool writeData(Ostream&) const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -175,7 +175,8 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat fmt,
IOstream::versionNumber ver, IOstream::versionNumber ver,
IOstream::compressionType cmp IOstream::compressionType cmp,
const bool valid
) const ) const
{ {
if (fmt == IOstream::ASCII) if (fmt == IOstream::ASCII)
@ -185,7 +186,26 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
const_cast<word&>(typeName) = IOList<T>::typeName; 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 // Change type back
const_cast<word&>(typeName) = oldTypeName; const_cast<word&>(typeName) = oldTypeName;
@ -213,7 +233,7 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
} }
else 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -114,7 +114,8 @@ public:
( (
IOstream::streamFormat, IOstream::streamFormat,
IOstream::versionNumber, IOstream::versionNumber,
IOstream::compressionType IOstream::compressionType,
const bool valid
) const; ) const;
virtual bool writeData(Ostream&) const; virtual bool writeData(Ostream&) const;

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,22 +23,43 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "globalIOFields.H" #include "GlobalIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTemplateTypeNameWithName(labelGlobalIOField, "labelField"); defineTemplateTypeNameAndDebugWithName
defineTemplateTypeNameWithName(scalarGlobalIOField, "scalarField");
defineTemplateTypeNameWithName(vectorGlobalIOField, "vectorField");
defineTemplateTypeNameWithName
( (
sphericalTensorGlobalIOField, GlobalIOField<scalar>,
"sphericalTensorField" "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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -90,7 +90,7 @@ public:
// either in the case/processor or case otherwise null // either in the case/processor or case otherwise null
virtual fileName filePath() const virtual fileName filePath() const
{ {
return globalFilePath(); return globalFilePath(type());
} }
//- ReadData function required for regIOobject read operation //- ReadData function required for regIOobject read operation

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License 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> template<class Type>
Foam::IOField<Type>::IOField(const IOobject& io, const label size) Foam::IOField<Type>::IOField(const IOobject& io, const label size)
: :

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -36,6 +36,14 @@ namespace Foam
{ {
return true; 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License 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 Foam::localIOdictionary::localIOdictionary
( (
const IOobject& io, const IOobject& io,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -65,6 +65,10 @@ public:
//- Construct given an IOobject and Istream //- Construct given an IOobject and Istream
localIOdictionary(const IOobject& io, Istream& is); localIOdictionary(const IOobject& io, Istream& is);
//- Construct given an IOobject, supply wanted typeName
localIOdictionary(const IOobject& io, const word& wantedType);
//- Destructor //- Destructor
virtual ~localIOdictionary(); virtual ~localIOdictionary();
@ -82,7 +86,7 @@ public:
virtual fileName filePath() const virtual fileName filePath() const
{ {
// Use default (local only) search strategy // 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -85,7 +85,7 @@ public:
// either in the case/processor or case otherwise null // either in the case/processor or case otherwise null
virtual fileName filePath() const virtual fileName filePath() const
{ {
return globalFilePath(); return globalFilePath(type());
} }
//- Add file watch on object (READ_IF_MODIFIED) //- 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -40,7 +40,8 @@ namespace Foam
Foam::OFstreamAllocator::OFstreamAllocator Foam::OFstreamAllocator::OFstreamAllocator
( (
const fileName& pathname, const fileName& pathname,
IOstream::compressionType compression IOstream::compressionType compression,
const bool append
) )
: :
allocatedPtr_(nullptr) allocatedPtr_(nullptr)
@ -52,26 +53,48 @@ Foam::OFstreamAllocator::OFstreamAllocator
InfoInFunction << "Cannot open null file " << endl; InfoInFunction << "Cannot open null file " << endl;
} }
} }
ofstream::openmode mode(ofstream::out);
if (append)
{
mode |= ofstream::app;
}
if (compression == IOstream::COMPRESSED) if (compression == IOstream::COMPRESSED)
{ {
// Get identically named uncompressed version out of the way // 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); 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 else
{ {
// Get identically named compressed version out of the way // get identically named compressed version out of the way
if (isFile(pathname + ".gz", false)) 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, const fileName& pathname,
streamFormat format, streamFormat format,
versionNumber version, versionNumber version,
compressionType compression compressionType compression,
const bool append
) )
: :
OFstreamAllocator(pathname, compression), OFstreamAllocator(pathname, compression, append),
OSstream(*allocatedPtr_, pathname, format, version, compression) OSstream
(
*allocatedPtr_,
"OFstream.sinkFile_",
format,
version,
compression
)
{ {
setClosed(); setClosed();
setState(allocatedPtr_->rdstate()); setState(allocatedPtr_->rdstate());

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -68,7 +68,8 @@ protected:
OFstreamAllocator OFstreamAllocator
( (
const fileName& pathname, 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, const fileName& pathname,
streamFormat format=ASCII, streamFormat format=ASCII,
versionNumber version=currentVersion, 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 "HashSet.H"
#include "profiling.H" #include "profiling.H"
#include "demandDrivenData.H" #include "demandDrivenData.H"
#include "IOdictionary.H"
#include <sstream> #include <sstream>
@ -177,13 +178,12 @@ void Foam::Time::setControls()
// Check if time directory exists // Check if time directory exists
// If not increase time precision to see if it is formatted differently. // 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 oldPrecision = precision_;
int requiredPrecision = -1; int requiredPrecision = -1;
bool found = false; bool found = false;
word oldTime(timeName()); word oldTime(timeName());
for for
( (
precision_ = maxPrecision_; precision_ = maxPrecision_;
@ -194,7 +194,6 @@ void Foam::Time::setControls()
// Update the time formatting // Update the time formatting
setTime(startTime_, 0); setTime(startTime_, 0);
// Check that the time name has changed otherwise exit loop
word newTime(timeName()); word newTime(timeName());
if (newTime == oldTime) if (newTime == oldTime)
{ {
@ -203,7 +202,7 @@ void Foam::Time::setControls()
oldTime = newTime; oldTime = newTime;
// Check the existence of the time directory with the new format // Check the existence of the time directory with the new format
found = exists(timePath(), false); found = fileHandler().exists(timePath(), false);
if (found) if (found)
{ {
@ -379,17 +378,8 @@ void Foam::Time::setMonitoring(const bool forceProfiling)
// Time objects not registered so do like objectRegistry::checkIn ourselves. // Time objects not registered so do like objectRegistry::checkIn ourselves.
if (runTimeModifiable_) if (runTimeModifiable_)
{ {
monitorPtr_.reset
(
new fileMonitor
(
regIOobject::fileModificationChecking == inotify
|| regIOobject::fileModificationChecking == inotifyMaster
)
);
// Monitor all files that controlDict depends on // Monitor all files that controlDict depends on
addWatches(controlDict_, controlDict_.files()); fileHandler().addWatches(controlDict_, controlDict_.files());
} }
// Clear dependent files - not needed now // Clear dependent files - not needed now
@ -685,7 +675,7 @@ Foam::Time::~Time()
forAllReverse(controlDict_.watchIndices(), i) forAllReverse(controlDict_.watchIndices(), i)
{ {
removeWatch(controlDict_.watchIndices()[i]); fileHandler().removeWatch(controlDict_.watchIndices()[i]);
} }
// Destroy function objects first // Destroy function objects first
@ -698,86 +688,6 @@ Foam::Time::~Time()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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) Foam::word Foam::Time::timeName(const scalar t, const int precision)
{ {
std::ostringstream buf; std::ostringstream buf;
@ -806,26 +716,22 @@ Foam::word Foam::Time::findInstancePath
const instant& t const instant& t
) const ) const
{ {
// Read directory entries into a list // Simplified version: use findTimes (readDir + sort). The expensive
fileNameList dirEntries(readDir(directory, fileName::DIRECTORY)); // bit is the readDir, not the sorting. Tbd: avoid calling findInstancePath
// from filePath.
forAll(dirEntries, i) instantList timeDirs = findTimes(path(), constant());
{ // Note:
scalar timeValue; // - times will include constant (with value 0) as first element.
if (readScalar(dirEntries[i].c_str(), timeValue) && t.equal(timeValue)) // For backwards compatibility make sure to find 0 in preference
{ // to constant.
return dirEntries[i]; // - list is sorted so could use binary search
}
}
if (t.equal(0.0)) forAllReverse(timeDirs, i)
{ {
const word& constantName = constant(); if (t.equal(timeDirs[i].value()))
// Looking for 0 or constant. 0 already checked above.
if (isDir(directory/constantName))
{ {
return constantName; return timeDirs[i].name();
} }
} }
@ -1030,6 +936,7 @@ void Foam::Time::setTime(const Time& t)
value() = t.value(); value() = t.value();
dimensionedScalar::name() = t.dimensionedScalar::name(); dimensionedScalar::name() = t.dimensionedScalar::name();
timeIndex_ = t.timeIndex_; 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("deltaT", deltaT_);
timeDict.readIfPresent("deltaT0", deltaT0_); timeDict.readIfPresent("deltaT0", deltaT0_);
timeDict.readIfPresent("index", timeIndex_); timeDict.readIfPresent("index", timeIndex_);
fileHandler().setTime(*this);
} }
@ -1070,6 +978,7 @@ void Foam::Time::setTime(const scalar newTime, const label newIndex)
value() = newTime; value() = newTime;
dimensionedScalar::name() = timeName(timeToUserTime(newTime)); dimensionedScalar::name() = timeName(timeToUserTime(newTime));
timeIndex_ = newIndex; timeIndex_ = newIndex;
fileHandler().setTime(*this);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -51,7 +51,6 @@ SourceFiles
#include "typeInfo.H" #include "typeInfo.H"
#include "dlLibraryTable.H" #include "dlLibraryTable.H"
#include "functionObjectList.H" #include "functionObjectList.H"
#include "fileMonitor.H"
#include "sigWriteNow.H" #include "sigWriteNow.H"
#include "sigStopAtWriteNow.H" #include "sigStopAtWriteNow.H"
@ -78,9 +77,6 @@ class Time
{ {
// Private data // Private data
//- file-change monitor for all registered files
mutable autoPtr<fileMonitor> monitorPtr_;
//- Profiling trigger for time-loop (for run, loop) //- Profiling trigger for time-loop (for run, loop)
mutable profilingTrigger* loopProfiling_; mutable profilingTrigger* loopProfiling_;
@ -182,6 +178,9 @@ protected:
//- Read the control dictionary and set the write controls etc. //- Read the control dictionary and set the write controls etc.
virtual void readDict(); virtual void readDict();
//- Find IOobject in the objectPath
static bool exists(IOobject&);
private: private:
@ -331,41 +330,9 @@ public:
//- Read control dictionary, update controls and time //- Read control dictionary, update controls and time
virtual bool read(); virtual bool read();
// Automatic rereading
//- Read the objects that have been modified //- Read the objects that have been modified
void readModifiedObjects(); 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". //- Return the location of "dir" containing the file "name".
// (eg, used in reading mesh data) // (eg, used in reading mesh data)
// If name is null, search for the directory "dir" only. // If name is null, search for the directory "dir" only.
@ -410,9 +377,10 @@ public:
//- Write using given format, version and compression //- Write using given format, version and compression
virtual bool writeObject virtual bool writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat,
IOstream::versionNumber ver, IOstream::versionNumber,
IOstream::compressionType cmp IOstream::compressionType,
const bool valid
) const; ) const;
//- Write the objects now (not at end of iteration) and continue //- Write the objects now (not at end of iteration) and continue

View File

@ -28,6 +28,8 @@ License
#include "simpleObjectRegistry.H" #include "simpleObjectRegistry.H"
#include "dimensionedConstants.H" #include "dimensionedConstants.H"
#include "profiling.H" #include "profiling.H"
#include "IOdictionary.H"
#include "fileOperation.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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("graphFormat", graphFormat_);
controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_); controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
if (!runTimeModifiable_ && controlDict_.watchIndices().size()) if (!runTimeModifiable_ && controlDict_.watchIndices().size())
{ {
forAllReverse(controlDict_.watchIndices(), i) forAllReverse(controlDict_.watchIndices(), i)
{ {
removeWatch(controlDict_.watchIndices()[i]); fileHandler().removeWatch(controlDict_.watchIndices()[i]);
} }
controlDict_.watchIndices().clear(); controlDict_.watchIndices().clear();
} }
@ -393,7 +433,7 @@ bool Foam::Time::read()
// already updated all the watchIndices via the addWatch but // already updated all the watchIndices via the addWatch but
// controlDict_ is an unwatchedIOdictionary so will only have // controlDict_ is an unwatchedIOdictionary so will only have
// stored the dependencies as files. // stored the dependencies as files.
addWatches(controlDict_, controlDict_.files()); fileHandler().addWatches(controlDict_, controlDict_.files());
} }
controlDict_.files().clear(); controlDict_.files().clear();
@ -414,7 +454,7 @@ void Foam::Time::readModifiedObjects()
// valid filePath). // valid filePath).
// Note: requires same ordering in objectRegistries on different // Note: requires same ordering in objectRegistries on different
// processors! // processors!
monitorPtr_().updateStates fileHandler().updateStates
( (
( (
regIOobject::fileModificationChecking == inotifyMaster regIOobject::fileModificationChecking == inotifyMaster
@ -437,7 +477,7 @@ void Foam::Time::readModifiedObjects()
// controlDict_ is an unwatchedIOdictionary so will only have // controlDict_ is an unwatchedIOdictionary so will only have
// stored the dependencies as files. // stored the dependencies as files.
addWatches(controlDict_, controlDict_.files()); fileHandler().addWatches(controlDict_, controlDict_.files());
} }
controlDict_.files().clear(); controlDict_.files().clear();
} }
@ -482,7 +522,8 @@ bool Foam::Time::writeTimeDict() const
( (
IOstream::ASCII, IOstream::ASCII,
IOstream::currentVersion, IOstream::currentVersion,
IOstream::UNCOMPRESSED IOstream::UNCOMPRESSED,
true
); );
} }
@ -491,7 +532,8 @@ bool Foam::Time::writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat fmt,
IOstream::versionNumber ver, IOstream::versionNumber ver,
IOstream::compressionType cmp IOstream::compressionType cmp,
const bool valid
) const ) const
{ {
if (writeTime()) if (writeTime())
@ -500,7 +542,7 @@ bool Foam::Time::writeObject
if (writeOK) if (writeOK)
{ {
writeOK = objectRegistry::writeObject(fmt, ver, cmp); writeOK = objectRegistry::writeObject(fmt, ver, cmp, valid);
} }
if (writeOK) if (writeOK)

View File

@ -2,8 +2,8 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / 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. \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. 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 Foam::word Foam::Time::findInstance
( (
const fileName& dir, const fileName& dir,
@ -44,40 +87,33 @@ Foam::word Foam::Time::findInstance
) const ) const
{ {
// Note: - if name is empty, just check the directory itself // 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 // - check for an object with local file scope (so no looking up in
// parent directory in case of parallel) // parent directory in case of parallel)
const fileName tPath(path()); {
const fileName dirPath(tPath/timeName()/dir); IOobject io
// check the current time directory
if
( (
name.empty() name, // name might be empty!
? isDir(dirPath)
:
(
isFile(dirPath/name)
&& IOobject
(
name,
timeName(), timeName(),
dir, dir,
*this *this
).typeHeaderOk<IOList<label>>(false) // use object with local scope );
)
) if (exists(io))
{ {
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
<< "Found \"" << name << "Found exact match for \"" << name
<< "\" in " << timeName()/dir << "\" in " << timeName()/dir
<< endl; << endl;
} }
return timeName(); return timeName();
} }
}
// Search back through the time directories to find the time // Search back through the time directories to find the time
// closest to and lower than current time // closest to and lower than current time
@ -96,27 +132,20 @@ Foam::word Foam::Time::findInstance
// continue searching from here // continue searching from here
for (; instanceI >= 0; --instanceI) for (; instanceI >= 0; --instanceI)
{ {
if IOobject io
( (
name.empty() name, // name might be empty!
? isDir(tPath/ts[instanceI].name()/dir)
:
(
isFile(tPath/ts[instanceI].name()/dir/name)
&& IOobject
(
name,
ts[instanceI].name(), ts[instanceI].name(),
dir, dir,
*this *this
).typeHeaderOk<IOList<label>>(false) );
)
) if (exists(io))
{ {
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
<< "Found \"" << name << "Found instance match for \"" << name
<< "\" in " << ts[instanceI].name()/dir << "\" in " << ts[instanceI].name()/dir
<< endl; << endl;
} }
@ -129,7 +158,8 @@ Foam::word Foam::Time::findInstance
{ {
if (debug) if (debug)
{ {
InfoInFunction //InfoInFunction
Pout<< "findInstance : "
<< "Hit stopInstance " << stopInstance << "Hit stopInstance " << stopInstance
<< endl; << endl;
} }
@ -169,27 +199,20 @@ Foam::word Foam::Time::findInstance
// constant function of the time, because the latter points to // constant function of the time, because the latter points to
// the case constant directory in parallel cases // the case constant directory in parallel cases
if IOobject io
(
name.empty()
? isDir(tPath/constant()/dir)
:
(
isFile(tPath/constant()/dir/name)
&& IOobject
( (
name, name,
constant(), constant(),
dir, dir,
*this *this
).typeHeaderOk<IOList<label>>(false) );
)
) if (exists(io))
{ {
if (debug) if (debug)
{ {
InfoInFunction InfoInFunction
<< "Found \"" << name << "Found constant match for \"" << name
<< "\" in " << constant()/dir << "\" in " << constant()/dir
<< endl; << endl;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -40,62 +40,8 @@ Foam::instantList Foam::Time::findTimes
const word& constantName const word& constantName
) )
{ {
if (debug) return fileHandler().findTimes(directory, constantName);
{
InfoInFunction << "Finding times in directory " << directory << endl;
}
// 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 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License 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 * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, instant& I) Foam::Istream& Foam::operator>>(Istream& is, instant& I)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,112 +28,10 @@ License
#include "Time.H" #include "Time.H"
#include "Pstream.H" #include "Pstream.H"
#include "HashSet.H" #include "HashSet.H"
#include "fileOperation.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * 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 bool Foam::regIOobject::readHeaderOk
( (
const IOstream::streamFormat format, const IOstream::streamFormat format,
@ -176,7 +74,7 @@ bool Foam::regIOobject::readHeaderOk
|| isHeaderOk || isHeaderOk
) )
{ {
return regIOobject::read(masterOnly, format, typeName); return fileHandler().read(*this, masterOnly, format, typeName);
} }
else else
{ {
@ -184,9 +82,10 @@ bool Foam::regIOobject::readHeaderOk
} }
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::Istream& Foam::regIOobject::readStream() Foam::Istream& Foam::regIOobject::readStream(const bool valid)
{ {
if (IFstream::debug) if (IFstream::debug)
{ {
@ -206,13 +105,13 @@ Foam::Istream& Foam::regIOobject::readStream()
} }
// Construct object stream and read header if not already constructed // Construct object stream and read header if not already constructed
if (!isPtr_) if (!isPtr_.valid())
{ {
fileName objPath; fileName objPath;
if (watchIndices_.size()) if (watchIndices_.size())
{ {
// File is being watched. Read exact file that is being watched. // File is being watched. Read exact file that is being watched.
objPath = time().getFile(watchIndices_.last()); objPath = fileHandler().getFile(watchIndices_.last());
} }
else else
{ {
@ -227,72 +126,47 @@ Foam::Istream& Foam::regIOobject::readStream()
<< " in file " << objPath << " in file " << objPath
<< endl; << endl;
} }
if (!objPath.size())
{
FatalIOError
(
"regIOobject::readStream()",
__FILE__,
__LINE__,
objectPath(),
0
) << "cannot find file"
<< exit(FatalIOError);
}
} }
if (!(isPtr_ = IOobject::objectStream(objPath))) isPtr_ = fileHandler().readStream(*this, objPath, type(), valid);
{
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_; return isPtr_();
} }
Foam::Istream& Foam::regIOobject::readStream(const word& expectName) Foam::Istream& Foam::regIOobject::readStream
(
const word& expectName,
const bool valid
)
{ {
if (IFstream::debug) if (IFstream::debug)
{ {
Pout<< "regIOobject::readStream(const word&) : " Pout<< "regIOobject::readStream(const word&) : "
<< "reading object " << name() << "reading object " << name()
<< " of type " << type() << " of type " << type()
<< " from file " << objectPath() << " from file " << filePath()
<< endl; << endl;
} }
// Construct IFstream if not already constructed // Construct IFstream if not already constructed
if (!isPtr_) if (!isPtr_.valid())
{ {
readStream(); readStream(valid);
// Check the className of the regIOobject // Check the className of the regIOobject
// dictionary is an allowable name in case the actual class // dictionary is an allowable name in case the actual class
// instantiated is a dictionary // instantiated is a dictionary
if if
( (
expectName.size() valid
&& expectName.size()
&& headerClassName() != expectName && headerClassName() != expectName
&& headerClassName() != "dictionary" && headerClassName() != "dictionary"
) )
{ {
FatalIOErrorInFunction(*isPtr_) FatalIOErrorInFunction(isPtr_())
<< "unexpected class name " << headerClassName() << "unexpected class name " << headerClassName()
<< " expected " << expectName << endl << " expected " << expectName << endl
<< " while reading object " << name() << " 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) if (IFstream::debug)
{ {
Pout<< "regIOobject::close() : " Pout<< "regIOobject::close() : "
<< "finished reading " << filePath() << "finished reading " << isPtr_().name()
<< endl; << endl;
} }
if (isPtr_) isPtr_.clear();
{
delete isPtr_;
isPtr_ = nullptr;
}
} }
@ -341,11 +211,11 @@ bool Foam::regIOobject::read()
oldWatchFiles.setSize(watchIndices_.size()); oldWatchFiles.setSize(watchIndices_.size());
forAll(watchIndices_, i) forAll(watchIndices_, i)
{ {
oldWatchFiles[i] = time().getFile(watchIndices_[i]); oldWatchFiles[i] = fileHandler().getFile(watchIndices_[i]);
} }
forAllReverse(watchIndices_, i) forAllReverse(watchIndices_, i)
{ {
time().removeWatch(watchIndices_[i]); fileHandler().removeWatch(watchIndices_[i]);
} }
watchIndices_.clear(); watchIndices_.clear();
} }
@ -359,7 +229,9 @@ bool Foam::regIOobject::read()
|| regIOobject::fileModificationChecking == inotifyMaster || 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()) if (oldWatchFiles.size())
{ {
@ -375,7 +247,7 @@ bool Foam::regIOobject::modified() const
{ {
forAllReverse(watchIndices_, i) forAllReverse(watchIndices_, i)
{ {
if (time().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED) if (fileHandler().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
{ {
return true; return true;
} }
@ -392,7 +264,7 @@ bool Foam::regIOobject::readIfModified()
label modified = -1; label modified = -1;
forAllReverse(watchIndices_, i) forAllReverse(watchIndices_, i)
{ {
if (time().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED) if (fileHandler().getState(watchIndices_[i]) != fileMonitor::UNMODIFIED)
{ {
modified = watchIndices_[i]; modified = watchIndices_[i];
break; break;
@ -401,7 +273,7 @@ bool Foam::regIOobject::readIfModified()
if (modified != -1) if (modified != -1)
{ {
const fileName& fName = time().getFile(watchIndices_.last()); const fileName fName = fileHandler().getFile(watchIndices_.last());
if (modified == watchIndices_.last()) if (modified == watchIndices_.last())
{ {
@ -414,7 +286,8 @@ bool Foam::regIOobject::readIfModified()
InfoInFunction InfoInFunction
<< " Re-reading object " << name() << " Re-reading object " << name()
<< " from file " << fName << " from file " << fName
<< " because of modified file " << time().getFile(modified) << " because of modified file "
<< fileHandler().getFile(modified)
<< endl; << endl;
} }

View File

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

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