Commit 42299dca authored by Mark Olesen's avatar Mark Olesen Committed by Mark Olesen
Browse files

ENH: use IOstreamOption for writeObject() calls.

- reduces the number of parameters that are being passed around
  and allows future additions into the IOstreamOption with mininal
  effort.
parent 9be1772e
......@@ -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;
......
......@@ -1140,18 +1140,19 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const
bool Foam::decomposedBlockData::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
// Always write BINARY
streamOpt.format(IOstream::BINARY);
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));
// Note: always write binary. These are strings so readable anyway.
// They have already be tokenised on the sending side.
osPtr.reset(new OFstream(objectPath(), streamOpt));
IOobject::writeHeader(osPtr());
}
......
......@@ -135,12 +135,10 @@ public:
// and that the master data contains a header
virtual bool writeData(Ostream&) const;
//- Write using given format, version and compression
//- Write using stream options
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
IOstreamOption streamOpt,
const bool valid
) const;
......
......@@ -392,12 +392,10 @@ public:
//- Write time dictionary to the \<time\>/uniform directory
virtual bool writeTimeDict() const;
//- Write using given format, version and compression
//- Write using stream options
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
IOstreamOption streamOpt,
const bool valid
) const;
......
......@@ -524,9 +524,7 @@ bool Foam::Time::writeTimeDict() const
return timeDict.regIOobject::writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
IOstream::UNCOMPRESSED,
IOstreamOption(IOstream::ASCII),
true
);
}
......@@ -534,9 +532,7 @@ bool Foam::Time::writeTimeDict() const
bool Foam::Time::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
......@@ -546,7 +542,7 @@ bool Foam::Time::writeObject
if (writeOK)
{
writeOK = objectRegistry::writeObject(fmt, ver, cmp, valid);
writeOK = objectRegistry::writeObject(streamOpt, valid);
}
if (writeOK)
......
......@@ -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.
......@@ -625,9 +625,7 @@ bool Foam::functionObjectList::execute()
stateDictPtr_->writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
time_.writeCompression(),
IOstreamOption(IOstream::ASCII, time_.writeCompression()),
true
);
......
......@@ -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.
......@@ -473,9 +473,7 @@ bool Foam::objectRegistry::readIfModified()
bool Foam::objectRegistry::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
......@@ -496,7 +494,7 @@ bool Foam::objectRegistry::writeObject
if ((*iter)->writeOpt() != NO_WRITE)
{
ok = (*iter)->writeObject(fmt, ver, cmp, valid) && ok;
ok = (*iter)->writeObject(streamOpt, valid) && ok;
}
}
......
......@@ -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.
......@@ -524,12 +524,10 @@ public:
return false;
}
//- Write the objects
//- Write the objects using stream options
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const;
......
......@@ -43,6 +43,7 @@ SourceFiles
#include "IOobject.H"
#include "typeInfo.H"
#include "stdFoam.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -319,12 +320,10 @@ public:
// Must be defined in derived types
virtual bool writeData(Ostream&) const = 0;
//- Write using given format, version and compression
//- Write using stream options
virtual bool writeObject
(
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType,
IOstreamOption streamOpt,
const bool valid
) const;
......@@ -345,6 +344,19 @@ public:
//- Copy assignment
void operator=(const IOobject& io);
// Housekeeping
//- Write using given format, version and compression
FOAM_DEPRECATED_FOR(2020-02, "writeObject(IOstreamOption, bool)")
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType comp,
const bool valid
) const;
};
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -23,9 +24,6 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
write function for regIOobjects
\*---------------------------------------------------------------------------*/
#include "regIOobject.H"
......@@ -37,9 +35,7 @@ Description
bool Foam::regIOobject::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp,
IOstreamOption streamOpt,
const bool valid
) const
{
......@@ -62,7 +58,6 @@ bool Foam::regIOobject::writeObject
}
//- uncomment this if you want to write global objects on master only
//bool isGlobal = global();
bool isGlobal = false;
......@@ -119,7 +114,7 @@ bool Foam::regIOobject::writeObject
//if (mkDir(path()))
//{
// // Try opening an OFstream for object
// OFstream os(objectPath(), fmt, ver, cmp);
// OFstream os(objectPath(), streamOpt);
//
// // If any of these fail, return (leave error handling to Ostream
// // class)
......@@ -143,7 +138,7 @@ bool Foam::regIOobject::writeObject
//
// osGood = os.good();
//}
osGood = fileHandler().writeObject(*this, fmt, ver, cmp, valid);
osGood = fileHandler().writeObject(*this, streamOpt, valid);
}