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

coProcessorCommunication3D.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 
00025 #ifndef CO_PROCESSOR_COMMUNICATION_3D_HH
00026 #define CO_PROCESSOR_COMMUNICATION_3D_HH
00027 
00028 #include "core/globalDefs.h"
00029 #include "coProcessors/coProcessorCommunication3D.h"
00030 #include "io/parallelIO.h"
00031 #include <iomanip>
00032 
00033 namespace plb {
00034 
00035 template<typename T, template<typename U> class Descriptor>
00036 void transferToCoProcessors(MultiBlockLattice3D<T,Descriptor>& lattice)
00037 {
00038     MultiBlockManagement3D const& management = lattice.getMultiBlockManagement();
00039     ThreadAttribution const& threadAttribution = management.getThreadAttribution();
00040     std::map<plint,Box3D> const& bulks = management.getSparseBlockStructure().getBulks();
00041 
00042     std::vector<char> data;
00043     for (pluint iBlock=0; iBlock<management.getLocalInfo().getBlocks().size(); ++iBlock) {
00044         plint blockId = management.getLocalInfo().getBlocks()[iBlock];
00045         plint handle = threadAttribution.getCoProcessorHandle(blockId);
00046         if (handle>=0) {
00047              BlockLattice3D<T,Descriptor>& component = lattice.getComponent(blockId);
00048              component.getDataTransfer().send (
00049                      component.getBoundingBox(), data, modif::staticVariables );
00050              global::defaultCoProcessor3D<T>().send (
00051                      handle, component.getBoundingBox(), data );
00052         }
00053     }
00054 
00055 }
00056 
00057 template<typename T, template<typename U> class Descriptor>
00058 void transferFromCoProcessors(MultiBlockLattice3D<T,Descriptor>& lattice)
00059 {
00060     MultiBlockManagement3D const& management = lattice.getMultiBlockManagement();
00061     ThreadAttribution const& threadAttribution = management.getThreadAttribution();
00062     std::map<plint,Box3D> const& bulks = management.getSparseBlockStructure().getBulks();
00063 
00064     std::vector<char> data;
00065     for (pluint iBlock=0; iBlock<management.getLocalInfo().getBlocks().size(); ++iBlock) {
00066         plint blockId = management.getLocalInfo().getBlocks()[iBlock];
00067         plint handle = threadAttribution.getCoProcessorHandle(blockId);
00068         if (handle>=0) {
00069              BlockLattice3D<T,Descriptor>& component = lattice.getComponent(blockId);
00070              global::defaultCoProcessor3D<T>().receive (
00071                      handle, component.getBoundingBox(), data );
00072              component.getDataTransfer().receive (
00073                      component.getBoundingBox(), data, modif::staticVariables );
00074         }
00075     }
00076 }
00077 
00078 template<typename T, template<typename U> class Descriptor>
00079 void initiateCoProcessors( MultiBlockLattice3D<T,Descriptor>& lattice,
00080                            plint dynamicsId, bool printInfo )
00081 {
00082     std::map<plint,PureDynamics<T> > dynamicsPattern
00083         = identifyBlocksWithPureDynamics(lattice, dynamicsId);
00084 
00085     if (printInfo) {
00086         typename std::map<plint,PureDynamics<T> >::const_iterator it = dynamicsPattern.begin();
00087         plint i=0;
00088         for (; it != dynamicsPattern.end(); ++it, ++i) {
00089             plint blockId = it->first;
00090             bool isPure = it->second.isPure;
00091             T omega = it->second.omega;
00092             if (isPure) {
00093                 pcout << std::setw(4) << blockId << ": (" << std::setw(8) << omega << "); ";
00094             }
00095             else {
00096                 pcout << std::setw(4) << blockId << ";       ";
00097             }
00098             if (i%6==0) pcout << std::endl;
00099         }
00100         pcout << std::endl;
00101     }
00102 
00103     MultiBlockManagement3D const& management = lattice.getMultiBlockManagement();
00104     ThreadAttribution const& threadAttribution = management.getThreadAttribution();
00105     std::map<plint,Box3D> const& bulks = management.getSparseBlockStructure().getBulks();
00106     std::map<plint, int> coprocessors;
00107     for (pluint iBlock=0; iBlock<management.getLocalInfo().getBlocks().size(); ++iBlock) {
00108         plint blockId = management.getLocalInfo().getBlocks()[iBlock];
00109 
00110         typename std::map<plint,PureDynamics<T> >::const_iterator itPure = dynamicsPattern.find(blockId);
00111         PLB_ASSERT( itPure!=dynamicsPattern.end() );
00112         bool isPure = itPure->second.isPure;
00113         T omega = itPure->second.omega;
00114         if (isPure) {
00115             SmartBulk3D smartBulk(management, blockId);
00116             Box3D domain(smartBulk.computeEnvelope());
00117             int handle;
00118             global::defaultCoProcessor3D<T>().addDomain (
00119                     domain.getNx(), domain.getNy(), domain.getNz(), omega, handle );
00120             coprocessors.insert(std::pair<plint,int>(blockId, handle));
00121         }
00122         else {
00123             coprocessors.insert(std::pair<plint,int>(blockId, -1));
00124         }
00125     }
00126     lattice.setCoProcessors(coprocessors);
00127 }
00128 
00129 }  // namespace plb
00130 
00131 #endif  // CO_PROCESSOR_COMMUNICATION_3D_HH
00132