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

dataInitializerGenerics3D.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 DATA_FIELD_INITIALIZER_GENERICS_3D_H
00029 #define DATA_FIELD_INITIALIZER_GENERICS_3D_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "atomicBlock/dataProcessorWrapper3D.h"
00033 #include "multiBlock/multiDataProcessorWrapper3D.h"
00034 #include "latticeBoltzmann/geometricOperationTemplates.h"
00035 #include "multiGrid/multiGridUtil.h"
00036 
00037 namespace plb {
00038 
00039 /* *************** PART I ******************************************** */
00040 /* *************** Initialization of the block-lattice *************** */
00041 /* ******************************************************************* */
00042 
00043 /* ************ Class SetCustomBoundaryVelocityFunctional3D ********** */
00044 
00045 template<typename T, template<typename U> class Descriptor, class VelocityFunction>
00046 SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>::
00047     SetCustomBoundaryVelocityFunctional3D(VelocityFunction f_)
00048         : f(f_),
00049           velocityScale( (T)1 )
00050 { }
00051 
00052 template<typename T, template<typename U> class Descriptor, class VelocityFunction>
00053 SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>*
00054     SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>::clone() const
00055 {
00056     return new SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>(*this);
00057 }
00058 
00059 template<typename T, template<typename U> class Descriptor, class VelocityFunction>
00060 void SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>::execute (
00061         plint iX, plint iY, plint iZ, Cell<T,Descriptor>& cell ) const
00062 {
00063     Array<T,Descriptor<T>::d> u;
00064     f(iX, iY, iZ, u);
00065     u[0] *= velocityScale;
00066     u[1] *= velocityScale;
00067     u[2] *= velocityScale;
00068     cell.defineVelocity(u);
00069 }
00070 
00071 template<typename T, template<typename U> class Descriptor, class VelocityFunction>
00072 void SetCustomBoundaryVelocityFunctional3D<T,Descriptor,VelocityFunction>::setscale (
00073         int dxScale, int dtScale )
00074 {
00075     int dimDx = 1;
00076     int dimDt = -1;
00077     velocityScale = scaleFromReference(dxScale, dimDx,
00078                                        dtScale, dimDt);
00079 }
00080 
00081 /* ************ Class SetCustomBoundaryDensityFunctional3D ********** */
00082 
00083 template<typename T, template<typename U> class Descriptor, class DensityFunction>
00084 SetCustomBoundaryDensityFunctional3D<T,Descriptor,DensityFunction>::
00085     SetCustomBoundaryDensityFunctional3D(DensityFunction f_)
00086         : f(f_)
00087 { }
00088 
00089 template<typename T, template<typename U> class Descriptor, class DensityFunction>
00090 void SetCustomBoundaryDensityFunctional3D<T,Descriptor,DensityFunction>::
00091     execute(plint iX, plint iY, plint iZ, Cell<T,Descriptor>& cell) const
00092 {
00093     // No rescaling needed: rho is scale invariant.
00094     T rho = f(iX, iY, iZ);
00095     cell.defineDensity(rho);
00096 }
00097 
00098 template<typename T, template<typename U> class Descriptor, class DensityFunction>
00099 SetCustomBoundaryDensityFunctional3D<T,Descriptor,DensityFunction>*
00100     SetCustomBoundaryDensityFunctional3D<T,Descriptor,DensityFunction>::clone() const
00101 {
00102     return new SetCustomBoundaryDensityFunctional3D<T,Descriptor,DensityFunction>(*this);
00103 }
00104 
00105 
00106 /* ************ Class IniCustomEquilibriumFunctional3D ********** */
00107 
00108 template<typename T, template<typename U> class Descriptor, class RhoUFunction>
00109 IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>::
00110     IniCustomEquilibriumFunctional3D(RhoUFunction f_)
00111         : f(f_),
00112           velocityScale( (T)1 )
00113 { }
00114 
00115 template<typename T, template<typename U> class Descriptor, class RhoUFunction>
00116 void IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>::execute (
00117         plint iX, plint iY, plint iZ, Cell<T,Descriptor>& cell ) const
00118 {
00119     Array<T,Descriptor<T>::d> j;
00120     T rho;
00121     f(iX, iY, iZ, rho, j);
00122     for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00123         j[iD] *= rho;
00124         j[iD] *= velocityScale;
00125     }
00126     T rhoBar = Descriptor<T>::rhoBar(rho);
00127     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00128     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00129         cell[iPop] = cell.computeEquilibrium(iPop, rhoBar, j, jSqr);
00130     }
00131 }
00132 
00133 template<typename T, template<typename U> class Descriptor, class RhoUFunction>
00134 IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>*
00135     IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>::clone() const
00136 {
00137     return new IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>(*this);
00138 }
00139 
00140 template<typename T, template<typename U> class Descriptor, class RhoUFunction>
00141 void IniCustomEquilibriumFunctional3D<T,Descriptor,RhoUFunction>::setscale (
00142         int dxScale, int dtScale )
00143 {
00144     int dimDx = 1;
00145     int dimDt = -1;
00146     velocityScale = scaleFromReference(dxScale, dimDx,
00147                                        dtScale, dimDt);
00148 }
00149 
00150 /* ************ Class IniCustomThermalEquilibriumFunctional3D ********** */
00151 
00152 template<typename T, template<typename U> class Descriptor, class RhoVelTempFunction>
00153 IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>::
00154     IniCustomThermalEquilibriumFunctional3D(RhoVelTempFunction f_)
00155         : f(f_),
00156           velocityScale( (T)1 )
00157 { }
00158 
00159 template<typename T, template<typename U> class Descriptor, class RhoVelTempFunction>
00160 void IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>::execute (
00161         plint iX, plint iY, plint iZ, Cell<T,Descriptor>& cell ) const
00162 {
00163     Array<T,Descriptor<T>::d> j;
00164     T rho;
00165     T temperature;
00166     f(iX, iY, iZ, rho, j, temperature);
00167     for (int iD=0; iD<Descriptor<T>::d; ++iD) {
00168         j[iD] *= rho;
00169         j[iD] *= velocityScale;
00170     }
00171     T rhoBar = Descriptor<T>::rhoBar(rho);
00172     T thetaBar = temperature-(T)1;
00173     T jSqr = VectorTemplate<T,Descriptor>::normSqr(j);
00174     for (plint iPop=0; iPop<Descriptor<T>::q; ++iPop) {
00175         cell[iPop] = cell.computeEquilibrium(iPop, rhoBar, j, jSqr, thetaBar);
00176     }
00177 }
00178 
00179 template<typename T, template<typename U> class Descriptor, class RhoVelTempFunction>
00180 IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>*
00181     IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>::clone() const
00182 {
00183     return new IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>(*this);
00184 }
00185 
00186 template<typename T, template<typename U> class Descriptor, class RhoVelTempFunction>
00187 void IniCustomThermalEquilibriumFunctional3D<T,Descriptor,RhoVelTempFunction>::setscale (
00188         int dxScale, int dtScale )
00189 {
00190     int dimDx = 1;
00191     int dimDt = -1;
00192     velocityScale = scaleFromReference(dxScale, dimDx,
00193                                        dtScale, dimDt);
00194 }
00195 
00196 
00197 /* *************** PART II ******************************************* */
00198 /* *************** Initialization of the scalar- and tensor-field **** */
00199 /* ******************************************************************* */
00200 
00201 /* ************ SetToScalarFunctionFunctional3D ********************** */
00202 
00203 template<typename T, class Function>
00204 SetToScalarFunctionFunctional3D<T,Function>::SetToScalarFunctionFunctional3D(Function f_)
00205     : f(f_)
00206 { }
00207 
00208 template<typename T, class Function>
00209 void SetToScalarFunctionFunctional3D<T,Function>::process (
00210         Box3D domain, ScalarField3D<T>& field )
00211 {
00212     Dot3D relativeOffset = field.getLocation();
00213     Array<plint,3> ofs(relativeOffset.x, relativeOffset.y, relativeOffset.z);
00214     Array<plint,3> pos;
00215     for ( pos[0]=domain.x0; pos[0]<=domain.x1; ++pos[0] ) {
00216         for ( pos[1]=domain.y0; pos[1]<=domain.y1; ++pos[1] ) {
00217             for ( pos[2]=domain.z0; pos[2]<=domain.z1; ++pos[2] ) {
00218                     field.get(pos[0],pos[1],pos[2]) = 
00219                             f(pos[0]+ofs[0], pos[1]+ofs[1], pos[2]+ofs[2]);
00220             }
00221         }
00222     }
00223 }
00224 
00225 template<typename T, class Function>
00226 SetToScalarFunctionFunctional3D<T,Function>*
00227     SetToScalarFunctionFunctional3D<T,Function>::clone() const
00228 {
00229     return new SetToScalarFunctionFunctional3D<T,Function>(*this);
00230 }
00231 
00232 template<typename T, class Function>
00233 BlockDomain::DomainT SetToScalarFunctionFunctional3D<T,Function>::appliesTo() const
00234 {
00235     // Boundary cannot be included, because periodic boundaries would
00236     //   get the wrong value.
00237     return BlockDomain::bulk;
00238 }
00239 
00240 template<typename T, class Function>
00241 void SetToScalarFunctionFunctional3D<T,Function>::getTypeOfModification (
00242         std::vector<modif::ModifT>& modified) const
00243 {
00244     modified[0] = modif::staticVariables;
00245 }
00246 
00247 
00248 /* ************ SetToTensorFunctionFunctional3D ********************** */
00249 
00250 template<typename T, int nDim, class Function>
00251 SetToTensorFunctionFunctional3D<T,nDim,Function>::
00252     SetToTensorFunctionFunctional3D(Function f_)
00253         : f(f_)
00254 { }
00255 
00256 template<typename T, int nDim, class Function>
00257 void SetToTensorFunctionFunctional3D<T,nDim,Function>::process (
00258         Box3D domain, TensorField3D<T,nDim>& field )
00259 {
00260     Dot3D relativeOffset = field.getLocation();
00261     Array<plint,nDim> ofs(relativeOffset.x, relativeOffset.y, relativeOffset.z);
00262     Array<plint,nDim> pos;
00263     Array<T,nDim> value;
00264     for ( pos[0]=domain.x0; pos[0]<=domain.x1; ++pos[0] ) {
00265         for ( pos[1]=domain.y0; pos[1]<=domain.y1; ++pos[1] ) {
00266             for ( pos[2]=domain.z0; pos[2]<=domain.z1; ++pos[2] ) {
00267                 f(pos[0]+ofs[0], pos[1]+ofs[1], pos[2]+ofs[2], value);
00268                 field.get(pos[0],pos[1],pos[2]) = value;
00269             }
00270         }
00271     }
00272 }
00273 
00274 template<typename T, int nDim, class Function>
00275 SetToTensorFunctionFunctional3D<T,nDim,Function>*
00276     SetToTensorFunctionFunctional3D<T,nDim,Function>::clone() const
00277 {
00278     return new SetToTensorFunctionFunctional3D<T,nDim,Function>(*this);
00279 }
00280 
00281 template<typename T, int nDim, class Function>
00282 BlockDomain::DomainT SetToTensorFunctionFunctional3D<T,nDim,Function>::appliesTo() const
00283 {
00284     // Boundary cannot be included, because periodic boundaries
00285     //   would get the wrong value.
00286     return BlockDomain::bulk;
00287 }
00288 
00289 template<typename T, int nDim, class Function>
00290 void SetToTensorFunctionFunctional3D<T,nDim,Function>::getTypeOfModification (
00291         std::vector<modif::ModifT>& modified ) const
00292 {
00293     modified[0] = modif::staticVariables;
00294 }
00295 
00296 }  // namespace plb
00297 
00298 #endif  // DATA_FIELD_INITIALIZER_GENERICS_3D_H