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  

BlendingWeights.hpp

00001 //
00002 // implementation for BlendingWeights
00003 //
00004 
00005 #ifndef _BLENDINGWEIGHTS_
00006 # define _BLENDINGWEIGHTS_
00007 
00008 #include "LevelAdaptive.hpp"
00009 
00010 template<int DIM>
00011 BlendingWeights<DIM>::BlendingWeights() {
00012  G=NULL ;
00013  a=NULL ;
00014  nBD=0  ;
00015 }
00016 
00017 template<int DIM>
00018 BlendingWeights<DIM>::BlendingWeights(LevelAdaptiveGrid<DIM> *AG) {
00019  a=NULL ;
00020  nBD=0  ;
00021  Init(AG) ;  
00022 }
00023 
00024 template<int DIM>
00025 void BlendingWeights<DIM>::Init(LevelAdaptiveGrid<DIM> *AG) {
00026  G=AG ;
00027  G->Attach(this) ;
00028  
00029  // test whether LevelAdaptiveGrid has been initialized
00030  for (int i=0; i<DIM; i++)
00031    if (G->Level0[i]==0) { std::cout<< "BlendingWeights<DIM>::Init -> initialize LevelAdaptiveGrid first\n"; exit(-1) ;}
00032  
00033  // allocate
00034  a=new Matrix<int,DIM> ;
00035  int A[DIM]={0}  ;
00036  a->Init(A,G->L) ;
00037 
00038  Matrix<int,DIM>::iterator it(a) ;
00039  for (it=(*a).begin(); it <= (*a).end(); ++it) (*a)[it]=false ;
00040 }
00041 
00042 template<int DIM>
00043 BlendingWeights<DIM>::~BlendingWeights() {
00044  delete a ;
00045 }
00046 
00047 template<int DIM>
00048 void BlendingWeights<DIM>::Print(int all) {
00049  int i,s,anz,size ;
00050  
00051  if (all&1) {
00052    std::cout<< "Weights:\n" ;
00053    Matrix<int,DIM>::iterator it(a,DIM-1) ;
00054    for (it=(*a).begin(DIM-1); it <= (*a).end(); ++it) {
00055      std::cout<<'('<<it.i[0] ;
00056      for (i=1; i<DIM-1; i++) std::cout<<','<<it.i[i] ;
00057      std::cout<<",.)=" ;
00058      
00059      int in[DIM] ;
00060      for (i=0; i<DIM-1; i++) in[i]=it.i[i] ;
00061      for (in[DIM-1]=0; in[DIM-1]<=J[DIM-1]; in[DIM-1]++) std::cout<<(*a)[in]<<' ' ;
00062      std::cout<<'\n' ;
00063    }
00064  } 
00065  
00066  if (all&2) {
00067    
00068    Matrix<int,DIM>::iterator il(a) ;
00069    size=anz=0 ;
00070    for (il=(*a).begin(); il<= (*a).end(); ++il) {
00071      if ((*a)[il] != 0) {
00072        s=1 ; 
00073        for (i=0; i<DIM; i++) s *= (1<<il.i[i])+1 ;
00074        size +=s ;
00075        anz  ++  ; 
00076      }
00077    }
00078    std::cout<<"BlendigSpaces: "<<anz<<" Spaces , "<<size<<" Elements\n" ; 
00079  }
00080 }
00081 
00082 template<int DIM>
00083 void BlendingWeights<DIM>::Attach(BlendingData<DIM> *B) {
00084   int i ;
00085   for (i=0; i<nBD; i++) if (BD[i]==B) break;
00086   if (i==nBD) BD[nBD++]=B ;
00087 }
00088 
00089 //
00090 //
00091 template<int DIM>
00092 size_t BlendingWeights<DIM>::Size() {
00093   Matrix<int,DIM>::iterator il(a) ;
00094   size_t size=0 ;
00095   for (il=(*a).begin(); il<= (*a).end(); ++il) {
00096     if ((*a)[il] != 0) {
00097       size_t s=1,i ; 
00098       for (i=0; i<DIM; i++) s *= (1<<il.i[i])+1 ;
00099       size +=s ;
00100     }
00101   }
00102   return size ;
00103 }
00104 
00105 
00106 template<int DIM>
00107 void BlendingWeights<DIM>::Set(LevelAdaptiveGrid<DIM> *A) {
00108   int i,s,sm=0 ;
00109   
00110   if (a==NULL) { std::cout<<"BlendingWeights<"<<DIM<<">::Set(A) : (*this) not initialized\n"; exit(-1) ;} 
00111   
00112   // calc |J|_1
00113   for (i=0; i<DIM; i++) sm+=G->L[i] ;
00114   
00115   // loop in decreasing order because of recursive definition of weights
00116   for (s=sm; s>=0; s--) {
00117     // check all entries whether |.|_1=s
00118     Matrix<int , DIM>::iterator it(a) ;
00119     for (it=(*a).begin(); it <= (*a).end(); ++it) {
00120       int  l1  =0 ;
00121       bool lev0=true ; 
00122       for (i=0; i<DIM; i++) { 
00123         l1+=it.i[i] ; 
00124         if (it.i[i]<G->Level0[i]) lev0=false ;
00125       }
00126       // if |.|_1 ok and not coarser than Level0 calculate weight
00127       if (l1==s)
00128         if ( lev0 && ((*(A->a))[it.i])) {
00129           int w=0 ;
00130           Matrix<int , DIM>::iterator in(it.i , G->L) ;
00131           for (in.Set(it.i); in<=G->L; ++in) if (in != it) w += (*a)[in] ;
00132           
00133           (*a)[it]=1-w ;
00134         } else (*a)[it]=0 ;
00135       
00136     } // next it
00137   }   // next s
00138   
00139   for (i=0; i<nBD; i++) BD[i]->Allocate() ;
00140 }
00141 
00142 template<int DIM>
00143 void BlendingWeights<DIM>::Clear() {
00144   Matrix<int , DIM>::iterator it(a) ;
00145   for (it=(*a).begin(); it <= (*a).end(); ++it) (*a)[it]=0  ;
00146 }
00147 #endif

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