1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 If "name" is empty: return the location of "directory"
26 If "name" is not empty: return the location of "directory" containing the
28 Used in reading mesh data.
30 \*---------------------------------------------------------------------------*/
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 Foam::word Foam::Time::findInstance
41 const IOobject::readOption rOpt,
42 const word& stopInstance
45 // Note: if name is empty, just check the directory itself
48 const fileName tPath(path());
49 const fileName dirPath(tPath/timeName()/dir);
51 // check the current time directory
59 && IOobject(name, timeName(), dir, *this).headerOk()
65 Info<< "Time::findInstance"
66 "(const fileName&, const word&"
67 ", const IOobject::readOption, const word&)"
68 << " : found \"" << name
69 << "\" in " << timeName()/dir
76 // Search back through the time directories to find the time
77 // closest to and lower than current time
79 instantList ts = times();
82 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
84 if (ts[instanceI].value() <= timeOutputValue())
90 // continue searching from here
91 for (; instanceI >= 0; --instanceI)
96 ? isDir(tPath/ts[instanceI].name()/dir)
99 isFile(tPath/ts[instanceI].name()/dir/name)
100 && IOobject(name, ts[instanceI].name(), dir, *this).headerOk()
106 Info<< "Time::findInstance"
107 "(const fileName&, const word&"
108 ", const IOobject::readOption, const word&)"
109 << " : found \"" << name
110 << "\" in " << ts[instanceI].name()/dir
114 return ts[instanceI].name();
117 // Check if hit minimum instance
118 if (ts[instanceI].name() == stopInstance)
122 Info<< "Time::findInstance"
123 "(const fileName&, const word&"
124 ", const IOobject::readOption, const word&)"
125 << " : hit stopInstance " << stopInstance
131 rOpt == IOobject::MUST_READ
132 || rOpt == IOobject::MUST_READ_IF_MODIFIED
138 "(const fileName&, const word&"
139 ", const IOobject::readOption, const word&)"
140 ) << "Cannot find file \"" << name << "\" in directory "
141 << dir << " in times " << timeName()
142 << " down to " << stopInstance
146 return ts[instanceI].name();
151 // not in any of the time directories, try constant
153 // Note. This needs to be a hard-coded constant, rather than the
154 // constant function of the time, because the latter points to
155 // the case constant directory in parallel cases
160 ? isDir(tPath/constant()/dir)
163 isFile(tPath/constant()/dir/name)
164 && IOobject(name, constant(), dir, *this).headerOk()
170 Info<< "Time::findInstance"
171 "(const fileName&, const word&"
172 ", const IOobject::readOption, const word&)"
173 << " : found \"" << name
174 << "\" in " << constant()/dir
181 if (rOpt == IOobject::MUST_READ || rOpt == IOobject::MUST_READ_IF_MODIFIED)
186 "(const fileName&, const word&"
187 ", const IOobject::readOption, const word&)"
188 ) << "Cannot find file \"" << name << "\" in directory "
189 << dir << " in times " << timeName()
190 << " down to " << constant()
198 // ************************************************************************* //