00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::PointEdgeWave 00026 00027 Description 00028 Wave propagation of information through grid. Every iteration 00029 information goes through one layer of edges. Templated on information 00030 that is transferred. 00031 00032 Templated on information that is transferred. 00033 Handles parallel and cyclics. Only parallel reasonably tested. Cyclics 00034 hardly tested. 00035 00036 Note: whether to propagate depends on the return value of Type::update 00037 which returns true (i.e. propagate) if the value changes by more than a 00038 certain tolerance. 00039 00040 Note: parallel is done in two steps: 00041 -# transfer patch points in offset notation, i.e. every patch 00042 point is denoted by a patchface label and an index in this face. 00043 Receiving end uses that fact that f[0] is shared and order is 00044 reversed. 00045 -# do all non-local shared points by means of reduce of data on them. 00046 00047 Note: cyclics is with offset in patchface as well. Patch is divided into 00048 two sub patches and the point-point addressing is never explicitly 00049 calculated but instead use is made of the face-face correspondence. 00050 (it probably is more efficient to calculate a point-point 00051 correspondence at the start and then reuse this; task to be done) 00052 00053 SourceFiles 00054 PointEdgeWave.C 00055 00056 \*---------------------------------------------------------------------------*/ 00057 00058 #ifndef PointEdgeWave_H 00059 #define PointEdgeWave_H 00060 00061 #include <OpenFOAM/label.H> 00062 #include <OpenFOAM/boolList.H> 00063 #include <OpenFOAM/scalarField.H> 00064 #include <OpenFOAM/pointFields.H> 00065 #include <OpenFOAM/tensor.H> 00066 #include <OpenFOAM/primitivePatch.H> 00067 #include <OpenFOAM/PtrList.H> 00068 00069 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00070 00071 namespace Foam 00072 { 00073 00074 // Forward declaration of classes 00075 class polyMesh; 00076 00077 00078 /*---------------------------------------------------------------------------*\ 00079 Class PointEdgeWaveName Declaration 00080 \*---------------------------------------------------------------------------*/ 00081 00082 TemplateName(PointEdgeWave); 00083 00084 00085 /*---------------------------------------------------------------------------*\ 00086 Class PointEdgeWave Declaration 00087 \*---------------------------------------------------------------------------*/ 00088 00089 template <class Type> 00090 class PointEdgeWave 00091 : 00092 public PointEdgeWaveName 00093 { 00094 // Private static data 00095 00096 //- Relative tolerance. Stop propagation if relative changes 00097 // less than this tolerance (responsability for checking this is 00098 // up to Type implementation) 00099 static scalar propagationTol_; 00100 00101 00102 // Private data 00103 00104 //- Reference to mesh 00105 const polyMesh& mesh_; 00106 00107 //- Wall information for all points 00108 List<Type>& allPointInfo_; 00109 00110 //- Information on all mesh edges 00111 List<Type>& allEdgeInfo_; 00112 00113 //- Has point changed 00114 boolList changedPoint_; 00115 00116 //- List of changed points 00117 labelList changedPoints_; 00118 00119 //- Number of changed points 00120 label nChangedPoints_; 00121 00122 //- Edges that have changed 00123 boolList changedEdge_; 00124 labelList changedEdges_; 00125 label nChangedEdges_; 00126 00127 //- Number of cyclic patches 00128 label nCyclicPatches_; 00129 00130 //- For every cyclic patch two primitivePatches 00131 PtrList<primitivePatch> cycHalves_; 00132 00133 //- Number of evaluations 00134 label nEvals_; 00135 00136 //- Number of unvisited edges/points 00137 label nUnvisitedPoints_; 00138 label nUnvisitedEdges_; 00139 00140 00141 // Private Member Functions 00142 00143 //- Add value to all elements of labelList 00144 static void offset(const label val, labelList& elems); 00145 00146 00147 //- Adapt pointInfo for leaving domain 00148 void leaveDomain 00149 ( 00150 const polyPatch& meshPatch, 00151 const primitivePatch& patch, 00152 const List<label>& patchPointLabels, 00153 List<Type>& pointInfo 00154 ) const; 00155 00156 //- Adapt pointInfo for entering domain 00157 void enterDomain 00158 ( 00159 const polyPatch& meshPatch, 00160 const primitivePatch& patch, 00161 const List<label>& patchPointLabels, 00162 List<Type>& pointInfo 00163 ) const; 00164 00165 //- Transform. Implementation referred to Type 00166 void transform 00167 ( 00168 const tensorField& rotTensor, 00169 List<Type>& pointInfo 00170 ) const; 00171 00172 //- Updates pointInfo with information from neighbour. Updates all 00173 // statistics. 00174 bool updatePoint 00175 ( 00176 const label pointI, 00177 const label neighbourEdgeI, 00178 const Type& neighbourInfo, 00179 const scalar tol, 00180 Type& pointInfo 00181 ); 00182 00183 //- Updates pointInfo with information from same point. Updates all 00184 // statistics. 00185 bool updatePoint 00186 ( 00187 const label pointI, 00188 const Type& neighbourInfo, 00189 const scalar tol, 00190 Type& pointInfo 00191 ); 00192 00193 //- Updates edgeInfo with information from neighbour. Updates all 00194 // statistics. 00195 bool updateEdge 00196 ( 00197 const label edgeI, 00198 const label neighbourPointI, 00199 const Type& neighbourInfo, 00200 const scalar tol, 00201 Type& edgeInfo 00202 ); 00203 00204 // Parallel, cyclic 00205 00206 //- Has patches of certain type? 00207 template <class PatchType> 00208 label countPatchType() const; 00209 00210 //- Get info on patch points 00211 void getChangedPatchPoints 00212 ( 00213 const primitivePatch& patch, 00214 DynamicList<Type>& patchInfo, 00215 DynamicList<label>& patchPoints, 00216 DynamicList<label>& owner, 00217 DynamicList<label>& ownerIndex 00218 ) const; 00219 00220 //- Merge data from patch into overall data 00221 void updateFromPatchInfo 00222 ( 00223 const polyPatch& meshPatch, 00224 const primitivePatch& patch, 00225 const labelList& owner, 00226 const labelList& ownerIndex, 00227 List<Type>& patchInfo 00228 ); 00229 00230 //- Merge data from across processor boundaries 00231 void handleProcPatches(); 00232 00233 //- Calculate cyclic halves addressing. 00234 void calcCyclicAddressing(); 00235 00236 //- Merge data from across cyclic boundaries 00237 void handleCyclicPatches(); 00238 00239 00240 //- Disallow default bitwise copy construct 00241 PointEdgeWave(const PointEdgeWave&); 00242 00243 //- Disallow default bitwise assignment 00244 void operator=(const PointEdgeWave&); 00245 00246 public: 00247 00248 // Static Functions 00249 00250 //- Access to tolerance 00251 static scalar propagationTol() 00252 { 00253 return propagationTol_; 00254 } 00255 00256 //- Change tolerance 00257 static void setPropagationTol(const scalar tol) 00258 { 00259 propagationTol_ = tol; 00260 } 00261 00262 00263 00264 // Constructors 00265 00266 //- Construct from mesh, list of changed points with the Type 00267 // for these points. Gets work arrays to operate on, one of size 00268 // number of mesh points, the other number of mesh edges. 00269 // Iterates until nothing changes or maxIter reached. 00270 // (maxIter can be 0) 00271 PointEdgeWave 00272 ( 00273 const polyMesh& mesh, 00274 const labelList& initialPoints, 00275 const List<Type>& initialPointsInfo, 00276 List<Type>& allPointInfo, 00277 List<Type>& allEdgeInfo, 00278 const label maxIter 00279 ); 00280 00281 00282 // Destructor 00283 00284 ~PointEdgeWave(); 00285 00286 00287 // Member Functions 00288 00289 //- Get allPointInfo 00290 const List<Type>& allPointInfo() const 00291 { 00292 return allPointInfo_; 00293 } 00294 00295 //- Get allEdgeInfo 00296 const List<Type>& allEdgeInfo() const 00297 { 00298 return allEdgeInfo_; 00299 } 00300 00301 //- Get number of unvisited edges, i.e. edges that were not (yet) 00302 // reached from walking across mesh. This can happen from 00303 // - not enough iterations done 00304 // - a disconnected mesh 00305 // - a mesh without walls in it 00306 label getUnsetEdges() const; 00307 00308 label getUnsetPoints() const; 00309 00310 //- Copy initial data into allPointInfo_ 00311 void setPointInfo 00312 ( 00313 const labelList& changedPoints, 00314 const List<Type>& changedPointsInfo 00315 ); 00316 00317 //- Propagate from point to edge. Returns total number of edges 00318 // (over all processors) changed. 00319 label pointToEdge(); 00320 00321 //- Propagate from edge to point. Returns total number of points 00322 // (over all processors) changed. 00323 label edgeToPoint(); 00324 00325 //- Iterate until no changes or maxIter reached. Returns actual 00326 // number of iterations. 00327 label iterate(const label maxIter); 00328 }; 00329 00330 00331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00332 00333 /*---------------------------------------------------------------------------*\ 00334 Class listUpdateOp Declaration 00335 \*---------------------------------------------------------------------------*/ 00336 00337 //- List update operation 00338 template <class Type> 00339 class listUpdateOp 00340 { 00341 00342 public: 00343 00344 void operator()(List<Type>& x, const List<Type>& y) const 00345 { 00346 forAll(x, i) 00347 { 00348 x[i].updatePoint(y[i], PointEdgeWave<Type>::propagationTol()); 00349 } 00350 } 00351 }; 00352 00353 } // End namespace Foam 00354 00355 00356 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00357 00358 #ifdef NoRepository 00359 # include "PointEdgeWave.C" 00360 #endif 00361 00362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00363 00364 #endif 00365 00366 // ************************ vim: set sw=4 sts=4 et: ************************ //