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
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -114,7 +114,7 @@ int main(int argc, char *argv[])
|
||||
IOobject
|
||||
(
|
||||
dictName,
|
||||
"system",
|
||||
runTime.system(),
|
||||
runTime,
|
||||
IOobject::MUST_READ_IF_MODIFIED,
|
||||
IOobject::NO_WRITE,
|
||||
@ -128,9 +128,9 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
optRewrite = false;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
if
|
||||
(
|
||||
runTime.timeName() != "constant"
|
||||
runTime.timeName() != runTime.constant()
|
||||
&& runTime.timeName() != "0"
|
||||
)
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
if
|
||||
(
|
||||
runTime.timeName() != "constant"
|
||||
runTime.timeName() != runTime.constant()
|
||||
&& runTime.timeName() != "0"
|
||||
)
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
}
|
||||
else if
|
||||
(
|
||||
runTime.timeName() != "constant"
|
||||
runTime.timeName() != runTime.constant()
|
||||
&& runTime.timeName() != "0"
|
||||
)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -575,7 +575,7 @@ double* Foam::vtkPV3Foam::findTimes(int& nTimeSteps)
|
||||
// skip "constant" time whenever possible
|
||||
if (timeI == 0 && nTimes > 1)
|
||||
{
|
||||
if (timeLst[timeI].name() == "constant")
|
||||
if (timeLst[timeI].name() == runTime.constant())
|
||||
{
|
||||
++timeI;
|
||||
--nTimes;
|
||||
|
||||
@ -148,7 +148,7 @@ void Foam::Time::setControls()
|
||||
else
|
||||
{
|
||||
// Search directory for valid time directories
|
||||
instantList timeDirs = findTimes(path());
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
if (startFrom == "firstTime")
|
||||
{
|
||||
@ -694,13 +694,13 @@ Foam::word Foam::Time::timeName() const
|
||||
// Search the construction path for times
|
||||
Foam::instantList Foam::Time::times() const
|
||||
{
|
||||
return findTimes(path());
|
||||
return findTimes(path(), constant());
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::Time::findInstancePath(const instant& t) const
|
||||
{
|
||||
instantList timeDirs = findTimes(path());
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
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
|
||||
{
|
||||
instantList timeDirs = findTimes(path());
|
||||
instantList timeDirs = findTimes(path(), constant());
|
||||
|
||||
// there is only one time (likely "constant") so return it
|
||||
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
|
||||
// {
|
||||
// instantList timeDirs = findTimes(path());
|
||||
// label timeIndex = min(findClosestTimeIndex(timeDirs, t), 0);
|
||||
// instantList timeDirs = findTimes(path(), constant());
|
||||
// label timeIndex = min(findClosestTimeIndex(timeDirs, t), 0, constant());
|
||||
// return timeDirs[timeIndex];
|
||||
// }
|
||||
|
||||
Foam::label Foam::Time::findClosestTimeIndex
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const scalar t
|
||||
const scalar t,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
label nearestIndex = -1;
|
||||
@ -771,7 +772,7 @@ Foam::label Foam::Time::findClosestTimeIndex
|
||||
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
if (timeDirs[timeI].name() == "constant") continue;
|
||||
if (timeDirs[timeI].name() == constantName) continue;
|
||||
|
||||
scalar diff = mag(timeDirs[timeI].value() - t);
|
||||
if (diff < deltaT)
|
||||
|
||||
@ -374,7 +374,12 @@ public:
|
||||
instant findClosestTime(const scalar) const;
|
||||
|
||||
//- 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
|
||||
virtual bool writeObject
|
||||
@ -404,7 +409,11 @@ public:
|
||||
virtual word timeName() const;
|
||||
|
||||
//- 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
|
||||
virtual label startTimeIndex() const;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
@ -53,7 +57,7 @@ Foam::instantList Foam::Time::findTimes(const fileName& directory)
|
||||
bool haveConstant = false;
|
||||
forAll(dirEntries, i)
|
||||
{
|
||||
if (dirEntries[i] == "constant")
|
||||
if (dirEntries[i] == constantName)
|
||||
{
|
||||
Times[nTimes].value() = 0;
|
||||
Times[nTimes].name() = dirEntries[i];
|
||||
|
||||
@ -155,7 +155,8 @@ void Foam::timeSelector::addOptions
|
||||
Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
(
|
||||
const instantList& timeDirs,
|
||||
const argList& args
|
||||
const argList& args,
|
||||
const word& constantName
|
||||
)
|
||||
{
|
||||
if (timeDirs.size())
|
||||
@ -168,7 +169,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
if (timeDirs[timeI].name() == "constant")
|
||||
if (timeDirs[timeI].name() == constantName)
|
||||
{
|
||||
constantIdx = timeI;
|
||||
}
|
||||
@ -250,7 +251,12 @@ Foam::List<Foam::instant> Foam::timeSelector::select0
|
||||
const argList& args
|
||||
)
|
||||
{
|
||||
instantList timeDirs = timeSelector::select(runTime.times(), args);
|
||||
instantList timeDirs = timeSelector::select
|
||||
(
|
||||
runTime.times(),
|
||||
args,
|
||||
runTime.constant()
|
||||
);
|
||||
|
||||
if (timeDirs.empty())
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -138,7 +138,8 @@ public:
|
||||
static instantList select
|
||||
(
|
||||
const instantList&,
|
||||
const argList& args
|
||||
const argList& args,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
//- Return the set of times selected based on the argList options
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -138,7 +138,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
|
||||
IOobject
|
||||
(
|
||||
polyMesh::defaultRegion,
|
||||
"constant",
|
||||
registry.time().constant(),
|
||||
registry
|
||||
),
|
||||
xferMove(points_),
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -26,7 +26,7 @@ License
|
||||
#include "meshReader.H"
|
||||
#include "IOMap.H"
|
||||
#include "OFstream.H"
|
||||
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -80,7 +80,7 @@ void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
|
||||
IOobject
|
||||
(
|
||||
"interfaces",
|
||||
"constant",
|
||||
registry.time().constant(),
|
||||
polyMesh::meshSubDir,
|
||||
registry,
|
||||
IOobject::NO_READ,
|
||||
@ -115,7 +115,7 @@ void Foam::meshReader::writeMeshLabelList
|
||||
IOobject
|
||||
(
|
||||
propertyName,
|
||||
"constant",
|
||||
registry.time().constant(),
|
||||
polyMesh::meshSubDir,
|
||||
registry,
|
||||
IOobject::NO_READ,
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -72,7 +72,7 @@ void Foam::meshWriters::STARCD::getCellTable()
|
||||
IOobject
|
||||
(
|
||||
"cellTableId",
|
||||
"constant",
|
||||
mesh_.time().constant(),
|
||||
polyMesh::meshSubDir,
|
||||
mesh_,
|
||||
IOobject::READ_IF_PRESENT,
|
||||
@ -506,7 +506,7 @@ bool Foam::meshWriters::STARCD::write(const fileName& meshName) const
|
||||
if
|
||||
(
|
||||
mesh_.time().timeName() != "0"
|
||||
&& mesh_.time().timeName() != "constant"
|
||||
&& mesh_.time().timeName() != mesh_.time().constant()
|
||||
)
|
||||
{
|
||||
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"
|
||||
return t.path()/"constant"/localName;
|
||||
return t.path()/t.constant()/localName;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -85,7 +85,7 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
|
||||
IOobject
|
||||
(
|
||||
typeName,
|
||||
"constant",
|
||||
obr.time().constant(),
|
||||
obr,
|
||||
IOobject::READ_IF_PRESENT,
|
||||
IOobject::NO_WRITE
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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"
|
||||
return t.path()/"constant"/localName;
|
||||
return t.path()/t.constant()/localName;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ Foam::fileName Foam::triSurface::triSurfInstance(const Time& d)
|
||||
<< "reading " << foamName
|
||||
<< " from constant/" << endl;
|
||||
}
|
||||
return "constant";
|
||||
return d.constant();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user