PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
stencils.hh
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 #ifndef PISM_STENCILS_HH
21 #define PISM_STENCILS_HH
22 
23 namespace pism {
24 enum Direction {North = 0, East, South, West};
25 
26 namespace stencils {
27 
28 //! \brief Star stencil points (in the map-plane).
29 template <typename T>
30 struct Star {
31  T c, e, w, n, s;
32 
33  Star() = default;
34 
35  Star(T value) {
36  set(value);
37  }
38 
39  void set(T input) {
40  c = e = w = n = s = input;
41  }
42 
43  //! Get the element corresponding to a given direction.
44  //! Use foo.c to get the value at i,j (center of the star).
45  inline T& operator[](Direction direction) {
46  switch (direction) {
47  default: // just to silence the warning
48  case North:
49  return n;
50  case East:
51  return e;
52  case South:
53  return s;
54  case West:
55  return w;
56  }
57  }
58 
59  inline const T& operator[](Direction direction) const {
60  switch (direction) {
61  default: // just to silence the warning
62  case North:
63  return n;
64  case East:
65  return e;
66  case South:
67  return s;
68  case West:
69  return w;
70  }
71  }
72 };
73 
74 // NB: Do not change the order of elements in this struct. array::Array2D::box() depends
75 // on it.
76 template <typename T>
77 struct Box {
78  T c, n, nw, w, sw, s, se, e, ne;
79 };
80 
81 } // end of namespace stencils
82 
83 } // end of namespace pism
84 
85 #endif /* PISM_STENCILS_HH */
Direction
Definition: stencils.hh:24
@ North
Definition: stencils.hh:24
@ East
Definition: stencils.hh:24
@ South
Definition: stencils.hh:24
@ West
Definition: stencils.hh:24
T & operator[](Direction direction)
Definition: stencils.hh:45
void set(T input)
Definition: stencils.hh:39
const T & operator[](Direction direction) const
Definition: stencils.hh:59
Star stencil points (in the map-plane).
Definition: stencils.hh:30