1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Wave propagation of information through grid. Every iteration
29 information goes through one layer of edges. Templated on information
32 Templated on information that is transferred.
33 Handles parallel and cyclics. Only parallel reasonably tested. Cyclics
36 Note: whether to propagate depends on the return value of Type::update
37 which returns true (i.e. propagate) if the value changes by more than a
40 Note: parallel is done in two steps:
41 -# transfer patch points in offset notation, i.e. every patch
42 point is denoted by a patchface label and an index in this face.
43 Receiving end uses that fact that f[0] is shared and order is
45 -# do all non-local shared points by means of reduce of data on them.
47 Note: cyclics is with offset in patchface as well. Patch is divided into
48 two sub patches and the point-point addressing is never explicitly
49 calculated but instead use is made of the face-face correspondence.
50 (it probably is more efficient to calculate a point-point
51 correspondence at the start and then reuse this; task to be done)
56 \*---------------------------------------------------------------------------*/
58 #ifndef PointEdgeWave_H
59 #define PointEdgeWave_H
63 #include "scalarField.H"
64 #include "pointFields.H"
66 #include "primitivePatch.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 // Forward declaration of classes
78 /*---------------------------------------------------------------------------*\
79 Class PointEdgeWaveName Declaration
80 \*---------------------------------------------------------------------------*/
82 TemplateName(PointEdgeWave);
85 /*---------------------------------------------------------------------------*\
86 Class PointEdgeWave Declaration
87 \*---------------------------------------------------------------------------*/
92 public PointEdgeWaveName
94 // Private static data
96 //- Relative tolerance. Stop propagation if relative changes
97 // less than this tolerance (responsability for checking this is
98 // up to Type implementation)
99 static scalar propagationTol_;
104 //- Reference to mesh
105 const polyMesh& mesh_;
107 //- Wall information for all points
108 List<Type>& allPointInfo_;
110 //- Information on all mesh edges
111 List<Type>& allEdgeInfo_;
113 //- Has point changed
114 boolList changedPoint_;
116 //- List of changed points
117 labelList changedPoints_;
119 //- Number of changed points
120 label nChangedPoints_;
122 //- Edges that have changed
123 boolList changedEdge_;
124 labelList changedEdges_;
125 label nChangedEdges_;
127 //- Number of cyclic patches
128 bool nCyclicPatches_;
130 //- Number of cyclic patches
133 //- For every cyclic patch two primitivePatches
134 PtrList<primitivePatch> cycHalves_;
136 //- Number of evaluations
139 //- Number of unvisited edges/points
140 label nUnvisitedPoints_;
141 label nUnvisitedEdges_;
144 // Private Member Functions
146 //- Add value to all elements of labelList
147 static void offset(const label val, labelList& elems);
150 //- Adapt pointInfo for leaving domain
153 const polyPatch& meshPatch,
154 const primitivePatch& patch,
155 const List<label>& patchPointLabels,
156 List<Type>& pointInfo
159 //- Adapt pointInfo for entering domain
162 const polyPatch& meshPatch,
163 const primitivePatch& patch,
164 const List<label>& patchPointLabels,
165 List<Type>& pointInfo
168 //- Transform. Implementation referred to Type
171 const tensorField& rotTensor,
172 List<Type>& pointInfo
175 //- Updates pointInfo with information from neighbour. Updates all
180 const label neighbourEdgeI,
181 const Type& neighbourInfo,
186 //- Updates pointInfo with information from same point. Updates all
191 const Type& neighbourInfo,
196 //- Updates edgeInfo with information from neighbour. Updates all
201 const label neighbourPointI,
202 const Type& neighbourInfo,
209 //- Has patches of certain type?
210 template <class PatchType>
211 label countPatchType() const;
213 //- Get info on patch points
214 void getChangedPatchPoints
216 const primitivePatch& patch,
217 DynamicList<Type>& patchInfo,
218 dynamicLabelList& patchPoints,
219 dynamicLabelList& owner,
220 dynamicLabelList& ownerIndex
223 //- Merge data from patch into overall data
224 void updateFromPatchInfo
226 const polyPatch& meshPatch,
227 const primitivePatch& patch,
228 const labelList& owner,
229 const labelList& ownerIndex,
230 List<Type>& patchInfo
233 //- Merge data from patch into overall data
234 void updateFromPatchInfo
236 const ggiPolyPatch& to,
237 const labelListList& addr,
238 const labelList& owner,
239 const labelList& ownerIndex,
240 List<Type>& patchInfo
243 //- Merge data from across processor boundaries
244 void handleProcPatches();
246 //- Calculate cyclic halves addressing.
247 void calcCyclicAddressing();
249 //- Merge data from across cyclic boundaries
250 void handleCyclicPatches();
252 //- Merge data from across cyclic boundaries
253 void handleGgiPatches();
256 //- Disallow default bitwise copy construct
257 PointEdgeWave(const PointEdgeWave&);
259 //- Disallow default bitwise assignment
260 void operator=(const PointEdgeWave&);
266 //- Access to tolerance
267 static scalar propagationTol()
269 return propagationTol_;
273 static void setPropagationTol(const scalar tol)
275 propagationTol_ = tol;
282 //- Construct from mesh, list of changed points with the Type
283 // for these points. Gets work arrays to operate on, one of size
284 // number of mesh points, the other number of mesh edges.
285 // Iterates until nothing changes or maxIter reached.
286 // (maxIter can be 0)
289 const polyMesh& mesh,
290 const labelList& initialPoints,
291 const List<Type>& initialPointsInfo,
292 List<Type>& allPointInfo,
293 List<Type>& allEdgeInfo,
306 const List<Type>& allPointInfo() const
308 return allPointInfo_;
312 const List<Type>& allEdgeInfo() const
317 //- Get number of unvisited edges, i.e. edges that were not (yet)
318 // reached from walking across mesh. This can happen from
319 // - not enough iterations done
320 // - a disconnected mesh
321 // - a mesh without walls in it
322 label getUnsetEdges() const;
324 label getUnsetPoints() const;
326 //- Copy initial data into allPointInfo_
329 const labelList& changedPoints,
330 const List<Type>& changedPointsInfo
333 //- Propagate from point to edge. Returns total number of edges
334 // (over all processors) changed.
337 //- Propagate from edge to point. Returns total number of points
338 // (over all processors) changed.
341 //- Iterate until no changes or maxIter reached. Returns actual
342 // number of iterations.
343 label iterate(const label maxIter);
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 /*---------------------------------------------------------------------------*\
350 Class listUpdateOp Declaration
351 \*---------------------------------------------------------------------------*/
353 //- List update operation
354 template <class Type>
360 void operator()(List<Type>& x, const List<Type>& y) const
364 x[i].updatePoint(y[i], PointEdgeWave<Type>::propagationTol());
370 //- List update operation
371 template <class Type>
377 void operator()(List<Type>& x, const List<Type>& y) const
383 } // End namespace Foam
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 # include "PointEdgeWave.C"
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 // ************************************************************************* //