sampledPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "sampledPatch.H"
27 #include "surfaceFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sampledSurfaces
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const word& name,
47  const polyMesh& mesh,
48  const wordReList& patchNames,
49  const bool triangulate
50 )
51 :
53  patchNames_(patchNames),
54  triangulate_(triangulate),
55  needsUpdate_(true)
56 {}
57 
58 
60 (
61  const word& name,
62  const polyMesh& mesh,
63  const dictionary& dict
64 )
65 :
67  patchNames_(dict.lookup("patches")),
68  triangulate_(dict.lookupOrDefault("triangulate", false)),
69  needsUpdate_(true)
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (patchIndices_.empty())
84  {
85  patchIndices_ = mesh().boundaryMesh().patchSet
86  (
87  patchNames_,
88  false
89  ).sortedToc();
90  }
91  return patchIndices_;
92 }
93 
94 
96 {
97  return needsUpdate_;
98 }
99 
100 
102 {
103  // already marked as expired
104  if (needsUpdate_)
105  {
106  return false;
107  }
108 
111 
112  patchIndices_.clear();
113  patchIndex_.clear();
114  patchFaceLabels_.clear();
115  patchStart_.clear();
116 
117  needsUpdate_ = true;
118  return true;
119 }
120 
121 
123 {
124  if (!needsUpdate_)
125  {
126  return false;
127  }
128 
129  label sz = 0;
130  forAll(patchIndices(), i)
131  {
132  label patchi = patchIndices()[i];
133  const polyPatch& pp = mesh().boundaryMesh()[patchi];
134 
135  if (isA<emptyPolyPatch>(pp))
136  {
138  << "Cannot sample an empty patch. Patch " << pp.name()
139  << exit(FatalError);
140  }
141 
142  sz += pp.size();
143  }
144 
145  // For every face (or triangle) the originating patch and local face in the
146  // patch.
147  patchIndex_.setSize(sz);
148  patchFaceLabels_.setSize(sz);
149  patchStart_.setSize(patchIndices().size());
150  labelList meshFaceLabels(sz);
151 
152  sz = 0;
153 
154  forAll(patchIndices(), i)
155  {
156  label patchi = patchIndices()[i];
157 
158  patchStart_[i] = sz;
159 
160  const polyPatch& pp = mesh().boundaryMesh()[patchi];
161 
162  forAll(pp, j)
163  {
164  patchIndex_[sz] = i;
165  patchFaceLabels_[sz] = j;
166  meshFaceLabels[sz] = pp.start()+j;
167  sz++;
168  }
169  }
170 
171  indirectPrimitivePatch allPatches
172  (
173  IndirectList<face>(mesh().faces(), meshFaceLabels),
174  mesh().points()
175  );
176 
177  this->storedPoints() = allPatches.localPoints();
178  this->storedFaces() = allPatches.localFaces();
179 
180 
181  // triangulate uses remapFaces()
182  // - this is somewhat less efficient since it recopies the faces
183  // that we just created, but we probably don't want to do this
184  // too often anyhow.
185  if (triangulate_)
186  {
188  }
189 
190  if (debug)
191  {
192  print(Pout);
193  Pout<< endl;
194  }
195 
196  needsUpdate_ = false;
197  return true;
198 }
199 
200 
201 // remap action on triangulation
202 void Foam::sampledSurfaces::patch::remapFaces(const labelUList& faceMap)
203 {
204  // recalculate the cells cut
205  if (notNull(faceMap) && faceMap.size())
206  {
208  patchFaceLabels_ = labelList
209  (
210  UIndirectList<label>(patchFaceLabels_, faceMap)
211  );
212  patchIndex_ = labelList
213  (
214  UIndirectList<label>(patchIndex_, faceMap)
215  );
216 
217  // Redo patchStart.
218  if (patchIndex_.size() > 0)
219  {
220  patchStart_[patchIndex_[0]] = 0;
221  for (label i = 1; i < patchIndex_.size(); i++)
222  {
223  if (patchIndex_[i] != patchIndex_[i-1])
224  {
225  patchStart_[patchIndex_[i]] = i;
226  }
227  }
228  }
229  }
230 }
231 
232 
234 (
235  const volScalarField& vField
236 ) const
237 {
238  return sampleField(vField);
239 }
240 
241 
243 (
244  const volVectorField& vField
245 ) const
246 {
247  return sampleField(vField);
248 }
249 
250 
252 (
253  const volSphericalTensorField& vField
254 ) const
255 {
256  return sampleField(vField);
257 }
258 
259 
261 (
262  const volSymmTensorField& vField
263 ) const
264 {
265  return sampleField(vField);
266 }
267 
268 
270 (
271  const volTensorField& vField
272 ) const
273 {
274  return sampleField(vField);
275 }
276 
277 
279 (
280  const surfaceScalarField& sField
281 ) const
282 {
283  return sampleField(sField);
284 }
285 
286 
288 (
289  const surfaceVectorField& sField
290 ) const
291 {
292  return sampleField(sField);
293 }
294 
295 
297 (
298  const surfaceSphericalTensorField& sField
299 ) const
300 {
301  return sampleField(sField);
302 }
303 
304 
306 (
307  const surfaceSymmTensorField& sField
308 ) const
309 {
310  return sampleField(sField);
311 }
312 
313 
315 (
316  const surfaceTensorField& sField
317 ) const
318 {
319  return sampleField(sField);
320 }
321 
322 
324 (
325  const interpolation<scalar>& interpolator
326 ) const
327 {
328  return interpolateField(interpolator);
329 }
330 
331 
333 (
334  const interpolation<vector>& interpolator
335 ) const
336 {
337  return interpolateField(interpolator);
338 }
339 
340 
342 (
343  const interpolation<sphericalTensor>& interpolator
344 ) const
345 {
346  return interpolateField(interpolator);
347 }
348 
349 
351 (
352  const interpolation<symmTensor>& interpolator
353 ) const
354 {
355  return interpolateField(interpolator);
356 }
357 
358 
360 (
361  const interpolation<tensor>& interpolator
362 ) const
363 {
364  return interpolateField(interpolator);
365 }
366 
367 
369 {
370  os << "patch: " << name() << " :"
371  << " patches:" << patchNames()
372  << " faces:" << faces().size()
373  << " points:" << points().size();
374 }
375 
376 
377 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:242
A List with indirect addressing.
Definition: IndirectList.H:105
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
virtual void remapFaces(const labelUList &faceMap)
Set new zones from faceMap.
virtual void clear()
Clear all storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
A List with indirect addressing.
Definition: UIndirectList.H:60
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for interpolation.
Definition: interpolation.H:55
const word & name() const
Return name.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the patch set corresponding to the given names.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:382
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:280
An abstract class for surfaces with sampling.
virtual void clearGeom() const
bool interpolate() const
Interpolation requested for surface.
A sampledSurface on patches. Non-triangulated by default.
Definition: sampledPatch.H:93
const labelList & patchIndices() const
Definition: sampledPatch.C:81
virtual ~patch()
Destructor.
Definition: sampledPatch.C:75
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
Definition: sampledPatch.C:234
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledPatch.C:101
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledPatch.C:95
virtual bool update()
Update the surface as required.
Definition: sampledPatch.C:122
virtual void print(Ostream &) const
Write.
Definition: sampledPatch.C:368
patch(const word &name, const polyMesh &mesh, const wordReList &patchNames, const bool triangulate=false)
Construct from components.
Definition: sampledPatch.C:45
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
const pointField & points
defineTypeNameAndDebug(cutPlane, 0)
addToRunTimeSelectionTable(sampledSurface, cutPlane, word)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
SurfaceField< tensor > surfaceTensorField
List< label > labelList
A List of labels.
Definition: labelList.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:64
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError
SurfaceField< sphericalTensor > surfaceSphericalTensorField
SurfaceField< symmTensor > surfaceSymmTensorField
wordList patchNames(nPatches)
dictionary dict
Foam::surfaceFields.