Department of Scientific Computing   
Institute for Numerical Simulation   
University of Bonn   
Documentation
Download
Programming References
Bug Reports / Suggestions
FAQ
Authors
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AdaptiveData.hpp

00001 #ifndef _ADAPTIVE_DATA_
00002 # define _ADAPTIVE_DATA_
00003 
00004 #include "Refine.hpp"
00005 #include "Adaptive1D.hpp"
00006 #include "AdaptiveDataArray.hpp"
00007 #include "Extensions.hpp"
00008 #include "UniformData.hpp"
00009 #include "Function.hpp"
00010 #include "SparseMatrixIO.hpp"
00011 
00012 template<int DIM>
00013 struct AdaptiveGrid ;
00014 
00017 template<int DIM> 
00018 struct AdaptiveData{
00019  
00020   typedef int* BCType[DIM] ;
00021 
00022 public:
00024          AdaptiveData()        ;
00026          AdaptiveData(AdaptiveGrid<DIM> *G) ;
00027         ~AdaptiveData()        ;
00028 
00030   void   Attach(AdaptiveGrid<DIM> *G) ;
00032   void   DeAttach()  ;
00033 
00035   size_t Size() ;
00036 
00038   size_t AllocatedEntries() ;
00039 
00044   void   SetRefine() ;
00045 
00046   // Refine
00047   void   Refine() ;
00048   void   Resize() ;
00049   // if (flag>0) (*this)-- ; else (*this)=CounterInitValue ; 
00050   void   UpdateRefineCounters(AdaptiveData<DIM> flags, int CounterInitValue) ;
00051   //
00052   void   Bining(double *eps, int Keps, int *count, AdaptivityCriterion *R) ; 
00053                                   // counts the number of waveletcoefficients c (scaled dependent on the level according to *R) in the buckets 
00054                                   // (c < eps[-Keps]) , (eps[-Keps]<= c < eps[-Keps+1]), .... , 
00055                                   //                    (eps[Keps-1]<= c < eps[Keps])  , ( eps[Keps] <= c)
00056 
00057   //
00058   //  Access to numerical values
00059   //
00060 
00063   void   FromUniform(UniformData<DIM>   *A, int *J) ;
00064   void   FromUniform(Matrix<double,DIM> *A, int *J) ;
00065 
00067   void   ToUniform  (UniformData<DIM>   *A, int *J) ;
00068   void   ToUniform  (Matrix<double,DIM> *A, int *J, int flag=0) ;
00069 
00070   // Special:
00072   double *GetP(int *l,int *t) ;
00074   int    Set(int *l,int *t,const double a) ;
00076   double Get(int *l,int *t) ;
00078   void   Set(int *l,const double a) ;
00080   void   Set(int dir, int k, int s, const double a) ; 
00081   void   Set(int  l,const double)   ;        // Set all coef of Level *k with k[0]>=l or k[1] >=l to a 
00087   void   Get(int *l,int *t,int dir, AdaptiveB *B, int leftrightall=0) ;
00090   void   Set(int *l,int *t,int dir, AdaptiveB *B, int leftrightall=0, bool add=false) ;
00091 
00094   void   ReadSlice (AdaptiveData<DIM+1> *X) ;
00098   void   WriteSlice(AdaptiveData<DIM+1> *X, bool add=false) ;
00099 
00106   void   SetFunction(Function *F, bool boundaryonly=false, bool notransform=false) ;
00107   
00131   void   SetBoundaryValueFunction(AdaptiveData<DIM-1> *F[DIM][2] , int BC[DIM][2] , bool ContinuousDirichletValues=false) ;
00132 
00133   void   SetDirichletBoundaryValues(AdaptiveData<DIM-1> *F[DIM][2] , int BC[DIM][2] , bool ContinuousDirichletValues=false) ;
00134   void   SetNeumannBoundaryValues  (AdaptiveData<DIM-1> *F[DIM][2] , int BC[DIM][2]) ;
00135   void   SetNeumannFaces           (AdaptiveData<DIM-1> *F[DIM][2] , int BC[DIM][2]) ;  // internal function, Neumann-values must have homogeneous normal derivatives
00136   AdaptiveData<DIM-3>* GetDi2Di1Fi0k0(AdaptiveData<DIM-1> *F[DIM][2] , int i2,int k2, int i1, int k1, int i0, int k0) ; // internal
00137   void   ComputeDerivatives        (AdaptiveData<DIM-1> *F[DIM][2] , int BC[DIM][2], int FD, int codim) ; // internal function
00138   void   InitCodimIteration        (int *t, int *n, int *f, int codim, Wavelets *W, int *tr,int *a, int *e) ;     // internal
00139   void   AddBiTriLinearContributionCodim2(int *l,int *t,int *n,int *f,int codim, AdaptiveData<DIM-1> *F[DIM][2],int BC[DIM][2]) ;// internal
00140   void   AddBiTriLinearContribution      (int *l,int *t,int *n,int *f,int codim, AdaptiveData<DIM-1> *F[DIM][2],int BC[DIM][2]) ;// internal
00141 
00142   void   Clear()  ;
00143 
00145   double Max()    ;
00147   double Min()    ;
00149   double MaxAbs() ;
00151   double Sum()    ;
00153   double SumAbs() ;
00155   double SumSqr() ;
00156 
00161   double LpNorm  (AdaptiveData<DIM> *Tmp, double p) ;
00163   double LmaxNorm(AdaptiveData<DIM> *Tmp) ;
00165   double L2Norm  (AdaptiveData<DIM> *Tmp) ;
00167   double L1Norm  (AdaptiveData<DIM> *Tmp) ;
00169   double Integrate() ;  
00171   double InnerProd(AdaptiveData<DIM> *X) ;
00172 
00174   void   Set(const double a)   ;
00175   void   SetDiagonalMatrix(const double p, const double alpha) ; // diag(l,t)=1+alpha*sum_i 2^(l_i p)
00177   void   Copy(AdaptiveData<DIM> *X) ;
00179   void   Abs(AdaptiveData<DIM> *X)  ;
00181   void   Pow(AdaptiveData<DIM> *X, double p) ; // (*this)=pow(X,p) ;
00183   void   Sqr(AdaptiveData<DIM> *X)  ;
00184 
00185   void   PPlus(const double a) ;
00187   void   PPlus(AdaptiveData<DIM> *X  ) ;
00189   void   PPlus(const double a , AdaptiveData<DIM> *X) ;
00191   void   Add(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ;
00193   void   Add(const double a , AdaptiveData<DIM> *X , const double b , AdaptiveData<DIM> *Y) ;
00195   void   Add(const double a , AdaptiveData<DIM> *X , const double b , AdaptiveData<DIM> *Y , const double c , AdaptiveData<DIM> *Z) ;
00197   void   Add(const double a , AdaptiveData<DIM> *X , const double b , AdaptiveData<DIM> *Y , const double c , AdaptiveData<DIM> *Z , 
00198              const double d , AdaptiveData<DIM> *Q) ;
00200   void   Add(const double a , AdaptiveData<DIM> *X , const double b , AdaptiveData<DIM> *Y , const double c , AdaptiveData<DIM> *Z ,
00201              const double d , AdaptiveData<DIM> *Q , const double f , AdaptiveData<DIM> *R) ;
00202 
00204   void   MMinus(AdaptiveData<DIM> *X) ;
00206   void   MMinus(const double a, AdaptiveData<DIM> *X) ;
00208   void   Sub(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ;
00209 
00211   void   Mul(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ; 
00213   void   Mul(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , double f) ;
00214   //void   Mul(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y)  ;
00216   void   Mul(AdaptiveData<DIM> *X , double f) ;
00218   void   Mul(double f) ;
00219   void   XplusYmalZ (AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) ;
00220   void   XminusYmalZ(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) ;
00221  
00222   void   Div(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ; // (*this):= (*X) / (*Y)  element by element
00223   void   Div(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y)  ;
00224 
00266   void   ApplyOp  (int *BCT , AdaptiveData<DIM> *X,int dir,unsigned int op) ;
00268   void   ApplyOp  (AdaptiveData<DIM> *X,int dir,unsigned int op) ;
00269   // multiply by diagonal matrix D_(l,t),(l,t) = \sum_i 2^(p l_i)
00270   void   ApplyDiagonal(AdaptiveData<DIM> *X , double p) ;
00271   // WENO
00272   void   ApplyWENO(int *BCT , AdaptiveData<DIM> *X, AdaptiveData<DIM> *RoeSpeed, int dir,unsigned int op) ;
00273 
00274   // Projection
00275   double ZeroMean() ;
00276 
00277 
00278   //
00279   //   IO
00280   // 
00281 
00287   void   WriteUDF(const char *name, UniformData<DIM> *M, AdaptiveData<DIM> *Tmp=NULL, bool CastToFloat=false) ;
00289   void   WriteUDF(const char *name,             int  *L, AdaptiveData<DIM> *Tmp=NULL, bool CastToFloat=false) ;
00291   void   WriteUDF(const char *name,             int   L, AdaptiveData<DIM> *Tmp=NULL, bool CastToFloat=false) ;
00292 
00297   void   WriteSparse(const char *name, AdaptiveData<DIM> **M, int N, bool CastToFloat=false, AdaptivityCriterion *R=NULL) ;
00299   void   WriteSparse(const char *name, AdaptivityCriterion *R=NULL) ;
00303   void   ReadSparse (const char *name, AdaptiveData<DIM> **M, int N, int *which) ;
00305   void   ReadSparse(const char *name) ;
00306 
00307   //
00308   //  Boundary Conditions
00309   //
00310 
00312   void   SetBoundaryConditions(AdaptiveData<DIM> *X) ;
00313   void   SetBoundaryConditions(BCType bc) ;
00315   void   SetBoundaryConditions(int bc[DIM][2]) ;
00316   // Set boundary conditions with respect to coordinate direction dir
00317   void   SetBoundaryConditions(int dir,int *bc) ;
00318   // Set boundary conditions with respect to coordinate direction dir
00319   void   SetBoundaryConditions(int dir,int bc0,int bc1) ;
00321   bool   SameBoundaryConditions(AdaptiveData<DIM> *X) ;
00322   
00323   // Compatibility Check for multi-array operations like A+B,A+B+C and so on 
00324   void   CheckBC(AdaptiveData<DIM> *X) ;
00325   void   CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ;
00326   void   CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) ;
00327   void   CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q) ;
00328   void   CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q , AdaptiveData<DIM> *R) ;
00329 
00330   //
00331   void   Compatible(AdaptiveData<DIM> *X) ;
00332   void   Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y) ;
00333   void   Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z) ;
00334   void   Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z, AdaptiveData<DIM> *Q) ;
00335   void   Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z, AdaptiveData<DIM> *Q, AdaptiveData<DIM> *R) ;
00336 
00337   //
00338   void   CheckAdaptiveGrid(AdaptiveData<DIM> *X) ;
00339   void   CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) ;
00340   void   CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) ;
00341   void   CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q) ;
00342   void   CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q , AdaptiveData<DIM> *R) ;
00343 
00345   void   CopyExtensions(AdaptiveData<DIM> *X) ;
00346 
00347   // numerical data
00348   AdaptiveDataArray<DIM>  *ba ;
00349   // adaptive grid
00350   AdaptiveGrid<DIM>       *G  ;
00351   // boundary conditions, filter coefficients and augmentions for singular linear systems
00352   Extensions<DIM>          Ext ;
00353 } ;
00354 
00355 
00356 //
00357 //
00358 //
00359 template<>
00360 struct AdaptiveData<0> {
00361 
00362    AdaptiveData()                    {G=NULL;}
00363    AdaptiveData(AdaptiveGrid<0> *Gr) {G=Gr;}
00364   ~AdaptiveData() {;}
00365  
00366   void   ReadSlice (AdaptiveData<1> *X)                 ;
00367   void   WriteSlice(AdaptiveData<1> *X, bool add=false) ;
00368 
00369   void   Add (const double a , AdaptiveData<0> *X , const double b , AdaptiveData<0> *Y) {data=a*X->data+b*Y->data;}
00370   void   Copy(AdaptiveData<0> *X) {data=X->data;}
00371 
00372   double*GetP(int * ,int * )                {return &data;}
00373   int    Set (int * ,int * ,const double a) {data=a; return 0;}
00374   double Get (int * ,int * )                {return data;}
00375 
00376   AdaptiveGrid<0> *G ;
00377   // numerical data
00378   double           data ;
00379 } ;
00380 
00381 
00382 #include "AdaptiveGrid.hpp"
00383 
00385 //                       //
00386 // Data::Implementations //
00387 //                       //
00389 
00390 // for specialization
00391 void AdaptiveData<0>::ReadSlice (AdaptiveData<1> *X) { 
00392   assert(G->SliceParent==X->G); 
00393   data=X->Get(&G->Slicel,&G->Slicet); 
00394 }
00395 
00396 void AdaptiveData<0>::WriteSlice(AdaptiveData<1> *X, bool add) { 
00397   assert(G->SliceParent==X->G); 
00398   double *p=X->GetP(&G->Slicel,&G->Slicet); 
00399   if (add) (*p)+=data; 
00400   else     (*p) =data;
00401 }
00402 
00403 //
00404 // general
00405 //
00406 template<int DIM>
00407 AdaptiveData<DIM>::AdaptiveData() { 
00408   G=NULL ;
00409   ba=new AdaptiveDataArray<DIM> ; 
00410 }
00411 
00412 
00413 template<int DIM>
00414 AdaptiveData<DIM>::AdaptiveData(AdaptiveGrid<DIM> *Gr) {
00415   G=NULL ;
00416   ba=new AdaptiveDataArray<DIM> ; 
00417   Attach(Gr) ;
00418 }
00419 
00420 
00421 template<int DIM>
00422 AdaptiveData<DIM>::~AdaptiveData() { 
00423   DeAttach() ; 
00424   delete ba        ;
00425 }
00426 
00427 
00428 template<int DIM>
00429 void AdaptiveData<DIM>::Clear(){ ba->Clear() ;}
00430 
00431 
00432 template<int DIM>
00433 void AdaptiveData<DIM>::Attach(AdaptiveGrid<DIM> *Gr) {
00434   assert((G==NULL)&&(Gr!=NULL)) ;
00435   G=Gr ;
00436   G->ResizeGroup.Insert(this)  ;
00437   G->RefineGroup.Remove(this)  ;
00438   ba->Resize(&G->CounterArray) ;
00439   Ext.WC=G->WC ;
00440   Ext.XA=G->XA ;
00441   Ext.XE=G->XE ;
00442 }
00443 
00444 
00445 template<int DIM>
00446 void AdaptiveData<DIM>::DeAttach() {
00447   assert(G!=NULL) ;
00448   G->ResizeGroup.Remove(this) ;
00449   G->RefineGroup.Remove(this) ;
00450   G=NULL  ;
00451   Ext.WC=NULL ;
00452   Ext.XA=Ext.XE=NULL ;
00453 }
00454 
00455 template<int DIM>
00456 size_t AdaptiveData<DIM>::Size() {
00457   if (G==NULL) std::cout <<"AdaptiveData not attached to a grid\n";
00458   else return G->Size() ;
00459 }
00460 
00461 template<int DIM>
00462 size_t AdaptiveData<DIM>::AllocatedEntries() {
00463   int reserved,used ;
00464   ba->Memory(&reserved,&used) ;
00465   return (size_t) reserved    ;
00466 }
00467 
00468 template<int DIM>
00469 void AdaptiveData<DIM>::SetRefine() {
00470   assert(G!=NULL) ;
00471   G->ResizeGroup.Remove(this) ;
00472   G->RefineGroup.Insert(this) ;
00473 }
00474 
00475 template<int DIM>
00476 void AdaptiveData<DIM>::SetBoundaryConditions(AdaptiveData<DIM> *X) {
00477   Ext.SetBoundaryConditions(X->Ext.BC) ;
00478   G->SetPeriodicConditions(Ext.BC) ;
00479 }
00480 
00481 template<int DIM>
00482 void AdaptiveData<DIM>::SetBoundaryConditions(int bc[DIM][2]) {
00483   Ext.SetBoundaryConditions(bc) ;
00484   G->SetPeriodicConditions(Ext.BC) ;
00485 }
00486 
00487 template<int DIM>
00488 void AdaptiveData<DIM>::SetBoundaryConditions(int d,int *bc) {
00489   Ext.SetBoundaryConditions(d,bc) ;
00490 }
00491 template<int DIM>
00492 void AdaptiveData<DIM>::SetBoundaryConditions(int d,int bc0,int bc1) {
00493   Ext.SetBoundaryConditions(d,bc0,bc1) ;
00494 }
00495 
00496 
00497 template<int DIM>
00498 bool AdaptiveData<DIM>::SameBoundaryConditions(AdaptiveData<DIM> *X) {
00499   return Ext.SameBoundaryConditions(&X->Ext) ;
00500 }
00501 
00502 template<int DIM>
00503 void AdaptiveData<DIM>::CheckBC(AdaptiveData<DIM> *X) {
00504   assert(SameBoundaryConditions(X)) ;
00505 }
00506 
00507 template<int DIM>
00508 void AdaptiveData<DIM>::CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) 
00509 { CheckBC(X) ;  CheckBC(Y) ; }
00510 
00511 template<int DIM>
00512 void AdaptiveData<DIM>::CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) 
00513 { CheckBC(X) ;  CheckBC(Y) ; CheckBC(Z) ; }
00514 
00515 template<int DIM>
00516 void AdaptiveData<DIM>::CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q) 
00517 { CheckBC(X) ;  CheckBC(Y) ; CheckBC(Z) ;  CheckBC(Q) ; }
00518 
00519 template<int DIM>
00520 void AdaptiveData<DIM>::CheckBC(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q , AdaptiveData<DIM> *R) 
00521 { CheckBC(X) ;  CheckBC(Y) ; CheckBC(Z) ; CheckBC(Q) ; CheckBC(R) ; }
00522 
00523 template<int DIM>
00524 void AdaptiveData<DIM>::CheckAdaptiveGrid(AdaptiveData<DIM> *X) 
00525 { assert (G==X->G) ;}
00526 
00527 template<int DIM>
00528 void AdaptiveData<DIM>::CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y) 
00529 { assert ((G==X->G)&&(G==Y->G)) ;}
00530 
00531 template<int DIM>
00532 void AdaptiveData<DIM>::CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) 
00533 { assert ((G==X->G)&&(G==Y->G)&&(G==Z->G)) ;}
00534 
00535 template<int DIM>
00536 void AdaptiveData<DIM>::CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q) 
00537 { assert ((G==X->G)&&(G==Y->G)&&(G==Z->G)&&(G==Q->G)) ;}
00538 
00539 template<int DIM>
00540 void AdaptiveData<DIM>::CheckAdaptiveGrid(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z , AdaptiveData<DIM> *Q , AdaptiveData<DIM> *R) 
00541 { assert ((G==X->G)&&(G==Y->G)&&(G==Z->G)&&(G==Q->G)&&(G==R->G)) ;}
00542 
00543 
00544 //
00545 //
00546 template<int DIM>
00547 void AdaptiveData<DIM>::CopyExtensions(AdaptiveData<DIM> *X) {
00548   assert (G==X->G) ;
00549   Ext.CopyFlags(&X->Ext) ;
00550 }
00551 
00552 //
00553 template<int DIM>
00554 void AdaptiveData<DIM>::Compatible(AdaptiveData<DIM> *X) {
00555   assert (G==X->G) ;
00556   assert (Ext.IsSame(&X->Ext)) ;
00557 }
00558 
00559 template<int DIM>
00560 void AdaptiveData<DIM>::Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y) {
00561   Compatible(X) ;
00562   Compatible(Y) ;
00563 }
00564 
00565 template<int DIM>
00566 void AdaptiveData<DIM>::Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z) {
00567   Compatible(X) ;
00568   Compatible(Y) ;
00569   Compatible(Z) ;
00570 }
00571 
00572 template<int DIM>
00573 void AdaptiveData<DIM>::Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z, AdaptiveData<DIM> *Q) {
00574   Compatible(X) ;
00575   Compatible(Y) ;
00576   Compatible(Z) ;
00577   Compatible(Q) ;
00578 }
00579 
00580 template<int DIM>
00581 void AdaptiveData<DIM>::Compatible(AdaptiveData<DIM> *X, AdaptiveData<DIM> *Y, AdaptiveData<DIM> *Z, AdaptiveData<DIM> *Q, AdaptiveData<DIM> *R) {
00582   Compatible(X) ;
00583   Compatible(Y) ;
00584   Compatible(Z) ;
00585   Compatible(Q) ;
00586   Compatible(R) ;
00587 }
00588 
00589 
00590 //
00591 //
00592 template<int DIM>
00593 void  AdaptiveData<DIM>::Set(const double a) { 
00594   ba->Set(a) ;
00595   Ext.Set(0) ;
00596 }
00597 
00598 template<int DIM>
00599 void  AdaptiveData<DIM>::Set(int *l , const double a) { 
00600   ba->Set(l,a) ; 
00601 }
00602 
00603 template<int DIM>
00604 void AdaptiveData<DIM>::Set(int l , const double a) {
00605   AdaptiveDataArray<DIM>::VectorArray::iterator it(&ba->d) ;
00606   for (it=ba->d.begin(); it<= ba->d.end(); ++it) {
00607     bool set=false ;
00608     for (int i=0; i<DIM; i++) if (it.i[i]>=l) set=true ;
00609     if (set) ba->Set(it.i,a) ; 
00610   }
00611 }
00612 
00613 // Get pointer to a particular value 
00614 template<int DIM>
00615 double *AdaptiveData<DIM>::GetP(int *l,int *t) {
00616   AdaptiveDataArray<DIM>::DataVector *v=ba->d[l] ;
00617   long second = *(G->FindOrInsert(G->BasisPG[0],0, l , t )) ;
00618   if ((second)==MAXINT) return NULL ;
00619   return &(*v)[second] ;
00620 }
00621 
00622 // Set particular value 
00623 template<int DIM>
00624 int AdaptiveData<DIM>::Set(int *l,int *t,const double a) {
00625   double *p=GetP(l,t) ;
00626   if (p==NULL) return -1 ;
00627   (*p)=a ;
00628   return 0 ;
00629 }
00630 
00631 // Get particular value 
00632 template<int DIM>
00633 double AdaptiveData<DIM>::Get(int *l,int *t) {
00634   double *p=GetP(l,t) ;
00635   if (p==NULL) exit(-1) ;
00636   return *p ;
00637 }
00638 
00639 
00640 template<int DIM>
00641 void AdaptiveData<DIM>::Set(int dir, int k, int s, const double a) {
00642   AdaptiveGrid<DIM>::ProjectionGrid           *pg=G->BasisPG[dir] ;
00643   AdaptiveGrid<DIM>::ProjectionGrid::iterator  pgit               ;
00644   
00645   int    i,j,l[DIM] ;
00646 
00647   for (pgit=(*pg).begin(); pgit!=(*pg).end(); ++pgit) {
00648     AdaptiveLevelsIndex *ali=(*pgit).first  ;
00649     AdaptiveLevels      *als=(*pgit).second ;
00650    
00651     j=0 ;
00652     for (i=0; i<DIM; i++)
00653       if (i!=dir) {
00654         l[i]=ali->l[j] ;
00655         j++ ;
00656       }
00657     l[dir]=k ;
00658 
00659     AdaptiveLevels::AdaptiveL *al=(*als)[k] ;
00660     AdaptiveLevels::AdaptiveL::iterator alit=(*al).find(s) ;
00661     assert(alit!=(*al).end()) ;
00662 
00663     j=(*alit).second ;
00664     int rl[DIM],rt[DIM] ;
00665     for (i=0; i<DIM; i++) rl[i]=ali->l[i], rt[i]=ali->t[i] ;
00666     (*ba->d[l])[j] = a ;
00667 
00668    }   // next pgit
00669 }
00670 
00671 template<int DIM>
00672 void AdaptiveData<DIM>::Get(int *l,int *t,int dir, AdaptiveB *B, int leftrightall) {
00673   int K0,K1,ld,i ;
00674   
00675   AdaptiveLevelsIndex *lt=AdaptiveLevelsIndexAllocator.NewItem() ;
00676   lt->dim=DIM-1 ;
00677   for (i=0    ; i<dir; i++) lt->l[i  ]=l[i], lt->t[i  ]=t[i] ;
00678   for (i=dir+1; i<DIM; i++) lt->l[i-1]=l[i], lt->t[i-1]=t[i] ;
00679 
00680   AdaptiveGrid<DIM>::ProjectionGrid          *pg=G->BasisPG[dir]  ;
00681   AdaptiveGrid<DIM>::ProjectionGrid::iterator plt=(*pg).find(lt) ;
00682  
00683   // if no such 1-dimensional line, return empty AdaptiveB
00684   if (plt==(*pg).end()) {
00685     for (ld=G->Level0[dir]; ld<=LMAX; ld++) B->L[ld].IS->nr=0 ;
00686     std::cout<< "AdaptiveData<"<<DIM<<">::Get:  attempt to load AdaptiveB* from non-existent AdaptiveLevels\n" ;
00687     lt->Print() ;
00688     assert(0) ;
00689     return ;
00690   }
00691   AdaptiveLevelsIndexAllocator.DeleteItem(lt) ;
00692 
00693   // otherwise load values
00694   AdaptiveLevels *als=(*plt).second ;
00695   for (ld=G->Level0[dir]; ld<=LMAX; ld++) {
00696     l[dir]=ld ;
00697 
00698     K0=-1, K1=(1<<ld)+1 ;
00699     if (ld > B->Level0) {
00700       if (leftrightall & 1) K0=                 G->WC->KW0 ; 
00701       if (leftrightall & 2) K1=(1<<(ld-1)) -1 - G->WC->KW1 ; 
00702     } else { 
00703       if (leftrightall & 1) K0=                 G->WC->K0 ;
00704       if (leftrightall & 2) K1=(1<<ld)        - G->WC->K1 ; 
00705     }
00706     
00707     if (leftrightall==0) B->L[ld].IS->Load        ((*als)[ld] , ba->d[l] , B->L[ld].d ) ;
00708     else                 B->L[ld].IS->LoadBoundary((*als)[ld] , ba->d[l] , B->L[ld].d , K0 , K1 ) ;
00709   }
00710 }
00711 
00712 
00713 template<int DIM>
00714 void AdaptiveData<DIM>::Set(int *l,int *t,int dir, AdaptiveB *B, int leftrightall, bool add) {
00715   int K0,K1,ld,i ;
00716   
00717   AdaptiveLevelsIndex *lt=AdaptiveLevelsIndexAllocator.NewItem() ;
00718   lt->dim=DIM-1 ;
00719   for (i=0    ; i<dir; i++) lt->l[i  ]=l[i], lt->t[i  ]=t[i] ;
00720   for (i=dir+1; i<DIM; i++) lt->l[i-1]=l[i], lt->t[i-1]=t[i] ;
00721 
00722   AdaptiveGrid<DIM>::ProjectionGrid          *pg=G->BasisPG[dir]  ;
00723   AdaptiveGrid<DIM>::ProjectionGrid::iterator plt=(*pg).find(lt) ;
00724  
00725   // if no such 1-dimensional line, return empty AdaptiveB
00726   if (plt==(*pg).end()) {
00727     std::cout<< "AdaptiveData<"<<DIM<<">::Get:  attempt to load AdaptiveB* from non-existent AdaptiveLevels\n" ;
00728     lt->Print() ;
00729     assert(0) ;
00730   }
00731   AdaptiveLevelsIndexAllocator.DeleteItem(lt) ;
00732 
00733   // otherwise load values
00734   AdaptiveLevels *als=(*plt).second ;
00735   int ldold=l[dir] ;
00736   for (ld=G->Level0[dir]; ld<=LMAX; ld++) {
00737     l[dir]=ld ;
00738 
00739     K0=-1, K1=(1<<ld)+1 ;
00740     if (ld > G->Level0[dir]) {
00741       if (leftrightall & 1) K0=                 G->WC->KW0 ; 
00742       if (leftrightall & 2) K1=(1<<(ld-1)) -1 - G->WC->KW1 ; 
00743     } else { 
00744       if (leftrightall & 1) K0=                 G->WC->K0 ;
00745       if (leftrightall & 2) K1=(1<<ld)        - G->WC->K1 ; 
00746     }
00747 
00748     if (leftrightall==0) B->L[ld].IS->Store        ((*als)[ld] , ba->d[l] , B->L[ld].d , add) ;
00749     else                 B->L[ld].IS->StoreBoundary((*als)[ld] , ba->d[l] , B->L[ld].d , K0 , K1 ,add) ;
00750   }
00751   l[dir]=ldold ;
00752 }
00753 
00754 
00755 
00756 
00757 
00758 template<int DIM>
00759 void AdaptiveData<DIM>::ReadSlice(AdaptiveData<DIM+1> *X) {
00760   // checks
00761   assert (G->SliceParent=X->G) ;
00762 
00763   AdaptiveGrid<DIM>::ProjectionGrid              *pg=X->G->BasisPG[G->SliceDir] ;
00764   AdaptiveGrid<DIM>::ProjectionGrid::iterator     pgit             ;
00765   
00766   int    i,l[DIM+1] ;
00767   long   j ;
00768 
00769   // set Flags
00770   j=0 ;
00771   for (i=0; i<DIM+1; i++)
00772     if (i!=G->SliceDir) {
00773       Ext.islifting   [j]=X->Ext.islifting   [i] ;
00774       Ext.ismultiscale[j]=X->Ext.ismultiscale[i] ;
00775       Ext.BC[j][0]       =X->Ext.BC[i][0] ;
00776       Ext.BC[j][1]       =X->Ext.BC[i][1] ;
00777       j++ ;
00778     }
00779 
00780   for (pgit=(*pg).begin(); pgit!=(*pg).end(); ++pgit) {
00781     AdaptiveLevelsIndex *ali=(*pgit).first  ;
00782     AdaptiveLevels      *als=(*pgit).second ;
00783    
00784     j=0 ;
00785     for (i=0; i<DIM+1; i++)
00786       if (i!=G->SliceDir) {
00787         l[i]=ali->l[j] ;
00788         j++ ;
00789       }
00790     l[G->SliceDir]=G->Slicel ;
00791 
00792     AdaptiveLevels::AdaptiveL *al=(*als)[G->Slicel] ;
00793     AdaptiveLevels::AdaptiveL::iterator alit=(*al).find(G->Slicet) ;
00794     if (alit ==(*al).end()) continue;
00795 
00796     j=(*alit).second ;
00797     int rl[DIM],rt[DIM] ;
00798     for (i=0; i<DIM; i++) rl[i]=ali->l[i], rt[i]=ali->t[i] ;
00799     Set(rl , rt, (*X->ba->d[l])[j]) ;
00800 
00801    }   // next pgit
00802 }  
00803 
00804 
00805 template<int DIM>
00806 void AdaptiveData<DIM>::WriteSlice(AdaptiveData<DIM+1> *X, bool add) {
00807   // checks
00808   assert(G->SliceParent=X->G) ;
00809 
00810   int  i ;
00811   long j=0 ;
00812   for (i=0; i<DIM+1; i++)
00813     if (i!=G->SliceDir) {
00814       assert(Ext.islifting   [j]==X->Ext.islifting   [i]) ;
00815       assert(Ext.ismultiscale[j]==X->Ext.ismultiscale[i]) ;
00816       assert(Ext.BC[j][0]       ==X->Ext.BC[i][0]) ;
00817       assert(Ext.BC[j][1]       ==X->Ext.BC[i][1]) ;
00818       j++ ;
00819     }
00820 
00821   AdaptiveGrid<DIM+1>::ProjectionGrid          *pg=X->G->BasisPG[G->SliceDir] ;
00822   AdaptiveGrid<DIM+1>::ProjectionGrid::iterator pgit ;
00823   
00824   int l[DIM+1] ;
00825   for (pgit=(*pg).begin(); pgit!=(*pg).end(); ++pgit) {
00826     AdaptiveLevelsIndex *ali=(*pgit).first  ;
00827     AdaptiveLevels      *als=(*pgit).second ;
00828    
00829     j=0 ;
00830     for (i=0; i<DIM+1; i++)
00831       if (i!=G->SliceDir) {
00832         l[i]=ali->l[j] ;
00833         j++ ;
00834       }
00835     l[G->SliceDir]=G->Slicel ;
00836    
00837     AdaptiveLevels::AdaptiveL *al=(*als)[G->Slicel] ;
00838     AdaptiveLevels::AdaptiveL::iterator alit=(*al).find(G->Slicet) ;
00839     if (alit==(*al).end()) continue;
00840 
00841     j=(*alit).second ;
00842     int rl[DIM],rt[DIM] ;
00843     for (i=0; i<DIM; i++) rl[i]=ali->l[i], rt[i]=ali->t[i] ;
00844     if (add) (*X->ba->d[l])[j] = (*X->ba->d[l])[j] + Get(rl , rt) ;
00845     else     (*X->ba->d[l])[j] =                     Get(rl , rt) ;
00846    }   // next pgit
00847 }  
00848 
00849 
00850 
00851 template<int DIM>
00852 void  AdaptiveData<DIM>::Copy(AdaptiveData<DIM> *X) { 
00853   CopyExtensions(X) ;
00854   Ext.CopyData(&X->Ext) ;
00855   ba->Copy(X->ba) ;
00856 }
00857 
00858 template<int DIM>
00859 double AdaptiveData<DIM>::Max() { 
00860   return max( ba->Max() , Ext.Max() ) ;
00861 }
00862 template<int DIM>
00863 double AdaptiveData<DIM>::Min() {
00864   return min (ba->Min() , Ext.Min() ) ;
00865 }
00866 template<int DIM>
00867 double AdaptiveData<DIM>::MaxAbs() { 
00868   return max( ba->MaxAbs() , Ext.MaxAbs() ) ;
00869 }
00870 
00871 template<int DIM>
00872 double AdaptiveData<DIM>::Sum() {
00873   return  ba->Sum() + Ext.Sum() ;
00874 }
00875 
00876 template<int DIM>
00877 double AdaptiveData<DIM>::SumSqr() {
00878   return  ba->SumSqr() + Ext.SumSqr() ;
00879 }
00880 
00881 template<int DIM>
00882 double AdaptiveData<DIM>::InnerProd(AdaptiveData<DIM> *X) { 
00883   Compatible(X) ;
00884   return ba->InnerProd(X->ba) + Ext.InnerProd(&X->Ext) ;
00885 }
00886 
00887 template<int DIM>
00888 void  AdaptiveData<DIM>::Abs(AdaptiveData<DIM> *X) { 
00889   CopyExtensions(X) ;
00890   ba  ->Abs(X->ba) ;
00891   Ext.Abs(&X->Ext) ;
00892 }
00893 
00894 template<int DIM>
00895 void  AdaptiveData<DIM>::Sqr(AdaptiveData<DIM> *X) { 
00896   CopyExtensions(X) ;
00897   ba  ->Sqr(X->ba) ;
00898   Ext.Sqr(&X->Ext) ;
00899 }
00900 
00901 template<int DIM>
00902 void  AdaptiveData<DIM>::Pow(AdaptiveData<DIM> *X, double p) { 
00903   CopyExtensions(X) ;
00904   ba  ->Pow(X->ba,p) ;
00905   Ext.Pow(&X->Ext,p) ;
00906 }
00907 
00908 template<int DIM>
00909 void  AdaptiveData<DIM>::PPlus(const double a) {
00910   ba->PPlus(a) ;
00911   Ext.PPlus(a) ;
00912 }
00913 
00914 
00915 template<int DIM>
00916 void  AdaptiveData<DIM>::PPlus(AdaptiveData<DIM> *X) {
00917   Compatible(X)   ;
00918   ba->PPlus(X->ba)      ;
00919   Ext.PPlus(&X->Ext)    ;
00920 }
00921 
00922 template<int DIM>
00923 void  AdaptiveData<DIM>::PPlus(const double a,AdaptiveData<DIM> *X) { 
00924   Compatible(X) ;
00925   ba->PPlus(a,X->ba)  ;
00926   Ext.PPlus(&X->Ext) ;
00927 }
00928 
00929 template<int DIM>
00930 void  AdaptiveData<DIM>::Add(AdaptiveData<DIM> *X,AdaptiveData<DIM> *Y) { 
00931   X->Compatible(Y) ;
00932   CopyExtensions(X) ;
00933   ba->Add(X->ba,Y->ba)    ;
00934   Ext.Add(&X->Ext , &Y->Ext) ;
00935 }
00936 
00937 template<int DIM>
00938 void  AdaptiveData<DIM>::Add(const double a,AdaptiveData<DIM> *X,const double b,AdaptiveData<DIM> *Y) { 
00939   X->Compatible(Y) ;
00940   CopyExtensions(X)   ;
00941   ba->Add(a,X->ba   , b,Y->ba)   ;
00942   Ext.Add(a,&X->Ext , b,&Y->Ext) ;
00943 }
00944 
00945 template<int DIM>
00946 void  AdaptiveData<DIM>::Add(const double a,AdaptiveData<DIM> *X,const double b,AdaptiveData<DIM> *Y,
00947                      const double c,AdaptiveData<DIM> *Z)
00948 { 
00949   X->Compatible(Y,Z) ;
00950   CopyExtensions(X) ;
00951   ba->Add(a, X->ba  , b, Y->ba  , c, Z->ba) ;
00952   Ext.Add(a,&X->Ext , b,&Y->Ext , c,&Z->Ext) ;
00953 }
00954 
00955 template<int DIM>
00956 void  AdaptiveData<DIM>::Add(const double a,AdaptiveData<DIM> *X,const double b,AdaptiveData<DIM> *Y,
00957                              const double c,AdaptiveData<DIM> *Z,const double d,AdaptiveData<DIM> *Q) 
00958 { 
00959   X->Compatible(Y,Z,Q) ; 
00960   CopyExtensions(X) ;
00961   ba->Add(a, X->ba  , b, Y->ba  , c, Z->ba  , d, Q->ba) ;
00962   Ext.Add(a,&X->Ext , b,&Y->Ext , c,&Z->Ext , d,&Q->Ext) ;
00963 }
00964 
00965 template<int DIM>
00966 void  AdaptiveData<DIM>::Add(const double a,AdaptiveData<DIM> *X,const double b,AdaptiveData<DIM> *Y,
00967                              const double c,AdaptiveData<DIM> *Z,const double d,AdaptiveData<DIM> *Q,
00968                              const double e,AdaptiveData<DIM> *R)
00969 {
00970   X->Compatible(Y,Z,Q,R)  ;
00971   CopyExtensions(X) ;
00972   ba->Add(a, X->ba  , b, Y->ba  , c, Z->ba  , d, Q->ba  , e, R->ba) ;
00973   Ext.Add(a,&X->Ext , b,&Y->Ext , c,&Z->Ext , d,&Q->Ext , e,&R->Ext) ;
00974 }
00975 
00976 template<int DIM>
00977 void  AdaptiveData<DIM>::MMinus(AdaptiveData<DIM> *X) { 
00978   Compatible(X) ;
00979   ba->MMinus( X->ba ) ;
00980   Ext.MMinus(&X->Ext) ;
00981 }
00982 
00983 template<int DIM>
00984 void  AdaptiveData<DIM>::MMinus(const double a,AdaptiveData<DIM> *X) { 
00985   Compatible(X) ;
00986   ba->MMinus(a, X->ba) ;
00987   Ext.MMinus(a,&X->Ext) ;
00988 }
00989 
00990 template<int DIM>
00991 void  AdaptiveData<DIM>::Sub(AdaptiveData<DIM> *X,AdaptiveData<DIM> *Y) { 
00992   X->Compatible(Y) ;
00993   CopyExtensions(X) ;
00994   ba->Sub( X->ba ,  Y->ba) ;
00995   Ext.Sub(&X->Ext, &Y->Ext) ;
00996 }
00997 
00998 template<int DIM>
00999 void  AdaptiveData<DIM>::Mul(AdaptiveData<DIM> *X,AdaptiveData<DIM> *Y) { 
01000   X->Compatible(Y) ;
01001   CopyExtensions(X) ;
01002   ba->Mul( X->ba ,  Y->ba) ;
01003   Ext.Mul(&X->Ext, &Y->Ext) ;
01004 }
01005 
01006 template<int DIM>
01007 void  AdaptiveData<DIM>::Div(AdaptiveData<DIM>      *X ,AdaptiveData<DIM>      *Y) { 
01008   X->Compatible(Y) ;
01009   CopyExtensions(X) ;
01010   ba->Div( X->ba ,  Y->ba)  ;
01011   Ext.Div(&X->Ext, &Y->Ext) ;
01012 }
01013 
01014 
01015 template<int DIM>
01016 void  AdaptiveData<DIM>::Mul(AdaptiveData<DIM>      *X ,AdaptiveData<DIM>      *Y , double f) { 
01017   X->Compatible(Y) ;
01018   CopyExtensions(X) ;
01019   ba->Mul( X->ba ,  Y->ba , f) ;
01020   Ext.Mul(&X->Ext, &Y->Ext, f) ;
01021 }
01022 
01023 /*
01024 template<int DIM>
01025 void  AdaptiveData<DIM>::Mul(AdaptiveDataArray<DIM> *X ,AdaptiveDataArray<DIM> *Y) {
01026   ba->Mul(X , Y) ;
01027 }
01028 */
01029 
01030 template<int DIM>
01031 void  AdaptiveData<DIM>::Mul(AdaptiveData<DIM> *X , double f) { 
01032   Compatible(X) ;
01033   ba->Mul( X->ba , f) ;
01034   Ext.Mul(&X->Ext, f) ;
01035 }
01036 
01037 template<int DIM>
01038 void  AdaptiveData<DIM>::Mul(double f) { 
01039   ba->Mul(f) ;
01040   Ext.Mul(f) ;
01041 }
01042 
01043 template<int DIM>
01044 void  AdaptiveData<DIM>::XplusYmalZ (AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) { 
01045   X->Compatible(Y) ;
01046   X->Compatible(Z) ;
01047   CopyExtensions(X) ;
01048   ba->XplusYmalZ(X->ba,Y->ba,Z->ba) ;
01049   Ext.XplusYmalZ(&X->Ext,&Y->Ext,&Z->Ext) ;
01050 }
01051 
01052 template<int DIM>
01053 void  AdaptiveData<DIM>::XminusYmalZ(AdaptiveData<DIM> *X , AdaptiveData<DIM> *Y , AdaptiveData<DIM> *Z) { 
01054   X->Compatible(Y) ;
01055   X->Compatible(Z) ;
01056   CopyExtensions(X) ;
01057   ba->XminusYmalZ(X->ba,Y->ba,Z->ba) ;
01058   Ext.XminusYmalZ(&X->Ext,&Y->Ext,&Z->Ext) ;
01059 }
01060 
01061 
01062 //
01063 // Norms
01064 template<int DIM>
01065 double AdaptiveData<DIM>::LpNorm(AdaptiveData<DIM> *Tmp, double p) {
01066   int i,GBC[2] ;
01067   AdaptiveData<DIM> *X=this ;
01068   
01069   for (i=0; i<DIM; i++)
01070     if (Ext.islifting[i]) {
01071       Tmp->ApplyOp(Ext.BC[i], X , i , LIFTING2INTERPOLET) ;
01072       X=Tmp ;
01073     }
01074   
01075   for (i=0; i<DIM; i++) {
01076     GetGeneralBoundaryConditions(Ext.BC[i],GBC) ;
01077     Tmp->ApplyOp(GBC, (i==0) ? X : Tmp , i , PROJECTION) ;
01078   }
01079   
01080   for (i=0; i<DIM; i++) Tmp->ApplyOp(GBC, Tmp , i , INVERSETRANSFORM) ;
01081   Tmp->Abs(Tmp) ;
01082   
01083   // Maximum Norm
01084   if (p==HUGE_VAL) return Tmp->Max() ;
01085   
01086   Tmp->Pow(Tmp,p) ;
01087   for (i=0; i<DIM; i++) Tmp->ApplyOp(GBC, Tmp , i , TRANSFORM) ;
01088   
01089   return pow(Tmp->Integrate(),1/p) ;
01090 }
01091 
01092 template<int DIM>
01093 double AdaptiveData<DIM>::LmaxNorm(AdaptiveData<DIM> *Tmp) { return LpNorm(Tmp,HUGE_VAL) ; }
01094 
01095 template<int DIM>
01096 double AdaptiveData<DIM>::L2Norm(AdaptiveData<DIM> *Tmp)   { return LpNorm(Tmp,2.0) ; }
01097 
01098 template<int DIM>
01099 double AdaptiveData<DIM>::L1Norm(AdaptiveData<DIM> *Tmp)   { return LpNorm(Tmp,1.0) ; }
01100 
01101 // WriteUDF
01102 template<int DIM>
01103 void AdaptiveData<DIM>::WriteUDF(const char *name, int  *L, AdaptiveData<DIM> *Tmp, bool CastToFloat) {
01104   int a[DIM]={0},e[DIM],i ;
01105   for (i=0; i<DIM; i++) e[i]=1<<L[i] ;
01106   UniformData <DIM> M(a,e,Ext.WC) ;
01107   WriteUDF(name,&M,Tmp,CastToFloat) ;
01108 }
01109 
01110 template<int DIM>
01111 void AdaptiveData<DIM>::WriteUDF(const char *name, int  L, AdaptiveData<DIM> *Tmp, bool CastToFloat) {
01112   int LL[DIM],i ;
01113   for (i=0; i<DIM; i++) LL[i]=L ;
01114   WriteUDF(name,LL,Tmp,CastToFloat) ;
01115 }
01116 
01117 template<int DIM>
01118 void AdaptiveData<DIM>::WriteUDF(const char *name, UniformData<DIM> *M, AdaptiveData<DIM> *Tmp, bool CastToFloat) {
01119   int  i,BG[DIM][2],L[DIM] ;
01120   AdaptiveData<DIM> *X=this ;
01121 
01122   // change of basis to Interpolets without boundary conditions
01123   if (Tmp) {
01124     for (i=0; i<DIM; i++) {
01125       assert(Ext.ismultiscale[i]) ;
01126       if (Ext.islifting[i]) {
01127         Tmp->ApplyOp( Ext.BC[i] , X , i, LIFTING2INTERPOLET) ;
01128         X=Tmp ;
01129       }
01130     }
01131     for (i=0; i<DIM; i++) {
01132       GetGeneralBoundaryConditions(Ext.BC[i],BG[i]) ;    
01133       Tmp->ApplyOp( BG[i] , X , i, PROJECTION) ;
01134       X=Tmp ; 
01135     }
01136   }
01137    
01138   M->ba->CalcLevel(L) ;
01139   X->ToUniform(M,L) ;
01140   // inverse transform ?
01141   if (Tmp) 
01142     for (i=0; i<DIM; i++) M->ApplyOp(BG[i], M, i, INVERSETRANSFORM) ;
01143 
01144   M->WriteUDF(name,NULL,CastToFloat) ;
01145 }
01146 
01147 
01148 template<int DIM>
01149 void  AdaptiveData<DIM>::Bining(double *eps,int Keps, int *count, AdaptivityCriterion *R) {
01150 
01151   AdaptiveDataArray<DIM>::VectorArray::iterator it(&ba->d),dend=ba->d.end() ;
01152   AdaptiveDataArray<DIM>::DataVector *v ;
01153   
01154   int i,n,j,a,e ;
01155   double c,eps0=R->eps ;
01156 
01157   for (i=-(Keps+1); i<=Keps; i++) count[i]=0 ;
01158 
01159   // loop over all levels
01160   for (it=ba->d.begin(); it<=dend; ++it) {
01161     v=ba->d[it]    ;
01162     n=(*v).size() ;
01163 
01164     // loop over coefficients of one level
01165     for (i=0; i<n; i++) {
01166       c = (*v)[i] ;
01167 
01168       // binary search for c in eps[]
01169       R->eps=eps[-Keps] ;
01170       if (!R->IsActive(c, it.i, G->Level0, DIM)) count[-(Keps+1)]++ ; // c<eps[-Keps]
01171       else {
01172         R->eps=eps[Keps] ;
01173         if (R->IsActive(c, it.i, G->Level0, DIM)) count[Keps]++ ;     // c>=eps[Keps]
01174         else { // eps[-Keps]<= c < eps[Keps]
01175           a=-Keps, e=Keps ;
01176           while (a<e-1) {
01177             j=(a+e)/2 ;
01178             R->eps=eps[j] ;
01179             if (!R->IsActive(c, it.i, G->Level0, DIM)) e=j ; // c<eps[j]
01180             else                                       a=j ;
01181           }
01182           // if e>a: eps[a] <= c < eps[e];  otherwise c=eps[a]=eps[e]
01183           count[a]++ ;
01184         } // else
01185       } // else
01186     } // next coefficient
01187   }   // next subspace
01188 
01189   R->eps=eps0 ;
01190 }
01191 
01192 
01194 //                       // 
01195 //  from/to UniformData  //
01196 //                       //
01198 template<int DIM>
01199 void AdaptiveData<DIM>::FromUniform(UniformData<DIM> *A,int *J) {
01200   Ext.CopyFlags(&A->Ext) ;
01201   Ext.CopyData (&A->Ext) ;
01202   G->SetPeriodicConditions(Ext.BC) ;
01203   for (int i=0; i<DIM; i++)
01204     if (!Ext.ismultiscale[i]) {
01205       std::cout<< "AdaptiveData<"<<DIM<<">::FromUniform: UniformData must be in multiscale representation\n" ;
01206       assert(0);
01207     }
01208   FromUniform(A->ba , J) ;
01209 }
01210 
01211 
01212 template<int DIM>
01213 void AdaptiveData<DIM>::FromUniform(Matrix<double,DIM>* A , int *J) {
01214   int  i,a[DIM]={0},e[DIM],t1[DIM] ;
01215  
01216   G->SetFull(J) ;
01217 
01218   Matrix<double,DIM>::iterator l(G->Level0,J) ;
01219   for (l.Set(G->Level0); l<=J; ++l) {
01220     for (i=0; i<DIM; i++)
01221       e[i]=(l.i[i]==G->Level0[i]) ? 1<<l.i[i] : (1<<(l.i[i]-1))-1 ;
01222     
01223     Matrix<double,DIM>::iterator t(a,e) ;
01224     for (t.Set(a) ; t<=e ;++t) {
01225       for (i=0; i<DIM; i++) t1[i] = ( (l.i[i]==G->Level0[i]) ? 0 : (1<<(l.i[i]-1))+1 )  +  t.i[i] ;
01226       Set(l.i, t.i, (*A)[t1]) ;
01227     }
01228   }
01229 }
01230 
01231 
01232 template<int DIM>
01233 void AdaptiveData<DIM>::ToUniform(UniformData<DIM> *A , int *J)  { 
01234  ToUniform(A->ba,J,0) ;
01235  A->Ext.CopyFlags(&Ext) ;
01236  A->Ext.CopyData (&Ext) ;
01237 }
01238 
01239 template<int DIM>
01240 void AdaptiveData<DIM>::ToUniform(Matrix<double,DIM> *A , int *J, int flag)
01241 {
01242  int i,l[DIM],dj[DIM] ; /*,sel=1*/ ; // sel / flag only for debug purposes
01243  size_t k,t[DIM],a[DIM] ; 
01244 
01245  A->Set(0.0) ;
01246 
01247  AdaptiveGrid<DIM>::ProjectionGrid          *pg=G->BasisPG[0] ;
01248  AdaptiveGrid<DIM>::ProjectionGrid::iterator pgit ;
01249 
01250  for (pgit=(*pg).begin(); pgit!=(*pg).end(); ++pgit) {
01251    AdaptiveLevelsIndex *ali=(*pgit).first  ;
01252    AdaptiveLevels      *als=(*pgit).second ;
01253    bool ins=true ;
01254    for (i=1; i<DIM; i++) { 
01255      l[i]=ali->l[i-1] ;
01256      t[i]=ali->t[i-1] ;
01257      if (l[i]>J[i]) ins=false ;
01258     }
01259 
01260    if (ins) 
01261      for (l[0]=G->Level0[0]; l[0]<=J[0]; l[0]++) {
01262        AdaptiveLevels::AdaptiveL           *al =(*als)[l[0]] ;
01263        AdaptiveLevels::AdaptiveL::iterator alit ;
01264        
01265        AdaptiveDataArray<DIM>::DataVector *v=ba->d[l] ;
01266        
01267        for (i=0;i<DIM;i++) a[i]=(l[i]==G->Level0[i]) ? 0 : (1<<(l[i]-1))+1 ;
01268        for (alit=(*al).begin(); alit!=(*al).end(); alit++) {
01269          t[0]=(*alit).first  ;
01270          k   =(*alit).second ;
01271          for (i=0;i<DIM;i++) dj[i]=(int)(t[i]+a[i]) ;
01272          (*A)[dj]= (flag) ? (double)(k+1) : (*v)[k] ;
01273        }
01274      }
01275  }
01276 }
01277 
01278 
01279 
01281 
01282 #include "AdaptiveGridRefine.hpp"
01283 #include "Operations.hpp"
01284 
01285 #endif

Generated at Mon Aug 19 10:02:31 2002 for AWFD by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001