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 * * * * * * * * * * * * * * * //
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
virtual ~Time();

View File

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

View File

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

View File

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

View File

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

View File

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