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  

CP.cc

00001 //
00002 // solves the linear convection problem    du/dt + nabla*(Au) = 0
00003 // u is the advected scalar and A(x,y)=(-y,x) is the given velocity (a rotation in our case)
00004 // 
00005 // An explicit multistep scheme (3rd order Adams-Bashforth)
00006 // and a WENO discretization of the convection term are used. 
00007 //
00008 // At regular intervals, the current solution is evaluated on a uniform grid and written to a 
00009 // file with advancing time mark. These files can be read and visualized using MATLAB
00010 // 
00011 
00012 # include "AdaptiveData.hpp"
00013 # include "Operators.hpp"
00014 # include "Solver.hpp"
00015 
00016 int debugRefine ; // needed for dummy reasons
00017 
00018 struct HillSharpFunction : public Function {
00019   double x0[3] ;
00020   double sigma ;
00021   void   SetParameters(double *p) { int    i  ; for (    i=0; i<2; i++) x0[i]=p[i]; sigma=p[i]; }
00022   double Eval         (double *x) { double r=0; for (int i=0; i<2; i++) r+=pow(x[i]-x0[i],2)  ; return max(4*exp(sigma*r)-3.0 , 0.0); }
00023 } ;
00024 
00025 int main(int argc, char **argv) {
00026 
00027   Wavelets WC("Interpolet",4) ; // use 4th order Interpolets
00028 
00029   int    i,prstep,dof  ; 
00030   int    BC[2][2],BG[2][2] ; // boundary conditions markers 
00031   for    (i=0; i<2; i++) BC[i][0]=-1 , BC[i][1]=PERIODIC ;
00032   
00033   int    Prints=100 ;
00034   double dt=3.9e-4, T=2*PI,t=0 ; // time step, stop time 
00035   
00036   prstep=(int)(T/(Prints*dt)+0.9999) ;
00037   dt=T/(prstep*Prints) ;  // adjust dt such that T is exactly hit.
00038   
00039   // refinement criterion
00040   AdaptivityCriterion R(AdaptivityCriterion::L2_THRESHOLD,1e-3) ;
00041   R.MaxLevel=8 ; 
00042   assert(dt<0.1/(1<<R.MaxLevel)) ;
00043   
00044   char   name[300]  ;
00045   
00046   // set functions for velocity
00047   double pars[20] ;
00048   TensorNPolynomFunction<2> fv[2] ;
00049   
00050   i=0;            // u(x,y)= 1.0*(1  )*(0 -y)
00051   pars[i++]=1.0 ;
00052   pars[i++]= 0  ; // degree          of x-polynomial 
00053   pars[i++]= 1  ; // degree          of y-    "
00054   pars[i++]= 1  ; // 0th coefficient of x-    "
00055   pars[i++]= 0  ; // 0th coefficient of y-    "
00056   pars[i++]=-1  ; // 1th coefficient of y-    "
00057   fv[0].SetParameters(pars) ;
00058   
00059   i=0;            // v(x,y)= 1.0*(0+x)*(1)
00060   pars[i++]=1.0 ;
00061   pars[i++]= 1  ; // degree          of x-polynomial 
00062   pars[i++]= 0  ; // degree          of y-    "
00063   pars[i++]= 0  ; // 0th coefficient of x-    "
00064   pars[i++]= 1  ; // 1th coefficient of x-    "
00065   pars[i++]= 1  ; // 0th coefficient of y-    "
00066   fv[1].SetParameters(pars) ;
00067   
00068   // initial condition is a sharp edged hill
00069   HillSharpFunction fu0   ;
00070   pars[0]=1./4  ;
00071   pars[1]=1./4  ;
00072   pars[2]=-30/2 ;
00073   fu0.SetParameters(pars) ;
00074   
00075   // AdaptiveData
00076   AdaptiveGrid<2> G(&WC) ;
00077   G.XA[0]=G.XA[1]=-1 ;
00078   G.XE[0]=G.XE[1]= 1 ;
00079   
00080   AdaptiveData<2> U[4] , UN[2] , K(&G) , Tmp(&G) , Tmp1(&G), Tmp2(&G), *Uold,*Unew ;
00081   
00082   // BoundaryConditions
00083   for (i=0; i<2; i++) GetGeneralBoundaryConditions(BC[i] , BG[i]) ;
00084   for (i=0; i<2; i++) {
00085     UN[i].Attach(&G) ;
00086     UN[i].SetBoundaryConditions(BG) ;
00087   }
00088   for (i=0; i<4; i++) {
00089     U [i].Attach(&G) ;
00090     U [i].SetBoundaryConditions(BC) ;
00091     U [i].SetRefine() ;
00092   }
00093   
00094   K.SetBoundaryConditions(BC) ;
00095   K.SetRefine() ;
00096   
00097   // initial Grid
00098   G.SetFull(7)     ;
00099   
00100   // initial Conditions
00101   U[0].SetFunction(&fu0) ;
00102   for (i=0; i<2; i++) U[0].ApplyOp(BC[i] , &U[0] , i ,PROJECTION) ;
00103   Tmp.Copy(&U[0]) ;
00104   
00105   G.Refine(&Tmp,&R) ;
00106   dof=G.Size() ;
00107   
00108   for (i=0; i<2; i++) UN[i].SetFunction(&fv[i], false, true) ;
00109   
00110   // operators
00111   ConvectionOperator<AdaptiveData<2>,2> CONV ;
00112   CONV.Tmp =&Tmp      ;
00113   CONV.Tmp1=&Tmp1     ;
00114   for (i=0; i<2; i++) CONV.U [i]=&UN[i] ;
00115   
00116   //
00117   // Main Loop
00118   //
00119   int tsk=0, ts=0  ;
00120   Unew=&U[0] ;
00121   
00122   // T=dt ;
00123   while (t<T+dt) {
00124     
00125     // Output
00126     if (ts%prstep==0) {
00127       i=ts/prstep ;
00128       sprintf(name,"../../Data/Test/U.%d", i) ;
00129       Unew->WriteUDF(name,7,&Tmp2) ;
00130     }
00131     
00132     //AB3
00133     Uold=&U[0] ;
00134     Unew=&U[0] ;
00135     AdaptiveData<2> *KK[3]={&U[1],&U[2],&U[3]} ;
00136     CONV.ApplyConservativeWENO(Uold , KK[tsk%3]) ;
00137     
00138     switch (tsk) {
00139     case 0 :
00140       Tmp.Copy(KK[tsk%3]) ;
00141       break ;
00142     case 1 :
00143       Tmp.Add(2.0,KK[tsk%3] , -1.0,KK[(tsk+2)%3]) ;
00144       break ;
00145     default : 
00146       Tmp.Add(23./12,KK[tsk%3]  , -16./12,KK[(tsk+2)%3] , 5./12,KK[(tsk+1)%3]) ;
00147       break ;
00148     }
00149     
00150     Unew->Add(1.0,Uold , -dt,&Tmp) ;
00151     
00152     for (i=0; i<2; i++) Tmp.ApplyOp(Unew->Ext.BC[i] , (i==0) ? Unew : &Tmp, i , INVERSETRANSFORM) ;
00153     if ((ts%10)==0) printf("ts= %4d   t= %e   max U= %e   DOF= %d\n",ts ,t , Tmp.MaxAbs() , dof) ;
00154     fflush(stdout) ;
00155     
00156     // refine grid
00157     if ((ts%10==0) && (R.strategy!=AdaptivityCriterion::FIXED_LEVEL)) {
00158       Tmp.Copy(Unew) ;
00159      
00160       G.Refine(&Tmp,&R) ;
00161       dof=G.Size() ;
00162       
00163       // evaluate velocity functions on the new adaptive grid
00164       for (i=0; i<2; i++) UN[i].SetFunction(&fv[i], false, true) ;
00165     }
00166     
00167     tsk++ ;
00168     ts++  ;
00169     t+=dt ;
00170     
00171   } // next t
00172 }

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