Overture  Version 25
intMappedGridFunction.h
Go to the documentation of this file.
1 /* -*-Mode: c++; -*- */
2 
3 #ifndef INT_MAPPED_GRID_FUNCTION_H
4 #define INT_MAPPED_GRID_FUNCTION_H "intMappedGridFunction.h"
5 //========================================================================================================
6 // This file defines the header file for the mappedGridFunction Class
7 //
8 // The perl script gf.p is used to convert this file into the files
9 // <type>intMappedGridFunction.C where <type> is one of float, int or int
10 //
11 // Notes:
12 // o a intMappedGridFunction is derived from an A++ array
13 // o a intMappedGridFunction contains a pointer to a MappedGrid
14 //
15 // Who to blame: Bill Henshaw, CIC-3, henshaw@lanl.gov
16 // Date of last change: 95/04/09
17 //
18 //========================================================================================================
19 
20 #include <limits.h>
21 #include "aString.H" // Livermore aString Library
22 #include "intGenericGridFunction.h"
23 #include "mathutil.h"
24 #include "OGgetIndex.h" // functions for Index objects
26 #include "BCTypes.h"
27 #include "GridFunctionParameters.h"
28 
29 // *** for new A++ ***
30 typedef Internal_Index IndexArg;
31 
32 class MappedGrid; // forward declaration
33 class MappedGridData; // forward declaration
34 class SparseRepForMGF; // forward declaration
35 
36 class GenericMappedGridOperators; // forward declaration, class that defines derivtaives and BC's
37 class GenericDataBase;
39 
40 // extern BoundaryConditionParameters Overture::defaultBoundaryConditionParameters();
41 #include "OvertureInit.h"
42 
43 
44 //----------------------------------------------------------------------------
45 // This reference counted data class has to be moved here because of a
46 // compiler bug that causes the constructor to call the A++ new operator
47 //----------------------------------------------------------------------------
49 {
50  friend class intMappedGridFunction;
53 
54  int numberOfComponents; // number of components (ie. vector, matrix, ...)
55  // IntegerArray positionOfComponent; // positions of the components
56  // IntegerArray positionOfCoordinate; // positions of the coordinate directions
57 
59  int faceCentering;
60 
61  int numberOfDimensions; // equals value found in grid, this is here for convenience
62 
63  int isACoefficientMatrix; // true if this grid function is a coefficient array
64  int stencilType; // type of stencil
65  // IntegerArray stencilOffset; // (0:2,0:numberOfStencilCoefficinets-1) offsets for Indexing
66  int stencilWidth;
67  int updateToMatchGridOption;
68 
69  aString *name; // pointer to an array of names for the grid function and components
70  int numberOfNames; // length of the name array
71  enum
72  {
73  maximumNumberOfIndicies=8, // we support up to this many Indicies for a grid function
74  numberOfIndicies=4 // A++ supports this many Indicies
75  };
76  Range R[maximumNumberOfIndicies+1]; // here we store the Range for each indicee,
77  // keep one extra for convenience in some computations
78  Range Ra[numberOfIndicies]; // here we store the actual Ranges for the A++ array
79  Range Rc[3]; // Range object that saves special information about the
80  // coordinate positions for grid functions that live on boundaries.
81 
82  int positionOfComponent[maximumNumberOfIndicies]; // positions of the components
83  int positionOfCoordinate[maximumNumberOfIndicies]; // positions of the coordinate directions
84 
85  intMappedGridFunctionRCData & operator=( const intMappedGridFunctionRCData & rcData ); // deep copy
86 
87 private:
88 
89  // These are used by list's of ReferenceCounting objects
90  virtual void reference( const ReferenceCounting & mgf )
91  { intMappedGridFunctionRCData::reference( (intMappedGridFunctionRCData&) mgf ); }
92  virtual ReferenceCounting & operator=( const ReferenceCounting & mgf )
93  { return intMappedGridFunctionRCData::operator=( (intMappedGridFunctionRCData&) mgf ); }
94  virtual ReferenceCounting* virtualConstructor( const CopyType ) const
95  { return ::new intMappedGridFunctionRCData(); }
96 };
97 
98 //===================================================================
99 // intMappedGridFunction
100 //
101 // Define a grid function to be used with a mapped grid.
102 // This class is derived from an A++ array so all A++ operations
103 // are defined.
104 //
105 // This is a reference counted class so that there is no need
106 // to keep a pointer to a grid function. Use the reference
107 // member function to make one grid function reference another.
108 //
109 // Usage:
110 // MappedGrid cg(...); // here is a mapped grid
111 // intMappedGridFunction u(cg),v;
112 // u=5.;
113 // Index I(0,10);
114 // u(I,I)=3.;
115 // v.reference(u); // v is referenced to u
116 // v=7.; // changes u as well
117 // v.breakReference(); // v is no longer referenced to u
118 // ...
119 //
120 //==================================================================
122 {
123  public:
124 
125  enum
126  {
127  maximumNumberOfIndicies=intMappedGridFunctionRCData::maximumNumberOfIndicies, // we support this many Indicies
128  numberOfIndicies=intMappedGridFunctionRCData::numberOfIndicies, // A++ supports this many Indicies
132  forAll=-997
133  };
134 
135  enum edgeGridFunctionValues // these enums are used to declare grid functions defined on faces or edges
136  {
137  startingGridIndex =-(INT_MAX/2), // choose a big negative number assuming that
138  biggerNegativeNumber=startingGridIndex/2, // no grid will ever have dimensions in this range
141  };
142 
143  enum stencilTypes // if the grid function holds a coefficient matrix
144  { // these are the types of stencil that it may contain
145  standardStencil, // 3x3 int 2D or 3x3x3 in 3D (if 2nd order accuracy)
146  starStencil, // 5 point star in 2D or 7pt star in 3D (if 2nd order accuracy)
148  };
149 
150  enum updateReturnValue // the return value from updateToMatchGrid is a mask of the following values
151  {
152  updateNoChange = 0, // no changes made
153  updateReshaped = 1, // grid function was reshaped
154  updateResized = 2, // grid function was resized
155  updateComponentsChanged = 4 // component dimensions may have changed (but grid was not resized or reshaped)
156  };
157 
158 
160  {
163  };
164 
165  // IntegerArray positionOfComponent; // positions of the component Index's
166  // IntegerArray positionOfCoordinate; // positions of the coordinate Index's
167 
170  GenericMappedGridOperators *operators; // pointer to operators (cannot be const)
171  SparseRepForMGF *sparse; // pointer to info on sparse representation for coefficients
172  IntegerArray isCellCentered; // grid function may have different values from the grid
173 
174  public:
175  // IntegerArray stencilOffset; // (0:2,0:numberOfStencilCoefficinets-1) offsets for Indexing
176 
177  //-----------------------------------------------------------------------------
178  //-----------------------Constructors------------------------------------------
179  //-----------------------------------------------------------------------------
180 
183 
184  intMappedGridFunction(const intMappedGridFunction & cgf, const CopyType copyType = DEEP );
185 
187 
188  // This constructor takes ranges, the first 3 "nullRange" values are taken to be the
189  // coordinate directions in the grid function.
191  const Range & R0,
192  const Range & R1=nullRange,
193  const Range & R2=nullRange,
194  const Range & R3=nullRange,
195  const Range & R4=nullRange,
196  const Range & R5=nullRange,
197  const Range & R6=nullRange,
198  const Range & R7=nullRange );
199 
201  const Range & R0,
202  const Range & R1=nullRange,
203  const Range & R2=nullRange,
204  const Range & R3=nullRange,
205  const Range & R4=nullRange,
206  const Range & R5=nullRange,
207  const Range & R6=nullRange,
208  const Range & R7=nullRange );
209 
211  const int & i0,
212  const Range & R1=nullRange,
213  const Range & R2=nullRange,
214  const Range & R3=nullRange,
215  const Range & R4=nullRange,
216  const Range & R5=nullRange,
217  const Range & R6=nullRange,
218  const Range & R7=nullRange );
219 
221  const int & i0,
222  const Range & R1=nullRange,
223  const Range & R2=nullRange,
224  const Range & R3=nullRange,
225  const Range & R4=nullRange,
226  const Range & R5=nullRange,
227  const Range & R6=nullRange,
228  const Range & R7=nullRange );
229 
230  //
231  // This constructor takes a GridFunctionType
232  //
235  const Range & component0=nullRange, // defaults to Range(0,0)
236  const Range & component1=nullRange,
237  const Range & component2=nullRange,
238  const Range & component3=nullRange,
239  const Range & component4=nullRange );
240 
242  const Range & component0=nullRange, // defaults to Range(0,0)
243  const Range & component1=nullRange,
244  const Range & component2=nullRange,
245  const Range & component3=nullRange,
246  const Range & component4=nullRange );
247 
248 
250 
252  intMappedGridFunction & operator=( const int x );
254 
255  // ==========Define all of the instances of the operator()=====================
256 
257  // ------ first define all the scalar index operators-----------
258  // these return by reference so the can be used as an lvalue
259  int & operator()(const int & i0 ) const
260  { return intDistributedArray::operator()(i0); }
261  int & operator()(const int & i0, const int & i1 ) const
262  { return intDistributedArray::operator()(i0,i1); }
263  int & operator()(const int & i0, const int & i1, const int i2 ) const
264  { return intDistributedArray::operator()(i0,i1,i2); }
265  int & operator()(const int & i0, const int & i1, const int & i2, const int & i3 ) const
266  { return intDistributedArray::operator()(i0,i1,i2,i3); }
267  int & operator()(const int & i0, const int & i1, const int & i2, const int & i3, const int & i4) const
268  { return intDistributedArray::operator()(i0,i1,i2,i3+rcData->R[3].length()*(i4-rcData->R[4].getBase())); }
269  int & operator()(const int & i0, const int & i1, const int & i2, const int & i3, const int & i4,
270  const int & i5) const
271  { return intDistributedArray::operator()(i0,i1,i2,i3+rcData->R[3].length()*(
272  i4-rcData->R[4].getBase()+rcData->R[4].length()*(
273  i5-rcData->R[5].getBase())));}
274  int & operator()(const int & i0, const int & i1, const int & i2, const int & i3, const int & i4,
275  const int & i5, const int & i6) const
276  { return intDistributedArray::operator()(i0,i1,i2,i3+rcData->R[3].length()*(
277  i4-rcData->R[4].getBase()+rcData->R[4].length()*(
278  +i5-rcData->R[5].getBase()+rcData->R[5].length()*(
279  i6-rcData->R[6].getBase()))));}
280  int & operator()(const int & i0, const int & i1, const int & i2, const int & i3, const int & i4,
281  const int & i5, const int & i6, const int & i7) const
282  { return intDistributedArray::operator()(i0,i1,i2,i3+rcData->R[3].length()*(
283  i4-rcData->R[4].getBase()+rcData->R[4].length()*(
284  +i5-rcData->R[5].getBase()+rcData->R[5].length()*(
285  +i6-rcData->R[6].getBase()+rcData->R[6].length()*(
286  i7-rcData->R[7].getBase())))));}
287 
288  // -------- One Argument functions -------------
290  { return intDistributedArray::operator()(I0); }
291 
292  // -------- Two Argument functions -------------
293  intDistributedArray operator()(const IndexArg & I0, const IndexArg & I1 ) const
294  { return intDistributedArray::operator()(I0,I1); }
295 
296  // -------- Three Argument functions -------------
297  intDistributedArray operator()(const IndexArg & I0, const IndexArg & I1, const IndexArg & I2 ) const
298  { return intDistributedArray::operator()(I0,I1,I2); }
299 
300  // -------- Four Argument functions -------------
302  const IndexArg & I1,
303  const IndexArg & I2,
304  const IndexArg & I3 ) const
305  { return intDistributedArray::operator()(I0,I1,I2,I3); }
306 
307  // -------- Five Argument functions -------------
308  intDistributedArray operator()(const IndexArg & I0, // define this for efficiency
309  const IndexArg & I1,
310  const IndexArg & I2,
311  const IndexArg & I3,
312  const int & i4 ) const
313  { return (*this)(I0,I1,I2,I3+rcData->R[3].length()*(i4-rcData->R[4].getBase())); }
314 
316  const IndexArg & I1,
317  const IndexArg & I2,
318  const IndexArg & I3,
319  const IndexArg & I4 ) const;
320 
321  // -------- Six Argument functions -------------
322  intDistributedArray operator()(const IndexArg & I0, // define this for efficiency
323  const IndexArg & I1,
324  const IndexArg & I2,
325  const IndexArg & I3,
326  const int & i4,
327  const int & i5 ) const
328  { return (*this)(I0,I1,I2,I3+rcData->R[3].length()*(i4-rcData->R[4].getBase()
329  +rcData->R[4].length()*(i5-rcData->R[5].getBase()))); }
330 
332  const IndexArg & I1,
333  const IndexArg & I2,
334  const IndexArg & I3,
335  const IndexArg & I4,
336  const IndexArg & I5 ) const;
337 
338  // -------- Seven Argument functions -------------
339  intDistributedArray operator()(const IndexArg & I0, // define this for efficiency
340  const IndexArg & I1,
341  const IndexArg & I2,
342  const IndexArg & I3,
343  const int & i4,
344  const int & i5,
345  const int & i6 ) const
346  { return (*this)(I0,I1,I2,I3+rcData->R[3].length()*(i4-rcData->R[4].getBase()
347  +rcData->R[4].length()*(i5-rcData->R[5].getBase()
348  +rcData->R[5].length()*(i6-rcData->R[6].getBase())))); }
349 
351  const IndexArg & I1,
352  const IndexArg & I2,
353  const IndexArg & I3,
354  const IndexArg & I4,
355  const IndexArg & I5,
356  const IndexArg & I6 ) const;
357 
358  // -------- Eight Argument functions -------------
359  intDistributedArray operator()(const IndexArg & I0, // define this for efficiency
360  const IndexArg & I1,
361  const IndexArg & I2,
362  const IndexArg & I3,
363  const int & i4,
364  const int & i5,
365  const int & i6,
366  const int & i7 ) const
367  { return (*this)(I0,I1,I2,I3+rcData->R[3].length()*(i4-rcData->R[4].getBase()
368  +rcData->R[4].length()*(i5-rcData->R[5].getBase()
369  +rcData->R[5].length()*(i6-rcData->R[6].getBase()
370  +rcData->R[6].length()*(i7-rcData->R[7].getBase()))))); }
371 
373  const IndexArg & I1,
374  const IndexArg & I2,
375  const IndexArg & I3,
376  const IndexArg & I4,
377  const IndexArg & I5,
378  const IndexArg & I6,
379  const IndexArg & I7 ) const;
380 
381  // Use this function when you have too many arguments to a grid function:
382  // u(i0,i1,i2,i3,i4,i5,i6,i7) -> u(i0,i1,i2,u.arg3(i3,i4,i5,i6,i7))
383  int arg3(int i3,
384  int i4,
385  int i5=defaultValue,
386  int i6=defaultValue,
387  int i7=defaultValue) const;
388 
389 
390  // The sa, "standard argument" function permutes the arguments to that you can always
391  // refer to a function as u(coordinate(0),coordinate(1),corrdinate(2),component(0),component(1),...)
392  int & sa(const int & i0, const int & i1, const int & i2,
393  const int & c0=0, const int & c1=0, const int & c2=0, const int & c3=0, const int & c4=0) const;
394 
395 
396  // positions of the component Index's
397  inline int positionOfComponent(int i) const {return rcData->positionOfComponent[i];}
398  // positions of the coordinate Index's
399  inline int positionOfCoordinate(int i) const {return rcData->positionOfCoordinate[i];}
400 
401 
402  intSerialArray & getSerialArray();
403  const intSerialArray & getSerialArray() const;
404 
405  virtual aString getClassName() const;
406 
407  int getComponentBound( int component ) const; // get the bound of the given component
408  int getComponentBase( int component ) const; // get the base of the given component
409  int getComponentDimension( int component ) const; // get the dimension of the given component
410 
411  int getCoordinateBound( int coordinate ) const; // get the bound of the given coordinate
412  int getCoordinateBase( int coordinate ) const; // get the base of the given coordinate
413  int getCoordinateDimension( int coordinate ) const; // get the dimension of the given coordinate
414 
415  MappedGrid* getMappedGrid(const bool abortIfNull=TRUE) const; // return a pointer to the MappedGrid
416 
418  getGridFunctionType(const Index & component0=nullIndex, // return the type of the grid function
419  const Index & component1=nullIndex,
420  const Index & component2=nullIndex,
421  const Index & component3=nullIndex,
422  const Index & component4=nullIndex ) const;
423 
425  getGridFunctionTypeWithComponents(const Index & component0=nullIndex, // return the type of the grid function
426  const Index & component1=nullIndex,
427  const Index & component2=nullIndex,
428  const Index & component3=nullIndex,
429  const Index & component4=nullIndex ) const;
430 
431  int getNumberOfComponents() const; // number of components
432 
433  bool isNull(); // TRUE is this is a null grid function (no grid)
434 
435  void setIsACoefficientMatrix(const bool trueOrFalse=TRUE,
436  const int stencilSize=defaultValue,
437  const int numberOfGhostLines=1,
438  const int numberOfComponentsForCoefficients=1,
439  const int offset=0 );
440 
441  void setIsACoefficientMatrix(SparseRepForMGF *sparseRep);
442 
443  bool getIsACoefficientMatrix() const;
444 
446 
448 
449  int getStencilWidth() const;
450 
451  // use for setting equation numbers for coefficient grid functions:
452  virtual int setCoefficientIndex(const int & m,
453  const int & na, const Index & I1a, const Index & I2a, const Index & I3a,
454  const int & nb, const Index & I1b, const Index & I2b, const Index & I3b);
455 
456  int positionOfCoefficient(const int m1, const int m2, const int m3, const int component) const;
457 
458  int dataCopy( const intMappedGridFunction & mgf ); // copy the array data only
459 
460  void getRanges(Range & R0, // return the current values for the Ranges
461  Range & R1,
462  Range & R2,
463  Range & R3,
464  Range & R4,
465  Range & R5,
466  Range & R6,
467  Range & R7 );
468 
469  // link this grid function to another
470  void link(const intMappedGridFunction & mgf,
471  const Range & R0, // these 5 Ranges correspond to the 5 possible components
472  const Range & R1=nullRange,
473  const Range & R2=nullRange,
474  const Range & R3=nullRange,
475  const Range & R4=nullRange );
476 
477  void link(const intMappedGridFunction & mgf,
478  const int componentToLinkTo=0,
479  const int numberOfComponents=1 );
480 
481  inline int numberOfDimensions() const { return rcData->numberOfDimensions; }
482  inline int numberOfComponents() const { return rcData->numberOfComponents; }
483  inline int positionOfFaceCentering() const { return rcData->positionOfFaceCentering; }
484 
485  // Clean up a grid function, release the memory
486  int destroy();
487 
488  // Update edges of periodic grids
489  void periodicUpdate(const Range & C0=nullRange,
490  const Range & C1=nullRange,
491  const Range & C2=nullRange,
492  const Range & C3=nullRange,
493  const Range & C4=nullRange,
494  const bool & derivativePeriodic=FALSE);
495 
496  // Update arrays to match grid, keep same number of components by default
498 
500 
502 
504  const Range & R0,
505  const Range & R1=nullRange,
506  const Range & R2=nullRange,
507  const Range & R3=nullRange,
508  const Range & R4=nullRange,
509  const Range & R5=nullRange,
510  const Range & R6=nullRange,
511  const Range & R7=nullRange );
512 
514  const Range & R0,
515  const Range & R1=nullRange,
516  const Range & R2=nullRange,
517  const Range & R3=nullRange,
518  const Range & R4=nullRange,
519  const Range & R5=nullRange,
520  const Range & R6=nullRange,
521  const Range & R7=nullRange );
522 
523  updateReturnValue updateToMatchGrid(const Range & R0,
524  const Range & R1=nullRange,
525  const Range & R2=nullRange,
526  const Range & R3=nullRange,
527  const Range & R4=nullRange,
528  const Range & R5=nullRange,
529  const Range & R6=nullRange,
530  const Range & R7=nullRange );
531 
533  const int & i0,
534  const Range & R1=nullRange,
535  const Range & R2=nullRange,
536  const Range & R3=nullRange,
537  const Range & R4=nullRange,
538  const Range & R5=nullRange,
539  const Range & R6=nullRange,
540  const Range & R7=nullRange );
541 
544  const Range & component0,
545  const Range & component1=nullRange, // defaults to Range(0,0)
546  const Range & component2=nullRange,
547  const Range & component3=nullRange,
548  const Range & component4=nullRange );
551  const Range & component0,
552  const Range & component1=nullRange, // defaults to Range(0,0)
553  const Range & component2=nullRange,
554  const Range & component3=nullRange,
555  const Range & component4=nullRange );
557  const Range & component0,
558  const Range & component1=nullRange, // defaults to Range(0,0)
559  const Range & component2=nullRange,
560  const Range & component3=nullRange,
561  const Range & component4=nullRange );
565 
566 
567  // update this grid function to match another grid function
570  const Range & R0,
571  const Range & R1=nullRange,
572  const Range & R2=nullRange,
573  const Range & R3=nullRange,
574  const Range & R4=nullRange,
575  const Range & R5=nullRange,
576  const Range & R6=nullRange,
577  const Range & R7=nullRange );
578 
579  // set the name of the grid function or a component
580  void setName(const aString & name,
581  const int & component0=defaultValue,
582  const int & component1=defaultValue,
583  const int & component2=defaultValue,
584  const int & component3=defaultValue,
585  const int & component4=defaultValue );
586 
587  // get the name of the grid function or a component
588  aString getName(const int & component0=defaultValue,
589  const int & component1=defaultValue,
590  const int & component2=defaultValue,
591  const int & component3=defaultValue,
592  const int & component4=defaultValue ) const;
593 
594  // reference
595  void reference( const intMappedGridFunction & cgf );
596  // break a reference
597  void breakReference();
598 
599  virtual int get( const GenericDataBase & dir, const aString & name); // get from a database file
600  virtual int put( GenericDataBase & dir, const aString & name) const; // put to a database file
601 
602  // inquire cell centredness
603  bool getIsCellCentered(const Index & axis=nullIndex,
604  const Index & component0=nullIndex,
605  const Index & component1=nullIndex,
606  const Index & component2=nullIndex,
607  const Index & component3=nullIndex,
608  const Index & component4=nullIndex ) const;
609  // change cell centredness:
610  void setIsCellCentered(const bool trueOrFalse,
611  const Index & axis=nullIndex,
612  const Index & component0=nullIndex,
613  const Index & component1=nullIndex,
614  const Index & component2=nullIndex,
615  const Index & component3=nullIndex,
616  const Index & component4=nullIndex );
617 
618  // inquire whether the grid function is face-centred along a given axis, for a given component
619  bool getIsFaceCentered(const int & axis=forAll,
620  const Index & component0=nullIndex,
621  const Index & component1=nullIndex,
622  const Index & component2=nullIndex,
623  const Index & component3=nullIndex,
624  const Index & component4=nullIndex ) const;
625 
626  // set a component to be face centred along a given axis
627  void setIsFaceCentered(const int & axis=forAll,
628  const Index & component0=nullIndex,
629  const Index & component1=nullIndex,
630  const Index & component2=nullIndex,
631  const Index & component3=nullIndex,
632  const Index & component4=nullIndex );
633 
634  // This next function tells you whether the grid function is face centred in a standard way
636 
637  // Set the type of face centering, the behaviour of this function depends on whether the
638  // argument "axis" has been specified, otherwise the current value for getFaceCentering():
639  // (1) if "axis" is given then make all components face centred in direction=axis
640  // (2) if getFaceCentering()==all : make components face centered in all directions, the
641  // grid function should have been contructed or updated using the faceRange to specify
642  // which Index is to be used for the "directions"
643  void setFaceCentering( const int & axis=defaultValue );
644 
645  // ------------------Define Derivatives-----------------------------------------------------
646  MappedGridOperators* getOperators() const; // return a pointer to the operators
647  void setOperators(GenericMappedGridOperators & operators ); // supply an operator to use
648 
649 
650  // specify what should be updated when calls are made to updateToMatchGrid
651  void setUpdateToMatchGridOption( const UpdateToMatchGridOption & updateToMatchGridOption );
652 
653  // return size of this object
654  virtual real sizeOf(FILE *file = NULL ) const;
655 
656  // fixup unused points
657  virtual int fixupUnusedPoints(const RealArray & value =Overture::nullRealArray(),
658  int numberOfGhostlines=1 );
659 
660 // int zeroUnusedPoints(intMappedGridFunction & coeff,
661 // int value = 0,
662 // const Index & component0=nullIndex,
663 // const Index & component1=nullIndex,
664 // const Index & component2=nullIndex,
665 // const Index & component3=nullIndex,
666 // const Index & component4=nullIndex );
667 
668  // ************************************************
669  // ***** DIFFERENTIATION CLASS FUNCTIONS **********
670  // ************************************************
671 
672 
673 // Macro to define a typical function call
674 #define FUNCTION(type) \
675  virtual intMappedGridFunction type(const Index & I1 = nullIndex, \
676  const Index & I2 = nullIndex, \
677  const Index & I3 = nullIndex, \
678  const Index & I4 = nullIndex, \
679  const Index & I5 = nullIndex, \
680  const Index & I6 = nullIndex, \
681  const Index & I7 = nullIndex, \
682  const Index & I8 = nullIndex ) const; \
683  \
684  virtual intMappedGridFunction type(const GridFunctionParameters & gfType, \
685  const Index & I1 = nullIndex, \
686  const Index & I2 = nullIndex, \
687  const Index & I3 = nullIndex, \
688  const Index & I4 = nullIndex, \
689  const Index & I5 = nullIndex, \
690  const Index & I6 = nullIndex, \
691  const Index & I7 = nullIndex, \
692  const Index & I8 = nullIndex ) const; \
693 
694 
695  // parametric derivatives in the r1,r2,r3 directions
696  FUNCTION(r1)
697  FUNCTION(r1Coefficients)
698  FUNCTION(r2)
699  FUNCTION(r2Coefficients)
700  FUNCTION(r3)
701  FUNCTION(r3Coefficients)
702  FUNCTION(r1r1)
703  FUNCTION(r1r1Coefficients)
704  FUNCTION(r1r2)
705  FUNCTION(r1r2Coefficients)
706  FUNCTION(r1r3)
707  FUNCTION(r1r3Coefficients)
708  FUNCTION(r2r2)
709  FUNCTION(r2r2Coefficients)
710  FUNCTION(r2r3)
711  FUNCTION(r2r3Coefficients)
712  FUNCTION(r3r3)
713  FUNCTION(r3r3Coefficients)
714 
715  // FUNCTIONs in the x,y,z directions
716  FUNCTION(x)
717  FUNCTION(xCoefficients)
718  FUNCTION(y)
719  FUNCTION(yCoefficients)
720  FUNCTION(z)
721  FUNCTION(zCoefficients)
722  FUNCTION(xx)
723  FUNCTION(xxCoefficients)
724  FUNCTION(xy)
725  FUNCTION(xyCoefficients)
726  FUNCTION(xz)
727  FUNCTION(xzCoefficients)
728  FUNCTION(yy)
729  FUNCTION(yyCoefficients)
730  FUNCTION(yz)
731  FUNCTION(yzCoefficients)
732  FUNCTION(zz)
733  FUNCTION(zzCoefficients)
734 
735  // other forms of derivatives
736 
737  // compute face-centered variable from cell-centered variable
738  FUNCTION(cellsToFaces)
739 
740  //compute (u.grad)u (convective derivative)
742 
743  // compute contravariant velocity from either cell-centered or face-centered input velocity
744  FUNCTION(contravariantVelocity)
745 
746  FUNCTION(div)
747  FUNCTION(divCoefficients)
748 
749  //returns cell-centered divergence given normal velocities
750  FUNCTION(divNormal)
751 
752  // compute faceArea-weighted normal velocity from either cell-centered or
753  // face-centered input velocity (this is just an alias for contravariantVelocity)
754  FUNCTION(normalVelocity)
755 
756  FUNCTION(grad)
757  FUNCTION(gradCoefficients)
758 
759  FUNCTION(identity)
760  FUNCTION(identityCoefficients)
761 
762  FUNCTION(laplacian)
763  FUNCTION(laplacianCoefficients)
764 
765  FUNCTION(vorticity)
766 
767 #undef FUNCTION
768  // ******* derivatives in non-standard form ***********
769 
770  //compute (u.grad)w (convective derivative of passive variable(s))
772  const intMappedGridFunction &w,
773  const Index & I1 = nullIndex,
774  const Index & I2 = nullIndex,
775  const Index & I3 = nullIndex
776  ) const;
778  const intMappedGridFunction &w,
779  const Index & I1 = nullIndex,
780  const Index & I2 = nullIndex,
781  const Index & I3 = nullIndex
782  ) const;
783 
784 #define SCALAR_FUNCTION(type) \
785  virtual intMappedGridFunction type(\
786  const intMappedGridFunction & s,\
787  const Index & I1 = nullIndex, \
788  const Index & I2 = nullIndex, \
789  const Index & I3 = nullIndex, \
790  const Index & I4 = nullIndex,\
791  const Index & I5 = nullIndex,\
792  const Index & I6 = nullIndex,\
793  const Index & I7 = nullIndex,\
794  const Index & I8 = nullIndex\
795  ) const; \
796  virtual intMappedGridFunction type(const GridFunctionParameters & gfType,\
797  const intMappedGridFunction & s,\
798  const Index & I1 = nullIndex, \
799  const Index & I2 = nullIndex, \
800  const Index & I3 = nullIndex, \
801  const Index & I4 = nullIndex,\
802  const Index & I5 = nullIndex,\
803  const Index & I6 = nullIndex,\
804  const Index & I7 = nullIndex,\
805  const Index & I8 = nullIndex\
806  ) const;
807 
808 
809  // div(s grad(u)), s=scalar field
810  SCALAR_FUNCTION(divScalarGrad)
811  SCALAR_FUNCTION(divScalarGradCoefficients)
812 
813  // div((1/s).grad(u))
814  SCALAR_FUNCTION(divInverseScalarGrad)
815  SCALAR_FUNCTION(divInverseScalarGradCoefficients)
816 
817  // div( sv u )
818  SCALAR_FUNCTION(divVectorScalar)
819  SCALAR_FUNCTION(divVectorScalarCoefficients)
820 
821 #undef SCALAR_FUNCTION
822 
824  const intMappedGridFunction & s,
825  const int & direction1,
826  const int & direction2,
827  const Index & I1 = nullIndex,
828  const Index & I2 = nullIndex,
829  const Index & I3 = nullIndex,
830  const Index & I4 = nullIndex,
831  const Index & I5 = nullIndex,
832  const Index & I6 = nullIndex,
833  const Index & I7 = nullIndex,
834  const Index & I8 = nullIndex
835  ) const;
836 
838  const intMappedGridFunction & s,
839  const int & direction1,
840  const int & direction2,
841  const Index & I1 = nullIndex,
842  const Index & I2 = nullIndex,
843  const Index & I3 = nullIndex,
844  const Index & I4 = nullIndex,
845  const Index & I5 = nullIndex,
846  const Index & I6 = nullIndex,
847  const Index & I7 = nullIndex,
848  const Index & I8 = nullIndex
849  ) const;
851  const intMappedGridFunction & s,
852  const int & direction1,
853  const int & direction2,
854  const Index & I1 = nullIndex,
855  const Index & I2 = nullIndex,
856  const Index & I3 = nullIndex,
857  const Index & I4 = nullIndex,
858  const Index & I5 = nullIndex,
859  const Index & I6 = nullIndex,
860  const Index & I7 = nullIndex,
861  const Index & I8 = nullIndex
862  ) const;
864  const GridFunctionParameters & gfType,
865  const intMappedGridFunction & s,
866  const int & direction1,
867  const int & direction2,
868  const Index & I1 = nullIndex,
869  const Index & I2 = nullIndex,
870  const Index & I3 = nullIndex,
871  const Index & I4 = nullIndex,
872  const Index & I5 = nullIndex,
873  const Index & I6 = nullIndex,
874  const Index & I7 = nullIndex,
875  const Index & I8 = nullIndex
876  ) const;
877 
878 
879  //returns face-centered gradients
880  virtual intMappedGridFunction FCgrad (
881  const int c0 = 0,
882  const int c1 = 0,
883  const int c2 = 0,
884  const int c3 = 0,
885  const int c4 = 0,
886  const Index & I1 = nullIndex,
887  const Index & I2 = nullIndex,
888  const Index & I3 = nullIndex,
889  const Index & I4 = nullIndex,
890  const Index & I5 = nullIndex,
891  const Index & I6 = nullIndex,
892  const Index & I7 = nullIndex,
893  const Index & I8 = nullIndex
894  ) const;
895 
896  virtual intMappedGridFunction FCgrad (const GridFunctionParameters & gfType,
897  const int c0 = 0,
898  const int c1 = 0,
899  const int c2 = 0,
900  const int c3 = 0,
901  const int c4 = 0,
902  const Index & I1 = nullIndex,
903  const Index & I2 = nullIndex,
904  const Index & I3 = nullIndex,
905  const Index & I4 = nullIndex,
906  const Index & I5 = nullIndex,
907  const Index & I6 = nullIndex,
908  const Index & I7 = nullIndex,
909  const Index & I8 = nullIndex
910  ) const;
911 
912 
913 
914  // ********************************************************************
915  // ------------- Here we define the Boundary Conditions ---------------
916  // ********************************************************************
917 
918  virtual void applyBoundaryConditions(const real & time = 0.);
919  // fill in coefficients for the boundary conditions
920  virtual void assignBoundaryConditionCoefficients(const real & time = 0.);
921 
922  // new BC interface:
923  void applyBoundaryCondition(const Index & Components,
924  const BCTypes::BCNames & boundaryConditionType=BCTypes::dirichlet,
925  const int & boundaryCondition = BCTypes::allBoundaries,
926  const real & forcing = 0.,
927  const real & time = 0.,
928  const BoundaryConditionParameters & bcParameters
930  const int & grid=0);
931 
932 
933  void applyBoundaryCondition(const Index & Components,
934  const BCTypes::BCNames & boundaryConditionType,
935  const int & boundaryCondition,
936  const RealArray & forcing,
937  const real & time = 0.,
938  const BoundaryConditionParameters & bcParameters
940  const int & grid=0);
941 
942  void applyBoundaryCondition(const Index & Components,
943  const BCTypes::BCNames & boundaryConditionType,
944  const int & boundaryCondition,
945  const RealArray & forcing,
946  RealArray *forcinga[2][3],
947  const real & time = 0.,
948  const BoundaryConditionParameters & bcParameters
950  const int & grid=0);
951 
952  void applyBoundaryCondition(const Index & Components,
953  const BCTypes::BCNames & boundaryConditionType,
954  const int & boundaryCondition,
955  const intMappedGridFunction & forcing,
956  const real & time = 0.,
957  const BoundaryConditionParameters & bcParameters
959  const int & grid=0);
960 
961 #ifdef USE_PPP
962 // // this version takes a distributed array "forcing"
963 // void applyBoundaryCondition(const Index & Components,
964 // const BCTypes::BCNames & boundaryConditionType,
965 // const int & boundaryCondition,
966 // const RealDistributedArray & forcing,
967 // const real & time = 0.,
968 // const BoundaryConditionParameters & bcParameters
969 // = Overture::defaultBoundaryConditionParameters(),
970 // const int & grid=0 );
971 #endif
972 
973  // fix corners and periodic update:
975  const Range & C0=nullRange);
976 
977  void applyBoundaryConditionCoefficients(const Index & Equation,
978  const Index & Component,
979  const BCTypes::BCNames & boundaryConditionType=BCTypes::dirichlet,
980  const int & boundaryCondition = BCTypes::allBoundaries,
981  const BoundaryConditionParameters & bcParameters
983  const int & grid=0);
984 
985 
986  // Here are functions used to evaluate a whole set of derivatives at a time (for efficiency)
987  // Make a list of derivatives to be evaluated and supply arrays to save the results in
988 
989  void getDerivatives(const Index & I1 = nullIndex,
990  const Index & I2 = nullIndex,
991  const Index & I3 = nullIndex,
992  const Index & I4 = nullIndex,
993  const Index & I5 = nullIndex,
994  const Index & I6 = nullIndex,
995  const Index & I7 = nullIndex,
996  const Index & I8 = nullIndex ) const;
997 
998 
999  // --------member functions for boundary conditions ----------------------------------
1000 
1002 
1003 
1004  protected:
1005  void setNumberOfDimensions(const int & number);
1006  void setNumberOfComponents(const int & number);
1007 
1008  int faceCentering() const { return rcData->faceCentering; }
1009  int isACoefficientMatrix() const { return rcData->isACoefficientMatrix; }
1010  int stencilType() const { return rcData->stencilType; }
1011  int stencilWidth() const { return rcData->stencilWidth; }
1012 
1013  void setPositionOfFaceCentering( const int & position );
1014 
1015  private:
1016 
1017  updateReturnValue privateUpdateToMatchGrid(); // called by other update functions
1018 
1019  void dimensionName(); // make sure name is long enough
1020  void updateRanges(const Range & R0, // update the R[] array
1021  const Range & R1,
1022  const Range & R2,
1023  const Range & R3,
1024  const Range & R4,
1025  const Range & R5,
1026  const Range & R6,
1027  const Range & R7,
1029 
1030 
1031  // These are used by list's of ReferenceCounting objects
1032  virtual void reference( const ReferenceCounting & mgf )
1034  virtual ReferenceCounting & operator=( const ReferenceCounting & mgf )
1036  virtual ReferenceCounting* virtualConstructor( const CopyType ct = DEEP ) const
1037  { return ::new intMappedGridFunction(*this,ct); }
1038 
1039  void initialize();
1040  void derivativeError() const;
1041  void boundaryConditionError() const;
1042 
1045 
1046 
1047 };
1048 
1049 // Here are a non-member utility routines
1051 multiply( const intMappedGridFunction & a, const intMappedGridFunction & coeff );
1052 
1054 multiply( const intDistributedArray & a, const intMappedGridFunction & coeff );
1055 
1056 // These next declarations are needed to be compatible with STL
1061 intDistributedArray operator!=(const intMappedGridFunction& x, const int& y);
1062 intDistributedArray operator> (const intMappedGridFunction& x, const int& y);
1063 intDistributedArray operator<=(const intMappedGridFunction& x, const int& y);
1064 intDistributedArray operator>=(const intMappedGridFunction& x, const int& y);
1065 intDistributedArray operator!=(const int& x, const intMappedGridFunction& y);
1066 intDistributedArray operator> (const int& x, const intMappedGridFunction& y);
1067 intDistributedArray operator<=(const int& x, const intMappedGridFunction& y);
1068 intDistributedArray operator>=(const int& x, const intMappedGridFunction& y);
1069 
1070 // add these to overcome STL's definition of min and max
1072 intDistributedArray min(const intMappedGridFunction & u, const int& x );
1073 intDistributedArray min(const int& x, const intMappedGridFunction & v );
1074 
1076 intDistributedArray max(const intMappedGridFunction & u, const int& x );
1077 intDistributedArray max(const int& x, const intMappedGridFunction & v );
1078 
1079 
1080 #endif // intMappedGridFunction.h