Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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"
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
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
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
227void 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
238 labelUIndList(facePatchId_, faceMap)
239 );
240 }
241}
242
243
245(
247) const
248{
249 return sampleOnFaces(sampler);
250}
251
252
254(
256) const
257{
258 return sampleOnFaces(sampler);
259}
260
261
263(
265) const
266{
267 return sampleOnFaces(sampler);
268}
269
270
272(
274) const
275{
276 return sampleOnFaces(sampler);
277}
278
279
281(
283) const
284{
285 return sampleOnFaces(sampler);
286}
287
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
331Foam::tmp<Foam::tensorField> Foam::sampledFaceZone::sample
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(
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
385void 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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A List with indirect addressing.
const Addr & addressing() const noexcept
The list addressing.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
virtual label triangulate()
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
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:89
bool empty() const noexcept
Definition UList.H:701
bool get(const label i) const
Definition UList.H:868
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
labelList indices(const wordRe &matcher, const bool useGroups=true) const
The (sorted) patch indices for all matches, optionally matching zone groups.
Definition ZoneMesh.C:562
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A subset of mesh faces organised as a primitive patch.
Definition faceZone.H:63
Abstract base class for volume field interpolation.
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition polyMesh.H:671
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A sampledSurface defined by a faceZone or faceZones.
virtual void print(Ostream &os, int level=0) const
Print information.
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
sampledFaceZone(const word &name, const polyMesh &mesh, const UList< wordRe > &zoneNames, const bool triangulate=false)
Construct from components.
virtual const faceList & faces() const
Faces of surface.
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.
sampledSurface(const word &name, std::nullptr_t)
Construct null.
const word & name() const noexcept
Name of surface.
virtual void clearGeom() const
Additional cleanup when clearing the geometry.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
bool interpolate() const noexcept
Same as isPointData().
A class for managing temporary objects.
Definition tmp.H:75
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
auto & names
const pointField & points
const labelIOList & zoneIDs
Definition correctPhi.H:59
label faceId(-1)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
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:62
UIndirectList< label > labelUIndList
UIndirectList of labels.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
Foam::surfaceFields.