mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Time: use constant(), time() instead of hardcoded strings
This commit is contained in:
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -114,7 +114,7 @@ int main(int argc, char *argv[])
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
dictName,
|
dictName,
|
||||||
"system",
|
runTime.system(),
|
||||||
runTime,
|
runTime,
|
||||||
IOobject::MUST_READ_IF_MODIFIED,
|
IOobject::MUST_READ_IF_MODIFIED,
|
||||||
IOobject::NO_WRITE,
|
IOobject::NO_WRITE,
|
||||||
@ -128,9 +128,9 @@ int main(int argc, char *argv[])
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optRewrite && solutionDict.instance() != "system")
|
if (optRewrite && solutionDict.instance() != runTime.system())
|
||||||
{
|
{
|
||||||
Info<<"instance is not 'system' "
|
Info<<"instance is not " << runTime.system()
|
||||||
"- disabling rewrite for this file" << nl;
|
"- disabling rewrite for this file" << nl;
|
||||||
optRewrite = false;
|
optRewrite = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
runTime.timeName() != "constant"
|
runTime.timeName() != runTime.constant()
|
||||||
&& runTime.timeName() != "0"
|
&& runTime.timeName() != "0"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
runTime.timeName() != "constant"
|
runTime.timeName() != runTime.constant()
|
||||||
&& runTime.timeName() != "0"
|
&& runTime.timeName() != "0"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
else if
|
else if
|
||||||
(
|
(
|
||||||
runTime.timeName() != "constant"
|
runTime.timeName() != runTime.constant()
|
||||||
&& runTime.timeName() != "0"
|
&& runTime.timeName() != "0"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -575,7 +575,7 @@ double* Foam::vtkPV3Foam::findTimes(int& nTimeSteps)
|
|||||||
// skip "constant" time whenever possible
|
// skip "constant" time whenever possible
|
||||||
if (timeI == 0 && nTimes > 1)
|
if (timeI == 0 && nTimes > 1)
|
||||||
{
|
{
|
||||||
if (timeLst[timeI].name() == "constant")
|
if (timeLst[timeI].name() == runTime.constant())
|
||||||
{
|
{
|
||||||
++timeI;
|
++timeI;
|
||||||
--nTimes;
|
--nTimes;
|
||||||
|
|||||||
@ -148,7 +148,7 @@ void Foam::Time::setControls()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Search directory for valid time directories
|
// Search directory for valid time directories
|
||||||
instantList timeDirs = findTimes(path());
|
instantList timeDirs = findTimes(path(), constant());
|
||||||
|
|
||||||
if (startFrom == "firstTime")
|
if (startFrom == "firstTime")
|
||||||
{
|
{
|
||||||
@ -694,13 +694,13 @@ Foam::word Foam::Time::timeName() const
|
|||||||
// Search the construction path for times
|
// Search the construction path for times
|
||||||
Foam::instantList Foam::Time::times() const
|
Foam::instantList Foam::Time::times() const
|
||||||
{
|
{
|
||||||
return findTimes(path());
|
return findTimes(path(), constant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::Time::findInstancePath(const instant& t) const
|
Foam::word Foam::Time::findInstancePath(const instant& t) const
|
||||||
{
|
{
|
||||||
instantList timeDirs = findTimes(path());
|
instantList timeDirs = findTimes(path(), constant());
|
||||||
|
|
||||||
forAllReverse(timeDirs, timeI)
|
forAllReverse(timeDirs, timeI)
|
||||||
{
|
{
|
||||||
@ -716,7 +716,7 @@ Foam::word Foam::Time::findInstancePath(const instant& t) const
|
|||||||
|
|
||||||
Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||||
{
|
{
|
||||||
instantList timeDirs = findTimes(path());
|
instantList timeDirs = findTimes(path(), constant());
|
||||||
|
|
||||||
// there is only one time (likely "constant") so return it
|
// there is only one time (likely "constant") so return it
|
||||||
if (timeDirs.size() == 1)
|
if (timeDirs.size() == 1)
|
||||||
@ -755,15 +755,16 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
|||||||
//
|
//
|
||||||
// Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
// Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||||
// {
|
// {
|
||||||
// instantList timeDirs = findTimes(path());
|
// instantList timeDirs = findTimes(path(), constant());
|
||||||
// label timeIndex = min(findClosestTimeIndex(timeDirs, t), 0);
|
// label timeIndex = min(findClosestTimeIndex(timeDirs, t), 0, constant());
|
||||||
// return timeDirs[timeIndex];
|
// return timeDirs[timeIndex];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Foam::label Foam::Time::findClosestTimeIndex
|
Foam::label Foam::Time::findClosestTimeIndex
|
||||||
(
|
(
|
||||||
const instantList& timeDirs,
|
const instantList& timeDirs,
|
||||||
const scalar t
|
const scalar t,
|
||||||
|
const word& constantName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
label nearestIndex = -1;
|
label nearestIndex = -1;
|
||||||
@ -771,7 +772,7 @@ Foam::label Foam::Time::findClosestTimeIndex
|
|||||||
|
|
||||||
forAll(timeDirs, timeI)
|
forAll(timeDirs, timeI)
|
||||||
{
|
{
|
||||||
if (timeDirs[timeI].name() == "constant") continue;
|
if (timeDirs[timeI].name() == constantName) continue;
|
||||||
|
|
||||||
scalar diff = mag(timeDirs[timeI].value() - t);
|
scalar diff = mag(timeDirs[timeI].value() - t);
|
||||||
if (diff < deltaT)
|
if (diff < deltaT)
|
||||||
|
|||||||
@ -374,7 +374,12 @@ public:
|
|||||||
instant findClosestTime(const scalar) const;
|
instant findClosestTime(const scalar) const;
|
||||||
|
|
||||||
//- Search instantList for the time index closest to the given time
|
//- Search instantList for the time index closest to the given time
|
||||||
static label findClosestTimeIndex(const instantList&, const scalar);
|
static label findClosestTimeIndex
|
||||||
|
(
|
||||||
|
const instantList&,
|
||||||
|
const scalar,
|
||||||
|
const word& constantName = "constant"
|
||||||
|
);
|
||||||
|
|
||||||
//- Write using given format, version and compression
|
//- Write using given format, version and compression
|
||||||
virtual bool writeObject
|
virtual bool writeObject
|
||||||
@ -404,7 +409,11 @@ public:
|
|||||||
virtual word timeName() const;
|
virtual word timeName() const;
|
||||||
|
|
||||||
//- Search a given directory for valid time directories
|
//- Search a given directory for valid time directories
|
||||||
static instantList findTimes(const fileName&);
|
static instantList findTimes
|
||||||
|
(
|
||||||
|
const fileName&,
|
||||||
|
const word& constantName = "constant"
|
||||||
|
);
|
||||||
|
|
||||||
//- Return start time index
|
//- Return start time index
|
||||||
virtual label startTimeIndex() const;
|
virtual label startTimeIndex() const;
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -34,7 +34,11 @@ Description
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::instantList Foam::Time::findTimes(const fileName& directory)
|
Foam::instantList Foam::Time::findTimes
|
||||||
|
(
|
||||||
|
const fileName& directory,
|
||||||
|
const word& constantName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
@ -53,7 +57,7 @@ Foam::instantList Foam::Time::findTimes(const fileName& directory)
|
|||||||
bool haveConstant = false;
|
bool haveConstant = false;
|
||||||
forAll(dirEntries, i)
|
forAll(dirEntries, i)
|
||||||
{
|
{
|
||||||
if (dirEntries[i] == "constant")
|
if (dirEntries[i] == constantName)
|
||||||
{
|
{
|
||||||
Times[nTimes].value() = 0;
|
Times[nTimes].value() = 0;
|
||||||
Times[nTimes].name() = dirEntries[i];
|
Times[nTimes].name() = dirEntries[i];
|
||||||
|
|||||||
@ -155,7 +155,8 @@ void Foam::timeSelector::addOptions
|
|||||||
Foam::List<Foam::instant> Foam::timeSelector::select
|
Foam::List<Foam::instant> Foam::timeSelector::select
|
||||||
(
|
(
|
||||||
const instantList& timeDirs,
|
const instantList& timeDirs,
|
||||||
const argList& args
|
const argList& args,
|
||||||
|
const word& constantName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (timeDirs.size())
|
if (timeDirs.size())
|
||||||
@ -168,7 +169,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
|||||||
|
|
||||||
forAll(timeDirs, timeI)
|
forAll(timeDirs, timeI)
|
||||||
{
|
{
|
||||||
if (timeDirs[timeI].name() == "constant")
|
if (timeDirs[timeI].name() == constantName)
|
||||||
{
|
{
|
||||||
constantIdx = timeI;
|
constantIdx = timeI;
|
||||||
}
|
}
|
||||||
@ -250,7 +251,12 @@ Foam::List<Foam::instant> Foam::timeSelector::select0
|
|||||||
const argList& args
|
const argList& args
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
instantList timeDirs = timeSelector::select(runTime.times(), args);
|
instantList timeDirs = timeSelector::select
|
||||||
|
(
|
||||||
|
runTime.times(),
|
||||||
|
args,
|
||||||
|
runTime.constant()
|
||||||
|
);
|
||||||
|
|
||||||
if (timeDirs.empty())
|
if (timeDirs.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -138,7 +138,8 @@ public:
|
|||||||
static instantList select
|
static instantList select
|
||||||
(
|
(
|
||||||
const instantList&,
|
const instantList&,
|
||||||
const argList& args
|
const argList& args,
|
||||||
|
const word& constantName = "constant"
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Return the set of times selected based on the argList options
|
//- Return the set of times selected based on the argList options
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -138,7 +138,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
polyMesh::defaultRegion,
|
polyMesh::defaultRegion,
|
||||||
"constant",
|
registry.time().constant(),
|
||||||
registry
|
registry
|
||||||
),
|
),
|
||||||
xferMove(points_),
|
xferMove(points_),
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -26,7 +26,7 @@ License
|
|||||||
#include "meshReader.H"
|
#include "meshReader.H"
|
||||||
#include "IOMap.H"
|
#include "IOMap.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
|
#include "Time.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
"interfaces",
|
"interfaces",
|
||||||
"constant",
|
registry.time().constant(),
|
||||||
polyMesh::meshSubDir,
|
polyMesh::meshSubDir,
|
||||||
registry,
|
registry,
|
||||||
IOobject::NO_READ,
|
IOobject::NO_READ,
|
||||||
@ -115,7 +115,7 @@ void Foam::meshReader::writeMeshLabelList
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
propertyName,
|
propertyName,
|
||||||
"constant",
|
registry.time().constant(),
|
||||||
polyMesh::meshSubDir,
|
polyMesh::meshSubDir,
|
||||||
registry,
|
registry,
|
||||||
IOobject::NO_READ,
|
IOobject::NO_READ,
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -72,7 +72,7 @@ void Foam::meshWriters::STARCD::getCellTable()
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
"cellTableId",
|
"cellTableId",
|
||||||
"constant",
|
mesh_.time().constant(),
|
||||||
polyMesh::meshSubDir,
|
polyMesh::meshSubDir,
|
||||||
mesh_,
|
mesh_,
|
||||||
IOobject::READ_IF_PRESENT,
|
IOobject::READ_IF_PRESENT,
|
||||||
@ -506,7 +506,7 @@ bool Foam::meshWriters::STARCD::write(const fileName& meshName) const
|
|||||||
if
|
if
|
||||||
(
|
(
|
||||||
mesh_.time().timeName() != "0"
|
mesh_.time().timeName() != "0"
|
||||||
&& mesh_.time().timeName() != "constant"
|
&& mesh_.time().timeName() != mesh_.time().constant()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
baseName += "_" + mesh_.time().timeName();
|
baseName += "_" + mesh_.time().timeName();
|
||||||
|
|||||||
@ -105,7 +105,7 @@ Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshInstance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "constant";
|
return t.constant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fallback to "constant"
|
// fallback to "constant"
|
||||||
return t.path()/"constant"/localName;
|
return t.path()/t.constant()/localName;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -85,7 +85,7 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
|
|||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
typeName,
|
typeName,
|
||||||
"constant",
|
obr.time().constant(),
|
||||||
obr,
|
obr,
|
||||||
IOobject::READ_IF_PRESENT,
|
IOobject::READ_IF_PRESENT,
|
||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
|
|||||||
@ -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) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -105,7 +105,7 @@ Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "constant";
|
return t.constant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fallback to "constant"
|
// fallback to "constant"
|
||||||
return t.path()/"constant"/localName;
|
return t.path()/t.constant()/localName;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ Foam::fileName Foam::triSurface::triSurfInstance(const Time& d)
|
|||||||
<< "reading " << foamName
|
<< "reading " << foamName
|
||||||
<< " from constant/" << endl;
|
<< " from constant/" << endl;
|
||||||
}
|
}
|
||||||
return "constant";
|
return d.constant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user