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  

2DMergingInitial.cc

00001 //
00002 // generate initial conditions for 2D merging vortices simulation
00003 // the initial velocities are computed from an initial vorticity 
00004 // distribution
00005 //
00006 
00007 #include "UniformData.hpp"
00008 #include "Operators.hpp"
00009 #include "Solver.hpp"
00010 
00011 #define D 2 
00012 int debugRefine ;
00013 
00014 int main() {
00015   printf("2DMergingInitial\n") ;
00016   // which wavelets
00017   Wavelets WC("Interpolet",6) ;
00018   // box
00019   double XA[2]={0,0},XE[2]={1,1} ;
00020   // refinement level for initial values
00021   int L[D]={8,8} ;
00022   // boundary conditions
00023   int i,j,BC[D][2] ;
00024   for (i=0; i<D; i++) BC[i][0]=-1, BC[i][1]=PERIODIC ;
00025 
00026   // initial distribution of vortices: 3 Gaussian blobs
00027   int    NV  =3 ; // number of vortices
00028   double px[]={3./8 , 5./8 , 5./8                  },    // x coordinates
00029          py[]={1./2 , 1./2 , (1+1/(2*sqrt(2.0)))/2 },    // y coordinates
00030          am[]={PI   ,  PI   ,-0.5*PI},                   // amplitude
00031          si[]={1/(2*PI*PI) , 1/(2*PI*PI) ,1/(2*PI*PI)},  // variance
00032          ommean=0;
00033 
00034   // allocate uniform data structures
00035   int a[D]={0},e[D] ;
00036   for (i=0; i<D; i++) e[i]=1<<L[i] ;
00037   UniformData<D> U[D],Omega(a,e,&WC,XA,XE),Psi(a,e,&WC,XA,XE), TMP[Solver<UniformData<D>,D>::NUMTMP_BICGSTAB2+2],P(a,e,&WC,XA,XE) ;
00038   for (i=0; i<D; i++) U[i].Init(a,e,&WC,XA,XE) ;
00039   for (i=0; i<Solver<UniformData<D>,D>::NUMTMP_BICGSTAB2+2; i++) TMP[i].Init(a,e,&WC,XA,XE) ;
00040 
00041   // set initial vorticity distribution
00042   Matrix<double,D>::iterator s(a,e) ;
00043   for (s.Set(a); s<=e; ++s) {
00044     double x[D],r2,s2,dx,dy,om=0.0 ;
00045     for (i=0; i<D; i++) x[i]=(s.i[i]*XE[i])/e[i] ;
00046         
00047     for (i=0; i<NV; i++) {
00048       dx =x[0]-px[i] ;
00049       dy =x[1]-py[i] ;
00050       
00051       r2 =dx*dx + dy*dy ;
00052       s2 =si[i]*si[i];
00053       om+=am[i]*exp(-r2/s2) ;
00054     }
00055     
00056     for (i=0; i<D; i++) if (s.i[i]==e[i]) om=0 ;
00057     
00058     Omega[s]=om ;
00059     ommean +=om ;
00060   }
00061   // set flags/bcs
00062   for (i=0; i<D; i++) Omega.Ext.ismultiscale[i]=false ,  Omega.Ext.islifting[i]=false ;
00063   Omega.SetBoundaryConditions(BC) ;
00064 
00065   // enforce vanishing mean vorticity
00066   ommean /=(1<<(2*L[0])) ;
00067   for (s.Set(a); s<=e; ++s) {
00068     bool f=true ;
00069     for (i=0; i<D; i++) if (s.i[i]==e[i]) f=false ;
00070     if (f) Omega[s] -=ommean ;
00071   }
00072 
00073   // compute stream function psi by  \Delta(psi) - Omega
00074   HelmholtzOperator< UniformData<D> , D> MO ;
00075   MO.Tmp =&TMP[Solver<UniformData<D>,D>::NUMTMP_BICGSTAB2] ;
00076   MO.Tmp2=&TMP[Solver<UniformData<D>,D>::NUMTMP_BICGSTAB2+1] ;
00077   
00078   MO.par[0]=0.0 ;
00079   for (i=0; i<D; i++) MO.par[i+1]=1/(XE[i]*XE[i]) ;
00080   
00081   Solver<UniformData<D>,D> MS ;
00082   MS.eps          =1e-10 ;
00083   MS.maxiter      =150 ;
00084   MS.Op           =&MO ;
00085   MS.StopCriterion=StoppingCriterionAbsoluteResidual ;
00086   MS.print        ="BiCG:" ;
00087   MS.prstep       =10 ;
00088   for (i=0; i<Solver<UniformData<D>,D>::NUMTMP_BICGSTAB2; i++) MS.Tmp[i]=&TMP[i] ;
00089 
00090   for (i=0; i<D; i++) Omega.ApplyOp(BC[i] , &Omega , i , TRANSFORM) ;
00091   Omega.Mul(-1) ;
00092 
00093   // initial guess for Psi
00094   ConstFunction F ;
00095   ommean=0.0 ;
00096   F.SetParameters(&ommean) ;
00097   Psi.SetBoundaryConditions(BC) ;
00098   Psi.SetFunction(&F) ;
00099 
00100   MS.BiCGSTAB2(&Psi,&Omega) ;
00101   MS.BiCGSTAB2(&Psi,&Omega) ;
00102   
00103   // compute velocity components
00104   for (i=0; i<2; i++) {
00105     j= (i==0) ? 1 : 0 ;
00106     U[i].ApplyOp(BC[j] , &Psi , j , FIRSTDERIVATIVE) ;
00107     
00108     if (i==0) U[i].Mul( 1/XE[1]) ;
00109     else      U[i].Mul(-1/XE[0]) ;
00110   }
00111   
00112   // set pressure
00113   P.SetBoundaryConditions(BC) ;
00114   P.SetFunction(&F) ;
00115 
00116    // write 
00117   UniformData<D> *MM[D+1]={&U[0],&U[1],&P} ;
00118   U[0].WriteSparse("../../Data/Merging2D/UVWP0", MM, D+1) ;
00119   
00120 }

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