Overture  Version 25
GenericMappedGridOperators.h
Go to the documentation of this file.
1 /* -*-Mode: c++; -*- */
2 
3 #ifndef GENERIC_MAPPED_GRID_OPERATORS
4 #define GENERIC_MAPPED_GRID_OPERATORS
5 
6 #include "Overture.h"
7 #include "OGFunction.h"
9 #include "BCTypes.h"
10 #include "GridFunctionParameters.h"
11 #include "OvertureTypes.h"
12 
13 // extern BoundaryConditionParameters Overture::defaultBoundaryConditionParameters();
14 
15 
16 //===========================================================================================
17 // This class is the base class for MappedGridOperators
18 //
19 // o To define the derivatives in a different way you should derive from this class
20 // and redefine any functions that you want to. If you provide the virtualConstructor
21 // member function then your derived class can be used by the GridCollectionOperators
22 // and CompositeGridOperators classes which define derivatives for GridCollectionFunction's
23 // and CompositeGridFunction's.
24 //
25 // Who to blame: Bill Henshaw, CIC-19, henshaw@lanl.gov
26 //===========================================================================================
27 
28 class AssignInterpNeighbours; // forward declaration
29 
31 {
32 
33  public:
34 
36  {
39  };
40 
41  enum
42  {
46  spectral=-999 // for order of accuracy
47  };
48 
49 
50  MappedGrid mappedGrid; // operators are defined for this MappedGrid
51 
52  // ********************************************************************
53  // **************** Miscellaneous Functions **************************
54  // ********************************************************************
55 
56  // default constructor
58  // contructor taking a MappedGrid
60  // copy constructor
62  // create a new object of this class
64 
66 
68 
69  // return size of this object
70  virtual real sizeOf(FILE *file = NULL ) const;
71 
72  // supply a new grid to use
73  virtual void updateToMatchGrid( MappedGrid & mg );
74 
75  // get from a database file
76  virtual int get( const GenericDataBase & dir, const aString & name);
77  // put to a database file
78  virtual int put( GenericDataBase & dir, const aString & name) const;
79 
80  // set the order of accuracy
81  virtual void setOrderOfAccuracy( const int & orderOfAccuracy );
82 
83  // get the order of accuracy
84  int getOrderOfAccuracy() const { return orderOfAccuracy; }
85 
88 
89  // set the default width for extrapolation of interpolation neighbours
91 
92  // return true if the grid is rectangular
93  virtual bool isRectangular();
94 
95  // This function is used to evaluate a whole set of derivatives at a time (for efficiency)
96  virtual void getDerivatives(const realMappedGridFunction & u,
97  const Index & I1 = nullIndex,
98  const Index & I2 = nullIndex,
99  const Index & I3 = nullIndex,
100  const Index & I4 = nullIndex,
101  const Index & Evalute = nullIndex ); // evaluate these
102 
103  // Indicate the stencil size for functions returning coefficients
104  virtual void setStencilSize(const int stencilSize);
105 
106  // Indicate the number of components (system size) for functions returning coefficients
107  virtual void setNumberOfComponentsForCoefficients(const int number);
108 
109  // Indicate if twilight-zone forcing should be added to boundary conditions
110  virtual void setTwilightZoneFlow( const int & twilightZoneFlow );
111 
112  // Supply a twilight-zone forcing to use for boundary conditions
114 
115 
116 
117  // ************************************************
118  // ***** DIFFERENTIATION CLASS FUNCTIONS **********
119  // ************************************************
120 
121 
122 // Macro to define a typical function call
123 #define FUNCTION(type) \
124  virtual realMappedGridFunction type(const realMappedGridFunction & u, \
125  const Index & I1 = nullIndex, \
126  const Index & I2 = nullIndex, \
127  const Index & I3 = nullIndex, \
128  const Index & I4 = nullIndex, \
129  const Index & I5 = nullIndex, \
130  const Index & I6 = nullIndex, \
131  const Index & I7 = nullIndex, \
132  const Index & I8 = nullIndex ); \
133  \
134  virtual realMappedGridFunction type(const realMappedGridFunction & u, \
135  const GridFunctionParameters & gfType, \
136  const Index & I1 = nullIndex, \
137  const Index & I2 = nullIndex, \
138  const Index & I3 = nullIndex, \
139  const Index & I4 = nullIndex, \
140  const Index & I5 = nullIndex, \
141  const Index & I6 = nullIndex, \
142  const Index & I7 = nullIndex, \
143  const Index & I8 = nullIndex );
144 
145 
146 #define FUNCTION_COEFFICIENTS(type) \
147  virtual realMappedGridFunction type(const Index & I1 = nullIndex, \
148  const Index & I2 = nullIndex, \
149  const Index & I3 = nullIndex, \
150  const Index & I4 = nullIndex, \
151  const Index & I5 = nullIndex, \
152  const Index & I6 = nullIndex, \
153  const Index & I7 = nullIndex, \
154  const Index & I8 = nullIndex ); \
155  \
156  virtual realMappedGridFunction type(const GridFunctionParameters & gfType, \
157  const Index & I1 = nullIndex, \
158  const Index & I2 = nullIndex, \
159  const Index & I3 = nullIndex, \
160  const Index & I4 = nullIndex, \
161  const Index & I5 = nullIndex, \
162  const Index & I6 = nullIndex, \
163  const Index & I7 = nullIndex, \
164  const Index & I8 = nullIndex );
165 
166  // parametric derivatives in the r1,r2,r3 directions
167  FUNCTION(r1)
168  FUNCTION_COEFFICIENTS(r1Coefficients)
169  FUNCTION(r2)
170  FUNCTION_COEFFICIENTS(r2Coefficients)
171  FUNCTION(r3)
172  FUNCTION_COEFFICIENTS(r3Coefficients)
173  FUNCTION(r1r1)
174  FUNCTION_COEFFICIENTS(r1r1Coefficients)
175  FUNCTION(r1r2)
176  FUNCTION_COEFFICIENTS(r1r2Coefficients)
177  FUNCTION(r1r3)
178  FUNCTION_COEFFICIENTS(r1r3Coefficients)
179  FUNCTION(r2r2)
180  FUNCTION_COEFFICIENTS(r2r2Coefficients)
181  FUNCTION(r2r3)
182  FUNCTION_COEFFICIENTS(r2r3Coefficients)
183  FUNCTION(r3r3)
184  FUNCTION_COEFFICIENTS(r3r3Coefficients)
185 
186  // FUNCTIONs in the x,y,z directions
187  FUNCTION(x)
188  FUNCTION_COEFFICIENTS(xCoefficients)
189  FUNCTION(y)
190  FUNCTION_COEFFICIENTS(yCoefficients)
191  FUNCTION(z)
192  FUNCTION_COEFFICIENTS(zCoefficients)
193  FUNCTION(xx)
194  FUNCTION_COEFFICIENTS(xxCoefficients)
195  FUNCTION(xy)
196  FUNCTION_COEFFICIENTS(xyCoefficients)
197  FUNCTION(xz)
198  FUNCTION_COEFFICIENTS(xzCoefficients)
199  FUNCTION(yy)
200  FUNCTION_COEFFICIENTS(yyCoefficients)
201  FUNCTION(yz)
202  FUNCTION_COEFFICIENTS(yzCoefficients)
203  FUNCTION(zz)
204  FUNCTION_COEFFICIENTS(zzCoefficients)
205 
206  // other forms of derivatives
207 
208  // compute face-centered variable from cell-centered variable
209  FUNCTION(cellsToFaces)
210 
211  //compute (u.grad)u (convective derivative)
213 
214  // compute contravariant velocity from either cell-centered or face-centered input velocity
215  FUNCTION(contravariantVelocity)
216 
217  FUNCTION(div)
218  FUNCTION_COEFFICIENTS(divCoefficients)
219 
220  //returns cell-centered divergence given normal velocities
221  FUNCTION(divNormal)
222 
223  // compute faceArea-weighted normal velocity from either cell-centered or
224  // face-centered input velocity (this is just an alias for contravariantVelocity)
225  FUNCTION(normalVelocity)
226 
227  FUNCTION(grad)
228  FUNCTION_COEFFICIENTS(gradCoefficients)
229 
230  FUNCTION(identity)
231  FUNCTION_COEFFICIENTS(identityCoefficients)
232 
233  FUNCTION(laplacian)
234  FUNCTION_COEFFICIENTS(laplacianCoefficients)
235 
236  FUNCTION(vorticity)
237 
238 #undef FUNCTION
239 #undef FUNCTION_COEFFICIENTS
240  // ******* derivatives in non-standard form ***********
241 
242  //compute (u.grad)w (convective derivative of passive variable(s))
244  const realMappedGridFunction &u,
245  const realMappedGridFunction &w,
246  const Index & I1 = nullIndex,
247  const Index & I2 = nullIndex,
248  const Index & I3 = nullIndex
249  );
251  const realMappedGridFunction &u,
252  const GridFunctionParameters & gfType,
253  const realMappedGridFunction &w,
254  const Index & I1 = nullIndex,
255  const Index & I2 = nullIndex,
256  const Index & I3 = nullIndex
257  );
258 
259 
260 #define SCALAR_FUNCTION(type) \
261  virtual realMappedGridFunction type(const realMappedGridFunction & u, \
262  const realMappedGridFunction & s, \
263  const Index & I1 = nullIndex, \
264  const Index & I2 = nullIndex, \
265  const Index & I3 = nullIndex, \
266  const Index & I4 = nullIndex, \
267  const Index & I5 = nullIndex, \
268  const Index & I6 = nullIndex, \
269  const Index & I7 = nullIndex, \
270  const Index & I8 = nullIndex ); \
271  \
272  virtual realMappedGridFunction type(const realMappedGridFunction & u, \
273  const GridFunctionParameters & gfType, \
274  const realMappedGridFunction & s, \
275  const Index & I1 = nullIndex, \
276  const Index & I2 = nullIndex, \
277  const Index & I3 = nullIndex, \
278  const Index & I4 = nullIndex, \
279  const Index & I5 = nullIndex, \
280  const Index & I6 = nullIndex, \
281  const Index & I7 = nullIndex, \
282  const Index & I8 = nullIndex );
283 
284 #define SCALAR_FUNCTION_COEFFICIENTS(type) \
285  virtual realMappedGridFunction type(const realMappedGridFunction & s, \
286  const Index & I1 = nullIndex, \
287  const Index & I2 = nullIndex, \
288  const Index & I3 = nullIndex, \
289  const Index & I4 = nullIndex, \
290  const Index & I5 = nullIndex, \
291  const Index & I6 = nullIndex, \
292  const Index & I7 = nullIndex, \
293  const Index & I8 = nullIndex ); \
294  \
295  virtual realMappedGridFunction type(const GridFunctionParameters & gfType, \
296  const realMappedGridFunction & s, \
297  const Index & I1 = nullIndex, \
298  const Index & I2 = nullIndex, \
299  const Index & I3 = nullIndex, \
300  const Index & I4 = nullIndex, \
301  const Index & I5 = nullIndex, \
302  const Index & I6 = nullIndex, \
303  const Index & I7 = nullIndex, \
304  const Index & I8 = nullIndex );
305 
306 // div(s grad(u)), s=scalar field
307 SCALAR_FUNCTION(divScalarGrad)
308 SCALAR_FUNCTION_COEFFICIENTS(divScalarGradCoefficients)
309 // div( (1/s) grad(u)), s=scalar field
310 SCALAR_FUNCTION(divInverseScalarGrad)
311 SCALAR_FUNCTION_COEFFICIENTS(divInverseScalarGradCoefficients)
312 // s grad(u)
313 SCALAR_FUNCTION(scalarGrad)
314 SCALAR_FUNCTION_COEFFICIENTS(scalarGradCoefficients)
315 
316 // div( sv u )
317 SCALAR_FUNCTION(divVectorScalar)
318 SCALAR_FUNCTION_COEFFICIENTS(divVectorScalarCoefficients)
319 
320 #undef SCALAR_FUNCTION
321 #undef SCALAR_FUNCTION_COEFFICIENTS
322 
324  const realMappedGridFunction & s,
325  const int & direction1,
326  const int & direction2,
327  const Index & I1 = nullIndex,
328  const Index & I2 = nullIndex,
329  const Index & I3 = nullIndex,
330  const Index & I4 = nullIndex,
331  const Index & I5 = nullIndex,
332  const Index & I6 = nullIndex,
333  const Index & I7 = nullIndex,
334  const Index & I8 = nullIndex );
335 
337  const GridFunctionParameters & gfType,
338  const realMappedGridFunction & s,
339  const int & direction1,
340  const int & direction2,
341  const Index & I1 = nullIndex,
342  const Index & I2 = nullIndex,
343  const Index & I3 = nullIndex,
344  const Index & I4 = nullIndex,
345  const Index & I5 = nullIndex,
346  const Index & I6 = nullIndex,
347  const Index & I7 = nullIndex,
348  const Index & I8 = nullIndex );
349 
351  const int & direction1,
352  const int & direction2,
353  const Index & I1 = nullIndex,
354  const Index & I2 = nullIndex,
355  const Index & I3 = nullIndex,
356  const Index & I4 = nullIndex,
357  const Index & I5 = nullIndex,
358  const Index & I6 = nullIndex,
359  const Index & I7 = nullIndex,
360  const Index & I8 = nullIndex );
361 
363  const realMappedGridFunction & s,
364  const int & direction1,
365  const int & direction2,
366  const Index & I1 = nullIndex,
367  const Index & I2 = nullIndex,
368  const Index & I3 = nullIndex,
369  const Index & I4 = nullIndex,
370  const Index & I5 = nullIndex,
371  const Index & I6 = nullIndex,
372  const Index & I7 = nullIndex,
373  const Index & I8 = nullIndex );
374 
375 
376  //returns face-centered gradients
378  const int c0 = 0,
379  const int c1 = 0,
380  const int c2 = 0,
381  const int c3 = 0,
382  const int c4 = 0,
383  const Index & I1 = nullIndex,
384  const Index & I2 = nullIndex,
385  const Index & I3 = nullIndex,
386  const Index & I4 = nullIndex,
387  const Index & I5 = nullIndex,
388  const Index & I6 = nullIndex,
389  const Index & I7 = nullIndex,
390  const Index & I8 = nullIndex
391  );
392 
394  const GridFunctionParameters & gfType,
395  const int c0 = 0,
396  const int c1 = 0,
397  const int c2 = 0,
398  const int c3 = 0,
399  const int c4 = 0,
400  const Index & I1 = nullIndex,
401  const Index & I2 = nullIndex,
402  const Index & I3 = nullIndex,
403  const Index & I4 = nullIndex,
404  const Index & I5 = nullIndex,
405  const Index & I6 = nullIndex,
406  const Index & I7 = nullIndex,
407  const Index & I8 = nullIndex
408  );
409 
410 
411  // scalar times identityCoefficients
413  const realMappedGridFunction & s,
414  const Index & I1 = nullIndex,
415  const Index & I2 = nullIndex,
416  const Index & I3 = nullIndex,
417  const Index & I4 = nullIndex,
418  const Index & I5 = nullIndex,
419  const Index & I6 = nullIndex,
420  const Index & I7 = nullIndex,
421  const Index & I8 = nullIndex
422  );
423 
424 
425  void setInterpolationPoint( intArray & interpolationPoint ); // used by GenericCompositeGridOperators
426 
427  // ********************************************************************
428  // ------------- Here we define the Boundary Conditions ---------------
429  // ********************************************************************
430 
431  public:
432 
433  enum boundaryConditionTypes // get rid of this eventually **** Must match BCTypes ****
434  {
469  numberOfDifferentBoundaryConditionTypes // counts number of entries in this list
470  };
471 
472  virtual void applyBoundaryConditions(realMappedGridFunction & u, const real & time = 0.);
473  // fill in coefficients for the boundary conditions
474  virtual void assignBoundaryConditionCoefficients(realMappedGridFunction & coeff, const real & time = 0.);
475 
476  // +++++++++++++++++++ new BC interface: ++++++++++++++++++++++++++++++++++++
478  const Index & Components,
479  const BCTypes::BCNames & boundaryConditionType
481  const int & boundaryCondition = allBoundaries,
482  const real & forcing = 0.,
483  const real & time = 0.,
484  const BoundaryConditionParameters & bcParameters
486  const int & grid=0 );
487 
488 
490  const Index & Components,
491  const BCTypes::BCNames & boundaryConditionType,
492  const int & boundaryCondition,
493  const RealArray & forcing,
494  const real & time = 0.,
495  const BoundaryConditionParameters & bcParameters
497  const int & grid=0 );
498 
499 
501  const Index & Components,
502  const BCTypes::BCNames & boundaryConditionType,
503  const int & boundaryCondition,
504  const RealArray & forcing,
505  RealArray *forcinga[2][3],
506  const real & time = 0.,
507  const BoundaryConditionParameters & bcParameters
509  const int & grid=0 );
510 
511 
513  const Index & Components,
514  const BCTypes::BCNames & boundaryConditionType,
515  const int & boundaryCondition,
516  const realMappedGridFunction & forcing,
517  const real & time = 0.,
518  const BoundaryConditionParameters & bcParameters
520  const int & grid=0 );
521 
522 #ifdef USE_PPP
523 // // this version takes a distributed array "forcing"
524 // void applyBoundaryCondition(realMappedGridFunction & u,
525 // const Index & Components,
526 // const BCTypes::BCNames & boundaryConditionType,
527 // const int & boundaryCondition,
528 // const RealDistributedArray & forcing,
529 // const real & time = 0.,
530 // const BoundaryConditionParameters & bcParameters
531 // = Overture::defaultBoundaryConditionParameters(),
532 // const int & grid=0 );
533 #endif
534 
535  // fix corners and periodic update:
536  virtual void finishBoundaryConditions
539  const Range & C0=nullRange);
540 
541  virtual void finishBoundaryConditionsOld
544  const Range & C0=nullRange);
545 
546  // the next routine is normally only called by finishBoundaryConditions
547  virtual void fixBoundaryCorners
550  const Range & C0=nullRange);
551 
552  // fill in the BC's for a coefficient grid function
553  virtual void
555  realMappedGridFunction & coeff,
556  const Index & Equations,
557  const Index & Components,
558  const BCTypes::BCNames & boundaryConditionType=BCTypes::dirichlet,
559  const int & boundaryCondition= allBoundaries,
560  const BoundaryConditionParameters & bcParameters
562  const int & grid=0 );
563 
564 
565  virtual void useConservativeApproximations(bool trueOrFalse = TRUE );
566  bool usingConservativeApproximations() const;
567 
568  void setAveragingType(const AveragingType & type );
570 
571  realArray harmonic(const realArray & a, const realArray & b ); // harmonic average
572 
573  // here are some parameters -- these are public for now ?? ------
575  int stencilSize; //
576  int numberOfComponentsForCoefficients; // for dimensioning coefficient matrices
577  int twilightZoneFlow; // 0, 1 or 2.
579 
580  // These next functions are called by finishBoundaryConditions
581 
582  virtual void setCornerCoefficients(realMappedGridFunction & coeff,
583  const int n,
584  const Index & I1,
585  const Index & I2,
586  const Index & I3,
587  int side1,
588  int side2,
589  int side3,
590  const BoundaryConditionParameters & bcParameters );
591 
593  const int n,
594  const Index & I1,
595  const Index & I2,
596  const Index & I3,
597  const int order);
598 
599  virtual void setSymmetryCoefficients(realMappedGridFunction & coeff,
600  const int n,
601  const Index & I1,
602  const Index & I2,
603  const Index & I3,
604  const int option = 0);
605 
606  virtual void setPeriodicCoefficients(realMappedGridFunction & coeff );
607 
608  protected:
609 
610 // *wdh* 091123 -- Here is the old way: ------------------------------------------------------
611  // routine for setting up arrays for extrapolating neighbours to interpolation points
612  virtual void findInterpolationNeighbours();
619 // *wdh* 091123 -- Here is the new way: ------------------------------------------------------
621 
623 
625 
627 
628 public:
629 
630  // This next enum is used for setting an error status
632  {
635  } errorStatus;
636 
637 
638 public:
639 
641 
659 
662 static void printBoundaryConditionStatistics(FILE *file=stdout);
663 
664 };
665 
666 
667 
668 
669 
670 
671 #endif