00001
00002
00003
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
00105
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
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
00118 void InducedByWavelets (IndexSet *B,int l, int *BC, Wavelets *W) ;
00119
00120 void InducedByCoarseScalings (IndexSet *S,int l, int *BC, Wavelets *W) ;
00121
00122 void InducedByFineScalings (IndexSet *S,int l, int *BC, Wavelets *W) ;
00123
00124 void InducedByFineDualScalings (IndexSet *S,int l, int *BC, Wavelets *W) ;
00125
00126 void WaveletsInducedByFineScalings(IndexSet *B,int l, int *BC, Wavelets *W) ;
00127
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
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
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
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
00162
00163
00164
00165
00166
00167
00168
00169
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
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
00297
00299
00301
00303
00305
00307
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
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
00350
00351
00352
00353
00354
00355
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
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
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) ;
00419
00421
00423
00424
00425
00426
00427
00428
00431 void FromAdaptiveB (AdaptiveB *B , Wavelets *W) ;
00432 void FromAdaptiveB1 (AdaptiveB *B , Wavelets *W) ;
00433 void Projection (int *BCTo , Wavelets *W) ;
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) ;
00456
00457
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
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
00475 double a0,a1 ;
00476 Wavelets *WC ;
00477 } ;
00478
00479 #endif
00480
00481
00482