PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Mask.hh
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021, 2022, 2023 Constantine Khroulev and David Maxwell
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 #ifndef _MASK_H_
20 #define _MASK_H_
21 
22 // the following three includes are needed here because of inlined code
23 #include "pism/util/ConfigInterface.hh"
24 #include "pism/util/error_handling.hh"
25 
26 namespace pism {
27 namespace array {
28 class Scalar;
29 }
30 enum MaskValue {
36 };
37 
38 namespace mask {
39 //! \brief An ocean cell (floating ice or ice-free).
40 inline bool ocean(int M) {
41  return M >= MASK_FLOATING;
42 }
43 //! \brief Grounded cell (grounded ice or ice-free).
44 inline bool grounded(int M) {
45  return not ocean(M);
46 }
47 //! \brief Ice-filled cell (grounded or floating).
48 inline bool icy(int M) {
49  return (M == MASK_GROUNDED) || (M == MASK_FLOATING);
50 }
51 inline bool grounded_ice(int M) {
52  return icy(M) && grounded(M);
53 }
54 inline bool floating_ice(int M) {
55  return icy(M) && ocean(M);
56 }
57 //! \brief Ice-free cell (grounded or ocean).
58 inline bool ice_free(int M) {
59  return not icy(M);
60 }
61 inline bool ice_free_ocean(int M) {
62  return ocean(M) && ice_free(M);
63 }
64 inline bool ice_free_land(int M) {
65  return grounded(M) && ice_free(M);
66 }
67 } // namespace mask
68 
70 public:
71  GeometryCalculator(const Config &config) {
72  m_alpha = 1 - config.get_number("constants.ice.density") /
73  config.get_number("constants.sea_water.density");
74  m_icefree_thickness = config.get_number("geometry.ice_free_thickness_standard");
75  if (m_icefree_thickness < 0.0) {
76  throw RuntimeError::formatted(PISM_ERROR_LOCATION, "invalid ice-free thickness threshold: %f",
78  }
79  }
80 
81  void set_icefree_thickness(double threshold) {
82  if (threshold < 0.0) {
83  throw RuntimeError::formatted(PISM_ERROR_LOCATION, "invalid ice-free thickness threshold: %f",
84  threshold);
85  }
86  m_icefree_thickness = threshold;
87  }
88 
89  void compute(const array::Scalar &sea_level, const array::Scalar &bed,
90  const array::Scalar &thickness, array::Scalar &out_mask,
91  array::Scalar &out_surface) const;
92 
93  void compute_mask(const array::Scalar &sea_level, const array::Scalar &bed,
94  const array::Scalar &thickness, array::Scalar &result) const;
95 
96  void compute_surface(const array::Scalar &sea_level, const array::Scalar &bed,
97  const array::Scalar &thickness, array::Scalar &result) const;
98 
99  inline void compute(double sea_level, double bed, double thickness,
100  int *out_mask, double *out_surface) const {
101  const double hgrounded = bed + thickness; // FIXME issue #15
102  const double hfloating = sea_level + m_alpha*thickness;
103 
104  const bool
105  is_floating = (hfloating > hgrounded),
106  ice_free = (thickness <= m_icefree_thickness);
107 
108  int mask_result;
109  double surface_result;
110 
111  if (is_floating) {
112  surface_result = hfloating;
113 
114  if (ice_free) {
115  mask_result = MASK_ICE_FREE_OCEAN;
116  } else {
117  mask_result = MASK_FLOATING;
118  }
119  } else { // Grounded
120  surface_result = hgrounded;
121 
122  if (ice_free) {
123  mask_result = MASK_ICE_FREE_BEDROCK;
124  } else {
125  mask_result = MASK_GROUNDED;
126  }
127  }
128 
129  if (out_surface != NULL) {
130  *out_surface = surface_result;
131  }
132 
133  if (out_mask != NULL) {
134  *out_mask = mask_result;
135  }
136  }
137 
138  inline int mask(double sea_level, double bed, double thickness) const {
139  int result;
140  compute(sea_level, bed, thickness, &result, NULL);
141  return result;
142  }
143 
144  inline double surface(double sea_level, double bed, double thickness) const {
145  double result;
146  compute(sea_level, bed, thickness, NULL, &result);
147  return result;
148  }
149 
150 protected:
151  double m_alpha;
153 };
154 
155 } // end of namespace pism
156 
157 #endif /* _MASK_H_ */
double get_number(const std::string &name, UseFlag flag=REMEMBER_THIS_USE) const
A class for storing and accessing PISM configuration flags and parameters.
double m_icefree_thickness
Definition: Mask.hh:152
void compute_mask(const array::Scalar &sea_level, const array::Scalar &bed, const array::Scalar &thickness, array::Scalar &result) const
Definition: Mask.cc:36
void compute(double sea_level, double bed, double thickness, int *out_mask, double *out_surface) const
Definition: Mask.hh:99
void set_icefree_thickness(double threshold)
Definition: Mask.hh:81
GeometryCalculator(const Config &config)
Definition: Mask.hh:71
int mask(double sea_level, double bed, double thickness) const
Definition: Mask.hh:138
double surface(double sea_level, double bed, double thickness) const
Definition: Mask.hh:144
void compute(const array::Scalar &sea_level, const array::Scalar &bed, const array::Scalar &thickness, array::Scalar &out_mask, array::Scalar &out_surface) const
Definition: Mask.cc:27
void compute_surface(const array::Scalar &sea_level, const array::Scalar &bed, const array::Scalar &thickness, array::Scalar &result) const
Definition: Mask.cc:56
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
#define PISM_ERROR_LOCATION
bool icy(int M)
Ice-filled cell (grounded or floating).
Definition: Mask.hh:48
bool grounded_ice(int M)
Definition: Mask.hh:51
bool ice_free_land(int M)
Definition: Mask.hh:64
bool ice_free_ocean(int M)
Definition: Mask.hh:61
bool grounded(int M)
Grounded cell (grounded ice or ice-free).
Definition: Mask.hh:44
bool ice_free(int M)
Ice-free cell (grounded or ocean).
Definition: Mask.hh:58
bool floating_ice(int M)
Definition: Mask.hh:54
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition: Mask.hh:40
MaskValue
Definition: Mask.hh:30
@ MASK_FLOATING
Definition: Mask.hh:34
@ MASK_ICE_FREE_OCEAN
Definition: Mask.hh:35
@ MASK_ICE_FREE_BEDROCK
Definition: Mask.hh:32
@ MASK_GROUNDED
Definition: Mask.hh:33
@ MASK_UNKNOWN
Definition: Mask.hh:31