PISM, A Parallel Ice Sheet Model  stable v2.0.4 committed by Constantine Khrulev on 2022-05-25 12:02:27 -0800
Mask.hh
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021 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 "iceModelVec.hh"
24 #include "ConfigInterface.hh"
25 #include "error_handling.hh"
26 
27 namespace pism {
28 
29 enum MaskValue {
35 };
36 
37 namespace mask {
38 //! \brief An ocean cell (floating ice or ice-free).
39  inline bool ocean(int M) {
40  return M >= MASK_FLOATING;
41  }
42  //! \brief Grounded cell (grounded ice or ice-free).
43  inline bool grounded(int M) {
44  return not ocean(M);
45  }
46  //! \brief Ice-filled cell (grounded or floating).
47  inline bool icy(int M) {
48  return (M == MASK_GROUNDED) || (M == MASK_FLOATING);
49  }
50  inline bool grounded_ice(int M) {
51  return icy(M) && grounded(M);
52  }
53  inline bool floating_ice(int M) {
54  return icy(M) && ocean(M);
55  }
56  //! \brief Ice-free cell (grounded or ocean).
57  inline bool ice_free(int M) {
58  return not icy(M);
59  }
60  inline bool ice_free_ocean(int M) {
61  return ocean(M) && ice_free(M);
62  }
63  inline bool ice_free_land(int M) {
64  return grounded(M) && ice_free(M);
65  }
66 }
67 
69 public:
70  GeometryCalculator(const Config &config) {
71  m_alpha = 1 - config.get_number("constants.ice.density") / config.get_number("constants.sea_water.density");
72  m_icefree_thickness = config.get_number("geometry.ice_free_thickness_standard");
73  if (m_icefree_thickness < 0.0) {
75  "invalid ice-free thickness threshold: %f", m_icefree_thickness);
76  }
77  }
78 
79  void set_icefree_thickness(double threshold) {
80  if (threshold < 0.0) {
81  throw RuntimeError::formatted(PISM_ERROR_LOCATION, "invalid ice-free thickness threshold: %f", threshold);
82  }
83  m_icefree_thickness = threshold;
84  }
85 
86  void compute(const IceModelVec2S &sea_level, const IceModelVec2S &bed, const IceModelVec2S &thickness,
87  IceModelVec2Int &out_mask, IceModelVec2S &out_surface) const;
88 
89  void compute_mask(const IceModelVec2S& sea_level, const IceModelVec2S& bed,
90  const IceModelVec2S& thickness, IceModelVec2Int& result) const;
91 
92  void compute_surface(const IceModelVec2S& sea_level, const IceModelVec2S& bed,
93  const IceModelVec2S& thickness, IceModelVec2S& result) const;
94 
95  inline void compute(double sea_level, double bed, double thickness,
96  int *out_mask, double *out_surface) const {
97  const double hgrounded = bed + thickness; // FIXME issue #15
98  const double hfloating = sea_level + m_alpha*thickness;
99 
100  const bool
101  is_floating = (hfloating > hgrounded),
102  ice_free = (thickness <= m_icefree_thickness);
103 
104  int mask_result;
105  double surface_result;
106 
107  if (is_floating) {
108  surface_result = hfloating;
109 
110  if (ice_free) {
111  mask_result = MASK_ICE_FREE_OCEAN;
112  } else {
113  mask_result = MASK_FLOATING;
114  }
115  } else { // Grounded
116  surface_result = hgrounded;
117 
118  if (ice_free) {
119  mask_result = MASK_ICE_FREE_BEDROCK;
120  } else {
121  mask_result = MASK_GROUNDED;
122  }
123  }
124 
125  if (out_surface != NULL) {
126  *out_surface = surface_result;
127  }
128 
129  if (out_mask != NULL) {
130  *out_mask = mask_result;
131  }
132  }
133 
134  inline int mask(double sea_level, double bed, double thickness) const {
135  int result;
136  compute(sea_level, bed, thickness, &result, NULL);
137  return result;
138  }
139 
140  inline double surface(double sea_level, double bed, double thickness) const {
141  double result;
142  compute(sea_level, bed, thickness, NULL, &result);
143  return result;
144  }
145 
146 protected:
147  double m_alpha;
149 };
150 
151 } // end of namespace pism
152 
153 #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:148
void compute_mask(const IceModelVec2S &sea_level, const IceModelVec2S &bed, const IceModelVec2S &thickness, IceModelVec2Int &result) const
Definition: Mask.cc:35
void compute(const IceModelVec2S &sea_level, const IceModelVec2S &bed, const IceModelVec2S &thickness, IceModelVec2Int &out_mask, IceModelVec2S &out_surface) const
Definition: Mask.cc:26
void compute(double sea_level, double bed, double thickness, int *out_mask, double *out_surface) const
Definition: Mask.hh:95
void set_icefree_thickness(double threshold)
Definition: Mask.hh:79
GeometryCalculator(const Config &config)
Definition: Mask.hh:70
int mask(double sea_level, double bed, double thickness) const
Definition: Mask.hh:134
void compute_surface(const IceModelVec2S &sea_level, const IceModelVec2S &bed, const IceModelVec2S &thickness, IceModelVec2S &result) const
Definition: Mask.cc:55
double surface(double sea_level, double bed, double thickness) const
Definition: Mask.hh:140
A simple class "hiding" the fact that the mask is stored as floating-point scalars (instead of intege...
Definition: iceModelVec.hh:389
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:47
bool grounded_ice(int M)
Definition: Mask.hh:50
bool ice_free_land(int M)
Definition: Mask.hh:63
bool ice_free_ocean(int M)
Definition: Mask.hh:60
bool grounded(int M)
Grounded cell (grounded ice or ice-free).
Definition: Mask.hh:43
bool ice_free(int M)
Ice-free cell (grounded or ocean).
Definition: Mask.hh:57
bool floating_ice(int M)
Definition: Mask.hh:53
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition: Mask.hh:39
MaskValue
Definition: Mask.hh:29
@ MASK_FLOATING
Definition: Mask.hh:33
@ MASK_ICE_FREE_OCEAN
Definition: Mask.hh:34
@ MASK_ICE_FREE_BEDROCK
Definition: Mask.hh:31
@ MASK_GROUNDED
Definition: Mask.hh:32
@ MASK_UNKNOWN
Definition: Mask.hh:30