PISM, A Parallel Ice Sheet Model  stable v2.0.6 committed by Constantine Khrulev on 2023-01-23 15:14:38 -0900
IceModelVec_inline.hh
Go to the documentation of this file.
1 /* Copyright (C) 2015, 2016, 2017, 2019 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 _ICEMODELVEC_INLINE_H_
21 #define _ICEMODELVEC_INLINE_H_
22 
23 // This header is included by iceModelVec.hh. Do not include it
24 // manually.
25 
26 namespace pism {
27 
28 inline double& IceModelVec2S::operator() (int i, int j) {
29 #if (Pism_DEBUG==1)
30  check_array_indices(i, j, 0);
31 #endif
32  return static_cast<double**>(m_array)[j][i];
33 }
34 
35 inline const double& IceModelVec2S::operator()(int i, int j) const {
36 #if (Pism_DEBUG==1)
37  check_array_indices(i, j, 0);
38 #endif
39  return static_cast<double**>(m_array)[j][i];
40 }
41 
42 inline stencils::Star<double> IceModelVec2S::star(int i, int j) const {
43  const IceModelVec2S &self = *this;
44 
46  result.ij = self(i,j);
47  result.e = self(i+1,j);
48  result.w = self(i-1,j);
49  result.n = self(i,j+1);
50  result.s = self(i,j-1);
51 
52  return result;
53 }
54 
55 inline stencils::Box<double> IceModelVec2S::box(int i, int j) const {
56  const IceModelVec2S &x = *this;
57 
58  const int
59  E = i + 1,
60  W = i - 1,
61  N = j + 1,
62  S = j - 1;
63 
64  return {x(i, j), x(i, N), x(W, N), x(W, j), x(W, S), x(i, S), x(E, S), x(E, j), x(E, N)};
65 }
66 
67 inline stencils::Star<double> IceModelVec2Stag::star(int i, int j) const {
68  const IceModelVec2Stag &self = *this;
69 
71 
72  result.ij = 0.0; // has no meaning in this context
73  result.e = self(i, j, 0);
74  result.w = self(i-1, j, 0);
75  result.n = self(i, j, 1);
76  result.s = self(i, j-1, 1);
77 
78  return result;
79 }
80 
81 inline int IceModelVec2Int::as_int(int i, int j) const {
82 #if (Pism_DEBUG==1)
83  check_array_indices(i, j, 0);
84 #endif
85  const double **a = (const double**) m_array;
86  return static_cast<int>(floor(a[j][i] + 0.5));
87 }
88 
89 inline stencils::Star<int> IceModelVec2Int::star(int i, int j) const {
90  stencils::Star<int> result;
91 
92  result.ij = as_int(i,j);
93  result.e = as_int(i+1,j);
94  result.w = as_int(i-1,j);
95  result.n = as_int(i,j+1);
96  result.s = as_int(i,j-1);
97 
98  return result;
99 }
100 
101 inline stencils::Box<int> IceModelVec2Int::box(int i, int j) const {
102  const IceModelVec2Int &x = *this;
103 
104  const int
105  E = i + 1,
106  W = i - 1,
107  N = j + 1,
108  S = j - 1;
109 
110  return {x.as_int(i, j), x.as_int(i, N), x.as_int(W, N), x.as_int(W, j), x.as_int(W, S),
111  x.as_int(i, S), x.as_int(E, S), x.as_int(E, j), x.as_int(E, N)};
112 }
113 
114 inline double& IceModelVec3::operator() (int i, int j, int k) {
115 #if (Pism_DEBUG==1)
116  check_array_indices(i, j, k);
117 #endif
118  return static_cast<double***>(m_array)[j][i][k];
119 }
120 
121 inline const double& IceModelVec3::operator() (int i, int j, int k) const {
122 #if (Pism_DEBUG==1)
123  check_array_indices(i, j, k);
124 #endif
125  return static_cast<double***>(m_array)[j][i][k];
126 }
127 
128 } // end of namespace pism
129 
130 #endif /* _ICEMODELVEC_INLINE_H_ */
stencils::Box< int > box(int i, int j) const
int as_int(int i, int j) const
stencils::Star< int > star(int i, int j) const
A simple class "hiding" the fact that the mask is stored as floating-point scalars (instead of intege...
Definition: iceModelVec.hh:389
double & operator()(int i, int j)
Provides access (both read and write) to the internal double array.
stencils::Box< double > box(int i, int j) const
stencils::Star< double > star(int i, int j) const
stencils::Star< double > star(int i, int j) const
Returns the values at interfaces of the cell i,j using the staggered grid.
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
Definition: iceModelVec.hh:449
double & operator()(int i, int j, int k)
void check_array_indices(int i, int j, unsigned int k) const
Check array indices and warn if they are out of range.
Definition: iceModelVec.cc:690
static const double k
Definition: exactTestP.cc:45
Star stencil points (in the map-plane).
Definition: stencils.hh:30
static double S(unsigned n)
Definition: test_cube.c:58