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

metaStuffFunctional2D.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 META_STUFF_FUNCTIONAL_2D_HH
00029 #define META_STUFF_FUNCTIONAL_2D_HH
00030 
00031 #include "dataProcessors/metaStuffFunctional2D.h"
00032 #include "core/plbDebug.h"
00033 #include "core/util.h"
00034 #include "core/blockStatistics.h"
00035 #include "core/dynamicsIdentifiers.h"
00036 #include "atomicBlock/atomicBlock2D.h"
00037 #include "atomicBlock/blockLattice2D.h"
00038 #include "atomicBlock/dataField2D.h"
00039 #include <cmath>
00040 
00041 namespace plb {
00042 
00043 
00044 
00045 /* ******** StoreDynamicsFunctional2D ************************************ */
00046 
00047 template<typename T, template<typename U> class Descriptor>
00048 StoreDynamicsFunctional2D<T,Descriptor>::StoreDynamicsFunctional2D()
00049     : maxChainLengthId(this->getStatistics().subscribeMax())
00050 { }
00051 
00052 template<typename T, template<typename U> class Descriptor>
00053 void StoreDynamicsFunctional2D<T,Descriptor>::processGenericBlocks (
00054         Box2D domain, std::vector<AtomicBlock2D*> blocks )
00055 {
00056     PLB_PRECONDITION( blocks.size()==2 );
00057     BlockLattice2D<T,Descriptor>& lattice = *dynamic_cast<BlockLattice2D<T,Descriptor>*>(blocks[0]);
00058     AtomicContainerBlock2D& container = *dynamic_cast<AtomicContainerBlock2D*>(blocks[1]);
00059     StoreDynamicsID* storeID = new StoreDynamicsID;
00060     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00061         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00062             std::vector<int> chain;
00063             constructIdChain(lattice.get(iX,iY).getDynamics(), chain);
00064             storeID->addIdChain(chain);
00065             this->getStatistics().gatherMax(maxChainLengthId, (double)chain.size());
00066         }
00067     }
00068     storeID->startIterations();
00069     container.setData(storeID);
00070 }
00071 
00072 template<typename T, template<typename U> class Descriptor>
00073 StoreDynamicsFunctional2D<T,Descriptor>* StoreDynamicsFunctional2D<T,Descriptor>::clone() const {
00074     return new StoreDynamicsFunctional2D<T,Descriptor>(*this);
00075 }
00076 
00077 template<typename T, template<typename U> class Descriptor>
00078 void StoreDynamicsFunctional2D<T,Descriptor>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00079     modified[0] = modif::nothing;
00080     modified[1] = modif::staticVariables;
00081 }
00082 
00083 template<typename T, template<typename U> class Descriptor>
00084 BlockDomain::DomainT StoreDynamicsFunctional2D<T,Descriptor>::appliesTo() const {
00085     return BlockDomain::bulk;
00086 }
00087 
00088 template<typename T, template<typename U> class Descriptor>
00089 pluint StoreDynamicsFunctional2D<T,Descriptor>::getMaxChainLength() const {
00090     double maximum=this->getStatistics().getMax(maxChainLengthId);
00091     return (pluint)(.5+maximum);
00092 }
00093 
00094 
00095 
00096 /* ******** ExtractDynamicsChainFunctional2D ************************************ */
00097 
00098 template<typename T, template<typename U> class Descriptor>
00099 ExtractDynamicsChainFunctional2D<T,Descriptor>::ExtractDynamicsChainFunctional2D (
00100         ExtractDynamicsChainFunctional2D<T,Descriptor>::DMap const& dynamicsMap_,
00101         pluint maxChainSize_ )
00102     : dynamicsMap(dynamicsMap_),
00103       maxChainSize(maxChainSize_)
00104 { }
00105 
00106 template<typename T, template<typename U> class Descriptor>
00107 void ExtractDynamicsChainFunctional2D<T,Descriptor>::process (
00108         Box2D domain, BlockLattice2D<T,Descriptor>& lattice,
00109                       ScalarField2D<int>& mask )
00110 {
00111     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00112         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00113             std::vector<int> chain;
00114             constructIdChain(lattice.get(iX,iY).getDynamics(), chain);
00115             util::extendVectorSize(chain, maxChainSize);
00116             mask.get(iX,iY) = dynamicsMap[chain];
00117         }
00118     }
00119 }
00120 
00121 template<typename T, template<typename U> class Descriptor>
00122 ExtractDynamicsChainFunctional2D<T,Descriptor>* ExtractDynamicsChainFunctional2D<T,Descriptor>::clone() const {
00123     return new ExtractDynamicsChainFunctional2D<T,Descriptor>(*this);
00124 }
00125 
00126 template<typename T, template<typename U> class Descriptor>
00127 void ExtractDynamicsChainFunctional2D<T,Descriptor>::getTypeOfModification(std::vector<modif::ModifT>& modified) const {
00128     modified[0] = modif::nothing;
00129     modified[1] = modif::staticVariables;
00130 }
00131 
00132 template<typename T, template<typename U> class Descriptor>
00133 BlockDomain::DomainT ExtractDynamicsChainFunctional2D<T,Descriptor>::appliesTo() const {
00134     return BlockDomain::bulk;
00135 }
00136 
00137 
00138 /* ******** ExtractTopMostDynamicsFunctional2D ************************************ */
00139 
00140 template<typename T, template<typename U> class Descriptor>
00141 void ExtractTopMostDynamicsFunctional2D<T,Descriptor>::process (
00142         Box2D domain, BlockLattice2D<T,Descriptor>& lattice,
00143                       ScalarField2D<int>& mask )
00144 {
00145     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00146         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00147             mask.get(iX,iY) = lattice.get(iX,iY).getDynamics().getId();
00148         }
00149     }
00150 }
00151 
00152 template<typename T, template<typename U> class Descriptor>
00153 ExtractTopMostDynamicsFunctional2D<T,Descriptor>*
00154     ExtractTopMostDynamicsFunctional2D<T,Descriptor>::clone() const
00155 {
00156     return new ExtractTopMostDynamicsFunctional2D<T,Descriptor>(*this);
00157 }
00158 
00159 template<typename T, template<typename U> class Descriptor>
00160 void ExtractTopMostDynamicsFunctional2D<T,Descriptor>::
00161     getTypeOfModification(std::vector<modif::ModifT>& modified) const
00162 {
00163     modified[0] = modif::nothing;
00164     modified[1] = modif::staticVariables;
00165 }
00166 
00167 template<typename T, template<typename U> class Descriptor>
00168 BlockDomain::DomainT ExtractTopMostDynamicsFunctional2D<T,Descriptor>::appliesTo() const {
00169     return BlockDomain::bulk;
00170 }
00171 
00172 
00173 /* ******** ExtractBottomMostDynamicsFunctional2D ************************************ */
00174 
00175 template<typename T, template<typename U> class Descriptor>
00176 void ExtractBottomMostDynamicsFunctional2D<T,Descriptor>::process (
00177         Box2D domain, BlockLattice2D<T,Descriptor>& lattice,
00178                       ScalarField2D<int>& mask )
00179 {
00180     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00181         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00182             mask.get(iX,iY) = getBottomMostDynamics(lattice.get(iX,iY).getDynamics()).getId();
00183         }
00184     }
00185 }
00186 
00187 template<typename T, template<typename U> class Descriptor>
00188 ExtractBottomMostDynamicsFunctional2D<T,Descriptor>*
00189     ExtractBottomMostDynamicsFunctional2D<T,Descriptor>::clone() const
00190 {
00191     return new ExtractBottomMostDynamicsFunctional2D<T,Descriptor>(*this);
00192 }
00193 
00194 template<typename T, template<typename U> class Descriptor>
00195 void ExtractBottomMostDynamicsFunctional2D<T,Descriptor>::
00196     getTypeOfModification(std::vector<modif::ModifT>& modified) const
00197 {
00198     modified[0] = modif::nothing;
00199     modified[1] = modif::staticVariables;
00200 }
00201 
00202 template<typename T, template<typename U> class Descriptor>
00203 BlockDomain::DomainT ExtractBottomMostDynamicsFunctional2D<T,Descriptor>::appliesTo() const {
00204     return BlockDomain::bulk;
00205 }
00206 
00207 
00208 /* ******** AssignEntireCellFunctional2D ************************************ */
00209 
00210 template<typename T, template<typename U> class Descriptor>
00211 void AssignEntireCellFunctional2D<T,Descriptor>::process (
00212         Box2D domain, BlockLattice2D<T,Descriptor>& sourceLattice,
00213                       BlockLattice2D<T,Descriptor>& destinationLattice )
00214 {
00215     std::vector<char> data;
00216     Dot2D offset = computeRelativeDisplacement(sourceLattice, destinationLattice);
00217     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00218         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00219             Cell<T,Descriptor> const& cell = sourceLattice.get(iX,iY);
00220 
00221             pluint pos = data.size();
00222             data.resize(pos+CellInfo<T,Descriptor>::n*sizeof(T));
00223             cell.serialize(&data[pos]);
00224 
00225             HierarchicSerializer serializer(data, cell.getDynamics().getId());
00226             cell.getDynamics().serialize(serializer);
00227         }
00228     }
00229 
00230     pluint pos=0;
00231     for (plint iX=domain.x0; iX<=domain.x1; ++iX) {
00232         for (plint iY=domain.y0; iY<=domain.y1; ++iY) {
00233             plint iX_ = iX+offset.x;
00234             plint iY_ = iY+offset.y;
00235             Cell<T,Descriptor>& cell = destinationLattice.get(iX_,iY_);
00236 
00237             cell.unSerialize(&data[pos]);
00238             pos += CellInfo<T,Descriptor>::n*sizeof(T);
00239 
00240             HierarchicUnserializer unserializer(data, pos);
00241             destinationLattice.attributeDynamics (
00242                     iX_,iY_, meta::dynamicsRegistration<T,Descriptor>().
00243                                  generate(unserializer) );
00244             pos = unserializer.getCurrentPos();
00245         }
00246     }
00247 }
00248 
00249 template<typename T, template<typename U> class Descriptor>
00250 AssignEntireCellFunctional2D<T,Descriptor>*
00251     AssignEntireCellFunctional2D<T,Descriptor>::clone() const
00252 {
00253     return new AssignEntireCellFunctional2D<T,Descriptor>(*this);
00254 }
00255 
00256 template<typename T, template<typename U> class Descriptor>
00257 void AssignEntireCellFunctional2D<T,Descriptor>::
00258     getTypeOfModification(std::vector<modif::ModifT>& modified) const
00259 {
00260     modified[0] = modif::nothing;
00261     modified[1] = modif::staticVariables;
00262 }
00263 
00264 template<typename T, template<typename U> class Descriptor>
00265 BlockDomain::DomainT AssignEntireCellFunctional2D<T,Descriptor>::appliesTo() const {
00266     return BlockDomain::bulkAndEnvelope;
00267 }
00268 
00269 }  // namespace plb
00270 
00271 #endif  // META_STUFF_FUNCTIONAL_2D_HH