Overture  Version 25
Ogen.h
Go to the documentation of this file.
1 #ifndef OGEN_H
2 #define OGEN_H "ogen.h"
3 
4 #include "Overture.h"
5 //#include "PlotStuff.h"
7 #include "MappingInformation.h"
8 
9 int
10 checkOverlappingGrid( const CompositeGrid & cg, const int & option=0, bool onlyCheckBaseGrids=true );
11 
12 // forward class declarations:
14 
15 class Ogen
16 {
17  public:
19  {
23  };
24 
26  {
33  };
34 
35 
36  Ogen();
38  ~Ogen();
39 
41  MappingInformation & mapInfo,
42  const IntegerArray & mapList,
43  const int & numberOfMultigridLevels =1,
44  const bool useAnOldGrid=FALSE );
45 
46  static bool canDiscretize( MappedGrid & g, const int iv[3], bool checkOneSidedAtBoundaries=true );
47 
48  // interactively change parameters
50 
51  // Check that there are enough parallel ghost lines for ogen:
52  static int checkParallelGhostWidth( CompositeGrid & cg );
53 
54  // check the results from updateRefinement
55  static int checkUpdateRefinement( GridCollection & gc );
56 
57  static int displayCompositeGridParameters( CompositeGrid & cg, FILE *file=stdout );
58 
59  // output a list of orphan points
61 
62  static int saveGridToAFile(CompositeGrid & cg, aString & gridFileName, aString & gridName ) ;
63 
64  // set the values of some selected parameters
65  void set(const OgenParameterEnum option, const bool value);
66  void set(const OgenParameterEnum option, const int value);
67  void set(const OgenParameterEnum option, const real value);
68 
71 
72  // build a composite grid interactively from scratch
73  int updateOverlap( CompositeGrid & cg, MappingInformation & mapInfo );
74 
75  // build a composite grid non-interactively using the component grids found
76  // in cg. This function might be called if one or more grids have changed.
77  int updateOverlap( CompositeGrid & cg );
78 
79  // build a composite grid when some grids have moved, tryng to use optimized algorithms.
80  int updateOverlap(CompositeGrid & cg,
81  CompositeGrid & cgNew,
82  const LogicalArray & hasMoved,
83  const MovingGridOption & option =useOptimalAlgorithm );
84 
85  // update refinement level(s) on a composite grid.
87  const int & refinementLevel=-1 );
88 
89  // new parallel version
91  const int & refinementLevel=-1 );
92 
93  // newer parallel version
95  const int & refinementLevel=-1 );
96 
98 
100 
101 
102  protected:
103 
104  int buildBounds( CompositeGrid & cg );
105 
107 
108 
109  int chooseASide( MappedGrid & mg, int & side, int & axis );
110 
111  bool interpolateAPoint(CompositeGrid & cg, int grid, int iv[3], bool interpolatePoint,
112  bool checkInterpolationCoords, bool checkBoundaryPoint, int infoLevel );
113 
114  int interpolatePoints(CompositeGrid & cg, int grid, int numberToInterpolate, const IntegerArray & ia,
115  IntegerArray & interpolates );
116 
117  int interpolateMixedBoundary(CompositeGrid & cg, int mixedBoundaryNumber );
118 
119  int interpolateMixedBoundary(CompositeGrid & cg, int mixedBoundaryNumber,
120  int side, int axis, int grid, MappedGrid & g, int grid2, MappedGrid & g2,
121  int offset[3], real rScale[3],real rOffset[3]);
122 
124 
125  int classifyPoints(CompositeGrid & cg,
126  realSerialArray & invalidPoint,
127  int & numberOfInvalidPoints,
128  const int & level,
129  CompositeGrid & cg0 );
130 
131  int classifyRedundantPoints( CompositeGrid& cg, const int & grid,
132  const int & level,
133  CompositeGrid & cg0 );
134 
135  int computeOverlap( CompositeGrid & cg,
136  CompositeGrid & cgOld,
137  const int & level=0,
138  const bool & movingGrids =FALSE,
139  const IntegerArray & hasMoved = Overture::nullIntArray() );
140 
142 
143  // older version:
144  int cutHoles(CompositeGrid & cg );
145 
146  // current default version:
147  int cutHolesNew(CompositeGrid & cg );
148 
149  // new parallel version
150  int cutHolesNewer(CompositeGrid & cg );
151 
152  // explicit hole cutting:
154 
155  int getHoleWidth( CompositeGrid & cg,
156  MappedGrid & g2,
157  int pHoleMarker[3],
158  IntegerArray & holeCenter,
159  IntegerArray & holeMask,
160  IntegerArray & holeWidth,
161  RealArray & r,
162  RealArray & x,
163  const int *pIndexRange2,
164  const int *pExtendedIndexRange2,
165  const int *plocalIndexBounds2,
166  int iv[3], int jv[3], int jpv[3],
167  bool isPeriodic2[3], bool isPeriodic2p[3],
168  const Index Iv[3],
169  const int &grid, const int &grid2,
170  int &ib, int &ib2,
171  int & skipThisPoint,
172  int & initialPoint,
173  const int & numberOfDimensions,
174  const int & axisp1, const int & axisp2, const real & cellCenterOffset,
175  const int & maximumHoleWidth, int & numberOfHoleWidthWarnings );
176 
178  const realArray & x,
179  IntegerArray & crossings );
180 
182 
183  int interpolateAll(CompositeGrid & cg, IntegerArray & numberOfInterpolationPoints, CompositeGrid & cg0);
184 
185  bool isNeededForDiscretization(MappedGrid& g, const int iv[3] );
186  bool isOnInterpolationBoundary(MappedGrid& g, const int iv[3], const int & width=1 );
188  const int & grid,
189  const int & l,
190  const int iv[3]);
191  real computeInterpolationQuality(CompositeGrid & cg, const int & grid,
192  const int & i1, const int & i2, const int & i3,
193  real & qForward, real & qReverse );
194 
195  int markMaskAtGhost( CompositeGrid & cg );
196 
197  int markPointsNeededForInterpolation( CompositeGrid & cg, const int & grid, const int & lowerOrUpper=-1 );
198 
199  // parallel version:
200  int markPointsNeededForInterpolationNew( CompositeGrid & cg, const int & grid, const int & lowerOrUpper=-1 );
201 
203 
204 // int markPartiallyPeriodicBoundaries( CompositeGrid & cg,
205 // intArray *iInterp );
206 
207  int improveQuality( CompositeGrid & cg, const int & grid, RealArray & removedPointBound );
208  int updateCanInterpolate( CompositeGrid & cg, CompositeGrid & cg0, RealArray & removedPointBound );
209 
210  int plot(const aString & title,
211  CompositeGrid & cg,
212  const int & queryForChanges =TRUE );
213 
214  // new:
215  int projectToParameterBoundary( const real rv0[3], const real rv1[3], real rv[3],
216  const int numberOfDimensions, const int grid );
217 
219  const int & grid,
220  const realArray & r,
221  const int iv[3],
222  const int ivp[3],
223  real rv[3] );
224 
225  int queryAPoint(CompositeGrid & cg);
226 
227  // int projectGhostPoints(CompositeGrid & cg);
228 
230  const bool boundariesHaveCutHoles= FALSE );
231 
233  const bool boundariesHaveCutHoles= FALSE );
234 
236 
237  int unmarkBoundaryInterpolationPoints( CompositeGrid & cg, const int & grid );
238 
239  int unmarkInterpolationPoints( CompositeGrid & cg, const bool & unMarkAll=FALSE );
240 
241  int updateGeometry(CompositeGrid & cg,
242  CompositeGrid & cgOld,
243  const bool & movingGrids=FALSE,
244  const IntegerArray & hasMoved = Overture::nullIntArray() );
245 
246  public:
247  int debug; // for turning on debug info and extra plotting
248  int info; // bit flag for turning on info messages
252  int myid; // processor number
254  bool loadBalanceGrids; // load balance cg when it is created
255  bool doubleCheckInterpolation; // double check interpolation in checkOverlappingGrid
256 
257  protected:
258  // repeat some enumerators to simplify
259  enum
260  {
263  resetTheGrid=123456789,
265  };
266 
271 
272  bool outputGridOnFailure; // save the grid in a file if the algorithm fails
274 
275  FILE *logFile,*plogFile; // log file to save info for users (plogFile = log file for a given processor)
276  FILE *checkFile; // contains data on the grid that we can use to check when we change the code.
277 
278  real boundaryEps; // We can still interpolate from a grid provided we are this close (in r)
279  RealArray gridScale; // gridScale(grid) = maximum length of the bounding box for a grid
280  RealArray rBound; // rBound(0:1,.) : bounds on r for valid interpolation
282 
284 
285  IntegerArray geometryNeedsUpdating; // true if the geometry needs to be updated after changes in parameters
286  bool numberOfGridsHasChanged; // true if we need to update stuff that depends on the number of grids
288  IntegerArray isNew; // this grid is in the list of new grids (for the incremental algorithm)
289 
292  IntegerArray plotHolePoints; // plotHolePoints(grid) : 0 = no, 1=colour black, 2=colour by grid
293 
297 
298  int maximumNumberOfPointsToInvertAtOneTime; // limit the number of pts we invert at a time to save memory
299 
300  int maskRatio[3]; // for multigrid: ratio of coarse to fine grid spacing for ray tracing
301 
302  int holeCuttingOption; // 0=old way, 1=new way
304 
305  int numberOfArrays; // to check for memory leaks, track of how many arrays we have.
306 
307  // warnForSharedSides : TRUE if we have warned about possible shared sides not being marked properly
308  IntegerArray warnForSharedSides; // warnForSharedSides(grid,side+2*axis,grid2,side2+2*dir)
309 
310  // for mixed physical-interpolation boundaries
314 
315  // for manual hole cutting
319 
320  // For explicit hole cutters
323 
324  // for manual shared sides
328 
329  // For over-riding the default shared boundary tolerances
333 
334 
335  // For specifying non-cutting boundary points (to prevent a portion of a boundary from cutting holes)
338 
339 
340  intSerialArray *backupValues; // holds info on backup values.
341  IntegerArray backupValuesUsed; // backupValuesUsed(grid) = TRUE is some backup values have been used
342 
343  IntegerArray preInterpolate; // for grids that pre-interpolate
344 
345  MappingInformation cutMapInfo; // put here temporarily. Holds curves that cut holes.
349  bool minimizeTheOverlap; // *** this should be in the CompositeGrid
353  int incrementalHoleSweep; // if >0 holds the number of sweeps.
354  bool useLocalBoundingBoxes; // new parallel option
355 
356  char buff[200];
357 
358  real totalTime; // total CPU time used to generate the grid
371 
372  int adjustBoundary(CompositeGrid & cg,
373  const Integer& k1,
374  const Integer& k2,
375  const intSerialArray& i1,
376  const realSerialArray& x);
378  const Integer& k1,
379  const Integer& k2,
380  const intSerialArray& i1,
381  const realSerialArray& x);
382  int oppositeBoundaryIndex(MappedGrid & g, const int & ks, const int & kd );
383 #ifdef USE_PPP
384  int adjustBoundary(CompositeGrid & cg,
385  const Integer& k1,
386  const Integer& k2,
387  const intArray& i1,
388  const realArray& x);
389 #endif
390 
392  IntegerArray & numberOfInterpolationPoints,
393  intSerialArray *iInterp );
394 
396  const int grid,
397  const int grid2,
398  IntegerArray & sidesShare,
399  const int ks1, const int kd1, const int ks2, const int kd2,
400  BoundaryAdjustment & bA , bool & first, bool & needAdjustment,
401  int numberOfDirectionsAdjusted, bool & directionAdjusted, bool & wasAdjusted,
402  Range & R, IntegerArray & ia, IntegerArray & ok,
403  const int it, real shareTol[3][2],
404  RealArray & r, RealArray & r2, RealArray & r3, RealArray & rOk,
405  RealArray & xx, RealArray & x2, RealArray & x3 );
406 
408  const int grid,
409  const int grid2,
410  const int ks1, const int kd1,
411  BoundaryAdjustment & bA ,
412  int numberOfDirectionsAdjusted,
413  Range & R, IntegerArray & ia, IntegerArray & ok,
414  RealArray & r, RealArray & r2, RealArray & r3, RealArray & rOk,
415  RealArray & xx, RealArray & x2, RealArray & x3);
416 
417  int checkForBoundaryAdjustments(CompositeGrid & cg, int k1, int k2, IntegerArray & sidesShare,
418  bool & needAdjustment, int manualSharedBoundaryNumber[2][3] );
419 
421  int grid, int grid2, bool & needAdjustment, int numberOfPoints,
422  int it, int ks1, int kd1, int ks2, int kd2, Index Iv[3], RealArray & x1 );
423 
424 public:
425  static int checkCanInterpolate(CompositeGrid & cg ,
426  int grid, int donor, int numberToCheck,
427  RealArray & r, IntegerArray & interpolates,
428  IntegerArray & useBackupRules );
429 
430  static int checkCanInterpolate(CompositeGrid & cg ,
431  int grid, int donor, RealArray & r, IntegerArray & interpolates,
432  IntegerArray & useBackupRules );
433 
434 protected:
435  bool canInterpolate(CompositeGrid & cg,
436  const Integer& k10,
437  const Integer& k20,
438  const RealArray& r,
439  const LogicalArray& ok,
440  const LogicalArray& useBackupRules,
441  const Logical checkForOneSided);
442 
443  int checkCrossings(CompositeGrid & cg,
444  const int & numToCheck,
445  const IntegerArray & ia,
446  intArray & mask,
447  realArray & x,
448  realArray & vertex,
449  IntegerArray & crossings,
450  const Range & Rx,
451  const int & usedPoint );
452 
454 
456  const int & grid,
457  const int & gridI,
458  const real r[3],
459  int stencil[3][2],
460  bool useOneSidedAtBoundaries = true,
461  bool useOddInterpolationWidth = false );
462 
463  int conformToCmpgrd( CompositeGrid & cg );
464 
466 
468 
469  int findBestGuess(CompositeGrid & cg,
470  const int & grid,
471  const int & numberToCheck,
472  intSerialArray & ia,
473  realSerialArray & x,
474  realSerialArray & r,
475  realSerialArray & rI,
476  intSerialArray & inverseGrid,
477  const realSerialArray & center );
478 
479  int findClosestBoundaryPoint( MappedGrid & mg, real *x, int *iv, int *ivb, int & sideb, int & axisb );
480 
482  const IntegerArray & numberOfInterpolationPoints,
483  intSerialArray *iInterp );
484 
485  int initialize();
486 
488  CompositeGrid & cg0,
489  const int & grid,
490  const IntegerArray & ia,
491  const IntegerArray & ok,
492  intSerialArray & interpolates,
493  int & numberOfInvalidPoints,
494  realSerialArray & invalidPoint,
495  const int & printDiagnosticMessages = false,
496  const bool & tryBackupRules = false,
497  const bool saveInvalidPoints = true,
498  int lastChanceOption = 0 );
499 
500  int movingUpdate(CompositeGrid & cg,
501  CompositeGrid & cgOld,
502  const LogicalArray & hasMoved,
503  const MovingGridOption & option =useOptimalAlgorithm );
504 
505  int movingUpdateNew(CompositeGrid & cg,
506  CompositeGrid & cgOld,
507  const LogicalArray & hasMoved,
508  const MovingGridOption & option =useOptimalAlgorithm );
509 
511 
512 public:
513  int resetGrid( CompositeGrid & cg );
514 
515 protected:
516  int setGridParameters(CompositeGrid & cg );
517 
518  inline bool sidesShareBoundary( CompositeGrid & cg, int grid1, int side1, int dir1, int grid2, int side2, int dir2 ) const;
519 
520  void getSharedBoundaryTolerances( CompositeGrid & cg, int grid1, int side1, int dir1, int grid2, int side2, int dir2,
521  real & rTol, real & xTol, real & nTol ) const;
522 
524  const int & grid,
525  const int & grid2,
526  intSerialArray *iag,
527  realSerialArray *rg,
528  realSerialArray *xg,
529  IntegerArray & sidesShare );
530 
531  public:
532  int updateParameters(CompositeGrid & cg, const int level = -1,
533  const RealArray & minimumOverlap = Overture::nullRealArray() );
534  protected:
535  // int updateMaskPeriodicity(MappedGrid & c, const int & i1, const int & i2, const int & i3 );
536  int getNormal(const int & numberOfDimensions, const int & side, const int & axis,
537  const RealArray & xr, real signForJacobian, RealArray & normal);
538 
539 // int markOffAxisRefinementMask( int numberOfDimensions, Range Ivr[3], Range Ivb[3], int rf[3],
540 // intArray & mask, const intArray & maskb );
541 
542 // int setRefinementMaskFace(intArray & mask,
543 // int side, int axis,
544 // int numberOfDimensions, int rf[3],
545 // Range & I1r, Range & I2r, Range & I3r,
546 // const intArray & mask00,
547 // const intArray & mask10,
548 // const intArray & mask01,
549 // const intArray & mask11);
550 
551  int markOffAxisRefinementMask( int numberOfDimensions, Index Ivr[3], Index Ivb[3], int rf[3],
552  intSerialArray & mask, const intSerialArray & maskb );
553 
554  int setRefinementMaskFace(intSerialArray & mask,
555  int side, int axis,
556  int numberOfDimensions, int rf[3],
557  Index & I1r, Index & I2r, Index & I3r,
558  const intSerialArray & mask00,
559  const intSerialArray & mask10,
560  const intSerialArray & mask01,
561  const intSerialArray & mask11);
562 
565 
566 };
567 
569 bool Ogen::
570 sidesShareBoundary( CompositeGrid & cg, int grid1, int side1, int dir1, int grid2, int side2, int dir2 ) const
571 {
572  int share1= cg[grid1].sharedBoundaryFlag(side1,dir1);
573  int share2= cg[grid2].sharedBoundaryFlag(side2,dir2);
574 
575  int bc1=cg[grid1].boundaryCondition(side1,dir1);
576  int bc2=cg[grid2].boundaryCondition(side2,dir2);
577  if( share1==share2 && share1!=0 && share2!=0 && bc1>0 && bc2>0 )
578  {
579  return true;
580  }
581  for( int n=0; n<numberOfManualSharedBoundaries; n++ )
582  {
583  if( manualSharedBoundary(n,0)==grid1 && manualSharedBoundary(n,3)==grid2 &&
584  manualSharedBoundary(n,1)==side1 && manualSharedBoundary(n,2)==dir1 &&
585  manualSharedBoundary(n,4)==side2 && manualSharedBoundary(n,5)==dir2 )
586  {
587  return true;
588  }
589  }
590 
591  return false;
592 }
593 
594 
595 #endif
596