tIceModelVec_inline.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
(HTM) git clone git://src.adamsgaard.dk/pism
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
tIceModelVec_inline.hh (4482B)
---
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& IceModelVec2::operator() (int i, int j, int k) {
29 #if (Pism_DEBUG==1)
30 check_array_indices(i, j, k);
31 #endif
32 return static_cast<double***>(m_array)[j][i][k];
33 }
34
35 inline const double& IceModelVec2::operator() (int i, int j, int k) const {
36 #if (Pism_DEBUG==1)
37 check_array_indices(i, j, k);
38 #endif
39 return static_cast<double***>(m_array)[j][i][k];
40 }
41
42 inline double& IceModelVec2S::operator() (int i, int j) {
43 #if (Pism_DEBUG==1)
44 check_array_indices(i, j, 0);
45 #endif
46 return static_cast<double**>(m_array)[j][i];
47 }
48
49 inline const double& IceModelVec2S::operator()(int i, int j) const {
50 #if (Pism_DEBUG==1)
51 check_array_indices(i, j, 0);
52 #endif
53 return static_cast<double**>(m_array)[j][i];
54 }
55
56 inline StarStencil<double> IceModelVec2S::star(int i, int j) const {
57 const IceModelVec2S &self = *this;
58
59 StarStencil<double> result;
60 result.ij = self(i,j);
61 result.e = self(i+1,j);
62 result.w = self(i-1,j);
63 result.n = self(i,j+1);
64 result.s = self(i,j-1);
65
66 return result;
67 }
68
69 inline BoxStencil<double> IceModelVec2S::box(int i, int j) const {
70 const IceModelVec2S &x = *this;
71
72 const int
73 E = i + 1,
74 W = i - 1,
75 N = j + 1,
76 S = j - 1;
77
78 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)};
79 }
80
81 inline StarStencil<double> IceModelVec2Stag::star(int i, int j) const {
82 const IceModelVec2Stag &self = *this;
83
84 StarStencil<double> result;
85
86 result.ij = 0.0; // has no meaning in this context
87 result.e = self(i, j, 0);
88 result.w = self(i-1, j, 0);
89 result.n = self(i, j, 1);
90 result.s = self(i, j-1, 1);
91
92 return result;
93 }
94
95 inline int IceModelVec2Int::as_int(int i, int j) const {
96 #if (Pism_DEBUG==1)
97 check_array_indices(i, j, 0);
98 #endif
99 const double **a = (const double**) m_array;
100 return static_cast<int>(floor(a[j][i] + 0.5));
101 }
102
103 inline StarStencil<int> IceModelVec2Int::int_star(int i, int j) const {
104 StarStencil<int> result;
105
106 result.ij = as_int(i,j);
107 result.e = as_int(i+1,j);
108 result.w = as_int(i-1,j);
109 result.n = as_int(i,j+1);
110 result.s = as_int(i,j-1);
111
112 return result;
113 }
114
115 inline BoxStencil<int> IceModelVec2Int::int_box(int i, int j) const {
116 const IceModelVec2Int &x = *this;
117
118 const int
119 E = i + 1,
120 W = i - 1,
121 N = j + 1,
122 S = j - 1;
123
124 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),
125 x.as_int(i, S), x.as_int(E, S), x.as_int(E, j), x.as_int(E, N)};
126 }
127
128 inline Vector2& IceModelVec2V::operator()(int i, int j) {
129 #if (Pism_DEBUG==1)
130 check_array_indices(i, j, 0);
131 #endif
132 return static_cast<Vector2**>(m_array)[j][i];
133 }
134
135 inline const Vector2& IceModelVec2V::operator()(int i, int j) const {
136 #if (Pism_DEBUG==1)
137 check_array_indices(i, j, 0);
138 #endif
139 return static_cast<Vector2**>(m_array)[j][i];
140 }
141
142 inline StarStencil<Vector2> IceModelVec2V::star(int i, int j) const {
143 const IceModelVec2V &self = *this;
144
145 StarStencil<Vector2> result;
146
147 result.ij = self(i,j);
148 result.e = self(i+1,j);
149 result.w = self(i-1,j);
150 result.n = self(i,j+1);
151 result.s = self(i,j-1);
152
153 return result;
154 }
155
156 inline double& IceModelVec3D::operator() (int i, int j, int k) {
157 #if (Pism_DEBUG==1)
158 check_array_indices(i, j, k);
159 #endif
160 return static_cast<double***>(m_array)[j][i][k];
161 }
162
163 inline const double& IceModelVec3D::operator() (int i, int j, int k) const {
164 #if (Pism_DEBUG==1)
165 check_array_indices(i, j, k);
166 #endif
167 return static_cast<double***>(m_array)[j][i][k];
168 }
169
170 } // end of namespace pism
171
172 #endif /* _ICEMODELVEC_INLINE_H_ */