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-2021 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"
36 
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(sampledPatch, 0);
44  addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch);
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const word& name,
53  const polyMesh& mesh,
55  const bool triangulate
56 )
57 :
59  selectionNames_(patchNames),
60  triangulate_(triangulate),
61  needsUpdate_(true)
62 {}
63 
64 
66 (
67  const word& name,
68  const polyMesh& mesh,
69  const dictionary& dict
70 )
71 :
73  selectionNames_(dict.get<wordRes>("patches")),
74  triangulate_(dict.getOrDefault("triangulate", false)),
75  needsUpdate_(true)
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (patchIDs_.empty())
84  {
85  labelList selected
86  (
87  mesh().boundaryMesh().patchSet(selectionNames_).sortedToc()
88  );
89 
91  for (const label patchi : selected)
92  {
93  const polyPatch& pp = mesh().boundaryMesh()[patchi];
94 
95  if (isA<emptyPolyPatch>(pp))
96  {
97  bad.append(patchi);
98  }
99  }
100 
101  if (bad.size())
102  {
103  label nGood = (selected.size() - bad.size());
104 
105  auto& os = nGood > 0 ? WarningInFunction : FatalErrorInFunction;
106 
107  os << "Cannot sample an empty patch" << nl;
108 
109  for (const label patchi : bad)
110  {
111  os << " "
112  << mesh().boundaryMesh()[patchi].name() << nl;
113  }
114 
115  if (nGood)
116  {
117  os << "No non-empty patches selected" << endl
118  << exit(FatalError);
119  }
120  else
121  {
122  os << "Selected " << nGood << " non-empty patches" << nl;
123  }
124 
125  patchIDs_.resize(nGood);
126  nGood = 0;
127  for (const label patchi : selected)
128  {
129  if (!bad.found(patchi))
130  {
131  patchIDs_[nGood] = patchi;
132  ++nGood;
133  }
134  }
135  }
136  else
137  {
138  patchIDs_ = std::move(selected);
139  }
140  }
141 
142  return patchIDs_;
143 }
144 
145 
147 {
148  return needsUpdate_;
149 }
150 
151 
153 {
154  // already marked as expired
155  if (needsUpdate_)
156  {
157  return false;
158  }
159 
161  Mesh::clear();
162 
163  patchIDs_.clear();
164  patchStart_.clear();
165 
166  patchIndex_.clear();
167  patchFaceLabels_.clear();
168 
169  needsUpdate_ = true;
170  return true;
171 }
172 
173 
175 {
176  if (!needsUpdate_)
177  {
178  return false;
179  }
180 
181  // Total number of faces selected
182  label numFaces = 0;
183  for (const label patchi : patchIDs())
184  {
185  const polyPatch& pp = mesh().boundaryMesh()[patchi];
186  numFaces += pp.size();
187  }
188 
189  patchStart_.resize(patchIDs().size());
190 
191  // The originating patch and local face in the patch.
192  patchIndex_.resize(numFaces);
193  patchFaceLabels_.resize(numFaces);
194 
195  IndirectList<face> selectedFaces(mesh().faces(), labelList());
196  labelList& meshFaceIds = selectedFaces.addressing();
197  meshFaceIds.resize(numFaces);
198 
199  numFaces = 0;
200 
201  forAll(patchIDs(), idx)
202  {
203  const label patchi = patchIDs()[idx];
204  const polyPatch& pp = mesh().boundaryMesh()[patchi];
205  const label len = pp.size();
206 
207  patchStart_[idx] = numFaces;
208 
209  SubList<label>(patchIndex_, len, numFaces) = idx;
210 
211  SubList<label>(patchFaceLabels_, len, numFaces) = identity(len);
212 
213  SubList<label>(meshFaceIds, len, numFaces) = identity(len, pp.start());
214 
215  numFaces += len;
216  }
217 
218 
219  uindirectPrimitivePatch allPatches(selectedFaces, mesh().points());
220 
221  this->storedPoints() = allPatches.localPoints();
222  this->storedFaces() = allPatches.localFaces();
223 
224 
225  // triangulate uses remapFaces()
226  // - this is somewhat less efficient since it recopies the faces
227  // that we just created, but we probably don't want to do this
228  // too often anyhow.
229  if (triangulate_)
230  {
231  Mesh::triangulate();
232  }
233 
234  if (debug)
235  {
236  print(Pout, debug);
237  Pout<< endl;
238  }
239 
240  needsUpdate_ = false;
241  return true;
242 }
243 
244 
245 // remap action on triangulation
246 void Foam::sampledPatch::remapFaces(const labelUList& faceMap)
247 {
248  if (!faceMap.empty())
249  {
250  Mesh::remapFaces(faceMap);
251  patchFaceLabels_ = labelList
252  (
253  labelUIndList(patchFaceLabels_, faceMap)
254  );
255  patchIndex_ = labelList
256  (
257  labelUIndList(patchIndex_, faceMap)
258  );
259 
260  // Update patchStart
261  if (patchIndex_.size())
262  {
263  patchStart_[patchIndex_[0]] = 0;
264  for (label i = 1; i < patchIndex_.size(); ++i)
265  {
266  if (patchIndex_[i] != patchIndex_[i-1])
267  {
268  patchStart_[patchIndex_[i]] = i;
269  }
270  }
271  }
272  }
273 }
274 
275 
277 (
278  const interpolation<scalar>& sampler
279 ) const
280 {
281  return sampleOnFaces(sampler);
282 }
283 
284 
286 (
287  const interpolation<vector>& sampler
288 ) const
289 {
290  return sampleOnFaces(sampler);
291 }
292 
293 
295 (
296  const interpolation<sphericalTensor>& sampler
297 ) const
298 {
299  return sampleOnFaces(sampler);
300 }
301 
302 
304 (
305  const interpolation<symmTensor>& sampler
306 ) const
307 {
308  return sampleOnFaces(sampler);
309 }
310 
311 
313 (
314  const interpolation<tensor>& sampler
315 ) const
316 {
317  return sampleOnFaces(sampler);
318 }
319 
320 
322 {
323  return true;
324 }
325 
326 
328 (
329  const surfaceScalarField& sField
330 ) const
331 {
332  return sampleOnFaces(sField);
333 }
334 
335 
337 (
338  const surfaceVectorField& sField
339 ) const
340 {
341  return sampleOnFaces(sField);
342 }
343 
344 
346 (
347  const surfaceSphericalTensorField& sField
348 ) const
349 {
350  return sampleOnFaces(sField);
351 }
352 
353 
355 (
356  const surfaceSymmTensorField& sField
357 ) const
358 {
359  return sampleOnFaces(sField);
360 }
361 
362 
364 (
365  const surfaceTensorField& sField
366 ) const
367 {
368  return sampleOnFaces(sField);
369 }
370 
371 
373 (
374  const interpolation<scalar>& interpolator
375 ) const
376 {
377  return sampleOnPoints(interpolator);
378 }
379 
380 
382 (
383  const interpolation<vector>& interpolator
384 ) const
385 {
386  return sampleOnPoints(interpolator);
387 }
388 
389 
391 (
392  const interpolation<sphericalTensor>& interpolator
393 ) const
394 {
395  return sampleOnPoints(interpolator);
396 }
397 
398 
400 (
401  const interpolation<symmTensor>& interpolator
402 ) const
403 {
404  return sampleOnPoints(interpolator);
405 }
406 
407 
409 (
410  const interpolation<tensor>& interpolator
411 ) const
412 {
413  return sampleOnPoints(interpolator);
414 }
415 
416 
417 void Foam::sampledPatch::print(Ostream& os, int level) const
418 {
419  os << "sampledPatch: " << name() << " :"
420  << " patches:" << flatOutput(selectionNames_);
421 
422  if (level)
423  {
424  os << " faces:" << faces().size()
425  << " points:" << points().size();
426  }
427 }
428 
429 
430 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
sampledPatch.H
Foam::sampledPatch::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPatch.C:146
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::sampledPatch::patchIDs
const labelList & patchIDs() const
The patches selected.
Definition: sampledPatch.C:81
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
uindirectPrimitivePatch.H
polyPatch.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
Foam::IndirectList::addressing
const Addr & addressing() const noexcept
The list addressing.
Definition: IndirectListAddressing.H:76
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
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:296
Foam::sampledPatch::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample boundary of volume field onto surface faces.
Definition: sampledPatch.C:277
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::sampledPatch::withSurfaceFields
virtual bool withSurfaceFields() const
Can it sample surface-fields?
Definition: sampledPatch.C:321
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::sampledPatch::sampledPatch
sampledPatch(const word &name, const polyMesh &mesh, const UList< wordRe > &patchNames, const bool triangulate=false)
Construct from components.
Definition: sampledPatch.C:51
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:121
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:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::PrimitivePatch::localFaces
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatch.C:317
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::PrimitivePatch::localPoints
const Field< point_type > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:359
Foam::sampledPatch::update
virtual bool update()
Update the surface as required.
Definition: sampledPatch.C:174
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< label >
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
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:199
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:152
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:53
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::sampledPatch::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledPatch.C:417
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::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
Foam::labelUIndList
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: UIndirectList.H:58