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

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