tMaxTimestep.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tMaxTimestep.cc (2166B)
---
1 /* Copyright (C) 2015, 2016 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 "MaxTimestep.hh"
21
22 namespace pism {
23
24 // Time step restrictions
25 MaxTimestep::MaxTimestep()
26 : m_finite(false), m_value(0.0) {
27 // empty
28 }
29
30 MaxTimestep::MaxTimestep(double v)
31 : m_finite(true), m_value(v) {
32 // empty
33 }
34
35 MaxTimestep::MaxTimestep(const std::string &new_description)
36 : m_finite(false), m_value(0.0), m_description(new_description) {
37 // empty
38 }
39
40 MaxTimestep::MaxTimestep(double v, const std::string &new_description)
41 : m_finite(true), m_value(v), m_description(new_description) {
42 // empty
43 }
44
45 bool MaxTimestep::finite() const {
46 return m_finite;
47 }
48
49 bool MaxTimestep::infinite() const {
50 return not m_finite;
51 }
52
53 double MaxTimestep::value() const {
54 return m_value;
55 }
56
57 std::string MaxTimestep::description() const {
58 return m_description;
59 }
60
61 bool operator==(const MaxTimestep &a, const MaxTimestep &b) {
62 if (a.finite() and b.finite()) {
63 return a.value() == b.value();
64 } else if (a.infinite() and b.infinite()) {
65 return true;
66 } else {
67 return false;
68 }
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 } else if (a.finite()) {
75 return true;
76 } else if (b.finite()) {
77 return false;
78 } else {
79 return false;
80 }
81 }
82
83 bool operator>(const MaxTimestep &a, const MaxTimestep &b) {
84 return (not (a == b)) and (not (a < b));
85 }
86
87 } // end of namespace pism