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  

Adaptive1D.hpp

00001 //
00002 //: Adaptive1D.hpp
00003 // DatenStructuren fuer 1D schnelle adaptive Verfahren
00004 //
00005 
00006 #ifndef ADAPTIVE1D_H
00007 # define ADAPTIVE1D_H
00008 
00009 #include "Wavelet.hpp"
00010 #include <map>
00011 #include <vector>
00012 #include "Refine.hpp"
00013 
00014 #define _MAX_INDEXSET_ 1025 // max number of intervals which may be stored by IndexSet
00015 
00016 struct intlt { bool operator()(const int i,const int j) const ; } ;
00017 
00018 
00021 struct IndexSet { 
00022   typedef map<int,long,intlt>  AdaptiveLE ;
00023 
00024   int  nr,*a,*e ;
00025 
00026 public:
00028        IndexSet()          ;
00030        IndexSet(int Size)  ;
00031       ~IndexSet()          ;
00032 
00034   int    Init(int Size)    ;
00035 
00037   int    Print(char *st=NULL) ;
00039   void   Print(char *st,int l,int Level0) ;
00041   size_t Size() ;
00043   void   Copy(IndexSet *F)   ;
00045   bool   IsSame(IndexSet *F) ;
00046 
00048   void Union     (IndexSet *A,IndexSet *B) ;
00050   void Difference(IndexSet *A,IndexSet *B) ;
00051 
00053   bool Contains  (int i,int *r=NULL) ;
00054 
00056   double VecMax   (double *t) ;
00058   double VecMaxAbs(double *t) ;  
00059 
00061   void VecAdd  (double *to,double *a, double *b) ;
00063   void VecSub  (double *to,double *a, double *b) ;
00065   void VecPlus (double *to,double *a) ;
00067   void VecMinus(double *to,double *a) ;
00069   void VecMinus(double *to,double  a)  ;
00071   void VecMul  (double *to,const double factor)   ;
00073   void VecCopy (double *to,double *from)    ;
00075   void VecFill (double *to,const double f)  ;
00077   void VecClear(double *to) ;
00079   double VecInnerProd(double *a,double *b) ;
00081   void VecPrint(const char *st,double *t)  ;
00083   void GenerateRandom(bool boundflag , int KW , int J , bool isW , bool dorandom) ;
00084      
00092   void VecApplyWENO(double *to, double *f, double *roespeed, int *BC, int J, int k , double DX) ;
00093 
00095   void Load  (AdaptiveLE *al) ;
00096   void LoadIS(AdaptiveLE *al) ;
00097 
00099   void Load (AdaptiveLE *al , vector<double> *v, double *d) ;
00100 
00102   void Store(AdaptiveLE *al , vector<double> *v, double *d, bool add=false) ;
00103   //void Store(AdaptiveLE *al , vector<double> *v, double *d,int p) ;
00105   void LoadBoundary  (AdaptiveLE *al , vector<double> *v, double *d,int Left,int Right) ;
00106   void LoadBoundaryIS(AdaptiveLE *al , int Left,int Right) ;
00107 
00109   void StoreBoundary (AdaptiveLE *al , vector<double> *v, double *d,int Left,int Right, bool add=false) ;
00110   //void WriteToAdaptiveLE(AdaptiveLE *al,int *counter) ;
00111 
00112 
00113   void CopyWithBounds     (IndexSet *B,int l, int *BC, Wavelets *W) ;
00114   void CalcIndexSet       (double *d,int Size,int K0,int K1,bool Insert0,bool Insert1) ;
00115   void ForBoundaryWavelets(bool left, bool right, IndexSet *I, int level, Wavelets *W) ;
00116 
00117   // scaling functions of level l which span the given wavelets of level l
00118   void InducedByWavelets            (IndexSet *B,int l, int *BC, Wavelets *W) ;
00119   // scalings(l) influenced by the given scalings(l-1)
00120   void InducedByCoarseScalings      (IndexSet *S,int l, int *BC, Wavelets *W) ;  
00121   // scalings(l-1) required to span the given scalings(l)
00122   void InducedByFineScalings        (IndexSet *S,int l, int *BC, Wavelets *W) ;
00123   // dual scalings(l-1) required to span the given dual scalings(l)
00124   void InducedByFineDualScalings    (IndexSet *S,int l, int *BC, Wavelets *W) ;
00125   // wavelets(l) which coincide with the given scalings(l)
00126   void WaveletsInducedByFineScalings(IndexSet *B,int l, int *BC, Wavelets *W) ;
00127   // dual wavelets(l) influenced by the given dual scalings(l)
00128   void WaveletsInducedByFineDualScalings(IndexSet *B,int l, int *BC, Wavelets *W) ;
00129 
00130   void InducedByOperatorMatrix      (IndexSet *S,int l, int *BC, OperatorMatrix *W) ;
00131 
00132   // scalings(l-1) required to span the given lifting wavelets(l)
00133   void ScalingsInducedByLifting     (IndexSet *S,int l, int *BC, Wavelets *W) ;
00134 
00135 
00136   void IndexSetForTypeIII       (IndexSet *S,int l,             int *BC, Wavelets *W) ;
00137   
00138   //
00139   // Let A be a XxY matrix, M subset Y, then 
00140   //                C(A,M):={ x in X | exists y in M: A_{xy} !=0 } 
00141   //
00142   // A is given by (*H) and (more important) by the functions First/LastNZE(P)
00143   //
00144   // CAM is used mainly to DETECT dependencies -> overestimation of intervals is valid
00145   //
00146   // It is assumed that A is a banded matrix.
00147   // First(j) returns the number of the smallest i such that A_{i,j}!= 0
00148   // Last (j) returns the number of the largest  i such that A_{i,j}!= 0
00149   // 
00150   // in case of the TransformMatrices (No Transpose) some special care in the 
00151   // definition of First/Last is required:
00152   // First: j<=2i+O  -> First=(j-O+1)/2
00153   // Last : 2i-U<=j  -> Last =(j+U)/2 
00154   // 
00155   void CAM(IndexSet *M, int *BC, 
00156            MatrixShape *H,
00157            int (*FirstNZEP)(int,MatrixShape *) , int (*LastNZEP )(int,MatrixShape *) ,
00158            int (*FirstNZE )(int,MatrixShape *) , int (*LastNZE  )(int,MatrixShape *)) ;
00159 
00160   //
00161   //                E(A,M):={x in X | forall y: A_{xy}!=0 there holds y in M}
00162   //
00163   // EAM is used mainly to find COMPLETELY dependent intervals  -> UNDERestimation of intervals 
00164   // is valid
00165   //
00166   // in case of the TransformMatrices (No Transpose) some special care in the 
00167   // definition of First/Last is required:
00168   // First: 2i+O<=j  -> First=(j-O  )/2
00169   // Last : j<=2i-U  -> Last =(j+U+1)/2
00170   // 
00171   void EAM(IndexSet *M, int *BC, 
00172            MatrixShape *H,
00173            int (*FirstNZEP)(int,MatrixShape *) , int (*LastNZEP )(int,MatrixShape *) ,
00174            int (*FirstNZE )(int,MatrixShape *) , int (*LastNZE  )(int,MatrixShape *)) ;
00175 
00176   //
00177   // set operations
00178 
00179   void SatisfyBoundCondition(int M,int N,int BL0, int BR0,bool *Insert0, bool *Insert1) ;
00180 
00181 } ;
00182 
00183 
00184 struct AdaptiveGS ;
00185 struct AdaptiveBOperator ;
00186 
00191 struct AdaptiveB {
00192    
00194    int Level0 ;
00196    int J ;
00198    int BC[2] ;
00199  
00201    double XA ;
00203    double XE ;
00205    bool ismultiscale ;
00207    bool islifting ;
00208   
00210    struct AdaptiveLevel {
00212      bool     ISowner ; 
00214      IndexSet *IS     ; 
00215      int      Size    ;
00217      double   *d      ;
00218 
00219    public:    
00220               AdaptiveLevel() ;
00221              ~AdaptiveLevel() ;
00222 
00224      int      Init(int size)  ;
00226      int      InitD(int size) ;
00228      int      Print()         ;
00230      int      Print(char *st,int level,int allflag) ;
00231      friend class AdaptiveGS  ;
00232   } L[LMAX+1] ;
00233 
00234 public:
00236        AdaptiveB() ;
00238        AdaptiveB(AdaptiveB *B) ;
00239       ~AdaptiveB() ;
00240 
00242   int  Init(int Level0,int J,double xa=0, double xe=0) ;
00244   void Copy(AdaptiveB *B) ;
00246   void CopyIndexSets(AdaptiveB *B) ;
00248   bool SameIndexSets(AdaptiveB *B) ;
00250   void SetBoundaryConditions(int *BCs)        ;
00252   void SetBoundaryConditions(int bc0,int bc1) ;
00253 
00255   void Print(int allflag) ;
00257   void Print(char *st=NULL,int allflag=0) ;
00259   void Print(char *st) ;
00261   size_t Size() ;
00262   
00263   void FromFull(double *d,int *BC , Wavelets *W , double eps) ;
00265   void FromFull(double *d,int *BC , Wavelets *W , AdaptivityCriterion *R) ;
00267   void FromFull(double *d) ;
00269   void ToFull(double *d) ;
00270 
00274   void FromAdaptiveGS (AdaptiveGS *G , Wavelets *W) ;
00278   void FromAdaptiveGS2(AdaptiveGS *G , Wavelets *W) ;
00283   void FromAdaptiveGS3(AdaptiveGS *G , Wavelets *W) ;
00284   void FromAdaptiveGS4(AdaptiveGS *G , Wavelets *W) ;
00285   void AdditiveFromAdaptiveGS (AdaptiveGS *G , Wavelets *W) ;
00286   void HighPassFilterFromAdaptiveGS (AdaptiveGS *G , Wavelets *W) ;
00287 
00289   void IndexSetFromAdaptiveGS(AdaptiveGS *G , Wavelets *W) ;
00290 
00292   void LoadFromInterpoletGS       (AdaptiveGS *G , Wavelets *W) ;
00293   void LoadFromLiftingInterpoletGS(AdaptiveGS *G , Wavelets *W) ;
00294 
00295   //void copy(AdaptiveB *X) ;
00297   double Max() ;
00299   double MaxAbs() ;
00301   void Sub(AdaptiveB *X,AdaptiveB *Y) ;
00303   void Add(AdaptiveB *X,AdaptiveB *Y) ;
00305   void Add(const double a,AdaptiveB *X,const double b,AdaptiveB *Y) ;
00307   void Add(const double a,AdaptiveB *X,const double b,AdaptiveB *Y,const double c,AdaptiveB *Z) ;
00308 
00310   void PPlus(AdaptiveB *X) ;
00312   void PPlus(const double a,AdaptiveB *X) ;
00314   void PPlus(AdaptiveB *X,AdaptiveB *Y) ;
00316   void PPlus(const double a,AdaptiveB *X,const double b,AdaptiveB *Y) ;
00317   
00319   void MMinus(AdaptiveB *X) ;
00321   void MMinus(const double a,AdaptiveB *X) ;
00323   double InnerProd(AdaptiveB *X) ;
00325   void MMul(const double a) ;
00326 
00327   // dummy function, does nothing
00328   void CopyExtensions(AdaptiveB *X) ; 
00329 
00331   void Fill(double a) ;
00332   
00342   void Refine(AdaptiveB *B , AdaptivityCriterion *R,int *l,int dir,int Dim,Wavelets *W,bool copyflag=false) ;
00343   void Refine(AdaptiveB *B , AdaptivityCriterion *R,Wavelets *W) ;
00344   void Refine(AdaptivityCriterion *R,Wavelets *W) ;
00345   bool CheckBoundCondition (Wavelets *W) ;
00346   void InterpoletRegularity(Wavelets *W) ;
00347 
00348   //  
00349   // active operations: ApplyOp , Multiply,  ApplyFD, ApplyWENO
00350   // result in *this,  
00351   // for  ApplyOp and Multiply the  IndexSets of u are used
00352   // for ApplyXXX the BC of  (*this)  are the To-RB !   
00353   //
00354   // GStmp must be different from GS and is just used as temporary buffer, must be initialized, but no
00355   // valid values are required
00356   // 
00357   void ApplyOp  (AdaptiveB *u , int op , Wavelets *W, AdaptiveGS *GS, AdaptiveGS *GStmp) ;
00358   void ApplyOp  (AdaptiveB *u , int op , Wavelets *W                ) ;
00359   void ApplyFD  (AdaptiveB *u , int op , Wavelets *W, AdaptiveGS *GS) ;
00360   void ApplyWENO(AdaptiveB *u , int op , Wavelets *W, AdaptiveGS *GS, AdaptiveGS *GRoeSpeed) ;
00361 
00362   // GS must be initialized, but no IndexSets have to be set
00363   void ApplyFD2 (AdaptiveB *u , int op , Wavelets *W, AdaptiveGS *GS) ;
00364 
00365   void Multiply  (AdaptiveB *u , AdaptiveB *v, Wavelets *W,int which) ;
00366   void Projection(AdaptiveB *u , Wavelets *W , AdaptiveGS *GS, AdaptiveGS *GStmp) ;
00367 
00368   int  Solve(AdaptiveB *RHS, AdaptiveBOperator  *Op) ;
00369 
00370   // special for div*grad operators
00371   void RestrictPressure() ;
00372 
00373   friend class AdaptiveGS ;
00374 
00375   doubleBuffer *Buffers[2] ;
00376 } ;
00377 #ifdef _TYPEDEF_STRUCTS_
00378 typedef struct AdaptiveB AdaptiveB;
00379 #endif
00380 
00385 struct AdaptiveGS {
00386 
00387   int    Level0,J,BC[2] ;
00388   double XA,XE ;
00389 
00390   struct AdaptiveLevel {
00391     IndexSet I,II,III,IV ;
00392     int      Size        ;
00393     double   *d          ;
00394 
00395 public:
00396           AdaptiveLevel() ;
00397          ~AdaptiveLevel() ;
00398 
00399      int  Init(int size) ;
00400      int  Print() ;
00401      int  Print(char *st,int level,int allflag) ;
00402   } L[LMAX+1] ;
00403   
00404 public:
00406        AdaptiveGS() ;
00408       ~AdaptiveGS() ;
00410   int  Init(int Lev0,int J) ;
00412   void Print()              ;
00413   void Print(int allflag)   ;
00414   void Print(char *st,int allflag) ;
00415 
00417   void IndexSetForAdaptiveGS  (AdaptiveB *B , Wavelets *W) ; //with    III, using IV
00419   void IndexSetForAdaptiveGS2 (AdaptiveB *B , Wavelets *W) ; //without III
00421   void IndexSetForAdaptiveGSOp(AdaptiveB *X , Wavelets *W) ;
00423   void IndexSetForAdaptiveGSFD(AdaptiveB *X , OperatorMatrix *FD , Wavelets *W) ;
00424 
00425   //
00426   // Get adaptive generating system.
00427   //
00428 
00431   void FromAdaptiveB         (AdaptiveB *B , Wavelets *W) ; 
00432   void FromAdaptiveB1        (AdaptiveB *B , Wavelets *W) ;
00433   void Projection            (int *BCTo , Wavelets *W)    ; // project V->(V_0) 
00434 
00435   void BoundaryQuadrature    (Wavelets  *W , int which)   ;
00436   void ApplyFD               (int *BCTo , AdaptiveGS *G , Wavelets *W , int op) ;
00437   void ApplyWENO             (int *BCTo , AdaptiveGS *G , AdaptiveGS *GRoeSpeed, int op) ;
00438 
00441   void RestoreFromInterpoletBasis(AdaptiveB *B , Wavelets *W) ;
00442 
00446   void RestoreFromInterpoletBasis(AdaptiveB *B , AdaptiveGS *G , Wavelets *W) ;
00447 
00448   void CopyIndexSets(AdaptiveGS *G) ;
00449   void Copy         (AdaptiveGS *G) ;
00450 
00451   bool SameIndexSetsI  (AdaptiveGS *G) ;
00452   bool SameIndexSetsII (AdaptiveGS *G) ;
00453   bool SameIndexSetsIII(AdaptiveGS *G) ;
00454   bool SameIndexSetsIV (AdaptiveGS *G) ;
00455   bool SameIndexSets   (AdaptiveGS *G) ; // I && II && III && IV
00456 
00457   // some linear Algebra Stuff
00458   void   MMinus   (AdaptiveGS *G) ;
00459   double InnerProd(AdaptiveGS *G) ;
00460 
00461   doubleBuffer *Buffers[2] ;
00462 } ;
00463 #ifdef _TYPEDEF_STRUCTS_
00464 typedef struct AdaptiveGS AdaptiveGS;
00465 #endif
00466 
00467 // generalized Helmholtz-operator
00468 struct AdaptiveBOperator {
00469 
00470        AdaptiveBOperator(double aa0,double aa1,Wavelets *W) ;
00471 
00472   void apply         (AdaptiveB *X, AdaptiveB *R) ;
00473   void Preconditioner(AdaptiveB *X, AdaptiveB *R) ;
00474   // data
00475   double a0,a1 ; // (op u,v) == a0*(u,v) + a1*(grad u,grad v)
00476   Wavelets *WC ;
00477 } ;
00478 
00479 #endif
00480 
00481 
00482 

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