ENH: added Time::New factory method

- creates a dummy time, which is useful when a local object registry
  is needed
This commit is contained in:
Mark Olesen
2019-08-02 12:44:47 +02:00
parent 6c4764dfa6
commit b5f12fe397
7 changed files with 66 additions and 84 deletions

View File

@ -711,6 +711,38 @@ Foam::Time::Time
} }
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::Time> Foam::Time::New()
{
return
autoPtr<Time>::New
(
".", // root-path
".", // case-name
"system",
"constant",
false, // No enableFunctionObjects
false // No enableLibs
);
}
Foam::autoPtr<Foam::Time> Foam::Time::New(const fileName& caseDir)
{
return
autoPtr<Time>::New
(
caseDir.path(), // root-path
caseDir.name(), // case-name
"system",
"constant",
false, // No enableFunctionObjects
false // No enableLibs
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Time::~Time() Foam::Time::~Time()

View File

@ -271,6 +271,15 @@ public:
); );
// Selectors
//- Construct dummy time, without functionObjects or libraries
static autoPtr<Time> New();
//- Construct dummy time, without functionObjects or libraries
static autoPtr<Time> New(const fileName& caseDir);
//- Destructor //- Destructor
virtual ~Time(); virtual ~Time();

View File

@ -52,22 +52,15 @@ bool Foam::fileFormats::edgeMeshFormat::read
{ {
clear(); clear();
// Construct dummy time to use as an objectRegistry // Use dummy Time for objectRegistry
Time dummyTime autoPtr<Time> dummyTimePtr(Time::New());
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the headerOk & readHeader // Construct IOobject to re-use the headerOk & readHeader
// (so we can read ascii and binary) // (so we can read ascii and binary)
IOobject io IOobject io
( (
filename, filename,
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
@ -150,21 +143,14 @@ void Foam::fileFormats::edgeMeshFormat::write
const edgeMesh& mesh const edgeMesh& mesh
) )
{ {
// Construct dummy time to use as an objectRegistry // Use dummy Time for objectRegistry
Time dummyTime autoPtr<Time> dummyTimePtr(Time::New());
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the writeHeader // Construct IOobject to re-use the writeHeader
IOobject io IOobject io
( (
filename, filename,
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false

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) 2009-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2010, 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -98,24 +98,15 @@ bool Foam::fileFormats::VTKedgeFormat::read
<< exit(FatalError); << exit(FatalError);
} }
// Construct dummy time so we have something to create an objectRegistry // Use dummy Time for objectRegistry
// from autoPtr<Time> dummyTimePtr(Time::New());
Time dummyTime
(
"dummyRoot",
"dummyCase",
"system",
"constant",
false // enableFunctionObjects
);
// Make dummy object registry
objectRegistry obr objectRegistry obr
( (
IOobject IOobject
( (
"dummy", "vtk::edgeFormat",
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false

View File

@ -50,22 +50,15 @@ bool Foam::fileFormats::extendedEdgeMeshFormat::read
{ {
clear(); clear();
// Construct dummy time to use as an objectRegistry // Use dummy Time for objectRegistry
Time dummyTime autoPtr<Time> dummyTimePtr(Time::New());
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the headerOk & readHeader // Construct IOobject to re-use the headerOk & readHeader
// (so we can read ascii and binary) // (so we can read ascii and binary)
IOobject io IOobject io
( (
filename, filename,
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false

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) 2004-2010, 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2010, 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -102,24 +102,15 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
bool sorted = true; bool sorted = true;
// Construct dummy time so we have something to create an objectRegistry // Use dummy Time for objectRegistry
// from autoPtr<Time> dummyTimePtr(Time::New());
Time dummyTime
(
"dummyRoot",
"dummyCase",
"system",
"constant",
false // enableFunctionObjects
);
// Make dummy object registry
objectRegistry obr objectRegistry obr
( (
IOobject IOobject
( (
"dummy", "vtk::surfaceFormat",
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false

View File

@ -112,18 +112,8 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
} }
// Dummy time to use as an objectRegistry // Dummy Time to use as objectRegistry
const fileName caseDir(argList::envGlobalPath()); autoPtr<Time> dummyTimePtr(Time::New(argList::envGlobalPath()));
Time dummyTime
(
caseDir.path(), // root-path,
caseDir.name(), // case-name,
"system", //
"constant", //
false, // no function objects
false // no libs
);
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
@ -140,7 +130,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
IOobject IOobject
( (
surfaceDir/"points", surfaceDir/"points",
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
@ -183,18 +173,8 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
const fileName outputFile(surfaceDir/timeName()/fieldName); const fileName outputFile(surfaceDir/timeName()/fieldName);
// Dummy time to use as an objectRegistry // Dummy Time to use as objectRegistry
const fileName caseDir(argList::envGlobalPath()); autoPtr<Time> dummyTimePtr(Time::New(argList::envGlobalPath()));
Time dummyTime
(
caseDir.path(), // root-path,
caseDir.name(), // case-name,
"system", //
"constant", //
false, // no function objects
false // no libs
);
// Geometry merge() implicit // Geometry merge() implicit
@ -217,7 +197,7 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
IOobject IOobject
( (
surfaceDir/"points", surfaceDir/"points",
dummyTime, *dummyTimePtr,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false