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-------------------------------------------------------------------------------
10License
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"
37
39
40// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41
42namespace Foam
43{
46 (
49 word,
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(numFaces);
155 facePatchId_.resize(numFaces);
156
157 IndirectList<face> selectedFaces(mesh().faces(), labelList());
158 labelList& meshFaceIds = selectedFaces.addressing();
159 meshFaceIds.resize(numFaces);
160
161 numFaces = 0;
162
163 forAll(zoneIDs(), idx)
164 {
165 const label zonei = zoneIDs()[idx];
166 const faceZone& fZone = mesh().faceZones()[zonei];
167
168 for (const label meshFacei : fZone)
169 {
170 // Internal faces
171 label faceId = meshFacei;
172 label facePatchId = -1;
173
174 // Boundary faces
175 if (!mesh().isInternalFace(meshFacei))
176 {
177 facePatchId = mesh().boundaryMesh().whichPatch(meshFacei);
178 const polyPatch& pp = mesh().boundaryMesh()[facePatchId];
179
180 if (isA<emptyPolyPatch>(pp))
181 {
182 // Do not sample an empty patch
183 continue;
184 }
185
186 const auto* procPatch = isA<processorPolyPatch>(pp);
187 if (procPatch && !procPatch->owner())
188 {
189 // Do not sample neighbour-side, retain owner-side only
190 continue;
191 }
192
193 const auto* cpp = isA<coupledPolyPatch>(pp);
194 if (cpp)
195 {
196 faceId = (cpp->owner() ? pp.whichFace(meshFacei) : -1);
197 }
198 else
199 {
200 faceId = pp.whichFace(meshFacei);
201 }
202 }
203
204 if (faceId >= 0)
205 {
206 faceId_[numFaces] = faceId;
207 facePatchId_[numFaces] = facePatchId;
208 meshFaceIds[numFaces] = meshFacei;
209 ++numFaces;
210 }
211 }
212 }
213
214 // Shrink to size used
215 faceId_.resize(numFaces);
216 facePatchId_.resize(numFaces);
217 meshFaceIds.resize(numFaces);
218
219 uindirectPrimitivePatch zoneFaces(selectedFaces, mesh().points());
220
221 this->storedPoints() = zoneFaces.localPoints();
222 this->storedFaces() = zoneFaces.localFaces();
223
224 // triangulate - uses remapFaces()
225 if (triangulate_)
226 {
227 Mesh::triangulate();
228 }
229
230 needsUpdate_ = false;
231 return true;
232}
233
234
235// remap action on triangulation
236void Foam::sampledFaceZone::remapFaces(const labelUList& faceMap)
237{
238 if (!faceMap.empty())
239 {
240 Mesh::remapFaces(faceMap);
241 faceId_ = labelList
242 (
243 labelUIndList(faceId_, faceMap)
244 );
245 facePatchId_ = labelList
246 (
247 labelUIndList(facePatchId_, faceMap)
248 );
249 }
250}
251
252
254(
255 const interpolation<scalar>& sampler
256) const
257{
258 return sampleOnFaces(sampler);
259}
260
261
263(
264 const interpolation<vector>& sampler
265) const
266{
267 return sampleOnFaces(sampler);
268}
269
270
272(
273 const interpolation<sphericalTensor>& sampler
274) const
275{
276 return sampleOnFaces(sampler);
277}
278
279
281(
282 const interpolation<symmTensor>& sampler
283) const
284{
285 return sampleOnFaces(sampler);
286}
287
288
290(
291 const interpolation<tensor>& sampler
292) const
293{
294 return sampleOnFaces(sampler);
295}
296
297
299{
300 return true;
301}
302
303
305(
306 const surfaceScalarField& sField
307) const
308{
309 return sampleOnFaces(sField);
310}
311
312
314(
315 const surfaceVectorField& sField
316) const
317{
318 return sampleOnFaces(sField);
319}
320
321
323(
324 const surfaceSphericalTensorField& sField
325) const
326{
327 return sampleOnFaces(sField);
328}
329
330
332(
333 const surfaceSymmTensorField& sField
334) const
335{
336 return sampleOnFaces(sField);
337}
338
339
341(
342 const surfaceTensorField& sField
343) const
344{
345 return sampleOnFaces(sField);
346}
347
348
350(
351 const interpolation<scalar>& interpolator
352) const
353{
354 return sampleOnPoints(interpolator);
355}
356
357
359(
360 const interpolation<vector>& interpolator
361) const
362{
363 return sampleOnPoints(interpolator);
364}
365
368(
369 const interpolation<sphericalTensor>& interpolator
370) const
371{
372 return sampleOnPoints(interpolator);
373}
374
375
377(
378 const interpolation<symmTensor>& interpolator
379) const
380{
381 return sampleOnPoints(interpolator);
382}
383
384
386(
387 const interpolation<tensor>& interpolator
388) const
389{
390 return sampleOnPoints(interpolator);
391}
392
393
395{
396 os << "faceZone: " << name() << " :"
397 << " zones:" << flatOutput(selectionNames_);
398
399 if (level)
400 {
401 os << " faces:" << faces().size()
402 << " points:" << points().size();
403 }
404}
405
406
407// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
Minimal example by using system/controlDict.functions:
A List with indirect addressing.
Definition: IndirectList.H:119
const Addr & addressing() const noexcept
The list addressing.
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of faces which address into the list of points.
const Field< point_type > & localPoints() const
Return pointField of points in patch.
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:377
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:67
Abstract base class for volume field interpolation.
Definition: interpolation.H:60
scalar print()
Print to screen.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:498
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
label whichFace(const label l) const
Return label of face in patch from global face label.
Definition: polyPatch.H:451
A sampledSurface defined by a faceZone or faceZones.
const labelList & zoneIDs() const
The selected face zones (sorted)
virtual bool expire()
Mark the surface as needing an update.
virtual bool needsUpdate() const
Does the surface need an update?
virtual bool withSurfaceFields() const
Can it sample surface-fields?
virtual bool update()
Update the surface as required.
An abstract class for surfaces with sampling.
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
bool interpolate() const noexcept
Same as isPointData()
A class for managing temporary objects.
Definition: tmp.H:65
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
const labelIOList & zoneIDs
Definition: correctPhi.H:59
label faceId(-1)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< label > labelList
A List of labels.
Definition: List.H:66
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: IndirectList.H:68
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Foam::surfaceFields.