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

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