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 protected:
168 
169  /// the VoFs
171  /// the weights
173 
175 };
176 
177 ///
178 /**
179  Face-centered Stencil for embedded boundary applications.
180 */
182 {
183 public:
184  ///
185  FaceStencil();
186 
187  ///
188  virtual ~FaceStencil();
189 
190  ///
191  void clear();
192 
193  ///
194  /**
195  add an Face and it's weight
196  If the face is already in the
197  stencil, add the weights.
198  */
199  void add(const FaceIndex& face,const Real& weight, int variable=0);
200 
201  ///
202  /**
203  shift all entries by a_shift
204  */
205  void shift(const IntVect& a_shift);
206 
207  ///
208  /**
209  number of Faces in the Stencil
210  */
211  virtual int size() const;
212 
213  ///
214  void setAllVariables(int a_var)
215  {
216  if (faces.size() > 0)
217  {
218  variables = Vector<int>(faces.size(), a_var);
219  }
220  }
221 
222  ///
223  /** access an Face
224  */
225  const FaceIndex& face(int i) const;
226 
227  ///
228  /**
229  access a weight
230  */
231  virtual const Real& weight(int i) const;
232 
233  ///
234  virtual BaseIndex& index(int i) const
235  {
236  return (BaseIndex&)(face(i));
237  }
238 
239  ///
240  virtual const int& variable(int i) const;
241 
242  ///
243  virtual int& variable(int i);
244 
245  ///
246  /**
247  add all faces and weights of inputs
248  to this. If a face is already in the
249  stencil, add the weights.
250  only addition is well-defined here
251  as far as arithmatic operations are
252  concerned.
253  */
254  FaceStencil& operator+=(const FaceStencil& a_facesten);
255 
256  ///
257  FaceStencil& operator=(const FaceStencil& a_facesten);
258 
259  ///
260  FaceStencil(const FaceStencil& a_facesten);
261 
262  ///
263  /**
264  */
265  void operator*=(const Real& scaling);
266 
267  void outputToPout() const;
268 private:
269 
270  /// the Faces
272  /// the weights
274  /// the variable numbers
276 
277 };
278 
279 class EBCellFAB;
280 class EBFaceFAB;
281 ///variable argument ignored---now uses the variables that live in the stencil
282 extern Real applyVoFStencil(const VoFStencil& a_vofSten, const EBCellFAB& a_fab, const int& a_comp);
283 
284 ///variable argument ignored---now uses the variables that live in the stencil
285 extern Real applyFaceStencil(const FaceStencil& a_faceSten, const EBFaceFAB& a_fab, const int& a_comp);
286 
287 /** inlines */
288 
289 /**************/
290 inline int
292 {
293  return weights.size();
294 }
295 /**************/
296 /**************/
297 inline const VolIndex&
298 VoFStencil::vof(int i) const
299 {
300  return vofs[i];
301 }
302 /**************/
303 /**************/
304 inline const Real&
305 VoFStencil::weight(int i) const
306 {
307  return weights[i];
308 }
309 
310 inline Real&
312 {
313  return weights[i];
314 }
315 
316 #ifdef CH_EXPLICIT_TEMPLATES
317 //
318 // Extra no-op stuff required for successful explicit template instantiation.
319 //
320 inline int linearSize( const FaceStencil& fs )
321 {
322  CH_assert(0);
323  return -1;
324 }
325 template<> inline
326 void linearIn<FaceStencil>(FaceStencil& a_outputT, const void* const inBuf)
327 {
328  CH_assert(0);
329 }
330 template<> inline
331 void linearOut<FaceStencil>(void* const a_outBuf, const FaceStencil& a_inputT)
332 {
333  CH_assert(0);
334 }
335 
336 
337 inline int linearSize( const VoFStencil& fs )
338 {
339  CH_assert(0);
340  return -1;
341 }
342 template<> inline
343 void linearIn<VoFStencil>(VoFStencil& a_outputT, const void* const inBuf)
344 {
345  CH_assert(0);
346 }
347 template<> inline
348 void linearOut<VoFStencil>(void* const a_outBuf, const VoFStencil& a_inputT)
349 {
350  CH_assert(0);
351 }
352 
353 
354 inline int linearSize( const bool& fs )
355 {
356  CH_assert(0);
357  return -1;
358 }
359 template<> inline
360 void linearIn<bool>(bool& a_outputT, const void* const inBuf)
361 {
362  CH_assert(0);
363 }
364 template<> inline
365 void linearOut<bool>(void* const a_outBuf, const bool& a_inputT)
366 {
367  CH_assert(0);
368 }
369 
370 
371 #endif // CH_EXPLICIT_TEMPLATES
372 
373 
374 #include "NamespaceFooter.H"
375 #endif
Vector< int > variables
the variable numbers
Definition: Stencils.H:275
Definition: Stencils.H:181
void operator*=(const Real &scaling)
#define CH_assert(cond)
Definition: CHArray.H:37
Vector< FaceIndex > faces
the Faces
Definition: Stencils.H:271
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
virtual const int & variable(int i) const
void clear()
Definition: FaceIndex.H:28
virtual BaseIndex & index(int i) const
Definition: Stencils.H:234
void operator*=(const Real &scaling)
virtual const BaseIndex & index(int isten) const =0
virtual int size() const
void shift(const IntVect &a_shift)
void setAllVariables(int a_var)
Definition: Stencils.H:153
virtual const Real & weight(int i) const
Definition: Stencils.H:305
index for other indicies to inherit
Definition: BaseIndex.H:26
const VolIndex & vof(int i) const
Definition: Stencils.H:298
Definition: EBFaceFAB.H:28
virtual const Real & weight(int i) const
void add(const FaceIndex &face, const Real &weight, int variable=0)
void clear()
void outputToPout() const
virtual const int & variable(int i) const
VoFStencil & operator=(const VoFStencil &a_vofsten)
FaceStencil & operator=(const FaceStencil &a_facesten)
VoF-centered stencil.
Definition: Stencils.H:60
void outputToPout() const
void add(const VolIndex &vof, const Real &weight, int ivar=0)
Vector< Real > weights
the weights
Definition: Stencils.H:172
VoFStencil & operator+=(const VoFStencil &a_vofsten)
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 poutFortranRelative(const IntVect &a_startIV, const string &a_prefix, const Real &wgtScaling) const
prints the stencil to 16 digits—all weights are divided by weight scaling (typically h or h^2) ...
void setAllVariables(int a_var)
Definition: Stencils.H:214
Definition: EBCellFAB.H:29
double Real
Definition: REAL.H:33
const FaceIndex & face(int i) const
int linearSize(const T &inputT)
Definition: SPMDI.H:21
virtual ~BaseStencil()
Definition: Stencils.H:35
BaseStencil()
Definition: Stencils.H:30
virtual int size() const
Definition: Stencils.H:291
Definition: Stencils.H:26
Vector< VolIndex > vofs
the VoFs
Definition: Stencils.H:170
FaceStencil & operator+=(const FaceStencil &a_facesten)
Vector< Real > weights
the weights
Definition: Stencils.H:273
virtual ~VoFStencil()
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void getExponentAndMantissa(Real &a_mantissa, int &a_exp, Real a_input) const
size_t size() const
Definition: Vector.H:192
Volume of Fluid Index.
Definition: VolIndex.H:31
virtual BaseIndex & index(int i) const
Definition: Stencils.H:100
virtual ~FaceStencil()
void shift(const IntVect &a_shift)
Vector< int > variables
Definition: Stencils.H:174
virtual const Real & weight(int isten) const =0
virtual const int & variable(int isten) const =0