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

momentTemplates2D.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 
00029 #ifndef MOMENT_TEMPLATES_2D_H
00030 #define MOMENT_TEMPLATES_2D_H
00031 
00032 #include "core/globalDefs.h"
00033 #include "latticeBoltzmann/nearestNeighborLattices2D.h"
00034 #include "latticeBoltzmann/geometricOperationTemplates.h"
00035 
00036 namespace plb {
00037 
00038 // Efficient specialization for D2Q9 base lattice
00039 template<typename T>
00040 struct momentTemplatesImpl<T, descriptors::D2Q9DescriptorBase<T> > {
00041 
00042 typedef descriptors::D2Q9DescriptorBase<T> Descriptor;
00043 
00044 static void partial_rho ( Array<T,Descriptor::q> const& f,
00045                           T& lineX_P1, T& lineX_0, T& lineX_M1, T& lineY_P1, T& lineY_M1 )
00046 {
00047     lineX_P1  = f[5] + f[6] + f[7];
00048     lineX_0   = f[0] + f[4] + f[8];
00049     lineX_M1  = f[1] + f[2] + f[3];
00050 
00051     lineY_P1  = f[7] + f[8] + f[1];
00052     lineY_M1  = f[3] + f[4] + f[5];
00053 }
00054 
00055 static T get_rhoBar(Array<T,Descriptor::q> const& f) {
00056     T rhoBar = f[0] + f[1] + f[2] + f[3] + f[4]
00057                        + f[5] + f[6] + f[7] + f[8];
00058     return rhoBar;
00059 }
00060 
00061 static void get_j(Array<T,Descriptor::q> const& f, Array<T,2>& j ) {
00062     T lineX_P1, lineX_M1, lineY_P1, lineY_M1;
00063 
00064     lineX_P1  = f[5] + f[6] + f[7];
00065     lineX_M1  = f[1] + f[2] + f[3];
00066     lineY_P1  = f[7] + f[8] + f[1];
00067     lineY_M1  = f[3] + f[4] + f[5];
00068 
00069     j[0]  = (lineX_P1 - lineX_M1);
00070     j[1]  = (lineY_P1 - lineY_M1);
00071 }
00072 
00073 static T get_eBar(Array<T,Descriptor::q> const& f) {
00074     T eBar = (T)2 * (f[1] + f[3] + f[5] + f[7])
00075                    + f[2] + f[4] + f[6] + f[8];
00076     return eBar;
00077 }
00078 
00079 
00080 static void get_rhoBar_j(Array<T,Descriptor::q> const& f, T& rhoBar, Array<T,2>& j) {
00081     T lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1;
00082     partial_rho(f, lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1);
00083 
00084     rhoBar = lineX_P1 + lineX_0 + lineX_M1;
00085     j[0]  = (lineX_P1 - lineX_M1);
00086     j[1]  = (lineY_P1 - lineY_M1);
00087 }
00088 
00089 static T compute_rho(Array<T,Descriptor::q> const& f) {
00090     return Descriptor::fullRho(get_rhoBar(f));
00091 }
00092 
00093 static void compute_uLb(Array<T,Descriptor::q> const& f, Array<T,2>& uLb ) {
00094     T rhoBar;
00095     get_rhoBar_j(f, rhoBar, uLb);
00096     T invRho = Descriptor::invRho(rhoBar);
00097     uLb[0] *= invRho;
00098     uLb[1] *= invRho;
00099 }
00100 
00101 static void compute_rho_uLb(Array<T,Descriptor::q> const& f, T& rho, Array<T,2>& uLb ) {
00102     T rhoBar;
00103     get_rhoBar_j(f, rhoBar, uLb);
00104     rho = Descriptor::fullRho(rhoBar);
00105     T invRho = Descriptor::invRho(rhoBar);
00106     uLb[0] *= invRho;
00107     uLb[1] *= invRho;
00108 }
00109 
00110 static T compute_e(Array<T,Descriptor::q> const& f) {
00111     return get_eBar(f) + Descriptor::SkordosFactor * Descriptor::d * Descriptor::cs2;
00112 }
00113 
00114 static T compute_rhoThetaBar(Array<T,Descriptor::q> const& f, T rhoBar, T jSqr) {
00115     T invRho = Descriptor::invRho(rhoBar);
00116     return Descriptor::invCs2 * Descriptor::invD * (get_eBar(f) - invRho*jSqr) - rhoBar;
00117 }
00118 
00119 static void compute_rho_rhoThetaBar(Array<T,Descriptor::q> const& f, T& rho, T& rhoThetaBar) {
00120     T j[Descriptor::d], rhoBar;
00121     get_rhoBar_j(f, rhoBar, j);
00122     T jSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(j);
00123     rho = Descriptor::fullRho(rhoBar);
00124     rhoThetaBar = compute_rhoThetaBar(f, rhoBar, jSqr);
00125 }
00126 
00127 static T compute_theta(Array<T,Descriptor::q> const& f, T rhoBar, T jSqr) {
00128     T invRho = Descriptor::invRho(rhoBar);
00129     T e = compute_e(f);
00130     return invRho * Descriptor::invD * Descriptor::invCs2 * (e - invRho*jSqr);
00131 }
00132 
00133 static T compute_rhoEpsilon(Array<T,Descriptor::q> const& f, T rhoBar, T jSqr) {
00134     T invRho = Descriptor::invRho(rhoBar);
00135     T e = compute_e(f);
00136     return (e - invRho*jSqr) / (T)2;
00137 }
00138 
00139 static void compute_PiNeq(Array<T,Descriptor::q> const& f, T rhoBar, Array<T,2> const& j, Array<T,3>& PiNeq, bool incompr)
00140 {
00141     typedef SymmetricTensorImpl<T,2> S;
00142 
00143     T invRho = incompr ? (T)1 : Descriptor::invRho(rhoBar);
00144     T lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1;
00145     partial_rho(f, lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1);
00146 
00147     PiNeq[S::xx] = lineX_P1+lineX_M1 - Descriptor::cs2*rhoBar - invRho*j[0]*j[0];
00148     PiNeq[S::yy] = lineY_P1+lineY_M1 - Descriptor::cs2*rhoBar - invRho*j[1]*j[1];
00149     PiNeq[S::xy] = -f[1] + f[3] - f[5] + f[7] - invRho*j[0]*j[1];
00150 }
00151 
00152 static void compute_thermal_PiNeq(Array<T,Descriptor::q> const& f, T rhoBar, T thetaBar,
00153                                   Array<T,2> const& j, Array<T,3>& PiNeq) {
00154     typedef SymmetricTensorImpl<T,2> S;
00155 
00156     T rhoTheta_bar = rhoBar*thetaBar + rhoBar + Descriptor::SkordosFactor*thetaBar;
00157     T invRho = Descriptor::invRho(rhoBar);
00158     T lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1;
00159     partial_rho(f, lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1);
00160 
00161     PiNeq[S::xx] = lineX_P1+lineX_M1 - Descriptor::cs2*rhoTheta_bar - invRho*j[0]*j[0];
00162     PiNeq[S::yy] = lineY_P1+lineY_M1 - Descriptor::cs2*rhoTheta_bar - invRho*j[1]*j[1];
00163     PiNeq[S::xy] = -f[1] + f[3] - f[5] + f[7] - invRho*j[0]*j[1];
00164 }
00165 
00166 static void compute_rhoBar_j_PiNeq(Array<T,Descriptor::q> const& f, T& rhoBar, Array<T,2>& j, Array<T,3>& PiNeq, bool incompr)
00167 {
00168     typedef SymmetricTensorImpl<T,2> S;
00169 
00170     T lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1;
00171     partial_rho(f, lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1);
00172 
00173     rhoBar = lineX_P1 + lineX_0 + lineX_M1;
00174     j[0]   = lineX_P1 - lineX_M1;
00175     j[1]   = lineY_P1 - lineY_M1;
00176     T invRho = incompr ? (T)1 : Descriptor::invRho(rhoBar);
00177     PiNeq[S::xx] = lineX_P1+lineX_M1 - Descriptor::cs2*rhoBar - invRho*j[0]*j[0];
00178     PiNeq[S::yy] = lineY_P1+lineY_M1 - Descriptor::cs2*rhoBar - invRho*j[1]*j[1];
00179     PiNeq[S::xy] = -f[1] + f[3] - f[5] + f[7] - invRho*j[0]*j[1];
00180 }
00181 
00182 static void compute_rhoBar_thetaBar_j_PiNeq(Array<T,Descriptor::q> const& f, T& rhoBar, T& thetaBar,
00183                                             Array<T,2> const& j, Array<T,3>& PiNeq)
00184 {
00185     get_rhoBar_j(f, rhoBar, j);
00186     compute_PiNeq(f, rhoBar, j, PiNeq);
00187     T rhoThetaBar = compute_rhoThetaBar(f);
00188     thetaBar = rhoThetaBar * Descriptor::invRho(rhoBar);
00189     compute_thermal_PiNeq(f, rhoBar, thetaBar, j, PiNeq);
00190 }
00191 
00192 static void compute_P(Array<T,Descriptor::q> const& f, T rhoBar, Array<T,2> const& j, Array<T,3>& P) {
00193     typedef SymmetricTensorImpl<T,2> S;
00194 
00195     T invRho = Descriptor::invRho(rhoBar);
00196     T lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1;
00197     partial_rho(f, lineX_P1, lineX_0, lineX_M1, lineY_P1, lineY_M1);
00198 
00199     P[S::xx] = lineX_P1+lineX_M1 - invRho*j[0]*j[0];
00200     P[S::yy] = lineY_P1+lineY_M1 - invRho*j[1]*j[1];
00201     P[S::xy] = -f[1] + f[3] - f[5] + f[7] - invRho*j[0]*j[1];
00202 }
00203 
00204 static void modifyJ(Array<T,Descriptor::q>& f, Array<T,2> const& newJ) {
00205     T rhoBar;
00206     Array<T,2> oldJ;
00207     get_rhoBar_j(f, rhoBar, oldJ);
00208     const T oldJSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(oldJ);
00209     const T newJSqr = VectorTemplateImpl<T,Descriptor::d>::normSqr(newJ);
00210     for (plint iPop=0; iPop<Descriptor::q; ++iPop) {
00211         f[iPop] = f[iPop]
00212                          - equilibrium(iPop, rhoBar, oldJ, oldJSqr)
00213                          + equilibrium(iPop, rhoBar, newJ, newJSqr);
00214     }
00215 }
00216 
00217 };  //struct momentTemplatesImlp<D2Q9DescriptorBase>
00218 
00219 }  // namespace plb
00220 
00221 #endif  // MOMENT_TEMPLATES_2D_H