CG  Version 25
amrMacros.h
Go to the documentation of this file.
1 // ======================================================================================================
2 // This macro will update the grids and grid functions when using AMR
3 // ======================================================================================================
4 #beginMacro updateForAdaptiveGridsMacro()
5 // --- Start AMR ---
6 
7 const int regridFrequency = parameters.dbase.get<int >("amrRegridFrequency")>0 ?
8  parameters.dbase.get<int >("amrRegridFrequency") :
9  parameters.dbase.get<Regrid* >("regrid")==NULL ? 2 :
10  parameters.dbase.get<Regrid* >("regrid")->getRefinementRatio();
11 
12 if( parameters.isAdaptiveGridProblem() && ((globalStepNumber % regridFrequency) == 0) )
13 {
14  // ****************************************************************************
15  // ****************** Adaptive Grid Step *************************************
16  // ****************************************************************************
17 
18  if( debug & 2 )
19  {
20  printP("***** advance: AMR regrid at step %i t=%e dt=%8.2e***** \n",globalStepNumber,t,dt);
21  fPrintF(debugFile,"***** advance: AMR regrid at step %i t=%e dt=%8.2e***** \n",globalStepNumber,t,dt);
22  }
23 
24  real timea=getCPU();
25 
26  if( debug & 4 )
27  fPrintF(debugFile,"\n ***** advance: AMR regrid at step %i ***** \n\n",globalStepNumber);
28 
29 
30  if( debug & 8 )
31  {
32  if( parameters.dbase.get<bool >("twilightZoneFlow") )
33  {
34  getErrors( current,t,dt,sPrintF(" advance: errors before regrid, t=%e \n",t) );
35  }
36  else
37  {
38  fPrintF(debugFile," ***advance: before regrid: solution ***\n");
39  outputSolution( gf[current].u,t );
40  }
41  }
42 
43 
44  int numberToUpdate=0; // we need to update ub to live on the new grid, and interpolate values.
45  if( ((SmParameters&)parameters).isSecondOrderSystem() )
46  {
47  numberToUpdate=1; // also update and interpolate prev solution to the new grid
48  }
49 
50  adaptGrids( gf[current], numberToUpdate,&(gf[prev].u), NULL ); // last arg is for work-space **fix me **
51 
52  // *wdh* do this: 090315
53  cg.reference(gf[current].cg);
54  gf[prev].cg.reference(gf[current].cg);
55  gf[next].cg.reference(gf[current].cg);
56  gf[next].u.updateToMatchGrid(cg);
57 
58  // printF(" After adaptGrids: prev=%i, current=%i, next=%i\n",prev,current,next);
59  for( int n=0; n<numberOfTimeLevels; n++ )
60  {
61  if( n!=current )
62  {
63  gf[n].cg.reference(gf[current].cg); //
64  if( n!=prev ) // this was already done for prev in adaptGrids
65  gf[n].u.updateToMatchGrid(gf[current].cg);
66  }
67 
68  gf[n].u.setOperators(*cgop);
69  // printF(" After adaptGrids: gf[%i].cg.numberOfComponentGrids = %i\n",n,gf[n].cg.numberOfComponentGrids());
70  // printF(" After adaptGrids: gf[%i].u.getCompositeGrid()->numberOfComponentGrids = %i\n",n,gf[n].u.getCompositeGrid()->numberOfComponentGrids());
71  }
72 
73  // ** do this for now ** fix me **
74  if( checkErrors )
75  {
76  assert( cgerrp!=NULL );
77  (*cgerrp).updateToMatchGrid(cg);
78  }
79 
80 
81  // the next has been moved into adaptGrids 070706
82  // real time1=getCPU();
83  // cgf1.cg.rcData->interpolant->updateToMatchGrid( cgf1.cg );
84  // parameters.dbase.get<RealArray>("timing")(parameters.dbase.get<int>("timeForUpdateInterpolant"))+=getCPU()-time1;
85  real time1=getCPU();
86 
87  if( debug & 8 )
88  {
89  outputSolution( gf[current].u,t,
90  sPrintF(" advance:after adaptGrids, before interpAndApplyBC at t=%11.4e \n",t) );
91  }
92 
93  interpolateAndApplyBoundaryConditions( gf[current] );
94 
95  // *wdh* 090829
96  if( numberToUpdate==1 )
97  {
98  interpolateAndApplyBoundaryConditions( gf[prev] );
99  }
100 
101 
102  parameters.dbase.get<RealArray>("timing")(parameters.dbase.get<int>("timeForAmrBoundaryConditions"))+=getCPU()-time1;
103 
104  if( debug & 4 )
105  {
106  if( parameters.dbase.get<bool >("twilightZoneFlow") )
107  {
108  getErrors( prev ,t-dt,dt,sPrintF(" advance: errors in prev after regrid, t=%e \n",t-dt) );
109  getErrors( current,t ,dt,sPrintF(" advance: errors in current after regrid, t=%e \n",t) );
110  }
111  else
112  {
113  fPrintF(debugFile," ***after regrid: solution ***\n");
114  outputSolution( gf[current].u,t );
115  }
116  }
117 
118 
119  parameters.dbase.get<RealArray>("timing")(parameters.dbase.get<int>("timeForAmrRegrid"))+=getCPU()-timea;
120 }
121 
122 
123 
124 // --- End AMR ---
125 #endMacro