Chombo + EB + MF  3.2
Stencils.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 #ifndef _STENCILS_H_
12 #define _STENCILS_H_
13 
14 #include "Vector.H"
15 #include "VolIndex.H"
16 #include "BaseIndex.H"
17 #include "FaceIndex.H"
18 #include "REAL.H"
19 #include "NamespaceHeader.H"
20 using std::string;
21 ///
22 /**
23  class for vofstencil and basestencil to inherit from
24  so AggStencil can unify them.
25 */
27 {
28 public:
29  ///
31  {
32  }
33 
34  ///
35  virtual ~BaseStencil()
36  {
37  }
38 
39  ///
40  virtual int size() const = 0;
41 
42  ///
43  virtual const BaseIndex& index(int isten) const = 0;
44 
45 
46  ///
47  virtual const Real& weight(int isten) const = 0;
48 
49  ///
50  virtual const int& variable(int isten) const = 0;
51 };
52 
53 /// VoF-centered stencil
54 /**
55  This stencil is a fundamental tool for building
56  eb applications by making the ability to cache
57  stencil information. This object consists of
58  a vector of VoFs and a vector of weights.
59 */
60 class VoFStencil: public BaseStencil
61 {
62 public:
63  ///
64  /**
65  default constructor. makes empty vectors.
66  */
67  VoFStencil();
68 
69  ///
70  virtual ~VoFStencil();
71 
72  ///
73  void clear();
74 
75  ///
76  /**
77  add a VoF to the Stencil, with it's associated weight
78  it is required that all VoFs are in the same EBIndexSpace
79  If the vof is already in the
80  stencil, add the weights.
81  */
82  void
83  add(const VolIndex& vof,const Real& weight, int ivar = 0);
84 
85  ///
86  /**
87  number of VoFs in the Stencil
88  */
89  virtual int size() const;
90 
91  ///
92  /**
93  access a VoF
94  */
95  const VolIndex& vof(int i) const;
96 
97 
98 
99  ///
100  virtual BaseIndex& index(int i) const
101  {
102  return (BaseIndex&)(vof(i));
103  }
104 
105  ///
106  /**
107  access a weight
108  */
109  virtual const Real& weight(int i) const;
110 
111  ///
112  /**
113  access a weight
114  */
115  virtual Real& weight(int i);
116 
117  ///
118  /**
119  shift all entries by a_shift
120  */
121  void shift(const IntVect& a_shift);
122 
123  ///
124  virtual const int& variable(int i) const;
125 
126  ///
127  virtual int& variable(int i);
128 
129  ///
130  /**
131  add all faces and weights of inputs
132  to this. If a vof is already in the
133  stencil, add the weights.
134  only addition is well-defined here
135  as far as arithmatic operations are
136  concerned.
137  */
138  VoFStencil&
139  operator+=(const VoFStencil& a_vofsten);
140 
141  ///
142  /**
143  */
144  void operator*=(const Real& scaling);
145 
146  ///
147  VoFStencil&
148  operator=(const VoFStencil& a_vofsten);
149 
150  ///
151  VoFStencil(const VoFStencil& a_vofstenin);
152 
153  void setAllVariables(int a_var)
154  {
155  if (vofs.size() > 0)
156  {
157  variables = Vector<int>(vofs.size(), a_var);
158  }
159  }
160 
161  void getExponentAndMantissa(Real& a_mantissa, int& a_exp, Real a_input) const;
162 
163  /// prints the stencil to 16 digits---all weights are divided by weight scaling (typically h or h^2)
164  void poutFortranRelative(const IntVect& a_startIV, const string& a_prefix, const Real& wgtScaling) const;
165 
166  void outputToPout() const;
167 
168  friend std::ostream& operator<<(std::ostream& os, const VoFStencil& a_sten )
169  {
170  int n = a_sten.size();
171  os << "[";
172  for( int i=0; i<n; i++ ) {
173  if( i ) os << " ";
174  os << a_sten.vofs[i] << ":" << a_sten.weights[i] << "," << a_sten.variables[i];
175  }
176  os << "]";
177  return os;
178  }
179 
180 protected:
181 
182  /// the VoFs
184  /// the weights
186 
188 };
189 
190 ///
191 /**
192  Face-centered Stencil for embedded boundary applications.
193 */
195 {
196 public:
197  ///
198  FaceStencil();
199 
200  ///
201  virtual ~FaceStencil();
202 
203  ///
204  void clear();
205 
206  ///
207  /**
208  add an Face and it's weight
209  If the face is already in the
210  stencil, add the weights.
211  */
212  void add(const FaceIndex& face,const Real& weight, int variable=0);
213 
214  ///
215  /**
216  shift all entries by a_shift
217  */
218  void shift(const IntVect& a_shift);
219 
220  ///
221  /**
222  number of Faces in the Stencil
223  */
224  virtual int size() const;
225 
226  ///
227  void setAllVariables(int a_var)
228  {
229  if (faces.size() > 0)
230  {
231  variables = Vector<int>(faces.size(), a_var);
232  }
233  }
234 
235  ///
236  /** access an Face
237  */
238  const FaceIndex& face(int i) const;
239 
240  ///
241  /**
242  access a weight
243  */
244  virtual const Real& weight(int i) const;
245 
246  ///
247  virtual BaseIndex& index(int i) const
248  {
249  return (BaseIndex&)(face(i));
250  }
251 
252  ///
253  virtual const int& variable(int i) const;
254 
255  ///
256  virtual int& variable(int i);
257 
258  ///
259  /**
260  add all faces and weights of inputs
261  to this. If a face is already in the
262  stencil, add the weights.
263  only addition is well-defined here
264  as far as arithmatic operations are
265  concerned.
266  */
267  FaceStencil& operator+=(const FaceStencil& a_facesten);
268 
269  ///
270  FaceStencil& operator=(const FaceStencil& a_facesten);
271 
272  ///
273  FaceStencil(const FaceStencil& a_facesten);
274 
275  ///
276  /**
277  */
278  void operator*=(const Real& scaling);
279 
280  void outputToPout() const;
281 private:
282 
283  /// the Faces
285  /// the weights
287  /// the variable numbers
289 
290 };
291 
292 class EBCellFAB;
293 class EBFaceFAB;
294 ///variable argument ignored---now uses the variables that live in the stencil
295 extern Real applyVoFStencil(const VoFStencil& a_vofSten, const EBCellFAB& a_fab, const int& a_comp);
296 
297 ///variable argument ignored---now uses the variables that live in the stencil
298 extern Real applyFaceStencil(const FaceStencil& a_faceSten, const EBFaceFAB& a_fab, const int& a_comp);
299 
300 /** inlines */
301 
302 /**************/
303 inline int
305 {
306  return weights.size();
307 }
308 /**************/
309 /**************/
310 inline const VolIndex&
311 VoFStencil::vof(int i) const
312 {
313  return vofs[i];
314 }
315 /**************/
316 /**************/
317 inline const Real&
318 VoFStencil::weight(int i) const
319 {
320  return weights[i];
321 }
322 
323 inline Real&
325 {
326  return weights[i];
327 }
328 
329 #ifdef CH_EXPLICIT_TEMPLATES
330 //
331 // Extra no-op stuff required for successful explicit template instantiation.
332 //
333 inline int linearSize( const FaceStencil& fs )
334 {
335  CH_assert(0);
336  return -1;
337 }
338 template<> inline
339 void linearIn<FaceStencil>(FaceStencil& a_outputT, const void* const inBuf)
340 {
341  CH_assert(0);
342 }
343 template<> inline
344 void linearOut<FaceStencil>(void* const a_outBuf, const FaceStencil& a_inputT)
345 {
346  CH_assert(0);
347 }
348 
349 
350 inline int linearSize( const VoFStencil& fs )
351 {
352  CH_assert(0);
353  return -1;
354 }
355 template<> inline
356 void linearIn<VoFStencil>(VoFStencil& a_outputT, const void* const inBuf)
357 {
358  CH_assert(0);
359 }
360 template<> inline
361 void linearOut<VoFStencil>(void* const a_outBuf, const VoFStencil& a_inputT)
362 {
363  CH_assert(0);
364 }
365 
366 
367 inline int linearSize( const bool& fs )
368 {
369  CH_assert(0);
370  return -1;
371 }
372 template<> inline
373 void linearIn<bool>(bool& a_outputT, const void* const inBuf)
374 {
375  CH_assert(0);
376 }
377 template<> inline
378 void linearOut<bool>(void* const a_outBuf, const bool& a_inputT)
379 {
380  CH_assert(0);
381 }
382 
383 
384 #endif // CH_EXPLICIT_TEMPLATES
385 
386 
387 #include "NamespaceFooter.H"
388 #endif
Vector< int > variables
the variable numbers
Definition: Stencils.H:288
Definition: Stencils.H:194
#define CH_assert(cond)
Definition: CHArray.H:37
Vector< FaceIndex > faces
the Faces
Definition: Stencils.H:284
virtual int size() const =0
Real applyFaceStencil(const FaceStencil &a_faceSten, const EBFaceFAB &a_fab, const int &a_comp)
variable argument ignored—now uses the variables that live in the stencil
Definition: FaceIndex.H:28
virtual const BaseIndex & index(int isten) const =0
void setAllVariables(int a_var)
Definition: Stencils.H:153
index for other indicies to inherit
Definition: BaseIndex.H:26
Definition: EBFaceFAB.H:28
VoF-centered stencil.
Definition: Stencils.H:60
Vector< Real > weights
the weights
Definition: Stencils.H:185
Real applyVoFStencil(const VoFStencil &a_vofSten, const EBCellFAB &a_fab, const int &a_comp)
variable argument ignored—now uses the variables that live in the stencil
void setAllVariables(int a_var)
Definition: Stencils.H:227
Definition: EBCellFAB.H:29
double Real
Definition: REAL.H:33
friend std::ostream & operator<<(std::ostream &os, const VoFStencil &a_sten)
Definition: Stencils.H:168
int linearSize(const T &inputT)
Definition: SPMDI.H:21
virtual ~BaseStencil()
Definition: Stencils.H:35
BaseStencil()
Definition: Stencils.H:30
Definition: Stencils.H:26
Vector< VolIndex > vofs
the VoFs
Definition: Stencils.H:183
virtual int size() const
Definition: Stencils.H:304
Vector< Real > weights
the weights
Definition: Stencils.H:286
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Volume of Fluid Index.
Definition: VolIndex.H:31
virtual const Real & weight(int i) const
Definition: Stencils.H:318
const VolIndex & vof(int i) const
Definition: Stencils.H:311
virtual BaseIndex & index(int i) const
Definition: Stencils.H:100
Vector< int > variables
Definition: Stencils.H:187
virtual const Real & weight(int isten) const =0
virtual const int & variable(int isten) const =0
virtual BaseIndex & index(int i) const
Definition: Stencils.H:247