CG  Version 25
mx/src/forcing.h
Go to the documentation of this file.
1 // (Ex).t = (1/eps)*[ (Hz).y ]
2 // (Ey).t = (1/eps)*[ -(Hz).x ]
3 // (Hz).t = (1/mu) *[ (Ex).y - (Ey).x ]
4 
5 #define exTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[0]
6 #define eyTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[1]
7 #define hzTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[5]
8 
9 #define extTrue(x,y,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[0]
10 #define eytTrue(x,y,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[1]
11 #define hztTrue(x,y,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)-cc*(t)))*pwc[5]
12 
13 #define exLaplacianTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky))*pwc[0])
14 #define eyLaplacianTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky))*pwc[1])
15 #define hzLaplacianTrue(x,y,t) sin(twoPi*(kx*(x)+ky*(y)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky))*pwc[5])
16 
17 // Here is a plane wave with the shape of a Gaussian
18 // xi = kx*(x)+ky*(y)-cc*(t)
19 // cc= c*sqrt( kx*kx+ky*ky );
20 #define hzGaussianPulse(xi) exp(-betaGaussianPlaneWave*((xi)*(xi)))
21 #define exGaussianPulse(xi) hzGaussianPulse(xi)*(-ky/(eps*cc))
22 #define eyGaussianPulse(xi) hzGaussianPulse(xi)*( kx/(eps*cc))
23 
24 #define hzLaplacianGaussianPulse(xi) ((4.*betaGaussianPlaneWave*betaGaussianPlaneWave*(kx*kx+ky*ky))*xi*xi-\
25  (2.*betaGaussianPlaneWave*(kx*kx+ky*ky)))*exp(-betaGaussianPlaneWave*((xi)*(xi)))
26 #define exLaplacianGaussianPulse(xi) hzLaplacianGaussianPulse(xi,t)*(-ky/(eps*cc))
27 #define eyLaplacianGaussianPulse(xi) hzLaplacianGaussianPulse(xi,t)*( kx/(eps*cc))
28 
29 // 3D
30 //
31 // (Ex).t = (1/eps)*[ (Hz).y - (Hy).z ]
32 // (Ey).t = (1/eps)*[ (Hx).z - (Hz).x ]
33 // (Ez).t = (1/eps)*[ (Hy).x - (Hx).y ]
34 // (Hx).t = (1/mu) *[ (Ey).z - (Ez).y ]
35 // (Hy).t = (1/mu) *[ (Ez).x - (Ex).z ]
36 // (Hz).t = (1/mu) *[ (Ex).y - (Ey).x ]
37 
38 // ****************** finish this -> should `rotate' the 2d solution ****************
39 
40 #define exTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[0]
41 #define eyTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[1]
42 #define ezTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[2]
43 
44 #define extTrue3d(x,y,z,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[0]
45 #define eytTrue3d(x,y,z,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[1]
46 #define eztTrue3d(x,y,z,t) (-twoPi*cc)*cos(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[2]
47 
48 
49 
50 #define hxTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[3]
51 #define hyTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[4]
52 #define hzTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*pwc[5]
53 
54 #define exLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[0])
55 #define eyLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[1])
56 #define ezLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[2])
57 
58 #define hxLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[3])
59 #define hyLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[4])
60 #define hzLaplacianTrue3d(x,y,z,t) sin(twoPi*(kx*(x)+ky*(y)+kz*(z)-cc*(t)))*(-(twoPi*twoPi*(kx*kx+ky*ky+kz*kz))*pwc[5])
61 
62 
63 
64 //==================================================================================================
65 // Evaluate Tom Hagstom's exact solution defined as an integral of Guassian sources
66 //
67 // OPTION: OPTION=solution or OPTION=error OPTION=bounary to compute the solution or the error or
68 // the boundary condition
69 //
70 //==================================================================================================
71 #beginMacro getGaussianIntegralSolution(OPTION,VEX,VEY,VHZ,t,I1,I2,I3)
72 
73 if( initialConditionOption==gaussianIntegralInitialCondition )
74 {
75 
76  double wt,wx,wy;
77  const int nsources=1;
78  double xs[nsources], ys[nsources], tau[nsources], var[nsources], amp[nsources];
79  xs[0]=0.;
80  ys[0]=1.e-8*1./3.; // should not be on a grid point
81  tau[0]=-.95;
82  var[0]=30.;
83  amp[0]=1.;
84 
85  double period= 1.; // period in y
86  double time=t;
87 
88  int i1,i2,i3;
89 
90  FOR_3D(i1,i2,i3,I1,I2,I3)
91  {
92  double x=X(i1,i2,i3,0);
93  double y=X(i1,i2,i3,1);
94 
95  exmax(wt,wx,wy,nsources,xs[0],ys[0],tau[0],var[0],amp[0],period,x,y,time);
96 
97  #If #OPTION eq "solution"
98  VEX(i1,i2,i3) = wy;
99  VEY(i1,i2,i3) =-wx;
100  VHZ(i1,i2,i3)= wt;
101  #Elif #OPTION eq "error"
102  ERREX(i1,i2,i3) = VEX(i1,i2,i3) - wy;
103  ERREY(i1,i2,i3) = VEY(i1,i2,i3) + wx;
104  ERRHZ(i1,i2,i3) = VHZ(i1,i2,i3) - wt;
105 
106  #Else
107  U(i1,i2,i3,ex) = wy;
108  U(i1,i2,i3,ey) =-wx;
109  U(i1,i2,i3,hz) = wt;
110  #End
111 
112  }
113 }
114 
115 #endMacro
116 
117 
118 //==================================================================================================
119 // The DEFINE_GF_MACRO is a helper for EXTRACT_GFP and sets up the cpp macros for a given field
120 //
121 //==================================================================================================
122 #beginMacro DEFINE_GF_MACRO(GFM,GFP,DIM0,DIM1,DIM2,DFA,CCX)
123 
124 #ifdef GFM ##
125 ERROR : GFM ## already defined!
126 #else
127 #define GFM ## (i0,i1,i2) GFP ## [i0+DIM0 ## *(i1+DIM1 ## *(i2+DIM2 ## *( CCX )))]
128 #endif
129 
130 #endMacro
131 //==================================================================================================
132 
133 //==================================================================================================
134 // The EXTRACT_GFP macro extracts gridfunction pointers and array bounds.
135 // We use these to write code that works in 2/3D for both the nfdtd and
136 // dsi schemes.
137 //
138 // The macro expects the user to have the following variables defined in the enclosing scope:
139 // Index I1,I2,I3 - used to get the index ranges for each grid
140 // CompositeGrid &cg - the composite grid used by the fields
141 // int grid - the current grid to setup the pointers for
142 // int i1,i2,i3 - grid indices into the arrays at the appropriate centering
143 // MappedGrid *Maxwell:mgp - or -
144 // CompositeGrid *Maxwell cgfields -or- CompositeGrid *Maxwell dsi_cgfields
145 //
146 // The macro defines:
147 // cpp macros:
148 // UH{XYZ}(i0,i1,i2) - access the current h field at i1,i2,i3 with the appropriate centering
149 // UE{XYZ}(i0,i1,i2) - access the current e field at i1,i2,i3 with the appropriate centering
150 // UMH{XYZ}(i0,i1,i2) - the h field at the previous timestep
151 // UME{XYZ}(i0,i1,i2) - the e field at the previous timestep
152 // UNH{XYZ}(i0,i1,i2) - the h field at the next timestep
153 // UNE{XYZ}(i0,i1,i2) - the h field at the next timestep
154 //
155 // ERRH{XYZ}(i0,i1,i2) - acces the h field error gridfunction
156 // ERRE{XYZ}(i0,i1,i2) - acces the e field error gridfunction
157 //
158 // XEP(i0,i1,i2,i3) - coordinates of e centering
159 // XHP(i0,i1,i2,i3) - coordinates of h centering
160 //
161 // variables:
162 // MappedGrid &mg - the current mapped grid (cg[grid])
163 //
164 // const bool isStructured - true for structured grids
165 // const bool isRectangular - true for rectangular grids
166 //
167 // realMappedGridFunction uh - view of the current h or h.n field
168 // realMappedGridFunction ue - view of the current e or e.n field
169 // realMappedGridFunction umh - view of the previous h or h.n field
170 // realMappedGridFunction ume - view of the previous e or e.n field
171 // realMappedGridFunction unh - view of the next h or h.n field
172 // realMappedGridFunction une - view of the next e or e.n field
173 // realMappedGridFunction errh - view of the h field error
174 // realMappedGridFunction erre - view of the e field error
175 // realArray xe - view of the x coordinates at the e centering
176 // realArray xh - view of the x coordinates at the h centering
177 // realArray ye - view of the y coordinates at the e centering
178 // realArray yh - view of the y coordinates at the h centering
179 // realArray ze - view of the z coordinates at the e centering
180 // realArray zh - view of the z coordinates at the h centering
181 // realArray xce - coordinates of the e centering
182 // realArray xch - coordinates of the h centering
183 // realArray emptyArray - used for setting references to things we don't need
184 // real *uhp - data pointer for the current h or h.n field
185 // real *uep - data pointer for the current h or e.n field
186 // real *umhp - data pointer for the previous h or h.n field
187 // real *umep - data pointer for the previous h or e.n field
188 // real *unhp - data pointer for the next h or h.n field
189 // real *unep - data pointer for the next h or e.n field
190 // real *xep - data pointer for the coordinates at the e centering
191 // real *xhp - data pointer for the coordinates at the h centering
192 //
193 // real dx[3] - dx in each direction for rectangular grids (={0,0,0} if !isRectangular)
194 // real xab[2][3] - coordinate bounds for rectangular grids (={ {0,0},.. } if !isRectangular)
195 //
196 // int uhDim0,uhDim1,uhDim2 - array dimensions for the e gridfunctions
197 // int ueDim0,ueDim1,ueDim2 - array dimensions for the h gridfunctions
198 // int xeDim0,xeDim1,xeDim2 - array dimensions for the e centering coordinates
199 // int xhDim0,xhDim1,xhDim2 - array dimensions for the h centering coordinates
200 //
201 // KNOWN ASSUMPTIONS: * gridFunctions for the same variable at different time levels have the same
202 // raw data sizes
203 // * there are unrecognized and perhaps subtle assumptions being made
204 //
205 // OPTION:
206 //==================================================================================================
207 #beginMacro EXTRACT_GFP(OPTION)
208 
209 #ifdef EXTGFP_SENTINEL
210 ERROR : XXX : you have not closed the current EXTRACT_GFP macro before starting a new one!
211 #endif
212 #define EXTGFP_SENTINEL
213 #ifdef EXTGFP_SENTINEL
214 
215 realArray emptyArray;
216 realSerialArray emptySerialArray;
217 
218 Range all;
219 Index I1,I2,I3;
220 Index Iev[3], &Ie1=Iev[0], &Ie2=Iev[1], &Ie3=Iev[2];
221 Index Ihv[3], &Ih1=Ihv[0], &Ih2=Ihv[1], &Ih3=Ihv[2];
222 
223 MappedGrid & mg = cg[grid];
224 const bool isStructured = mg.getGridType()==MappedGrid::structuredGrid;
225 const bool isRectangular = mg.isRectangular();
226 assert( !(isRectangular && !isStructured) ); // just a little check on the MappedGrid's data
227 
228 real dx[3]={1.,1.,1.}, xab[2][3]={{0.,0.,0.},{0.,0.,0.}};
229 if( isRectangular )
230  mg.getRectangularGridParameters( dx, xab );
231 
232 //realMappedGridFunction uh,ue,umh,ume,unh,une;
233 realSerialArray uh,ue,umh,ume,unh,une,errh,erre;
234 realSerialArray xe,xh,ye,yh,ze,zh,xce,xch;
235 realSerialArray uepp, uhpp; // dsi projection arrays
236 
237 intArray & mask = mg.mask();
238 #ifdef USE_PPP
239  intSerialArray maskLocal; getLocalArrayWithGhostBoundaries(mask,maskLocal);
240 #else
241  intSerialArray & maskLocal = mask;
242 #endif
243 
244 
245 const bool buildCenter = !( isRectangular &&
246  ( initialConditionOption==squareEigenfunctionInitialCondition ||
247  initialConditionOption==gaussianPulseInitialCondition ||
248  (forcingOption==gaussianChargeSource && initialConditionOption==defaultInitialCondition)
249  // || initialConditionOption==planeMaterialInterfaceInitialCondition
250  // || initialConditionOption==annulusEigenfunctionInitialCondition
251  )
252  ); // fix this
253 
255 {
256  // printF("assignInitialConditions:INFO:build the grid vertices, grid=%i\n",grid);
257  mg.update(MappedGrid::THEcenter | MappedGrid::THEvertex);
258 }
259 
260 const realArray & center = buildCenter ? mg.center() : emptyArray;
261 realSerialArray uLocal;
262 
263 real dtb2=dt*.5;
264 real tE = t, tH = t;
265 
266 
267 getIndex(mg.dimension(),I1,I2,I3);
269 bool ok = ParallelUtility::getLocalArrayBounds(mask,maskLocal,I1,I2,I3,includeGhost);
270 #If #OPTION ne "FORCING"
271 if( !ok ) continue; // no communication allowed after this point : check this ******************************************************
272 #Else
273 if( !ok ) return 0; // no communication allowed after this point : check this ******************************************************
274 #End
275 
276 
277 
278 if( method==nfdtd || method==sosup )
279 {
280  Ie1 = Ih1 = I1;
281  Ie2 = Ih2 = I2;
282  Ie3 = Ih3 = I3;
283 
284  // nfdtd uses one gridFunction per time level
285  realMappedGridFunction & uall = mgp==NULL ? getCGField(HField,current)[grid] : fields[current];
286  realMappedGridFunction & umall = mgp==NULL ? getCGField(HField,prev)[grid] : fields[prev];
287  realMappedGridFunction & unall = mgp==NULL ? getCGField(HField,next)[grid] : fields[next];
288 
289  #ifdef USE_PPP
290  getLocalArrayWithGhostBoundaries(uall,uLocal);
291  realSerialArray umLocal; getLocalArrayWithGhostBoundaries(umall,umLocal);
292  realSerialArray unLocal; getLocalArrayWithGhostBoundaries(unall,unLocal);
293  #else
294  uLocal.reference(uall);
295  realSerialArray & umLocal = umall;
296  realSerialArray & unLocal = unall;
297  #endif
298 
299  if ( cg.numberOfDimensions()==2 )
300  {
301  ue.reference( uLocal(I1,I2,I3,Range(ex,ey)) );
302  uh.reference( uLocal(I1,I2,I3,hz) );
303  ume.reference( umLocal(I1,I2,I3,Range(ex,ey)) );
304  umh.reference( umLocal(I1,I2,I3,hz) );
305  une.reference( unLocal(I1,I2,I3,Range(ex,ey)) );
306  unh.reference( unLocal(I1,I2,I3,hz) );
307 
308  if( errp )
309  {
310  #ifdef USE_PPP
311  realSerialArray errLocal; getLocalArrayWithGhostBoundaries(*errp,errLocal);
312  errh.reference(errLocal(I1,I2,I3,hz));
313  erre.reference(errLocal(I1,I2,I3,Range(ex,ey)));
314  #else
315  errh.reference((*errp)(I1,I2,I3,hz));
316  erre.reference((*errp)(I1,I2,I3,Range(ex,ey)));
317  #endif
318  }
319  else if ( cgerrp )
320  {
321  #ifdef USE_PPP
322  realSerialArray errLocal; getLocalArrayWithGhostBoundaries((*cgerrp)[grid],errLocal);
323  errh.reference(errLocal(I1,I2,I3,hz));
324  erre.reference(errLocal(I1,I2,I3,Range(ex,ey)));
325  #else
326  errh.reference((*cgerrp)[grid](I1,I2,I3,hz));
327  erre.reference((*cgerrp)[grid](I1,I2,I3,Range(ex,ey)));
328  #endif
329  }
330  }
331  else
332  {
333  if ( solveForElectricField )
334  {
335  ue.reference( uLocal(I1,I2,I3,Range(ex,ez)) );
336  ume.reference( umLocal(I1,I2,I3,Range(ex,ez)) );
337  une.reference( unLocal(I1,I2,I3,Range(ex,ez)) );
338  if ( errp )
339  {
340  #ifdef USE_PPP
341  realSerialArray errLocal; getLocalArrayWithGhostBoundaries(*errp,errLocal);
342  erre.reference(errLocal(I1,I2,I3,Range(ex,ez)));
343  #else
344  erre.reference((*errp)(I1,I2,I3,Range(ex,ez)));
345  #endif
346 
347  }
348  else if ( cgerrp )
349  {
350  #ifdef USE_PPP
351  realSerialArray errLocal; getLocalArrayWithGhostBoundaries((*cgerrp)[grid],errLocal);
352  erre.reference(errLocal(I1,I2,I3,Range(ex,ez)));
353  #else
354  erre.reference((*cgerrp)[grid](I1,I2,I3,Range(ex,ez)));
355  #endif
356  }
357  }
358 
359  if ( solveForMagneticField )
360  {
361  uh.reference( uLocal(I1,I2,I3,Range(hx,hz)) );
362  umh.reference( umLocal(I1,I2,I3,Range(hx,hz)) );
363  unh.reference( unLocal(I1,I2,I3,Range(hx,hz)) );
364  if ( errp )
365  {
366  #ifdef USE_PPP
367  realSerialArray errLocal; getLocalArrayWithGhostBoundaries(*errp,errLocal);
368  errh.reference(errLocal(I1,I2,I3,Range(hx,hz)));
369  #else
370  errh.reference((*errp)(I1,I2,I3,Range(hx,hz)));
371  #endif
372  }
373  else if ( cgerrp )
374  {
375  #ifdef USE_PPP
376  realSerialArray errLocal; getLocalArrayWithGhostBoundaries((*cgerrp)[grid],errLocal);
377  errh.reference(errLocal(I1,I2,I3,Range(hx,hz)));
378  #else
379  errh.reference((*cgerrp)[grid](I1,I2,I3,Range(hx,hz)));
380  #endif
381  }
382  }
383  }
384 
385  #ifdef USE_PPP
386  realSerialArray xLocal; if( buildCenter ) getLocalArrayWithGhostBoundaries(center,xLocal);
387  #else
388  const realSerialArray & xLocal = center;
389  #endif
390 
391  if( buildCenter )
392  {
393  // *wdh* 041015 these next assignments fail in P++ if buildCenter==false -- but why make the reference?
394  xe.reference( (buildCenter ? xLocal(I1,I2,I3,0) : emptySerialArray) );
395  ye.reference( (buildCenter ? xLocal(I1,I2,I3,1) : emptySerialArray) );
396  if ( numberOfDimensions==3 )
397  ze.reference( (buildCenter ? xLocal(I1,I2,I3,2) : emptySerialArray) );
398 
399  // nfdtd uses the same centering for e and h
400  xh.reference(xe);
401  yh.reference(ye);
402  zh.reference(ze); // *wdh* 090628
403  }
404 
405  if ( buildCenter )
406  {
407  xce.reference(xLocal);
408  xch.reference(xce);
409  }
410 }
411 else // dsi or yee scheme
412 {
413  tE -= dtb2;
414 
415  if ( method==dsiMatVec /*&& numberOfDimensions==3*/ )
416  {
417  realMappedGridFunction &uep = (mgp==NULL ? getCGField(EField,current)[grid] : fields[current+numberOfTimeLevels]);
418  realMappedGridFunction &uhp = (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]);
419  realMappedGridFunction &uepm = (mgp==NULL ? getCGField(EField,next)[grid] : fields[next+numberOfTimeLevels]);
420  realMappedGridFunction &uhpm = (mgp==NULL ? getCGField(HField,next)[grid] : fields[next]);
421 
422  #ifdef USE_PPP
423  realSerialArray uepLocal; getLocalArrayWithGhostBoundaries(uep,uepLocal);
424  realSerialArray uhpLocal; getLocalArrayWithGhostBoundaries(uhp,uhpLocal);
425  realSerialArray uepmLocal; getLocalArrayWithGhostBoundaries(uepm,uepmLocal);
426  realSerialArray uhpmLocal; getLocalArrayWithGhostBoundaries(uhpm,uhpmLocal);
427  #else
428  realSerialArray & uepLocal=uep;
429  realSerialArray & uhpLocal=uhp;
430  realSerialArray & uepmLocal=uepm;
431  realSerialArray & uhpmLocal=uhpm;
432  #endif
433 
434  realMappedGridFunction uer, uhr, uerm, uhrm;
435  uepp.reference(uepLocal);
436  uhpp.reference(uhpLocal);
437 
438 #If #OPTION == "FORCING"
439 
440  ue.reference ( uepLocal );
441  uh.reference ( uhpLocal );
442  ume.reference ( uepmLocal );
443  umh.reference ( uhpmLocal );
444 
445 #Else
446 
447  uer.updateToMatchGrid(mg,GridFunctionParameters::edgeCentered,numberOfDimensions);
448  uerm.updateToMatchGrid(mg,GridFunctionParameters::edgeCentered,numberOfDimensions);
449  if ( numberOfDimensions==2 )
450  {
451  uhr.updateToMatchGrid(mg,GridFunctionParameters::cellCentered);
452  uhrm.updateToMatchGrid(mg,GridFunctionParameters::cellCentered);
453  }
454  else
455  {
456  uhr.updateToMatchGrid(mg,GridFunctionParameters::faceCenteredAll,numberOfDimensions);
457  uhrm.updateToMatchGrid(mg,GridFunctionParameters::faceCenteredAll,numberOfDimensions);
458  }
459 
460 
461  uer = uerm = -100;
462  uhr = uhrm = -100;
463 
464  #If #OPTION == "IC"
465 
466  #Else
467  reconstructDSIField(tE,EField,uep,uer);
468  reconstructDSIField(tE-dt,EField,uepm,uerm);
469 
470  reconstructDSIField(tH,HField,uhp,uhr);
471  reconstructDSIField(tH-dt,HField,uhpm,uhrm);
472  #End
473 
474  #ifdef USE_PPP
475  realSerialArray uerLocal; getLocalArrayWithGhostBoundaries(uer,uerLocal);
476  realSerialArray uhrLocal; getLocalArrayWithGhostBoundaries(uhr,uhrLocal);
477  realSerialArray uermLocal; getLocalArrayWithGhostBoundaries(uerm,uermLocal);
478  realSerialArray uhrmLocal; getLocalArrayWithGhostBoundaries(uhrm,uhrmLocal);
479  #else
480  realSerialArray & uerLocal=uer;
481  realSerialArray & uhrLocal=uhr;
482  realSerialArray & uermLocal=uerm;
483  realSerialArray & uhrmLocal=uhrm;
484  #endif
485  ue.reference ( uerLocal );
486  uh.reference ( uhrLocal );
487  ume.reference ( uermLocal );
488  umh.reference ( uhrmLocal );
489 
490  // cout<<"UMH SIZE "<<umh.getLength(0)<<" "<<umh.getLength(3)<<endl;
491 #End
492 
493  }
494  else
495  {
496  #ifdef USE_PPP
497  Overture::abort("finish me for parallel");
498  #else
499  ue.reference ( (mgp==NULL ? getCGField(EField,current)[grid] : fields[current+numberOfTimeLevels]) );
500  uh.reference ( (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]) );
501  ume.reference ( (mgp==NULL ? getCGField(EField,next)[grid] : fields[next+numberOfTimeLevels]) );
502  umh.reference ( (mgp==NULL ? getCGField(HField,next)[grid] : fields[next]) );
503  #endif
504  }
505 
506 // #Else
507 // ue.reference ( (mgp==NULL ? getCGField(EField,current)[grid] : fields[current+numberOfTimeLevels]) );
508 // uh.reference ( (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]) );
509 // ume.reference ( (mgp==NULL ? getCGField(EField,next)[grid] : fields[next+numberOfTimeLevels]) );
510 // umh.reference ( (mgp==NULL ? getCGField(HField,next)[grid] : fields[next]) );
511 
512 // #End
513 
514  if ( errp )
515  {
516  #ifdef USE_PPP
517  Overture::abort("finish me for parallel");
518  #else
519  erre.reference(errp[0]);
520  errh.reference(errp[1]);
521  #endif
522  }
523  else if ( cgerrp )
524  {
525  #ifdef USE_PPP
526  Overture::abort("finish me for parallel");
527  #else
528  erre.reference(cgerrp[0][grid]);
529  errh.reference(cgerrp[1][grid]);
530  #endif
531  }
532 
533  Ih1 = Range(uh.getBase(0),uh.getBound(0));
534  Ih2 = Range(uh.getBase(1),uh.getBound(1));
535  Ih3 = Range(uh.getBase(2),uh.getBound(2));
536 
537  Ie1 = Range(ue.getBase(0),ue.getBound(0));
538  Ie2 = Range(ue.getBase(1),ue.getBound(1));
539  Ie3 = Range(ue.getBase(2),ue.getBound(2));
540 
541  I1 = Ih1;
542  I2 = Ih2;
543  I3 = Ih3;
544 
545  if ( buildCenter )
546  {
547  const realArray & center = mg.isAllVertexCentered() ? mg.corner() : mg.center();
548 
549  // cout<<"CENTER SIZE "<<center.getLength(0)<<endl;
550  // cout<<"MG VERTEX/CELL CENT "<<mg.isAllVertexCentered()<<" "<<mg.isAllCellCentered()<<endl;
551  // getFaceCenters(mg, xce);
552  #ifdef USE_PPP
553  Overture::abort("finish me for parallel");
554  #else
555 
556  if ( mg.numberOfDimensions()==2 )
557  {
558  getCenters(mg, UnstructuredMapping::Edge, xce);
559  xch.reference(center);
560  xce.reshape(Range(xce.getLength(0)),1,1,Range(xce.getLength(1)));
561  }
562  else
563  {
564  getCenters(mg, UnstructuredMapping::Face, xch);
565  getCenters(mg, UnstructuredMapping::Edge, xce);
566  xce.reshape(Range(xce.getLength(0)),1,1,Range(xce.getLength(1)));
567  xch.reshape(Range(xch.getLength(0)),1,1,Range(xch.getLength(1)));
568 
569  }
570 
571 
572 
573  //xh.reference(xch(all,all,all,0));
574  //yh.reference(xch(all,all,all,1));
575  xh.reference(xch(Ih1,Ih2,Ih3,0,all));
576  yh.reference(xch(Ih1,Ih2,Ih3,1,all));
577  if ( numberOfDimensions==3 )
578  zh.reference(xch(Ih1,Ih2,Ih3,2,all));
579 
580  xe.reference(xce(Ie1,Ie2,Ie3,0,all));
581  ye.reference(xce(Ie1,Ie2,Ie3,1,all));
582  if ( numberOfDimensions==3 )
583  ze.reference(xce(Ie1,Ie2,Ie3,2,all));
584  #endif
585 
586  }
587 }
588 
589 real *uhp=0,*uep=0,*umhp=0,*umep=0,*unhp=0,*unep=0,*xep=0,*xhp=0,*errhp=0,*errep=0;
594 uhDim0=uhDim1=uhDim2=ueDim0=ueDim1=ueDim2=xeDim0=xeDim1=xeDim2=xhDim0=xhDim1=xhDim2=-1;
595 
596 // #ifdef USE_PPP
597 
598 // realSerialArray uel; getLocalArrayWithGhostBoundaries(ue,uel);
599 // realSerialArray uhl; getLocalArrayWithGhostBoundaries(uh,uhl);
600 // realSerialArray umel; if( ume.getLength(0)>0 ) ume.getLocalArrayWithGhostBoundaries(ume,umel);
601 // realSerialArray umhl; if( umh.getLength(0)>0 ) umh.getLocalArrayWithGhostBoundaries(umh,umhl);
602 // realSerialArray unel; getLocalArrayWithGhostBoundaries(une,unel);
603 // realSerialArray unhl; getLocalArrayWithGhostBoundaries(unh,unhl);
604 // realSerialArray xcel; getLocalArrayWithGhostBoundaries(xce,xcel);
605 // realSerialArray xchl; getLocalArrayWithGhostBoundaries(xch,xchl);
606 
607 // realSerialArray errel; getLocalArrayWithGhostBoundaries(erre,errel);
608 // realSerialArray errhl; getLocalArrayWithGhostBoundaries(errh,errhl);
609 
610 // // intSerialArray maskLocal; getLocalArrayWithGhostBoundaries(mask,maskl);
611 
612 // #else
613 
614 const realSerialArray &uel = ue;
615 const realSerialArray &uhl = uh;
616 const realSerialArray &umel = ume;
617 const realSerialArray &umhl = umh;
618 const realSerialArray &unel = une;
619 const realSerialArray &unhl = unh;
620 const realSerialArray &xcel = xce;
621 const realSerialArray &xchl = xch;
622 const realSerialArray &errel = erre;
623 const realSerialArray &errhl = errh;
624 
625 // const intSerialArray & maskLocal = mask;
626 
627 // #endif
628 
629 // H field pointer and array definitions
630 uhp = uhl.Array_Descriptor.Array_View_Pointer3;
631 if ( umhl.getLength(0) )
632 {
633  umhp = umhl.Array_Descriptor.Array_View_Pointer3;
634 }
635 unhp = unhl.Array_Descriptor.Array_View_Pointer3;
636 uhDim0 = uhl.getRawDataSize(0);
637 uhDim1 = uhl.getRawDataSize(1);
638 uhDim2 = uhl.getRawDataSize(2);
639 uhDimFA = uhl.getRawDataSize(4);
640 
641 //DEFINE_GF_MACRO is a bpp macro
642 DEFINE_GF_MACRO(UHX,uhp,uhDim0,uhDim1,uhDim2,uhDimFA,hx);
643 DEFINE_GF_MACRO(UHY,uhp,uhDim0,uhDim1,uhDim2,uhDimFA,hy);
644 DEFINE_GF_MACRO(UHZ,uhp,uhDim0,uhDim1,uhDim2,uhDimFA,hz);
645 
646 DEFINE_GF_MACRO(UMHX,umhp,uhDim0,uhDim1,uhDim2,uhDimFA,hx);
647 DEFINE_GF_MACRO(UMHY,umhp,uhDim0,uhDim1,uhDim2,uhDimFA,hy);
648 DEFINE_GF_MACRO(UMHZ,umhp,uhDim0,uhDim1,uhDim2,uhDimFA,hz);
649 
650 DEFINE_GF_MACRO(UNHX,unhp,uhDim0,uhDim1,uhDim2,uhDimFA,hx);
651 DEFINE_GF_MACRO(UNHY,unhp,uhDim0,uhDim1,uhDim2,uhDimFA,hy);
652 DEFINE_GF_MACRO(UNHZ,unhp,uhDim0,uhDim1,uhDim2,uhDimFA,hz);
653 
654 errhp = errhl.Array_Descriptor.Array_View_Pointer3;
655 DEFINE_GF_MACRO(ERRHX,errhp,uhDim0,uhDim1,uhDim2,uhDimFA,hx);
656 DEFINE_GF_MACRO(ERRHY,errhp,uhDim0,uhDim1,uhDim2,uhDimFA,hy);
657 DEFINE_GF_MACRO(ERRHZ,errhp,uhDim0,uhDim1,uhDim2,uhDimFA,hz);
658 
659 // #ifdef UNH
660 // ERROR : UNH already defined!
661 // #else
662 // #define UNH(i0,i1,i2,i3) unhp[i0+uhDim0*(i1+uhDim1*(i2+uhDim2*(i3)))]
663 // #endif
664 
665 xhp = xchl.Array_Descriptor.Array_View_Pointer3;
666 xhDim0 = xchl.getRawDataSize(0);
667 xhDim1 = xchl.getRawDataSize(1);
668 xhDim2 = xchl.getRawDataSize(2);
669 #ifdef XHP
670 ERROR : XHP already defined!
671 #else
672 #define XHP(i0,i1,i2,i3) xhp[i0+xhDim0*(i1+xhDim1*(i2+xhDim2*(i3)))]
673 #endif
674 
675 #ifdef X
676 ERROR : X already defined!
677 #else
678 #define X(i0,i1,i2,i3) xhp[i0+xhDim0*(i1+xhDim1*(i2+xhDim2*(i3)))]
679 #endif
680 
681 // E Field pointer and array definitions
682 uep = uel.Array_Descriptor.Array_View_Pointer3;
683 if ( umel.getLength(0) )
684 {
685  umep = umel.Array_Descriptor.Array_View_Pointer3;
686 }
687 unep = unel.Array_Descriptor.Array_View_Pointer3;
688 ueDim0 = uel.getRawDataSize(0);
689 ueDim1 = uel.getRawDataSize(1);
690 ueDim2 = uel.getRawDataSize(2);
691 ueDimFA = uel.getRawDataSize(4);
692 
693 //DEFINE_GF_MACRO is a bpp macro
694 DEFINE_GF_MACRO(UEX,uep,ueDim0,ueDim1,ueDim2,ueDimFA,ex);
695 DEFINE_GF_MACRO(UEY,uep,ueDim0,ueDim1,ueDim2,ueDimFA,ey);
696 DEFINE_GF_MACRO(UEZ,uep,ueDim0,ueDim1,ueDim2,ueDimFA,ez);
697 
698 DEFINE_GF_MACRO(UMEX,umep,ueDim0,ueDim1,ueDim2,ueDimFA,ex);
699 DEFINE_GF_MACRO(UMEY,umep,ueDim0,ueDim1,ueDim2,ueDimFA,ey);
700 DEFINE_GF_MACRO(UMEZ,umep,ueDim0,ueDim1,ueDim2,ueDimFA,ez);
701 
702 DEFINE_GF_MACRO(UNEX,unep,ueDim0,ueDim1,ueDim2,ueDimFA,ex);
703 DEFINE_GF_MACRO(UNEY,unep,ueDim0,ueDim1,ueDim2,ueDimFA,ey);
704 DEFINE_GF_MACRO(UNEZ,unep,ueDim0,ueDim1,ueDim2,ueDimFA,ez);
705 
706 errep = errel.Array_Descriptor.Array_View_Pointer3;
707 DEFINE_GF_MACRO(ERREX,errep,ueDim0,ueDim1,ueDim2,ueDimFA,ex);
708 DEFINE_GF_MACRO(ERREY,errep,ueDim0,ueDim1,ueDim2,ueDimFA,ey);
709 DEFINE_GF_MACRO(ERREZ,errep,ueDim0,ueDim1,ueDim2,ueDimFA,ez);
710 
711 const int *maskp = maskLocal.Array_Descriptor.Array_View_Pointer2;
712 const int maskDim0=maskLocal.getRawDataSize(0);
713 const int maskDim1=maskLocal.getRawDataSize(1);
714 const int md1=maskDim0, md2=md1*maskDim1;
715 #define MASK(i0,i1,i2) maskp[(i0)+(i1)*md1+(i2)*md2]
716 
717 // #ifdef UE
718 // ERROR : UE already defined!
719 // #else
720 // #define UE(i0,i1,i2,i3) uep[i0+ueDim0*(i1+ueDim1*(i2+ueDim2*(i3)))]
721 // #endif
722 
723 xep = xcel.Array_Descriptor.Array_View_Pointer3;
724 xeDim0 = xcel.getRawDataSize(0);
725 xeDim1 = xcel.getRawDataSize(1);
726 xeDim2 = xcel.getRawDataSize(2);
727 #ifdef XEP
728 ERROR : XEP already defined!
729 #else
730 #define XEP(i0,i1,i2,i3) xep[i0+xeDim0*(i1+xeDim1*(i2+xeDim2*(i3)))]
731 #endif
732 
733 #endMacro
734 //==================================================================================================
735 //==================================================================================================
736 
737 
738 
739 //==================================================================================================
740 // This bpp macro undefs the cpp macros defined by EXTRACT_GFP
741 // UH(i0,i1,i2) - access the current h field at i1,i2,i3 with the appropriate centering
742 // UE(i0,i1,i2) - access the current e field at i1,i2,i3 with the appropriate centering
743 // UMH(i0,i1,i2) - the h field at the previous timestep
744 // UME(i0,i1,i2) - the e field at the previous timestep
745 // UNH(i0,i1,i2) - the h field at the next timestep
746 // UNE(i0,i1,i2) - the h field at the next timestep
747 // XEP(i0,i1,i2,i3) - coordinates of e centering
748 // XHP(i0,i1,i2,i3) - coordinates of h centering
749 // OPTION:
750 //==================================================================================================
751 #beginMacro EXTRACT_GFP_END(OPTION)
752 
753 
754 #If ( #OPTION == "IC" )
755 if( method==dsiMatVec )
756 {
757  #ifdef USE_PPP
758  Overture::abort("finish me for parallel");
759  #else
760 
761  // XXX the following is broken for PARALLEL right now (need to use more macros...
762  bool vCent = mg.isAllVertexCentered();
763  int nDim = mg.numberOfDimensions();
764  realMappedGridFunction &uep = (mgp==NULL ? getCGField(EField,current)[grid] : fields[current+numberOfTimeLevels]);
765  realMappedGridFunction &uhp = (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]);
766  realMappedGridFunction &uepm = (mgp==NULL ? getCGField(EField,next)[grid] : fields[next+numberOfTimeLevels]);
767  realMappedGridFunction &uhpm = (mgp==NULL ? getCGField(HField,next)[grid] : fields[next]);
768 
769  if ( mg.numberOfDimensions()==2 )
770  {
771  for ( int e=0; e<edgeAreaNormals.getLength(0); e++ )
772  {
773  uep(e,0,0,0) = 0;
774  uepm(e,0,0,0) = 0;
775  for ( int a=0; a<mg.numberOfDimensions(); a++ )
776  {
777  uep(e,0,0,0) += edgeAreaNormals(e,0,0,a)*ue(e,0,0,a);
778  uepm(e,0,0,0) += edgeAreaNormals(e,0,0,a)*ume(e,0,0,a);
779  }
780  }
781  uhp = uh;
782  uhpm = umh;
783  }
784  else
785  {
786  // cout<<"geom sizes "<<cFArea.getLength(0)<<" "<<cEArea.getLength(0)<<endl;
787  for ( int f=0; f<faceAreaNormals.getLength(0); f++ )
788  {
789  uhp(f,0,0,0) = 0;
790  uhpm(f,0,0,0) = 0;
791  for ( int a=0; a<mg.numberOfDimensions(); a++ )
792  {
793  uhp(f,0,0,0) += faceAreaNormals(f,0,0,a)*uh(f,0,0,a);
794  uhpm(f,0,0,0) += faceAreaNormals(f,0,0,a)*umh(f,0,0,a);
795  }
796  }
797 
798  for ( int e=0; e<edgeAreaNormals.getLength(0); e++ )
799  {
800  uep(e,0,0,0) = 0;
801  uepm(e,0,0,0) = 0;
802  for ( int a=0; a<mg.numberOfDimensions(); a++ )
803  {
804  uep(e,0,0,0) += edgeAreaNormals(e,0,0,a)*ue(e,0,0,a);
805  uepm(e,0,0,0) += edgeAreaNormals(e,0,0,a)*ume(e,0,0,a);
806  }
807  }
808  }
809  #endif
810 }
811 
812 if( method==nfdtd || method==sosup )
813 {
814  (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]).periodicUpdate();
815  (mgp==NULL ? getCGField(HField,prev)[grid] : fields[prev]).periodicUpdate();
816 
817 }
818 else
819 {
820  (mgp==NULL ? getCGField(HField,current)[grid] : fields[current]).periodicUpdate();
821  (mgp==NULL ? getCGField(EField,current)[grid] : fields[current+2]).periodicUpdate();
822 }
823 
824 #End
825 
826 #undef UHX
827 #undef UHY
828 #undef UHZ
829 #undef UEX
830 #undef UEY
831 #undef UEZ
832 #undef UMHX
833 #undef UMHY
834 #undef UMHZ
835 #undef UMEX
836 #undef UMEY
837 #undef UMEZ
838 #undef UNHX
839 #undef UNHY
840 #undef UNHZ
841 #undef UNEX
842 #undef UNEY
843 #undef UNEZ
844 #undef XEP
845 #undef XHP
846 #undef X
847 
848 #undef ERRHX
849 #undef ERRHY
850 #undef ERRHZ
851 
852 #undef ERREX
853 #undef ERREY
854 #undef ERREZ
855 
856 #undef MASK
857 
858 #endif
859 #undef EXTGFP_SENTINEL
860 #endMacro