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  

AdaptiveDataArray.hpp

00001 #ifndef _DATA_ARRAY_
00002 # define _DATA_ARRAY_
00003 
00004 # include<assert.h>
00005 # include<vector>
00006 
00007 #include "Matrix.hpp"
00008 
00009 template<int DIM>
00010 struct AdaptiveDataArray {
00011 
00012   typedef vector<double>            DataVector  ;
00013   typedef Matrix<DataVector* , DIM> VectorArray ;
00014 
00015           AdaptiveDataArray() ;
00016          ~AdaptiveDataArray() ;
00017   void    Clear    () ;
00018 
00019 // LinearAlgebra
00020   double  Max() ;
00021   double  Min() ;
00022   double  MaxAbs() ;
00023   double  Sum()    ;
00024   double  SumAbs() ;
00025   double  SumSqr() ;
00026 
00027   void    Set (const double f) ;
00028   void    Set (int *l , const double f) ; // set complete Level to a particular value
00029   void    Copy(AdaptiveDataArray<DIM> *X) ; // (*this) := (*X)
00030   void    PPlus(const double a)                ; // (*this) += a
00031   void    PPlus(AdaptiveDataArray<DIM> *X)                  ; // (*this) += (*X)
00032   void    PPlus(const double a , AdaptiveDataArray<DIM> *X) ; // (*this) += a(*X)
00033   void    Add (AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y) ; // (*this) := (*X) + (*Y)
00034   void    Add (const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y) ; // (*this) := a(*X) + b(*Y)
00035   void    Add (const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y , const double c , AdaptiveDataArray<DIM> *Z) ; // (*this) := a(*X) + b(*Y) + c(*Z)    
00036   void    Add (const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y , const double c , AdaptiveDataArray<DIM> *Z , const double d , AdaptiveDataArray<DIM> *Q) ; // (*this) := a(*X) + b(*Y) + c(*Z) + d(*Q)
00037   void    Add (const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y , const double c , AdaptiveDataArray<DIM> *Z , const double d , AdaptiveDataArray<DIM> *Q , const double f , AdaptiveDataArray<DIM> *R) ; // (*this) := a(*X) + b(*Y) + c(*Z) + d(*Q) + f(*R)
00038 
00039   void    MMinus(AdaptiveDataArray<DIM> *X) ; // (*this) -= (*X)
00040   void    MMinus(const double a , AdaptiveDataArray<DIM> *X) ; // (*this) -= a(*X)
00041   void    Sub (AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y)   ; // (*this) := (*X) - (*Y)
00042   void    Mul (AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y)   ; // (*this) := (*X) * (*Y)
00043   void    Mul (AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y , double f)   ; // (*this) := (*X) * (*Y) *f 
00044   void    Mul (AdaptiveDataArray<DIM> *X , double f) ;       // (*this) := f (*X)
00045   void    Mul (double f) ;                      // (*this) *= f
00046   void    XplusYmalZ (AdaptiveDataArray<DIM> *X,AdaptiveDataArray<DIM> *Y , AdaptiveDataArray<DIM> *Z) ; // (*this):= (*X) + (*Y)*(*Z)
00047   void    XminusYmalZ(AdaptiveDataArray<DIM> *X,AdaptiveDataArray<DIM> *Y , AdaptiveDataArray<DIM> *Z) ; // (*this):= (*X) - (*Y)*(*Z)
00048 
00049   void    Div (AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y)   ; // (*this) := (*X) / (*Y)
00050 
00051   void    Abs (AdaptiveDataArray<DIM> *X) ;
00052   void    Sqr (AdaptiveDataArray<DIM> *X) ;
00053   void    Pow (AdaptiveDataArray<DIM> *X, double p) ;
00054 
00055   double  InnerProd(AdaptiveDataArray<DIM> *X) ;
00056 
00057   void    Resize(Matrix<size_t,DIM> *A) ; // uninitialized resize
00058   void    Resize(AdaptiveDataArray<DIM> *Referenz) ; //       "
00059   void    Resize(Matrix<size_t,DIM> *A , double fill) ; // resize and fill
00060   void    Resize(AdaptiveDataArray<DIM> *Referenz   , double fill) ; //     "
00061   void    Resize(Matrix<size_t,DIM> *A , bool fillflag , double fill) ;
00062   void    Resize(AdaptiveDataArray<DIM> *Referenz   , bool fillflag , double fill) ;
00063 
00064   void    PrintSizes() ;
00065   void    Memory(int *reserved ,  int *used) ; // returns the size (bytes) allocated for (*this)
00066 
00067   //Daten
00068   VectorArray d ;
00069 } ;
00070 
00071 
00073 //                            //
00074 // AdaptiveDataArray<DIM>::Implementations //
00075 //                            //
00077 
00078 
00079 template<int DIM>
00080 AdaptiveDataArray<DIM>::AdaptiveDataArray() {
00081   int b[DIM] , e[DIM] ;
00082   for (int k=0;k<DIM;k++) { b[k]=0 , e[k]=LMAX ; }
00083   d.Init(b,e)                               ;
00084   VectorArray::iterator it(&d),dend=d.end() ;
00085   for (it=d.begin(); it<=dend; ++it) { d[it]=new vector<double> ; }
00086 }
00087 
00088 
00089 template<int DIM>
00090 AdaptiveDataArray<DIM>::~AdaptiveDataArray() {
00091   VectorArray::iterator it(&d),dend=d.end() ;
00092   for (it=d.begin(); it<=dend; ++it) { delete d[it] ;} 
00093 }
00094 
00095 
00096 template<int DIM>
00097 void AdaptiveDataArray<DIM>::Clear() {
00098   AdaptiveDataArray<DIM>::VectorArray::iterator it(&d),dend=d.end() ;
00099   for (it=d.begin(); it<=dend; ++it) { d[it]->clear() ;}
00100 }
00101 
00102 
00103 template<int DIM>
00104 double AdaptiveDataArray<DIM>::Max() {
00105   VectorArray::iterator it(&d),dend=d.end() ;
00106   DataVector *v ;
00107   size_t i,n ;
00108   double x,m=-1e+200 ;
00109 
00110   for (it=d.begin(); it<=dend; ++it) {
00111      v=d[it] ;
00112     n=(*v).size() ;
00113     for (i=0; i<n; i++) {
00114       x=(*v)[i] ;
00115       m = m>x ? m : x ;
00116     }
00117   }
00118  return m ;
00119 }
00120 
00121 
00122 template<int DIM>
00123 double AdaptiveDataArray<DIM>::Min() {
00124   VectorArray::iterator it(&d),dend=d.end() ;
00125   DataVector *v ;
00126   size_t i,n ;
00127   double x,m=1e+300 ;
00128 
00129   for (it=d.begin(); it<=dend; ++it) {
00130      v=d[it] ;
00131     n=(*v).size() ;
00132     for (i=0; i<n; i++) {
00133       x=(*v)[i] ;
00134       m = m<x ? m : x ;
00135     }
00136   }
00137  return m ;
00138 }
00139 
00140 
00141 template<int DIM>
00142 double AdaptiveDataArray<DIM>::MaxAbs() {
00143   VectorArray::iterator it(&d),dend=d.end() ;
00144   DataVector *v ;
00145   size_t i,n ;
00146   double x,m=-1.0 ;
00147 
00148   for (it=d.begin(); it<=dend; ++it) {
00149      v=d[it] ;
00150     n=(*v).size() ;
00151     for (i=0; i<n; i++) {
00152       x=fabs((*v)[i]) ;
00153       m = m>x ? m : x ;
00154     }
00155   }
00156  return m ;
00157 }
00158 
00159 
00160 template<int DIM>
00161 double AdaptiveDataArray<DIM>::Sum() {
00162   VectorArray::iterator it(&d),dend=d.end() ;
00163   DataVector *v ;
00164   size_t i,n    ;
00165   double m=0.0  ;
00166 
00167   for (it=d.begin(); it<=dend; ++it) {
00168     v=d[it] ;
00169     n=(*v).size() ;
00170     for (i=0; i<n; i++) m +=(*v)[i] ;
00171   }
00172  return m ;
00173 }
00174 
00175 
00176 template<int DIM>
00177 double AdaptiveDataArray<DIM>::SumAbs() {
00178   VectorArray::iterator it(&d),dend=d.end() ;
00179   DataVector *v ;
00180   size_t i,n    ;
00181   double m=0.0  ;
00182 
00183   for (it=d.begin(); it<=dend; ++it) {
00184     v=d[it] ;
00185     n=(*v).size() ;
00186     for (i=0; i<n; i++) m +=fabs((*v)[i]) ;
00187   }
00188  return m ;
00189 }
00190 
00191 template<int DIM>
00192 double AdaptiveDataArray<DIM>::SumSqr() {
00193   VectorArray::iterator it(&d),dend=d.end() ;
00194   DataVector *v ;
00195   size_t i,n    ;
00196   double m=0.0  ;
00197 
00198   for (it=d.begin(); it<=dend; ++it) {
00199     v=d[it] ;
00200     n=(*v).size() ;
00201     for (i=0; i<n; i++) m +=(*v)[i]*(*v)[i] ;
00202   }
00203  return m ;
00204 }
00205 
00206 
00207 template<int DIM>
00208 void  AdaptiveDataArray<DIM>::Set(int *l ,const double f) {
00209   DataVector *v=d[l] ;
00210   size_t i,n ;
00211 
00212   n=(*v).size() ;
00213   for (i=0; i<n; i++) (*v)[i] = f ;
00214 }
00215 
00216 
00217 template<int DIM>
00218 void  AdaptiveDataArray<DIM>::Set(const double f) {
00219   VectorArray::iterator it(&d),dend=d.end() ;
00220   DataVector *v ;
00221   size_t i,n ;
00222 
00223   for (it=d.begin(); it<=dend; ++it) {
00224      v=d[it] ;
00225     n=(*v).size() ;
00226     for (i=0; i<n; i++) { 
00227       (*v)[i] = f ;
00228     } 
00229   }
00230 }
00231 
00232 
00233 template<int DIM>
00234 void  AdaptiveDataArray<DIM>::Copy(AdaptiveDataArray<DIM> *X) {
00235   if (X==this) return ;
00236   VectorArray::iterator it(&d),dend=d.end() ;
00237   DataVector *v,*xv ;
00238   size_t i,n ;
00239 
00240   for (it=d.begin(); it<=dend; ++it) {
00241      v=d[it] ;
00242     xv=X->d[it] ;
00243     n=(*v).size() ;
00244     assert( n==(*xv).size() ) ;
00245     for (i=0; i<n; i++) { 
00246       (*v)[i] = (*xv)[i] ;
00247     } 
00248   }
00249 }
00250 
00251 
00252 template<int DIM>
00253 double AdaptiveDataArray<DIM>::InnerProd(AdaptiveDataArray<DIM> *X) {
00254   VectorArray::iterator it(&d),dend=d.end() ;
00255   DataVector *v,*xv ;
00256   size_t i,n ;
00257   double s=0 ;
00258 
00259   for (it=d.begin(); it<=dend; ++it) {
00260      v=d[it] ;
00261     xv=X->d[it] ;
00262     n=(*v).size() ;
00263     assert( n==(*xv).size() ) ;
00264     for (i=0; i<n; i++) s += (*v)[i]*(*xv)[i] ;
00265   }
00266  return s ;
00267 }
00268 
00269 
00270 template<int DIM>
00271 void  AdaptiveDataArray<DIM>::Abs(AdaptiveDataArray<DIM> *X) {
00272   VectorArray::iterator it(&d),dend=d.end() ;
00273   DataVector *v,*xv;
00274   size_t i,n ;
00275 
00276   for (it=d.begin(); it<=dend; ++it) {
00277      v=d[it] ;
00278     xv=X->d[it] ;
00279     n=(*v).size() ;
00280     assert( n==(*xv).size() ) ;
00281     for (i=0; i<n; i++) (*v)[i] = fabs((*xv)[i]) ;
00282   }
00283 }
00284 
00285 template<int DIM>
00286 void  AdaptiveDataArray<DIM>::Sqr(AdaptiveDataArray<DIM> *X) {
00287   VectorArray::iterator it(&d),dend=d.end() ;
00288   DataVector *v,*xv;
00289   size_t i,n ;
00290 
00291   for (it=d.begin(); it<=dend; ++it) {
00292      v=d[it] ;
00293     xv=X->d[it] ;
00294     n=(*v).size() ;
00295     assert( n==(*xv).size() ) ;
00296     for (i=0; i<n; i++) (*v)[i] = sqr((*xv)[i]) ;
00297   }
00298 }
00299 
00300 template<int DIM>
00301 void  AdaptiveDataArray<DIM>::Pow(AdaptiveDataArray<DIM> *X , double p) {
00302   VectorArray::iterator it(&d),dend=d.end() ;
00303   DataVector *v,*xv;
00304   size_t i,n ;
00305 
00306   for (it=d.begin(); it<=dend; ++it) {
00307      v=d[it] ;
00308     xv=X->d[it] ;
00309     n=(*v).size() ;
00310     assert( n==(*xv).size() ) ;
00311     for (i=0; i<n; i++) (*v)[i] = pow((*xv)[i],p) ;
00312   }
00313 }
00314 
00315 template<int DIM>
00316 void  AdaptiveDataArray<DIM>::PPlus(const double a) {
00317   VectorArray::iterator it(&d),dend=d.end() ;
00318   DataVector *v ;
00319   size_t i,n ;
00320 
00321   for (it=d.begin(); it<=dend; ++it) {
00322     v=d[it] ;
00323     n=(*v).size() ;
00324     for (i=0; i<n; i++) (*v)[i] += a ;
00325   }
00326 }
00327 
00328 template<int DIM>
00329 void  AdaptiveDataArray<DIM>::PPlus(AdaptiveDataArray<DIM> *X) {
00330   VectorArray::iterator it(&d),dend=d.end() ;
00331   DataVector *v,*xv ;
00332   size_t i,n ;
00333 
00334   for (it=d.begin(); it<=dend; ++it) {
00335      v=d[it] ;
00336     xv=X->d[it] ;
00337     n=(*v).size() ;
00338     assert( n==(*xv).size() ) ;
00339     for (i=0; i<n; i++) (*v)[i] += (*xv)[i] ;
00340   }
00341 }
00342 
00343 
00344 template<int DIM>
00345 void  AdaptiveDataArray<DIM>::PPlus(const double a , AdaptiveDataArray<DIM> *X) {
00346   VectorArray::iterator it(&d),dend=d.end() ;
00347   DataVector *v,*xv ;
00348   size_t i,n ;
00349 
00350   for (it=d.begin(); it<=dend; ++it) {
00351     v=d[it] ; xv=X->d[it] ; n=(*v).size() ;
00352     assert( n==(*xv).size() ) ;
00353     for (i=0; i<n; i++) (*v)[i] += a*(*xv)[i] ;
00354   }
00355 }
00356 
00357 
00358 template<int DIM>
00359 void  AdaptiveDataArray<DIM>::Add(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y) {
00360   VectorArray::iterator it(&d),dend=d.end() ;
00361   DataVector *v,*xv,*yv ;
00362   size_t i,n ;
00363 
00364   for (it=d.begin(); it<=dend; ++it) {
00365     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00366     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00367     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] + (*yv)[i] ;
00368   }
00369 }
00370 
00371 
00372 template<int DIM>
00373 void  AdaptiveDataArray<DIM>::Add(const double a , AdaptiveDataArray<DIM> *X,const double b , AdaptiveDataArray<DIM> *Y) {
00374   VectorArray::iterator it(&d),dend=d.end() ;
00375   DataVector *v,*xv,*yv ;
00376   size_t i,n ;
00377 
00378   for (it=d.begin(); it<=dend; ++it) {
00379     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00380     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00381     for (i=0; i<n; i++) (*v)[i] = a*(*xv)[i] + b*(*yv)[i] ;
00382   }
00383 }
00384 
00385 
00386 template<int DIM>
00387 void  AdaptiveDataArray<DIM>::Add(const double a , AdaptiveDataArray<DIM> *X,const double b , AdaptiveDataArray<DIM> *Y,
00388                           const double c , AdaptiveDataArray<DIM> *Z) {
00389   VectorArray::iterator it(&d),dend=d.end() ;
00390   DataVector *v,*xv,*yv,*zv ;
00391   size_t i,n ;
00392 
00393   for (it=d.begin(); it<=dend; ++it) {
00394     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; zv=Z->d[it] ; n=(*v).size() ;
00395     assert( (n==(*xv).size()) && (n==(*yv).size()) && (n==(*zv).size()) ) ;
00396     for (i=0; i<n; i++) (*v)[i] = a*(*xv)[i] + b*(*yv)[i] + c*(*zv)[i] ;
00397   }
00398 }
00399 
00400 
00401 template<int DIM>
00402 void  AdaptiveDataArray<DIM>::Add(const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y,
00403                           const double c , AdaptiveDataArray<DIM> *Z , const double e , AdaptiveDataArray<DIM> *Q) {
00404   VectorArray::iterator it(&d),dend=d.end() ;
00405   DataVector *v,*xv,*yv,*zv,*qv ;
00406   size_t i,n ;
00407 
00408   for (it=d.begin(); it<=dend; ++it) {
00409     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; zv=Z->d[it] ; qv=Q->d[it] ;
00410     n=(*v).size() ;
00411     assert( (n==(*xv).size()) && (n==(*yv).size()) && (n==(*zv).size()) && (n==(*qv).size()) ) ;
00412     for (i=0; i<n; i++) (*v)[i] = a*(*xv)[i] + b*(*yv)[i] + c*(*zv)[i] +e*(*qv)[i] ;
00413   }
00414 }
00415 
00416 
00417 template<int DIM>
00418 void  AdaptiveDataArray<DIM>::Add(const double a , AdaptiveDataArray<DIM> *X , const double b , AdaptiveDataArray<DIM> *Y,
00419                           const double c , AdaptiveDataArray<DIM> *Z , const double e , AdaptiveDataArray<DIM> *Q ,
00420                           const double f , AdaptiveDataArray<DIM> *R) {
00421   VectorArray::iterator it(&d),dend=d.end() ;
00422   DataVector *v,*xv,*yv,*zv,*qv,*rv ;
00423   size_t i,n ;
00424 
00425   for (it=d.begin(); it<=dend; ++it) {
00426     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; zv=Z->d[it] ; qv=Q->d[it] ;rv=R->d[it] ; 
00427     n=(*v).size() ;
00428     assert( (n==(*xv).size()) && (n==(*yv).size()) && (n==(*zv).size()) && (n==(*qv).size()) ) ;
00429     for (i=0; i<n; i++) (*v)[i] = a*(*xv)[i] + b*(*yv)[i] + c*(*zv)[i] +e*(*qv)[i] +f*(*rv)[i] ;
00430   }
00431 }
00432 
00433 
00434 template<int DIM>
00435 void  AdaptiveDataArray<DIM>::MMinus(AdaptiveDataArray<DIM> *X) {
00436   VectorArray::iterator it(&d),dend=d.end() ;
00437   DataVector *v,*xv ;
00438   size_t i,n ;
00439 
00440   for (it=d.begin(); it<=dend; ++it) {
00441     v=d[it] ; xv=X->d[it] ; n=(*v).size() ;
00442     assert( n==(*xv).size() ) ;
00443     for (i=0; i<n; i++) (*v)[i] -= (*xv)[i] ;
00444   }
00445 }
00446 
00447 
00448 template<int DIM>
00449 void  AdaptiveDataArray<DIM>::MMinus(const double a , AdaptiveDataArray<DIM> *X) {
00450   VectorArray::iterator it(&d),dend=d.end() ;
00451   DataVector *v,*xv ;
00452   size_t i,n ;
00453 
00454   for (it=d.begin(); it<=dend; ++it) {
00455     v=d[it] ; xv=X->d[it] ; n=(*v).size() ;
00456     assert( n==(*xv).size() ) ;
00457     for (i=0; i<n; i++) (*v)[i] -= a*(*xv)[i] ;
00458   }
00459 }
00460 
00461 
00462 template<int DIM>
00463 void  AdaptiveDataArray<DIM>::Sub(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y) {
00464   VectorArray::iterator it(&d),dend=d.end() ;
00465   DataVector *v,*xv,*yv ;
00466   size_t i,n ;
00467 
00468   for (it=d.begin(); it<=dend; ++it) {
00469     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00470     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00471     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] - (*yv)[i] ;
00472   }
00473 }
00474 
00475 
00476 template<int DIM>
00477 void  AdaptiveDataArray<DIM>::Mul(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y) {
00478   VectorArray::iterator it(&d),dend=d.end() ;
00479   DataVector *v,*xv,*yv ;
00480   size_t i,n ;
00481 
00482   for (it=d.begin(); it<=dend; ++it) {
00483     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00484     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00485     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] * (*yv)[i] ;
00486   }
00487 }
00488 
00489 
00490 template<int DIM>
00491 void  AdaptiveDataArray<DIM>::Div(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y) {
00492   VectorArray::iterator it(&d),dend=d.end() ;
00493   DataVector *v,*xv,*yv ;
00494   size_t i,n ;
00495 
00496   for (it=d.begin(); it<=dend; ++it) {
00497     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00498     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00499     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] / (*yv)[i] ;
00500   }
00501 }
00502 
00503 
00504 template<int DIM>
00505 void  AdaptiveDataArray<DIM>::Mul(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y , double f) {
00506   VectorArray::iterator it(&d),dend=d.end() ;
00507   DataVector *v,*xv,*yv ;
00508   size_t i,n ;
00509 
00510   for (it=d.begin(); it<=dend; ++it) {
00511     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; n=(*v).size() ;
00512     assert( (n==(*xv).size()) && (n==(*yv).size()) ) ;
00513     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] * (*yv)[i] * f ;
00514   }
00515 }
00516 
00517 
00518 template<int DIM>
00519 void  AdaptiveDataArray<DIM>::Mul(AdaptiveDataArray<DIM> *X , double f) {
00520   VectorArray::iterator it(&d),dend=d.end() ;
00521   DataVector *v,*xv ;
00522   size_t i,n ;
00523 
00524   for (it=d.begin(); it<=dend; ++it) {
00525     v=d[it] ; xv=X->d[it] ; n=(*v).size() ;
00526     assert (n==(*xv).size()) ;
00527     for (i=0; i<n; i++) (*v)[i] = f*(*xv)[i] ;
00528   }
00529 }
00530 
00531 
00532 template<int DIM>
00533 void  AdaptiveDataArray<DIM>::Mul(double f) {
00534   VectorArray::iterator it(&d),dend=d.end() ;
00535   DataVector *v ;
00536   size_t i,n ;
00537 
00538   for (it=d.begin(); it<=dend; ++it) {
00539     v=d[it] ; n=(*v).size() ;
00540     for (i=0; i<n; i++) (*v)[i] *= f ;
00541   }
00542 }
00543 
00544 
00545 template<int DIM>
00546 void  AdaptiveDataArray<DIM>::XplusYmalZ(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y , AdaptiveDataArray<DIM> *Z) {
00547   VectorArray::iterator it(&d),dend=d.end() ;
00548   DataVector *v,*xv,*yv,*zv ;
00549   size_t i,n ;
00550 
00551   for (it=d.begin(); it<=dend; ++it) {
00552     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; zv=Z->d[it] ; n=(*v).size() ;
00553     assert( (n==(*xv).size()) && (n==(*yv).size()) && (n==(*zv).size()) ) ;
00554     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] + (*yv)[i]*(*zv)[i] ;
00555   }
00556 }
00557 
00558 
00559 template<int DIM>
00560 void  AdaptiveDataArray<DIM>::XminusYmalZ(AdaptiveDataArray<DIM> *X , AdaptiveDataArray<DIM> *Y , AdaptiveDataArray<DIM> *Z) {
00561   VectorArray::iterator it(&d),dend=d.end() ;
00562   DataVector *v,*xv,*yv,*zv ;
00563   size_t i,n ;
00564 
00565   for (it=d.begin(); it<=dend; ++it) {
00566     v=d[it] ; xv=X->d[it] ; yv=Y->d[it] ; zv=Z->d[it] ; n=(*v).size() ;
00567     assert( (n==(*xv).size()) && (n==(*yv).size()) && (n==(*zv).size()) ) ;
00568     for (i=0; i<n; i++) (*v)[i] = (*xv)[i] - (*yv)[i]*(*zv)[i] ;
00569   }
00570 }
00571 
00572 
00573 template<int DIM>
00574 void AdaptiveDataArray<DIM>::Resize(Matrix<size_t,DIM> *A) {Resize(A,false,0.0) ;}
00575 
00576 template<int DIM>
00577 void AdaptiveDataArray<DIM>::Resize(AdaptiveDataArray<DIM> *R)          {Resize(R,false,0.0) ;}
00578 
00579 template<int DIM>
00580 void AdaptiveDataArray<DIM>::Resize(Matrix<size_t,DIM> *A , double fill) {Resize(A,true,fill) ;}  
00581 
00582 template<int DIM>
00583 void AdaptiveDataArray<DIM>::Resize(AdaptiveDataArray<DIM> *R , double fill)          {Resize(R,true,fill) ;}
00584 
00585 template<int DIM>
00586 void AdaptiveDataArray<DIM>::Resize(Matrix<size_t,DIM> *A, bool flag , double fill) {
00587  AdaptiveDataArray<DIM>::DataVector *v ;
00588 
00589  Matrix<size_t,DIM>::iterator it(A) ;
00590  for (it=(*A).begin(); it<=(*A).end(); ++it) {
00591    v=d[it.i] ;
00592    (*v).reserve(lmax((*v).capacity() , (*A)[it])) ;
00593    if (flag) {
00594      (*v).clear() ;
00595      (*v).insert((*v).begin() , (*A)[it] , fill) ;
00596    } else (*v).resize((*A)[it]) ;
00597   }
00598 }
00599 
00600 
00601 template<int DIM>
00602 void AdaptiveDataArray<DIM>::Resize(AdaptiveDataArray<DIM> *R, bool flag , double fill) {
00603  AdaptiveDataArray<DIM>::DataVector *v,*va ;
00604  size_t n ;  
00605 
00606 flag=true ;
00607 fill=0.0 ;
00608 
00609  VectorArray::iterator it(&d) ;
00610  for (it=d.begin(); it<=d.end(); ++it) {
00611    v =d[it.i] ;
00612    va=R->d[it.i] ;
00613    n =(*va).size() ;
00614 
00615    (*v).reserve(lmax((*v).capacity() , n )) ;
00616    if (flag) {
00617      (*v).clear() ;
00618      (*v).insert((*v).begin() , n , fill) ;
00619    } else (*v).resize(n) ;
00620   }
00621 }
00622 
00623 
00624 template<int DIM>
00625 void  AdaptiveDataArray<DIM>::PrintSizes() {
00626   VectorArray::iterator it(&d),dend=d.end() ;
00627   DataVector *v ;
00628   size_t n ;
00629 
00630   for (it=d.begin(); it<=dend; ++it) {
00631     v=d[it] ;
00632     n=(*v).size() ;
00633     std::cout<<"DataArraySize("<<it.i[0]<<','<<it.i[1]<<")="<<n<<'\n' ;
00634   }
00635 }
00636 
00637 
00638 template<int DIM>
00639 void  AdaptiveDataArray<DIM>::Memory(int *reserved , int *used) {
00640   VectorArray::iterator it(&d),dend=d.end() ;
00641   DataVector *v ;
00642 
00643   *reserved=*used=0 ;
00644   for (it=d.begin(); it<=dend; ++it) {
00645     v=d[it] ;
00646     (*used    ) +=(*v).size    ()*sizeof(double) ;
00647     (*reserved) +=(*v).capacity()*sizeof(double) ;
00648   }
00649 }
00650 
00651 #endif

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