PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
CellType.hh
Go to the documentation of this file.
1 /* Copyright (C) 2016, 2019, 2020, 2022, 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 #ifndef PISM_ARRAY_CELLTYPE_H
21 #define PISM_ARRAY_CELLTYPE_H
22 
23 #include "pism/util/array/Scalar.hh"
24 #include "pism/util/Mask.hh"
25 
26 namespace pism {
27 namespace array {
28 
29 //! "Cell type" mask. Adds convenience methods to `array::Scalar`.
30 class CellType : public Scalar {
31 public:
32  CellType(std::shared_ptr<const Grid> grid, const std::string &name);
33 
34  inline bool ocean(int i, int j) const {
35  return mask::ocean(as_int(i, j));
36  }
37 
38  inline bool grounded(int i, int j) const {
39  return mask::grounded(as_int(i, j));
40  }
41 
42  inline bool icy(int i, int j) const {
43  return mask::icy(as_int(i, j));
44  }
45 
46  inline bool grounded_ice(int i, int j) const {
47  return mask::grounded_ice(as_int(i, j));
48  }
49 
50  inline bool floating_ice(int i, int j) const {
51  return mask::floating_ice(as_int(i, j));
52  }
53 
54  inline bool ice_free(int i, int j) const {
55  return mask::ice_free(as_int(i, j));
56  }
57 
58  inline bool ice_free_ocean(int i, int j) const {
59  return mask::ice_free_ocean(as_int(i, j));
60  }
61 
62  inline bool ice_free_land(int i, int j) const {
63  return mask::ice_free_land(as_int(i, j));
64  }
65 protected:
66  CellType(std::shared_ptr<const Grid> grid, const std::string &name, int w);
67 };
68 
69 /*!
70  * Cell type array supporting width=1 stencil computations (ghosted).
71  */
72 class CellType1 : public CellType {
73 public:
74  CellType1(std::shared_ptr<const Grid> grid, const std::string &name);
77  using Scalar::star_int;
78  using Scalar::box_int;
79 
80  //! \brief Ice margin (ice-filled with at least one of four neighbors ice-free).
81  inline bool ice_margin(int i, int j) const {
82  return icy(i, j) and (ice_free(i + 1, j) or ice_free(i - 1, j) or
83  ice_free(i, j + 1) or ice_free(i, j - 1));
84  }
85 
86  //! \brief Ice-free margin (at least one of four neighbors has ice).
87  inline bool next_to_ice(int i, int j) const {
88  return (icy(i + 1, j) or icy(i - 1, j) or icy(i, j + 1) or icy(i, j - 1));
89  }
90 
91  inline bool next_to_floating_ice(int i, int j) const {
92  return (floating_ice(i + 1, j) or floating_ice(i - 1, j) or
93  floating_ice(i, j + 1) or floating_ice(i, j - 1));
94  }
95 
96  inline bool next_to_grounded_ice(int i, int j) const {
97  return (grounded_ice(i + 1, j) or grounded_ice(i - 1, j) or
98  grounded_ice(i, j + 1) or grounded_ice(i, j - 1));
99  }
100 
101  inline bool next_to_ice_free_land(int i, int j) const {
102  return (ice_free_land(i + 1, j) or ice_free_land(i - 1, j) or
103  ice_free_land(i, j + 1) or ice_free_land(i, j - 1));
104  }
105 
106  inline bool next_to_ice_free_ocean(int i, int j) const {
107  return (ice_free_ocean(i + 1, j) or ice_free_ocean(i - 1, j) or
108  ice_free_ocean(i, j + 1) or ice_free_ocean(i, j - 1));
109  }
110 protected:
111  CellType1(std::shared_ptr<const Grid> grid, const std::string &name, int width);
112 };
113 
114 /*!
115  * Cell type array supporting width=2 stencil computations (ghosted).
116  */
117 class CellType2 : public CellType1 {
118 public:
119  CellType2(std::shared_ptr<const Grid> grid, const std::string &name);
120 };
121 
122 } // end of namespace array
123 } // end of namespace pism
124 
125 #endif /* PISM_ARRAY_CELLTYPE_H */
A storage vector combining related fields in a struct.
Definition: Array2D.hh:32
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
CellType1(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: CellType.cc:36
bool next_to_ice(int i, int j) const
Ice-free margin (at least one of four neighbors has ice).
Definition: CellType.hh:87
bool ice_margin(int i, int j) const
Ice margin (ice-filled with at least one of four neighbors ice-free).
Definition: CellType.hh:81
bool next_to_ice_free_land(int i, int j) const
Definition: CellType.hh:101
bool next_to_grounded_ice(int i, int j) const
Definition: CellType.hh:96
bool next_to_floating_ice(int i, int j) const
Definition: CellType.hh:91
bool next_to_ice_free_ocean(int i, int j) const
Definition: CellType.hh:106
CellType2(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: CellType.cc:46
bool ice_free(int i, int j) const
Definition: CellType.hh:54
bool floating_ice(int i, int j) const
Definition: CellType.hh:50
bool ice_free_ocean(int i, int j) const
Definition: CellType.hh:58
bool grounded_ice(int i, int j) const
Definition: CellType.hh:46
CellType(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: CellType.cc:26
bool ocean(int i, int j) const
Definition: CellType.hh:34
bool grounded(int i, int j) const
Definition: CellType.hh:38
bool ice_free_land(int i, int j) const
Definition: CellType.hh:62
bool icy(int i, int j) const
Definition: CellType.hh:42
"Cell type" mask. Adds convenience methods to array::Scalar.
Definition: CellType.hh:30
int as_int(int i, int j) const
Definition: Scalar.hh:45
stencils::Box< int > box_int(int i, int j) const
Definition: Scalar.hh:84
stencils::Star< int > star_int(int i, int j) const
Definition: Scalar.hh:72
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