Overture  Version 25
MappedGrid.h
Go to the documentation of this file.
1 #ifndef _MappedGrid
2 #define _MappedGrid
3 
4 //
5 // Who to blame: Geoff Chesshire and WDH
6 //
7 
8 #include "GenericGrid.h"
9 #include "MappedGridFunction.h"
10 #include "MappingRC.h"
11 #include "Box.H"
12 #include "GCMath.h"
13 
14 // #include "DataBaseAccessFunctions.h" // Cannot include this here.
17 
18 class AMR_ParentChildSiblingInfo;
19 
20 //
21 // Class for reference-counted data.
22 //
24  public GenericGridData {
25  public:
26  enum {
31  THEcenter = THEvertex << 1, // bit 4
32  THEcorner = THEcenter << 1, // bit 5
33  THEvertexDerivative = THEcorner << 1, // bit 6
37  THEcellVolume = THEcenterJacobian << 1, // bit 10
38  THEcenterNormal = THEcellVolume << 1, // bit 11
39  THEcenterArea = THEcenterNormal << 1, // bit 12
40  THEfaceNormal = THEcenterArea << 1, // bit 13
41  THEfaceArea = THEfaceNormal << 1, // bit 14
45  THEfreeBit18 = THEcenterBoundaryTangent << 1, // bit 18 // *wdh* 100424 -- this is now free
46  THEboundingBox = THEfreeBit18 << 1, // bit 19
49  | THEmask
50  | THEvertex
51  | THEcenter
54  | THEmask
57  | THEvertex
58  | THEcenter
59  | THEcorner
68  | THEfaceArea
78  ISinterpolationPoint = INT_MIN, // (sign bit) bit 31
79  ISdiscretizationPoint = 1 << 30, // bit 30
85  ISreservedBit1 = ISreservedBit2 >> 1, // bit 24
86  ISreservedBit0 = ISreservedBit1 >> 1, // bit 23
87  GRIDnumberBits = ISreservedBit0 - 1, // bits 0-22
90  | ISghostPoint
91  };
93  IntegerArray boundaryCondition; // ****** todo : clean up all these arrays****
103  // int extendedRange[2][3]; // include interp pts outside mixed bndry's
104  int pExtendedRange[6]; // include interp pts outside mixed bndry's
112  // RealArray minimumEdgeLength; // *wdh* get rid of these 100424
113  // RealArray maximumEdgeLength; // *wdh* get rid of these 100424
114  IntegerArray I1array, I2array, I3array; // *wdh* Are these needed??
115  Integer *I1, *I2, *I3;
116  Partitioning_Type partition;
117  bool partitionInitialized; // true when the partition has been specified.
118  Partitioning_Type matrixPartition; // for coefficient-matrix grid functions
119  bool matrixPartitionInitialized; // true when the partition has been specified.
121  bool refinementGrid; // true if this is a refinement grid.
122  int shareGridWithMapping; // if true share the vertex array with the mapping
123 
126 
128  {
134  };
135 
137 
140  // RealMappedGridFunction* inverseVertexDerivative2D;
141  // RealMappedGridFunction* inverseVertexDerivative1D;
143  // RealMappedGridFunction* inverseCenterDerivative2D;
144  // RealMappedGridFunction* inverseCenterDerivative1D;
146  // RealMappedGridFunction* vertex2D;
147  // RealMappedGridFunction* vertex1D;
149  // RealMappedGridFunction* center2D;
150  // RealMappedGridFunction* center1D;
152  // RealMappedGridFunction* corner2D;
153  // RealMappedGridFunction* corner1D;
155  // RealMappedGridFunction* vertexDerivative2D;
156  // RealMappedGridFunction* vertexDerivative1D;
158  // RealMappedGridFunction* centerDerivative2D;
159  // RealMappedGridFunction* centerDerivative1D;
164  // RealMappedGridFunction* centerNormal2D;
165  // RealMappedGridFunction* centerNormal1D;
167  // RealMappedGridFunction* centerArea2D;
168  // RealMappedGridFunction* centerArea1D;
170  // RealMappedGridFunction* faceNormal2D;
171  // RealMappedGridFunction* faceNormal1D;
173  // RealMappedGridFunction* faceArea2D;
174  // RealMappedGridFunction* faceArea1D;
178  // The boundary grid functions should probably be serial arrays for parallel to avoid matching
179  // parallel distributions. Do this for now:
183 
185  Box box;
186  MappedGridData(const Integer numberOfDimensions_ = 0);
188  const MappedGridData& x,
189  const CopyType ct = DEEP);
190  virtual ~MappedGridData();
191 
193 
194  // MappedGridData& equals(const MappedGridData& x, int option=0); // equals operator with options
195  virtual GenericGridData& equals(const GenericGridData& x, int option=0); // equals operator with options
196 
197  void reference(const MappedGridData& x);
198  virtual void breakReference();
199  virtual void consistencyCheck() const;
200 
201  virtual Integer get(const GenericDataBase& db,
202  const aString& name,
203  bool getMapping=true ); // for AMR grids we may not get the mapping.
204 
205  virtual Integer put(GenericDataBase& db,
206  const aString& name,
207  bool putMapping = true, // for AMR grids we may not save the mapping.
208  int geometryToPut = -1 ) const; // by default put computedGeometry
209 
210  inline Integer update(
211  const Integer what = THEusualSuspects,
212  const Integer how = COMPUTEtheUsual)
213  { return update(*this, what, how); }
214  inline Integer update(
215  MappedGridData& x,
216  const Integer what = THEusualSuspects,
217  const Integer how = COMPUTEtheUsual)
218  { return update((GenericGridData&)x, what, how); }
219  virtual void destroy(const Integer what = NOTHING);
220  virtual void specifyProcesses(const Range& range);
221  void initialize(const Integer& numberOfDimensions_);
222 
223  // remove items from what that are not appropriate for the gridType:
224  virtual int getWhatForGrid(const int what) const;
225 
226  void initializePartition(); // initialize the partition object
227 
228 //
229 // The number of dimensions of the domain.
230 //
231  inline Integer domainDimension() const
232  {
233  if ( mapping.mapPointer->getClassName()!="Mapping" )
235  else
236  return numberOfDimensions;
237  }
238 
239 //
240 // The number of dimensions of the range.
241 //
242  inline Integer rangeDimension() const
243  {
244  if ( mapping.mapPointer->getClassName()!="Mapping" )
246  else
247  return numberOfDimensions;
248  }
249 
250  const IntegerArray *getUnstructuredBCInfo( int type );
251  const IntegerArray *getUnstructuredPeriodicBC( int type );
252 
253  protected:
254  virtual Integer update(
255  GenericGridData& x,
256  const Integer what = THEusualSuspects,
257  const Integer how = COMPUTEtheUsual);
258  private:
259 
260  Integer update1(
261  MappedGridData& y,
262  const Integer& what,
263  const Integer& how,
264  Integer& computeNeeded);
265  Integer update2(
266  MappedGridData& y,
267  const Integer& what,
268  const Integer& how,
269  Integer& computeNeeded);
270  Integer updateUnstructuredGrid(
271  MappedGridData& y,
272  const Integer& what,
273  const Integer& how,
274  Integer& computeNeeded);
275 
276  Integer computeGeometry(
277  const Integer& what,
278  const Integer& how);
279  Integer computeGeometryWithDifferences(
280  const Integer& what,
281  const Integer& how);
282  Integer computeGeometryFromMapping(
283  const Integer& what,
284  const Integer& how);
285  Integer computeUnstructuredGeometry(
286  const Integer& what,
287  const Integer& how);
288 //
289 // Virtual member functions used only through class ReferenceCounting:
290 //
291  private:
292  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
293  { return operator=((MappedGridData&)x); }
294  inline virtual void reference(const ReferenceCounting& x)
295  { reference((MappedGridData&)x); }
296  inline virtual ReferenceCounting* virtualConstructor(
297  const CopyType ct = DEEP) const
298  { return new MappedGridData(*this, ct); }
299  aString className;
300  public:
301  inline virtual aString getClassName() const { return className; }
302 };
303 
305  public GenericGrid {
306  public:
307 // Public constants:
308 
309 // Constants to be ORed to form the first argument of update() and destroy():
310  enum {
329  // THEminMaxEdgeLength = MappedGridData::THEminMaxEdgeLength,
333  };
334 
335 // Constants to be ORed to form the second argument of update():
336  enum {
341  };
342 
343 // Mask bits to access data in mask.
344  enum {
356  };
357 
358  // should be the same as in MappedGridData
360  {
366  };
367 
368 // Public data.
369  AMR_ParentChildSiblingInfo* parentChildSiblingInfo;
370 
371  AMR_ParentChildSiblingInfo* getParentChildSiblingInfo(){return parentChildSiblingInfo;}
372  void setParentChildSiblingInfo(AMR_ParentChildSiblingInfo *ptr){parentChildSiblingInfo=ptr;}
373 //
374 // Public member functions for access to data.
375 //
376 // Boxlib box.
377 //
378  inline const Box& box() const { return rcData->box; }
379 //
380 // Boundary condition flags.
381 //
382  inline const IntegerArray& boundaryCondition() const
383  { return rcData->boundaryCondition; }
384  inline const Integer& boundaryCondition(
385  const Integer& ks,
386  const Integer& kd) const
387  { return rcData->boundaryCondition(ks,kd); }
388 
389  MappedGrid::BoundaryFlagEnum boundaryFlag(int side,int axis ) const;
390 //
391 // Boundary condition stencil.
392 //
396  const Integer& ks,
397  const Integer& kd) const
398  { return rcData->boundaryDiscretizationWidth(ks,kd); }
399 //
400 // Bounding box for all grid vertices.
401 //
402  inline const RealArray& boundingBox() const
403  { return rcData->boundingBox; }
404  inline const Real& boundingBox(
405  const Integer& ks,
406  const Integer& kd) const
407  { return rcData->boundingBox(ks,kd); }
408 
409  inline const RealArray& localBoundingBox() const
410  { return rcData->localBoundingBox; }
411  inline const Real& localBoundingBox(
412  const Integer& ks,
413  const Integer& kd) const
414  { return rcData->localBoundingBox(ks,kd); }
415 
416  // Return the partition used in this grid
417  const Partitioning_Type& getPartition(){return rcData->partition;} //
418  const Partitioning_Type& getMatrixPartition(){return rcData->matrixPartition;} //
419 //
420 // Grid spacing.
421 //
422  inline const RealArray& gridSpacing() const
423  { return rcData->gridSpacing; }
424  inline const Real& gridSpacing(const Integer& kd) const
425  { return rcData->gridSpacing(kd); }
426 //
427 // Grid type, structured or unstructured.
428 //
430  { return rcData->gridType; }
431 
432 //
433 // get the name of the grid.
434 //
435  aString getName() const;
436 //
437 // Cell-centered in each direction.
438 //
439  inline const LogicalArray& isCellCentered() const
440  { return rcData->isCellCentered; }
441  inline const Logical& isCellCentered(const Integer& kd) const
442  { return rcData->isCellCentered(kd); }
443 //
444 // Cell-centered in all directions.
445 //
446  inline const Logical& isAllCellCentered() const
447  { return rcData->isAllCellCentered; }
448 //
449 // Vertex-centered in all directions.
450 //
451  inline const Logical& isAllVertexCentered() const
452  { return rcData->isAllVertexCentered; }
453 
454 // is the grid rectangular
455  bool isRectangular() const;
456 
457  // is the grid a refinement grid:
458  bool isRefinementGrid() const { return rcData->refinementGrid; }
460 
461  // show which geometry arrays are built
462  int displayComputedGeometry(FILE *file=stdout ) const;
463 
464  // return size of this object
465  virtual real sizeOf(FILE *file = NULL ) const;
466 
467 //
468 // Interior discretization stencil width.
469 //
470  inline const IntegerArray& discretizationWidth() const
471  { return rcData->discretizationWidth; }
472  inline const Integer& discretizationWidth(const Integer& kd) const
473  { return rcData->discretizationWidth(kd); }
474 //
475 // Index range, computational points.
476 //
477  inline const IntegerArray& indexRange() const
478  { return rcData->indexRange; }
479  inline const Integer& indexRange(
480  const Integer& ks,
481  const Integer& kd) const
482  { return rcData->indexRange(ks,kd); }
483 //
484 // Index range plus interpolation points.
485 //
486  inline const IntegerArray& extendedIndexRange() const
487  { return rcData->extendedIndexRange; }
489  const Integer& ks,
490  const Integer& kd) const
491  { return rcData->extendedIndexRange(ks,kd); }
492 //
493 // Index range of gridpoints.
494 //
495  inline const IntegerArray& gridIndexRange() const
496  { return rcData->gridIndexRange; }
497  inline const Integer& gridIndexRange(
498  const Integer& ks,
499  const Integer& kd) const
500  { return rcData->gridIndexRange(ks,kd); }
501 //
502 // Dimensions of grid arrays.
503 //
504  inline const IntegerArray& dimension() const
505  { return rcData->dimension; }
506  inline const Integer& dimension(
507  const Integer& ks,
508  const Integer& kd) const
509  { return rcData->dimension(ks,kd); }
510 //
511 // Range for all discretization, boundary and interpolation points.
512 //
513  inline const int& extendedRange( int side, int axis ) const
514  { return rcData->pExtendedRange[side+2*(axis)]; }
515  IntegerArray extendedRange() const;
516 //
517 // Number of ghost points.
518 //
519  inline const IntegerArray& numberOfGhostPoints() const
520  { return rcData->numberOfGhostPoints; }
522  const Integer& ks,
523  const Integer& kd) const
524  { return rcData->numberOfGhostPoints(ks,kd); }
525 //
526 // Indicate whether ghost points may be used for interpolation.
527 //
528  inline const Logical& useGhostPoints() const
529  { return rcData->useGhostPoints; }
530 //
531 // Grid periodicity.
532 //
533  inline const IntegerArray& isPeriodic() const
534  { return rcData->isPeriodic; }
535  inline const Integer& isPeriodic(const Integer& kd) const
536  { return rcData->isPeriodic(kd); }
537 //
538 // The number of dimensions of the range.
539 //
540  inline const Integer& numberOfDimensions() const
541  { return rcData->numberOfDimensions; }
542 
543 //
544 // The number of dimensions of the domain.
545 //
546  inline Integer domainDimension() const
547  { return rcData->domainDimension(); }
548 
549 //
550 // The number of dimensions of the range.
551 //
552  inline Integer rangeDimension() const
553  { return rcData->rangeDimension(); }
554 
555 // specify whether the vertex array should be shared with the mapping
556  void setShareGridWithMapping( bool trueOrFalse ){ rcData->shareGridWithMapping=trueOrFalse; } //
557 
558 //
559 // Shared boundary flags.
560 //
561  inline const IntegerArray& sharedBoundaryFlag() const
562  { return rcData->sharedBoundaryFlag; }
564  const Integer& ks,
565  const Integer& kd) const
566  { return rcData->sharedBoundaryFlag(ks,kd); }
567 //
568 // Shared boundary tolerance.
569 //
570  inline const RealArray& sharedBoundaryTolerance() const
571  { return rcData->sharedBoundaryTolerance; }
573  const Integer& ks,
574  const Integer& kd) const
575  { return rcData->sharedBoundaryTolerance(ks,kd); }
576 //
577 // Minimum grid cell-edge length.
578 //
579 // inline const RealArray& minimumEdgeLength() const
580 // { return rcData->minimumEdgeLength; }
581 // inline const Real& minimumEdgeLength(const Integer& kd) const
582 // { return rcData->minimumEdgeLength(kd); }
583 //
584 // Maximum grid cell-edge length.
585 //
586 // inline const RealArray& maximumEdgeLength() const
587 // { return rcData->maximumEdgeLength; }
588 // inline const Real& maximumEdgeLength(const Integer& kd) const
589 // { return rcData->maximumEdgeLength(kd); }
590 //
591 // delta x for rectangular grids
592 //
593  int getDeltaX( Real dx[3] ) const;
594 
595 // get delta x and corners of a rectangular grid.
596  int getRectangularGridParameters( Real dx[3], Real xab[2][3] ) const;
597 //
598 // Indirect addressing for periodic grids.
599 //
600  const Integer* I1() const { return rcData->I1; }
601  const Integer* I2() const { return rcData->I2; }
602  const Integer* I3() const { return rcData->I3; }
603 //
604 // Public member functions for setting data.
605 //
606  void setNumberOfDimensions(const Integer& numberOfDimensions_);
607 
608  void setBoundaryCondition(const Integer& ks,
609  const Integer& kd,
610  const Integer& boundaryCondition_);
611 
612  void setBoundaryFlag( int side, int axis, MappedGridData::BoundaryFlagEnum bc );
613 
615  const Integer& kd,
616  const Integer& boundaryDiscretizationWidth_);
617  void setIsCellCentered(const Integer& kd,
618  const Logical& isCellCentered_);
619  void setDiscretizationWidth(const Integer& kd,
620  const Integer& discretizationWidth_);
621  void setGridIndexRange(const Integer& ks,
622  const Integer& kd,
623  const Integer& gridIndexRange_);
624 
625  // Use a given mapping.
626  void setMapping(Mapping& x);
627  void setMapping(MappingRC& x);
628 
629  // On Parallel machines always add at least this many ghost lines on local arrays
630  static void setMinimumNumberOfDistributedGhostLines( int numGhost );
632 
633  void setNumberOfGhostPoints(const Integer& ks,
634  const Integer& kd,
635  const Integer& numberOfGhostPoints_);
636 
637  void setUseGhostPoints(const Logical& useGhostPoints_);
638 
639  void setIsPeriodic(const Integer& kd, const Mapping::periodicType& isPeriodic_);
640 
641  void setSharedBoundaryFlag(const Integer& ks,
642  const Integer& kd,
643  const Integer& sharedBoundaryFlag_);
644  void setSharedBoundaryTolerance(const Integer& ks,
645  const Integer& kd,
646  const Real& sharedBoundaryTolerance_);
647 //
648 // Discretization point mask.
649 //
651  { return *rcData->mask; }
652  inline const IntegerMappedGridFunction& mask() const
653  { return ((MappedGrid*)this)->mask(); }
654 //
655 // Inverse derivative of the mapping at the vertices.
656 //
658  { return *rcData->inverseVertexDerivative; }
660  { return ((MappedGrid*)this)->inverseVertexDerivative(); }
661 // //
662 // // Inverse derivative at the vertices, for a two-dimensional grid.
663 // //
664 // inline RealMappedGridFunction& inverseVertexDerivative2D()
665 // { return *rcData->inverseVertexDerivative2D; }
666 // inline const RealMappedGridFunction& inverseVertexDerivative2D() const
667 // { return ((MappedGrid*)this)->inverseVertexDerivative2D(); }
668 // //
669 // // Inverse derivative at the vertices, for a one-dimensional grid.
670 // //
671 // inline RealMappedGridFunction& inverseVertexDerivative1D()
672 // { return *rcData->inverseVertexDerivative1D; }
673 // inline const RealMappedGridFunction& inverseVertexDerivative1D() const
674 // { return ((MappedGrid*)this)->inverseVertexDerivative1D(); }
675 //
676 // Inverse derivative at the discretization centers.
677 //
679  { return *rcData->inverseCenterDerivative; }
681  { return ((MappedGrid*)this)->inverseCenterDerivative(); }
682 // //
683 // // Inverse derivative at the discretization centers, for a two-dimensional grid
684 // //
685 // inline RealMappedGridFunction& inverseCenterDerivative2D()
686 // { return *rcData->inverseCenterDerivative2D; }
687 // inline const RealMappedGridFunction& inverseCenterDerivative2D() const
688 // { return ((MappedGrid*)this)->inverseCenterDerivative2D(); }
689 // //
690 // // Inverse derivative at the discretization centers, for a one-dimensional grid
691 // //
692 // inline RealMappedGridFunction& inverseCenterDerivative1D()
693 // { return *rcData->inverseCenterDerivative1D; }
694 // inline const RealMappedGridFunction& inverseCenterDerivative1D() const
695 // { return ((MappedGrid*)this)->inverseCenterDerivative1D(); }
696 //
697 // Vertex coordinates.
698 //
700  { return *rcData->vertex; }
701  inline const RealMappedGridFunction& vertex() const
702  { return ((MappedGrid*)this)->vertex(); }
703 // //
704 // // Vertex coordinates, for a two-dimensional grid.
705 // //
706 // inline RealMappedGridFunction& vertex2D()
707 // { return *rcData->vertex2D; }
708 // inline const RealMappedGridFunction& vertex2D() const
709 // { return ((MappedGrid*)this)->vertex2D(); }
710 // //
711 // // Vertex coordinates, for a one-dimensional grid.
712 // //
713 // inline RealMappedGridFunction& vertex1D()
714 // { return *rcData->vertex1D; }
715 // inline const RealMappedGridFunction& vertex1D() const
716 // { return ((MappedGrid*)this)->vertex1D(); }
717 //
718 // Coordinates of discretization centers.
719 //
721  { return *rcData->center; }
722  inline const RealMappedGridFunction& center() const
723  { return ((MappedGrid*)this)->center(); }
724 // //
725 // // Coordinates of discretization centers, for a two-dimensional grid.
726 // //
727 // inline RealMappedGridFunction& center2D()
728 // { return *rcData->center2D; }
729 // inline const RealMappedGridFunction& center2D() const
730 // { return ((MappedGrid*)this)->center2D(); }
731 // //
732 // // Coordinates of discretization centers, for a one-dimensional grid.
733 // //
734 // inline RealMappedGridFunction& center1D()
735 // { return *rcData->center1D; }
736 // inline const RealMappedGridFunction& center1D() const
737 // { return ((MappedGrid*)this)->center1D(); }
738 //
739 // Coordinates of control volume corners.
740 //
742  { return *rcData->corner; }
743  inline const RealMappedGridFunction& corner() const
744  { return ((MappedGrid*)this)->corner(); }
745 // //
746 // // Coordinates of control volume corners, for a two-dimensional grid.
747 // //
748 // inline RealMappedGridFunction& corner2D()
749 // { return *rcData->corner2D; }
750 // inline const RealMappedGridFunction& corner2D() const
751 // { return ((MappedGrid*)this)->corner2D(); }
752 // //
753 // // Coordinates of control volume corners, for a one-dimensional grid.
754 // //
755 // inline RealMappedGridFunction& corner1D()
756 // { return *rcData->corner1D; }
757 // inline const RealMappedGridFunction& corner1D() const
758 // { return ((MappedGrid*)this)->corner1D(); }
759 //
760 // Derivative of the mapping at the vertices.
761 //
763  { return *rcData->vertexDerivative; }
765  { return ((MappedGrid*)this)->vertexDerivative(); }
766 // //
767 // // Derivative of the mapping at the vertices, for a two-dimensional grid.
768 // //
769 // inline RealMappedGridFunction& vertexDerivative2D()
770 // { return *rcData->vertexDerivative2D; }
771 // inline const RealMappedGridFunction& vertexDerivative2D() const
772 // { return ((MappedGrid*)this)->vertexDerivative2D(); }
773 // //
774 // // Derivative of the mapping at the vertices, for a one-dimensional grid.
775 // //
776 // inline RealMappedGridFunction& vertexDerivative1D()
777 // { return *rcData->vertexDerivative1D; }
778 // inline const RealMappedGridFunction& vertexDerivative1D() const
779 // { return ((MappedGrid*)this)->vertexDerivative1D(); }
780 //
781 // Derivative of the mapping at the discretization centers.
782 //
784  { return *rcData->centerDerivative; }
786  { return ((MappedGrid*)this)->centerDerivative(); }
787 // //
788 // // Derivative at the discretization centers, for a two-dimensional grid.
789 // //
790 // inline RealMappedGridFunction& centerDerivative2D()
791 // { return *rcData->centerDerivative2D; }
792 // inline const RealMappedGridFunction& centerDerivative2D() const
793 // { return ((MappedGrid*)this)->centerDerivative2D(); }
794 // //
795 // // Derivative at the discretization centers, for a one-dimensional grid.
796 // //
797 // inline RealMappedGridFunction& centerDerivative1D()
798 // { return *rcData->centerDerivative1D; }
799 // inline const RealMappedGridFunction& centerDerivative1D() const
800 // { return ((MappedGrid*)this)->centerDerivative1D(); }
801 //
802 // Determinant of vertexDerivative.
803 //
805  { return *rcData->vertexJacobian; }
807  { return ((MappedGrid*)this)->vertexJacobian(); }
808 //
809 // Determinant of centerDerivative.
810 //
812  { return *rcData->centerJacobian; }
814  { return ((MappedGrid*)this)->centerJacobian(); }
815 //
816 // Cell Volume.
817 //
819  { return *rcData->cellVolume; }
820  inline const RealMappedGridFunction& cellVolume() const
821  { return ((MappedGrid*)this)->cellVolume(); }
822 //
823 // Cell-center normal vector, normalized to cell-face area.
824 //
826  { return *rcData->centerNormal; }
827  inline const RealMappedGridFunction& centerNormal() const
828  { return ((MappedGrid*)this)->centerNormal(); }
829 // //
830 // // Cell-center normal vector, for a two-dimensional grid.
831 // //
832 // inline RealMappedGridFunction& centerNormal2D()
833 // { return *rcData->centerNormal2D; }
834 // inline const RealMappedGridFunction& centerNormal2D() const
835 // { return ((MappedGrid*)this)->centerNormal2D(); }
836 // //
837 // // Cell-center normal vector, for a one-dimensional grid.
838 // //
839 // inline RealMappedGridFunction& centerNormal1D()
840 // { return *rcData->centerNormal1D; }
841 // inline const RealMappedGridFunction& centerNormal1D() const
842 // { return ((MappedGrid*)this)->centerNormal1D(); }
843 //
844 // Cell-center area (Length of cell-center normal vector).
845 //
847  { return *rcData->centerArea; }
848  inline const RealMappedGridFunction& centerArea() const
849  { return ((MappedGrid*)this)->centerArea(); }
850 // //
851 // // Cell-center area, for a two-dimensional grid.
852 // //
853 // inline RealMappedGridFunction& centerArea2D()
854 // { return *rcData->centerArea2D; }
855 // inline const RealMappedGridFunction& centerArea2D() const
856 // { return ((MappedGrid*)this)->centerArea2D(); }
857 // //
858 // // Cell-center area, for a one-dimensional grid.
859 // //
860 // inline RealMappedGridFunction& centerArea1D()
861 // { return *rcData->centerArea1D; }
862 // inline const RealMappedGridFunction& centerArea1D() const
863 // { return ((MappedGrid*)this)->centerArea1D(); }
864 //
865 // Cell-face normal vector, normalized to cell-face area.
866 //
868  { return *rcData->faceNormal; }
869  inline const RealMappedGridFunction& faceNormal() const
870  { return ((MappedGrid*)this)->faceNormal(); }
871 // //
872 // // Cell-face normal vector, for a two-dimensional grid.
873 // //
874 // inline RealMappedGridFunction& faceNormal2D()
875 // { return *rcData->faceNormal2D; }
876 // inline const RealMappedGridFunction& faceNormal2D() const
877 // { return ((MappedGrid*)this)->faceNormal2D(); }
878 // //
879 // // Cell-face normal vector, for a one-dimensional grid.
880 // //
881 // inline RealMappedGridFunction& faceNormal1D()
882 // { return *rcData->faceNormal1D; }
883 // inline const RealMappedGridFunction& faceNormal1D() const
884 // { return ((MappedGrid*)this)->faceNormal1D(); }
885 //
886 // Cell-face area.
887 //
889  { return *rcData->faceArea; }
890  inline const RealMappedGridFunction& faceArea() const
891  { return ((MappedGrid*)this)->faceArea(); }
892 // //
893 // // Cell-face area, for a two-dimensional grid.
894 // //
895 // inline RealMappedGridFunction& faceArea2D()
896 // { return *rcData->faceArea2D; }
897 // inline const RealMappedGridFunction& faceArea2D() const
898 // { return ((MappedGrid*)this)->faceArea2D(); }
899 // //
900 // // Cell-face area, for a one-dimensional grid.
901 // //
902 // inline RealMappedGridFunction& faceArea1D()
903 // { return *rcData->faceArea1D; }
904 // inline const RealMappedGridFunction& faceArea1D() const
905 // { return ((MappedGrid*)this)->faceArea1D(); }
906 //
907 // Outward unit normal vectors at the vertices on each boundary.
908 //
910  const Integer& ks,
911  const Integer& kd)
912  { return *rcData->vertexBoundaryNormal[kd][ks]; }
914  const Integer& ks,
915  const Integer& kd) const
916  { return ((MappedGrid*)this)->vertexBoundaryNormal(ks,kd); }
917 
918  // Here is the new way: use serialArrays (for parallel)
920  { assert(rcData->pVertexBoundaryNormal[kd][ks]!=NULL); return *rcData->pVertexBoundaryNormal[kd][ks]; }
921  inline const realSerialArray& vertexBoundaryNormalArray(const Integer& ks,const Integer& kd) const
922  { assert(rcData->pVertexBoundaryNormal[kd][ks]!=NULL); return *rcData->pVertexBoundaryNormal[kd][ks]; }
923 //
924 // Outward unit normal vectors at the centers on each boundary.
925 //
927  const Integer& ks,
928  const Integer& kd)
929  { return *rcData->centerBoundaryNormal[kd][ks]; }
931  const Integer& ks,
932  const Integer& kd) const
933  { return ((MappedGrid*)this)->centerBoundaryNormal(ks,kd); }
934 
935  // Here is the new way: use serialArrays (for parallel)
937  { assert(rcData->pCenterBoundaryNormal[kd][ks]!=NULL); return *rcData->pCenterBoundaryNormal[kd][ks]; }
938  inline const realSerialArray& centerBoundaryNormalArray(const Integer& ks,const Integer& kd) const
939  { assert(rcData->pCenterBoundaryNormal[kd][ks]!=NULL); return *rcData->pCenterBoundaryNormal[kd][ks]; }
940 //
941 // Unit tangent vectors at the centers on each boundary.
942 //
944  const Integer& ks,
945  const Integer& kd)
946  { return *rcData->centerBoundaryTangent[kd][ks]; }
948  const Integer& ks,
949  const Integer& kd) const
950  { return ((MappedGrid*)this)->centerBoundaryTangent(ks,kd); }
951 
952  // Here is the new way: use serialArrays (for parallel)
954  { assert(rcData->pCenterBoundaryTangent[kd][ks]!=NULL); return *rcData->pCenterBoundaryTangent[kd][ks]; }
955  inline const realSerialArray& centerBoundaryTangentArray(const Integer& ks,const Integer& kd) const
956  { assert(rcData->pCenterBoundaryTangent[kd][ks]!=NULL); return *rcData->pCenterBoundaryTangent[kd][ks]; }
957 //
958 // Grid mapping.
959 //
960  inline MappingRC& mapping() { return rcData->mapping; }
961  inline const MappingRC& mapping() const { return rcData->mapping; }
962 
963 //
964 // cached unstructured boundary condition info
965 //
966  inline const IntegerArray *getUnstructuredBCInfo( int type )
967  { return rcData->getUnstructuredBCInfo( type ); }
968 
969 //
970 // cached unstructured periodic boundary info
971 //
972  inline const IntegerArray *getUnstructuredPeriodicBC( int type )
973  { return rcData->getUnstructuredPeriodicBC( type ); }
974 
975 //
976 // Public member functions.
977 //
978 // Default constructor.
979 //
980 // If numberOfDimensions_==0 (e.g., by default) then create a null
981 // MappedGrid. Otherwise, create a MappedGrid with the given
982 // number of dimensions.
983 //
984  MappedGrid(const Integer numberOfDimensions_ = 0);
985 
986  // initialize a NULL MappedGrid
987  void init(int numberOfDimensions_);
988 
989 //
990 // Copy constructor. (Does a deep copy by default.)
991 //
992  MappedGrid(
993  const MappedGrid& x,
994  const CopyType ct = DEEP);
995 //
996 // Constructor from a mapping.
997 //
1000 //
1001 // Destructor.
1002 //
1003  virtual ~MappedGrid();
1004 //
1005 // Assignment operator. (Does a deep copy.)
1006 //
1007  MappedGrid& operator=(const MappedGrid& x);
1008 
1009  MappedGrid& equals(const MappedGrid& x, int option=0); // equals operator with options
1010 
1011 //
1012 // Make a reference. (Does a shallow copy.)
1013 //
1014  void reference(const MappedGrid& x);
1015  void reference(MappedGridData& x);
1016 //
1017 // Use a given mapping.
1018 //
1019  void reference(Mapping& x, bool forceIncompatible=false ); //kkc 050120 for updating the grid when the mapping has changed
1020  void reference(MappingRC& x);
1021 //
1022 // Break a reference. (Replaces with a deep copy.)
1023 //
1024  virtual void breakReference();
1025 //
1026 // Change the grid to be all vertex-centered.
1027 //
1028  virtual void changeToAllVertexCentered();
1029 //
1030 // Change the grid to be all cell-centered.
1031 //
1032  virtual void changeToAllCellCentered();
1033 //
1034 // Check that the data structure is self-consistent.
1035 //
1036  virtual void consistencyCheck() const;
1037 //
1038 // "Get" and "put" database operations.
1039 //
1040  virtual Integer get(const GenericDataBase& db,
1041  const aString& name,
1042  bool getMapping=true ); // for AMR grids we may not get the mapping.
1043 
1044  virtual Integer put(GenericDataBase& db,
1045  const aString& name,
1046  bool putMapping = true, // for AMR grids we may not save the mapping.
1047  int geometryToPut = -1 // by default put computedGeometry
1048  ) const;
1049 //
1050 // Set references to reference-counted data.
1051 //
1052  void updateReferences(const Integer what = EVERYTHING);
1053 //
1054 // Update the grid.
1055 //
1056  inline Integer update(
1057  const Integer what = THEusualSuspects,
1058  const Integer how = COMPUTEtheUsual)
1059  { return update(*this, what, how); }
1060 //
1061 // Update the grid, sharing the data of another grid.
1062 //
1063  inline Integer update(
1064  MappedGrid& x,
1065  const Integer what = THEusualSuspects,
1066  const Integer how = COMPUTEtheUsual)
1067  { return update((GenericGrid&)x, what, how); }
1068 //
1069 // Destroy optional grid data.
1070 //
1071  virtual void destroy(const Integer what = NOTHING);
1072 #ifdef ADJUST_FOR_PERIODICITY
1073 //
1074 // Adjust the inverted coordinates for periodicity.
1075 //
1076  void adjustForPeriodicity(
1077  const RealArray& r,
1078  const LogicalArray& whereMask);
1079 #endif // ADJUST_FOR_PERIODICITY
1080 //
1081 // Adjust the inverted coordinates of boundary points
1082 // in cases where the points lie on a shared boundary.
1083 //
1084  void adjustBoundary(
1085  MappedGrid& g2,
1086  const Integer& ks1,
1087  const Integer& kd1,
1088  const RealArray& r2,
1089  const LogicalArray& whereMask);
1090 //
1091 // Compute the condition number of the mapping inverse.
1092 //
1093 // The condition number is the max norm (max absolute row sum) of the matrix
1094 //
1095 // [ 1/dr2 0 ] [ rx2 ry2 ] [ xr1 xs1 ] [ dr1 0 ]
1096 // [ 0 1/ds2 ] [ sx2 sy2 ] [ yr1 ys1 ] [ 0 ds1 ]
1097 //
1098  void getInverseCondition(
1099  MappedGrid& g2,
1100  const RealArray& xr1,
1101  const RealArray& rx2,
1102  const RealArray& condition,
1103  const LogicalArray& whereMask);
1104 //
1105 // Specify the set of processes over which MappedGridFunctions are distributed.
1106 // We now support only the specification of a contiguous range of process IDs.
1107 //
1108  virtual void specifyProcesses(const Range& range);
1109 //
1110 // Initialize the MappedGrid with the given number of dimensions.
1111 //
1112  virtual void initialize(
1113  const Integer& numberOfDimensions_);
1114 //
1115 // Pointer to reference-counted data.
1116 //
1119  inline MappedGridData* operator->() { return rcData; }
1120  inline const MappedGridData* operator->() const { return rcData; }
1121  inline MappedGridData& operator*() { return *rcData; }
1122  inline const MappedGridData& operator*() const { return *rcData; }
1123 
1124  private:
1125  virtual Integer update(
1126  GenericGrid& x,
1127  const Integer what = THEusualSuspects,
1128  const Integer how = COMPUTEtheUsual);
1129 
1130  // protected:
1131  public: // The next variable is needed by MappedGridData:
1132 
1133  // On Parallel machines always add at least this many ghost lines on local arrays
1135 
1136  protected:
1137 //
1138 // The following functions are declared protected here in order to disallow
1139 // access to the corresponding functions in class GenericGrid.
1140 //
1141  inline virtual void initialize() {
1142  cerr << "virtual void MappedGrid::initialize() must not be called!"
1143  << "It must have been called illegally through the base class GenericGridCollection."
1144  << endl;
1145  abort();
1146  }
1147 
1148 //
1149 // Virtual member functions used only through class ReferenceCounting:
1150 //
1151  private:
1152  inline virtual ReferenceCounting& operator=(const ReferenceCounting& x)
1153  { return operator=((MappedGrid&)x); }
1154  inline virtual void reference(const ReferenceCounting& x)
1155  { reference((MappedGrid&)x); }
1156  inline virtual ReferenceCounting* virtualConstructor(
1157  const CopyType ct = DEEP) const
1158  { return new MappedGrid(*this, ct); }
1159  aString className;
1160  public:
1161  inline virtual aString getClassName() const { return className; }
1163 };
1164 //
1165 // Stream output operator.
1166 //
1167 ostream& operator<<(ostream& s, const MappedGrid& g);
1168 
1169 #endif // _MappedGrid