PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
MaxTimestep.hh
Go to the documentation of this file.
1 /* Copyright (C) 2015, 2016, 2021 PISM Authors
2  *
3  * This file is part of PISM.
4  *
5  * PISM is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with PISM; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef PISM_MAXTIMESTEP_HH
21 #define PISM_MAXTIMESTEP_HH
22 
23 #include <string>
24 
25 namespace pism {
26 
27 //! @brief Combines the max. time step with the flag indicating if a
28 //! restriction is active. Makes is possible to use the less-than
29 //! operator (and `std::min`, etc) to choose the stricter of two
30 //! restrictions.
31 class MaxTimestep {
32 public:
33  //! @brief Create an instance corresponding to an "inactive"
34  //! time-step restriction (in other words, @f$ \Delta t = \infty @f$).
35  MaxTimestep();
36  //! Create an instance corresponding to a max time step of `value`.
37  MaxTimestep(double value);
38 
39  MaxTimestep(const std::string &new_description);
40  //! Create an instance and provide a description.
41  MaxTimestep(double value, const std::string &new_description);
42  //! Convert to `bool` to check if a time step restriction is "active".
43  bool finite() const;
44  bool infinite() const;
45 
46  //! Get the value of the maximum time step.
47  double value() const;
48 
49  std::string description() const;
50 private:
51  bool m_finite;
52  double m_value;
53  std::string m_description;
54 };
55 
56 //! Greater than operator for MaxTimestep.
57 bool operator>(const MaxTimestep &a, const MaxTimestep &b);
58 
59 //! Less than operator for MaxTimestep.
60 bool operator<(const MaxTimestep &a, const MaxTimestep &b);
61 
62 //! Equality operator for MaxTimestep.
63 bool operator==(const MaxTimestep &a, const MaxTimestep &b);
64 
65 } // end of namespace pism
66 
67 #endif /* PISM_MAXTIMESTEP_HH */
bool infinite() const
Definition: MaxTimestep.cc:51
MaxTimestep()
Create an instance corresponding to an "inactive" time-step restriction (in other words,...
Definition: MaxTimestep.cc:27
std::string description() const
Definition: MaxTimestep.cc:59
bool finite() const
Convert to bool to check if a time step restriction is "active".
Definition: MaxTimestep.cc:47
std::string m_description
Definition: MaxTimestep.hh:53
double value() const
Get the value of the maximum time step.
Definition: MaxTimestep.cc:55
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
bool operator>(const MaxTimestep &a, const MaxTimestep &b)
Greater than operator for MaxTimestep.
Definition: MaxTimestep.cc:79
bool operator<(const MaxTimestep &a, const MaxTimestep &b)
Less than operator for MaxTimestep.
Definition: MaxTimestep.cc:71
bool operator==(const MaxTimestep &a, const MaxTimestep &b)
Equality operator for MaxTimestep.
Definition: MaxTimestep.cc:63