$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

gridRefinement.hh

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 /* Main author: Daniel Lagrava
00026  **/
00027 
00031 #ifndef GRID_REFINEMENT_HH
00032 #define GRID_REFINEMENT_HH
00033 
00034 #include "multiGrid/gridRefinement.h"
00035 
00036 namespace plb {
00037 
00042 template<typename T>
00043 T interpolateValue(std::vector<T> const& knownX, std::vector<T> const& knownY, 
00044                    std::vector<std::vector<T> > const& knownF, T xValue, T yValue){
00045     
00046     // computation of the x coefficients of the polynomial
00047     std::vector<T> Linx;
00048     for (plint iX = 0; iX<(plint)knownX.size(); ++iX){
00049         T res = 1.;
00050         for (plint i = 0; i<(plint)knownX.size(); ++i){
00051             if (i!=iX){
00052                 res *= (xValue-knownX[i])/(knownX[iX]-knownX[i]); 
00053             }
00054         }
00055         Linx.push_back(res);
00056     }
00057     
00058     // computation of the y coefficients of the polynomial
00059     std::vector<T> Limy;
00060     for (plint iY = 0; iY<(plint)knownY.size(); ++iY){
00061         T res = 1.;
00062         for (plint i = 0; i<(plint)knownY.size(); ++i){
00063             if (i!=iY){
00064                 res *= (yValue-knownY[i])/(knownY[iY]-knownY[i]); 
00065             }
00066         }
00067         Limy.push_back(res);
00068     }
00069     
00070     // joining the whole following the given formula
00071     T result = 0.;
00072     for (plint iX=0; iX<(plint)knownX.size(); ++iX){
00073         for (plint iY=0; iY<(plint)knownY.size(); ++iY){
00074             result += Linx[iX]*Limy[iY]*knownF[iX][iY];
00075         }
00076     }
00077     return result;
00078 }
00079 
00080 
00081 /* *************** Class ConvectiveRescaleEngine **************************** */
00082    
00083 template<typename T, template<typename U> class Descriptor>
00084 const T ConvectiveRescaleEngine<T,Descriptor>::toFine_xDxInv   = (T) 2.;
00085 
00086 template<typename T, template<typename U> class Descriptor>
00087 const T ConvectiveRescaleEngine<T,Descriptor>::toFine_xDt      = (T)1./(T)2.;
00088 
00089 template<typename T, template<typename U> class Descriptor>
00090 const T ConvectiveRescaleEngine<T,Descriptor>::toCoarse_xDxInv = (T)1./(T)2.;
00091 
00092 template<typename T, template<typename U> class Descriptor>
00093 const T ConvectiveRescaleEngine<T,Descriptor>::toCoarse_xDt    = (T)2.;
00094 
00095 
00096 template<typename T, template<typename U> class Descriptor>
00097 ConvectiveRescaleEngine<T,Descriptor>::ConvectiveRescaleEngine(plint order_)
00098     : order(order_)
00099 { }
00100 
00101 template<typename T, template<typename U> class Descriptor>
00102 void ConvectiveRescaleEngine<T,Descriptor>::scaleCoarseFine (
00103         Cell<T,Descriptor> const& coarseCell, std::vector<T>& decomposedFineValues ) const
00104 {
00105     coarseCell.getDynamics().decompose(coarseCell, decomposedFineValues, order);
00106     T tauCoarse = 1./coarseCell.getDynamics().getOmega();
00107     T tauFine   = 2.*tauCoarse - (T)1./(T)2.;
00108     
00109     if (order == 0){
00110         for (plint iFneq=0; iFneq<Descriptor<T>::q; ++iFneq) {
00111             decomposedFineValues[1+Descriptor<T>::d+iFneq] *= tauFine/tauCoarse;
00112         }
00113     }
00114     else {
00115         for (plint iPineq=0; iPineq < SymmetricTensor<T,Descriptor>::n; ++iPineq) {
00116             decomposedFineValues[1+Descriptor<T>::d+iPineq] *= tauFine/tauCoarse;
00117         }    
00118     }
00119     
00120     coarseCell.getDynamics().rescale( decomposedFineValues, toFine_xDxInv,
00121                                       toFine_xDt, order );
00122     
00123 }
00124 
00125 template<typename T, template<typename U> class Descriptor>
00126 void ConvectiveRescaleEngine<T,Descriptor>::scaleFineCoarse (
00127         Cell<T,Descriptor> const& fineCell, std::vector<T>& decomposedCoarseValues ) const
00128 {
00129     // decompose the fine cell populations
00130     fineCell.getDynamics().decompose(fineCell, decomposedCoarseValues, order);
00131     
00132     // computation of the factor associated with both tau
00133     T tauFine   = 1./fineCell.getDynamics().getOmega();
00134     T tauCoarse = (tauFine+(T)1./(T)2.)/(T)2.;
00135     
00136     if (order == 0){
00137         for (plint iFneq=0; iFneq < Descriptor<T>::q; ++iFneq) {
00138             decomposedCoarseValues[1+Descriptor<T>::d+iFneq] *= tauCoarse/tauFine;
00139         }
00140     }
00141     else {
00142         for (plint iPineq=0; iPineq < SymmetricTensor<T,Descriptor>::n; ++iPineq) {
00143             decomposedCoarseValues[1+Descriptor<T>::d+iPineq] *= tauCoarse/tauFine;
00144         }    
00145     }
00146         
00147     // rescale and copy the values inside decomposedCoarseValues
00148     fineCell.getDynamics().rescale(decomposedCoarseValues, toCoarse_xDxInv,
00149                                    toCoarse_xDt, order);
00150 
00151 }
00152 
00153 template<typename T, template<typename U> class Descriptor>
00154 void ConvectiveRescaleEngine<T,Descriptor>::recompose (
00155         Cell<T,Descriptor>& cell, std::vector<T> const& decomposedValues ) const
00156 {
00157     cell.getDynamics().recompose(cell, decomposedValues, order);
00158 }
00159 
00160 template<typename T, template<typename U> class Descriptor>
00161 plint ConvectiveRescaleEngine<T,Descriptor>::getDecompositionOrder() const {
00162     return order;
00163 }
00164 
00165 template<typename T, template<typename U> class Descriptor>
00166 ConvectiveRescaleEngine<T,Descriptor>* ConvectiveRescaleEngine<T,Descriptor>::clone() const {
00167     return new ConvectiveRescaleEngine<T,Descriptor>(*this);
00168 }
00169 
00170 
00171 /* *************** Class NoScalingEngine ************************************ */
00172 
00173 template<typename T, template<typename U> class Descriptor>
00174 NoScalingEngine<T,Descriptor>::NoScalingEngine(plint order_)
00175     : order(order_)
00176 { }
00177 
00178 template<typename T, template<typename U> class Descriptor>
00179 void NoScalingEngine<T,Descriptor>::scaleCoarseFine (
00180         Cell<T,Descriptor> const& coarseCell, std::vector<T>& decomposedFineValues ) const
00181 {
00182     coarseCell.getDynamics().decompose(coarseCell, decomposedFineValues, order);
00183 }
00184 
00185 template<typename T, template<typename U> class Descriptor>
00186 void NoScalingEngine<T,Descriptor>::scaleFineCoarse (
00187         Cell<T,Descriptor> const& fineCell, std::vector<T>& decomposedCoarseValues ) const
00188 {
00189     fineCell.getDynamics().decompose(fineCell, decomposedCoarseValues, order);
00190 }
00191 
00192 template<typename T, template<typename U> class Descriptor>
00193 void NoScalingEngine<T,Descriptor>::recompose (
00194         Cell<T,Descriptor>& cell, std::vector<T> const& decomposedValues ) const
00195 {
00196     cell.getDynamics().recompose(cell, decomposedValues, order);
00197 }
00198 
00199 template<typename T, template<typename U> class Descriptor>
00200 plint NoScalingEngine<T,Descriptor>::getDecompositionOrder() const {
00201     return order;
00202 }
00203 
00204 template<typename T, template<typename U> class Descriptor>
00205 NoScalingEngine<T,Descriptor>* NoScalingEngine<T,Descriptor>::clone() const {
00206     return new NoScalingEngine<T,Descriptor>(*this);
00207 }
00208 
00209 
00210 /* ************* Interpolations ****************** */
00211 
00213 template<typename T>
00214 void linearInterpolation(std::vector<T>& pop1, std::vector<T>& pop2, std::vector<T>& decomposedValues)
00215 {
00216     PLB_PRECONDITION( pop1.size() == pop2.size() );
00217     decomposedValues.resize(pop1.size());
00218     
00219     for (pluint iVal=0; iVal<decomposedValues.size(); ++iVal) {
00220         decomposedValues[iVal] = 1./2. * (
00221                 pop1[iVal] + pop2[iVal] );
00222     }
00223 }
00224 
00226 template<typename T>
00227 void cubicCenteredInterpolation(std::vector<T>& pop1, std::vector<T>& pop2,
00228                                 std::vector<T>& pop3, std::vector<T>& pop4,
00229                                 std::vector<T>& decomposedValues )
00230 {
00231     PLB_PRECONDITION( pop1.size() == pop2.size() );
00232     decomposedValues.resize(pop1.size());
00233     
00234     for (pluint iVal=0; iVal<decomposedValues.size(); ++iVal) {
00235         decomposedValues[iVal] = 9./16. * (
00236             pop2[iVal] + pop3[iVal] ) -
00237             1./16. * (pop1[iVal] + pop4[iVal] );
00238     }
00239 }
00240 
00242 template<typename T>
00243 void quadraticNonCenteredInterpolation(std::vector<T>& pop1, std::vector<T>& pop2,
00244                                    std::vector<T>& pop3, std::vector<T>& decomposedValues )
00245 {
00246     PLB_PRECONDITION( pop1.size() == pop2.size() );
00247     decomposedValues.resize(pop1.size());
00248     
00249     for (pluint iVal=0; iVal<decomposedValues.size(); ++iVal) {
00250         decomposedValues[iVal] = 3./8.*pop1[iVal] + 3./4.*pop2[iVal] -1./8.*pop3[iVal];
00251     }
00252 }
00253 
00254 
00255 
00256 
00257 }  // namespace plb
00258 
00259 #endif  // GRID_REFINEMENT_HH