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

cell.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 
00028 #ifndef CELL_HH
00029 #define CELL_HH
00030 
00031 #include <algorithm>
00032 #include "core/cell.h"
00033 #include "core/util.h"
00034 #include <cstring>
00035 
00036 namespace plb {
00037 
00039 
00045 template<typename T, template<typename U> class Descriptor>
00046 Cell<T,Descriptor>::Cell()
00047     : takesStat(true), dynamics(0)
00048 {
00049     iniPop();
00050     iniExternal();
00051 }
00052 
00058 template<typename T, template<typename U> class Descriptor>
00059 Cell<T,Descriptor>::Cell(Dynamics<T,Descriptor>* dynamics_)
00060     : takesStat(true), dynamics(dynamics_)
00061 {
00062     iniPop();
00063     iniExternal();
00064 }
00065 
00066 template<typename T, template<typename U> class Descriptor>
00067 void Cell<T,Descriptor>::attributeDynamics(Dynamics<T,Descriptor>* dynamics_) {
00068     dynamics = dynamics_;
00069 }
00070 
00071 template<typename T, template<typename U> class Descriptor>
00072 Dynamics<T,Descriptor> const& Cell<T,Descriptor>::getDynamics() const {
00073     PLB_PRECONDITION(dynamics);
00074     return *dynamics;
00075 }
00076 
00077 template<typename T, template<typename U> class Descriptor>
00078 Dynamics<T,Descriptor>& Cell<T,Descriptor>::getDynamics() {
00079     PLB_PRECONDITION(dynamics);
00080     return *dynamics;
00081 }
00082 
00083 template<typename T, template<typename U> class Descriptor>
00084 void Cell<T,Descriptor>::revert() {
00085     for (plint iPop=1; iPop<=Descriptor<T>::numPop/2; ++iPop) {
00086         std::swap(f[iPop],f[iPop+Descriptor<T>::numPop/2]);
00087     }
00088 }
00089 
00090 template<typename T, template<typename U> class Descriptor>
00091 void Cell<T,Descriptor>::iniPop() {
00092     f.resetToZero();
00093 }
00094 
00095 template<typename T, template<typename U> class Descriptor>
00096 void Cell<T,Descriptor>::iniExternal() {
00097     for (plint iData=0; iData<Descriptor<T>::ExternalField::numScalars; ++iData) {
00098         *external.get(iData) = T();
00099     }
00100 }
00101 
00102 template<typename T, template<typename U> class Descriptor>
00103 void Cell<T,Descriptor>::serialize(char* data) const {
00104     const plint numPop = Descriptor<T>::numPop;
00105     const plint numExt = Descriptor<T>::ExternalField::numScalars;
00106     memcpy((void*)data, (const void*)(&f[0]), numPop*sizeof(T));
00107     if (numExt>0) {
00108         memcpy((void*)(data+numPop*sizeof(T)), (const void*)(external.get(0)), numExt*sizeof(T));
00109     }
00110 }
00111 
00112 template<typename T, template<typename U> class Descriptor>
00113 void Cell<T,Descriptor>::unSerialize(char const* data) {
00114     const plint numPop = Descriptor<T>::numPop;
00115     const plint numExt = Descriptor<T>::ExternalField::numScalars;
00116 
00117     memcpy((void*)(&f[0]), (const void*)data, numPop*sizeof(T));
00118     if (numExt>0) {
00119         memcpy((void*)(external.get(0)), (const void*)(data+numPop*sizeof(T)), numExt*sizeof(T));
00120     }
00121 }
00122 
00123 template<typename T, template<typename U> class Descriptor>
00124 void iniCellAtEquilibrium(Cell<T,Descriptor>& cell, T density, Array<T,Descriptor<T>::d> const& velocity) {
00125     Array<T,Descriptor<T>::d> j;
00126     VectorTemplate<T,Descriptor>::multiplyByScalar(velocity, density, j);
00127     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00128     T rhoBar = Descriptor<T>::rhoBar(density);
00129     for (plint iPop=0; iPop<Descriptor<T>::numPop; ++iPop) {
00130         cell[iPop] = cell.computeEquilibrium(iPop, rhoBar, j, jSqr);
00131     }
00132 }
00133 
00134 template<typename T, template<typename U> class Descriptor>
00135 void iniCellAtEquilibrium(Cell<T,Descriptor>& cell, T density, Array<T,Descriptor<T>::d> const& velocity, T temperature) {
00136     Array<T,Descriptor<T>::d> j;
00137     VectorTemplate<T,Descriptor>::multiplyByScalar(velocity, density, j);
00138     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00139     T rhoBar = Descriptor<T>::rhoBar(density);
00140     for (plint iPop=0; iPop<Descriptor<T>::numPop; ++iPop) {
00141         cell[iPop] = cell.computeEquilibrium(iPop, rhoBar, j, jSqr, temperature-(T)1);
00142     }
00143 }
00144 
00145 }  // namespace plb
00146 
00147 #endif  // CELL_HH