Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
24namespace 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
37MaxTimestep::MaxTimestep(const std::string &description)
38 : MaxTimestep() {
40}
41
42MaxTimestep::MaxTimestep(double v, const std::string &description)
43 : MaxTimestep(v) {
45}
46
47bool MaxTimestep::finite() const {
48 return m_finite;
49}
50
52 return not m_finite;
53}
54
55double MaxTimestep::value() const {
56 return m_value;
57}
58
59std::string MaxTimestep::description() const {
60 return m_description;
61}
62
63bool 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
71bool 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
79bool 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
MaxTimestep()
Create an instance corresponding to an "inactive" time-step restriction (in other words,...
std::string description() const
bool finite() const
Convert to bool to check if a time step restriction is "active".
std::string m_description
double value() const
Get the value of the maximum time step.
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
bool operator>(const MaxTimestep &a, const MaxTimestep &b)
Greater than operator for MaxTimestep.
bool operator<(const MaxTimestep &a, const MaxTimestep &b)
Less than operator for MaxTimestep.
bool operator==(const MaxTimestep &a, const MaxTimestep &b)
Equality operator for MaxTimestep.