$treeview $search $mathjax
|
Palabos
Version 1.1
$projectbrief
|
$projectbrief
|
$searchbox |
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 /* Main author: Daniel Lagrava 00026 */ 00027 00032 #ifndef COARSE_GRID_PROCESSORS_2D_HH 00033 #define COARSE_GRID_PROCESSORS_2D_HH 00034 00035 #include "multiGrid/coarseGridProcessors2D.h" 00036 00037 namespace plb { 00038 00039 /* *************** Class CopyFineToCoarse2D ********************************* */ 00040 00041 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00042 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::CopyFineToCoarse2D ( 00043 RescaleEngine<T,Descriptor1>* rescaleEngine_, plint numTimeSteps_, plint executionTime_, 00044 plint direction_, plint orientation_) 00045 : rescaleEngine(rescaleEngine_), 00046 numTimeSteps(numTimeSteps_), 00047 executionTime(executionTime_), 00048 direction(direction_), 00049 orientation(orientation_) 00050 { } 00051 00052 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00053 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::~CopyFineToCoarse2D() { 00054 delete rescaleEngine; 00055 } 00056 00057 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00058 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::CopyFineToCoarse2D(CopyFineToCoarse2D<T,Descriptor1,Descriptor2> const& 00059 rhs) 00060 : rescaleEngine(rhs.rescaleEngine->clone()), 00061 numTimeSteps(rhs.numTimeSteps), 00062 executionTime(rhs.executionTime), 00063 direction(rhs.direction), 00064 orientation(rhs.orientation) 00065 { } 00066 00067 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00068 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>& CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::operator= ( 00069 CopyFineToCoarse2D<T,Descriptor1,Descriptor2> const& rhs ) 00070 { 00071 delete rescaleEngine; 00072 rescaleEngine = rhs.rescaleEngine->clone(); 00073 numTimeSteps = rhs.numTimeSteps; 00074 executionTime = rhs.executionTime; 00075 direction = rhs.direction; 00076 orientation = rhs.orientation; 00077 } 00078 00079 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00080 void CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::process ( 00081 Box2D fineDomain, 00082 BlockLattice2D<T,Descriptor1>& fineLattice, 00083 BlockLattice2D<T,Descriptor2>& coarseLattice ) 00084 { 00085 PLB_PRECONDITION( fineDomain.x0==fineDomain.x1 || 00086 fineDomain.y0==fineDomain.y1 ); 00087 00088 // Determine current relative value of time steps 00089 size_t relativeTime = fineLattice.getTimeCounter().getTime()%numTimeSteps; 00090 00091 // Execute data processor only if one is at the end of a cycle (iT=1) 00092 if ((plint)relativeTime==executionTime) { 00093 Dot2D posFine = fineLattice.getLocation(); // Position of fine grid in multi block. 00094 Dot2D posCoarse = coarseLattice.getLocation(); // Position of coarse grid in multi block. 00095 00096 Box2D coarseDomain ( 00097 fineDomain.shift(posFine.x,posFine.y). // Convert to absolute fine coordinates. 00098 divideAndFitSmaller(2). // Rescale, but don't exceed original domain. 00099 shift(-posCoarse.x,-posCoarse.y) ); // Convert to relative coarse coordinates. 00100 std::vector<T> decomposedCoarseValues; 00101 00102 // Loop over coarse lattice 00103 for (plint iX=coarseDomain.x0; iX<=coarseDomain.x1; ++iX) { 00104 for (plint iY=coarseDomain.y0; iY<=coarseDomain.y1; ++iY) { 00105 // Determine corresonding coordinates on fine lattice 00106 plint fineX = (iX+posCoarse.x)*2 - posFine.x; 00107 plint fineY = (iY+posCoarse.y)*2 - posFine.y; 00108 Cell<T,Descriptor1>& coarseCell = coarseLattice.get(iX,iY); 00109 Cell<T,Descriptor2> const& fineCell = fineLattice.get(fineX,fineY); 00110 00111 rescaleEngine->scaleFineCoarse(fineCell, decomposedCoarseValues); 00112 rescaleEngine->recompose(coarseCell, decomposedCoarseValues); 00113 } 00114 } 00115 } 00116 } 00117 00118 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00119 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>* 00120 CopyFineToCoarse2D<T,Descriptor1,Descriptor2>::clone() const 00121 { 00122 return new CopyFineToCoarse2D(*this); 00123 } 00124 00125 /* *************** Class CopyFineToCoarseWithFiltering2D ********************************* */ 00126 00127 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00128 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::CopyFineToCoarseWithFiltering2D ( 00129 RescaleEngine<T,Descriptor1>* rescaleEngine_, plint numTimeSteps_, plint executionTime_, 00130 plint direction_, plint orientation_) 00131 : rescaleEngine(rescaleEngine_), 00132 numTimeSteps(numTimeSteps_), 00133 executionTime(executionTime_), 00134 direction(direction_), 00135 orientation(orientation_) 00136 { } 00137 00138 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00139 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::~CopyFineToCoarseWithFiltering2D() { 00140 delete rescaleEngine; 00141 } 00142 00143 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00144 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::CopyFineToCoarseWithFiltering2D(CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2> const& 00145 rhs) 00146 : rescaleEngine(rhs.rescaleEngine->clone()), 00147 numTimeSteps(rhs.numTimeSteps), 00148 executionTime(rhs.executionTime), 00149 direction(rhs.direction), 00150 orientation(rhs.orientation) 00151 { } 00152 00153 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00154 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>& CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::operator= ( 00155 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2> const& rhs ) 00156 { 00157 delete rescaleEngine; 00158 rescaleEngine = rhs.rescaleEngine->clone(); 00159 numTimeSteps = rhs.numTimeSteps; 00160 executionTime = rhs.executionTime; 00161 direction = rhs.direction; 00162 orientation = rhs.orientation; 00163 } 00164 00165 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00166 void CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::process ( 00167 Box2D fineDomain, 00168 BlockLattice2D<T,Descriptor1>& fineLattice, 00169 BlockLattice2D<T,Descriptor2>& coarseLattice ) 00170 { 00171 PLB_PRECONDITION( fineDomain.x0==fineDomain.x1 || 00172 fineDomain.y0==fineDomain.y1 ); 00173 00174 // Determine current relative value of time steps 00175 size_t relativeTime = fineLattice.getTimeCounter().getTime()%numTimeSteps; 00176 00177 // Execute data processor only if one is at the end of a cycle (iT=1) 00178 if ((plint)relativeTime==executionTime) { 00179 Dot2D posFine = fineLattice.getLocation(); // Position of fine grid in multi block. 00180 Dot2D posCoarse = coarseLattice.getLocation(); // Position of coarse grid in multi block. 00181 00182 Box2D coarseDomain ( 00183 fineDomain.shift(posFine.x,posFine.y). // Convert to absolute fine coordinates. 00184 divideAndFitSmaller(2). // Rescale, but don't exceed original domain. 00185 shift(-posCoarse.x,-posCoarse.y) ); // Convert to relative coarse coordinates. 00186 std::vector<T> decomposedCoarseValues; 00187 00188 plint start = (plint)1+Descriptor1<T>::d; 00189 // Loop over coarse lattice 00190 for (plint iX=coarseDomain.x0; iX<=coarseDomain.x1; ++iX) { 00191 for (plint iY=coarseDomain.y0; iY<=coarseDomain.y1; ++iY) { 00192 // Determine corresponding coordinates on fine lattice 00193 plint fineX = (iX+posCoarse.x)*2 - posFine.x; 00194 plint fineY = (iY+posCoarse.y)*2 - posFine.y; 00195 Cell<T,Descriptor1>& coarseCell = coarseLattice.get(iX,iY); 00196 Cell<T,Descriptor2> const& fineCell = fineLattice.get(fineX,fineY); 00197 00198 rescaleEngine->scaleFineCoarse(fineCell, decomposedCoarseValues); 00199 00200 for (plint iPop = 1; iPop < Descriptor2<T>::q; ++iPop) { 00201 std::vector<T> tmpDec; 00202 Cell<T,Descriptor2> const& nextCell = 00203 fineLattice.get(fineX+Descriptor2<T>::c[iPop][0],fineY+Descriptor2<T>::c[iPop][1]); 00204 00205 rescaleEngine->scaleFineCoarse(nextCell, tmpDec); 00206 for (pluint iA = start; iA < tmpDec.size(); ++iA) { 00207 decomposedCoarseValues[iA] += tmpDec[iA]; 00208 } 00209 } 00210 for (pluint iA = start; iA < decomposedCoarseValues.size(); ++iA) { 00211 decomposedCoarseValues[iA] /= (T)Descriptor2<T>::q; 00212 } 00213 00214 rescaleEngine->recompose(coarseCell, decomposedCoarseValues); 00215 } 00216 } 00217 } 00218 } 00219 00220 template<typename T, template<typename U> class Descriptor1, template<typename U> class Descriptor2> 00221 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>* 00222 CopyFineToCoarseWithFiltering2D<T,Descriptor1,Descriptor2>::clone() const 00223 { 00224 return new CopyFineToCoarseWithFiltering2D(*this); 00225 } 00226 00227 00228 00229 } // namespace plb 00230 00231 #endif // COARSE_GRID_PROCESSORS_2D_HH
1.6.3
1.6.3