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

isoThermalDynamics.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 
00029 #ifndef ISO_THERMAL_DYNAMICS_HH
00030 #define ISO_THERMAL_DYNAMICS_HH
00031 
00032 #include "basicDynamics/isoThermalDynamics.h"
00033 #include "core/cell.h"
00034 #include "core/dynamicsIdentifiers.h"
00035 #include "latticeBoltzmann/dynamicsTemplates.h"
00036 #include "latticeBoltzmann/momentTemplates.h"
00037 #include "latticeBoltzmann/externalForceTemplates.h"
00038 #include "latticeBoltzmann/offEquilibriumTemplates.h"
00039 #include "latticeBoltzmann/d3q13Templates.h"
00040 #include "latticeBoltzmann/geometricOperationTemplates.h"
00041 #include "core/latticeStatistics.h"
00042 #include <algorithm>
00043 #include <limits>
00044 
00045 namespace plb {
00046 
00047 /* *************** Class IsoThermalBulkDynamics ************************************ */
00048 
00049 template<typename T, template<typename U> class Descriptor>
00050 IsoThermalBulkDynamics<T,Descriptor>::IsoThermalBulkDynamics(T omega_)
00051   : BasicBulkDynamics<T,Descriptor>(omega_)
00052 { }
00053 
00054 template<typename T, template<typename U> class Descriptor>
00055 void IsoThermalBulkDynamics<T,Descriptor>::regularize (
00056          Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00057          T jSqr, Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq, T thetaBar ) const
00058 {
00059     typedef Descriptor<T> L;
00060     cell[0] = this->computeEquilibrium(0, rhoBar, j, jSqr)
00061                 + offEquilibriumTemplates<T,Descriptor>::fromPiToFneq(0, PiNeq);
00062     for (plint iPop=1; iPop<=L::q/2; ++iPop) {
00063         cell[iPop] = this->computeEquilibrium(iPop, rhoBar, j, jSqr);
00064         cell[iPop+L::q/2] = this->computeEquilibrium(iPop+L::q/2, rhoBar, j, jSqr);
00065         T fNeq = offEquilibriumTemplates<T,Descriptor>::fromPiToFneq(iPop, PiNeq);
00066         cell[iPop] += fNeq;
00067         cell[iPop+L::q/2] += fNeq;
00068     }
00069 }
00070 
00071 template<typename T, template<typename U> class Descriptor>
00072 T IsoThermalBulkDynamics<T,Descriptor>::computeTemperature(Cell<T,Descriptor> const& cell) const
00073 {
00074     return (T)1;
00075 }
00076 
00077 template<typename T, template<typename U> class Descriptor>
00078 void IsoThermalBulkDynamics<T,Descriptor>::computeDeviatoricStress (
00079     Cell<T,Descriptor> const& cell, Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00080 {
00081     T rhoBar;
00082     Array<T,Descriptor<T>::d> j;
00083     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00084     momentTemplates<T,Descriptor>::compute_PiNeq(cell, rhoBar, j, PiNeq);
00085 }
00086 
00087 template<typename T, template<typename U> class Descriptor>
00088 void IsoThermalBulkDynamics<T,Descriptor>::computeHeatFlux (
00089         Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& q ) const
00090 {
00091     q.resetToZero();
00092 }
00093 
00094 template<typename T, template<typename U> class Descriptor>
00095 T IsoThermalBulkDynamics<T,Descriptor>::computeEbar(Cell<T,Descriptor> const& cell) const
00096 {
00097     return T();
00098 }
00099 
00100 
00101 template<typename T, template<typename U> class Descriptor>
00102 plint IsoThermalBulkDynamics<T,Descriptor>::numDecomposedVariables(plint order) const {
00103     // Start with the decomposed version of the populations.
00104     plint numVariables =
00105                          // Order 0: density + velocity + fNeq
00106         ( order == 0 ) ? ( 1 + Descriptor<T>::d + Descriptor<T>::q )
00107                          // Order >=1: density + velocity + PiNeq
00108                        : ( 1 + Descriptor<T>::d + SymmetricTensor<T,Descriptor>::n );
00109 
00110     // Add the variables in the external scalars.
00111     numVariables += Descriptor<T>::ExternalField::numScalars;
00112     return numVariables;
00113 }
00114 
00115 template<typename T, template<typename U> class Descriptor>
00116 void IsoThermalBulkDynamics<T,Descriptor>::decompose (
00117         Cell<T,Descriptor> const& cell, std::vector<T>& rawData, plint order ) const
00118 {
00119     rawData.resize(numDecomposedVariables(order));
00120 
00121     if (order==0) {
00122         decomposeOrder0(cell, rawData);
00123     }
00124     else {
00125         decomposeOrder1(cell, rawData);
00126     }
00127 }
00128 
00129 template<typename T, template<typename U> class Descriptor>
00130 void IsoThermalBulkDynamics<T,Descriptor>::recompose (
00131         Cell<T,Descriptor>& cell, std::vector<T> const& rawData, plint order ) const
00132 {
00133     PLB_PRECONDITION( (plint)rawData.size() == numDecomposedVariables(order) );
00134 
00135     if (order==0) {
00136         recomposeOrder0(cell, rawData);
00137     }
00138     else {
00139         recomposeOrder1(cell, rawData);
00140     }
00141 }
00142 
00143 template<typename T, template<typename U> class Descriptor>
00144 void IsoThermalBulkDynamics<T,Descriptor>::rescale (
00145         std::vector<T>& rawData, T xDxInv, T xDt, plint order ) const
00146 {
00147     PLB_PRECONDITION( (plint)rawData.size()==numDecomposedVariables(order) );
00148 
00149     if (order==0) {
00150         rescaleOrder0(rawData, xDxInv, xDt);
00151     }
00152     else {
00153         rescaleOrder1(rawData, xDxInv, xDt);
00154     }
00155 }
00156 
00157 template<typename T, template<typename U> class Descriptor>
00158 void IsoThermalBulkDynamics<T,Descriptor>::decomposeOrder0 (
00159         Cell<T,Descriptor> const& cell, std::vector<T>& rawData ) const
00160 {
00161     T rhoBar;
00162     Array<T,Descriptor<T>::d> j;
00163     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00164     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00165     rawData[0] = rhoBar;
00166     j.to_cArray(&rawData[1]);
00167 
00168     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00169         rawData[1+Descriptor<T>::d+iPop] =
00170             cell[iPop] - this->computeEquilibrium(iPop, rhoBar, j, jSqr);
00171     }
00172 
00173     int offset = 1+Descriptor<T>::d+Descriptor<T>::q;
00174     for (plint iExt=0; iExt<Descriptor<T>::ExternalField::numScalars; ++iExt) {
00175         rawData[offset+iExt] = *cell.getExternal(iExt);
00176     }
00177 }
00178 
00179 template<typename T, template<typename U> class Descriptor>
00180 void IsoThermalBulkDynamics<T,Descriptor>::decomposeOrder1 (
00181         Cell<T,Descriptor> const& cell, std::vector<T>& rawData ) const
00182 {
00183     T rhoBar;
00184     Array<T,Descriptor<T>::d> j;
00185     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00186     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq);
00187 
00188     rawData[0] = rhoBar;
00189     j.to_cArray(&rawData[1]);
00190     PiNeq.to_cArray(&rawData[1+Descriptor<T>::d]);
00191 
00192     int offset = 1+Descriptor<T>::d+SymmetricTensor<T,Descriptor>::n;
00193     for (plint iExt=0; iExt<Descriptor<T>::ExternalField::numScalars; ++iExt) {
00194         rawData[offset+iExt] = *cell.getExternal(iExt);
00195     }
00196 }
00197 
00198 template<typename T, template<typename U> class Descriptor>
00199 void IsoThermalBulkDynamics<T,Descriptor>::recomposeOrder0 (
00200         Cell<T,Descriptor>& cell, std::vector<T> const& rawData ) const
00201 {
00202     T rhoBar = rawData[0];
00203     Array<T,Descriptor<T>::d> j;
00204     j.from_cArray(&rawData[1]);
00205     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00206 
00207     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00208         cell[iPop] = this->computeEquilibrium(iPop, rhoBar, j, jSqr)
00209                       + rawData[1+Descriptor<T>::d+iPop];
00210     }
00211 
00212     int offset = 1+Descriptor<T>::d+Descriptor<T>::q;
00213     for (plint iExt=0; iExt<Descriptor<T>::ExternalField::numScalars; ++iExt) {
00214         *cell.getExternal(iExt) = rawData[offset+iExt];
00215     }
00216 }
00217 
00218 template<typename T, template<typename U> class Descriptor>
00219 void IsoThermalBulkDynamics<T,Descriptor>::recomposeOrder1 (
00220         Cell<T,Descriptor>& cell, std::vector<T> const& rawData ) const
00221 {
00222     typedef Descriptor<T> L;
00223 
00224     T rhoBar;
00225     Array<T,Descriptor<T>::d> j;
00226     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00227 
00228     rhoBar = rawData[0];
00229     j.from_cArray(&rawData[1]);
00230     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00231     PiNeq.from_cArray(&rawData[1+Descriptor<T>::d]);
00232 
00233     cell[0] = this->computeEquilibrium(0, rhoBar, j, jSqr)
00234                 + offEquilibriumTemplates<T,Descriptor>::fromPiToFneq(0, PiNeq);
00235     for (plint iPop=1; iPop<=L::q/2; ++iPop) {
00236         cell[iPop] = this->computeEquilibrium(iPop, rhoBar, j, jSqr);
00237         cell[iPop+L::q/2] = this->computeEquilibrium(iPop+L::q/2, rhoBar, j, jSqr);
00238         T fNeq = offEquilibriumTemplates<T,Descriptor>::fromPiToFneq(iPop, PiNeq);
00239         cell[iPop] += fNeq;
00240         cell[iPop+L::q/2] += fNeq;
00241     }
00242 
00243     int offset = 1+Descriptor<T>::d+SymmetricTensor<T,Descriptor>::n;
00244     for (plint iExt=0; iExt<Descriptor<T>::ExternalField::numScalars; ++iExt) {
00245         *cell.getExternal(iExt) = rawData[offset+iExt];
00246     }
00247 }
00248 
00249 template<typename T, template<typename U> class Descriptor>
00250 void IsoThermalBulkDynamics<T,Descriptor>::rescaleOrder0 (
00251         std::vector<T>& rawData, T xDxInv, T xDt ) const
00252 {
00253     // Don't change rho (rawData[0]), because it is invariant
00254 
00255     // Change velocity, according to its units dx/dt
00256     T velScale = xDt * xDxInv;
00257     for (plint iVel=0; iVel<Descriptor<T>::d; ++iVel) {
00258         rawData[1+iVel] *= velScale;
00259     }
00260 
00261     // Change off-equilibrium, according to its units 1/dt
00262     T fNeqScale = xDt;
00263     for (plint iFneq=0; iFneq<Descriptor<T>::q; ++iFneq) {
00264         rawData[1+Descriptor<T>::d+iFneq] *= fNeqScale;
00265     }
00266 
00267     // Don't change external fields; their scaling must be taken care of
00268     //   in specialized versions of this class.
00269 }
00270 
00271 template<typename T, template<typename U> class Descriptor>
00272 void IsoThermalBulkDynamics<T,Descriptor>::rescaleOrder1 (
00273         std::vector<T>& rawData, T xDxInv, T xDt ) const
00274 {
00275     // Don't change rho (rawData[0]), because it is invariant
00276 
00277     // Change velocity, according to its units dx/dt
00278     T velScale = xDt * xDxInv;
00279     for (plint iVel=0; iVel<Descriptor<T>::d; ++iVel) {
00280         rawData[1+iVel] *= velScale;
00281     }
00282 
00283     // Change off-equilibrium stress, according to its units 1/dt
00284     T PiNeqScale = xDt;
00285     for (plint iPi=0; iPi<SymmetricTensor<T,Descriptor>::n; ++iPi) {
00286         rawData[1+Descriptor<T>::d+iPi] *= PiNeqScale;
00287     }
00288 
00289     // Don't change external fields; their scaling must be taken care of
00290     //   in specialized versions of this class.
00291 }
00292 
00293 /* *************** Class BGKdynamics *********************************************** */
00294 
00295 template<typename T, template<typename U> class Descriptor>
00296 int BGKdynamics<T,Descriptor>::id =
00297     meta::registerOneParamDynamics<T,Descriptor,BGKdynamics<T,Descriptor> >("BGK");
00298 
00301 template<typename T, template<typename U> class Descriptor>
00302 BGKdynamics<T,Descriptor>::BGKdynamics(T omega_ )
00303     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00304 { }
00305 
00306 template<typename T, template<typename U> class Descriptor>
00307 BGKdynamics<T,Descriptor>* BGKdynamics<T,Descriptor>::clone() const {
00308     return new BGKdynamics<T,Descriptor>(*this);
00309 }
00310 
00311 template<typename T, template<typename U> class Descriptor>
00312 int BGKdynamics<T,Descriptor>::getId() const {
00313     return id;
00314 }
00315 
00316 template<typename T, template<typename U> class Descriptor>
00317 void BGKdynamics<T,Descriptor>::collide (
00318         Cell<T,Descriptor>& cell,
00319         BlockStatistics& statistics )
00320 {
00321     T rhoBar;
00322     Array<T,Descriptor<T>::d> j;
00323     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00324     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00325     if (cell.takesStatistics()) {
00326         gatherStatistics(statistics, rhoBar, uSqr);
00327     }
00328 }
00329 
00330 template<typename T, template<typename U> class Descriptor>
00331 void BGKdynamics<T,Descriptor>::collide (
00332         Cell<T,Descriptor>& cell, T rhoBar,
00333         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00334 {
00335     dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00336 }
00337 
00338 template<typename T, template<typename U> class Descriptor>
00339 T BGKdynamics<T,Descriptor>::computeEquilibrium(plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00340                                                 T jSqr, T thetaBar) const
00341 {
00342     T invRho = Descriptor<T>::invRho(rhoBar);
00343     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00344 }
00345 
00346 
00347 /* *************** Class StoreRhoBarJBGKdynamics *********************************************** */
00348 
00349 template<typename T, template<typename U> class Descriptor>
00350 int StoreRhoBarJBGKdynamics<T,Descriptor>::id =
00351     meta::registerOneParamDynamics<T,Descriptor,StoreRhoBarJBGKdynamics<T,Descriptor> >
00352         ("StoreRhoBarJBGK");
00353 
00356 template<typename T, template<typename U> class Descriptor>
00357 StoreRhoBarJBGKdynamics<T,Descriptor>::StoreRhoBarJBGKdynamics(T omega_ )
00358     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00359 { }
00360 
00361 template<typename T, template<typename U> class Descriptor>
00362 StoreRhoBarJBGKdynamics<T,Descriptor>* StoreRhoBarJBGKdynamics<T,Descriptor>::clone() const {
00363     return new StoreRhoBarJBGKdynamics<T,Descriptor>(*this);
00364 }
00365 
00366 template<typename T, template<typename U> class Descriptor>
00367 int StoreRhoBarJBGKdynamics<T,Descriptor>::getId() const {
00368     return id;
00369 }
00370 
00371 template<typename T, template<typename U> class Descriptor>
00372 void StoreRhoBarJBGKdynamics<T,Descriptor>::collide (
00373         Cell<T,Descriptor>& cell,
00374         BlockStatistics& statistics )
00375 {
00376     T rhoBar;
00377     Array<T,Descriptor<T>::d> j;
00378     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00379     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00380     if (cell.takesStatistics()) {
00381         gatherStatistics(statistics, rhoBar, uSqr);
00382     }
00383     *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt)) = rhoBar;
00384     j.to_cArray(cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt));
00385 }
00386 
00387 template<typename T, template<typename U> class Descriptor>
00388 void StoreRhoBarJBGKdynamics<T,Descriptor>::collide (
00389         Cell<T,Descriptor>& cell, T rhoBar,
00390         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00391 {
00392     dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00393     *(cell.getExternal(Descriptor<T>::ExternalField::rhoBarBeginsAt)) = rhoBar;
00394     j.to_cArray(cell.getExternal(Descriptor<T>::ExternalField::jBeginsAt));
00395 }
00396 
00397 template<typename T, template<typename U> class Descriptor>
00398 T StoreRhoBarJBGKdynamics<T,Descriptor>::computeEquilibrium (
00399         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00400         T jSqr, T thetaBar) const
00401 {
00402     T invRho = Descriptor<T>::invRho(rhoBar);
00403     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00404 }
00405 
00406 
00407 /* *************** Class ExternalMomentBGKdynamics ********************************** */
00408 
00409 template<typename T, template<typename U> class Descriptor>
00410 int ExternalMomentBGKdynamics<T,Descriptor>::id =
00411     meta::registerOneParamDynamics<T,Descriptor,ExternalMomentBGKdynamics<T,Descriptor> >("BGK_ExternalMoment");
00412 
00415 template<typename T, template<typename U> class Descriptor>
00416 ExternalMomentBGKdynamics<T,Descriptor>::ExternalMomentBGKdynamics(T omega_ )
00417     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00418 { }
00419 
00420 template<typename T, template<typename U> class Descriptor>
00421 ExternalMomentBGKdynamics<T,Descriptor>* ExternalMomentBGKdynamics<T,Descriptor>::clone() const {
00422     return new ExternalMomentBGKdynamics<T,Descriptor>(*this);
00423 }
00424 
00425 template<typename T, template<typename U> class Descriptor>
00426 int ExternalMomentBGKdynamics<T,Descriptor>::getId() const {
00427     return id;
00428 }
00429 
00430 template<typename T, template<typename U> class Descriptor>
00431 void ExternalMomentBGKdynamics<T,Descriptor>::collide (
00432         Cell<T,Descriptor>& cell,
00433         BlockStatistics& statistics )
00434 {
00435     T& rho   = *cell.getExternal(Descriptor<T>::ExternalField::densityBeginsAt);
00436     T rhoBar = Descriptor<T>::rhoBar(rho);
00437     Array<T,Descriptor<T>::d> j;
00438     j.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::momentumBeginsAt) );
00439     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00440     if (cell.takesStatistics()) {
00441         gatherStatistics(statistics, rhoBar, uSqr);
00442     }
00443 } 
00444 
00445 template<typename T, template<typename U> class Descriptor>
00446 void ExternalMomentBGKdynamics<T,Descriptor>::collide (
00447         Cell<T,Descriptor>& cell, T rhoBar,
00448         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00449 {
00450     dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00451 }
00452 
00453 template<typename T, template<typename U> class Descriptor>
00454 T ExternalMomentBGKdynamics<T,Descriptor>::computeEquilibrium (
00455         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00456         T jSqr, T thetaBar) const
00457 {
00458     T invRho = Descriptor<T>::invRho(rhoBar);
00459     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00460 }
00461 
00462 template<typename T, template<typename U> class Descriptor>
00463 void ExternalMomentBGKdynamics<T,Descriptor>::computeVelocity (
00464              Cell<T,Descriptor> const& cell,
00465              Array<T,Descriptor<T>::d>& u ) const
00466 {
00467     T const& rho = *cell.getExternal(Descriptor<T>::ExternalField::densityBeginsAt);
00468     u.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::momentumBeginsAt) );
00469     u /= rho;
00470 }
00471 
00472 template<typename T, template<typename U> class Descriptor>
00473 T ExternalMomentBGKdynamics<T,Descriptor>::computeRhoBar(Cell<T,Descriptor> const& cell) const
00474 {
00475     return momentTemplates<T,Descriptor>::get_rhoBar(cell);
00476 }
00477 
00478 template<typename T, template<typename U> class Descriptor>
00479 void ExternalMomentBGKdynamics<T,Descriptor>::computeRhoBarJ (
00480                                 Cell<T,Descriptor> const& cell,
00481                                 T& rhoBar, Array<T,Descriptor<T>::d>& j ) const
00482 {
00483     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00484 }
00485 
00486 /* *************** Class ExternalVelocityBGKdynamics ********************************** */
00487 
00488 template<typename T, template<typename U> class Descriptor>
00489 int ExternalVelocityBGKdynamics<T,Descriptor>::id =
00490     meta::registerOneParamDynamics<T,Descriptor,ExternalVelocityBGKdynamics<T,Descriptor> >("BGK_ExternalVelocity");
00491 
00494 template<typename T, template<typename U> class Descriptor>
00495 ExternalVelocityBGKdynamics<T,Descriptor>::ExternalVelocityBGKdynamics(T omega_ )
00496     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00497 { }
00498 
00499 template<typename T, template<typename U> class Descriptor>
00500 ExternalVelocityBGKdynamics<T,Descriptor>* ExternalVelocityBGKdynamics<T,Descriptor>::clone() const {
00501     return new ExternalVelocityBGKdynamics<T,Descriptor>(*this);
00502 }
00503 
00504 template<typename T, template<typename U> class Descriptor>
00505 int ExternalVelocityBGKdynamics<T,Descriptor>::getId() const {
00506     return id;
00507 }
00508 
00509 template<typename T, template<typename U> class Descriptor>
00510 void ExternalVelocityBGKdynamics<T,Descriptor>::collide (
00511         Cell<T,Descriptor>& cell,
00512         BlockStatistics& statistics )
00513 {
00514     T rhoBar = momentTemplates<T,Descriptor>::get_rhoBar(cell);
00515     T rho = Descriptor<T>::fullRho(rhoBar);
00516     Array<T,Descriptor<T>::d> j;
00517     j.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::velocityBeginsAt) );
00518     j *= rho;
00519     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00520     if (cell.takesStatistics()) {
00521         gatherStatistics(statistics, rhoBar, uSqr);
00522     }
00523 } 
00524 
00525 template<typename T, template<typename U> class Descriptor>
00526 void ExternalVelocityBGKdynamics<T,Descriptor>::collide (
00527         Cell<T,Descriptor>& cell, T rhoBar,
00528         Array<T,Descriptor<T>::d> const& j, T thetaBar )
00529 {
00530     dynamicsTemplates<T,Descriptor>::bgk_ma2_collision(cell, rhoBar, j, this->getOmega());
00531 }
00532 
00533 template<typename T, template<typename U> class Descriptor>
00534 T ExternalVelocityBGKdynamics<T,Descriptor>::computeEquilibrium (
00535         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00536         T jSqr, T thetaBar) const
00537 {
00538     T invRho = Descriptor<T>::invRho(rhoBar);
00539     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00540 }
00541 
00542 template<typename T, template<typename U> class Descriptor>
00543 void ExternalVelocityBGKdynamics<T,Descriptor>::computeVelocity (
00544              Cell<T,Descriptor> const& cell,
00545              Array<T,Descriptor<T>::d>& u ) const 
00546 {
00547     u.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::velocityBeginsAt) );
00548 }
00549 
00550 template<typename T, template<typename U> class Descriptor>
00551 T ExternalVelocityBGKdynamics<T,Descriptor>::computeRhoBar(Cell<T,Descriptor> const& cell) const
00552 {
00553     return momentTemplates<T,Descriptor>::get_rhoBar(cell);
00554 }
00555 
00556 template<typename T, template<typename U> class Descriptor>
00557 void ExternalVelocityBGKdynamics<T,Descriptor>::computeRhoBarJ (
00558                                 Cell<T,Descriptor> const& cell,
00559                                 T& rhoBar, Array<T,Descriptor<T>::d>& j ) const
00560 {
00561     rhoBar = momentTemplates<T,Descriptor>::get_rhoBar(cell);
00562     j.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::velocityBeginsAt) );
00563     j *= Descriptor<T>::fullRho(rhoBar);
00564 }
00565 
00566 /* *************** Class QuasiIncBGKdynamics ************************************ */
00567 
00568 template<typename T, template<typename U> class Descriptor>
00569 int QuasiIncBGKdynamics<T,Descriptor>::id =
00570     meta::registerOneParamDynamics<T,Descriptor,QuasiIncBGKdynamics<T,Descriptor> >("QuasiInc_BGK");
00571 
00574 template<typename T, template<typename U> class Descriptor>
00575 QuasiIncBGKdynamics<T,Descriptor>::QuasiIncBGKdynamics(T omega_ )
00576     : BGKdynamics<T,Descriptor>(omega_)
00577 { }
00578 
00579 template<typename T, template<typename U> class Descriptor>
00580 QuasiIncBGKdynamics<T,Descriptor>* QuasiIncBGKdynamics<T,Descriptor>::clone() const {
00581     return new QuasiIncBGKdynamics<T,Descriptor>(*this);
00582 }
00583 
00584 template<typename T, template<typename U> class Descriptor>
00585 int QuasiIncBGKdynamics<T,Descriptor>::getId() const {
00586     return id;
00587 }
00588 
00589 template<typename T, template<typename U> class Descriptor>
00590 void QuasiIncBGKdynamics<T,Descriptor>::computeVelocity (
00591         Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& u ) const
00592 {
00593     T dummyRhoBar;
00594     this->computeRhoBarJ(cell, dummyRhoBar, u);
00595 }
00596 
00597 template<typename T, template<typename U> class Descriptor>
00598 void QuasiIncBGKdynamics<T,Descriptor>::computeRhoBarJPiNeq (
00599         Cell<T,Descriptor> const& cell, T& rhoBar,
00600         Array<T,Descriptor<T>::d>& j, Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00601 {
00602     bool incompressible = true;
00603     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq, incompressible);
00604 }
00605 
00606 
00607 template<typename T, template<typename U> class Descriptor>
00608 bool QuasiIncBGKdynamics<T,Descriptor>::velIsJ() const {
00609     return true;
00610 }
00611 
00612 
00613 /* *************** Class IncBGKdynamics ******************************************** */
00614 
00615 template<typename T, template<typename U> class Descriptor>
00616 int IncBGKdynamics<T,Descriptor>::id =
00617     meta::registerOneParamDynamics<T,Descriptor,IncBGKdynamics<T,Descriptor> >("BGK_Incompressible");
00618 
00621 template<typename T, template<typename U> class Descriptor>
00622 IncBGKdynamics<T,Descriptor>::IncBGKdynamics(T omega_)
00623     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00624 { }
00625 
00626 template<typename T, template<typename U> class Descriptor>
00627 IncBGKdynamics<T,Descriptor>* IncBGKdynamics<T,Descriptor>::clone() const {
00628     return new IncBGKdynamics<T,Descriptor>(*this);
00629 }
00630 
00631 template<typename T, template<typename U> class Descriptor>
00632 int IncBGKdynamics<T,Descriptor>::getId() const {
00633     return id;
00634 }
00635 
00636 template<typename T, template<typename U> class Descriptor>
00637 void IncBGKdynamics<T,Descriptor>::computeVelocity (
00638         Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& u ) const
00639 {
00640     T dummyRhoBar;
00641     this->computeRhoBarJ(cell, dummyRhoBar, u);
00642 }
00643 
00644 template<typename T, template<typename U> class Descriptor>
00645 void IncBGKdynamics<T,Descriptor>::computeRhoBarJPiNeq (
00646         Cell<T,Descriptor> const& cell, T& rhoBar,
00647         Array<T,Descriptor<T>::d>& j, Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00648 {
00649     bool incompressible = true;
00650     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq, incompressible);
00651 }
00652 
00653 template<typename T, template<typename U> class Descriptor>
00654 void IncBGKdynamics<T,Descriptor>::collide (
00655         Cell<T,Descriptor>& cell,
00656         BlockStatistics& statistics )
00657 {
00658     T rhoBar;
00659     Array<T,Descriptor<T>::d> j;
00660     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00661     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_inc_collision(cell, rhoBar, j, this->getOmega());
00662     if (cell.takesStatistics()) {
00663         gatherStatistics(statistics, rhoBar, uSqr);
00664     }
00665 }
00666 
00667 template<typename T, template<typename U> class Descriptor>
00668 void IncBGKdynamics<T,Descriptor>::collide (
00669         Cell<T,Descriptor>& cell, T rhoBar,
00670         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00671 {
00672     dynamicsTemplates<T,Descriptor>::bgk_inc_collision(cell, rhoBar, j, this->getOmega());
00673 }
00674 
00675 
00676 template<typename T, template<typename U> class Descriptor>
00677 T IncBGKdynamics<T,Descriptor>::computeEquilibrium(plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00678                                                    T jSqr, T thetaBar) const
00679 {
00680     // For the incompressible BGK dynamics, the "1/rho" pre-factor of
00681     // the O(Ma^2) term is unity.
00682     T invRho = (T)1;
00683     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00684 }
00685 
00686 template<typename T, template<typename U> class Descriptor>
00687 bool IncBGKdynamics<T,Descriptor>::velIsJ() const {
00688     return true;
00689 }
00690 
00691 
00692 /* *************** Class ConstRhoBGKdynamics *************************************** */
00693 
00694 template<typename T, template<typename U> class Descriptor>
00695 int ConstRhoBGKdynamics<T,Descriptor>::id =
00696     meta::registerOneParamDynamics<T,Descriptor,ConstRhoBGKdynamics<T,Descriptor> >("BGK_ConstRho");
00697 
00700 template<typename T, template<typename U> class Descriptor>
00701 ConstRhoBGKdynamics<T,Descriptor>::ConstRhoBGKdynamics(T omega_)
00702     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00703 { }
00704 
00705 template<typename T, template<typename U> class Descriptor>
00706 ConstRhoBGKdynamics<T,Descriptor>* ConstRhoBGKdynamics<T,Descriptor>::clone()
00707     const
00708 {
00709     return new ConstRhoBGKdynamics<T,Descriptor>(*this);
00710 }
00711 
00712 template<typename T, template<typename U> class Descriptor>
00713 int ConstRhoBGKdynamics<T,Descriptor>::getId() const {
00714     return id;
00715 }
00716 
00717 template<typename T, template<typename U> class Descriptor>
00718 void ConstRhoBGKdynamics<T,Descriptor>::collide (
00719         Cell<T,Descriptor>& cell,
00720         BlockStatistics& statistics )
00721 {
00722     T rhoBar;
00723     Array<T,Descriptor<T>::d> j;
00724     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
00725     T rho = Descriptor<T>::fullRho(rhoBar);
00726 
00727     T deltaRho = -statistics.getAverage(LatticeStatistics::avRhoBar)
00728                    + (1-Descriptor<T>::SkordosFactor());
00729     T ratioRho = (T)1 + deltaRho/rho;
00730 
00731     T uSqr = dynamicsTemplates<T,Descriptor>::bgk_ma2_constRho_collision (
00732                 cell, rhoBar, j, ratioRho, this->getOmega() );
00733     if (cell.takesStatistics()) {
00734         gatherStatistics(statistics, rhoBar+deltaRho, uSqr);
00735     }
00736 }
00737 
00738 
00739 template<typename T, template<typename U> class Descriptor>
00740 T ConstRhoBGKdynamics<T,Descriptor>::computeEquilibrium (
00741         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00742         T jSqr, T thetaBar) const
00743 {
00744     T invRho = Descriptor<T>::invRho(rhoBar);
00745     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00746 }
00747 
00748 
00749 /* *************** Class RLBdynamics *********************************************** */
00750 
00751 template<typename T, template<typename U> class Descriptor>
00752 int RLBdynamics<T,Descriptor>::id =
00753     meta::registerCompositeDynamics<T,Descriptor, RLBdynamics<T,Descriptor> >("Regularized_generic");
00754 
00757 template<typename T, template<typename U> class Descriptor>
00758 RLBdynamics<T,Descriptor>::RLBdynamics(Dynamics<T,Descriptor>* baseDynamics, bool automaticPrepareCollision)
00759     : BulkCompositeDynamics<T,Descriptor>(baseDynamics, automaticPrepareCollision)
00760 { }
00761 
00762 template<typename T, template<typename U> class Descriptor>
00763 RLBdynamics<T,Descriptor>* RLBdynamics<T,Descriptor>::clone() const
00764 {
00765     return new RLBdynamics<T,Descriptor>(*this);
00766 }
00767 
00768 template<typename T, template<typename U> class Descriptor>
00769 int RLBdynamics<T,Descriptor>::getId() const {
00770     return id;
00771 }
00772 
00773 template<typename T, template<typename U> class Descriptor>
00774 void RLBdynamics<T,Descriptor>::completePopulations(Cell<T,Descriptor>& cell) const
00775 {
00776     T rhoBar;
00777     Array<T,Descriptor<T>::d> j;
00778     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00779     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq);
00780     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00781     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00782         cell[iPop] = this -> computeEquilibrium(iPop, rhoBar, j, jSqr)
00783                    + offEquilibriumTemplates<T,Descriptor>::fromPiToFneq(iPop, PiNeq);
00784     }
00785 }
00786 
00787 
00788 /* *************** Class RegularizedBGKdynamics ************************************ */
00789 
00790 template<typename T, template<typename U> class Descriptor>
00791 int RegularizedBGKdynamics<T,Descriptor>::id =
00792     meta::registerOneParamDynamics<T,Descriptor,RegularizedBGKdynamics<T,Descriptor> >("Regularized_BGK");
00793 
00796 template<typename T, template<typename U> class Descriptor>
00797 RegularizedBGKdynamics<T,Descriptor>::RegularizedBGKdynamics(T omega_)
00798     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00799 { }
00800 
00801 template<typename T, template<typename U> class Descriptor>
00802 RegularizedBGKdynamics<T,Descriptor>* RegularizedBGKdynamics<T,Descriptor>::clone() const
00803 {
00804     return new RegularizedBGKdynamics<T,Descriptor>(*this);
00805 }
00806 
00807 template<typename T, template<typename U> class Descriptor>
00808 int RegularizedBGKdynamics<T,Descriptor>::getId() const {
00809     return id;
00810 }
00811 
00812 template<typename T, template<typename U> class Descriptor>
00813 void RegularizedBGKdynamics<T,Descriptor>::collide (
00814         Cell<T,Descriptor>& cell,
00815         BlockStatistics& statistics )
00816 {
00817     T rhoBar;
00818     Array<T,Descriptor<T>::d> j;
00819     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00820     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq);
00821     T invRho = Descriptor<T>::invRho(rhoBar);
00822     T uSqr = dynamicsTemplates<T,Descriptor>::rlb_collision (
00823                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00824     if (cell.takesStatistics()) {
00825         gatherStatistics(statistics, rhoBar, uSqr);
00826     }
00827 }
00828 
00829 template<typename T, template<typename U> class Descriptor>
00830 void RegularizedBGKdynamics<T,Descriptor>::collide (
00831         Cell<T,Descriptor>& cell, T rhoBar,
00832         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00833 {
00834     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00835     momentTemplates<T,Descriptor>::compute_PiNeq(cell, rhoBar, j, PiNeq);
00836     T invRho = Descriptor<T>::invRho(rhoBar);
00837     dynamicsTemplates<T,Descriptor>::rlb_collision (
00838                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00839 }
00840 
00841 template<typename T, template<typename U> class Descriptor>
00842 T RegularizedBGKdynamics<T,Descriptor>::computeEquilibrium (
00843         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j, T jSqr, T thetaBar ) const
00844 {
00845     T invRho = Descriptor<T>::invRho(rhoBar);
00846     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00847 }
00848 
00849 
00850 /* *************** Class IncRegularizedBGKdynamics ************************************ */
00851 
00852 template<typename T, template<typename U> class Descriptor>
00853 int IncRegularizedBGKdynamics<T,Descriptor>::id =
00854     meta::registerOneParamDynamics<T,Descriptor,IncRegularizedBGKdynamics<T,Descriptor> >("IncRegularized_BGK");
00855 
00858 template<typename T, template<typename U> class Descriptor>
00859 IncRegularizedBGKdynamics<T,Descriptor>::IncRegularizedBGKdynamics(T omega_)
00860     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00861 { }
00862 
00863 template<typename T, template<typename U> class Descriptor>
00864 IncRegularizedBGKdynamics<T,Descriptor>* IncRegularizedBGKdynamics<T,Descriptor>::clone() const
00865 {
00866     return new IncRegularizedBGKdynamics<T,Descriptor>(*this);
00867 }
00868 
00869 template<typename T, template<typename U> class Descriptor>
00870 int IncRegularizedBGKdynamics<T,Descriptor>::getId() const {
00871     return id;
00872 }
00873 
00874 template<typename T, template<typename U> class Descriptor>
00875 void IncRegularizedBGKdynamics<T,Descriptor>::computeVelocity (
00876         Cell<T,Descriptor> const& cell, Array<T,Descriptor<T>::d>& u ) const
00877 {
00878     T dummyRhoBar;
00879     this->computeRhoBarJ(cell, dummyRhoBar, u);
00880 }
00881 
00882 template<typename T, template<typename U> class Descriptor>
00883 void IncRegularizedBGKdynamics<T,Descriptor>::computeRhoBarJPiNeq (
00884         Cell<T,Descriptor> const& cell, T& rhoBar,
00885         Array<T,Descriptor<T>::d>& j, Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00886 {
00887     bool incompressible = true;
00888     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq, incompressible);
00889 }
00890 
00891 template<typename T, template<typename U> class Descriptor>
00892 void IncRegularizedBGKdynamics<T,Descriptor>::collide (
00893         Cell<T,Descriptor>& cell,
00894         BlockStatistics& statistics )
00895 {
00896     T rhoBar;
00897     Array<T,Descriptor<T>::d> j;
00898     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00899     momentTemplates<T,Descriptor>::compute_rhoBar_j_PiNeq(cell, rhoBar, j, PiNeq);
00900     T invRho = (T)1.;
00901     T uSqr = dynamicsTemplates<T,Descriptor>::rlb_collision (
00902                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00903     if (cell.takesStatistics()) {
00904         gatherStatistics(statistics, rhoBar, uSqr);
00905     }
00906 }
00907 
00908 template<typename T, template<typename U> class Descriptor>
00909 void IncRegularizedBGKdynamics<T,Descriptor>::collide (
00910         Cell<T,Descriptor>& cell, T rhoBar,
00911         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00912 {
00913     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00914     momentTemplates<T,Descriptor>::compute_PiNeq(cell, rhoBar, j, PiNeq);
00915     T invRho=(T)1.;
00916     dynamicsTemplates<T,Descriptor>::rlb_collision (
00917                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00918 }
00919 
00920 template<typename T, template<typename U> class Descriptor>
00921 T IncRegularizedBGKdynamics<T,Descriptor>::computeEquilibrium (
00922         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j, T jSqr, T thetaBar ) const
00923 {
00924     T invRho = (T)1.;
00925     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00926 }
00927 
00928 template<typename T, template<typename U> class Descriptor>
00929 bool IncRegularizedBGKdynamics<T,Descriptor>::velIsJ() const {
00930     return true;
00931 }
00932 
00933 
00934 /* *************** Class ExternalMomentRegularizedBGKdynamics *********************** */
00935 
00936 template<typename T, template<typename U> class Descriptor>
00937 int ExternalMomentRegularizedBGKdynamics<T,Descriptor>::id =
00938     meta::registerOneParamDynamics<T,Descriptor,ExternalMomentRegularizedBGKdynamics<T,Descriptor> >
00939                                       ("Regularized_BGK_ExternalMoment");
00940 
00943 template<typename T, template<typename U> class Descriptor>
00944 ExternalMomentRegularizedBGKdynamics<T,Descriptor>::ExternalMomentRegularizedBGKdynamics(T omega_ )
00945     : IsoThermalBulkDynamics<T,Descriptor>(omega_)
00946 { }
00947 
00948 template<typename T, template<typename U> class Descriptor>
00949 ExternalMomentRegularizedBGKdynamics<T,Descriptor>* ExternalMomentRegularizedBGKdynamics<T,Descriptor>::clone() const {
00950     return new ExternalMomentRegularizedBGKdynamics<T,Descriptor>(*this);
00951 }
00952 
00953 template<typename T, template<typename U> class Descriptor>
00954 int ExternalMomentRegularizedBGKdynamics<T,Descriptor>::getId() const {
00955     return id;
00956 }
00957 
00958 template<typename T, template<typename U> class Descriptor>
00959 void ExternalMomentRegularizedBGKdynamics<T,Descriptor>::collide (
00960         Cell<T,Descriptor>& cell,
00961         BlockStatistics& statistics )
00962 {
00963     T& rho   = *cell.getExternal(Descriptor<T>::ExternalField::densityBeginsAt);
00964     T rhoBar = Descriptor<T>::rhoBar(rho);
00965     Array<T,Descriptor<T>::d> j;
00966     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00967     j.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::momentumBeginsAt) );
00968     momentTemplates<T,Descriptor>::compute_PiNeq(cell, rhoBar, j, PiNeq);
00969     T invRho = Descriptor<T>::invRho(rhoBar);
00970     T uSqr = dynamicsTemplates<T,Descriptor>::rlb_collision (
00971                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00972     if (cell.takesStatistics()) {
00973         gatherStatistics(statistics, rhoBar, uSqr);
00974     }
00975 }
00976 
00977 template<typename T, template<typename U> class Descriptor>
00978 void ExternalMomentRegularizedBGKdynamics<T,Descriptor>::collide (
00979         Cell<T,Descriptor>& cell, T rhoBar,
00980         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
00981 {
00982     Array<T,SymmetricTensor<T,Descriptor>::n> PiNeq;
00983     momentTemplates<T,Descriptor>::compute_PiNeq(cell, rhoBar, j, PiNeq);
00984     T invRho = Descriptor<T>::invRho(rhoBar);
00985     dynamicsTemplates<T,Descriptor>::rlb_collision (
00986                  cell, rhoBar, invRho, j, PiNeq, this->getOmega() );
00987 }
00988 
00989 template<typename T, template<typename U> class Descriptor>
00990 T ExternalMomentRegularizedBGKdynamics<T,Descriptor>::computeEquilibrium (
00991         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00992         T jSqr, T thetaBar) const
00993 {
00994     T invRho = Descriptor<T>::invRho(rhoBar);
00995     return dynamicsTemplates<T,Descriptor>::bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr);
00996 }
00997 
00998 template<typename T, template<typename U> class Descriptor>
00999 void ExternalMomentRegularizedBGKdynamics<T,Descriptor>::computeVelocity (
01000              Cell<T,Descriptor> const& cell,
01001              Array<T,Descriptor<T>::d>& u ) const
01002 {
01003     T const& rho = *cell.getExternal(Descriptor<T>::ExternalField::densityBeginsAt);
01004     u.from_cArray( cell.getExternal(Descriptor<T>::ExternalField::momentumBeginsAt) );
01005     u /= rho;
01006 }
01007 
01008 template<typename T, template<typename U> class Descriptor>
01009 T ExternalMomentRegularizedBGKdynamics<T,Descriptor>::computeRhoBar(Cell<T,Descriptor> const& cell) const
01010 {
01011     return momentTemplates<T,Descriptor>::get_rhoBar(cell);
01012 }
01013 
01014 template<typename T, template<typename U> class Descriptor>
01015 void ExternalMomentRegularizedBGKdynamics<T,Descriptor>::computeRhoBarJ (
01016                                 Cell<T,Descriptor> const& cell,
01017                                 T& rhoBar, Array<T,Descriptor<T>::d>& j ) const
01018 {
01019     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
01020 }
01021 
01022 
01023 /* *************** Class ChopardDynamics ************************************ */
01024 
01025 template<typename T, template<typename U> class Descriptor>
01026 int ChopardDynamics<T,Descriptor>::id =
01027     meta::registerTwoParamDynamics<T,Descriptor,ChopardDynamics<T,Descriptor> >("Chopard_VariableCs2");
01028 
01032 template<typename T, template<typename U> class Descriptor>
01033 ChopardDynamics<T,Descriptor>::ChopardDynamics(T vs2_, T omega_)
01034     : IsoThermalBulkDynamics<T,Descriptor>(omega_),
01035       vs2(vs2_)
01036 { }
01037 
01038 template<typename T, template<typename U> class Descriptor>
01039 void ChopardDynamics<T,Descriptor>::serialize(HierarchicSerializer& serializer) const
01040 {
01041     serializer.addValue(vs2);
01042     serializer.addValue(this->getOmega());
01043 }
01044 
01045 template<typename T, template<typename U> class Descriptor>
01046 void ChopardDynamics<T,Descriptor>::unserialize(HierarchicUnserializer& unserializer)
01047 {
01048     vs2 = unserializer.readValue<T>();
01049     this->setOmega(unserializer.readValue<T>());
01050 }
01051 
01052 template<typename T, template<typename U> class Descriptor>
01053 ChopardDynamics<T,Descriptor>* ChopardDynamics<T,Descriptor>::clone() const
01054 {
01055     return new ChopardDynamics<T,Descriptor>(*this);
01056 }
01057 
01058 template<typename T, template<typename U> class Descriptor>
01059 int ChopardDynamics<T,Descriptor>::getId() const {
01060     return id;
01061 }
01062 
01063 template<typename T, template<typename U> class Descriptor>
01064 void ChopardDynamics<T,Descriptor>::collide (
01065         Cell<T,Descriptor>& cell,
01066         BlockStatistics& statistics )
01067 {
01068     T rhoBar;
01069     Array<T,Descriptor<T>::d> j;
01070     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
01071     T uSqr = chopardBgkCollision(cell, rhoBar, j, vs2, this->getOmega());
01072     if (cell.takesStatistics()) {
01073         gatherStatistics(statistics, rhoBar, uSqr);
01074     }
01075 }
01076 
01077 template<typename T, template<typename U> class Descriptor>
01078 void ChopardDynamics<T,Descriptor>::collide (
01079         Cell<T,Descriptor>& cell, T rhoBar,
01080         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
01081 {
01082     chopardBgkCollision(cell, rhoBar, j, vs2, this->getOmega());
01083 }
01084 
01085 template<typename T, template<typename U> class Descriptor>
01086 T ChopardDynamics<T,Descriptor>::computeEquilibrium (
01087         plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j, T jSqr, T thetaBar) const
01088 {
01089     T invRho = Descriptor<T>::invRho(rhoBar);
01090     return chopardEquilibrium(iPop, rhoBar, invRho, j, jSqr, vs2);
01091 }
01092 
01093 template<typename T, template<typename U> class Descriptor>
01094 T ChopardDynamics<T,Descriptor>::getParameter(plint whichParameter) const {
01095     switch (whichParameter) {
01096         case dynamicParams::omega_shear     : return this->getOmega();
01097         case dynamicParams::sqrSpeedOfSound : return this->getVs2();
01098     };
01099     return 0.;
01100 }
01101 
01102 template<typename T, template<typename U> class Descriptor>
01103 void ChopardDynamics<T,Descriptor>::setParameter(plint whichParameter, T value) {
01104     switch (whichParameter) {
01105         case dynamicParams::omega_shear     : setOmega(value);
01106         case dynamicParams::sqrSpeedOfSound : setVs2(value);
01107     };
01108 }
01109 
01110 template<typename T, template<typename U> class Descriptor>
01111 T ChopardDynamics<T,Descriptor>::getVs2() const {
01112     return vs2;
01113 }
01114 
01115 template<typename T, template<typename U> class Descriptor>
01116 void ChopardDynamics<T,Descriptor>::setVs2(T vs2_) {
01117     vs2 = vs2_;
01118 }
01119 
01120 template<typename T, template<typename U> class Descriptor>
01121 T ChopardDynamics<T,Descriptor>::chopardBgkCollision (
01122         Cell<T,Descriptor>& cell, T rhoBar, Array<T,Descriptor<T>::d> const& j, T vs2, T omega)
01123 {
01124     const T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
01125     T invRho = Descriptor<T>::invRho(rhoBar);
01126     for (plint iPop=0; iPop < Descriptor<T>::q; ++iPop) {
01127         cell[iPop] *= (T)1-omega;
01128         cell[iPop] += omega * chopardEquilibrium(iPop, rhoBar, invRho, j, jSqr, vs2);
01129     }
01130     return invRho*invRho*jSqr;
01131 }
01132 
01133 template<typename T, template<typename U> class Descriptor>
01134 T ChopardDynamics<T,Descriptor>::chopardEquilibrium (
01135         plint iPop, T rhoBar, T invRho, Array<T,Descriptor<T>::d> const& j, T jSqr, T vs2)
01136 {
01137     T kappa = vs2 - Descriptor<T>::cs2;
01138     if (iPop==0) {
01139         return Descriptor<T>::invCs2 * (
01140                      kappa * (Descriptor<T>::t[0]-(T)1)
01141                    + rhoBar * (Descriptor<T>::t[0]*vs2-kappa)
01142                    - invRho * jSqr * Descriptor<T>::t[0]/(T)2*Descriptor<T>::invCs2 );
01143     }
01144     else {
01145         T c_j = T();
01146         for (int iD=0; iD < Descriptor<T>::d; ++iD) {
01147            c_j += Descriptor<T>::c[iPop][iD]*j[iD];
01148         }
01149         return Descriptor<T>::invCs2 * Descriptor<T>::t[iPop] * (
01150                      kappa
01151                    + rhoBar * vs2
01152                    + c_j
01153                    + invRho/(T)2 * (Descriptor<T>::invCs2*c_j - jSqr) );
01154     }
01155 }
01156 
01157 
01158 /* *************** Class PrecondBGKdynamics *********************************************** */
01159 
01160 template<typename T, template<typename U> class Descriptor>
01161 int PrecondBGKdynamics<T,Descriptor>::id =
01162     meta::registerTwoParamDynamics<T,Descriptor,PrecondBGKdynamics<T,Descriptor> >("PrecondBGK");
01163 
01166 template<typename T, template<typename U> class Descriptor>
01167 PrecondBGKdynamics<T,Descriptor>::PrecondBGKdynamics(T omega_, T invGamma_ )
01168     : IsoThermalBulkDynamics<T,Descriptor>(omega_),
01169       invGamma(invGamma_)
01170 { }
01171 
01172 template<typename T, template<typename U> class Descriptor>
01173 PrecondBGKdynamics<T,Descriptor>* PrecondBGKdynamics<T,Descriptor>::clone() const {
01174     return new PrecondBGKdynamics<T,Descriptor>(*this);
01175 }
01176 
01177 template<typename T, template<typename U> class Descriptor>
01178 int PrecondBGKdynamics<T,Descriptor>::getId() const {
01179     return id;
01180 }
01181 
01182 template<typename T, template<typename U> class Descriptor>
01183 void PrecondBGKdynamics<T,Descriptor>::collide (
01184         Cell<T,Descriptor>& cell,
01185         BlockStatistics& statistics )
01186 {
01187     T rhoBar;
01188     Array<T,Descriptor<T>::d> j;
01189     momentTemplates<T,Descriptor>::get_rhoBar_j(cell, rhoBar, j);
01190     T uSqr = dynamicsTemplates<T,Descriptor>::precond_bgk_ma2_collision(cell, rhoBar, j, this->getOmega(), invGamma);
01191     if (cell.takesStatistics()) {
01192         gatherStatistics(statistics, rhoBar, uSqr);
01193     }
01194 }
01195 
01196 template<typename T, template<typename U> class Descriptor>
01197 void PrecondBGKdynamics<T,Descriptor>::collide (
01198         Cell<T,Descriptor>& cell, T rhoBar,
01199         Array<T,Descriptor<T>::d> const& j, T thetaBar, BlockStatistics& stat )
01200 {
01201     dynamicsTemplates<T,Descriptor>::precond_bgk_ma2_collision(cell, rhoBar, j, this->getOmega(), invGamma);
01202 }
01203 
01204 template<typename T, template<typename U> class Descriptor>
01205 T PrecondBGKdynamics<T,Descriptor>::computeEquilibrium(plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
01206                                                 T jSqr, T thetaBar) const
01207 {
01208     T invRho = Descriptor<T>::invRho(rhoBar);
01209     return dynamicsTemplates<T,Descriptor>::precond_bgk_ma2_equilibrium(iPop, rhoBar, invRho, j, jSqr, invGamma);
01210 }
01211 
01212 template<typename T, template<typename U> class Descriptor>
01213 void PrecondBGKdynamics<T,Descriptor>::serialize(HierarchicSerializer& serializer) const
01214 {
01215     serializer.addValue(invGamma);
01216     serializer.addValue(this->getOmega());
01217 }
01218 
01219 template<typename T, template<typename U> class Descriptor>
01220 void PrecondBGKdynamics<T,Descriptor>::unserialize(HierarchicUnserializer& unserializer)
01221 {
01222     invGamma = unserializer.readValue<T>();
01223     this->setOmega(unserializer.readValue<T>());
01224 }
01225 
01226 }  // namespace plb
01227 
01228 #endif  // ISO_THERMAL_DYNAMICS_HH