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

cell.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 
00028 #ifndef CELL_H
00029 #define CELL_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "core/plbDebug.h"
00033 #include "latticeBoltzmann/externalFields.h"
00034 #include "core/dynamics.h"
00035 #include "core/array.h"
00036 #include "core/hierarchicSerializer.h"
00037 
00038 namespace plb {
00039 
00041 template<typename T, typename ExternalField>
00042 class ExternalFieldArray {
00043 public:
00044     T* get(plint index) {
00045         PLB_PRECONDITION( index < ExternalField::numScalars );
00046         return data+index;
00047     }
00048     T const* get(plint index) const {
00049         PLB_PRECONDITION( index < ExternalField::numScalars );
00050         return data+index;
00051     }
00052 private:
00053     T data[ExternalField::numScalars];
00054 };
00055 
00057 template<typename T>
00058 class ExternalFieldArray<T,descriptors::NoExternalField> {
00059 public:
00060     T* get(pluint index) {
00061         PLB_PRECONDITION( false );
00062         static T data = T();
00063         return &data;
00064     }
00065     T const* get(pluint index) const {
00066         PLB_PRECONDITION( false );
00067         static T data = T();
00068         return &data;
00069     }
00070 };
00071 
00073 template<typename T, template<typename U> class Descriptor>
00074 struct CellInfo {
00075     static const int n = Descriptor<T>::numPop + Descriptor<T>::ExternalField::numScalars;
00076 };
00077 
00079 
00091 template<typename T, template<typename U> class Descriptor>
00092 class Cell {
00093 public:
00095     typedef ExternalFieldArray<T, typename Descriptor<T>::ExternalField> External;
00096 public:
00098     Cell();
00100     Cell(Dynamics<T,Descriptor>* dynamics_);
00101 public:
00103 
00104     T& operator[](plint iPop) {
00105         PLB_PRECONDITION( iPop < Descriptor<T>::numPop );
00106         return f[iPop];
00107     }
00109 
00110     T const& operator[](plint iPop) const {
00111         PLB_PRECONDITION( iPop < Descriptor<T>::numPop );
00112         return f[iPop];
00113     }
00115     Array<T,Descriptor<T>::numPop>& getRawPopulations() {
00116         return f;
00117     }
00119     Array<T,Descriptor<T>::numPop> const& getRawPopulations() const {
00120         return f;
00121     }
00123 
00125     Cell<T,Descriptor>& attributeF(Cell<T,Descriptor> const& rhs) {
00126         f = rhs.getRawPopulations();
00127         return *this;
00128     };
00130 
00135     Cell<T,Descriptor>& attributeValues(Cell<T,Descriptor> const& rhs) {
00136         attributeF(rhs);
00137         for (plint iExt=0; iExt < Descriptor<T>::ExternalField::numScalars; ++iExt) {
00138             *external.get(iExt) = *rhs.external.get(iExt);
00139         }
00140         return *this;
00141     };
00143     T* getExternal(plint offset) {
00144         PLB_PRECONDITION( offset < Descriptor<T>::ExternalField::numScalars );
00145         return external.get(offset);
00146     }
00148     T const* getExternal(plint offset) const {
00149         PLB_PRECONDITION( offset < Descriptor<T>::ExternalField::numScalars );
00150         return external.get(offset);
00151     }
00153     Dynamics<T,Descriptor> const& getDynamics() const;
00155     Dynamics<T,Descriptor>& getDynamics();
00157     bool takesStatistics() const {
00158         return takesStat;
00159     }
00161     void specifyStatisticsStatus(bool status) {
00162         takesStat = status;
00163     }
00164 private:
00166 
00170     void attributeDynamics(Dynamics<T,Descriptor>* dynamics_);
00171     // Declare the BlockLatticeXD as a friend, to enable access to attributeDynamics.
00172     template<typename T_, template<typename U_> class Descriptor_> friend class BlockLattice2D;
00173     template<typename T_, template<typename U_> class Descriptor_> friend class BlockLattice3D;
00174 #ifdef PLB_MPI_PARALLEL
00175     template<typename T_, template<typename U_> class Descriptor_> friend class ParallelCellAccess2D;
00176     template<typename T_, template<typename U_> class Descriptor_> friend class ParallelCellAccess3D;
00177 #endif
00178 
00179 // The following helper functions forward the function call
00180 // to the Dynamics object
00181 public:
00183     void collide(BlockStatistics& statistics) {
00184         PLB_PRECONDITION( dynamics );
00185         dynamics->collide(*this, statistics);
00186     }
00187 
00189     T computeEquilibrium(plint iPop, T rhoBar, Array<T,Descriptor<T>::d> const& j,
00190                          T jSqr, T thetaBar=T()) const
00191     {
00192         PLB_PRECONDITION( dynamics );
00193         return dynamics->computeEquilibrium(iPop, rhoBar, j, jSqr, thetaBar);
00194     }
00195 
00197     void regularize(T rhoBar, Array<T,Descriptor<T>::d> const& j, T jSqr,
00198                     Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq, T thetaBar=T() )
00199     {
00200         PLB_PRECONDITION( dynamics );
00201         dynamics->regularize(*this, rhoBar, j, jSqr, PiNeq, thetaBar);
00202     }
00203 
00205 
00207     T computeDensity() const {
00208         PLB_PRECONDITION( dynamics );
00209         return dynamics->computeDensity(*this);
00210     }
00211 
00213 
00215     T computePressure() const {
00216         PLB_PRECONDITION( dynamics );
00217         return dynamics->computePressure(*this);
00218     }
00219 
00221 
00223     void computeVelocity(Array<T,Descriptor<T>::d>& u) const {
00224         PLB_PRECONDITION( dynamics );
00225         dynamics->computeVelocity(*this, u);
00226     }
00227 
00229 
00231     T computeTemperature() const {
00232         PLB_PRECONDITION( dynamics );
00233         return dynamics->computeTemperature(*this);
00234     }
00235 
00237 
00238     void computeDeviatoricStress (
00239             Array<T,SymmetricTensor<T,Descriptor>::n>& PiNeq ) const
00240     {
00241         PLB_PRECONDITION( dynamics );
00242         dynamics->computeDeviatoricStress(*this, PiNeq);
00243     }
00244 
00246 
00248     void computeHeatFlux(Array<T,Descriptor<T>::d>& q) const {
00249         PLB_PRECONDITION( dynamics );
00250         dynamics->computeHeatFlux(*this, q);
00251     }
00252 
00254 
00257     void computeMoment(plint momentId, T* moment) {
00258         PLB_PRECONDITION( dynamics );
00259         dynamics->computeMoment(*this, momentId, moment);
00260     }
00261 
00263 
00268     void getPopulations(Array<T,Descriptor<T>::numPop>& f) const {
00269         PLB_PRECONDITION( dynamics );
00270         dynamics->getPopulations(*this, f);
00271     }
00272 
00274 
00279     void getExternalField(plint pos, plint size, T* ext) const {
00280         PLB_PRECONDITION( dynamics );
00281         dynamics->getExternalField(*this, pos, size, ext);
00282     }   
00283 
00285 
00287     void defineDensity(T rho) {
00288         PLB_PRECONDITION( dynamics );
00289         dynamics->defineDensity(*this, rho);
00290     }
00291 
00293 
00295     void defineVelocity(Array<T,Descriptor<T>::d> const& u) {
00296         PLB_PRECONDITION( dynamics );
00297         dynamics->defineVelocity(*this, u);
00298     }
00299 
00301 
00303     void defineTemperature(T temperature) {
00304         PLB_PRECONDITION( dynamics );
00305         dynamics->defineTemperature(*this, temperature);
00306     }
00307 
00309 
00311     void defineHeatFlux(Array<T,Descriptor<T>::d> const& q) {
00312         PLB_PRECONDITION( dynamics );
00313         dynamics->defineHeatFlux(*this, q);
00314     }
00315 
00317 
00319     void defineDeviatoricStress (
00320             Array<T,SymmetricTensor<T,Descriptor>::n> const& PiNeq )
00321     {
00322         PLB_PRECONDITION( dynamics );
00323         dynamics->defineDeviatoricStress(*this, PiNeq);
00324     }
00325 
00327 
00330     void defineMoment(plint momentId, T const* value)
00331     {
00332         PLB_PRECONDITION( dynamics );
00333         dynamics->defineMoment(*this, momentId, value);
00334     }
00335 
00337 
00342     void setPopulations(Array<T,Descriptor<T>::numPop> const& f) {
00343         PLB_PRECONDITION( dynamics );
00344         dynamics->setPopulations(*this, f);
00345     }
00347 
00352     void setExternalField(plint pos, plint size, const T* ext) {
00353         PLB_PRECONDITION( dynamics );
00354         dynamics->setExternalField(*this, pos, size, ext);
00355     }
00357     void revert();
00358     void serialize(char* data) const;
00359     void unSerialize(char const* data);
00360 private:
00361     void iniPop();
00362     void iniExternal();
00363 private:
00364     Array<T,Descriptor<T>::numPop> f;         
00365     External                       external;  
00366     bool                           takesStat; 
00367     Dynamics<T,Descriptor>*        dynamics;  
00368 };
00369 
00370 template<typename T, template<typename U> class Descriptor>
00371 void iniCellAtEquilibrium(Cell<T,Descriptor>& cell, T density, Array<T,Descriptor<T>::d> const& velocity);
00372 
00373 template<typename T, template<typename U> class Descriptor>
00374 void iniCellAtEquilibrium(Cell<T,Descriptor>& cell, T density, Array<T,Descriptor<T>::d> const& velocity, T temperature);
00375 
00376 }  // namespace plb
00377 
00378 #endif  // CELL_H