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  

WENO.cc

00001 #include "WENO.hpp" 
00002 #include "Adaptive1D.hpp"
00003 
00004 void IndexSet::VecApplyWENO(double *to, double *v, double *roespeed, int *BC, int J, int k , double DX) {
00005  assert ((k==2) || (k==3)) ;
00006  assert (BC[1]==PERIODIC) ;
00007 
00008  int i,nJ=1<<J,r,m,s ;
00009  double vr[10],br[10],d[10],aa[10],sa,fm,fi,vi,vi1,vi2,vm1,vm2,rs ;
00010  
00011  switch (k) {
00012     case 2: {d[0]=2./3 , d[1]=1./3 ;}
00013     break ;
00014     case 3: {d[0]=3./10, d[1]=3./5, d[2]=1./10 ;}
00015     break ;
00016   }
00017   
00018  // reconstruction of f
00019  
00020  m=(1<<J)-1 ;
00021  for (r=0; r<nr; r++)
00022    for (i=a[r]; i<=e[r]; i++) {
00023      // rs =  roespeed[i] ;
00024      rs = (roespeed[i] + roespeed[(i+1)&m]) / 2  ;
00025 
00026      //
00027      // calculate v(r)_(i+1/2) and  v(r)_(i-1/2)
00028      //  
00029      if (k==2) {
00030        if (rs >= 0) {
00031          vm1=v[(i+m)&m], vi=v[i],vi1=v[(i+1)&m] ;
00032        } else {
00033          vm1=v[(i+2)&m], vi=v[(i+1)&m],vi1=v[i] ;
00034        }
00035        
00036        vr[0]=(vi+vi1)/2      ;
00037        vr[1]=-0.5*vm1+1.5*vi ;
00038 
00039        br[0]=sqr(vi1-vi) ;
00040        br[1]=sqr(vi-vm1) ;
00041      }
00042 
00043      if (k==3) {
00044        if (rs >= 0) {
00045          vm2=v[(i+m-1)&m],  vm1=v[(i+m)&m], vi=v[i],vi1=v[(i+1)&m], vi2=v[(i+2)&m] ;
00046        } else {
00047          vm2=v[(i+3)&m],  vm1=v[(i+2)&m], vi=v[(i+1)&m],vi1=v[i], vi2=v[(i+m)&m] ;
00048        }
00049 
00050        vr[0]=( 2*vi  + 5*vi1 -   vi2)/6 ;
00051        vr[1]=(  -vm1 + 5*vi  + 2*vi1)/6 ;
00052        vr[2]=( 2*vm2 - 7*vm1 +11*vi )/6 ;
00053 
00054        br[0]=13./12.*sqr(vi -2*vi1+vi2) + sqr(3*vi -4*vi1+  vi2)/4;
00055        br[1]=13./12.*sqr(vm1-2*vi +vi1) + sqr(  vm1-vi1        )/4;
00056        br[2]=13./12.*sqr(vm2-2*vm1+vi ) + sqr(  vm2-4*vm1+3*vi )/4;
00057      }
00058 
00059      sa=0 ;
00060      for (s=0; s<k; s++) { 
00061        aa[s]=d[s]/sqr(1e-6 + br[s]); 
00062        sa +=aa[s] ;
00063       }
00064 
00065      to[i]=0 ;  
00066      for (s=0; s<k; s++) to[i] += (aa[s]*vr[s])/sa ;
00067    }
00068 
00069  // conservative discretization 
00070  
00071  double q=nJ/DX ;
00072  for (r=0; r<nr; r++) {
00073    fm = (a[r]==0) ? to[nJ-1] : 0 ;
00074    for (i=a[r]; i<=e[r]; i++) {
00075      fi=to[i] ;
00076      to[i]=(fi-fm)*q ;
00077      fm=fi ; 
00078    }
00079  }
00080 
00081 }
00082 
00083 
00084 
00085 /*
00086 void WENO_Apply(double *dv,int * , int *, double *v,int * , Wavelets *,int J,int ) {
00087  int i,nJ=1<<J,k=3,r ;
00088  double vs[10],vr[10],br[10],om[10],omt[10],d[10],a[10],at[10],sa,sat,vp,vm ;
00089  
00090  double *f=(double *)malloc(sizeof(double)*(nJ+1)) ;
00091 
00092  switch (k) {
00093     case 2: {d[0]=2./3 , d[1]=1./3 ;}
00094     break ;
00095     case 3: {d[0]=3./10, d[1]=3./5, d[2]=1./10 ;}
00096     break ;
00097     default: assert(0) ;
00098   }
00099 
00100 
00101  int m=(1<<J)-1 ;
00102  for (i=0; i<nJ; i++) {
00103 
00104    //
00105    // calculate v(r)_(i+1/2) and  v(r)_(i-1/2)
00106    //  
00107    if (k==2) {
00108      double vm1=v[(i+m)&m], vi=v[i],vi1=v[(i+1)&m] ;
00109    
00110      br[0]=sqr(vi1-vi) ;
00111      br[1]=sqr(vi-vm1) ;
00112   
00113      vr[0]=(vi+vi1)/2      ;
00114      vr[1]=-0.5*vm1+1.5*vi ;
00115 
00116      vs[0]=1.5*vi - 0.5*vi1 ;
00117      vs[1]=(vm1+vi)/2       ;
00118    }
00119 
00120    if (k==3) {
00121      double  vm2=v[(i+m-1)&m],  vm1=v[(i+m)&m], vi=v[i],vi1=v[(i+1)&m], vi2=v[(i+2)&m] ;
00122    
00123      br[0]=13./12.*sqr(vi -2*vi1+vi2) + sqr(3*vi -4*vi1+  vi2)/4;
00124      br[1]=13./12.*sqr(vm1-2*vi +vi1) + sqr(  vm1-vi1        )/4;
00125      br[2]=13./12.*sqr(vm2-2*vm1+vi ) + sqr(  vm2-4*vm1+3*vi )/4;
00126 
00127      vr[0]=( 2*vi  + 5*vi1 -   vi2)/6 ;
00128      vr[1]=(  -vm1 + 5*vi  + 2*vi1)/6 ;
00129      vr[2]=( 2*vm2 - 7*vm1 +11*vi )/6 ;
00130 
00131      vs[0]=(11*vi  - 7*vi1  + 2*vi2)/6 ;
00132      vs[1]=( 2*vm1 + 5*vi   -   vi1)/6 ;
00133      vs[2]=(  -vm2 + 5*vm1  + 2*vi )/6 ;
00134    }
00135 
00136 
00137    sa=0,sat=0 ;
00138    for (r=0; r<k; r++) {
00139      a [r]=d[    r]/sqr(1e-6 + br[r]) ;
00140      at[r]=d[k-1-r]/sqr(1e-6 + br[r]) ;
00141      sa += a[r] ; 
00142      sat+=at[r] ;
00143     }
00144    
00145    for (r=0; r<k; r++) om[r]=a[r]/sa, omt[r]=at[r]/sat ;
00146 
00147    vm=vp=0 ;
00148    for (r=0; r<k; r++) {
00149      vp += om [r]*vr[r] ;
00150      vm += omt[r]*vs[r] ;
00151    }
00152    
00153    f[i]=vp ;
00154  }
00155 
00156  for (i=0; i<nJ; i++) dv[i]=(f[i] - f[(i+m)&m])*nJ ;
00157 
00158  free (f) ;
00159 }
00160 */

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