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-2022 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 "processorPolyPatch.H"
33 #include "volFields.H"
34 #include "surfaceFields.H"
35 #include "volPointInterpolation.H"
36 #include "indirectPrimitivePatch.H"
37 
39 
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44  defineTypeNameAndDebug(sampledFaceZone, 0);
46  (
47  sampledSurface,
48  sampledFaceZone,
49  word,
50  faceZone
51  );
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const word& name,
60  const polyMesh& mesh,
61  const UList<wordRe>& zoneNames,
62  const bool triangulate
63 )
64 :
66  selectionNames_(zoneNames),
67  triangulate_(triangulate),
68  needsUpdate_(true)
69 {}
70 
71 
73 (
74  const word& name,
75  const polyMesh& mesh,
76  const dictionary& dict
77 )
78 :
80  selectionNames_(dict.get<wordRes>("zones")),
81  triangulate_(dict.getOrDefault("triangulate", false)),
82  needsUpdate_(true)
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
89 {
90  if (zoneIds_.empty())
91  {
92  // Zone indices for all matches, already sorted
93  zoneIds_ = mesh().faceZones().indices(selectionNames_);
94  }
95 
96  return zoneIds_;
97 }
98 
99 
101 {
102  return needsUpdate_;
103 }
104 
105 
107 {
108  // already marked as expired
109  if (needsUpdate_)
110  {
111  return false;
112  }
113 
115  Mesh::clear();
116 
117  zoneIds_.clear();
118 
119  faceId_.clear();
120  facePatchId_.clear();
121 
122  needsUpdate_ = true;
123  return true;
124 }
125 
126 
128 {
129  if (!needsUpdate_)
130  {
131  return false;
132  }
133 
134  // Total number of faces selected
135  label numFaces = 0;
136  for (const label zonei : zoneIDs())
137  {
138  numFaces += mesh().faceZones()[zonei].size();
139  }
140 
141  if (zoneIDs().empty())
142  {
144  << type() << ' ' << name() << ": "
145  << " No matching face zone(s): "
146  << flatOutput(selectionNames_) << nl
147  << " Known face zones: "
148  << flatOutput(mesh().faceZones().names()) << nl;
149  }
150 
151  // Could also check numFaces
152 
153  // The mesh face or local patch face and the patch id
154  faceId_.resize_nocopy(numFaces);
155  facePatchId_.resize_nocopy(numFaces);
156 
157  IndirectList<face> selectedFaces(mesh().faces(), labelList());
158  labelList& meshFaceIds = selectedFaces.addressing();
159  meshFaceIds.resize_nocopy(numFaces);
160 
161  numFaces = 0;
162 
163  for (const label zoneId : zoneIDs())
164  {
165  const faceZone& fZone = mesh().faceZones()[zoneId];
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  continue; // Ignore empty patch
182  }
183 
184  const auto* cpp = isA<coupledPolyPatch>(pp);
185 
186  if (cpp && !cpp->owner())
187  {
188  continue; // Ignore neighbour side
189  }
190 
191  faceId = pp.whichFace(meshFacei);
192  }
193 
194  if (faceId >= 0)
195  {
196  faceId_[numFaces] = faceId;
197  facePatchId_[numFaces] = facePatchId;
198  meshFaceIds[numFaces] = meshFacei;
199 
200  ++numFaces;
201  }
202  }
203  }
204 
205  // Shrink to size used
206  faceId_.resize(numFaces);
207  facePatchId_.resize(numFaces);
208  meshFaceIds.resize(numFaces);
209 
210  uindirectPrimitivePatch zoneFaces(selectedFaces, mesh().points());
211 
212  this->storedPoints() = zoneFaces.localPoints();
213  this->storedFaces() = zoneFaces.localFaces();
214 
215  // triangulate - uses remapFaces()
216  if (triangulate_)
217  {
218  Mesh::triangulate();
219  }
220 
221  needsUpdate_ = false;
222  return true;
223 }
224 
225 
226 // remap action on triangulation
227 void Foam::sampledFaceZone::remapFaces(const labelUList& faceMap)
228 {
229  if (!faceMap.empty())
230  {
231  Mesh::remapFaces(faceMap);
232  faceId_ = labelList
233  (
234  labelUIndList(faceId_, faceMap)
235  );
236  facePatchId_ = labelList
237  (
238  labelUIndList(facePatchId_, faceMap)
239  );
240  }
241 }
242 
243 
245 (
246  const interpolation<scalar>& sampler
247 ) const
248 {
249  return sampleOnFaces(sampler);
250 }
251 
252 
254 (
255  const interpolation<vector>& sampler
256 ) const
257 {
258  return sampleOnFaces(sampler);
259 }
260 
261 
263 (
264  const interpolation<sphericalTensor>& sampler
265 ) const
266 {
267  return sampleOnFaces(sampler);
268 }
269 
270 
272 (
273  const interpolation<symmTensor>& sampler
274 ) const
275 {
276  return sampleOnFaces(sampler);
277 }
278 
279 
281 (
282  const interpolation<tensor>& sampler
283 ) const
284 {
285  return sampleOnFaces(sampler);
286 }
287 
288 
290 {
291  return true;
292 }
293 
294 
296 (
297  const surfaceScalarField& sField
298 ) const
299 {
300  return sampleOnFaces(sField);
301 }
302 
303 
305 (
306  const surfaceVectorField& sField
307 ) const
308 {
309  return sampleOnFaces(sField);
310 }
311 
312 
314 (
315  const surfaceSphericalTensorField& sField
316 ) const
317 {
318  return sampleOnFaces(sField);
319 }
320 
321 
323 (
324  const surfaceSymmTensorField& sField
325 ) const
326 {
327  return sampleOnFaces(sField);
328 }
329 
330 
332 (
333  const surfaceTensorField& sField
334 ) const
335 {
336  return sampleOnFaces(sField);
337 }
338 
339 
341 (
342  const interpolation<scalar>& interpolator
343 ) const
344 {
345  return sampleOnPoints(interpolator);
346 }
347 
348 
350 (
351  const interpolation<vector>& interpolator
352 ) const
353 {
354  return sampleOnPoints(interpolator);
355 }
356 
359 (
360  const interpolation<sphericalTensor>& interpolator
361 ) const
362 {
363  return sampleOnPoints(interpolator);
364 }
365 
366 
368 (
369  const interpolation<symmTensor>& interpolator
370 ) const
371 {
372  return sampleOnPoints(interpolator);
373 }
374 
375 
377 (
378  const interpolation<tensor>& interpolator
379 ) const
380 {
381  return sampleOnPoints(interpolator);
382 }
383 
384 
385 void Foam::sampledFaceZone::print(Ostream& os, int level) const
386 {
387  os << "faceZone: " << name() << " :"
388  << " zones:" << flatOutput(selectionNames_);
389 
390  if (level)
391  {
392  os << " faces:" << faces().size()
393  << " points:" << points().size();
394  }
395 }
396 
397 
398 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Foam::surfaceFields.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
bool interpolate() const noexcept
Same as isPointData()
const labelIOList & zoneIDs
Definition: correctPhi.H:59
virtual bool withSurfaceFields() const
Can it sample surface-fields?
label faceId(-1)
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An abstract class for surfaces with sampling.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: IndirectList.H:65
virtual bool update()
Update the surface as required.
virtual bool expire()
Mark the surface as needing an update.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
Macros for easy insertion into run-time selection tables.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:435
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
virtual bool needsUpdate() const
Does the surface need an update?
patchWriters clear()
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
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:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:670
defineTypeNameAndDebug(combustionModel, 0)
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
#define WarningInFunction
Report a warning using Foam::Warning.
sampledFaceZone(const word &name, const polyMesh &mesh, const UList< wordRe > &zoneNames, const bool triangulate=false)
Construct from components.
Abstract base class for volume field interpolation.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const labelList & zoneIDs() const
The selected face zones (sorted)
virtual void print(Ostream &os, int level=0) const
Print information.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225