sampledMeshedSurface.H
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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::sampledMeshedSurface
29 
30 Description
31  A sampledSurface from a meshed surface.
32  It samples on the points/faces of the meshed surface.
33 
34  - it either samples cells or (non-coupled) boundary faces
35 
36  - 6 different modes:
37  - source=cells, interpolate=false:
38  finds per triangle centre the nearest cell centre and uses its value
39  - source=cells, interpolate=true
40  finds per triangle centre the nearest cell centre.
41  Per surface point checks if this nearest cell is the one containing
42  point; otherwise projects the point onto the nearest point on
43  the boundary of the cell (to make sure interpolateCellPoint
44  gets a valid location)
45 
46  - source=insideCells, interpolate=false:
47  finds per triangle centre the cell containing it and uses its value.
48  Trims triangles outside mesh.
49  - source=insideCells, interpolate=true
50  Per surface point interpolate cell containing it.
51 
52  - source=boundaryFaces, interpolate=false:
53  finds per triangle centre the nearest point on the boundary
54  (uncoupled faces only) and uses the value (or 0 if the nearest
55  is on an empty boundary)
56  - source=boundaryFaces, interpolate=true:
57  finds per triangle centre the nearest point on the boundary
58  (uncoupled faces only).
59  Per surface point projects the point onto this boundary face
60  (to make sure interpolateCellPoint gets a valid location)
61 
62  - since it finds a nearest per triangle each triangle is guaranteed
63  to be on one processor only. So after stitching (by sampledSurfaces)
64  the original surface should be complete.
65 
66  This is often embedded as part of a sampled surfaces function object.
67 
68 Usage
69  Example of function object partial specification:
70  \verbatim
71  surfaces
72  {
73  surface1
74  {
75  type meshedSurface;
76  surface something.obj;
77  source cells;
78  }
79  }
80  \endverbatim
81 
82  Where the sub-entries comprise:
83  \table
84  Property | Description | Required | Default
85  type | meshedSurface | yes |
86  surface | surface name in triSurface/ | yes |
87  patches | Limit to named surface regions (wordRes) | no |
88  source | cells/insideCells/boundaryFaces | yes |
89  keepIds | pass through id numbering | no | true
90  file | Alternative file name | no |
91  fileType | The surface format | no | (extension)
92  scale | Surface scaling factor | no | 0
93  \endtable
94 
95 SourceFiles
96  sampledMeshedSurface.C
97  sampledMeshedSurfaceTemplates.C
98 
99 \*---------------------------------------------------------------------------*/
100 
101 #ifndef sampledMeshedSurface_H
102 #define sampledMeshedSurface_H
103 
104 #include "sampledSurface.H"
105 #include "MeshedSurface.H"
106 #include "MeshedSurfacesFwd.H"
107 
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
109 
110 namespace Foam
111 {
112 
113 // Forward Declarations
114 class meshSearch;
115 
116 /*---------------------------------------------------------------------------*\
117  Class sampledMeshedSurface Declaration
118 \*---------------------------------------------------------------------------*/
119 
120 class sampledMeshedSurface
121 :
122  public sampledSurface,
123  public meshedSurface
124 {
125 public:
126  //- Types of sampling regions
127  enum samplingSource
128  {
129  cells,
130  insideCells,
132  };
133 
134 private:
135 
136  //- Private typedefs for convenience
137  typedef meshedSurface MeshStorage;
138 
139 
140  // Private Data
141 
142  static const Enum<samplingSource> samplingSourceNames_;
143 
144  //- The name of the input surface
145  word surfaceName_;
146 
147  //- Surface to sample on
148  meshedSurface surface_;
149 
150  //- Whether to sample internal cell values or boundary values
151  const samplingSource sampleSource_;
152 
153  //- Track if the surface needs an update
154  mutable bool needsUpdate_;
155 
156  //- Retain element ids/order of original surface
157  bool keepIds_;
158 
159  //- For compatibility with the meshSurf interface
160  labelList zoneIds_;
161 
162  //- From local surface triangle to mesh cell/face.
163  labelList sampleElements_;
164 
165  //- Local points to sample per point
166  pointField samplePoints_;
167 
168 
169  // Private Member Functions
170 
171  //- Set zoneIds list based on the surfZone information
172  void setZoneMap();
173 
174  //- Sample volume field onto surface faces
175  template<class Type>
176  tmp<Field<Type>> sampleOnFaces
177  (
178  const interpolation<Type>& sampler
179  ) const;
180 
181  //- Interpolate volume field onto surface points
182  template<class Type>
183  tmp<Field<Type>> sampleOnPoints
184  (
185  const interpolation<Type>& interpolator
186  ) const;
187 
188  bool update(const meshSearch& meshSearcher);
189 
190 public:
191 
192  //- Declare type-name, virtual type (with debug switch)
193  TypeName("sampledMeshedSurface");
194 
195 
196  // Constructors
197 
198  //- Construct from components
200  (
201  const word& name,
202  const polyMesh& mesh,
203  const word& surfaceName,
204  const samplingSource sampleSource
205  );
206 
207  //- Construct from dictionary
209  (
210  const word& name,
211  const polyMesh& mesh,
212  const dictionary& dict
213  );
214 
215 
216  //- Destructor
217  virtual ~sampledMeshedSurface() = default;
218 
219 
220  // Member Functions
221 
222  //- Does the surface need an update?
223  virtual bool needsUpdate() const;
224 
225  //- Mark the surface as needing an update.
226  // May also free up unneeded data.
227  // Return false if surface was already marked as expired.
228  virtual bool expire();
229 
230  //- Update the surface as required.
231  // Do nothing (and return false) if no update was needed
232  virtual bool update();
233 
234  //- Update the surface using a bound box to limit the searching.
235  // For direct use, i.e. not through sample.
236  // Do nothing (and return false) if no update was needed
237  bool update(const treeBoundBox& bb);
238 
239  //- Points of surface
240  virtual const pointField& points() const
241  {
242  return MeshStorage::points();
243  }
244 
245  //- Faces of surface
246  virtual const faceList& faces() const
247  {
248  return MeshStorage::surfFaces();
249  }
250 
251  //- Per-face zone/region information
252  virtual const labelList& zoneIds() const
253  {
254  return zoneIds_;
255  }
256 
257  //- Per-face identifier (eg, element Id)
258  virtual const labelList& faceIds() const
259  {
260  return MeshStorage::faceIds();
261  }
262 
263  //- Face area vectors
264  virtual const vectorField& Sf() const
265  {
266  return MeshStorage::Sf();
267  }
268 
269  //- Face area magnitudes
270  virtual const scalarField& magSf() const
271  {
272  return MeshStorage::magSf();
273  }
274 
275  //- Face centres
276  virtual const vectorField& Cf() const
277  {
278  return MeshStorage::Cf();
279  }
280 
281  //- If element ids/order of the original surface are kept
282  virtual bool hasFaceIds() const
283  {
284  return keepIds_ && !MeshStorage::faceIds().empty();
285  }
286 
287  //- Sampling boundary values instead of cell values
288  bool onBoundary() const
289  {
290  return sampleSource_ == boundaryFaces;
291  }
292 
293 
294  // Sample
295 
296  //- Sample volume field onto surface faces
297  virtual tmp<scalarField> sample
298  (
299  const interpolation<scalar>& sampler
300  ) const;
301 
302  //- Sample volume field onto surface faces
303  virtual tmp<vectorField> sample
304  (
305  const interpolation<vector>& sampler
306  ) const;
307 
308  //- Sample volume field onto surface faces
310  (
311  const interpolation<sphericalTensor>& sampler
312  ) const;
313 
314  //- Sample volume field onto surface faces
316  (
317  const interpolation<symmTensor>& sampler
318  ) const;
319 
320  //- Sample volume field onto surface faces
321  virtual tmp<tensorField> sample
322  (
323  const interpolation<tensor>& sampler
324  ) const;
325 
326 
327  // Interpolate
328 
329  //- Interpolate volume field onto surface points
331  (
332  const interpolation<scalar>& interpolator
333  ) const;
334 
335  //- Interpolate volume field onto surface points
337  (
338  const interpolation<vector>& interpolator
339  ) const;
340 
341  //- Interpolate volume field onto surface points
343  (
344  const interpolation<sphericalTensor>& interpolator
345  ) const;
346 
347  //- Interpolate volume field onto surface points
349  (
350  const interpolation<symmTensor>& interpolator
351  ) const;
352 
353  //- Interpolate volume field onto surface points
355  (
356  const interpolation<tensor>& interpolator
357  ) const;
358 
359 
360  // Output
361 
362  //- Write
363  virtual void print(Ostream& os) const;
364 };
365 
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 } // End namespace Foam
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 #ifdef NoRepository
375 #endif
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 #endif
380 
381 // ************************************************************************* //
Foam::MeshedSurface< face >::faceIds
const labelList & faceIds() const
Return const access to faces ids.
Definition: MeshedSurface.H:419
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::sampledMeshedSurface::magSf
virtual const scalarField & magSf() const
Face area magnitudes.
Definition: sampledMeshedSurface.H:314
Foam::Enum< samplingSource >
Foam::sampledMeshedSurface::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledMeshedSurface.C:584
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::sampledMeshedSurface::samplingSource
samplingSource
Types of sampling regions.
Definition: sampledMeshedSurface.H:171
Foam::sampledMeshedSurface::sampledMeshedSurface
sampledMeshedSurface(const word &name, const polyMesh &mesh, const word &surfaceName, const samplingSource sampleSource)
Construct from components.
Definition: sampledMeshedSurface.C:469
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::sampledMeshedSurface::faceIds
virtual const labelList & faceIds() const
Per-face identifier (eg, element Id)
Definition: sampledMeshedSurface.H:302
Foam::MeshedSurface< face >::Sf
const vectorField & Sf() const
Face area vectors (normals)
Definition: MeshedSurface.H:433
Foam::MeshedSurface< face >::surfFaces
const List< face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:411
Foam::sampledMeshedSurface::Sf
virtual const vectorField & Sf() const
Face area vectors.
Definition: sampledMeshedSurface.H:308
Foam::sampledMeshedSurface::update
virtual bool update()
Update the surface as required.
Definition: sampledMeshedSurface.C:610
Foam::sampledMeshedSurface::onBoundary
bool onBoundary() const
Sampling boundary values instead of cell values.
Definition: sampledMeshedSurface.H:332
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::MeshedSurface< face >::magSf
const scalarField & magSf() const
Face area magnitudes.
Definition: MeshedSurface.H:439
Foam::Field< vector >
sampledSurface.H
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
Foam::sampledMeshedSurface::cells
Definition: sampledMeshedSurface.H:173
Foam::sampledMeshedSurface::boundaryFaces
Definition: sampledMeshedSurface.H:175
Foam::sampledMeshedSurface::print
virtual void print(Ostream &os) const
Write.
Definition: sampledMeshedSurface.C:759
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:95
Foam::sampledMeshedSurface::hasFaceIds
virtual bool hasFaceIds() const
If element ids/order of the original surface are kept.
Definition: sampledMeshedSurface.H:326
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:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledMeshedSurface
A sampledSurface from a meshed surface. It samples on the points/faces of the meshed surface.
Definition: sampledMeshedSurface.H:164
Foam::sampledMeshedSurface::~sampledMeshedSurface
virtual ~sampledMeshedSurface()=default
Destructor.
Foam::sampledMeshedSurface::points
virtual const pointField & points() const
Points of surface.
Definition: sampledMeshedSurface.H:284
Foam::sampledMeshedSurface::insideCells
Definition: sampledMeshedSurface.H:174
Foam::meshedSurface
MeshedSurface< face > meshedSurface
Definition: MeshedSurfacesFwd.H:41
Foam::List< label >
Foam::sampledSurface::name
const word & name() const
Name of surface.
Definition: sampledSurface.H:308
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::sampledMeshedSurface::faces
virtual const faceList & faces() const
Faces of surface.
Definition: sampledMeshedSurface.H:290
Foam::MeshedSurface< face >::Cf
const vectorField & Cf() const
Face centres.
Definition: MeshedSurface.H:445
Foam::sampledSurface::mesh
const polyMesh & mesh() const
Access to the underlying mesh.
Definition: sampledSurface.H:302
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::sampledMeshedSurface::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledMeshedSurface.C:590
Foam::sampledMeshedSurface::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledMeshedSurface.C:671
Foam::sampledMeshedSurface::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: sampledMeshedSurface.H:296
MeshedSurfacesFwd.H
Foam::MeshedSurface< face >
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
sampledMeshedSurfaceTemplates.C
Foam::sampledMeshedSurface::Cf
virtual const vectorField & Cf() const
Face centres.
Definition: sampledMeshedSurface.H:320
Foam::sampledMeshedSurface::TypeName
TypeName("sampledMeshedSurface")
Declare type-name, virtual type (with debug switch)
MeshedSurface.H