BISICLES AMR ice sheet model  0.9
RealFunction.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3 * _______ __
4 * / ___/ / ___ __ _ / / ___
5 * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6 * \___/_//_/\___/_/_/_/_.__/\___/
7 * Please refer to Copyright.txt, in Chombo's root directory.
8 */
9 #endif
10 
11 
15 #ifndef _REALFUNCTION_H_
16 #define _REALFUNCTION_H_
17 #include "CH_HDF5.H"
18 #include "NamespaceHeader.H"
19 
20 // virtual base template which defines a Real function
21 template <typename T>
23 {
24 public:
25  virtual ~RealFunction()
26  {;}
27  virtual Real operator()(const T&)=0;
28 };
29 
30 // simple constant
31 template <typename T>
33 {
34  Real m_value;
35 public:
36  ConstantRealFunction(Real a_value) : m_value(a_value)
37  {;}
38  Real operator()(const T&){return m_value;}
39 };
40 
41 // simple compact-support constant
43 {
44  Real m_value;
45  RealVect m_loBound;
46  RealVect m_hiBound;
47 public:
48  CompactSupportConstantRealFunction(Real a_value, RealVect a_loBound, RealVect a_hiBound) : m_value(a_value), m_loBound(a_loBound), m_hiBound(a_hiBound)
49  {;}
50  Real operator()(const RealVect& a_loc)
51  {
52  Real retVal = 0.0;
53  if ((a_loc >= m_loBound) && (a_loc <= m_hiBound))
54  {
55  retVal = m_value;
56  }
57  return retVal;}
58 };
59 
60 
61 // compact-support constant in a circular region
63 {
64  Real m_value;
65  RealVect m_center;
66  Real m_radius;
67 public:
68  CircularSupportConstantRealFunction(Real a_value, RealVect a_center, Real a_radius) : m_value(a_value), m_center(a_center), m_radius(a_radius)
69  {;}
70  Real operator()(const RealVect& a_loc)
71  {
72  Real retVal = 0.0;
73  RealVect relativeLoc = a_loc - m_center;
74  if (relativeLoc.vectorLength() <= m_radius)
75  {
76  retVal = m_value;
77  }
78  return retVal;}
79 };
80 
81 
82 
83 // step: if x < cutoff, leftVal, else rightval
84 class StepRealFunction : public RealFunction<RealVect>
85 {
86  Real m_leftval;
87  Real m_rightval;
88  Real m_cutoff;
89  int m_dir;
90 public:
91  StepRealFunction(Real a_leftval, Real a_rightval, Real a_cutoff, int a_dir) : m_leftval(a_leftval), m_rightval(a_rightval), m_cutoff(a_cutoff), m_dir(a_dir)
92  {;}
93  Real operator()(const RealVect& x){return ( (x[m_dir]<m_cutoff)?m_leftval:m_rightval);}
94 };
95 
96 
97 //linear function of a realVect
98 class LinearRealFunction : public RealFunction<RealVect>
99 {
100  Real m_originValue;
101  RealVect m_gradient;
102 
103 public:
104 
105  Real operator()(const RealVect& x)
106  {
107  return m_originValue + (m_gradient * x).sum();
108  }
109 
110 };
111 
112 
113 class InclinedPlaneFunction : public RealFunction<RealVect>
114 {
115  Real m_origin;
116  RealVect m_slope;
117 public:
118  InclinedPlaneFunction(Real a_origin, const RealVect& a_slope)
119  : m_origin(a_origin),m_slope(a_slope)
120  {;}
121 
122  Real operator()(const RealVect& x)
123  {
124  Real r = m_origin +
125  D_TERM(x[0]*m_slope[0],+x[1]*m_slope[1],+x[2]*m_slope[2]);
126 
127  return r;
128 
129  }
130 };
131 
132 // blinear function with compact support
134 {
135  Real m_origin;
136  RealVect m_slope;
137  RealVect m_loBound;
138  RealVect m_hiBound;
139 public:
140  CompactSupportInclinedPlaneFunction(Real a_origin, const RealVect& a_slope,
141  const RealVect& a_loBound,
142  const RealVect& a_hiBound)
143  : m_origin(a_origin),m_slope(a_slope),m_loBound(a_loBound), m_hiBound(a_hiBound)
144  {;}
145 
146  Real operator()(const RealVect& x)
147  {
148  Real r = 0;
149  if ((x >= m_loBound) && (x <= m_hiBound))
150  {
151  r = m_origin +
152  D_TERM(x[0]*m_slope[0],+x[1]*m_slope[1],+x[2]*m_slope[2]);
153  }
154  return r;
155  }
156 
157 };
158 
160 {
161  Real m_origin;
162  RealVect m_slope;
163  RealVect m_symmetryPoint;
164 public:
165  SymmetricInclinedPlaneFunction(Real a_origin, const RealVect& a_slope,
166  const RealVect& a_symmetryPoint)
167  : m_origin(a_origin),m_slope(a_slope), m_symmetryPoint(a_symmetryPoint)
168  {;}
169 
170  Real operator()(const RealVect& x)
171  {
172  RealVect local_x(x);
173  local_x -= m_symmetryPoint;
174  D_TERM(local_x[0] = abs(local_x[0]);,
175  local_x[1] = abs(local_x[1]);,
176  local_x[2] = abs(local_x[2]);)
177 
178  Real r = m_origin +
179  D_TERM(local_x[0]*m_slope[0],+x[1]*m_slope[1],+x[2]*m_slope[2]);
180 
181  return r;
182 
183  }
184 
185 };
186 
187 
188 class GaussianFunction : public RealFunction<RealVect>
189 {
190  RealVect m_center;
191  RealVect m_radius;
192  Real m_mag;
193  Real m_offset;
194 public:
195  GaussianFunction(RealVect a_center, const RealVect& a_radius, Real a_mag, Real a_offset=0.0)
196  : m_center(a_center),m_radius(a_radius), m_mag(a_mag), m_offset(a_offset)
197  {;}
198 
199  Real operator()(const RealVect& x)
200  {
201  RealVect loc(x);
202  loc -= m_center;
203  loc /= m_radius;
204  Real radSqr = D_TERM(loc[0]*loc[0],+loc[1]*loc[1],+loc[2]*loc[2]);
205 
206  Real r = m_mag*exp(-radSqr) + m_offset;
207 
208  return r;
209 
210  }
211 
212 };
213 
215 class GaussianFunctionX : public RealFunction<RealVect>
216 {
217  Real m_center;
218  Real m_radius;
219  Real m_mag;
220 public:
221  GaussianFunctionX(Real a_center, const Real& a_radius, Real a_mag)
222  : m_center(a_center),m_radius(a_radius), m_mag(a_mag)
223  {;}
224 
225  Real operator()(const RealVect& x)
226  {
227  RealVect loc(x);
228  loc -= m_center;
229  loc /= m_radius;
230  Real radSqr = loc[0]*loc[0];
231 
232  Real r = m_mag*exp(-radSqr);
233 
234  return r;
235 
236  }
237 
238 };
239 
240 
245 
247 {
248 
249  Vector<Real> m_flowlineF;
250  Real m_dx;
251 public:
252 
253  ExtrudedPieceWiseLinearFlowline(std::string a_file, std::string a_set, Real a_dx)
254  :m_dx(a_dx)
255  {
256 #ifdef CH_USE_HDF5
257  herr_t status;
258  hid_t file_access = 0;
259 #ifdef CH_MPI
260  file_access = H5Pcreate (H5P_FILE_ACCESS);
261  H5Pset_fapl_mpio(file_access, Chombo_MPI::comm, MPI_INFO_NULL);
262 #else
263  file_access = H5P_DEFAULT;
264 #endif
265 
266  hid_t file_id = H5Fopen(a_file.c_str(), H5F_ACC_RDONLY, file_access);
267 #ifdef H516
268  hid_t dset_id = H5Dopen(file_id, a_set.c_str());
269 #else
270  hid_t dset_id = H5Dopen2(file_id, a_set.c_str(),
271  H5P_DEFAULT);
272 #endif
273  hid_t space_id = H5Dget_space(dset_id);
274  CH_assert( H5Sis_simple(space_id) > 0);
275  CH_assert( H5Sget_simple_extent_ndims(space_id) == 1);
276  hsize_t n,nmax;
277  status = H5Sget_simple_extent_dims(space_id,&n,&nmax);
278  //CH_assert(status == 0);
279  m_flowlineF.resize(n);
280  status = H5Dread(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT,&m_flowlineF[0]);
281  CH_assert(status == 0);
282 #ifdef CH_MPI
283  MPI_Barrier(Chombo_MPI::comm);
284 #endif
285  status = H5Dclose(dset_id);CH_assert(status == 0);
286  status = H5Sclose(space_id);CH_assert(status == 0);
287  status = H5Fclose(file_id);CH_assert(status == 0);
288 #else
289  MayDay::Error("ExtrudedPieceWiseLinearFlowline(std::string a_file, std::string a_set, Real a_dx) requires CH_USE_HDF5");
290 #endif
291  }
292 
293  Real operator()(const RealVect& a_x)
294  {
295  Real x = abs(a_x[0]);
296  int i = int( x / m_dx);
297 
298  if (i + 1 < m_flowlineF.size())
299  {
300  Real w = (x-(0.5+Real(i))*m_dx)/m_dx;
301  return m_flowlineF[i]*(1.0-w) + m_flowlineF[i+1]*w;
302  }
303  else
304  {
305  return m_flowlineF[m_flowlineF.size()-1];
306  }
307  }
308 
309 
310 };
311 
312 
313 
314 
315 #include "NamespaceFooter.H"
316 #endif
317 
Real operator()(const RealVect &x)
Definition: RealFunction.H:146
Definition: RealFunction.H:98
StepRealFunction(Real a_leftval, Real a_rightval, Real a_cutoff, int a_dir)
Definition: RealFunction.H:91
CompactSupportInclinedPlaneFunction(Real a_origin, const RealVect &a_slope, const RealVect &a_loBound, const RealVect &a_hiBound)
Definition: RealFunction.H:140
CompactSupportConstantRealFunction(Real a_value, RealVect a_loBound, RealVect a_hiBound)
Definition: RealFunction.H:48
GaussianFunctionX(Real a_center, const Real &a_radius, Real a_mag)
Definition: RealFunction.H:221
Real operator()(const RealVect &x)
Definition: RealFunction.H:199
virtual Real operator()(const T &)=0
Definition: RealFunction.H:188
Definition: RealFunction.H:84
Real operator()(const RealVect &a_loc)
Definition: RealFunction.H:70
SymmetricInclinedPlaneFunction(Real a_origin, const RealVect &a_slope, const RealVect &a_symmetryPoint)
Definition: RealFunction.H:165
CircularSupportConstantRealFunction(Real a_value, RealVect a_center, Real a_radius)
Definition: RealFunction.H:68
Real operator()(const RealVect &x)
Definition: RealFunction.H:170
Definition: RealFunction.H:113
Real operator()(const RealVect &a_loc)
Definition: RealFunction.H:50
Definition: RealFunction.H:42
Definition: RealFunction.H:159
Real operator()(const T &)
Definition: RealFunction.H:38
Real operator()(const RealVect &x)
Definition: RealFunction.H:225
Real operator()(const RealVect &x)
Definition: RealFunction.H:122
1D Gaussian hump
Definition: RealFunction.H:215
Definition: RealFunction.H:246
Definition: RealFunction.H:62
virtual ~RealFunction()
Definition: RealFunction.H:25
Definition: RealFunction.H:32
Real operator()(const RealVect &x)
Definition: RealFunction.H:105
GaussianFunction(RealVect a_center, const RealVect &a_radius, Real a_mag, Real a_offset=0.0)
Definition: RealFunction.H:195
Real operator()(const RealVect &a_x)
Definition: RealFunction.H:293
ConstantRealFunction(Real a_value)
Definition: RealFunction.H:36
ExtrudedPieceWiseLinearFlowline(std::string a_file, std::string a_set, Real a_dx)
Definition: RealFunction.H:253
Real operator()(const RealVect &x)
Definition: RealFunction.H:93
Definition: RealFunction.H:133
Definition: RealFunction.H:22
InclinedPlaneFunction(Real a_origin, const RealVect &a_slope)
Definition: RealFunction.H:118