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

defaultMultiBlockPolicy3D.h

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 DEFAULT_MULTI_BLOCK_POLICY_3D_H
00029 #define DEFAULT_MULTI_BLOCK_POLICY_3D_H
00030 
00031 #include "core/globalDefs.h"
00032 #include "parallelism/mpiManager.h"
00033 #include "multiBlock/serialBlockCommunicator3D.h"
00034 #include "parallelism/parallelBlockCommunicator3D.h"
00035 #include "multiBlock/combinedStatistics.h"
00036 #include "parallelism/parallelStatistics.h"
00037 #include "multiBlock/serialMultiBlockLattice3D.h"
00038 #include "parallelism/parallelMultiBlockLattice3D.h"
00039 #include "multiBlock/serialMultiDataField3D.h"
00040 #include "parallelism/parallelMultiDataField3D.h"
00041 #include "multiBlock/threadAttribution.h"
00042 #include "multiBlock/staticRepartitions3D.h"
00043 #include "multiBlock/multiBlockManagement3D.h"
00044 #include <cmath>
00045 
00046 namespace plb {
00047 
00048 class DefaultMultiBlockPolicy3D {
00049 public:
00050     void toggleBlockingCommunication(bool useBlockingCommunication_) {
00051         useBlockingCommunication = useBlockingCommunication_;
00052     }
00053 
00054     BlockCommunicator3D* getBlockCommunicator() {
00055 #ifdef PLB_MPI_PARALLEL
00056         if (useBlockingCommunication) {
00057             return new ParallelBlockCommunicator3D();
00058         }
00059         else {
00060             return new ParallelBlockCommunicator3D();
00061         }
00062 #else
00063         return new SerialBlockCommunicator3D();
00064 #endif
00065     }
00066 
00067     CombinedStatistics* getCombinedStatistics() {
00068 #ifdef PLB_MPI_PARALLEL
00069         return new ParallelCombinedStatistics();
00070 #else
00071         return new SerialCombinedStatistics();
00072 #endif
00073     }
00074 
00075     template<typename T, template<typename U> class Descriptor>
00076     MultiCellAccess3D<T,Descriptor>* getMultiCellAccess() {
00077 #ifdef PLB_MPI_PARALLEL
00078         return new ParallelCellAccess3D<T,Descriptor>();
00079 #else
00080         return new SerialCellAccess3D<T,Descriptor>();
00081 #endif
00082     }
00083 
00084     template<typename T>
00085     MultiScalarAccess3D<T>* getMultiScalarAccess() {
00086 #ifdef PLB_MPI_PARALLEL
00087         return new ParallelScalarAccess3D<T>();
00088 #else
00089         return new SerialScalarAccess3D<T>();
00090 #endif
00091     }
00092 
00093     template<typename T, int nDim>
00094     MultiTensorAccess3D<T,nDim>* getMultiTensorAccess() {
00095 #ifdef PLB_MPI_PARALLEL
00096         return new ParallelTensorAccess3D<T,nDim>();
00097 #else
00098         return new SerialTensorAccess3D<T,nDim>();
00099 #endif
00100     }
00101 
00102     template<typename T>
00103     MultiNTensorAccess3D<T>* getMultiNTensorAccess() {
00104 #ifdef PLB_MPI_PARALLEL
00105         return new ParallelNTensorAccess3D<T>();
00106 #else
00107         return new SerialNTensorAccess3D<T>();
00108 #endif
00109     }
00110 
00111     ThreadAttribution* getThreadAttribution() {
00112 #ifdef PLB_MPI_PARALLEL
00113         return new OneToOneThreadAttribution();
00114 #else
00115         return new SerialThreadAttribution();
00116 #endif
00117     }
00118 
00119     MultiBlockManagement3D getMultiBlockManagement(Box3D const& domain, plint envelopeWidth) {
00120         return MultiBlockManagement3D (
00121                 createRegularDistribution3D(domain, numProcesses),
00122                 getThreadAttribution(),
00123                 envelopeWidth );
00124     }
00125 
00126     MultiBlockManagement3D getMultiBlockManagement(plint nx, plint ny, plint nz, plint envelopeWidth) {
00127         return MultiBlockManagement3D (
00128                 createRegularDistribution3D(nx,ny,nz, numProcesses),
00129                 getThreadAttribution(),
00130                 envelopeWidth );
00131     }
00132 
00133     void setNumGridPoints(plint numGridPoints_) {
00134         numGridPoints = numGridPoints_;
00135         numGridPointsSpecified = true;
00136     }
00137 
00138     plint getNumGridPoints() const {
00139         return numGridPoints;
00140     }
00141 
00142     void setNumProcesses(int numProcesses_) {
00143         numProcesses = numProcesses_;
00144         if (!numGridPointsSpecified) {
00145             numGridPoints = numProcesses;
00146         }
00147     }
00148 
00149     int getNumProcesses() const {
00150         return numProcesses;
00151     }
00152 private:
00153     DefaultMultiBlockPolicy3D()
00154         : numProcesses(global::mpi().getSize()),
00155           numGridPointsSpecified(false),
00156           useBlockingCommunication(false)
00157     {
00158         numGridPoints = numProcesses;
00159     }
00160     friend DefaultMultiBlockPolicy3D& defaultMultiBlockPolicy3D();
00161 private:
00162     int numProcesses;
00163     plint numGridPoints;
00164     bool numGridPointsSpecified;
00165     bool useBlockingCommunication;
00166 };
00167 
00168 inline DefaultMultiBlockPolicy3D& defaultMultiBlockPolicy3D() {
00169     static DefaultMultiBlockPolicy3D singleton;
00170     return singleton;
00171 }
00172 
00173 }  // namespace plb
00174 
00175 #endif  //DEFAULT_MULTI_BLOCK_POLICY_3D_H