1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 Foam::directMappedPatchBase
28 Determines a mapping between patch face centres and mesh cell or face
29 centres and processors they're on.
31 If constructed from dictionary:
32 // Region to sample (default is region0)
36 // - nearestCell : sample nearest cell
37 // - nearestPatchFace : nearest face on selected patch
38 // - nearestFace : nearest boundary face on any patch
39 sampleMode nearestCell;
41 // If sampleMod is nearestPatchFace : patch to find faces of
42 samplePatch movingWall;
44 // How to supply offset (w.r.t. my patch face centres):
45 // - uniform : single offset vector
46 // - nonuniform : per-face offset vector
47 // - normal : using supplied distance and face normal
50 // According to offsetMode (see above) supply one of
51 // offset, offsets or distance
54 Note: if offsetMode is 'normal' it uses outwards pointing normals. So
55 supply a negative distance if sampling inside the domain.
59 Storage is not optimal. It temporary collects all (patch)face centres
60 on all processors to keep the addressing calculation simple.
63 directMappedPatchBase.C
65 \*---------------------------------------------------------------------------*/
67 #ifndef directMappedPatchBase_H
68 #define directMappedPatchBase_H
70 #include "pointField.H"
72 #include "pointIndexHit.H"
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
83 /*---------------------------------------------------------------------------*\
84 Class directMappedPatchBase Declaration
85 \*---------------------------------------------------------------------------*/
87 class directMappedPatchBase
92 //- Mesh items to sample
95 NEARESTCELL, // nearest cell
96 NEARESTPATCHFACE, // faces on selected patch
97 NEARESTFACE // nearest face
100 //- How to project face centres
103 UNIFORM, // single offset vector
104 NONUNIFORM, // per-face offset vector
105 NORMAL // use face normal + distance
108 static const NamedEnum<sampleMode, 3> sampleModeNames_;
110 static const NamedEnum<offsetMode, 3> offsetModeNames_;
113 //- Helper class for finding nearest
115 // - point+local index
118 typedef Tuple2<pointIndexHit, Tuple2<scalar, label> > nearInfo;
125 void operator()(nearInfo& x, const nearInfo& y) const
129 if (!x.first().hit())
133 else if (y.second().first() < x.second().first())
147 const polyPatch& patch_;
150 const word sampleRegion_;
153 const sampleMode mode_;
155 //- Patch (only if NEARESTPATCHFACE)
156 const word samplePatch_;
158 //- How to obtain samples
159 offsetMode offsetMode_;
161 //- Offset vector (uniform)
164 //- Offset vector (nonuniform)
165 vectorField offsets_;
167 //- Offset distance (normal)
171 const bool sameRegion_;
174 // Derived information
176 //- Communication schedule:
177 // - Cells/faces to sample per processor
178 // - Patch faces to receive per processor
180 mutable autoPtr<mapDistribute> mapPtr_;
183 // Private Member Functions
185 //- Collect single list of samples and originating processor+face.
189 labelList& patchFaceProcs,
190 labelList& patchFaces,
194 //- Find cells/faces containing samples
198 labelList& sampleProcs, // processor containing sample
199 labelList& sampleIndices, // local index of cell/face
200 pointField& sampleLocations // actual representative location
203 //- Calculate matching
204 void calcMapping() const;
209 //- Runtime type information
210 TypeName("directMappedPatchBase");
215 //- Construct from patch
216 directMappedPatchBase(const polyPatch&);
218 //- Construct with offsetMode=non-uniform
219 directMappedPatchBase
222 const word& sampleRegion,
223 const sampleMode sampleMode,
224 const word& samplePatch,
225 const vectorField& offsets
228 //- Construct from offsetMode=uniform
229 directMappedPatchBase
232 const word& sampleRegion,
233 const sampleMode sampleMode,
234 const word& samplePatch,
238 //- Construct from offsetMode=normal and distance
239 directMappedPatchBase
242 const word& sampleRegion,
243 const sampleMode sampleMode,
244 const word& samplePatch,
245 const scalar distance
248 //- Construct from dictionary
249 directMappedPatchBase(const polyPatch&, const dictionary&);
251 //- Construct as copy, resetting patch
252 directMappedPatchBase(const polyPatch&, const directMappedPatchBase&);
254 //- Construct as copy, resetting patch, map original data
255 directMappedPatchBase
258 const directMappedPatchBase&,
259 const labelUList& mapAddressing
264 virtual ~directMappedPatchBase();
272 const sampleMode& mode() const
278 const word& sampleRegion() const
280 return sampleRegion_;
283 //- Patch (only if NEARESTPATCHFACE)
284 const word& samplePatch() const
289 //- Offset vector (from patch faces to destination mesh objects)
290 const vector& offset() const
295 //- Offset vector (from patch faces to destination mesh objects)
296 const vectorField& offsets() const
301 //- Return reference to the parallel distribution map
302 const mapDistribute& map() const
311 //- Cached sampleRegion != mesh.name()
312 bool sameRegion() const
317 //- Get the region mesh
318 const polyMesh& sampleMesh() const;
320 //- Get the patch on the region
321 const polyPatch& samplePolyPatch() const;
323 //- Get the sample points
324 tmp<pointField> samplePoints() const;
326 //- Write as a dictionary
327 virtual void write(Ostream&) const;
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 } // End namespace Foam
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 // ************************************************************************* //