sampledFaceZone.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) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "sampledFaceZone.H"
29 #include "dictionary.H"
30 #include "polyMesh.H"
31 #include "polyPatch.H"
32 #include "volFields.H"
33 #include "surfaceFields.H"
34 #include "volPointInterpolation.H"
36 
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(sampledFaceZone, 0);
45  (
46  sampledSurface,
47  sampledFaceZone,
48  word,
49  faceZone
50  );
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 (
58  const word& name,
59  const polyMesh& mesh,
60  const UList<wordRe>& zoneNames,
61  const bool triangulate
62 )
63 :
65  selectionNames_(zoneNames),
66  triangulate_(triangulate),
67  needsUpdate_(true)
68 {}
69 
70 
72 (
73  const word& name,
74  const polyMesh& mesh,
75  const dictionary& dict
76 )
77 :
79  selectionNames_(dict.get<wordRes>("zones")),
80  triangulate_(dict.getOrDefault("triangulate", false)),
81  needsUpdate_(true)
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
89  if (zoneIds_.empty())
90  {
91  // Zone indices for all matches, already sorted
92  zoneIds_ = mesh().faceZones().indices(selectionNames_);
93  }
94 
95  return zoneIds_;
96 }
97 
98 
100 {
101  return needsUpdate_;
102 }
103 
104 
106 {
107  // already marked as expired
108  if (needsUpdate_)
109  {
110  return false;
111  }
112 
114  Mesh::clear();
115 
116  zoneIds_.clear();
117 
118  faceId_.clear();
119  facePatchId_.clear();
120 
121  needsUpdate_ = true;
122  return true;
123 }
124 
125 
127 {
128  if (!needsUpdate_)
129  {
130  return false;
131  }
132 
133  // Total number of faces selected
134  label numFaces = 0;
135  for (const label zonei : zoneIDs())
136  {
137  numFaces += mesh().faceZones()[zonei].size();
138  }
139 
140  if (zoneIDs().empty())
141  {
143  << type() << ' ' << name() << ": "
144  << " No matching face zone(s): "
145  << flatOutput(selectionNames_) << nl
146  << " Known face zones: "
147  << flatOutput(mesh().faceZones().names()) << nl;
148  }
149 
150  // Could also check numFaces
151 
152  // The mesh face or local patch face and the patch id
153  faceId_.resize(numFaces);
154  facePatchId_.resize(numFaces);
155 
156  IndirectList<face> selectedFaces(mesh().faces(), labelList());
157  labelList& meshFaceIds = selectedFaces.addressing();
158  meshFaceIds.resize(numFaces);
159 
160  numFaces = 0;
161 
162  forAll(zoneIDs(), idx)
163  {
164  const label zonei = zoneIDs()[idx];
165  const faceZone& fZone = mesh().faceZones()[zonei];
166 
167  for (const label meshFacei : fZone)
168  {
169  // Internal faces
170  label faceId = meshFacei;
171  label facePatchId = -1;
172 
173  // Boundary faces
174  if (!mesh().isInternalFace(meshFacei))
175  {
176  facePatchId = mesh().boundaryMesh().whichPatch(meshFacei);
177  const polyPatch& pp = mesh().boundaryMesh()[facePatchId];
178 
179  if (isA<emptyPolyPatch>(pp))
180  {
181  // Do not sample an empty patch
182  continue;
183  }
184 
185  const auto* procPatch = isA<processorPolyPatch>(pp);
186  if (procPatch && !procPatch->owner())
187  {
188  // Do not sample neighbour-side, retain owner-side only
189  continue;
190  }
191 
192  const auto* cpp = isA<coupledPolyPatch>(pp);
193  if (cpp)
194  {
195  faceId = (cpp->owner() ? pp.whichFace(meshFacei) : -1);
196  }
197  else
198  {
199  faceId = pp.whichFace(meshFacei);
200  }
201  }
202 
203  if (faceId >= 0)
204  {
205  faceId_[numFaces] = faceId;
206  facePatchId_[numFaces] = facePatchId;
207  meshFaceIds[numFaces] = meshFacei;
208  ++numFaces;
209  }
210  }
211  }
212 
213  // Shrink to size used
214  faceId_.resize(numFaces);
215  facePatchId_.resize(numFaces);
216  meshFaceIds.resize(numFaces);
217 
218  uindirectPrimitivePatch zoneFaces(selectedFaces, mesh().points());
219 
220  this->storedPoints() = zoneFaces.localPoints();
221  this->storedFaces() = zoneFaces.localFaces();
222 
223  // triangulate - uses remapFaces()
224  if (triangulate_)
225  {
226  Mesh::triangulate();
227  }
228 
229  needsUpdate_ = false;
230  return true;
231 }
232 
233 
234 // remap action on triangulation
235 void Foam::sampledFaceZone::remapFaces(const labelUList& faceMap)
236 {
237  if (!faceMap.empty())
238  {
239  Mesh::remapFaces(faceMap);
240  faceId_ = labelList
241  (
242  labelUIndList(faceId_, faceMap)
243  );
244  facePatchId_ = labelList
245  (
246  labelUIndList(facePatchId_, faceMap)
247  );
248  }
249 }
250 
251 
253 (
254  const interpolation<scalar>& sampler
255 ) const
256 {
257  return sampleOnFaces(sampler);
258 }
259 
260 
262 (
263  const interpolation<vector>& sampler
264 ) const
265 {
266  return sampleOnFaces(sampler);
267 }
268 
269 
271 (
272  const interpolation<sphericalTensor>& sampler
273 ) const
274 {
275  return sampleOnFaces(sampler);
276 }
277 
278 
280 (
281  const interpolation<symmTensor>& sampler
282 ) const
283 {
284  return sampleOnFaces(sampler);
285 }
286 
287 
289 (
290  const interpolation<tensor>& sampler
291 ) const
292 {
293  return sampleOnFaces(sampler);
294 }
295 
296 
298 {
299  return true;
300 }
301 
302 
304 (
305  const surfaceScalarField& sField
306 ) const
307 {
308  return sampleOnFaces(sField);
309 }
310 
311 
313 (
314  const surfaceVectorField& sField
315 ) const
316 {
317  return sampleOnFaces(sField);
318 }
319 
320 
322 (
323  const surfaceSphericalTensorField& sField
324 ) const
325 {
326  return sampleOnFaces(sField);
327 }
328 
329 
331 (
332  const surfaceSymmTensorField& sField
333 ) const
334 {
335  return sampleOnFaces(sField);
336 }
337 
338 
340 (
341  const surfaceTensorField& sField
342 ) const
343 {
344  return sampleOnFaces(sField);
345 }
346 
347 
349 (
350  const interpolation<scalar>& interpolator
351 ) const
352 {
353  return sampleOnPoints(interpolator);
354 }
355 
356 
358 (
359  const interpolation<vector>& interpolator
360 ) const
361 {
362  return sampleOnPoints(interpolator);
363 }
364 
367 (
368  const interpolation<sphericalTensor>& interpolator
369 ) const
370 {
371  return sampleOnPoints(interpolator);
372 }
373 
374 
376 (
377  const interpolation<symmTensor>& interpolator
378 ) const
379 {
380  return sampleOnPoints(interpolator);
381 }
382 
383 
385 (
386  const interpolation<tensor>& interpolator
387 ) const
388 {
389  return sampleOnPoints(interpolator);
390 }
391 
392 
393 void Foam::sampledFaceZone::print(Ostream& os, int level) const
394 {
395  os << "faceZone: " << name() << " :"
396  << " zones:" << flatOutput(selectionNames_);
397 
398  if (level)
399  {
400  os << " faces:" << faces().size()
401  << " points:" << points().size();
402  }
403 }
404 
405 
406 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
Foam::sampledFaceZone::sampledFaceZone
sampledFaceZone(const word &name, const polyMesh &mesh, const UList< wordRe > &zoneNames, const bool triangulate=false)
Construct from components.
Definition: sampledFaceZone.C:57
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::sampledFaceZone::zoneIDs
const labelList & zoneIDs() const
The selected face zones (sorted)
Definition: sampledFaceZone.C:87
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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::IndirectList::addressing
const Addr & addressing() const noexcept
The list addressing.
Definition: IndirectListAddressing.H:76
Foam::sampledFaceZone::withSurfaceFields
virtual bool withSurfaceFields() const
Can it sample surface-fields?
Definition: sampledFaceZone.C:297
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
surfaceFields.H
Foam::surfaceFields.
polyMesh.H
zoneIDs
const labelIOList & zoneIDs
Definition: correctPhi.H:59
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::sampledFaceZone::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledFaceZone.C:105
Foam::sampledSurface::interpolate
bool interpolate() const noexcept
Same as isPointData()
Definition: sampledSurface.H:598
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::sampledFaceZone::update
virtual bool update()
Update the surface as required.
Definition: sampledFaceZone.C:126
faceId
label faceId(-1)
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:56
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:486
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:812
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:121
Foam::interpolation< scalar >
dict
dictionary dict
Definition: searchingEngine.H:14
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::sampledFaceZone::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledFaceZone.C:253
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::ZoneMesh::indices
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:371
Foam::PrimitivePatch::localPoints
const Field< point_type > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:359
volPointInterpolation.H
sampledFaceZone.H
Foam::polyPatch::whichFace
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:448
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::sampledSurface::mesh
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
Definition: sampledSurface.H:316
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
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
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::sampledFaceZone::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledFaceZone.C:99
Foam::sampledSurface::clearGeom
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
Definition: sampledSurface.C:53
Foam::sampledFaceZone::print
virtual void print(Ostream &os, int level=0) const
Print information.
Definition: sampledFaceZone.C:393
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
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