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

dataAnalysisGenerics3D.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_ANALYSIS_GENERICS_3D_H
00029 #define DATA_ANALYSIS_GENERICS_3D_H
00030 
00031 #include "core/cell.h"
00032 
00033 namespace plb {
00034 
00035 /* ******** CountLatticeElementsFunctional3D **************************** */
00036 
00037 template<typename T, template<typename U> class Descriptor, class BoolMask> 
00038 CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>::CountLatticeElementsFunctional3D (
00039         BoolMask boolMask_)
00040   : countId(this->getStatistics().subscribeIntSum()),
00041     boolMask(boolMask_)
00042 { }
00043 
00044 template<typename T, template<typename U> class Descriptor, class BoolMask> 
00045 void CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>::process (
00046         Box3D domain, BlockLattice3D<T,Descriptor>& lattice )
00047 {
00048     BlockStatistics& statistics = this->getStatistics();
00049     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00050         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00051             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00052                 Cell<T,Descriptor> const& cell = lattice.get(iX,iY,iZ);
00053                 if (boolMask(cell)) {
00054                     statistics.gatherIntSum(countId, 1);
00055                 }
00056             }
00057         }
00058     }
00059 }
00060 
00061 template<typename T, template<typename U> class Descriptor, class BoolMask> 
00062 CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>*
00063     CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>::clone() const
00064 {
00065     return new CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>(*this);
00066 }
00067 
00068 template<typename T, template<typename U> class Descriptor, class BoolMask> 
00069 plint CountLatticeElementsFunctional3D<T,Descriptor,BoolMask>::getCount() const
00070 {
00071     return this->getStatistics().getIntSum(countId);
00072 }
00073 
00074 
00075 /* ******** CountScalarElementsFunctional3D **************************** */
00076 
00077 template<typename T, class BoolMask> 
00078 CountScalarElementsFunctional3D<T,BoolMask>::CountScalarElementsFunctional3D (
00079         BoolMask boolMask_)
00080   : countId(this->getStatistics().subscribeIntSum()),
00081     boolMask(boolMask_)
00082 { }
00083 
00084 template<typename T, class BoolMask> 
00085 void CountScalarElementsFunctional3D<T,BoolMask>::process (
00086         Box3D domain, ScalarField3D<T>& field )
00087 {
00088     BlockStatistics& statistics = this->getStatistics();
00089     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00090         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00091             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00092                 T value = field.get(iX,iY,iZ);
00093                 if (boolMask(value)) {
00094                     statistics.gatherIntSum(countId, 1);
00095                 }
00096             }
00097         }
00098     }
00099 }
00100 
00101 template<typename T, class BoolMask> 
00102 CountScalarElementsFunctional3D<T,BoolMask>*
00103     CountScalarElementsFunctional3D<T,BoolMask>::clone() const
00104 {
00105     return new CountScalarElementsFunctional3D<T,BoolMask>(*this);
00106 }
00107 
00108 template<typename T, class BoolMask> 
00109 plint CountScalarElementsFunctional3D<T,BoolMask>::getCount() const
00110 {
00111     return this->getStatistics().getIntSum(countId);
00112 }
00113 
00114 
00115 /* ******** CountTensorElementsFunctional3D **************************** */
00116 
00117 template<typename T, int nDim, class BoolMask> 
00118 CountTensorElementsFunctional3D<T,nDim,BoolMask>::CountTensorElementsFunctional3D (
00119         BoolMask boolMask_)
00120   : countId(this->getStatistics().subscribeIntSum()),
00121     boolMask(boolMask_)
00122 { }
00123 
00124 template<typename T, int nDim, class BoolMask> 
00125 void CountTensorElementsFunctional3D<T,nDim,BoolMask>::process (
00126         Box3D domain, TensorField3D<T,nDim>& field )
00127 {
00128     BlockStatistics& statistics = this->getStatistics();
00129     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00130         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00131             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00132                 Array<T,nDim> const& value = field.get(iX,iY,iZ);
00133                 if (boolMask(value)) {
00134                     statistics.gatherIntSum(countId, 1);
00135                 }
00136             }
00137         }
00138     }
00139 }
00140 
00141 template<typename T, int nDim, class BoolMask> 
00142 CountTensorElementsFunctional3D<T,nDim,BoolMask>*
00143     CountTensorElementsFunctional3D<T,nDim,BoolMask>::clone() const
00144 {
00145     return new CountTensorElementsFunctional3D<T,nDim,BoolMask>(*this);
00146 }
00147 
00148 template<typename T, int nDim, class BoolMask> 
00149 plint CountTensorElementsFunctional3D<T,nDim,BoolMask>::getCount() const
00150 {
00151     return this->getStatistics().getIntSum(countId);
00152 }
00153 
00154 
00155 
00156 /* ******** ApplyScalarFunctional3D ************************************* */
00157 
00158 template<typename T, class Function>
00159 ApplyScalarFunctional3D<T,Function>::ApplyScalarFunctional3D(Function f_)
00160     : f(f_)
00161 { }
00162 
00163 template<typename T,class Function>
00164 void ApplyScalarFunctional3D<T,Function>::process (
00165         Box3D domain, ScalarField3D<T>& field )
00166 {
00167     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00168         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00169             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00170                 field.get(iX,iY,iZ) = f(field.get(iX,iY,iZ));
00171             }
00172         }
00173     }
00174 }
00175 
00176 template<typename T,class Function>
00177 ApplyScalarFunctional3D<T,Function>* ApplyScalarFunctional3D<T,Function>::clone() const {
00178     return new ApplyScalarFunctional3D<T,Function>(*this);
00179 }
00180 
00181 template<typename T,class Function>
00182 void ApplyScalarFunctional3D<T,Function>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00183     modified[0] = modif::staticVariables;
00184 }
00185 
00186 template<typename T,class Function>
00187 BlockDomain::DomainT ApplyScalarFunctional3D<T,Function>::appliesTo() const {
00188     return BlockDomain::bulkAndEnvelope;
00189 }
00190 
00191 
00192 /* ******** EvaluateScalarFunctional3D ************************************* */
00193 
00194 template<typename T, class Function>
00195 EvaluateScalarFunctional3D<T,Function>::EvaluateScalarFunctional3D(Function f_)
00196     : f(f_)
00197 { }
00198 
00199 template<typename T, class Function>
00200 void EvaluateScalarFunctional3D<T,Function>::process (
00201         Box3D domain, ScalarField3D<T>& field, ScalarField3D<T>& result )
00202 {
00203     Dot3D offset = computeRelativeDisplacement(field, result);
00204     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00205         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00206             for (plint iZ=domain.z0; iZ<=domain.z1; ++iZ) {
00207                 result.get(iX+offset.x,iY+offset.y,iZ+offset.z) = f(field.get(iX,iY,iZ));
00208             }
00209         }
00210     }
00211 }
00212 
00213 template<typename T, class Function>
00214 EvaluateScalarFunctional3D<T,Function>* EvaluateScalarFunctional3D<T,Function>::clone() const {
00215     return new EvaluateScalarFunctional3D<T,Function>(*this);
00216 }
00217 
00218 template<typename T, class Function>
00219 void EvaluateScalarFunctional3D<T,Function>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00220     modified[0] = modif::nothing;
00221     modified[1] = modif::staticVariables;
00222 }
00223 
00224 template<typename T, class Function>
00225 BlockDomain::DomainT EvaluateScalarFunctional3D<T,Function>::appliesTo() const {
00226     return BlockDomain::bulkAndEnvelope;
00227 }
00228 
00229 }  // namespace plb
00230 
00231 #endif  // DATA_ANALYSIS_GENERICS_3D_H