Test-IOField: Updated and improved to use typeIOobject

This commit is contained in:
Henry Weller
2021-09-02 07:55:49 +01:00
parent 2b5edb1119
commit 3554f2140e

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -38,7 +38,7 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void write(const IOobject& io, const label sz)
void write(const typeIOobject<IOField<label>>& io, const label sz)
{
IOField<label> fld(io, sz);
forAll(fld, i)
@ -50,7 +50,7 @@ void write(const IOobject& io, const label sz)
}
void read(const IOobject& io, const label sz)
void read(const typeIOobject<IOField<label>>& io, const label sz)
{
bool valid = (sz > 0);
Pout<< " valid:" << valid << endl;
@ -59,14 +59,14 @@ void read(const IOobject& io, const label sz)
if (fld.size() != sz)
{
FatalErrorInFunction<< "io:" << io.objectPath() << exit(FatalError);
FatalErrorInFunction<< "io:" << fld.objectPath() << exit(FatalError);
}
}
void writeAndRead
(
const IOobject& io,
const typeIOobject<IOField<label>>& io,
const label sz,
const word& writeType,
const IOobject::readOption readOpt,
@ -83,11 +83,11 @@ void writeAndRead
fileHandler(writeHandler);
// Delete
Pout<< "Deleting:" << fileHandler().filePath(io.objectPath()) << endl;
fileHandler().rm(fileHandler().filePath(io.objectPath()));
Pout<< "Deleting:" << io.filePath() << endl;
fileHandler().rm(io.objectPath());
// Write
Pout<< "Writing:" << fileHandler().objectPath(io, word::null) << endl;
Pout<< "Writing:" << io.objectPath() << endl;
write(io, sz);
autoPtr<fileOperation> readHandler
@ -97,9 +97,9 @@ void writeAndRead
fileHandler(readHandler);
// Read
IOobject readIO(io);
typeIOobject<IOField<label>> readIO(io);
readIO.readOpt() = readOpt;
Pout<< "Reading:" << fileHandler().filePath(readIO.objectPath()) << endl;
Pout<< "Reading:" << readIO.filePath() << endl;
read(readIO, sz);
Pout<< "** Done writing:" << writeType
@ -109,7 +109,7 @@ void writeAndRead
void readIfPresent
(
IOobject& io,
typeIOobject<IOField<label>>& io,
const label sz,
const word& readType
)
@ -121,7 +121,7 @@ void readIfPresent
fileHandler(readHandler);
// Read
Pout<< "Reading:" << fileHandler().filePath(io.objectPath()) << endl;
Pout<< "Reading:" << io.filePath() << endl;
io.readOpt() = IOobject::READ_IF_PRESENT;
read(io, sz);
}
@ -142,7 +142,7 @@ int main(int argc, char *argv[])
sz = 1;
}
IOobject io
typeIOobject<IOField<label>> io
(
"bla",
runTime.timeName(),
@ -158,17 +158,6 @@ int main(int argc, char *argv[])
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];