PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
MaxTimestep.cc
Go to the documentation of this file.
1 /* Copyright (C) 2015, 2016, 2021, 2023 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 #include "pism/util/MaxTimestep.hh"
21 
22 #include <cassert>
23 
24 namespace pism {
25 
26 // Time step restrictions
28  : m_finite(false), m_value(0.0) {
29  // empty
30 }
31 
33  : m_finite(true), m_value(v) {
34  assert(v > 0.0);
35 }
36 
37 MaxTimestep::MaxTimestep(const std::string &description)
38  : MaxTimestep() {
40 }
41 
42 MaxTimestep::MaxTimestep(double v, const std::string &description)
43  : MaxTimestep(v) {
45 }
46 
47 bool MaxTimestep::finite() const {
48  return m_finite;
49 }
50 
51 bool MaxTimestep::infinite() const {
52  return not m_finite;
53 }
54 
55 double MaxTimestep::value() const {
56  return m_value;
57 }
58 
59 std::string MaxTimestep::description() const {
60  return m_description;
61 }
62 
63 bool operator==(const MaxTimestep &a, const MaxTimestep &b) {
64  if (a.finite() and b.finite()) {
65  return a.value() == b.value();
66  }
67 
68  return (a.infinite() and b.infinite());
69 }
70 
71 bool operator<(const MaxTimestep &a, const MaxTimestep &b) {
72  if (a.finite() and b.finite()) {
73  return a.value() < b.value();
74  }
75 
76  return a.finite();
77 }
78 
79 bool operator>(const MaxTimestep &a, const MaxTimestep &b) {
80  return (not (a == b)) and (not (a < b));
81 }
82 
83 } // end of namespace pism
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