AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

GridFunction1.c

Go to the documentation of this file.
00001 #ifndef _included_GridFunction1_c
00002 #define _included_GridFunction1_c
00003 
00009 /*****************************************************************************/
00010 /**** Constructors ****/
00011 /*****************************************************************************/
00012 
00013 /*****************************************************************************/
00014 /**** Simple Constructors - the GF is explicitly setup using GF_Set*() ****/
00015 /*****************************************************************************/
00016 template <class DAGH_GFType>
00017 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[], 
00018                                               GridHierarchy& gh)
00019         : GridFunctionVoid(gh.dagh_type(),1,name,gh,0,1,
00020                            gh.default_alignment(1),
00021                            gh.boundarywidth(),
00022                            gh.externalghostwidth(),
00023                            DAGHComm,
00024                            gh.boundarytype(),
00025                            gh.adaptboundarytype(),
00026                            DAGHNoExternalGhost),
00027           gdb(0), bvalue(0),
00028           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00029           iofunc(0) { 
00030 
00031   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00032   
00033   length = new int[gh.totallevels()];
00034   for (register int l=0; l<gh.totallevels(); l++)
00035     length[l] = 0;
00036 
00037   const int pnum = comm_service::proc_num();
00038   register int p = 0;
00039   
00040   /* set up storage for ghost comm */
00041   if (comm()) {
00042     ghost_send_info = new GF_Interaction** [pnum];
00043     ghost_recv_info = new GF_Interaction** [pnum];
00044     ghost_recv_server = new GridTableGhostRcv** [pnum];
00045     for (p=0;p<pnum;p++) {
00046       ghost_send_info[p] = (GF_Interaction**) 0;
00047       ghost_recv_info[p] = (GF_Interaction**) 0;
00048       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00049     }
00050   }
00051   
00052   /* setup storage for data comm */
00053   data_recv_server = new GridTableDataRcv** [pnum];
00054   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00055   
00056   myargc = 0;
00057   myargs = new char[1];
00058   myargs[1] = 0;
00059 }
00060 
00061 /*****************************************************************************/
00062 /*** Constructor for backward compatibility ***/
00063 /*****************************************************************************/
00064 template <class DAGH_GFType>
00065 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00066                                               const int t_sten, 
00067                                               const int s_sten,
00068                                               GridHierarchy& gh,
00069                                               const int cflag, 
00070                                               const int extghflag)
00071         : GridFunctionVoid(gh.dagh_type(),1,name,t_sten,s_sten,
00072                            gh,0,1,DAGH_All,gh.boundarywidth(),
00073                            gh.externalghostwidth(),
00074                            cflag,gh.boundarytype(),
00075                            gh.adaptboundarytype(),extghflag), 
00076           gdb(0), bvalue(0),
00077           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00078           iofunc(0) { 
00079 
00080   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00081   
00082   length = new int[gh.totallevels()];
00083   for (register int l=0; l<gh.totallevels(); l++)
00084     length[l] = 0;
00085   
00086   const int pnum = comm_service::proc_num();
00087   register int p = 0;
00088 
00089   /* set up storage for ghost comm */
00090   if (comm()) {
00091     ghost_send_info = new GF_Interaction** [pnum];
00092     ghost_recv_info = new GF_Interaction** [pnum];
00093     ghost_recv_server = new GridTableGhostRcv** [pnum];
00094     for (p=0;p<pnum;p++) {
00095       ghost_send_info[p] = (GF_Interaction**) 0;
00096       ghost_recv_info[p] = (GF_Interaction**) 0;
00097       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00098     }
00099   }
00100 
00101   /* setup storage for data comm */
00102   data_recv_server = new GridTableDataRcv** [pnum];
00103   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00104   
00105   GF_Compose();
00106   
00107   if (dagh.chkpt_restart() && checkpoint()) 
00108     GF_CheckpointRestart();
00109   
00110   myargc = 0;
00111   myargs = new char[1];
00112   myargs[1] = 0;
00113 }
00114 
00115 template <class DAGH_GFType>
00116 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00117                                               const int t_sten, 
00118                                               const int s_sten,
00119                                               const int cfac,
00120                                               GridHierarchy& gh,
00121                                               const int cflag, 
00122                                               const int extghflag)
00123         : GridFunctionVoid(gh.dagh_type(),1,name,t_sten,s_sten,
00124                            gh,0,cfac,DAGH_All,gh.boundarywidth(),
00125                            gh.externalghostwidth(),
00126                            cflag,gh.boundarytype(),
00127                            gh.adaptboundarytype(),extghflag), 
00128           gdb(0), bvalue(0),
00129           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00130           iofunc(0) { 
00131 
00132   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00133   
00134   length = new int[gh.totallevels()];
00135   for (register int l=0; l<gh.totallevels(); l++)
00136     length[l] = 0;
00137   
00138   const int pnum = comm_service::proc_num();
00139   register int p = 0;
00140 
00141   /* set up storage for ghost comm */
00142   if (comm()) {
00143     ghost_send_info = new GF_Interaction** [pnum];
00144     ghost_recv_info = new GF_Interaction** [pnum];
00145     ghost_recv_server = new GridTableGhostRcv** [pnum];
00146     for (p=0;p<pnum;p++) {
00147       ghost_send_info[p] = (GF_Interaction**) 0;
00148       ghost_recv_info[p] = (GF_Interaction**) 0;
00149       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00150     }
00151   }
00152 
00153   /* setup storage for data comm */
00154   data_recv_server = new GridTableDataRcv** [pnum];
00155   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00156   
00157   GF_Compose();
00158   
00159   if (dagh.chkpt_restart() && checkpoint()) 
00160     GF_CheckpointRestart();
00161   
00162   myargc = 0;
00163   myargs = new char[1];
00164   myargs[1] = 0;
00165 }
00166 
00167 /*****************************************************************************/
00168 /*** Constructor to set GF type (Cell/NonCell Centerted). ***/
00169 /*****************************************************************************/
00170 template <class DAGH_GFType>
00171 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00172                                               const int t_sten, 
00173                                               const int s_sten,
00174                                               GridHierarchy& gh, 
00175                                               const int type,
00176                                               const int cflag, 
00177                                               const int bflag,
00178                                               const int adptbflag,
00179                                               const int extghflag)
00180         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00181                            1,name,t_sten,s_sten,gh,0,1,DAGH_All,
00182                            gh.boundarywidth(),gh.externalghostwidth(),
00183                            cflag,bflag,adptbflag,extghflag),
00184           gdb(0), bvalue(0),
00185           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0),
00186           iofunc(0) {
00187  
00188   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00189   
00190   length = new int[gh.totallevels()];
00191   for (register int l=0; l<gh.totallevels(); l++)
00192     length[l] = 0;
00193   
00194   const int pnum = comm_service::proc_num();
00195   register int p = 0;
00196   
00197   /* set up storage for ghost comm */
00198   if (comm()) {
00199     ghost_send_info = new GF_Interaction** [pnum];
00200     ghost_recv_info = new GF_Interaction** [pnum];
00201     ghost_recv_server = new GridTableGhostRcv** [pnum];
00202     for (p=0;p<pnum;p++) {
00203       ghost_send_info[p] = (GF_Interaction**) 0;
00204       ghost_recv_info[p] = (GF_Interaction**) 0;
00205       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00206     }
00207   }
00208 
00209   /* setup storage for data comm */
00210   data_recv_server = new GridTableDataRcv** [pnum];
00211   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00212   
00213   GF_Compose();
00214   
00215   if (dagh.chkpt_restart() && checkpoint()) 
00216     GF_CheckpointRestart();
00217    
00218   myargc = 0;
00219   myargs = new char[1];
00220   myargs[1] = 0;
00221 }
00222 
00223 template <class DAGH_GFType>
00224 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00225                                               const int t_sten, 
00226                                               const int* s_sten,
00227                                               GridHierarchy& gh, 
00228                                               const int type,
00229                                               const int cflag, 
00230                                               const int bflag,
00231                                               const int adptbflag,
00232                                               const int extghflag)
00233         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00234                            1,name,t_sten,s_sten,gh,0,1,DAGH_All,
00235                            gh.boundarywidth(),gh.externalghostwidth(),
00236                            cflag,bflag,adptbflag,extghflag),
00237           gdb(0), bvalue(0),
00238           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00239           iofunc(0) {
00240  
00241   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00242 
00243   length = new int[gh.totallevels()];
00244   for (register int l=0; l<gh.totallevels(); l++)
00245     length[l] = 0;
00246   
00247   const int pnum = comm_service::proc_num();
00248   register int p = 0;
00249 
00250   /* set up storage for ghost comm */
00251   if (comm()) {
00252     ghost_send_info = new GF_Interaction** [pnum];
00253     ghost_recv_info = new GF_Interaction** [pnum];
00254     ghost_recv_server = new GridTableGhostRcv** [pnum];
00255     for (p=0;p<pnum;p++) {
00256       ghost_send_info[p] = (GF_Interaction**) 0;
00257       ghost_recv_info[p] = (GF_Interaction**) 0;
00258       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00259     }
00260   }
00261   
00262   /* setup storage for data comm */
00263   data_recv_server = new GridTableDataRcv** [pnum];
00264   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00265   
00266   GF_Compose();
00267   
00268   if (dagh.chkpt_restart() && checkpoint()) 
00269     GF_CheckpointRestart();
00270   
00271   myargc = 0;
00272   myargs = new char[1];
00273   myargs[1] = 0;
00274 }
00275 
00276 /*****************************************************************************/
00277 /*** Constructor for GF's with gfRank < dagh.rank ***/
00278 /*****************************************************************************/
00279 template <class DAGH_GFType>
00280 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00281                                               const int t_sten, 
00282                                               const int s_sten,
00283                                               GridHierarchy& gh, 
00284                                               const int type,
00285                                               const int loff,
00286                                               const int cfac,
00287                                               const int align,
00288                                               const int cflag, 
00289                                               const int bflag,
00290                                               const int adptbflag,
00291                                               const int extghflag)
00292         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00293                            1,name,t_sten,s_sten,gh,loff,cfac,align,
00294                            gh.boundarywidth(),gh.externalghostwidth(),
00295                            cflag,bflag,adptbflag,extghflag),
00296           gdb(0), bvalue(0),
00297           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0),
00298           iofunc(0) { 
00299 
00300   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00301   
00302   length = new int[gh.totallevels()];
00303   for (register int l=0; l<gh.totallevels(); l++)
00304     length[l] = 0;
00305   
00306   const int pnum = comm_service::proc_num();
00307 
00308   register int p = 0;
00309   
00310   /* set up storage for ghost comm */
00311   if (comm()) {
00312     ghost_send_info = new GF_Interaction** [pnum];
00313     ghost_recv_info = new GF_Interaction** [pnum];
00314     ghost_recv_server = new GridTableGhostRcv** [pnum];
00315     for (p=0;p<pnum;p++) {
00316       ghost_send_info[p] = (GF_Interaction**) 0;
00317       ghost_recv_info[p] = (GF_Interaction**) 0;
00318       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00319     }
00320   }
00321 
00322   /* setup storage for data comm */
00323   data_recv_server = new GridTableDataRcv** [pnum];
00324   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00325   
00326   GF_Compose();
00327   
00328   if (dagh.chkpt_restart() && checkpoint()) 
00329     GF_CheckpointRestart();
00330   
00331   myargc = 0;
00332   myargs = new char[1];
00333   myargs[1] = 0;
00334 }
00335 
00336 template <class DAGH_GFType>
00337 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00338                                               const int t_sten, 
00339                                               const int* s_sten,
00340                                               GridHierarchy& gh, 
00341                                               const int type,
00342                                               const int loff,
00343                                               const int cfac,
00344                                               const int align,
00345                                               const int cflag, 
00346                                               const int bflag,
00347                                               const int adptbflag,
00348                                               const int extghflag)
00349         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00350                            1,name,t_sten,s_sten,gh,loff,cfac,align,
00351                            gh.boundarywidth(),gh.externalghostwidth(),
00352                            cflag,bflag,adptbflag,extghflag),
00353           gdb(0), bvalue(0),
00354           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0),
00355           iofunc(0) {
00356  
00357   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00358   
00359   length = new int[gh.totallevels()];
00360   for (register int l=0; l<gh.totallevels(); l++)
00361     length[l] = 0;
00362    
00363   const int pnum = comm_service::proc_num();
00364   register int p = 0;
00365 
00366   /* set up storage for ghost comm */
00367   if (comm()) {
00368     ghost_send_info = new GF_Interaction** [pnum];
00369     ghost_recv_info = new GF_Interaction** [pnum];
00370     ghost_recv_server = new GridTableGhostRcv** [pnum];
00371     for (p=0;p<pnum;p++) {
00372       ghost_send_info[p] = (GF_Interaction**) 0;
00373       ghost_recv_info[p] = (GF_Interaction**) 0;
00374       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00375     }
00376   }
00377 
00378   /* setup storage for data comm */
00379   data_recv_server = new GridTableDataRcv** [pnum];
00380   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00381 
00382   GF_Compose();
00383   
00384   if (dagh.chkpt_restart() && checkpoint()) 
00385     GF_CheckpointRestart();
00386   
00387   myargc = 0;
00388   myargs = new char[1];
00389   myargs[1] = 0;
00390 }
00391 
00392 /*****************************************************************************/
00393 /*** Constructor for GF's at a given time and level ***/
00394 /*****************************************************************************/
00395 template <class DAGH_GFType>
00396 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00397                                               const int t_sten, 
00398                                               const int s_sten,
00399                                               const int time, 
00400                                               const int level,
00401                                               GridHierarchy& gh, 
00402                                               const int type,
00403                                               const int loff,
00404                                               const int cfac,
00405                                               const int cflag, 
00406                                               const int bflag,
00407                                               const int adptbflag,
00408                                               const int extghflag)
00409         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00410                            1,name,t_sten,s_sten,gh,loff,cfac,DAGH_All,
00411                            gh.boundarywidth(),gh.externalghostwidth(),
00412                            cflag,bflag,adptbflag,extghflag),
00413           gdb(0), bvalue(0),
00414           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0),
00415           iofunc(0) {
00416  
00417   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00418   
00419   length = new int[gh.totallevels()];
00420   for (register int l=0; l<gh.totallevels(); l++)
00421     length[l] = 0;   
00422 
00423   const int pnum = comm_service::proc_num();
00424   register int p = 0;
00425   
00426   /* set up storage for ghost comm */
00427   if (comm()) {
00428     ghost_send_info = new GF_Interaction** [pnum];
00429     ghost_recv_info = new GF_Interaction** [pnum];
00430     ghost_recv_server = new GridTableGhostRcv** [pnum];
00431     for (p=0;p<pnum;p++) {
00432       ghost_send_info[p] = (GF_Interaction**) 0;
00433       ghost_recv_info[p] = (GF_Interaction**) 0;
00434       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00435     }
00436   }
00437 
00438   /* setup storage for data comm */
00439   data_recv_server = new GridTableDataRcv** [pnum];
00440   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00441   
00442   GF_Compose(time,level);
00443   
00444   if (dagh.chkpt_restart() && checkpoint()) 
00445     GF_CheckpointRestart();
00446   
00447   myargc = 0;
00448   myargs = new char[1];
00449   myargs[1] = 0;
00450 }
00451 
00452 template <class DAGH_GFType>
00453 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[],
00454                                               const int t_sten, 
00455                                               const int* s_sten,
00456                                               const int time, 
00457                                               const int level,
00458                                               GridHierarchy& gh, 
00459                                               const int type,
00460                                               const int loff,
00461                                               const int cfac,
00462                                               const int cflag, 
00463                                               const int bflag,
00464                                               const int adptbflag,
00465                                               const int extghflag)
00466         : GridFunctionVoid(((type == DAGHNull) ? gh.dagh_type() : type),
00467                            1,name,t_sten,s_sten,gh,loff,cfac,DAGH_All,
00468                            gh.boundarywidth(),gh.externalghostwidth(),
00469                            cflag,bflag,adptbflag,extghflag),
00470           gdb(0), bvalue(0),
00471           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00472           iofunc(0) { 
00473 
00474   gfid = gh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00475   
00476   length = new int[gh.totallevels()];
00477   for (register int l=0; l<gh.totallevels(); l++)
00478     length[l] = 0;   
00479   
00480   const int pnum = comm_service::proc_num();
00481   register int p = 0;
00482   
00483   /* set up storage for ghost comm */
00484   if (comm()) {
00485     ghost_send_info = new GF_Interaction** [pnum];
00486     ghost_recv_info = new GF_Interaction** [pnum];
00487     ghost_recv_server = new GridTableGhostRcv** [pnum];
00488     for (p=0;p<pnum;p++) {
00489       ghost_send_info[p] = (GF_Interaction**) 0;
00490       ghost_recv_info[p] = (GF_Interaction**) 0;
00491       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00492     }
00493   }
00494 
00495   /* setup storage for data comm */
00496   data_recv_server = new GridTableDataRcv** [pnum];
00497   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00498   
00499   GF_Compose(time,level);
00500   
00501   if (dagh.chkpt_restart() && checkpoint()) 
00502     GF_CheckpointRestart();
00503   
00504   myargc = 0;
00505   myargs = new char[1];
00506   myargs[1] = 0;
00507 }
00508 
00509 /*****************************************************************************/
00510 /*** Constructor from another GF ***/
00511 /*****************************************************************************/
00512 template <class DAGH_GFType>
00513 GridFunction(1)<DAGH_GFType>::GridFunction(1)(const char name[], 
00514                          const GridFunction(1)<DAGH_GFType>& gf,
00515                                               const int time, 
00516                                               const int level,
00517                                               const int cflag, 
00518                                               const int bflag,
00519                                               const int adptbflag,
00520                                               const int extghflag)
00521         : GridFunctionVoid(name,1,gf,cflag,bflag,adptbflag,extghflag),
00522           gdb(0), bvalue(0),
00523           ifunc(0), ufunc(0), bfunc(0), abfunc(0), pfunc(0), rfunc(0), 
00524           iofunc(0) {
00525  
00526   length = new int[dagh.totallevels()];
00527   for (register int l=0; l<dagh.totallevels(); l++)
00528     length[l] = 0;   
00529   
00530   for (register int i=0;i<2*time_sten_rad+1;i++) 
00531     time_alias[i] = gf.time_alias[i];
00532 
00533   gfid = dagh.DAGH_AddGridFunction((GridFunctionVoid *) this);
00534 
00535   const int pnum = comm_service::proc_num(); 
00536   register int p = 0;
00537   
00538   /* set up storage for ghost comm */
00539   if (comm()) {
00540     ghost_send_info = new GF_Interaction** [pnum];
00541     ghost_recv_info = new GF_Interaction** [pnum];
00542     ghost_recv_server = new GridTableGhostRcv** [pnum];
00543     for (p=0;p<pnum;p++) {
00544       ghost_send_info[p] = (GF_Interaction**) 0;
00545       ghost_recv_info[p] = (GF_Interaction**) 0;
00546       ghost_recv_server[p] = (GridTableGhostRcv**) 0;
00547     }
00548   }
00549 
00550   /* setup storage for data comm */
00551   data_recv_server = new GridTableDataRcv** [pnum];
00552   for (p=0;p<pnum;p++) data_recv_server[p] = (GridTableDataRcv**) 0;
00553   
00554   GF_Compose(gf,time,level);
00555   
00556   if (dagh.chkpt_restart() && checkpoint()) 
00557     GF_CheckpointRestart();
00558    
00559   myargc = 0;
00560   myargs = new char[1];
00561   myargs[1] = 0;
00562 }
00563 
00564 /*****************************************************************************/
00565 /**** Destructor ****/
00566 /*****************************************************************************/
00567 template <class DAGH_GFType>
00568 GridFunction(1)<DAGH_GFType>::~GridFunction(1)() {
00569   GF_DeleteGDBStorage();
00570   
00571   if (comm()) {
00572     GF_DeleteGhostCommInfo();
00573     if (ghost_send_info) delete [] ghost_send_info;
00574     ghost_send_info = (GF_Interaction***) 0;
00575     if (ghost_recv_cnt) delete [] ghost_recv_cnt;
00576     ghost_recv_cnt = 0;
00577     if (ghost_recv_info) delete [] ghost_recv_info;
00578     ghost_recv_info = (GF_Interaction***) 0;
00579     if (ghost_recv_server) delete [] ghost_recv_server;
00580     ghost_recv_server = (GridTableGhostRcv***) 0;
00581   }
00582   GF_DeleteGhostBndryInfo();
00583   
00584   GF_DeleteDataCommInfo();
00585   if (data_recv_server) delete [] data_recv_server;
00586   data_recv_server = (GridTableDataRcv***) 0;
00587   
00588   if (gt) delete gt;
00589   
00590   dagh.DAGH_DelGridFunction(gfid);
00591   
00592   delete myargs;
00593   delete [] length;
00594 }
00595    
00596 /*****************************************************************************/
00597 /**** DeleteInfo ***/
00598 /*****************************************************************************/
00599 template <class DAGH_GFType>
00600 void GridFunction(1)<DAGH_GFType>::GF_DeleteGDBStorage() {
00601   const int timesteps = 2*time_sten_rad+1;
00602   if (gdb) {
00603     for (register int t = 0 ; t < timesteps ; t++) 
00604       GF_DeleteGDBStorage(t);
00605     delete [] gdb; 
00606     gdb = (GridDataBlock(1)<DAGH_GFType> ****) 0;
00607   }
00608 }
00609 
00610 template <class DAGH_GFType>
00611 void GridFunction(1)<DAGH_GFType>::GF_DeleteGDBStorage(const int t) {
00612   const int crslev = dagh.coarselevel();
00613   const int levels = dagh.totallevels();
00614 
00615   if (gdb) if (gdb[t]) {
00616     for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
00617       GF_DeleteGDBStorage(t, l);
00618     delete [] gdb[t]; 
00619     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) 0;
00620   }
00621 }
00622 
00623 template <class DAGH_GFType>
00624 void GridFunction(1)<DAGH_GFType>::GF_DeleteGDBStorage(const int t, const int l) {
00625   assert (l < dagh.totallevels());
00626   
00627   if (gdb) if (gdb[t]) 
00628     if (gdb[t][l]) {
00629       for (register int i = 0 ; i < length[l] ; i++) 
00630         if (gdb[t][l][i]) { 
00631           delete gdb[t][l][i]; 
00632           gdb[t][l][i] = (GridDataBlock(1)<DAGH_GFType> *) 0; 
00633         }
00634       delete [] gdb[t][l]; 
00635       gdb[t][l] = (GridDataBlock(1)<DAGH_GFType> **) 0;
00636     }
00637 }
00638 
00639 template <class DAGH_GFType>
00640 void GridFunction(1)<DAGH_GFType>::GF_CreateGDBStorage(const int t) {
00641   const int crslev = dagh.coarselevel();
00642   const int levels = dagh.totallevels();
00643 
00644   assert (t!=time_sten_rad);
00645   if (gdb) if (!gdb[t]) {
00646     gdb[t] = new GridDataBlock(1)<DAGH_GFType> **[levels];
00647     for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
00648       gdb[t][l] = (GridDataBlock(1)<DAGH_GFType> **) NULL;
00649       GF_CreateGDBStorage(t, l);
00650     }
00651   }
00652 }
00653 
00654 template <class DAGH_GFType>
00655 void GridFunction(1)<DAGH_GFType>::GF_CreateGDBStorage(const int t, const int l) {
00656   assert (l < dagh.totallevels());
00657   
00658   if (gdb) if (gdb[t]) 
00659     if (!gdb[t][l]) {
00660       GridBoxList* lgbl = dagh.lgbl(l);
00661       assert (length[l] == Length(lgbl));
00662       GridBox** mgb = new GridBox*[length[l]];
00663       register int m=0; 
00664       for (register GridBox* tmpgb=lgbl->first();tmpgb;tmpgb=lgbl->next()) 
00665         mgb[m] = tmpgb; m++;
00666       
00667       gdb[t][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
00668       const int mindex = dagh.GlobalMaxIndex(l)+1;
00669       for (register int i=0;i<length[l];i++) {
00670         if (gdb[time_sten_rad][l][i]) {      
00671           gdb[t][l][i] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt,
00672                                                                interactions,
00673                                                                i, *mgb[i],
00674                                                                t, l, bwidth, 
00675                                                                bndrybboxlist[l],
00676                                                                prolongbboxlist[l],
00677                                                                extghostwidth,
00678                                                                overlap,
00679                                                                space_sten_rad,
00680                                                                alignment, mindex,
00681                                                                comm(t,l), 
00682                                                                gdb[time_sten_rad][l][i]);
00683              
00684         }
00685         else
00686           gdb[t][l][i] = (GridDataBlock(1)<DAGH_GFType>*) NULL;
00687       } 
00688       delete [] mgb;
00689     }
00690 }
00691 
00692 template <class DAGH_GFType>
00693 void GridFunction(1)<DAGH_GFType>::GF_DeleteGhostCommInfo() {
00694   const int pnum = comm_service::proc_num();
00695 
00696   if (comm()) {
00697     const int levels = dagh.totallevels();
00698     const int cnt = DAGHMaxAxis * DAGHMaxDirs * levels;
00699     
00700     register int i = 0, j = 0;
00701     
00702     for (i=pnum-1;i>=0;i--) {
00703       if (ghost_send_info[i]) {
00704         for (j=cnt-1;j>=0;j--) {
00705           if (ghost_send_info[i] && ghost_send_info[i][j]) {
00706             delete ghost_send_info[i][j];
00707             ghost_send_info[i][j] = (GF_Interaction*) 0;
00708           }
00709         }
00710         delete [] ghost_send_info[i];
00711         ghost_send_info[i] = (GF_Interaction**) 0;
00712       }
00713       if (ghost_recv_info[i] || ghost_recv_server[i]) {
00714         for (j=cnt-1;j>=0;j--) {
00715           if (ghost_recv_info[i] && ghost_recv_info[i][j]) {
00716             delete ghost_recv_info[i][j];
00717             ghost_recv_info[i][j] = (GF_Interaction*) 0;
00718           }
00719           if (ghost_recv_server[i] && ghost_recv_server[i][j]) {
00720             delete ghost_recv_server[i][j];
00721             ghost_recv_server[i][j] = (GridTableGhostRcv*) 0;
00722           }
00723         }
00724         if (ghost_recv_info[i]) delete [] ghost_recv_info[i];
00725         ghost_recv_info[i] = (GF_Interaction**) 0;
00726         if (ghost_recv_server[i]) delete [] ghost_recv_server[i];
00727         ghost_recv_server[i] = (GridTableGhostRcv**) 0;
00728       }
00729     }
00730   }
00731 }
00732  
00733 template <class DAGH_GFType>
00734 void GridFunction(1)<DAGH_GFType>::GF_DeleteDataCommInfo() {
00735   const int pnum = comm_service::proc_num();
00736   
00737   const int timesteps = 2*time_sten_rad+1;
00738   for (register int i=pnum-1;i>=0;i--) {
00739     if (data_recv_server[i]) {
00740       for (register int j=timesteps-1;j>=0;j--) {
00741         if (data_recv_server[i][j]) {
00742           delete data_recv_server[i][j];
00743           data_recv_server[i][j] = (GridTableDataRcv*) 0;
00744         }
00745       }
00746       delete [] data_recv_server[i];
00747       data_recv_server[i] = (GridTableDataRcv**) 0;
00748     }
00749   }
00750 }
00751 
00752 /*****************************************************************************/
00753 /**** Compose() ****/
00754 /*****************************************************************************/
00755 template <class DAGH_GFType>
00756 void GridFunction(1)<DAGH_GFType>::GF_Compose() {
00757   AllocError::SetTexts("GridFunction(1)","GF_Compose()");      
00758   
00759   if (comm_flag >= DAGHTemplateComm) {
00760     template_flag = comm_flag - DAGHTemplateComm;
00761 #ifdef DEBUG_PRINT
00762     assert(dagh.gflist[template_flag]);
00763 #endif
00764     comm_flag = dagh.gflist[template_flag]->comm_type();
00765   }
00766 
00767   if (composed()) return;
00768   /* set up the interactions */
00769   interactions.compute_interactions(GhostInteraction::face_flag(comm_flag),
00770                                     GhostInteraction::corner_flag(comm_flag),
00771                                     GhostInteraction::edge_flag(comm_flag),
00772                                     GhostInteraction::simple_flag(comm_flag));
00773 
00774   const int crslev = dagh.coarselevel();
00775   const int levels = dagh.totallevels();
00776 
00777   register int t = 0, l = 0, i = 0;  
00778   const int tsteps = 2*time_sten_rad+1;
00779   
00780   gt = new GridTable(gfid,levels,tsteps);
00781   
00782   GridBoxList** lgbl = dagh.lgbl();
00783   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
00784     length[l] = Length(lgbl[l]);
00785 
00786 #ifdef DEBUG_PRINT_GF_GT
00787   ( comm_service::log() << "\n************* Grid Table *************\n"
00788                         << "------ [" << gfname << "] ------" << "\n"
00789                         << *gt
00790                         << "\n************* ***************** *************\n"
00791                           ).flush();
00792 #endif
00793 
00794   /* If memory is already allocated, delete it.... */
00795   GF_DeleteGDBStorage();
00796 
00797   /* Allocate memory */
00798   gdb = new GridDataBlock(1)<DAGH_GFType> ***[tsteps];
00799   for (t=0;t<tsteps;t++) {
00800     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
00801   }
00802   for (t=0;t<tsteps;t++) {
00803     if (!gdb[time_alias[t]]) {
00804       gdb[time_alias[t]] = new GridDataBlock(1)<DAGH_GFType> **[levels];
00805       for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
00806         gdb[time_alias[t]][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
00807         for (i=0;i<length[l];i++) 
00808           gdb[time_alias[t]][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
00809       }
00810     }
00811   }
00812    
00813   GridFunction(1)<DAGH_GFType>* gftemplate = 0;
00814   if (template_flag != DAGHNull) {
00815     gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
00816     if (gftemplate && !gftemplate->composed()) gftemplate = 0;
00817   }
00818   const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
00819 
00820   GF_GatherGhostBndryInfo();
00821 
00822   register int gbi = 0;
00823   GridBox* gb = 0;
00824   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
00825     if (!lgbl[l]) continue;
00826     const int mindex = dagh.GlobalMaxIndex(l)+1;
00827     for (gb = lgbl[l]->first(), gbi = 0; gb; gb = lgbl[l]->next(), gbi++) {
00828       const int ct = dagh.getCurrentTime(l);
00829       int tmplcti = DAGHNull;
00830       if (template_flag != DAGHNull && 
00831           gftemplate && 
00832           gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
00833           && gftemplate->gdb[tmplcti][l])
00834         gdbtmpl = gftemplate->gdb[tmplcti][l][gbi];
00835       else gdbtmpl = 0;
00836       for (int tc=0;tc<tsteps;tc++) { 
00837         t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
00838         if (gdb[t]) if (gdb[t][l]) {
00839           gdb[t][l][gbi] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt, 
00840                                                                  interactions,
00841                                                                  gbi, *gb,
00842                                                                  t, l, bwidth,
00843                                                                  bndrybboxlist[l],
00844                                                                  prolongbboxlist[l],
00845                                                                  extghostwidth,
00846                                                                  overlap, 
00847                                                                  space_sten_rad, 
00848                                                                  alignment, mindex,
00849                                                                  comm(t,l), 
00850                                                                  gdbtmpl);
00851           if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][gbi];
00852         }
00853       }
00854     }
00855   }
00856 
00857   if (comm()) {
00858     GF_GatherGhostCommInfo();
00859     GF_SetUpGhostCommServers();
00860   }
00861   compose_flag = DAGHTrue;
00862 }
00863 
00864 /*****************************************************************************/
00865 /**** Compose(const int T, const int L) ****/
00866 /*****************************************************************************/
00867 template <class DAGH_GFType>
00868 void GridFunction(1)<DAGH_GFType>::GF_Compose(const int T, const int L) {
00869   AllocError::SetTexts("GridFunction(1)","GF_Compose(const int T, const int L)");      
00870 
00871   if (comm_flag >= DAGHTemplateComm) {
00872     template_flag = comm_flag - DAGHTemplateComm;
00873 #ifdef DEBUG_PRINT
00874     assert(dagh.gflist[template_flag]);
00875 #endif
00876     comm_flag = dagh.gflist[template_flag]->comm_type();
00877   }
00878 
00879   if (composed()) return;
00880   /* set up the interactions */
00881   interactions.compute_interactions(GhostInteraction::face_flag(comm_flag),
00882                                     GhostInteraction::corner_flag(comm_flag),
00883                                     GhostInteraction::edge_flag(comm_flag),
00884                                     GhostInteraction::simple_flag(comm_flag));
00885 
00886   const int crslev = dagh.coarselevel();
00887   const int levels = dagh.totallevels();
00888 
00889   register int t = 0, l = 0, i = 0;
00890 
00891   const int tsteps = 2*time_sten_rad+1;
00892   const int fl = dagh.finelevel();
00893 
00894   if (L == DAGHAllLevels) {
00895     gt = new GridTable(gfid,levels,tsteps);
00896   }
00897   else if (L <= fl) {
00898     gt = new GridTable(gfid,levels,tsteps);
00899   }
00900   else {
00901     // right now I will allow only one extra level
00902 #ifdef DEBUG_PRINT
00903     assert((L-fl) == 1); 
00904 #endif
00905     gt = new GridTable(gfid,levels,tsteps);
00906   }
00907 
00908 #ifdef DEBUG_PRINT_GF_GT
00909   ( comm_service::log() << "\n************* Grid Table *************\n"
00910                         << "------ [" << gfname << "] ------" << "\n"
00911                         << *gt
00912                         << "\n************* ***************** *************\n"
00913                          ).flush();
00914 #endif
00915 
00916   GridBoxList** lgbl = dagh.lgbl();
00917   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
00918     if (L == DAGHAllLevels || L == l) 
00919       length[l] = Length(lgbl[l]);
00920 
00921   /* If memory is already allocated, delete it.... */
00922   GF_DeleteGDBStorage();
00923 
00924   /* Allocate memory */
00925   gdb = new GridDataBlock(1)<DAGH_GFType> ***[tsteps];
00926   for (t=0;t<tsteps;t++) {
00927     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
00928   }
00929   for (t=0;t<tsteps;t++) {
00930     for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
00931       if (T != DAGHAllTimes && dagh_timeindex(T,l) != time_alias[t]) continue;
00932       if (!gdb[time_alias[t]]) {
00933         gdb[time_alias[t]] = new GridDataBlock(1)<DAGH_GFType> **[levels];
00934         for (register int ll=Max(crslev,crslev+loffset); ll<Min(levels,levels+loffset); ll++)
00935           gdb[time_alias[t]][ll] = (GridDataBlock(1)<DAGH_GFType> **) NULL;
00936       }
00937       if ((L == DAGHAllLevels || L == l) && !gdb[time_alias[t]][l]) {
00938         gdb[time_alias[t]][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
00939 
00940         for (i=0;i<length[l];i++)
00941           gdb[time_alias[t]][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
00942       }
00943     }
00944   }
00945 
00946   GridFunction(1)<DAGH_GFType>* gftemplate = 0;
00947   if (template_flag != DAGHNull) {
00948     gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
00949     if (gftemplate && !gftemplate->composed()) gftemplate = 0;
00950   }
00951   const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
00952 
00953   GF_GatherGhostBndryInfo();
00954 
00955   register int gbi = 0;
00956   GridBox* gb = 0;
00957   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
00958     if (!lgbl[l]) continue;
00959     if (L != DAGHAllLevels && L != l) continue;
00960     const int mindex = dagh.GlobalMaxIndex(l)+1;
00961     const int ct = dagh.getCurrentTime(l);
00962     int tmplcti = DAGHNull;
00963     for (gb = lgbl[l]->first(), gbi = 0; gb; gb = lgbl[l]->next(), gbi++) {
00964       if (template_flag != DAGHNull && 
00965           gftemplate && 
00966           gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
00967           && gftemplate->gdb[tmplcti][l])
00968         gdbtmpl = gftemplate->gdb[tmplcti][l][gbi];
00969       else gdbtmpl = 0;
00970       for (int tc=0;tc<tsteps;tc++) { 
00971         t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
00972         if (gdb[t]) if (gdb[t][l]) {
00973           gdb[t][l][gbi] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt, 
00974                                                                  interactions,
00975                                                                  gbi, *gb,
00976                                                                  t, l, bwidth, 
00977                                                                  bndrybboxlist[l],
00978                                                                  prolongbboxlist[l],
00979                                                                  extghostwidth,
00980                                                                  overlap, 
00981                                                                  space_sten_rad,  
00982                                                                  alignment, mindex,
00983                                                                  comm(t,l), 
00984                                                                  gdbtmpl);
00985           if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][gbi];
00986         }
00987       }
00988     }
00989   }
00990 
00991   if (comm()) {
00992     GF_GatherGhostCommInfo();
00993     GF_SetUpGhostCommServers();
00994   }
00995 
00996   compose_flag = DAGHTrue;
00997 }
00998 
00999 /*****************************************************************************/
01000 /*** Compose(const GridFunction(1)<DAGH_GFType>&const int T, const int L) ***/
01001 /*****************************************************************************/
01002 template <class DAGH_GFType>
01003 void GridFunction(1)<DAGH_GFType>::GF_Compose(
01004                                         const GridFunction(1)<DAGH_GFType>& gf,
01005                                         const int T, const int L) {
01006   AllocError::SetTexts("GridFunction(1)",
01007                        "GF_Compose(GridFunction(1)&gf,const int T, const int L)");      
01008 
01009   if (comm_flag >= DAGHTemplateComm) {
01010     template_flag = comm_flag - DAGHTemplateComm;
01011 #ifdef DEBUG_PRINT
01012     assert(dagh.gflist[template_flag]);
01013 #endif
01014     comm_flag = dagh.gflist[template_flag]->comm_type();
01015   }
01016 
01017   if (composed()) return;
01018   /* set up the interactions */
01019   interactions.compute_interactions(GhostInteraction::face_flag(comm_flag),
01020                                     GhostInteraction::corner_flag(comm_flag),
01021                                     GhostInteraction::edge_flag(comm_flag),
01022                                     GhostInteraction::simple_flag(comm_flag));
01023 
01024   const int me = comm_service::proc_me();
01025   const int pnum = comm_service::proc_num();
01026   
01027   const int crslev = dagh.coarselevel();
01028   const int levels = dagh.totallevels();
01029 
01030   register int t = 0, l = 0, i = 0;
01031   const int tsteps = 2*time_sten_rad+1;
01032   const int fl = dagh.finelevel();
01033 
01034   if (L == DAGHAllLevels) {
01035     gt = new GridTable(gfid,levels,tsteps);
01036    }
01037   else if (L <= fl) {
01038     gt = new GridTable(gfid,levels,tsteps);
01039   }
01040   else {
01041     // right now I will allow only one extra level
01042 #ifdef DEBUG_PRINT
01043     assert((L-fl) == 1); 
01044 #endif
01045     gt = new GridTable(gfid,levels,tsteps);
01046   }
01047 
01048   length = gf.length;
01049 
01050 #ifdef DEBUG_PRINT_GF_GT
01051   ( comm_service::log() << "\n************* Grid Table *************\n"
01052                         << "------ [" << gfname << "] ------" << "\n"
01053                         << *gt
01054                         << "\n************* ***************** *************\n"
01055                          ).flush();
01056 #endif
01057 
01058   /* If memory is already allocated, delete it.... */
01059   GF_DeleteGDBStorage();
01060 
01061   /* Allocate memory */
01062   gdb = new GridDataBlock(1)<DAGH_GFType> ***[tsteps];
01063   for (t=0;t<tsteps;t++) {
01064     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
01065   }
01066   for (t=0;t<tsteps;t++) {
01067     for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01068       if (T != DAGHAllTimes && dagh_timeindex(T,l) != time_alias[t]) continue;
01069       if (!gdb[time_alias[t]]) {
01070         gdb[time_alias[t]] = new GridDataBlock(1)<DAGH_GFType> **[levels];
01071         for (register int ll=Max(crslev,crslev+loffset); ll<Min(levels,levels+loffset); ll++)
01072           gdb[time_alias[t]][ll] = (GridDataBlock(1)<DAGH_GFType> **) NULL;
01073       }
01074       if ((L == DAGHAllLevels || L == l) && !gdb[time_alias[t]][l]) {
01075         gdb[time_alias[t]][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
01076 
01077         for (i=0;i<length[l];i++)
01078           gdb[time_alias[t]][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
01079       }
01080     }
01081   }
01082 
01083   GridFunction(1)<DAGH_GFType>* gftemplate = 0;
01084   if (template_flag != DAGHNull) {
01085     gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01086     if (gftemplate && !gftemplate->composed()) gftemplate = 0;
01087   }
01088   const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
01089 
01090   GridBoxList** lgbl = dagh.lgbl();
01091   GridBox* gb = 0;
01092   GDB_Interaction* pi;     
01093   int npi;
01094 
01095   GF_GatherGhostBndryInfo();
01096 
01097   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01098     if (L != DAGHAllLevels && L != l) continue;
01099     if (!lgbl[l]) continue;
01100     const int mindex = dagh.GlobalMaxIndex(l)+1;
01101     const int cti = dagh_timeindex(dagh.getCurrentTime(l),l);
01102     const int ct = dagh.getCurrentTime(l);
01103     int tmplcti = DAGHNull;
01104     gb = lgbl[l]->first();
01105     for (i=0;i<length[l];i++) {
01106       if (template_flag != DAGHNull && 
01107           gftemplate && 
01108           gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
01109           && gftemplate->gdb[tmplcti][l])
01110         gdbtmpl = gftemplate->gdb[tmplcti][l][i];
01111       else gdbtmpl = 0;
01112       for (int tc=0;tc<tsteps;tc++) { 
01113         t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
01114         const int ll = (l < fl) ? l : fl;
01115         if (gdb[t]) if (gdb[t][l]) 
01116           if (gf.gdb[t]) if (gf.gdb[t][ll]) if (gf.gdb[t][ll][i]) { 
01117             gdb[t][l][i] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt, 
01118                                                                  interactions,
01119                                                                  i, *gb,
01120                                                                  t, l, bwidth, 
01121                                                                  bndrybboxlist[l],
01122                                                                  prolongbboxlist[l],
01123                                                                  extghostwidth,
01124                                                                  overlap, 
01125                                                                  space_sten_rad, 
01126                                                                  alignment, mindex,
01127                                                                  comm(t,l), gdbtmpl);
01128 
01129             if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][i];
01130 
01131             // Initialize data from the other GF ....
01132             if (DAGHInitGFOnCreation == DAGHTrue) { 
01133               if (l-1==ll && pfunc && prolong() && 
01134                   (npi=gdb[t][l][i]->gdb_parent_index)>0 && 
01135                   (pi=gdb[t][l][i]->gdb_parent_info)) { /* prolong */
01136                 for (register int j=0; j<npi; j++)
01137                   if (gf.gdb[t][ll][pi[j].idx]) 
01138                     (*pfunc)(FORTRAN_ARGS(1,gf.gdb[t][ll][pi[j].idx]->data),
01139                              FORTRAN_ARGS(1,gdb[t][l][i]->data),
01140                              BOUNDING_BOX(pi[j].bbox),myargs,&myargc);
01141               }
01142               else if (l == ll)  /* copy... */
01143                 gdb[t][l][i]->data.copy(gf.gdb[t][ll][i]->data);
01144               
01145             }
01146           } // end inititalize from other GF
01147       }
01148       gb = lgbl[l]->next();
01149     }
01150   }
01151 
01152   if (comm()) {
01153     GF_GatherGhostCommInfo();
01154     GF_SetUpGhostCommServers();
01155   }
01156   
01157   compose_flag = DAGHTrue;
01158 }
01159 
01160 /*****************************************************************************/
01161 /**** .. & Recompose  ****/ 
01162 /* Needs consistent data. Ensure calling Syncs() before recomposing !            */
01163 /* Reads and writes also values of ghostcells. During redistribution the values */
01164 /* of ghostcells might be copied into interior cells. This is why they have to be */
01165 /* consistent.  */
01166 /*****************************************************************************/
01167 template <class DAGH_GFType>
01168 void GridFunction(1)<DAGH_GFType>::GF_Recompose(int* reuse_possible,
01169                                                     GridBoxList** ollist,
01170                                                     GridBoxList** rlist, 
01171                                                     GridBoxList** slist,
01172                                                     GridBoxList** olist)
01173 
01174 {
01175 #ifdef DEBUG_PRINT_GF_RG
01176   ( comm_service::log() << "\n************* GF_Recompose() [" << gfid << "] *************\n").flush();
01177 #endif
01178    AllocError::SetTexts("GridFunction(1)", "GF_Recompose(...)");    
01179    const int me = comm_service::proc_me();
01180    const int pnum = comm_service::proc_num();
01181 
01182    register int t=0,i=0,oi=0,p=0,m=0;
01183    int l;
01184    register GridBox* tmpgb = 0;
01185 
01186    GridDataBlock(1)<DAGH_GFType> ****oldgdb = gdb; gdb = 0;
01187    int* oldlength = length;
01188 
01189    gt->resettable();
01190 
01191    const int crslev = dagh.coarselevel();
01192    const int levels = dagh.totallevels();
01193    const int timesteps = 2*time_sten_rad+1;
01194    length = new int[levels];
01195    GridBoxList** lgbl = dagh.lgbl();
01196    GridBox*** mgb = new GridBox**[levels];
01197    for (l=0; l<levels; l++) {
01198      if (l>=Max(crslev,crslev+loffset) && l<Min(levels,levels+loffset))
01199        length[l] = Length(lgbl[l]);
01200      else
01201        length[l] = 0;
01202      mgb[l] = new GridBox*[length[l]];
01203      if (length[l]>0)
01204        for (tmpgb=lgbl[l]->first(),m=0;tmpgb;tmpgb=lgbl[l]->next()) {
01205          mgb[l][m] = tmpgb; m++;
01206        }
01207    }
01208    int* reuse = new int[levels];
01209    for (l=0; l<levels; l++) reuse[l] = 0;
01210    for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01211      for (t=0;t<timesteps;t++) {
01212        if (!oldgdb[t]) break;
01213        if (!oldgdb[t][l]) break;
01214      }
01215      if (t==timesteps) reuse[l] = reuse_possible[l];
01216    }
01217 
01218    gdb = new GridDataBlock(1)<DAGH_GFType> ***[timesteps];
01219    for (t=0;t<timesteps;t++) {
01220      gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
01221      if (oldgdb[t]) {
01222        gdb[t] = new GridDataBlock(1)<DAGH_GFType> **[levels];
01223        for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01224          gdb[t][l] = (GridDataBlock(1)<DAGH_GFType> **) NULL;
01225          if (oldgdb[t][l]) {
01226            if (reuse[l])
01227              gdb[t][l] = oldgdb[t][l];
01228            else {
01229              gdb[t][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
01230              for (i=0;i<length[l];i++)
01231                gdb[t][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
01232            }
01233          }
01234        }
01235      }
01236    }
01237 
01238    /* destroy old storage for data comm */
01239    GF_DeleteDataCommInfo();     
01240 
01241    /* destroy old storage for ghost comm */
01242    GF_DeleteGhostCommInfo();
01243    GF_DeleteGhostBndryInfo();
01244    
01245    GF_GatherGhostBndryInfo();
01246 
01247    register int idx = 0;
01248    register int oldowner = DAGHNoBody;
01249 
01250    /* Comm: Post Rcvs */
01251    if (comm_service::dce() && pnum > 1) {
01252 #ifdef DEBUG_PRINT_GF_RG
01253      ( comm_service::log() << "\n*************     Recv List     *************\n" ).flush();
01254 #endif
01255      if (rlist) {
01256 
01257        idx = 0;
01258        oldowner = DAGHNoBody;
01259      
01260        if (template_flag == DAGHNull) {
01261     
01262          if (rcvsize) delete [] rcvsize;     
01263          rcvsize = new unsigned[timesteps*pnum];     
01264          for (p=0;p<timesteps*pnum;p++) 
01265            rcvsize[p] = 0;
01266 
01267          const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
01268          
01269          for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01270            if (!rlist[l] || !lgbl[l]) continue;
01271            if (rlist[l]->isempty()) continue;
01272 #ifdef DEBUG_PRINT_GF_RG
01273            ( comm_service::log() << "   on l=" << l << "\n" << *rlist[l] ).flush();
01274 #endif
01275            const int mindex = dagh.GlobalMaxIndex(l)+1;
01276            for (tmpgb=rlist[l]->first();tmpgb;
01277                 tmpgb=rlist[l]->next()) {
01278              oldowner = tmpgb->gbOwner();
01279              idx = lgbl[l]->index(tmpgb->gbBBox());
01280              gdbtmpl = 0;
01281              for (int tc=0;tc<timesteps;tc++) { 
01282                t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
01283                if (!gdb[t]) continue; 
01284                if (!gdb[t][l]) continue;
01285                if (!gdb[t][l][idx]) {
01286                  gdb[t][l][idx] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt,
01287                                                                         interactions,
01288                                                                         idx, *mgb[l][idx],
01289                                                                         t, l, bwidth, 
01290                                                                         bndrybboxlist[l],
01291                                                                         prolongbboxlist[l],
01292                                                                         extghostwidth,
01293                                                                         overlap,
01294                                                                         space_sten_rad,
01295                                                                         alignment, mindex,
01296                                                                         comm(t,l), 
01297                                                                         gdbtmpl);
01298                  if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][idx];
01299                } 
01300                if (l<=lmax_recompose) {
01301                  BBox gb = usedbbox(*tmpgb,l,alignment);
01302                  rcvsize[oldowner+t*pnum] += gdhdr::gdbsize(sizeof(DAGH_GFType)*gb.size());
01303 
01304 #ifdef DEBUG_PRINT_GF_RG
01305                  ( comm_service::log() << "GF_Recompose::RecvInfo "
01306                    << "[From:" << oldowner << "]"
01307                    << "[BB:" << gb << "]"
01308                    << "[Si:" << tmpgb->gbIndex() << "]"
01309                    << "[Ri:" << idx << "]"
01310                    << "[Sl:" << l << "]"
01311                    << endl ).flush();
01312 #endif
01313                }
01314              }
01315            }
01316          }
01317 
01318        } else {
01319 
01320          GridFunction(1)<DAGH_GFType>* gftemplate = 
01321            (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01322 
01323          rcvsize = gftemplate->rcvsize;
01324        }
01325 
01326        for (t=0;t<timesteps;t++) {
01327          if (!gdb[t]) continue;
01328          for (p=0;p<pnum;p++) {
01329            if (me == p) continue;
01330            if (rcvsize[p+t*pnum] > 0) {
01331              if (!data_recv_server[p]) {
01332                data_recv_server[p] = new GridTableDataRcv *[timesteps];
01333                for (i=0; i<timesteps; i++) data_recv_server[p][i] = 0; 
01334              }
01335              data_recv_server[p][t] = 
01336                new GridTableDataRcv(*gt, (DAGHDataTag | t), rcvsize[p+t*pnum], p);
01337              data_recv_server[p][t]->postrcv();
01338            }
01339          }
01340        }
01341        
01342        if (template_flag != DAGHNull) {
01343          rcvsize = 0;
01344        }
01345      }
01346 #ifdef DEBUG_PRINT_GF_RG
01347      ( comm_service::log() << "\n************* ***************** *************\n" ).flush();
01348 #endif
01349    } 
01350    
01351    /* Comm: Do Sends */
01352    if (comm_service::dce() && pnum > 1) {
01353      int newowner = DAGHNoBody;
01354 #ifdef DEBUG_PRINT_GF_RG
01355      ( comm_service::log() << "\n*************     Send List     *************\n" ).flush();
01356 #endif
01357      if (slist) {
01358 
01359        idx = 0;
01360 
01361        int mlindex = 0;
01362        for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
01363          if (slist[l]) if (!slist[l]->isempty())
01364            mlindex += slist[l]->number();
01365        
01366        if (template_flag == DAGHNull) {
01367          
01368          if (sndcnt) delete [] sndcnt;
01369          sndcnt = new short[timesteps*pnum];
01370          for (p=0;p<timesteps*pnum;p++) sndcnt[p] = 0;
01371 
01372          if (sndsize) delete [] sndsize;
01373          if (sndbbox) delete [] sndbbox;
01374          if (sndindex) delete [] sndindex;
01375          if (rcvindex) delete [] rcvindex;
01376          if (sndlevel) delete [] sndlevel;
01377 
01378          sndsize = new unsigned[timesteps*pnum*mlindex];
01379          sndbbox = new BBox[timesteps*pnum*mlindex];
01380          sndindex = new short[timesteps*pnum*mlindex];
01381          rcvindex = new short[timesteps*pnum*mlindex];
01382          sndlevel = new short[timesteps*pnum*mlindex];
01383 
01384          register int tmpid = 0;       
01385          for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01386            if (!slist[l] || !ollist[l]) continue;
01387            if (slist[l]->isempty()) continue;
01388 #ifdef DEBUG_PRINT_GF_RG
01389            ( comm_service::log() << "   on l=" << l << "\n" << *slist[l] ).flush();
01390 #endif
01391            for(tmpgb=slist[l]->first();tmpgb;
01392                tmpgb=slist[l]->next()) {
01393              GridBox oldgb = ollist[l]->find(tmpgb->gbBBox());
01394              idx = oldgb.gbIndex();
01395              newowner = tmpgb->gbOwner();
01396              if (l>lmax_recompose) break;
01397              BBox gb = usedbbox(*tmpgb,l,alignment);
01398              for (t=0;t<timesteps;t++) {
01399                if (!gdb[t]) continue;
01400                if (!gdb[t][l]) continue;
01401 
01402                tmpid = t*pnum*mlindex + newowner*mlindex + sndcnt[newowner+t*pnum];
01403                sndbbox[tmpid] = gb;
01404                sndsize[tmpid] = sizeof(DAGH_GFType)*sndbbox[tmpid].size();
01405                sndindex[tmpid] = idx;
01406                rcvindex[tmpid] = tmpgb->gbIndex();
01407                sndlevel[tmpid] = l;
01408                    
01409 #ifdef DEBUG_PRINT_GF_RG
01410                ( comm_service::log() << "GF_Recompose::SendInfo [" 
01411                  << sndcnt[newowner+t*pnum] << "]"
01412                  << "[To:" << newowner << "]"
01413                  << "[BB:" << sndbbox[tmpid] << "]"
01414                  << "[Sz:" << sndsize[tmpid] << "]"
01415                  << "[Si:" << sndindex[tmpid] << "]"
01416                  << "[Ri:" << rcvindex[tmpid] << "]"
01417                  << "[Sl:" << sndlevel[tmpid] << "]"
01418                  << endl ).flush();
01419 #endif
01420                sndcnt[newowner+t*pnum]++;                
01421              }
01422            }
01423          }
01424 
01425        } else {
01426 
01427          GridFunction(1)<DAGH_GFType>* gftemplate = 
01428            (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01429 
01430          sndsize = gftemplate->sndsize;
01431          sndbbox = gftemplate->sndbbox;
01432          sndindex = gftemplate->sndindex;
01433          rcvindex = gftemplate->rcvindex;
01434          sndlevel = gftemplate->sndlevel;
01435          sndcnt = gftemplate->sndcnt;
01436        }
01437 
01438        register int s = 0;
01439        register int off = 0;
01440        for (t=0;t<timesteps;t++) {
01441          if (!oldgdb[t] || !gdb[t]) continue;
01442          for (p=0;p<pnum;p++) {
01443            if (p == me) continue;
01444                
01445 #ifdef DEBUG_PRINT_GF_RG
01446            ( comm_service::log() << "sndcnt[p]:" << sndcnt[p+t*pnum] << endl ).flush();
01447 #endif   
01448            
01449            if (sndcnt[p+t*pnum] == 0) continue;
01450            off = t*pnum*mlindex + p*mlindex;
01451            GridDataBucket<DAGH_GFType> *gdbkt = 
01452              new GridDataBucket<DAGH_GFType>(sndcnt[p+t*pnum],(sndsize+off),DAGHPacked);
01453            s = 0;
01454            while (s<sndcnt[p+t*pnum]) {
01455 #ifdef DEBUG_PRINT
01456              assert(oldgdb[t][sndlevel[off+s]][sndindex[off+s]]);
01457 #endif
01458              const int time_value = dagh_timevalue(time_sten_rad,sndlevel[off+s]);
01459              oldgdb[t][sndlevel[off+s]][sndindex[off+s]]->gdbWriteData(time_value,sndbbox[off+s],
01460                                                                        *gdbkt,s);
01461              (gdbkt->head(s))->index = rcvindex[off+s];
01462              (gdbkt->head(s))->level = sndlevel[off+s];
01463 #ifdef DEBUG_PRINT_GF_RG
01464              ( comm_service::log() << "GF_Recompose::Sending"
01465                << *gdbkt->head(s) << " called BBox: " << sndbbox[off+s]
01466                << endl ).flush();
01467 #endif
01468              s++;
01469            }
01470 #ifdef DEBUG_PRINT_GF_RG
01471            ( comm_service::log() << "send" << endl ).flush();
01472 #endif
01473            gt->send((DAGHDataTag | t),gdbkt,p);
01474          }
01475        }
01476      
01477        if (template_flag != DAGHNull) {       
01478          sndsize = 0;
01479          sndbbox = 0;
01480          sndindex = 0;
01481          rcvindex = 0;
01482          sndlevel = 0;
01483          sndcnt = 0;
01484        }
01485      } 
01486 #ifdef DEBUG_PRINT_GF_RG
01487      ( comm_service::log() << "\n************* ***************** *************\n" ).flush();
01488 #endif
01489    }
01490 
01491    /* Allocate remaining GDB's */
01492    {
01493      GridFunction(1)<DAGH_GFType>* gftemplate = 0;
01494      if (template_flag != DAGHNull) {
01495        gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01496      }
01497      const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
01498      
01499      for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01500        if (!lgbl[l] || reuse[l]) continue;
01501        if (lgbl[l]->isempty()) continue;
01502        const int mindex = dagh.GlobalMaxIndex(l)+1;
01503        const int ct = dagh.getCurrentTime(l);
01504        int tmplcti = DAGHNull;       
01505        for (i = 0 ; i < length[l] ; i++) {
01506          if (template_flag != DAGHNull &&
01507              gftemplate && 
01508              gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
01509              && gftemplate->gdb[tmplcti][l])
01510            gdbtmpl = gftemplate->gdb[tmplcti][l][i];
01511          else gdbtmpl = 0;
01512          for (int tc=0;tc<timesteps;tc++) { 
01513            t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
01514            if (!gdb[t]) continue;
01515            if (!gdb[t][l]) continue;
01516            if (!gdb[t][l][i]) {
01517 #ifdef DEBUG_PRINT_GF_RG
01518              ( comm_service::log() << "Creating for " << mgb[l][i]->gbBBox() 
01519                << " on l=" << l << " for l=" << l-loffset   ).flush();
01520 #endif
01521              gdb[t][l][i] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt,
01522                                                                   interactions,
01523                                                                   i, *mgb[l][i],
01524                                                                   t, l, bwidth, 
01525                                                                   bndrybboxlist[l],
01526                                                                   prolongbboxlist[l],
01527                                                                   extghostwidth,
01528                                                                   overlap,
01529                                                                   space_sten_rad,
01530                                                                   alignment, mindex,
01531                                                                   comm(t,l), 
01532                                                                   gdbtmpl);
01533              assert (!gdb[t][l][i]->boundingbox().empty());
01534 #ifdef DEBUG_PRINT_GF_RG
01535              ( comm_service::log() << "  Done " << gdb[t][l][i]->boundingbox() << "\n" ).flush();
01536 #endif
01537              if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][i];
01538            }
01539          }
01540        }
01541      }
01542    }
01543    
01544    // Setup new serves
01545    if (comm()) {
01546      GF_GatherGhostCommInfo();
01547      GF_SetUpGhostCommServers();
01548    }
01549 
01550    /* All Data: interpolate and/or copy */
01551    {
01552 #ifdef DEBUG_PRINT_GF_RG
01553      ( comm_service::log() << "\n************* Overlap List *************\n" ).flush();
01554 #endif
01555      for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01556        if (!lgbl[l] || reuse[l]) continue;
01557        if (lgbl[l]->isempty()) continue;
01558        if (l>lmax_recompose) break;
01559 #ifdef DEBUG_PRINT_GF_RG
01560        ( comm_service::log() << "   on l=" << l << "\n" << *olist[l] ).flush();
01561 #endif
01562        GDB_Interaction* pi;
01563        int npi;
01564 
01565        for (t=0;t<timesteps;t++) {
01566          if (!gdb[t]) continue;
01567          if (!gdb[t][l]) continue;
01568          
01569          for (i=0; i<length[l]; i++) if (l>Max(crslev,crslev+loffset) && pfunc && prolong())
01570            if (gdb[t][l][i] && gdb[t][l-1]) 
01571              if ((npi=gdb[t][l][i]->gdb_parent_index)>0 && 
01572                  (pi=gdb[t][l][i]->gdb_parent_info)) {
01573                for (register int j=0; j<npi; j++)
01574                  if (gdb[t][l-1][pi[j].idx]) {
01575 #ifdef DEBUG_PRINT_GF_RG
01576                    ( comm_service::log() << "Prolonging to " << gdb[t][l][i]->boundingbox() 
01577                      << " from " << gdb[t][l-1][pi[j].idx]->boundingbox() << " using " 
01578                      << pi[j].bbox << "\n" ).flush();
01579 #endif
01580                    if (t==dagh_timeindex(dagh.getCurrentTime(l-1),l-1) &&
01581                        t==dagh_timeindex(dagh.getCurrentTime(l),l))
01582                      (*pfunc)(FORTRAN_ARGS(1,gdb[t][l-1][pi[j].idx]->data),
01583                               FORTRAN_ARGS(1,gdb[t][l][i]->data),
01584                               BOUNDING_BOX(pi[j].bbox),
01585                               myargs,&myargc);
01586                    else
01587                      gdb[t][l][i]->data.equals(DAGH_GFType(0.0),pi[j].bbox);    
01588                  }             
01589              }
01590 
01591          /* Local copies - use only internal cells */
01592          for (tmpgb=olist[l]->first();
01593               tmpgb;tmpgb=olist[l]->next()) {
01594 #ifdef DEBUG_PRINT
01595            assert (tmpgb->gbOwner() == me);
01596 #endif
01597            oi = tmpgb->gbIndex();
01598            i = lgbl[l]->index(tmpgb->gbBBox());
01599            if (!gdb[t][l][i]) continue;
01600 #ifdef DEBUG_PRINT
01601            assert(oldgdb[t][l][oi]);
01602 #endif
01603 
01604 #ifdef DEBUG_PRINT_GF_RG
01605            ( comm_service::log() << "Copying from " << oldgdb[t][l][oi]->boundingbox() 
01606              << " to " << gdb[t][l][i]->boundingbox() << " using " 
01607              << oldgdb[t][l][oi]->interiorbox() << "\n" ).flush();
01608 #endif
01609            if (gdb[t][l][i]->boundingbox().intersects(
01610                oldgdb[t][l][oi]->boundingbox())) 
01611              gdb[t][l][i]->data.copy(oldgdb[t][l][oi]->data,
01612                                      oldgdb[t][l][oi]->interiorbox());
01613          }
01614         
01615          /* Receives*/
01616          if (comm_service::dce() && pnum > 1) {
01617            for (p=0; p<pnum; p++) {
01618              if (data_recv_server[p] && data_recv_server[p][t]) {
01619                if (!data_recv_server[p][t]->received())
01620                  comm_service::serve(*data_recv_server[p][t]->req());
01621                delete data_recv_server[p][t];
01622                data_recv_server[p][t] = 0;
01623              }
01624            }
01625            GF_ReadData(t,l);
01626          }
01627         
01628          /* Now synchronize all grids and set ghost cells */
01629          int tnum = dagh_timevalue(t,l);
01630          GF_BndryUpdate(tnum,l);
01631        }  
01632      }
01633 #ifdef DEBUG_PRINT_GF_RG
01634      ( comm_service::log() << "\n************* ***************** *************\n" ).flush();
01635 #endif
01636      /* Empty GridTable after ALL levels got their data. */
01637      for (t=0;t<timesteps;t++) {
01638        List<GridDataBucketVoid*>& lgdbkt = gt->data(t);
01639        GridDataBucketVoid** gdbkt = 0;
01640        DAGHListLoop(lgdbkt, gdbkt, GridDataBucketVoid*) {
01641          GridDataBucket<DAGH_GFType>* rcvbkt =
01642            (GridDataBucket<DAGH_GFType> *) *gdbkt;
01643          delete rcvbkt; rcvbkt = 0;
01644        } DAGHEndLoop
01645        lgdbkt.empty();
01646      }
01647      for (p=0;p<pnum;p++) {
01648        if (data_recv_server[p]) {
01649          delete [] data_recv_server[p];
01650          data_recv_server[p] = 0;
01651        }
01652      }
01653    }   
01654    
01655 #ifdef DEBUG_PRINT_GF_MEMORY
01656    int newmem = 0; int newgrids=0;
01657    int oldmem = 0; int oldgrids=0;
01658    for (t=0;t<timesteps;t++) 
01659      if (gdb[t])   
01660        for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
01661          if (gdb[t][l]) 
01662            for (i=0;i<length[l];i++) 
01663              if (gdb[t][l][i]) { 
01664                newmem += gdb[t][l][i]->MemoryUsage();
01665                newgrids++;
01666              }
01667    if (oldgdb) {
01668      for (t=0;t<timesteps;t++) 
01669        if (oldgdb[t])   
01670          for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
01671            if (oldgdb[t][l]) 
01672              for (i=0;i<oldlength[l];i++) 
01673                if (oldgdb[t][l][i]) { 
01674                  oldmem += oldgdb[t][l][i]->MemoryUsage();
01675                  oldgrids++;
01676                }
01677    }
01678    ( comm_service::log() << "\n************* GF_Recompose() [" << gfid << "] *************\n"
01679      << "Memory GridDataBlocks: New=" << newmem 
01680      << " Bytes, Remaining Old=" << oldmem << " Bytes, Whole=" << newmem+oldmem 
01681      << "\nGrids: New=" << newgrids << " Remaining Old=" << oldgrids 
01682      << "\n************* ******************* *************\n"
01683      ).flush();
01684 #endif
01685 
01686    /* Delete Old Data */
01687    if (oldgdb) {
01688      for (t=0;t<timesteps;t++) {
01689        if (oldgdb[t])   {
01690          for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01691            if (oldgdb[t][l] && !reuse[l]) {
01692              for (i=0;i<oldlength[l];i++) {
01693                if (oldgdb[t][l][i]){ 
01694                  delete oldgdb[t][l][i];
01695                }
01696              }
01697              delete [] oldgdb[t][l];
01698            }
01699          }
01700          delete [] oldgdb[t];
01701        } 
01702      } 
01703      delete [] oldgdb;
01704    }
01705    delete [] oldlength;
01706    if (mgb) {
01707      for (l=0; l<levels; l++) 
01708        if (mgb[l]) delete [] mgb[l];
01709      delete [] mgb;
01710    }
01711    delete [] reuse;
01712 }
01713 
01714 /*****************************************************************************/
01715 /**** .Recompose  using a checkpoint file...****/
01716 /*****************************************************************************/
01717 template <class DAGH_GFType>
01718 void GridFunction(1)<DAGH_GFType>::GF_CheckpointRecompose() {
01719 
01720   AllocError::SetTexts("GridFunction(1)", "GF_CheckpointRecompose()");    
01721   
01722   register int t=0,l=0,i=0;
01723   
01724   const int levels = dagh.totallevels();
01725   const int timesteps = 2*time_sten_rad+1;
01726   const int crslev = dagh.coarselevel();
01727   
01728   GridDataBlock(1)<DAGH_GFType> ****oldgdb = gdb; gdb = 0;
01729   int* oldlength = new int[levels];
01730   for (i=0; i<levels; i++)
01731     oldlength[i] = length[i];
01732 
01733   gt->resettable();
01734    
01735   GridBoxList** lgbl = dagh.lgbl();
01736   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
01737     length[l] = Length(lgbl[l]);
01738      
01739   gdb = new GridDataBlock(1)<DAGH_GFType> ***[timesteps];
01740   for (t=0;t<timesteps;t++) {
01741     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
01742     if (oldgdb[t]) {
01743       gdb[t] = new GridDataBlock(1)<DAGH_GFType> **[levels];
01744       for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01745         gdb[t][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
01746         for (i=0;i<length[l];i++)
01747           gdb[t][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
01748       }
01749     }
01750   }
01751 
01752   /* destroy old storage for ghost comm */
01753   GF_DeleteGhostCommInfo();
01754   GF_DeleteGhostBndryInfo();
01755    
01756   /* destroy old storage for data comm */
01757   GF_DeleteDataCommInfo();
01758 
01759   GF_GatherGhostBndryInfo();
01760 
01761   /* Delete Old Data */
01762   if (oldgdb) {
01763     for (t=0;t<timesteps;t++) {
01764       if (oldgdb[t])   {
01765         for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01766           if (oldgdb[t][l]) {
01767             for (i=0;i<oldlength[l];i++) 
01768               if (oldgdb[t][l][i]) delete oldgdb[t][l][i];
01769             
01770             delete [] oldgdb[t][l];
01771           }
01772         }
01773         delete [] oldgdb[t];
01774       } 
01775     } 
01776     delete [] oldgdb;
01777   }
01778   delete [] oldlength;
01779 
01780   /* Allocate GDB's */
01781   {
01782     GridFunction(1)<DAGH_GFType>* gftemplate = 0;
01783     if (template_flag != DAGHNull) {
01784       gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01785     }
01786     const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
01787 
01788     register GridBox* tmpgb = 0;
01789     register int idx = 0;
01790     for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01791       if (!lgbl[l]) continue;
01792       const int mindex = dagh.GlobalMaxIndex(l)+1;
01793       const int ct = dagh.getCurrentTime(l);
01794       int tmplcti = DAGHNull;
01795 
01796       for (tmpgb=lgbl[l]->first(),idx=0;tmpgb;tmpgb=lgbl[l]->next(),idx++) {   
01797         if (template_flag != DAGHNull &&
01798             gftemplate && 
01799             gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
01800             && gftemplate->gdb[tmplcti][l])
01801           gdbtmpl = gftemplate->gdb[tmplcti][l][idx];
01802         else gdbtmpl = 0;
01803         for (int tc=0;tc<timesteps;tc++) { 
01804           t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
01805           if (!gdb[t]) continue;
01806           if (!gdb[t][l]) continue;
01807 
01808           if (!gdb[t][l][idx]) {
01809             gdb[t][l][idx] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt,
01810                                                                    interactions,
01811                                                                    idx, *tmpgb,
01812                                                                    t, l, bwidth, 
01813                                                                    bndrybboxlist[l],
01814                                                                    prolongbboxlist[l],
01815                                                                    extghostwidth,
01816                                                                    overlap,
01817                                                                    space_sten_rad,
01818                                                                    alignment, mindex,
01819                                                                    comm(t,l), 
01820                                                                    gdbtmpl);
01821             if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][idx];
01822           }
01823         }
01824       }
01825     }
01826   }
01827   
01828   /* Setup new serves */
01829   if (comm()) {
01830     GF_GatherGhostCommInfo();
01831     GF_SetUpGhostCommServers();
01832   }
01833   
01834   /* Read data from checkpoint file */
01835   if (checkpoint()) GF_CheckpointRestart();
01836 }
01837 
01838 
01839 /*****************************************************************************/
01840 /**** Recompose from memory ****/
01841 /*****************************************************************************/
01842 template <class DAGH_GFType>
01843 void GridFunction(1)<DAGH_GFType>::GF_CheckpointRecompose(strstream& ifs) {
01844 
01845   AllocError::SetTexts("GridFunction(1)",  "GF_CheckpointRecompose(strstream& ifs)");    
01846   
01847   register int t=0,l=0,i=0;
01848 
01849   const int levels = dagh.totallevels();
01850   const int timesteps = 2*time_sten_rad+1;  
01851   const int crslev = dagh.coarselevel();
01852   
01853   GridDataBlock(1)<DAGH_GFType> ****oldgdb = gdb; gdb = 0;
01854   int* oldlength = new int[levels];
01855   for (i=0; i<levels; i++)
01856     oldlength[i] = length[i];
01857   
01858   gt->resettable();
01859    
01860   GridBoxList** lgbl = dagh.lgbl();
01861   for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) 
01862     length[l] = Length(lgbl[l]);
01863   
01864   gdb = new GridDataBlock(1)<DAGH_GFType> ***[timesteps];
01865   for (t=0;t<timesteps;t++) {
01866     gdb[t] = (GridDataBlock(1)<DAGH_GFType> ***) NULL;
01867     if (oldgdb[t]) {
01868       gdb[t] = new GridDataBlock(1)<DAGH_GFType> **[levels];
01869       for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01870         gdb[t][l] = new GridDataBlock(1)<DAGH_GFType> *[length[l]];
01871         for (i=0;i<length[l];i++)
01872           gdb[t][l][i] = (GridDataBlock(1)<DAGH_GFType> *) NULL;
01873       }
01874     }
01875   }
01876 
01877   /* destroy old storage for ghost comm */
01878   GF_DeleteGhostCommInfo();
01879   GF_DeleteGhostBndryInfo();
01880   
01881   /* destroy old storage for data comm */
01882   GF_DeleteDataCommInfo();
01883   
01884   GF_GatherGhostBndryInfo();
01885 
01886   /* Delete Old Data */
01887   if (oldgdb) {
01888     for (t=0;t<timesteps;t++) {
01889       if (oldgdb[t])   {
01890         for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01891           if (oldgdb[t][l]) {
01892             for (i=0;i<oldlength[l];i++) 
01893               if (oldgdb[t][l][i]) delete oldgdb[t][l][i];
01894 
01895             delete [] oldgdb[t][l];
01896           }
01897         }
01898         delete [] oldgdb[t];
01899       } 
01900     } 
01901     delete [] oldgdb;
01902   }
01903 
01904   /* Allocate GDB's */
01905   {
01906     GridFunction(1)<DAGH_GFType>* gftemplate = 0;
01907     if (template_flag != DAGHNull) {
01908       gftemplate = (GridFunction(1)<DAGH_GFType>*) dagh.gflist[template_flag];
01909     }
01910     const GridDataBlock(1)<DAGH_GFType>* gdbtmpl = 0;
01911     
01912     register GridBox* tmpgb = 0;
01913     register int idx = 0;
01914     for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
01915       if (!lgbl[l]) continue;
01916       const int mindex = dagh.GlobalMaxIndex(l)+1;
01917       const int ct = dagh.getCurrentTime(l);
01918       int tmplcti = DAGHNull;
01919       
01920       for (tmpgb=lgbl[l]->first(),idx=0;tmpgb;tmpgb=lgbl[l]->next(),idx++) {   
01921         if (template_flag != DAGHNull &&
01922             gftemplate && 
01923             gftemplate->gdb[(tmplcti=gftemplate->dagh_timeindex(ct,l))] 
01924             && gftemplate->gdb[tmplcti][l])
01925           gdbtmpl = gftemplate->gdb[tmplcti][l][idx];
01926         else gdbtmpl = 0;
01927         for (int tc=0;tc<timesteps;tc++) { 
01928           t = (tc<=time_sten_rad ? tc+time_sten_rad : tc-time_sten_rad-1);
01929           if (!gdb[t]) continue;
01930           if (!gdb[t][l]) continue;
01931 
01932           if (!gdb[t][l][idx]) {
01933             gdb[t][l][idx] = new GridDataBlock(1)<DAGH_GFType>(*this, dagh, *gt,
01934                                                                    interactions,
01935                                                                    idx, *tmpgb,
01936                                                                    t, l, bwidth, 
01937                                                                    bndrybboxlist[l],
01938                                                                    prolongbboxlist[l],
01939                                                                    extghostwidth,
01940                                                                    overlap,
01941                                                                    space_sten_rad,
01942                                                                    alignment, mindex,
01943                                                                    comm(t,l), 
01944                                                                    gdbtmpl);
01945             if (gdbtmpl == 0 || comm(t,l)) gdbtmpl = gdb[t][l][idx];
01946           }
01947         }
01948       }
01949     }
01950   }
01951 
01952   /* Setup new serves */
01953   if (comm()) {
01954     GF_GatherGhostCommInfo();
01955     GF_SetUpGhostCommServers();
01956   }
01957   
01958   /* Read data from checkpoint file */
01959   if (checkpoint()) GF_CheckpointRestart(ifs);
01960 }
01961 
01962 /*****************************************************************************/
01963 /* Set Up Ghost Comm Servers */
01964 /*****************************************************************************/
01965 template <class DAGH_GFType>
01966 void GridFunction(1)<DAGH_GFType>::GF_SetUpGhostCommServers() {
01967   if (!comm()) return;
01968 
01969   const int pnum = comm_service::proc_num();
01970   const int me = comm_service::proc_me();  
01971   const int levels = dagh.totallevels();
01972   const int cnt = levels * DAGHMaxAxis * DAGHMaxDirs ;
01973   
01974   for (register int i=0;i<pnum;i++) {
01975     if (i == me || !ghost_recv_info[i]) continue;
01976     if (!ghost_recv_server[i]) {
01977       ghost_recv_server[i] = new GridTableGhostRcv *[cnt];
01978       for (register int c=0; c<cnt; c++) ghost_recv_server[i][c] = 0;
01979     }
01980     for (register int j=0;j<cnt;j++) {
01981       if (!ghost_recv_info[i][j]) continue;
01982       const GF_Interaction* gri = ghost_recv_info[i][j];
01983       ghost_recv_server[i][j] =
01984         new GridTableGhostRcv(*gt, (DAGHGhostTag | j), gri->tsize, i);
01985     }
01986   }
01987 }
01988 
01989 /*****************************************************************************/
01990 /**** Gather Ghost Communication Info ****/
01991 /*****************************************************************************/
01992 template <class DAGH_GFType>
01993 void GridFunction(1)<DAGH_GFType>::GF_GatherGhostCommInfo() {
01994   if (!comm()) return;
01995   
01996   const int me = comm_service::proc_me();
01997   
01998   register int t=0, l=0, c=0, i=0, p=0, m=0, k=0;
01999   for (t=0;t<=2*time_sten_rad;t++) if (gdb[t]) break;
02000   
02001   const int pnum = comm_service::proc_num();
02002   const int crslev = dagh.coarselevel();
02003   const int levels = dagh.totallevels();
02004   const int cnt1 = levels * DAGHMaxAxis * DAGHMaxDirs ;
02005   const int cnt2 = DAGHMaxAxis * DAGHMaxDirs ;
02006 
02007   if (ghost_recv_cnt) delete [] ghost_recv_cnt;
02008   ghost_recv_cnt = new short[cnt1];
02009   for (k=0;k<cnt1;k++) ghost_recv_cnt[k] = 0;
02010   
02011   List<unsigned> rsize;
02012   List<unsigned> wsize;
02013   unsigned r=0, w=0;
02014 
02015   GridDataBlock(1)<DAGH_GFType> *g = 0;
02016   GDB_Interaction *gdbi;
02017   int ngdbi;
02018   
02019   for (p=0;p<pnum;p++) {
02020     for (l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02021       for (c=0;c<cnt2;c++) {
02022         const int idx1 = l*cnt2 + c;
02023         for (i=0; i<length[l]; i++) {
02024           if (gdb[t]) if (gdb[t][l]) if (gdb[t][l][i]) {
02025             g = gdb[t][l][i];
02026             /* Write Info */
02027             if (g->gdb_write_info[p] && g->gdb_write_index[p])
02028               if ((ngdbi=g->gdb_write_index[p][c])>0 && 
02029                   (gdbi=g->gdb_write_info[p][c]))
02030                 for (m=0; m<ngdbi; m++) {
02031                   /* Allocate storage */
02032                   if (!ghost_send_info[p]) {
02033                     ghost_send_info[p] = new GF_Interaction* [cnt1];
02034                     for (k=0;k<cnt1;k++) ghost_send_info[p][k] = 0;
02035                   }
02036                   if (!ghost_send_info[p][idx1]) 
02037                     ghost_send_info[p][idx1] = new GF_Interaction;
02038 
02039 #ifdef DEBUG_PRINT_GF_COMM
02040                   ( comm_service::log() << "sendbox " << idx1 << " " 
02041                     << gdbi[m].bbox << "  " << gdbi[m].idx << endl ).flush();
02042 #endif
02043                   w = sizeof(DAGH_GFType)*gdbi[m].bbox.size();
02044                   ghost_send_info[p][idx1]->tsize += gdhdr::gdbsize(w);
02045 #ifdef DEBUG_PRINT
02046                   assert( w != 0 );
02047 #endif
02048                   wsize.add(w);
02049                 }
02050               
02051             /* Read Info */
02052             if (g->gdb_read_info[p] && g->gdb_read_index[p])
02053               if ((ngdbi=g->gdb_read_index[p][c])>0 && 
02054                   (gdbi=g->gdb_read_info[p][c]))
02055                 for (m=0; m<ngdbi; m++) {
02056                   /* Allocate storage */
02057                   if (!ghost_recv_info[p]) {
02058                     ghost_recv_info[p] = new GF_Interaction* [cnt1];
02059                     for (k=0;k<cnt1;k++) ghost_recv_info[p][k] = 0;
02060                   }
02061                   if (!ghost_recv_info[p][idx1]) 
02062                     ghost_recv_info[p][idx1] = new GF_Interaction;
02063 
02064 #ifdef DEBUG_PRINT_GF_COMM
02065                   ( comm_service::log() << "receivebox " << idx1 << " " 
02066                     << gdbi[m].bbox << "  " << gdbi[m].idx << endl ).flush();
02067 #endif
02068   
02069                   r = sizeof(DAGH_GFType)*gdbi[m].bbox.size();
02070                   ghost_recv_info[p][idx1]->tsize += gdhdr::gdbsize(r);
02071 #ifdef DEBUG_PRINT
02072                   assert( r != 0 );
02073 #endif
02074                   rsize.add(r); 
02075                 }
02076           }
02077         }
02078         if (ghost_send_info[p] && ghost_send_info[p][idx1])
02079           wsize.array(ghost_send_info[p][idx1]->size,ghost_send_info[p][idx1]->cnt);
02080         if (ghost_recv_info[p] && ghost_recv_info[p][idx1]) {
02081           rsize.array(ghost_recv_info[p][idx1]->size,ghost_recv_info[p][idx1]->cnt);
02082           if (p != me) ghost_recv_cnt[idx1] += ghost_recv_info[p][idx1]->cnt;
02083         }
02084         wsize.empty(); rsize.empty();
02085       }
02086     }
02087 #ifdef DEBUG_PRINT_GF_COMM
02088     ( comm_service::log() << "[GF_Interaction:[" << p << "]" << endl ).flush();
02089     for (k=0;k<cnt1;k++) {
02090       if (ghost_recv_info[p] && ghost_recv_info[p][k])
02091         ( comm_service::log() << "\t [Rcv[" << k << "]" 
02092                               << *ghost_recv_info[p][k] << "]"
02093                               << endl ).flush();
02094     }
02095     ( comm_service::log() << endl ).flush();
02096     for (k=0;k<cnt1;k++) {
02097       if (ghost_send_info[p] && ghost_send_info[p][k])
02098         ( comm_service::log() << "\t [Snd[" << k << "]" 
02099                               << *ghost_send_info[p][k] << "]"
02100                               << endl ).flush();
02101     }
02102     ( comm_service::log() << "]" << endl ).flush();
02103 #endif 
02104   }
02105 }
02106 
02107 /*****************************************************************************/
02108 /**** Swap storage for time levels  ****/
02109 /*****************************************************************************/
02110 template <class DAGH_GFType>
02111 void GridFunction(1)<DAGH_GFType>::GF_SwapTimeLevels(const int l, 
02112                                                      const int t1, 
02113                                                      const int t2) {
02114   const int ti1 = dagh_timeindex(t1,l); 
02115   const int ti2 = dagh_timeindex(t2,l); 
02116 
02117   if (ti1 == ti2) return;
02118 
02119 #ifdef DEBUG_PRINT
02120   assert(gdb[ti1] && gdb[ti2]);
02121 #endif
02122 
02123   GridDataBlock(1)<DAGH_GFType>** gdb1 = gdb[ti1][l];
02124   GridDataBlock(1)<DAGH_GFType>** gdb2 = gdb[ti2][l];
02125 
02126   if (gdb1) {
02127     for (register int i=0;i<length[l];i++)
02128       if (gdb1[i]) gdb1[i]->timenum = ti2;
02129   }
02130   if (gdb2) {
02131     for (register int i=0;i<length[l];i++)
02132       if (gdb2[i]) gdb2[i]->timenum = ti1;
02133   }
02134   gdb[ti1][l] = gdb2;
02135   gdb[ti2][l] = gdb1;
02136 }
02137 
02138 /* Move next -> current && current -> previous && previous -> next */
02139 template <class DAGH_GFType>
02140 void GridFunction(1)<DAGH_GFType>::GF_CycleTimeLevels(const int l) {
02141   if (time_sten_rad == 0)  return;
02142 
02143   const int cti = dagh_timeindex(dagh.getCurrentTime(l),l);
02144   const int pti = dagh_timeindex(dagh.getPreviousTime(l),l);
02145   const int nti = dagh_timeindex(dagh.getNextTime(l),l);
02146 
02147 #ifdef DEBUG_PRINT
02148   assert(gdb[cti] && gdb[pti] && gdb[nti]);
02149 #endif
02150 
02151   GridDataBlock(1)<DAGH_GFType>** cgdb = gdb[cti][l];
02152   GridDataBlock(1)<DAGH_GFType>** pgdb = gdb[pti][l];
02153   GridDataBlock(1)<DAGH_GFType>** ngdb = gdb[nti][l];
02154 
02155   register int i = 0;
02156 
02157   if (cgdb && (cti != pti)) {
02158     for (i=0;i<length[l];i++)
02159       if (cgdb[i]) cgdb[i]->timenum = pti;
02160   }
02161   if (pgdb && (pti != nti)) {
02162     for (i=0;i<length[l];i++)
02163       if (pgdb[i]) pgdb[i]->timenum = nti;
02164   }
02165   if (ngdb && (nti != cti)) {
02166     for (i=0;i<length[l];i++)
02167       if (ngdb[i]) ngdb[i]->timenum = cti;
02168   }
02169   if (cti != nti) gdb[cti][l] = ngdb;
02170   if (pti != cti) gdb[pti][l] = cgdb;
02171   if (nti != pti) gdb[nti][l] = pgdb;
02172 }
02173 
02174 /*****************************************************************************/
02175 /**** BBox Queries ****/
02176 /*****************************************************************************/
02177 template <class DAGH_GFType>
02178 void GridFunction(1)<DAGH_GFType>::intbboxlist(BBoxList &bbl, const int l) {
02179   if (!bbl.isempty()) bbl.empty();
02180   register int t = 0, i = 0;
02181   for (t=0;t<=2*time_sten_rad;t++) if (gdb[t]) break;
02182   for (i=0; i<length[l]; i++)
02183     if (gdb[t][l][i]) bbl.add(gdb[t][l][i]->interiorbox());
02184 }
02185 
02186 template <class DAGH_GFType>
02187 void GridFunction(1)<DAGH_GFType>::databboxlist(BBoxList &bbl, const int l) {
02188   if (!bbl.isempty()) bbl.empty();
02189   register int t = 0, i = 0;
02190   for (t=0;t<=2*time_sten_rad;t++) if (gdb[t]) break;
02191   for (i=0; i<length[l]; i++)
02192     if (gdb[t][l][i]) bbl.add(gdb[t][l][i]->databox());
02193 }
02194 
02195 template <class DAGH_GFType>
02196 void GridFunction(1)<DAGH_GFType>::boundingbboxlist(BBoxList &bbl, const int l) { 
02197   if (!bbl.isempty()) bbl.empty();
02198   register int t = 0, i = 0;
02199   for (t=0;t<=2*time_sten_rad;t++) if (gdb[t]) break;
02200   for (i=0; i<length[l]; i++)
02201     if (gdb[t][l][i]) bbl.add(gdb[t][l][i]->boundingbox());
02202 }
02203 
02204 
02205 /*****************************************************************************/
02206 /**** Checkpoint/Restart ****/
02207 /*****************************************************************************/
02208 template <class DAGH_GFType>
02209 void GridFunction(1)<DAGH_GFType>::GF_Checkpoint(ofstream& ofs) {
02210 #ifdef DEBUG_PRINT
02211   assert (dagh.chkpt_restart() && checkpoint());
02212 #endif
02213 
02214   const int crslev = dagh.coarselevel();
02215   const short levels = dagh.totallevels();
02216   const short timesteps = 2*time_sten_rad + 1;
02217   ofs.write((char*)&levels,sizeof(short));
02218   int maxlength = 0;
02219   for (register int i=0; i<levels; i++) 
02220     if (maxlength<length[i]) maxlength=length[i];
02221   ofs.write((char*)&maxlength,sizeof(int));
02222   ofs.write((char*)&timesteps,sizeof(short));
02223 
02224   const int dirnum = levels*maxlength*timesteps;
02225   streampos* chkptdir = new streampos[dirnum];
02226   streampos chkptdirpos = ofs.tellp();
02227   ofs.write((char*)chkptdir,sizeof(streampos)*dirnum);
02228 
02229   for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02230     for (register int t=0; t<timesteps; t++) {
02231       for (register int c=0; c<maxlength; c++) {
02232         chkptdir[c*levels*timesteps+l*timesteps+t] = DAGHNull;
02233         if (gdb[t]) if (gdb[t][l]) if (c<length[l] && gdb[t][l][c]) {
02234           chkptdir[c*levels*timesteps+l*timesteps+t] = ofs.tellp();
02235           ofs << *gdb[t][l][c];
02236         }
02237       }
02238     }
02239   }
02240   streampos curpos = ofs.tellp();
02241   ofs.seekp(chkptdirpos);
02242   ofs.write((char*)chkptdir,sizeof(streampos)*dirnum);
02243   ofs.seekp(curpos);
02244   if (chkptdir) delete [] chkptdir;
02245 }
02246 
02247 template <class DAGH_GFType>
02248 int GridFunction(1)<DAGH_GFType>::GF_Checkpoint_StrStream_Memory() {
02249 #ifdef DEBUG_PRINT
02250   assert (checkpoint());
02251 #endif
02252   const int crslev = dagh.coarselevel();
02253   const short levels = dagh.totallevels();
02254   const short timesteps = 2*time_sten_rad + 1;
02255   int maxlength = 0;
02256   for (register int i=0; i<levels; i++) 
02257     if (maxlength<length[i]) maxlength=length[i];
02258   const int dirnum = levels*maxlength*timesteps;
02259 
02260   int mem = 0;
02261   mem += 2*sizeof(short)+sizeof(int);
02262   mem += sizeof(streampos)*dirnum;
02263   for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02264     int tc = dagh_timeindex(dagh.getCurrentTime(l),l);
02265     for (register int t=0; t<timesteps; t++) 
02266       for (register int c=0; c<maxlength; c++) 
02267         if (tc==t && gdb[t]) if (gdb[t][l]) if (c<length[l] && gdb[t][l][c]) 
02268           mem += gdb[t][l][c]->databox().size()*sizeof(DAGH_GFType)+
02269                  sizeof(BBox)+2*sizeof(short);    
02270   }
02271   return mem;
02272 }
02273 
02274 template <class DAGH_GFType>
02275 void GridFunction(1)<DAGH_GFType>::GF_Checkpoint(strstream& ofs) {
02276 #ifdef DEBUG_PRINT
02277   assert (dagh.chkpt_restart() && checkpoint());
02278 #endif
02279   
02280   const int crslev = dagh.coarselevel();
02281   const short levels = dagh.totallevels();
02282   const short timesteps = 2*time_sten_rad + 1;
02283   ofs.write((char*)&levels,sizeof(short));
02284   int maxlength = 0;
02285   for (register int i=0; i<levels; i++) 
02286     if (maxlength<length[i]) maxlength=length[i];
02287   ofs.write((char*)&maxlength,sizeof(int));
02288   ofs.write((char*)&timesteps,sizeof(short));
02289   
02290   const int dirnum = levels*maxlength*timesteps;
02291   streampos* chkptdir = new streampos[dirnum];
02292   streampos chkptdirpos = ofs.tellp();
02293   ofs.write((char*)chkptdir,sizeof(streampos)*dirnum);
02294 
02295   for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02296     int tc = dagh_timeindex(dagh.getCurrentTime(l),l);
02297     for (register int t=0; t<timesteps; t++) {
02298       for (register int c=0; c<maxlength; c++) {
02299         chkptdir[c*levels*timesteps+l*timesteps+t] = DAGHNull;
02300         if (tc==t && gdb[t]) if (gdb[t][l]) if (c<length[l] && gdb[t][l][c]) {
02301           chkptdir[c*levels*timesteps+l*timesteps+t] = ofs.tellp();
02302           ofs << *gdb[t][l][c];
02303         }
02304       }
02305     }
02306   }
02307   streampos curpos = ofs.tellp();
02308 
02309   /* Set get-pointer on current end to allow seekp(curpos)     */
02310   /* Absolutely necessary for newer strstreams implementations */
02311   ofs.seekg((streampos)0,ios::end);
02312 
02313   ofs.seekp(chkptdirpos);
02314   ofs.write((char*)chkptdir,sizeof(streampos)*dirnum);   
02315   ofs.seekp(curpos);
02316   if (chkptdir) delete [] chkptdir;
02317 }
02318 
02319 template <class DAGH_GFType>
02320 void GridFunction(1)<DAGH_GFType>::GF_CheckpointRestart(int proc) {
02321 #ifdef DEBUG_PRINT
02322   assert (dagh.chkpt_restart() && checkpoint());
02323 #endif
02324 
02325   const int num = comm_service::proc_num();
02326   const int me = comm_service::proc_me();
02327   const int oldpnum = dagh.chkpt_pnum();
02328   const int crslev = dagh.coarselevel();
02329   const int levels = dagh.totallevels();
02330   const int timesteps = 2*time_sten_rad + 1;
02331   
02332   if (oldpnum == num) { /* Old dist == new dist */
02333     register streampos pos;
02334     
02335     ifstream ifs;
02336     int eflag = dagh.DAGH_GetGFChkptIStream(me,gfname,gfid,ifs);
02337     if (eflag == DAGHFalse) return;
02338     
02339     short hislevels = 0, histsteps = 0; 
02340     int hismaxlength = 0;
02341     ifs.read((char*)&hislevels,sizeof(short));
02342 #ifdef DEBUG_PRINT
02343     assert (hislevels == levels);
02344 #endif
02345     ifs.read((char*)&hismaxlength,sizeof(int));
02346     ifs.read((char*)&histsteps,sizeof(short));
02347     
02348     const int dirnum = hislevels*hismaxlength*histsteps;
02349     streampos* chkptdir = new streampos[dirnum];
02350     ifs.read((char*)chkptdir,sizeof(streampos)*dirnum);    
02351     for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02352       for (register int t=0; t<timesteps; t++) {
02353         for (register int c=0; c<hismaxlength; c++) {
02354           if (gdb[t]) if (gdb[t][l]) if (c<length[l] && gdb[t][l][c] && t < histsteps &&
02355              (pos=chkptdir[c*hislevels*histsteps+l*histsteps+t])!=(streampos) DAGHNull) {
02356             ifs.seekg(pos);
02357             ifs >> *gdb[t][l][c];
02358           } 
02359         }
02360       }
02361     }
02362     if (chkptdir) delete [] chkptdir;
02363     dagh.DAGH_CloseChkptIStream(ifs);
02364   }
02365   else { /* A new dist. */
02366     register streampos pos;
02367 
02368     if (proc<0) proc=me;
02369     ifstream ifs;
02370     int eflag = dagh.DAGH_GetGFChkptIStream(proc,gfname,gfid,ifs);
02371     if (eflag == DAGHFalse) return;
02372     
02373     short hislevels = 0, histsteps = 0; 
02374     int hismaxlength = 0;
02375     ifs.read((char*)&hislevels,sizeof(short));
02376 #ifdef DEBUG_PRINT
02377     assert (hislevels == levels);
02378 #endif
02379     ifs.read((char*)&hismaxlength,sizeof(int));
02380     ifs.read((char*)&histsteps,sizeof(short));
02381     
02382     const int dirnum = hislevels*hismaxlength*histsteps;
02383     streampos* chkptdir = new streampos[dirnum];
02384     ifs.read((char*)chkptdir,sizeof(streampos)*dirnum);    
02385     for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02386       for (register int t=0; t<timesteps; t++) {
02387         for (register int hisc=0; hisc<hismaxlength; hisc++) {
02388           if (gdb[t]) if (gdb[t][l]) if (t<histsteps &&
02389              (pos=chkptdir[hisc*hislevels*histsteps+l*histsteps+t])!=(streampos) DAGHNull) {
02390             ifs.seekg(pos);
02391 
02392             short histimenum, hislevelnum;
02393             ifs.read((char*)&histimenum,sizeof(short));
02394             ifs.read((char*)&hislevelnum,sizeof(short));
02395 //          ( comm_service::log() << "Read in: " << hisc << "  " << " on l=" << hislevelnum 
02396 //            << " for t=" << histimenum << "\n" ).flush();
02397    
02398 #ifdef DEBUG_PRINT
02399             assert (histimenum==t && hislevelnum == l);
02400 #endif
02401             GridData(1)<DAGH_GFType> gdbhelp;       
02402             ifs >> gdbhelp;
02403             for (register int c=0; c<length[l]; c++) 
02404               if (gdb[t][l][c]) {
02405                 BBox bb = gdbhelp.bbox();
02406                 bb.grow(-extghostwidth);                
02407                 bb.shrinkupperbydim(overlap);
02408                 bb.shrinkbydim(space_sten_rad);   
02409                 gdb[t][l][c]->data.copy(gdbhelp,bb);
02410               }
02411           } 
02412         }
02413         /* Now synchronize all grids and set ghost cells */
02414         if (oldpnum-1 == proc) {
02415           int tnum = dagh_timevalue(t,l);
02416           GF_BndryUpdate(tnum,l);
02417         }
02418       }
02419     }
02420     if (chkptdir) delete [] chkptdir;
02421     dagh.DAGH_CloseChkptIStream(ifs);
02422   }
02423 }
02424 
02425 template <class DAGH_GFType>
02426 void GridFunction(1)<DAGH_GFType>::GF_CheckpointRestart(strstream& ifs) {
02427 #ifdef DEBUG_PRINT
02428   assert (dagh.chkpt_restart() && checkpoint());
02429 #endif
02430 
02431   const int crslev = dagh.coarselevel();
02432   const int levels = dagh.totallevels();
02433   const int timesteps = 2*time_sten_rad + 1;
02434   
02435   register streampos pos;
02436    
02437   int eflag = dagh.DAGH_GetGFChkptStrStream(gfname,gfid,ifs);
02438   if (eflag == DAGHFalse) return;
02439    
02440   short hislevels = 0, histsteps = 0; 
02441   int hismaxlength = 0;
02442   ifs.read((char*)&hislevels,sizeof(short));
02443 #ifdef DEBUG_PRINT
02444   assert (hislevels == levels);
02445 #endif
02446   ifs.read((char*)&hismaxlength,sizeof(int));
02447   ifs.read((char*)&histsteps,sizeof(short));
02448   
02449   const int dirnum = hislevels*hismaxlength*histsteps;
02450   streampos* chkptdir = new streampos[dirnum];
02451   ifs.read((char*)chkptdir,sizeof(streampos)*dirnum);    
02452   for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02453     int tc = dagh_timeindex(dagh.getCurrentTime(l),l);
02454     for (register int t=0; t<timesteps; t++) {
02455       for (register int c=0; c<hismaxlength; c++) {
02456         if (tc==t && gdb[t]) if (gdb[t][l]) if (c<length[l] && gdb[t][l][c])
02457           if (t < histsteps &&
02458               (pos=chkptdir[c*hislevels*histsteps+l*histsteps+t])!=(streampos) DAGHNull) {
02459             ifs.seekg(pos);
02460             ifs >> *gdb[t][l][c];
02461           }     
02462           else 
02463             gdb[t][l][c]->griddata() = 0;
02464       }
02465     }
02466   }
02467   
02468   if (chkptdir) delete [] chkptdir;
02469 }
02470 
02471 /*****************************************************************************/
02472 /**** Some debugging ****/
02473 /*****************************************************************************/
02474 template <class DAGH_GFType>
02475 ostream &GridFunction(1)<DAGH_GFType>::GF_DebugPrintIntData(ostream &os,
02476                                                             const int time, 
02477                                                             const int level) {
02478   os << *this;
02479   os << "(" << time << ") ";
02480   os << "(" << level << ") ";
02481   os << "\n";
02482   register const int t = dagh_timeindex(time,level);
02483   register const int l = level;
02484   for (register int i=0; i<length[l]; i++) { 
02485     if (gdb[t][l][i]) {
02486       os << "Interior: " << gdb[t][l][i]->boundingbox() << "\n";
02487       GridData(1)<DAGH_GFType> tmpgd(gdb[t][l][i]->boundingbox());
02488       tmpgd = gdb[t][l][i]->griddata();
02489       os << tmpgd;
02490       os << "\n";
02491     }
02492   }
02493   return os;
02494 }
02495 
02496 template <class DAGH_GFType>
02497 ostream &GridFunction(1)<DAGH_GFType>::GF_DebugPrintData(ostream &os, 
02498                                                          const int time, 
02499                                                          const int level) {
02500   os << *this;
02501   os << "(" << time << ") ";
02502   os << "(" << level << ") ";
02503   os << "\n";
02504   register const int t = dagh_timeindex(time,level);
02505   register const int l = level;
02506   for (register int i=0; i<length[l]; i++)
02507     if (gdb[t][l][i]) os << gdb[t][l][i]->griddata();
02508   return os;
02509 }
02510 
02511 template <class DAGH_GFType>
02512 ostream &GridFunction(1)<DAGH_GFType>::GF_DebugPrintDataBlk(ostream &os,
02513                                                             const int time, 
02514                                                             const int level) {
02515   os << *this;
02516   os << "(" << time << ") ";
02517   os << "(" << level << ") ";
02518   os << "\n";
02519   register const int t = dagh_timeindex(time,level);
02520   register const int l = level;
02521   for (register int i=0; i<length[l]; i++)
02522     if (gdb[t][l][i]) os << *gdb[t][l][i] << "\n";
02523   return os;
02524 }
02525 
02526 /*****************************************************************************/
02527 /**** Overloaded stdout ****/
02528 /*****************************************************************************/
02529 
02530 template <class DAGH_GFType>
02531 ostream&  operator << (ostream& os, const GridFunction(1)<DAGH_GFType>& gf) {
02532 
02533   if (&gf == (GridFunction(1)<DAGH_GFType> *) NULL) return os;
02534   
02535   os << "GridFunction: " << gf.GF_Name();
02536   
02537   return os;
02538 }
02539 
02540 
02541 template <class DAGH_GFType>
02542 ostream &GridFunction(1)<DAGH_GFType>::GF_DebugPrintTheData(ostream &os) {
02543     
02544   const int crslev = dagh.coarselevel();
02545   const int levels = dagh.totallevels();
02546   const int timesteps = 2*time_sten_rad+1;
02547 
02548   os << "******* THE DATA *********" << endl;
02549   if (gdb) {
02550     for (register int t=0;t<timesteps;t++) {
02551       if (gdb[t])   {
02552         for (register int l=Max(crslev,crslev+loffset); l<Min(levels,levels+loffset); l++) {
02553           if (gdb[t][l]) {
02554             for (register int i=0;i<length[l];i++) {
02555               if (gdb[t][l][i]){ 
02556                 os << "gdb[ " << t << "][" 
02557                    << l << "][" << i << "]:" << endl;
02558                 os << *gdb[t][l][i] << endl;
02559               }
02560             }
02561           }
02562         }
02563       } 
02564     } 
02565   }
02566   os << "******* END THE DATA *********" << endl;
02567   return os;
02568 }
02569 
02570 #include "GridFunctionComm1.h"
02571 #include "GridFunctionFuncs1.h"
02572 #include "GridFunctionOps1.h"
02573 #include "GridFunctionOpsRed1.h"
02574 #include "GridFunctionBndry1.h"
02575 #include "GridFunctionIO1.h"
02576 
02577 #endif


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04