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

dynamicsTemplates.h

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 
00031 #ifndef DYNAMICS_TEMPLATES_H
00032 #define DYNAMICS_TEMPLATES_H
00033 
00034 #include "core/globalDefs.h"
00035 #include "core/cell.h"
00036 #include "core/util.h"
00037 #include "latticeBoltzmann/offEquilibriumTemplates.h"
00038 
00039 namespace plb {
00040 
00041 template<typename T, class Descriptor> struct dynamicsTemplatesImpl;
00042 
00044 template<typename T, template<typename U> class Descriptor>
00045 struct dynamicsTemplates {
00046 
00047 static T bgk_ma2_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j, T jSqr) {
00048     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00049         ::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00050 }
00051 
00052 static void bgk_ma2_equilibria( T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j,
00053                                 T jSqr, Array<T,Descriptor<T>::q>& eqPop )
00054 {
00055     dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00056         ::bgk_ma2_equilibria(rhoBar, invRho, j, jSqr, eqPop);
00057 }
00058 
00059 static T bgk_ma2_collision(Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j, T omega)
00060 {
00061     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00062         ::bgk_ma2_collision(cell.getRawPopulations(), rhoBar, j, omega);
00063 }
00064 
00065 static T bgk_inc_collision(Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j, T omega)
00066 {
00067     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00068         ::bgk_inc_collision(cell.getRawPopulations(), rhoBar, j, omega);
00069 }
00070 
00071 static T rlb_collision(Cell<T,Descriptor>& cell, T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j,
00072                        Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq, T omega )
00073 {
00074     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00075         ::rlb_collision(cell.getRawPopulations(), rhoBar, invRho, j, PiNeq, omega);
00076 }
00077 
00078 static T bgk_ma2_constRho_collision(Cell<T,Descriptor>& cell,
00079                                 T rhoBar, Array<T,Descriptor<T>::d> const& j, T ratioRho, T omega)
00080 {
00081     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00082                ::bgk_ma2_constRho_collision(cell.getRawPopulations(), rhoBar, j, ratioRho, omega);
00083 }
00084 
00085 static T precond_bgk_ma2_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j, T jSqr, T invGamma)
00086 {
00087     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00088         ::precond_bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr, invGamma);
00089 }
00090 
00091 static T precond_bgk_ma2_collision(Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j, T omega, T invGamma)
00092 {
00093     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00094         ::precond_bgk_ma2_collision(cell.getRawPopulations(), rhoBar, j, omega, invGamma);
00095 }
00096 
00097 static T bgk_ma4_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j, T jSqr, T rhoThetaBar) {
00098     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00099         ::bgk_ma4_equilibrium(iPop, rhoBar, invRho, j, jSqr, rhoThetaBar);
00100 }
00101 
00102 static T bgk_ma4_collision(Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j, T rhoThetaBar, T omega)
00103 {
00104     return dynamicsTemplatesImpl<T,typename Descriptor<T>::BaseDescriptor>
00105         ::bgk_ma4_collision(cell.getRawPopulations(), rhoBar, j, rhoThetaBar, omega);
00106 }
00107 
00108 };  // struct dynamicsTemplates
00109 
00110 
00112 template<typename T, class Descriptor>
00113 struct dynamicsTemplatesImpl {
00114 
00115 static T bgk_ma2_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor::d> const& j, T jSqr) {
00116     T c_j = Descriptor::c[iPop][0]*j[0];
00117     for (int iD=1; iD < Descriptor::d; ++iD) {
00118        c_j += Descriptor::c[iPop][iD]*j[iD];
00119     }
00120     return Descriptor::t[iPop] * (
00121            rhoBar + Descriptor::invCs2 * c_j +
00122            Descriptor::invCs2/(T)2 * invRho * (
00123                Descriptor::invCs2 * c_j*c_j - jSqr )
00124        );
00125 }
00126 
00127 static void bgk_ma2_equilibria( T rhoBar, T invRho, Array<T,Descriptor::d>
00128         const& j,
00129                                 T jSqr, Array<T,Descriptor::q>& eqPop )
00130 {
00131     for (int iPop=0; iPop<Descriptor::d; ++iPop) {
00132         eqPop[iPop] = bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00133     }
00134 }
00135 
00136 static T bgk_ma2_collision(Array<T,Descriptor::q>& f, T rhoBar, Array<T,Descriptor::d> const& j, T omega) {
00137     T invRho = Descriptor::invRho(rhoBar);
00138     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00139     for (plint iPop=0; iPop < Descriptor::q; ++iPop) {
00140         f[iPop] *= (T)1-omega;
00141         f[iPop] += omega * dynamicsTemplatesImpl<T,Descriptor>::bgk_ma2_equilibrium (
00142                                 iPop, rhoBar, invRho, j, jSqr );
00143     }
00144     return jSqr*invRho*invRho;
00145 }
00146 
00147 static T bgk_inc_collision(Array<T,Descriptor::q>& f, T rhoBar, Array<T,Descriptor::d> const& j, T omega) {
00148     // In incompressible BGK, the Ma^2 term is preceeded by 1 instead of 1/rho.
00149     T invRho = (T)1;
00150     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00151     for (plint iPop=0; iPop < Descriptor::q; ++iPop) {
00152         f[iPop] *= (T)1-omega;
00153         f[iPop] += omega * dynamicsTemplatesImpl<T,Descriptor>::bgk_ma2_equilibrium (
00154                                 iPop, rhoBar, invRho, j, jSqr );
00155     }
00156     return jSqr;
00157 }
00158 
00159 static T rlb_collision (
00160     Array<T,Descriptor::q>& f, T rhoBar, T invRho, Array<T,Descriptor::d> const& j,
00161     Array<T,SymmetricTensorImpl<T,Descriptor::d>::n> const& PiNeq, T omega )
00162 {
00163     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00164     f[0] = dynamicsTemplatesImpl<T,Descriptor>::bgk_ma2_equilibrium(0, rhoBar, invRho, j, jSqr)
00165                   + ((T)1-omega) *
00166                         offEquilibriumTemplatesImpl<T,Descriptor>::fromPiToFneq(0, PiNeq);
00167     for (plint iPop=1; iPop<=Descriptor::q/2; ++iPop) {
00168         f[iPop] = dynamicsTemplatesImpl<T,Descriptor>::
00169                 bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00170         f[iPop+Descriptor::q/2] = dynamicsTemplatesImpl<T,Descriptor>::
00171                 bgk_ma2_equilibrium(iPop+Descriptor::q/2, rhoBar, invRho, j, jSqr);
00172         T fNeq = ((T)1-omega) *
00173                  offEquilibriumTemplatesImpl<T,Descriptor>::fromPiToFneq(iPop, PiNeq);
00174         f[iPop] += fNeq;
00175         f[iPop+Descriptor::q/2] += fNeq;
00176     }
00177     return jSqr*invRho*invRho;
00178 }
00179 
00180 static T bgk_ma2_constRho_collision(Array<T,Descriptor::q>& f, T rhoBar, Array<T,Descriptor::d> const& j, T ratioRho, T omega) {
00181     T invRho = Descriptor::invRho(rhoBar);
00182     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00183     for (plint iPop=0; iPop < Descriptor::q; ++iPop) {
00184         T feq = dynamicsTemplatesImpl<T,Descriptor>::
00185                     bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr );
00186         f[iPop] =
00187           ratioRho*feq + Descriptor::t[iPop]*(ratioRho-(T)1) +
00188           ((T)1-omega)*(f[iPop]-feq);
00189     }
00190     return jSqr*invRho*invRho;
00191 }
00192 
00193 static T precond_bgk_ma2_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor::d> const& j, T jSqr, T invGamma) {
00194     T c_j = Descriptor::c[iPop][0]*j[0];
00195     for (int iD=1; iD < Descriptor::d; ++iD) {
00196        c_j += Descriptor::c[iPop][iD]*j[iD];
00197     }
00198     return Descriptor::t[iPop] * (
00199            rhoBar + Descriptor::invCs2 * c_j +
00200            invGamma * Descriptor::invCs2/(T)2 * invRho * (
00201                Descriptor::invCs2 * c_j*c_j - jSqr )
00202        );
00203 }
00204 
00205 static T precond_bgk_ma2_collision(Array<T,Descriptor::q>& f, T rhoBar, Array<T,Descriptor::d> const& j, T omega, T invGamma) {
00206     T invRho = Descriptor::invRho(rhoBar);
00207     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00208     for (plint iPop=0; iPop < Descriptor::q; ++iPop) {
00209         f[iPop] *= (T)1-omega;
00210         f[iPop] += omega * dynamicsTemplatesImpl<T,Descriptor>::precond_bgk_ma2_equilibrium (
00211                                 iPop, rhoBar, invRho, j, jSqr, invGamma );
00212     }
00213     return jSqr*invRho*invRho;
00214 }
00215 
00216 static T bgk_ma4_equilibrium(plint iPop, T rhoBar, T invRho, Array<T,Descriptor::d> const& j, T jSqr, T rhoThetaBar) {
00217     typedef Descriptor L;
00218     T c_j = (T)L::c[iPop][0]*j[0];
00219     for (int iD=1; iD < L::d; ++iD) {
00220         c_j += (T)L::c[iPop][iD]*j[iD];
00221     }
00222     
00223     T c_u = c_j*invRho;
00224     T uSqr = jSqr*invRho*invRho;
00225     T thetaBar = invRho*rhoThetaBar;
00226     
00227     return L::t[iPop] * (
00228         rhoBar + L::invCs2 * c_j +
00229         L::invCs2/(T)2 * ( invRho * (L::invCs2 * c_j*c_j - jSqr )
00230                                     + rhoThetaBar * ((T)L::cNormSqr[iPop]-L::cs2*(T)L::d))
00231         + L::invCs2*L::invCs2*L::invCs2/(T)6 * c_j * (
00232             c_u*c_u-(T)3*L::cs2*uSqr+(T)3*L::cs2*thetaBar*(L::cNormSqr[iPop]-L::cs2*((T)L::d+(T)2))
00233         )
00234         + L::invCs2*L::invCs2*L::invCs2*L::invCs2/(T)24 * (
00235             c_j*c_u*c_u*c_u - (T)6*L::cs2*uSqr*c_j*c_u + (T)3*L::cs2*L::cs2*jSqr*invRho*uSqr
00236             + (T)6*L::cs2*rhoThetaBar*(c_u*c_u*((T)L::cNormSqr[iPop]-L::cs2*((T)L::d+(T)4))+L::cs2*uSqr*(L::cs2*((T)L::d+(T)2)-(T)L::cNormSqr[iPop]))
00237             + (T)3*L::cs2*L::cs2*rhoThetaBar*rhoThetaBar*invRho*(
00238                 (T)L::cNormSqr[iPop]*(T)L::cNormSqr[iPop]-(T)2*L::cs2*(L::d+2)*L::cNormSqr[iPop]+L::cs2*L::cs2*(T)L::d*((T)L::d+(T)2)
00239             )
00240         )
00241     );
00242 }
00243 
00244 static T bgk_ma4_collision(Array<T,Descriptor::q>& f, T rhoBar, Array<T,Descriptor::d> const& j, T rhoThetaBar, T omega) {
00245     T invRho = Descriptor::invRho(rhoBar);
00246     const T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00247     for (plint iPop=0; iPop < Descriptor::q; ++iPop) {
00248         f[iPop] *= (T)1-omega;
00249         f[iPop] += omega * dynamicsTemplatesImpl<T,Descriptor>::bgk_ma4_equilibrium (
00250             iPop, rhoBar, invRho, j, jSqr, rhoThetaBar);
00251     }
00252     return jSqr*invRho*invRho;
00253 }
00254 
00255 };  // struct dynamicsTemplatesImpl
00256 
00257 }  // namespace plb
00258 
00259 #include "latticeBoltzmann/dynamicsTemplates2D.h"
00260 #include "latticeBoltzmann/dynamicsTemplates3D.h"
00261 
00262 #endif  // DYNAMICS_TEMPLATES_H