OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

timeSelector.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::timeSelector
00027 
00028 Description
00029     A List of scalarRange for selecting times.
00030 
00031     The timeSelector provides a convenient means of selecting multiple
00032     times. A typical use would be the following:
00033 
00034     @verbatim
00035     timeSelector::addOptions();
00036     // add other options
00037     #include "setRootCase.H"
00038     #include "createTime.H"
00039     instantList timeDirs = timeSelector::select0(runTime, args);
00040     ...
00041     forAll(timeDirs, timeI)
00042     {
00043         ...
00044     }
00045     @endverbatim
00046 
00047     The result program would receive @b -time, @b -latestTime, @b -constant
00048     and @b -noZero options. The @b -constant option explicitly includes the
00049     @c constant/ directory in the time list and the @b -noZero option
00050     explicitly excludes the @c 0/ directory from the time list.
00051 
00052     There may however also be many cases in which neither the @c constant/
00053     directory nor the @c 0/ directory contain particularly relevant
00054     information. This might occur, for example, when post-processing
00055     results. In this case, addOptions is called with optional boolean
00056     arguments.
00057 
00058     @verbatim
00059     timeSelector::addOptions(false, true);
00060     @endverbatim
00061 
00062     The first argument avoids adding the @b -constant option. The second
00063     argument adds an additional @b -zeroTime option and also prevents the
00064     @c 0/ directory from being included in the default time range and in the
00065     @b -latestTime selection.
00066 
00067 SourceFiles
00068     timeSelector.C
00069 
00070 \*---------------------------------------------------------------------------*/
00071 
00072 #ifndef timeSelector_H
00073 #define timeSelector_H
00074 
00075 #include "scalarRanges.H"
00076 #include "instant.H"
00077 
00078 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00079 
00080 namespace Foam
00081 {
00082 
00083 // Forward declaration of classes
00084 class argList;
00085 class Time;
00086 
00087 /*---------------------------------------------------------------------------*\
00088                         Class timeSelector Declaration
00089 \*---------------------------------------------------------------------------*/
00090 
00091 class timeSelector
00092 :
00093     public scalarRanges
00094 {
00095 public:
00096 
00097     // Constructors
00098 
00099         //- Construct Null
00100         timeSelector();
00101 
00102         //- Construct from Istream
00103         timeSelector(Istream&);
00104 
00105 
00106     // Member Functions
00107 
00108         //- Return true if the given instant is within the ranges
00109         bool selected(const instant&) const;
00110 
00111         //- Return the set of selected instants in the given list that are
00112         //  within the ranges
00113         List<bool> selected(const List<instant>&) const;
00114 
00115         //- Select a list of Time values that are within the ranges
00116         List<instant> select(const List<instant>&) const;
00117 
00118         //- Select a list of Time values that are within the ranges
00119         void inplaceSelect(List<instant>&) const;
00120 
00121         //- Add the options handled by timeSelector to argList::validOptions
00122         //
00123         // @param constant
00124         //   Add the @b -constant option to include the @c constant/ directory
00125         //
00126         // @param zeroTime
00127         //   Enable the @b -zeroTime option and alter the normal time selection
00128         //   behaviour (and @b -latestTime behaviour) to exclude the @c 0/
00129         //   directory. The @c 0/ directory will only be included when
00130         //   @b -zeroTime is specified.
00131         //   The @b -noZero option has precedence over the @b -zeroTime option.
00132         static void addOptions
00133         (
00134             const bool constant=true,
00135             const bool zeroTime=false
00136         );
00137 
00138         //- Return the set of times selected based on the argList options
00139         static List<instant> select
00140         (
00141             const List<instant>&,
00142             const argList& args
00143         );
00144 
00145         //- Return the set of times selected based on the argList options
00146         //  also set the runTime to the first instance
00147         static List<instant> select0
00148         (
00149             Time& runTime,
00150             const argList& args
00151         );
00152 };
00153 
00154 
00155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00156 
00157 } // End namespace Foam
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 #endif
00162 
00163 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd