Overture  Version 25
floatGridCollectionFunction.h
Go to the documentation of this file.
1 /* -*-Mode: c++; -*- */
2 #ifndef FLOAT_GRID_COLLECTION_FUNCTION
3 #define FLOAT_GRID_COLLECTION_FUNCTION "floatGridCollectionFunction.h"
4 
9 
10 
11 // Note that fabs is converted to abs in the int case
12 
13 class GridCollection; // forward declaration
14 class GridCollectionData; // forward declaration
15 class Interpolant; // forward declaration
16 class GenericGridCollectionOperators; // forward declaration
17 class SparseRepForGCF; // forward declaration
22 class DisplayParameters;
23 
24 //===================================================================
25 // floatGridCollectionFunction
26 //
27 // Define a grid function to be used with a composite grid.
28 // This class contains a list of floatMappedGridFunction's
29 // and a gridCollection
30 //
31 // This is a reference counted class so that there is no need
32 // to keep a pointer to a grid function. Use the reference
33 // member function to make one grid function reference another.
34 //
35 // Usage:
36 // GridCollection cg(...); // here is a composite grid
37 // doubleGridCollectionFunction u(cg),v;
38 // u[0]=5.; // mapped grid function for grid 0
39 // Index I(0,10);
40 // u[1](I,I)=3.; // mapped grid function for grid 1
41 // v.reference(u); // v is referenced to u
42 // v[1]=7.; // changes u as well
43 // v.breakReference(); // v is no longer referenced to u
44 // ...
45 //
46 //==================================================================
47 
49 {
50  public:
51 
52  enum
53  {
60  };
61 
62  enum updateReturnValue // the return value from updateToMatchGrid is a mask of the following values
63  {
66  updateResized = floatMappedGridFunction::updateResized, // grid function was resized
68  // have changed (but grid was not resized or reshaped)
69  };
70 
71 // IntegerArray positionOfComponent;
72 // IntegerArray positionOfCoordinate;
73  // positions of the component Index's
74  inline int positionOfComponent(int i) const {return rcData->positionOfComponent[i];}
75  // positions of the coordinate Index's
76  inline int positionOfCoordinate(int i) const {return rcData->positionOfCoordinate[i];}
77  // takes on values found in the faceCenteringType enumerator
78  // numberOfComponentGrids : number of grids including refinements but excluding multigrid levels
79  int numberOfComponentGrids() const;
80  // numberOfGrids : total number of grids including refinements and multigrid levels
81  int numberOfGrids() const;
82 
83  int numberOfRefinementLevels() const;
84  int numberOfMultigridLevels() const;
85  inline int positionOfFaceCentering() const { return rcData->positionOfFaceCentering; }
86  inline int faceCentering() const { return rcData->faceCentering; }
87 
89 
90  // Collections of grid functions having the same base grid.
92 
93  // Collections of grid functions having the same multigrid level.
95 
96  // Collections of grid functions having the same refinement level.
98 
99  // the next two pointers could be in rcData!
100  GridCollectionData *gridCollectionData; // for normal access to the gridCollection
101  GridCollection *gridCollection; // pointer to the GridCollection
102  GenericCollectionOperators *operators; // object to define derivatives and BC's
103  SparseRepForGCF *sparse; // pointer to info on sparse representation for coefficients
104 
105  //-----------------------------------------------------------------------------------------
106  //----------------------------Constructors-------------------------------------------------
107  //-----------------------------------------------------------------------------------------
109 
110  // This constructor takes ranges, the first 3 "nullRange" values are taken to be the
111  // coordinate directions in the grid function.
113  const Range & R0,
114  const Range & R1=nullRange,
115  const Range & R2=nullRange,
116  const Range & R3=nullRange,
117  const Range & R4=nullRange,
118  const Range & R5=nullRange,
119  const Range & R6=nullRange,
120  const Range & R7=nullRange );
121 
123  const Range & R0,
124  const Range & R1=nullRange,
125  const Range & R2=nullRange,
126  const Range & R3=nullRange,
127  const Range & R4=nullRange,
128  const Range & R5=nullRange,
129  const Range & R6=nullRange,
130  const Range & R7=nullRange );
131 
133  const int & i0,
134  const Range & R1=nullRange,
135  const Range & R2=nullRange,
136  const Range & R3=nullRange,
137  const Range & R4=nullRange,
138  const Range & R5=nullRange,
139  const Range & R6=nullRange,
140  const Range & R7=nullRange );
141 
143  const int & i0,
144  const Range & R1=nullRange,
145  const Range & R2=nullRange,
146  const Range & R3=nullRange,
147  const Range & R4=nullRange,
148  const Range & R5=nullRange,
149  const Range & R6=nullRange,
150  const Range & R7=nullRange );
151 
152  //
153  // This constructor takes a GridFunctionType
154  //
157  const Range & component0=nullRange, // defaults to Range(0,0)
158  const Range & component1=nullRange,
159  const Range & component2=nullRange,
160  const Range & component3=nullRange,
161  const Range & component4=nullRange );
162 
165 
167 
169 
170 
172 
173  virtual floatMappedGridFunction & operator[]( const int grid ) const
174  {
175  return mappedGridFunctionList[grid];
176  }
177 
178  // Return a link to some specfied components ** cannot be virtual**
179  floatGridCollectionFunction operator()(const Range & component0,
180  const Range & component1=nullRange,
181  const Range & component2=nullRange,
182  const Range & component3=nullRange,
183  const Range & component4=nullRange );
184 
185  virtual void consistencyCheck() const;
186 
187  virtual aString getClassName() const;
188 
189  int getComponentBound( int component ) const; // get the bound of the given component
190  int getComponentBase( int component ) const; // get the base of the given component
191  int getComponentDimension( int component ) const; // get the dimension of the given component
192 
193  int getCoordinateBound( int coordinate ) const; // get the bound of the given coordinate
194  int getCoordinateBase( int coordinate ) const; // get the base of the given coordinate
195  int getCoordinateDimension( int coordinate ) const; // get the dimension of the given coordinate
196 
198  getGridFunctionType(const Index & component0=nullIndex, // return the type of the grid function
199  const Index & component1=nullIndex,
200  const Index & component2=nullIndex,
201  const Index & component3=nullIndex,
202  const Index & component4=nullIndex ) const;
203 
206  const Index & component0=nullIndex, // return the type of the grid function
207  const Index & component1=nullIndex,
208  const Index & component2=nullIndex,
209  const Index & component3=nullIndex,
210  const Index & component4=nullIndex ) const;
211 
212  int getNumberOfComponents() const; // number of components
213 
214  bool isNull(); // TRUE is this is a null grid function (no grid)
215 
216  virtual void setIsACoefficientMatrix(const bool trueOrFalse=TRUE,
217  const int stencilSize=defaultValue,
218  const int numberOfGhostLines=1,
219  const int numberOfComponentsForCoefficients=1,
220  const int offset=0 );
221  bool getIsACoefficientMatrix() const;
222 
223  virtual int dataCopy( const floatGridCollectionFunction & gcf ); // copy the array data only
224 
225  virtual void display( const aString & label=nullString, FILE *file = NULL, const aString & format=nullString ) const;
226  virtual void display( const aString & label, const aString & format ) const;
227  virtual void display( const aString & label, const DisplayParameters & displayParameters) const;
228 
229  virtual int interpolate(Interpolant & interpolant,
230  const Range & C0 = nullRange,
231  const Range & C1 = nullRange,
232  const Range & C2 = nullRange );
233  virtual int interpolate(const Range & C0 = nullRange,
234  const Range & C1 = nullRange,
235  const Range & C2 = nullRange );
236 
237  // Clean up a grid function, release the memory
238  virtual int destroy();
239 
240  // link to a component of another grid Function
241  virtual void link(const floatGridCollectionFunction & gcf,
242  const Range & R0,
243  const Range & R1=nullRange,
244  const Range & R2=nullRange,
245  const Range & R3=nullRange,
246  const Range & R4=nullRange );
247 
248  void getRanges(Range & R0, // return the current values for the Ranges
249  Range & R1,
250  Range & R2,
251  Range & R3,
252  Range & R4,
253  Range & R5,
254  Range & R6,
255  Range & R7 ) const;
256 
257  virtual void link(const floatGridCollectionFunction & gcf,
258  const int componentToLinkTo=0,
259  const int numberOfComponents=1 );
260 
261 
262  virtual void reference( const floatGridCollectionFunction & cgf );
263  virtual void breakReference();
264 
265  // set the name of the grid function or of a component
266  void setName(const aString & name,
267  const int & component0=defaultValue,
268  const int & component1=defaultValue,
269  const int & component2=defaultValue,
270  const int & component3=defaultValue,
271  const int & component4=defaultValue );
272 
273  // get the name of the grid function or a component
274  aString getName(const int & component0=defaultValue,
275  const int & component1=defaultValue,
276  const int & component2=defaultValue,
277  const int & component3=defaultValue,
278  const int & component4=defaultValue ) const ;
279 
280  virtual GridCollection* getGridCollection(const bool abortIfNull=TRUE) const; // return a pointer to the grid collection
281 
282  virtual int get( const GenericDataBase & dir, const aString & name); // get from a database file
283  virtual int put( GenericDataBase & dir, const aString & name) const; // put to a database file
284 
285  // Update edges of periodic grids
286  virtual void periodicUpdate(const Range & C0=nullRange,
287  const Range & C1=nullRange,
288  const Range & C2=nullRange,
289  const Range & C3=nullRange,
290  const Range & C4=nullRange,
291  const bool & derivativePeriodic=FALSE);
292 
295  const Range & R0,
296  const Range & R1=nullRange,
297  const Range & R2=nullRange,
298  const Range & R3=nullRange,
299  const Range & R4=nullRange,
300  const Range & R5=nullRange,
301  const Range & R6=nullRange,
302  const Range & R7=nullRange );
303 
305  const Range & R0,
306  const Range & R1=nullRange,
307  const Range & R2=nullRange,
308  const Range & R3=nullRange,
309  const Range & R4=nullRange,
310  const Range & R5=nullRange,
311  const Range & R6=nullRange,
312  const Range & R7=nullRange );
313 
314  // define this version to avoid overloading ambiguities
316  const int & i0,
317  const Range & R1=nullRange,
318  const Range & R2=nullRange,
319  const Range & R3=nullRange,
320  const Range & R4=nullRange,
321  const Range & R5=nullRange,
322  const Range & R6=nullRange,
323  const Range & R7=nullRange );
324 
325  virtual updateReturnValue updateToMatchGrid(const Range & R0,
326  const Range & R1=nullRange,
327  const Range & R2=nullRange,
328  const Range & R3=nullRange,
329  const Range & R4=nullRange,
330  const Range & R5=nullRange,
331  const Range & R6=nullRange,
332  const Range & R7=nullRange );
333 
336  const Range & component0,
337  const Range & component1=nullRange,
338  const Range & component2=nullRange,
339  const Range & component3=nullRange,
340  const Range & component4=nullRange );
341 
343  const Range & component0,
344  const Range & component1=nullRange,
345  const Range & component2=nullRange,
346  const Range & component3=nullRange,
347  const Range & component4=nullRange );
348 
352 
353 
356 
357 
358  // update this grid function to match another grid function
360  const Range & R0,
361  const Range & R1=nullRange,
362  const Range & R2=nullRange,
363  const Range & R3=nullRange,
364  const Range & R4=nullRange,
365  const Range & R5=nullRange,
366  const Range & R6=nullRange,
367  const Range & R7=nullRange );
368 
370 
371  // make sure the number of mappedGridFunction's is correct
373  // Update the grid collection to match the component grids
375 
376 
377  void setInterpolant(Interpolant *interpolant );
378  // inquire cell centredness:
379  bool getIsCellCentered(const Index & axis=nullIndex,
380  const Index & component0=nullIndex,
381  const Index & component1=nullIndex,
382  const Index & component2=nullIndex,
383  const Index & component3=nullIndex,
384  const Index & component4=nullIndex,
385  const Index & grid=nullIndex ) const;
386  // change cell centredness:
387  void setIsCellCentered(const bool trueOrFalse,
388  const Index & axis=nullIndex,
389  const Index & component0=nullIndex,
390  const Index & component1=nullIndex,
391  const Index & component2=nullIndex,
392  const Index & component3=nullIndex,
393  const Index & component4=nullIndex,
394  const Index & grid=nullIndex );
395  // set a component to be face centred along a given axis
396  void setIsFaceCentered(const int & axis=forAll,
397  const Index & component0=nullIndex,
398  const Index & component1=nullIndex,
399  const Index & component2=nullIndex,
400  const Index & component3=nullIndex,
401  const Index & component4=nullIndex,
402  const Index & grid=nullIndex );
403 
404  // inquire whether the grid function is face-centred
405  bool getIsFaceCentered(const int & axis=forAll,
406  const Index & component0=nullIndex,
407  const Index & component1=nullIndex,
408  const Index & component2=nullIndex,
409  const Index & component3=nullIndex,
410  const Index & component4=nullIndex,
411  const Index & grid=nullIndex ) const;
412 
413  // This next function tells you whether the grid function is face centred in a standard way
415 
416  // Set the type of face centering, the behaviour of this function depends on whether the
417  // argument "axis" has been specified ore else the current value for getFaceCentering():
418  // (1) if "axis" is given then make all components face centred in direction=axis
419  // (2) if getFaceCentering()==all : make components face centered in all directions, the
420  // grid function should have been contructed or updated using the faceRange to specify
421  // which Index is to be used for the "directions"
422  void setFaceCentering( const int & axis=defaultValue );
423 
424  // Make sure the the faceCentering of the grid collection is consistent with the
425  // face centering of the MappedGridFunctions
426  int updateFaceCentering();
427 
428  // specify options on hold the array data is allocated.
429  void setDataAllocationOption(int option );
430 
431  // return size of this object
432  virtual real sizeOf(FILE *file = NULL ) const;
433 
434  // fixup unused points
435  virtual int fixupUnusedPoints(const RealArray & value =Overture::nullRealArray(),
436  int numberOfGhostlines=1 );
437 
438 // // zero out unused points based on the classify array in a coefficient matrix
439 // int zeroUnusedPoints(floatGridCollectionFunction & coeff,
440 // float value = 0,
441 // const Index & component0=nullIndex,
442 // const Index & component1=nullIndex,
443 // const Index & component2=nullIndex,
444 // const Index & component3=nullIndex,
445 // const Index & component4=nullIndex );
446 
447 
448  // ************************************************
449  // ***** DIFFERENTIATION CLASS FUNCTIONS **********
450  // ************************************************
451 
452 
453  // *wdh* 020423 Index I1,I2,I3;
454 
455  GridCollectionOperators* getOperators() const; // return a pointer to the operators **not virtual**
456  virtual void setOperators(GenericCollectionOperators & operators ); // supply a derivative object to use
457 
459 
460 #define COLLECTION_FUNCTION floatGridCollectionFunction
461 #define INT_COLLECTION_FUNCTION intGridCollectionFunction
462 #define COLLECTION GridCollection
463 #define INTEGRAL_TYPE float
464 #include "derivativeDefinitions.h"
465 #undef COLLECTION_FUNCTION
466 #undef INT_COLLECTION_FUNCTION
467 #undef COLLECTION
468 #undef INTEGRAL_TYPE
469 
470  // ***non-member friend functions ***
472 
473  // use this function to "evaluate and expression" when calling a function with an expression
474  // involving grid collection functions.
476 
477  private:
478 
479  // These are used by list's of ReferenceCounting objects
480  virtual void reference( const ReferenceCounting & mgf )
482  virtual ReferenceCounting & operator=( const ReferenceCounting & mgf )
484  virtual ReferenceCounting* virtualConstructor( const CopyType ct = DEEP ) const
485  { return ::new floatGridCollectionFunction(*this,ct); }
486 
487  protected:
488  void constructor(GridCollection *gridCollection0,
489  GridCollectionData *gridCollectionData0,
490  const Range & R0,
491  const Range & R1,
492  const Range & R2,
493  const Range & R3,
494  const Range & R4,
495  const Range & R5,
496  const Range & R6,
497  const Range & R7,
498  const bool createMappedGridFunctionList=TRUE );
499  void initialize();
500  void dimensionName(); // make sure name is long enough
501  virtual int updateCollections(); // update refinementLevel etc.
502  void setPositionOfFaceCentering(const int number);
503 
504  protected:
506  bool temporary; // TRUE if this is a temporary used internally
507  int dataAllocationOption; // ==1 means do not allocate data for rectangular grids.
508 
509  // holds data to be reference counted
510  public:
511  class RCData : public ReferenceCounting
512  {
513  public:
515  RCData();
516  virtual ~RCData();
517  RCData & operator=( const RCData & rcdata );
518 // IntegerArray positionOfComponent;
519 // IntegerArray positionOfCoordinate;
520 
521  int positionOfComponent[maximumNumberOfIndicies]; // positions of the components
522  int positionOfCoordinate[maximumNumberOfIndicies]; // positions of the coordinate directions
523 
527  aString *name; // pointer to an array of names for the grid function and components
528  int numberOfNames; // length of the name array
529  Interpolant *interpolant; // pointer to an interpolant
530  ListOfFloatGridCollectionFunction multigridLevel; // Collections of grid functions having the same multigrid level.
531  ListOfFloatGridCollectionFunction refinementLevel; // Collections of grid functions having the same refinement level.
532  private:
533 
534  // These are used by list's of ReferenceCounting objects
535  virtual void reference( const ReferenceCounting & mgf )
536  { RCData::reference( (RCData&) mgf ); }
537  virtual ReferenceCounting & operator=( const ReferenceCounting & mgf )
538  { return RCData::operator=( (RCData&) mgf ); }
539  virtual ReferenceCounting* virtualConstructor( const CopyType ) const
540  { return ::new RCData(); }
541  };
542 
543  protected:
545 
546 };
547 
548 
549 
550 #endif