initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / db / Time / timeSelector.H
blob7d1f15fda1dd18115029487823a587cb2c84272f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::timeSelector
28 Description
29     A List of scalarRange for selecting times.
31     The timeSelector provides a convenient means of selecting multiple
32     times. A typical use would be the following:
34     @verbatim
35     timeSelector::addOptions();
36     // add other options
37     #include "setRootCase.H"
38     #include "createTime.H"
39     instantList timeDirs = timeSelector::select0(runTime, args);
40     ...
41     forAll(timeDirs, timeI)
42     {
43         ...
44     }
45     @endverbatim
47     The result program would receive @b -time, @b -latestTime, @b -constant
48     and @b -noZero options. The @b -constant option explicitly includes the
49     @c constant/ directory in the time list and the @b -noZero option
50     explicitly excludes the @c 0/ directory from the time list.
52     There may however also be many cases in which neither the @c constant/
53     directory nor the @c 0/ directory contain particularly relevant
54     information. This might occur, for example, when post-processing
55     results. In this case, addOptions is called with optional boolean
56     arguments.
58     @verbatim
59     timeSelector::addOptions(false, true);
60     @endverbatim
62     The first argument avoids adding the @b -constant option. The second
63     argument adds an additional @b -zeroTime option and prevents the @c 0/
64     directory from being included in the default time range.
66 SourceFiles
67     timeSelector.C
69 \*---------------------------------------------------------------------------*/
71 #ifndef timeSelector_H
72 #define timeSelector_H
74 #include "scalarRanges.H"
75 #include "instant.H"
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
79 namespace Foam
82 // Forward declaration of classes
83 class argList;
84 class Time;
86 /*---------------------------------------------------------------------------*\
87                        Class timeSelector Declaration
88 \*---------------------------------------------------------------------------*/
90 class timeSelector
92     public scalarRanges
94 public:
96     // Constructors
98         //- Construct Null
99         timeSelector();
101         //- Construct from Istream
102         timeSelector(Istream&);
105     // Member Functions
107         //- Return true if the given instant is within the ranges
108         bool selected(const instant&) const;
110         //- Return the set of selected instants in the given list that are
111         //  within the ranges
112         List<bool> selected(const List<instant>&) const;
114         //- Select a list of Time values that are within the ranges
115         List<instant> select(const List<instant>&) const;
117         //- Select a list of Time values that are within the ranges
118         void inplaceSelect(List<instant>&) const;
120         //- Add the options handled by timeSelector to argList::validOptions
121         //
122         // @param constant
123         //   Add the @b -constant option to include the @c constant/ directory
124         // @param zeroTime
125         //   Additional to the @b -noZero option (explicitly exclude the
126         //   @c 0/ directory), add the @b -zeroTime option to include the
127         //   @c 0/ directory. The @b -noZero option has precedence.
128         static void addOptions
129         (
130             const bool constant = true,
131             const bool zeroTime = false
132         );
134         //- Return the set of times selected based on the argList options
135         static List<Foam::instant> select
136         (
137             const List<instant>&,
138             const argList& args
139         );
141         //- Return the set of times selected based on the argList options
142         //  also set the runTime to the first instance
143         static List<Foam::instant> select0
144         (
145             Time& runTime,
146             const argList& args
147         );
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 } // End namespace Foam
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 #endif
159 // ************************************************************************* //