sampledPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sampledPatch.H"
30 #include "dictionary.H"
31 #include "polyMesh.H"
32 #include "polyPatch.H"
33 #include "volFields.H"
34 #include "surfaceFields.H"
35 
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42  defineTypeNameAndDebug(sampledPatch, 0);
43  addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const word& name,
52  const polyMesh& mesh,
54  const bool triangulate
55 )
56 :
58  patchNames_(patchNames),
59  triangulate_(triangulate),
60  needsUpdate_(true)
61 {}
62 
63 
65 (
66  const word& name,
67  const polyMesh& mesh,
68  const dictionary& dict
69 )
70 :
72  patchNames_(dict.get<wordRes>("patches")),
73  triangulate_(dict.lookupOrDefault("triangulate", false)),
74  needsUpdate_(true)
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
82  if (patchIDs_.empty())
83  {
84  patchIDs_ = mesh().boundaryMesh().patchSet(patchNames_).sortedToc();
85  }
86  return patchIDs_;
87 }
88 
89 
91 {
92  return needsUpdate_;
93 }
94 
95 
97 {
98  // already marked as expired
99  if (needsUpdate_)
100  {
101  return false;
102  }
103 
106  patchIDs_.clear();
107  patchIndex_.clear();
108  patchFaceLabels_.clear();
109  patchStart_.clear();
110 
111  needsUpdate_ = true;
112  return true;
113 }
114 
115 
117 {
118  if (!needsUpdate_)
119  {
120  return false;
121  }
122 
123  label sz = 0;
124  for (const label patchi : patchIDs())
125  {
126  const polyPatch& pp = mesh().boundaryMesh()[patchi];
127 
128  if (isA<emptyPolyPatch>(pp))
129  {
131  << "Cannot sample an empty patch. Patch " << pp.name()
132  << exit(FatalError);
133  }
134 
135  sz += pp.size();
136  }
137 
138  // For every face (or triangle) the originating patch and local face in the
139  // patch.
140  patchIndex_.setSize(sz);
141  patchFaceLabels_.setSize(sz);
142  patchStart_.setSize(patchIDs().size());
143  labelList meshFaceLabels(sz);
144 
145  sz = 0;
146 
147  forAll(patchIDs(), i)
148  {
149  const label patchi = patchIDs()[i];
150 
151  patchStart_[i] = sz;
152 
153  const polyPatch& pp = mesh().boundaryMesh()[patchi];
154 
155  forAll(pp, j)
156  {
157  patchIndex_[sz] = i;
158  patchFaceLabels_[sz] = j;
159  meshFaceLabels[sz] = pp.start()+j;
160  ++sz;
161  }
162  }
163 
164  indirectPrimitivePatch allPatches
165  (
166  IndirectList<face>(mesh().faces(), meshFaceLabels),
167  mesh().points()
168  );
169 
170  this->storedPoints() = allPatches.localPoints();
171  this->storedFaces() = allPatches.localFaces();
172 
173 
174  // triangulate uses remapFaces()
175  // - this is somewhat less efficient since it recopies the faces
176  // that we just created, but we probably don't want to do this
177  // too often anyhow.
178  if (triangulate_)
179  {
180  MeshStorage::triangulate();
181  }
182 
183  if (debug)
184  {
185  print(Pout);
186  Pout<< endl;
187  }
188 
189  needsUpdate_ = false;
190  return true;
191 }
192 
193 
194 // remap action on triangulation
195 void Foam::sampledPatch::remapFaces(const labelUList& faceMap)
196 {
197  // Recalculate the cells cut
198  if (!faceMap.empty())
199  {
200  MeshStorage::remapFaces(faceMap);
201  patchFaceLabels_ = labelList
202  (
203  labelUIndList(patchFaceLabels_, faceMap)
204  );
205  patchIndex_ = labelList
206  (
207  labelUIndList(patchIndex_, faceMap)
208  );
209 
210  // Redo patchStart.
211  if (patchIndex_.size() > 0)
212  {
213  patchStart_[patchIndex_[0]] = 0;
214  for (label i = 1; i < patchIndex_.size(); i++)
215  {
216  if (patchIndex_[i] != patchIndex_[i-1])
217  {
218  patchStart_[patchIndex_[i]] = i;
219  }
220  }
221  }
222  }
223 }
224 
225 
227 (
228  const interpolation<scalar>& sampler
229 ) const
230 {
231  return sampleOnFaces(sampler);
232 }
233 
234 
236 (
237  const interpolation<vector>& sampler
238 ) const
239 {
240  return sampleOnFaces(sampler);
241 }
242 
243 
245 (
246  const interpolation<sphericalTensor>& sampler
247 ) const
248 {
249  return sampleOnFaces(sampler);
250 }
251 
252 
254 (
255  const interpolation<symmTensor>& sampler
256 ) const
257 {
258  return sampleOnFaces(sampler);
259 }
260 
261 
263 (
264  const interpolation<tensor>& sampler
265 ) const
266 {
267  return sampleOnFaces(sampler);
268 }
269 
270 
272 {
273  return true;
274 }
275 
276 
278 (
279  const surfaceScalarField& sField
280 ) const
281 {
282  return sampleOnFaces(sField);
283 }
284 
285 
287 (
288  const surfaceVectorField& sField
289 ) const
290 {
291  return sampleOnFaces(sField);
292 }
293 
294 
296 (
297  const surfaceSphericalTensorField& sField
298 ) const
299 {
300  return sampleOnFaces(sField);
301 }
302 
303 
305 (
306  const surfaceSymmTensorField& sField
307 ) const
308 {
309  return sampleOnFaces(sField);
310 }
311 
312 
314 (
315  const surfaceTensorField& sField
316 ) const
317 {
318  return sampleOnFaces(sField);
319 }
320 
321 
323 (
324  const interpolation<scalar>& interpolator
325 ) const
326 {
327  return sampleOnPoints(interpolator);
328 }
329 
330 
332 (
333  const interpolation<vector>& interpolator
334 ) const
335 {
336  return sampleOnPoints(interpolator);
337 }
338 
339 
341 (
342  const interpolation<sphericalTensor>& interpolator
343 ) const
344 {
345  return sampleOnPoints(interpolator);
346 }
347 
348 
350 (
351  const interpolation<symmTensor>& interpolator
352 ) const
353 {
354  return sampleOnPoints(interpolator);
355 }
356 
357 
359 (
360  const interpolation<tensor>& interpolator
361 ) const
362 {
363  return sampleOnPoints(interpolator);
364 }
365 
366 
368 {
369  os << "sampledPatch: " << name() << " :"
370  << " patches:" << patchNames()
371  << " faces:" << faces().size()
372  << " points:" << points().size();
373 }
374 
375 
376 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
volFields.H
sampledPatch.H
Foam::sampledPatch::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPatch.C:90
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::sampledPatch::patchIDs
const labelList & patchIDs() const
Definition: sampledPatch.C:80
polyPatch.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:458
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceFields.H
Foam::surfaceFields.
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::sampledPatch::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample boundary of volume field onto surface faces.
Definition: sampledPatch.C:227
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::sampledPatch::print
virtual void print(Ostream &) const
Write.
Definition: sampledPatch.C:367
Foam::sampledPatch::withSurfaceFields
virtual bool withSurfaceFields() const
Can it sample surface-fields?
Definition: sampledPatch.C:271
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::sampledPatch::sampledPatch
sampledPatch(const word &name, const polyMesh &mesh, const UList< wordRe > &patchNames, const bool triangulate=false)
Construct from components.
Definition: sampledPatch.C:50
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:56
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
patchNames
wordList patchNames(nPatches)
Foam::interpolation< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:311
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::sampledPatch::update
virtual bool update()
Update the surface as required.
Definition: sampledPatch.C:116
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
clear
patchWriters clear()
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::BitOps::print
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Definition: BitOps.H:172
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::sampledPatch::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPatch.C:96
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::polyBoundaryMesh::patchSet
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
Definition: polyBoundaryMesh.C:857
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:55
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatch.C:398
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::patchIdentifier::name
const word & name() const
Return the patch name.
Definition: patchIdentifier.H:109
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90
Foam::labelUIndList
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: UIndirectList.H:59