Commit 2ee93155 authored by Mattijs Janssens's avatar Mattijs Janssens
Browse files

Merge branch 'feature-writeObject' into 'develop'

Feature write object

See merge request !341
parents 9be1772e 8498e3f5
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -48,8 +49,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
IOstream::streamFormat format=IOstream::BINARY;
// IOstream::streamFormat format=IOstream::ASCII;
IOstream::streamFormat format = IOstream::BINARY;
// IOstream::streamFormat format = IOstream::ASCII;
const label size = 20000000;
......@@ -84,12 +85,9 @@ int main(int argc, char *argv[])
<< runTime.cpuTimeIncrement() << " s" << nl << endl;
// Write binary
faces2.writeObject
(
format,
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(format),
true
);
......@@ -147,12 +145,9 @@ int main(int argc, char *argv[])
<< runTime.cpuTimeIncrement() << " s" << nl << endl;
// Write binary
faces2.writeObject
(
format,
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(format),
true
);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -643,9 +643,11 @@ int main(int argc, char *argv[])
(
!runTime.objectRegistry::writeObject
(
runTime.writeFormat(),
IOstream::currentVersion,
runTime.writeCompression(),
IOstreamOption
(
runTime.writeFormat(),
runTime.writeCompression()
),
true
)
)
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -157,12 +157,10 @@ bool writeZones
Info<< " Writing " << name << endl;
// Force writing as ascii
// Force writing as ASCII
writeOk = meshObject.regIOobject::writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
compression,
IOstreamOption(IOstream::ASCII, compression),
true
);
}
......@@ -471,9 +469,11 @@ int main(int argc, char *argv[])
parcels.writeObject
(
runTime.writeFormat(),
IOstream::currentVersion,
runTime.writeCompression(),
IOstreamOption
(
runTime.writeFormat(),
runTime.writeCompression()
),
parcels.size()
);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -93,14 +93,8 @@ public:
virtual void autoMap(const mapPolyMesh&)
{}
//- Switch off writing the objects
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
const bool valid
) const
//- Disable writing objects
virtual bool writeObject(IOstreamOption, const bool valid) const
{
return true;
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -660,9 +660,7 @@ int main(int argc, char *argv[])
Info<< "Writing modified " << fieldName << endl;
dictList.writeObject
(
runTime.writeFormat(),
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(runTime.writeFormat()),
true
);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2017 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -199,9 +199,7 @@ void createFieldFiles
fieldOut.regIOobject::writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(IOstream::ASCII),
true
);
}
......
......@@ -7,7 +7,7 @@
-------------------------------------------------------------------------------
Copyright (C) 2007-2019 PCOpt/NTUA
Copyright (C) 2013-2019 FOSS GP
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -95,9 +95,7 @@ int main(int argc, char *argv[])
// Write modified dictionary
optDict.regIOobject::writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(IOstream::ASCII),
true
);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -175,28 +175,26 @@ Foam::CompactIOField<T, BaseType>::CompactIOField
template<class T, class BaseType>
bool Foam::CompactIOField<T, BaseType>::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
if (fmt == IOstream::ASCII)
if (streamOpt.format() == IOstream::ASCII)
{
// Change type to be non-compact format type
const word oldTypeName(typeName);
const_cast<word&>(typeName) = IOField<T>::typeName;
bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, valid);
bool good = regIOobject::writeObject(streamOpt, valid);
// Change type back
// Restore type
const_cast<word&>(typeName) = oldTypeName;
return good;
}
return regIOobject::writeObject(fmt, ver, cmp, valid);
return regIOobject::writeObject(streamOpt, valid);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -112,11 +113,10 @@ public:
// Member Functions
//- Write using stream options
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
IOstreamOption streamOpt,
const bool valid
) const;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -168,21 +168,17 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
template<class T, class BaseType>
bool Foam::CompactIOList<T, BaseType>::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
bool nonCompact = false;
if (fmt == IOstream::ASCII)
{
nonCompact = true;
}
else if (overflows())
if
(
streamOpt.format() == IOstream::BINARY
&& overflows()
)
{
nonCompact = true;
streamOpt.format(IOstream::ASCII);
WarningInFunction
<< "Overall number of elements of CompactIOList of size "
......@@ -190,14 +186,14 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
<< nl << " Switching to ascii writing" << endl;
}
if (nonCompact)
if (streamOpt.format() == IOstream::ASCII)
{
// Change to non-compact type
// 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);
bool good = regIOobject::writeObject(streamOpt, valid);
// Change type back
const_cast<word&>(typeName) = oldTypeName;
......@@ -205,7 +201,7 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
return good;
}
return regIOobject::writeObject(fmt, ver, cmp, valid);
return regIOobject::writeObject(streamOpt, valid);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -114,11 +114,10 @@ public:
// Member Functions
//- Write using stream options. Checks for overflow in binary
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
IOstreamOption streamOpt,
const bool valid
) const;
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,7 +31,6 @@ License
#include "IPstream.H"
#include "PstreamBuffers.H"
#include "Fstream.H"
#include "StringStream.H"
#include "dictionary.H"
#include "objectRegistry.H"
#include "SubList.H"
......@@ -160,12 +160,6 @@ Foam::decomposedBlockData::decomposedBlockData
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
Foam::decomposedBlockData::~decomposedBlockData()
{}
// * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is)
......@@ -181,15 +175,11 @@ bool Foam::decomposedBlockData::readMasterHeader(IOobject& io, Istream& is)
List<char> data(is);
is.fatalCheck("read(Istream&) : reading entry");
IListStream str
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
is.name()
);
return io.readHeader(str);
UIListStream headerStream(data);
headerStream.name() = is.name();
return io.readHeader(headerStream);
}
......@@ -254,24 +244,15 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
is.fatalCheck("read(Istream&)");
List<char> data;
autoPtr<ISstream> realIsPtr;
if (blocki == 0)
{
is >> data;
List<char> data(is);
is.fatalCheck("read(Istream&) : reading entry");
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
is.name()
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = is.name();
// Read header
if (!headerIO.readHeader(realIsPtr()))
......@@ -284,7 +265,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
else
{
// Read master for header
is >> data;
List<char> data(is);
is.fatalCheck("read(Istream&) : reading entry");
IOstream::versionNumber ver(IOstream::currentVersion);
......@@ -292,13 +273,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
unsigned labelByteSize;
unsigned scalarByteSize;
{
UIListStream headerStream
(
data,
IOstream::ASCII,
IOstream::currentVersion,
is.name()
);
UIListStream headerStream(data);
// Read header
if (!headerIO.readHeader(headerStream))
......@@ -315,20 +290,12 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
for (label i = 1; i < blocki+1; i++)
{
// Read data, override old data
// Read and discard data, only retain the last one
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
}
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
is.name()
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = is.name();
// Apply master stream settings to realIsPtr
realIsPtr().format(fmt);
......@@ -336,6 +303,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
realIsPtr().setLabelByteSize(labelByteSize);
realIsPtr().setScalarByteSize(scalarByteSize);
}
return realIsPtr;
}
......@@ -358,22 +326,6 @@ bool Foam::decomposedBlockData::readBlocks
bool ok = false;
//// Scatter master header info
//string ver;
//unsigned labelByteSize;
//unsigned scalarByteSize;
//if (UPstream::master(comm))
//{
// ver = isPtr().version().str();
// labelByteSize = isPtr().labelByteSize();
// scalarByteSize = isPtr().scalarByteSize();
//}
//Pstream::scatter(ver); //, Pstream::msgType(), comm);
//Pstream::scatter(labelByteSize); //, Pstream::msgType(), comm);
//Pstream::scatter(scalarByteSize); //, Pstream::msgType(), comm);
if (commsType == UPstream::commsTypes::scheduled)
{
if (UPstream::master(comm))
......@@ -509,17 +461,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
fName
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = fName;
// Read header
if (!headerIO.readHeader(realIsPtr()))
......@@ -566,16 +509,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
);
is >> data;
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
fName
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = fName;
}
}
else
......@@ -597,16 +532,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
is >> data;
is.fatalCheck("read(Istream&) : reading entry");
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
fName
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = fName;
// Read header
if (!headerIO.readHeader(realIsPtr()))
......@@ -643,16 +570,8 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
UIPstream is(UPstream::masterNo(), pBufs);
is >> data;
realIsPtr.reset
(
new IListStream
(
std::move(data),
IOstream::ASCII,
IOstream::currentVersion,
fName
)
);
realIsPtr.reset(new IListStream(std::move(data)));
realIsPtr->name() = fName;
}
}
......@@ -661,26 +580,24 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
//- Set stream properties from realIsPtr on master
// Scatter master header info
string ver;
string format;
string versionString;
label formatValue;
unsigned labelByteSize;
unsigned scalarByteSize;
if (UPstream::master(comm))
{
ver = realIsPtr().version().str();
OStringStream os;
os << realIsPtr().format();
format = os.str();
versionString = realIsPtr().version().str();
formatValue = static_cast<label>(realIsPtr().format());
labelByteSize = realIsPtr().labelByteSize();
scalarByteSize = realIsPtr().scalarByteSize();
}
Pstream::scatter(ver); //, Pstream::msgType(), comm);
Pstream::scatter(format); //, Pstream::msgType(), comm);
Pstream::scatter(versionString); //, Pstream::msgType(), comm);
Pstream::scatter(formatValue); //, Pstream::msgType(), comm);
Pstream::scatter(labelByteSize); //, Pstream::msgType(), comm);
Pstream::scatter(scalarByteSize); //, Pstream::msgType(), comm);