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

metaStuffWrapper2D.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_WRAPPER_2D_HH
00029 #define META_STUFF_WRAPPER_2D_HH
00030 
00031 #include "dataProcessors/metaStuffWrapper2D.h"
00032 #include "dataProcessors/metaStuffFunctional2D.h"
00033 #include "dataProcessors/dataInitializerWrapper2D.h"
00034 #include "multiBlock/reductiveMultiDataProcessorWrapper2D.h"
00035 #include "multiBlock/multiDataProcessorWrapper2D.h"
00036 #include "multiBlock/multiContainerBlock2D.h"
00037 #include "core/dynamicsIdentifiers.h"
00038 
00039 
00040 namespace plb {
00041 
00042 template<typename T, template<typename U> class Descriptor>
00043 void extractTopMostDynamics(MultiBlockLattice2D<T,Descriptor>& lattice, MultiScalarField2D<int>& dynamicsId,
00044                             Box2D domain )
00045 {
00046     applyProcessingFunctional (
00047             new ExtractTopMostDynamicsFunctional2D<T,Descriptor>(),
00048             domain, lattice, dynamicsId );
00049 }
00050 
00051 template<typename T, template<typename U> class Descriptor>
00052 std::auto_ptr< MultiScalarField2D<int> > extractTopMostDynamics (
00053                                              MultiBlockLattice2D<T,Descriptor>& lattice, Box2D domain )
00054 {
00055     MultiScalarField2D<int>* dynamicsId = new MultiScalarField2D<int>(lattice, domain);
00056     extractTopMostDynamics(lattice, *dynamicsId, domain);
00057     return std::auto_ptr<MultiScalarField2D<int> >(dynamicsId);
00058 }
00059 
00060 template<typename T, template<typename U> class Descriptor>
00061 std::auto_ptr< MultiScalarField2D<int> > extractTopMostDynamics (
00062                                              MultiBlockLattice2D<T,Descriptor>& lattice )
00063 {
00064     return extractTopMostDynamics(lattice, lattice.getBoundingBox());
00065 }
00066 
00067 
00068 template<typename T, template<typename U> class Descriptor>
00069 void extractBottomMostDynamics(MultiBlockLattice2D<T,Descriptor>& lattice, MultiScalarField2D<int>& dynamicsId,
00070                             Box2D domain )
00071 {
00072     applyProcessingFunctional (
00073             new ExtractBottomMostDynamicsFunctional2D<T,Descriptor>(),
00074             domain, lattice, dynamicsId );
00075 }
00076 
00077 template<typename T, template<typename U> class Descriptor>
00078 std::auto_ptr< MultiScalarField2D<int> > extractBottomMostDynamics (
00079                                              MultiBlockLattice2D<T,Descriptor>& lattice, Box2D domain )
00080 {
00081     MultiScalarField2D<int>* dynamicsId = new MultiScalarField2D<int>(lattice, domain);
00082     extractBottomMostDynamics(lattice, *dynamicsId, domain);
00083     return std::auto_ptr<MultiScalarField2D<int> >(dynamicsId);
00084 }
00085 
00086 template<typename T, template<typename U> class Descriptor>
00087 std::auto_ptr< MultiScalarField2D<int> > extractBottomMostDynamics (
00088                                              MultiBlockLattice2D<T,Descriptor>& lattice )
00089 {
00090     return extractBottomMostDynamics(lattice, lattice.getBoundingBox());
00091 }
00092 
00093 
00094 template<typename T, template<typename U> class Descriptor>
00095 void uniqueDynamicsChains (
00096         MultiBlockLattice2D<T,Descriptor>& lattice, Box2D domain,
00097         std::vector<std::vector<int> >& chains, pluint& maxChainLength )
00098 {
00099     MultiContainerBlock2D container(lattice);
00100     std::vector<MultiBlock2D*> latticeAndContainer, containerVector;
00101     latticeAndContainer.push_back(&lattice);
00102     latticeAndContainer.push_back(&container);
00103     containerVector.push_back(&container);
00104 
00105     StoreDynamicsFunctional2D<T,Descriptor> SDFunctional;
00106     applyProcessingFunctional(SDFunctional, domain, latticeAndContainer);
00107     maxChainLength = SDFunctional.getMaxChainLength();
00108 
00109     std::vector<int> nextMaximum(maxChainLength);
00110     for (pluint i=0; i<nextMaximum.size(); ++i) {
00111         nextMaximum[i] = -1;
00112     }
00113     std::vector<int> emptyVector(nextMaximum);
00114     std::vector<std::vector<int> > maxima;
00115     do {
00116         IterateDynamicsFunctional2D functional(nextMaximum);
00117         applyProcessingFunctional(functional, domain, containerVector);
00118         nextMaximum = functional.getNextMaximum();
00119         if (!vectorEquals(nextMaximum, emptyVector)) {
00120             maxima.push_back(nextMaximum);
00121         }
00122     }
00123     while (!vectorEquals(nextMaximum, emptyVector));
00124     chains.swap(maxima);
00125 }
00126 
00127 template<typename T, template<typename U> class Descriptor>
00128 void uniqueDynamicsIds (
00129         MultiBlockLattice2D<T,Descriptor>& lattice, Box2D domain, std::vector<int>& ids )
00130 {
00131     std::vector<std::vector<int> > chains;
00132     pluint maxChainLength;
00133     uniqueDynamicsChains(lattice, domain, chains, maxChainLength);
00134     std::set<int> idSet;
00135     for (pluint iChain=0; iChain<chains.size(); ++iChain) {
00136         idSet.insert(chains[iChain].begin(), chains[iChain].end());
00137     }
00138     idSet.erase(-1);
00139     std::vector<int>(idSet.begin(), idSet.end()).swap(ids);
00140 }
00141 
00142 template<typename T, template<typename U> class Descriptor>
00143 void extractDynamicsChain(MultiBlockLattice2D<T,Descriptor>& lattice,
00144                           MultiScalarField2D<int>& dynamicsId,
00145                           std::map<int,std::string>& nameOfDynamics, Box2D domain )
00146 {
00147     std::vector<std::vector<int> > chains;
00148     pluint maxChainLength;
00149     uniqueDynamicsChains(lattice, domain, chains, maxChainLength);
00150     nameOfDynamics.clear();
00151     typename ExtractDynamicsChainFunctional2D<T,Descriptor>::DMap dynamicsMap;
00152     for (pluint iChain=0; iChain<chains.size(); ++iChain) {
00153         dynamicsMap[chains[iChain]] = iChain;
00154         nameOfDynamics[iChain] = meta::constructIdNameChain<T,Descriptor>(chains[iChain], " >> ");
00155     }
00156     setToConstant(dynamicsId, dynamicsId.getBoundingBox(), -1);
00157     applyProcessingFunctional (
00158             new ExtractDynamicsChainFunctional2D<T,Descriptor>(dynamicsMap, maxChainLength),
00159             domain, lattice, dynamicsId );
00160 }
00161 
00162 
00163 template<typename T, template<typename U> class Descriptor>
00164 std::auto_ptr< MultiScalarField2D<int> > extractDynamicsChain (
00165             MultiBlockLattice2D<T,Descriptor>& lattice,
00166             std::map<int,std::string>& nameOfDynamics, Box2D domain )
00167 {
00168     MultiScalarField2D<int>* dynamicsId = new MultiScalarField2D<int>(lattice, domain);
00169     extractDynamicsChain(lattice, *dynamicsId, nameOfDynamics, domain);
00170     return std::auto_ptr<MultiScalarField2D<int> >(dynamicsId);
00171 }
00172 
00173 template<typename T, template<typename U> class Descriptor>
00174 std::auto_ptr< MultiScalarField2D<int> > extractDynamicsChain (
00175             MultiBlockLattice2D<T,Descriptor>& lattice,
00176             std::map<int,std::string>& nameOfDynamics )
00177 {
00178     return extractDynamicsChain(lattice, nameOfDynamics, lattice.getBoundingBox());
00179 }
00180 
00181 
00182 template<typename T, template<typename U> class Descriptor>
00183 void copyEntireCells( MultiBlockLattice2D<T,Descriptor>& sourceLattice,
00184                       MultiBlockLattice2D<T,Descriptor>& destinationLattice,
00185                       Box2D domain )
00186 {
00187     applyProcessingFunctional(new AssignEntireCellFunctional2D<T,Descriptor>, domain,
00188                               sourceLattice, destinationLattice);
00189 }
00190 
00191 template<typename T, template<typename U> class Descriptor>
00192 std::auto_ptr< MultiBlockLattice2D<T,Descriptor> > copyEntireCells (
00193             MultiBlockLattice2D<T,Descriptor>& lattice )
00194 {
00195     return copyEntireCells(lattice, lattice.getBoundingBox());
00196 }
00197 
00198 template<typename T, template<typename U> class Descriptor>
00199 std::auto_ptr< MultiBlockLattice2D<T,Descriptor> > copyEntireCells (
00200             MultiBlockLattice2D<T,Descriptor>& lattice, Box2D domain )
00201 {
00202     MultiBlockLattice2D<T,Descriptor>* newLattice = new MultiBlockLattice2D<T,Descriptor>(lattice, domain);
00203     copyEntireCells(lattice, *newLattice, domain);
00204     return std::auto_ptr<MultiBlockLattice2D<T,Descriptor> >(newLattice);
00205 }
00206 
00207 }  // namespace plb
00208 
00209 #endif  // META_STUFF_WRAPPER_2D_HH