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

parallelMultiBlockLattice3D.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 PARALLEL_MULTI_BLOCK_LATTICE_3D_HH
00029 #define PARALLEL_MULTI_BLOCK_LATTICE_3D_HH
00030 
00031 #include "parallelism/parallelMultiBlockLattice3D.h"
00032 #include "parallelism/parallelDynamics.h"
00033 #include "multiBlock/staticRepartitions3D.h"
00034 #include "atomicBlock/blockLattice3D.h"
00035 
00036 
00037 #ifdef PLB_MPI_PARALLEL
00038 
00039 namespace plb {
00040 
00042 
00043 template<typename T, template<typename U> class Descriptor>
00044 ParallelCellAccess3D<T,Descriptor>::ParallelCellAccess3D()
00045     : parallelDynamics( 0 )
00046 { }
00047 
00048 template<typename T, template<typename U> class Descriptor>
00049 ParallelCellAccess3D<T,Descriptor>::~ParallelCellAccess3D() {
00050     delete parallelDynamics;
00051 }
00052 
00053 template<typename T, template<typename U> class Descriptor>
00054 void ParallelCellAccess3D<T,Descriptor>::broadCastCell(Cell<T,Descriptor>& cell, plint fromBlock,
00055                                                        MultiBlockManagement3D const& multiBlockManagement) const
00056 {
00057     const plint sizeOfCell = Descriptor<T>::q + Descriptor<T>::ExternalField::numScalars;
00058     char* cellData = new char[sizeOfCell*sizeof(T)];
00059     plint fromProc = multiBlockManagement.getThreadAttribution().getMpiProcess(fromBlock);
00060     if (global::mpi().getRank()==fromProc) {
00061         cell.serialize(cellData);
00062     }
00063     global::mpi().bCast(cellData, sizeOfCell, fromProc);
00064     cell.unSerialize(cellData);
00065     delete [] cellData;
00066 }
00067 
00068 template<typename T, template<typename U> class Descriptor>
00069 Cell<T,Descriptor>& ParallelCellAccess3D<T,Descriptor>::getDistributedCell (
00070         plint iX, plint iY, plint iZ,
00071         MultiBlockManagement3D const& multiBlockManagement,
00072         std::map<plint,BlockLattice3D<T,Descriptor>*>& lattices )
00073 {
00074     std::vector<plint> foundId;
00075     std::vector<plint> foundX, foundY, foundZ;
00076     bool hasBulkCell =
00077         multiBlockManagement.findAllLocalRepresentations(iX,iY,iZ, foundId, foundX, foundY, foundZ);
00078     baseCells.clear();
00079     for (pluint iBlock=0; iBlock<foundId.size(); ++iBlock) {
00080         plint foundBlock = foundId[iBlock];
00081         baseCells.push_back ( &lattices[foundBlock] -> get ( foundX[iBlock], foundY[iBlock], foundZ[iBlock] ) );
00082     }
00083     delete parallelDynamics;
00084     parallelDynamics = new ParallelDynamics<T,Descriptor>(baseCells, hasBulkCell);
00085     distributedCell.attributeDynamics(parallelDynamics);
00086     return distributedCell;
00087 }
00088 
00089 template<typename T, template<typename U> class Descriptor>
00090 Cell<T,Descriptor> const& ParallelCellAccess3D<T,Descriptor>::getDistributedCell (
00091         plint iX, plint iY, plint iZ,
00092         MultiBlockManagement3D const& multiBlockManagement,
00093         std::map<plint,BlockLattice3D<T,Descriptor>*> const& lattices ) const
00094 {
00095     std::vector<plint> foundId;
00096     std::vector<plint> foundX, foundY, foundZ;
00097     bool hasBulkCell =
00098         multiBlockManagement.findAllLocalRepresentations(iX,iY,iZ, foundId, foundX, foundY, foundZ);
00099     constBaseCells.clear();
00100     for (pluint iBlock=0; iBlock<foundId.size(); ++iBlock) {
00101         plint foundBlock = foundId[iBlock];
00102         typename std::map<plint,BlockLattice3D<T,Descriptor>*>::const_iterator it = lattices.find(foundBlock);
00103         constBaseCells.push_back ( &it->second -> get ( foundX[iBlock], foundY[iBlock], foundZ[iBlock] ) );
00104     }
00105     delete parallelDynamics;
00106     parallelDynamics = new ConstParallelDynamics<T,Descriptor>(constBaseCells, hasBulkCell);
00107     distributedCell.attributeDynamics(parallelDynamics);
00108     return distributedCell;
00109 }
00110 
00111 template<typename T, template<typename U> class Descriptor>
00112 ParallelCellAccess3D<T,Descriptor>* ParallelCellAccess3D<T,Descriptor>::clone() const {
00113     return new ParallelCellAccess3D<T,Descriptor>;
00114 }
00115 
00116 }  // namespace plb
00117 
00118 #endif  // PLB_MPI_PARALLEL
00119 
00120 #endif