sampledTriSurfaceMesh.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-2018 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::sampledTriSurfaceMesh
29 
30 Description
31  A sampledSurface from a triSurfaceMesh. It samples on the points/triangles
32  of the triSurface.
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 sampledTriSurfaceMesh;
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 | sampledTriSurfaceMesh | yes |
86  surface | surface name in triSurface/ | yes |
87  source | cells/insideCells/boundaryFaces | yes |
88  keepIds | pass through id numbering | no | false
89  \endtable
90 
91 SourceFiles
92  sampledTriSurfaceMesh.C
93  sampledTriSurfaceMeshTemplates.C
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef sampledTriSurfaceMesh_H
98 #define sampledTriSurfaceMesh_H
99 
100 #include "sampledSurface.H"
101 #include "triSurfaceMesh.H"
102 #include "MeshedSurface.H"
103 #include "MeshedSurfacesFwd.H"
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 namespace Foam
108 {
109 
110 class treeDataFace;
111 class meshSearch;
112 
113 /*---------------------------------------------------------------------------*\
114  Class sampledTriSurfaceMesh Declaration
115 \*---------------------------------------------------------------------------*/
116 
117 class sampledTriSurfaceMesh
118 :
119  public sampledSurface,
120  public meshedSurface
121 {
122 public:
123  //- Types of communications
124  enum samplingSource
125  {
126  cells,
127  insideCells,
129  };
130 
131 private:
132 
133  //- Private typedefs for convenience
134  typedef meshedSurface MeshStorage;
135 
136 
137  // Private data
138 
139  static const Enum<samplingSource> samplingSourceNames_;
140 
141  //- Surface to sample on
142  const triSurfaceMesh surface_;
143 
144  //- Whether to sample internal cell values or boundary values
145  const samplingSource sampleSource_;
146 
147  //- Track if the surface needs an update
148  mutable bool needsUpdate_;
149 
150  //- Retain element ids/order of original surface
151  bool keepIds_;
152 
153  //- List of element ids/order of the original surface,
154  // when keepIds is active.
155  labelList originalIds_;
156 
157  //- Search tree for all non-coupled boundary faces
158  mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
159 
160  //- For compatibility with the meshSurf interface
161  labelList zoneIds_;
162 
163  //- From local surface triangle to mesh cell/face.
164  labelList sampleElements_;
165 
166  //- Local points to sample per point
167  pointField samplePoints_;
168 
169 
170  // Private Member Functions
171 
172  //- Get tree of all non-coupled boundary faces
173  const indexedOctree<treeDataFace>& nonCoupledboundaryTree() const;
174 
175  //- Sample volume field onto surface faces
176  template<class Type>
177  tmp<Field<Type>> sampleOnFaces
178  (
179  const interpolation<Type>& sampler
180  ) const;
181 
182  //- Interpolate volume field onto surface points
183  template<class Type>
184  tmp<Field<Type>> sampleOnPoints
185  (
186  const interpolation<Type>& interpolator
187  ) const;
188 
189  bool update(const meshSearch& meshSearcher);
190 
191 public:
192 
193  //- Runtime type information
194  TypeName("sampledTriSurfaceMesh");
195 
196 
197  // Constructors
198 
199  //- Construct from components
201  (
202  const word& name,
203  const polyMesh& mesh,
204  const word& surfaceName,
205  const samplingSource sampleSource
206  );
207 
208  //- Construct from dictionary
210  (
211  const word& name,
212  const polyMesh& mesh,
213  const dictionary& dict
214  );
215 
216  //- Construct from triSurface
218  (
219  const word& name,
220  const polyMesh& mesh,
221  const triSurface& surface,
222  const word& sampleSourceName
223  );
224 
225 
226  //- Destructor
227  virtual ~sampledTriSurfaceMesh();
228 
229 
230  // Member Functions
231 
232  //- Set new zoneIds list based on the surfZoneList information
233  static void setZoneMap
234  (
235  const surfZoneList& zoneLst,
237  );
238 
239 
240  //- Does the surface need an update?
241  virtual bool needsUpdate() const;
242 
243  //- Mark the surface as needing an update.
244  // May also free up unneeded data.
245  // Return false if surface was already marked as expired.
246  virtual bool expire();
247 
248  //- Update the surface as required.
249  // Do nothing (and return false) if no update was needed
250  virtual bool update();
251 
252  //- Update the surface using a bound box to limit the searching.
253  // For direct use, i.e. not through sample.
254  // Do nothing (and return false) if no update was needed
255  bool update(const treeBoundBox& bb);
256 
257  //- Points of surface
258  virtual const pointField& points() const
259  {
260  return MeshStorage::points();
261  }
262 
263  //- Faces of surface
264  virtual const faceList& faces() const
265  {
266  return MeshStorage::surfFaces();
267  }
268 
269  //- Per-face zone/region information
270  virtual const labelList& zoneIds() const
271  {
272  return zoneIds_;
273  }
274 
275  //- Face area vectors
276  virtual const vectorField& Sf() const
277  {
278  return MeshStorage::Sf();
279  }
280 
281  //- Face area magnitudes
282  virtual const scalarField& magSf() const
283  {
284  return MeshStorage::magSf();
285  }
286 
287  //- Face centres
288  virtual const vectorField& Cf() const
289  {
290  return MeshStorage::Cf();
291  }
292 
293  //- If element ids/order of the original surface are kept
294  virtual bool hasFaceIds() const
295  {
296  return keepIds_;
297  }
298 
299  //- List of element ids/order of the original surface,
300  // when keepIds is active.
301  virtual const labelList& originalIds() const
302  {
303  return originalIds_;
304  }
305 
306  //- Sampling boundary values instead of cell values
307  bool onBoundary() const
308  {
309  return sampleSource_ == boundaryFaces;
310  }
311 
312 
313  // Sample
314 
315  //- Sample volume field onto surface faces
316  virtual tmp<scalarField> sample
317  (
318  const interpolation<scalar>& sampler
319  ) const;
320 
321  //- Sample volume field onto surface faces
322  virtual tmp<vectorField> sample
323  (
324  const interpolation<vector>& sampler
325  ) const;
326 
327  //- Sample volume field onto surface faces
329  (
330  const interpolation<sphericalTensor>& sampler
331  ) const;
332 
333  //- Sample volume field onto surface faces
335  (
336  const interpolation<symmTensor>& sampler
337  ) const;
338 
339  //- Sample volume field onto surface faces
340  virtual tmp<tensorField> sample
341  (
342  const interpolation<tensor>& sampler
343  ) const;
344 
345 
346  // Interpolate
347 
348  //- Interpolate volume field onto surface points
350  (
351  const interpolation<scalar>& interpolator
352  ) const;
353 
354  //- Interpolate volume field onto surface points
356  (
357  const interpolation<vector>& interpolator
358  ) const;
359 
360  //- Interpolate volume field onto surface points
362  (
363  const interpolation<sphericalTensor>& interpolator
364  ) const;
365 
366  //- Interpolate volume field onto surface points
368  (
369  const interpolation<symmTensor>& interpolator
370  ) const;
371 
372  //- Interpolate volume field onto surface points
374  (
375  const interpolation<tensor>& interpolator
376  ) const;
377 
378 
379  // Output
380 
381  //- Write
382  virtual void print(Ostream& os) const;
383 };
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #ifdef NoRepository
394 #endif
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 #endif
399 
400 // ************************************************************************* //
Foam::sampledTriSurfaceMesh::points
virtual const pointField & points() const
Points of surface.
Definition: sampledTriSurfaceMesh.H:282
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::sampledTriSurfaceMesh::cells
Definition: sampledTriSurfaceMesh.H:150
Foam::Enum< samplingSource >
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::sampledTriSurfaceMesh::faces
virtual const faceList & faces() const
Faces of surface.
Definition: sampledTriSurfaceMesh.H:288
Foam::sampledTriSurfaceMesh::needsUpdate
virtual bool needsUpdate() const
Does the surface need an update?
Definition: sampledTriSurfaceMesh.C:736
Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
sampledTriSurfaceMesh(const word &name, const polyMesh &mesh, const word &surfaceName, const samplingSource sampleSource)
Construct from components.
Definition: sampledTriSurfaceMesh.C:629
Foam::sampledTriSurfaceMesh::update
virtual bool update()
Update the surface as required.
Definition: sampledTriSurfaceMesh.C:764
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::sampledTriSurfaceMesh::sample
virtual tmp< scalarField > sample(const interpolation< scalar > &sampler) const
Sample volume field onto surface faces.
Definition: sampledTriSurfaceMesh.C:829
Foam::sampledTriSurfaceMesh::samplingSource
samplingSource
Types of communications.
Definition: sampledTriSurfaceMesh.H:148
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::MeshedSurface< face >::Sf
const vectorField & Sf() const
Face area vectors (normals)
Definition: MeshedSurface.H:376
Foam::MeshedSurface< face >::surfFaces
const List< face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:362
Foam::sampledTriSurfaceMesh::onBoundary
bool onBoundary() const
Sampling boundary values instead of cell values.
Definition: sampledTriSurfaceMesh.H:331
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:100
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::sampledTriSurfaceMesh
A sampledSurface from a triSurfaceMesh. It samples on the points/triangles of the triSurface.
Definition: sampledTriSurfaceMesh.H:141
Foam::MeshedSurface< face >::magSf
const scalarField & magSf() const
Face area magnitudes.
Definition: MeshedSurface.H:382
Foam::Field< vector >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:70
sampledSurface.H
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:50
Foam::sampledTriSurfaceMesh::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: sampledTriSurfaceMesh.H:294
Foam::sampledSurface
An abstract class for surfaces with sampling.
Definition: sampledSurface.H:120
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:95
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::sampledTriSurfaceMesh::TypeName
TypeName("sampledTriSurfaceMesh")
Runtime type information.
Foam::sampledTriSurfaceMesh::Sf
virtual const vectorField & Sf() const
Face area vectors.
Definition: sampledTriSurfaceMesh.H:300
Foam::sampledTriSurfaceMesh::boundaryFaces
Definition: sampledTriSurfaceMesh.H:152
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sampledTriSurfaceMesh::insideCells
Definition: sampledTriSurfaceMesh.H:151
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::sampledTriSurfaceMesh::setZoneMap
static void setZoneMap(const surfZoneList &zoneLst, labelList &zoneIds)
Set new zoneIds list based on the surfZoneList information.
Definition: sampledTriSurfaceMesh.C:87
Foam::meshedSurface
MeshedSurface< face > meshedSurface
Definition: MeshedSurfacesFwd.H:41
Foam::sampledTriSurfaceMesh::hasFaceIds
virtual bool hasFaceIds() const
If element ids/order of the original surface are kept.
Definition: sampledTriSurfaceMesh.H:318
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
sampledTriSurfaceMeshTemplates.C
Foam::sampledTriSurfaceMesh::magSf
virtual const scalarField & magSf() const
Face area magnitudes.
Definition: sampledTriSurfaceMesh.H:306
Foam::sampledTriSurfaceMesh::Cf
virtual const vectorField & Cf() const
Face centres.
Definition: sampledTriSurfaceMesh.H:312
Foam::sampledTriSurfaceMesh::~sampledTriSurfaceMesh
virtual ~sampledTriSurfaceMesh()
Destructor.
Definition: sampledTriSurfaceMesh.C:730
Foam::MeshedSurface< face >::Cf
const vectorField & Cf() const
Face centres.
Definition: MeshedSurface.H:388
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
MeshedSurfacesFwd.H
Foam::MeshedSurface< face >
Foam::sampledTriSurfaceMesh::expire
virtual bool expire()
Mark the surface as needing an update.
Definition: sampledTriSurfaceMesh.C:742
Foam::sampledSurface::interpolate
bool interpolate() const
Interpolation to nodes requested for surface.
Definition: sampledSurface.H:326
triSurfaceMesh.H
Foam::sampledTriSurfaceMesh::originalIds
virtual const labelList & originalIds() const
List of element ids/order of the original surface,.
Definition: sampledTriSurfaceMesh.H:325
Foam::sampledTriSurfaceMesh::print
virtual void print(Ostream &os) const
Write.
Definition: sampledTriSurfaceMesh.C:917
MeshedSurface.H