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

parallelMultiBlockLattice2D.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_2D_HH
00029 #define PARALLEL_MULTI_BLOCK_LATTICE_2D_HH
00030 
00031 #include "parallelism/parallelMultiBlockLattice2D.h"
00032 #include "parallelism/parallelDynamics.h"
00033 #include "multiBlock/staticRepartitions2D.h"
00034 #include "atomicBlock/blockLattice2D.h"
00035 
00036 
00037 #ifdef PLB_MPI_PARALLEL
00038 
00039 namespace plb {
00040 
00041 /* *************** Class ParallelCellAccess2D ************************** */
00042 
00043 template<typename T, template<typename U> class Descriptor>
00044 ParallelCellAccess2D<T,Descriptor>::ParallelCellAccess2D()
00045     : parallelDynamics( 0 )
00046 { }
00047 
00048 template<typename T, template<typename U> class Descriptor>
00049 ParallelCellAccess2D<T,Descriptor>::~ParallelCellAccess2D() {
00050     delete parallelDynamics;
00051 }
00052 
00053 template<typename T, template<typename U> class Descriptor>
00054 void ParallelCellAccess2D<T,Descriptor>::broadCastCell(Cell<T,Descriptor>& cell, plint fromBlock,
00055                                                     MultiBlockManagement2D 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>& ParallelCellAccess2D<T,Descriptor>::getDistributedCell (
00070         plint iX, plint iY,
00071         MultiBlockManagement2D const& multiBlockManagement,
00072         std::map<plint,BlockLattice2D<T,Descriptor>*>& lattices )
00073 {
00074     std::vector<plint> foundId;
00075     std::vector<plint> foundX, foundY;
00076     bool hasBulkCell = multiBlockManagement.findAllLocalRepresentations(iX,iY, foundId, foundX, foundY);
00077     baseCells.clear();
00078     for (pluint iBlock=0; iBlock<foundId.size(); ++iBlock) {
00079         plint foundBlock = foundId[iBlock];
00080         baseCells.push_back ( &lattices[foundBlock] -> get ( foundX[iBlock], foundY[iBlock] ) );
00081     }
00082     delete parallelDynamics;
00083     parallelDynamics = new ParallelDynamics<T,Descriptor>(baseCells, hasBulkCell);
00084     distributedCell.attributeDynamics(parallelDynamics);
00085     return distributedCell;
00086 }
00087 
00088 template<typename T, template<typename U> class Descriptor>
00089 Cell<T,Descriptor> const& ParallelCellAccess2D<T,Descriptor>::getDistributedCell (
00090         plint iX, plint iY,
00091         MultiBlockManagement2D const& multiBlockManagement,
00092         std::map<plint,BlockLattice2D<T,Descriptor>*> const& lattices ) const
00093 {
00094     std::vector<plint> foundId;
00095     std::vector<plint> foundX, foundY;
00096     bool hasBulkCell = multiBlockManagement.findAllLocalRepresentations(iX,iY, foundId, foundX, foundY);
00097     constBaseCells.clear();
00098     for (pluint iBlock=0; iBlock<foundId.size(); ++iBlock) {
00099         plint foundBlock = foundId[iBlock];
00100         typename std::map<plint,BlockLattice2D<T,Descriptor>*>::const_iterator it = lattices.find(foundBlock);
00101         constBaseCells.push_back ( &it->second -> get ( foundX[iBlock], foundY[iBlock] ) );
00102     }
00103     delete parallelDynamics;
00104     parallelDynamics = new ConstParallelDynamics<T,Descriptor>(constBaseCells, hasBulkCell);
00105     distributedCell.attributeDynamics(parallelDynamics);
00106     return distributedCell;
00107 }
00108 
00109 template<typename T, template<typename U> class Descriptor>
00110 ParallelCellAccess2D<T,Descriptor>* ParallelCellAccess2D<T,Descriptor>::clone() const {
00111     return new ParallelCellAccess2D<T,Descriptor>;
00112 }
00113 
00114 }  // namespace plb
00115 
00116 #endif  // PLB_MPI_PARALLEL
00117 
00118 #endif  // PARALLEL_MULTI_BLOCK_LATTICE_2D_HH