sampledTriSurfaceMesh.H
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-2020 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 Class
25  Foam::sampledSurfaces::triSurfaceMesh
26 
27 Description
28  A sampledSurface from a triSurfaceMesh. It samples on the points/triangles
29  of the triSurface. It either samples cells or (non-coupled) boundary faces.
30 
31  There are 6 possible modes:
32 
33  - source=cells, interpolate=false:
34  Finds per triangle centre the nearest cell centre and uses its value.
35 
36  - source=cells, interpolate=true
37  Finds per triangle centre the nearest cell centre. Per surface point
38  checks if this nearest cell is the one containing point; otherwise
39  projects the point onto the nearest point on the boundary of the cell
40  (to make sure interpolateCellPoint gets a valid location)
41 
42  - source=insideCells, interpolate=false:
43  Finds per triangle centre the cell containing it and uses its value.
44  Trims triangles outside mesh.
45 
46  - source=insideCells, interpolate=true
47  Per surface point interpolate cell containing it.
48 
49  - source=boundaryFaces, interpolate=false:
50  Finds per triangle centre the nearest point on the boundary (uncoupled
51  faces only) and uses the value (or 0 if the nearest is on an empty
52  boundary).
53 
54  - source=boundaryFaces, interpolate=true:
55  Finds per triangle centre the nearest point on the boundary (uncoupled
56  faces only). Per surface point projects the point onto this boundary
57  face (to make sure interpolateCellPoint gets a valid location)
58 
59  Since it finds a nearest per triangle each triangle is guaranteed to be on
60  one processor only. So after stitching (by sampledSurfaces) the original
61  surface should be complete.
62 
63  Example:
64  \verbatim
65  {
66  type triSurfaceMesh;
67  surface "surface.stl";
68  source cells;
69  interpolate yes;
70  }
71  \endverbatim
72 
73 Usage
74  \table
75  Property | Description | Required | Default value
76  surface | the surface file (within constant/triSurface) | yes |
77  source | see above | yes | no
78  interpolate | see above | no | no
79  \endtable
80 
81 SourceFiles
82  sampledTriSurfaceMesh.C
83 
84 \*---------------------------------------------------------------------------*/
85 
86 #ifndef sampledTriSurfaceMesh_H
87 #define sampledTriSurfaceMesh_H
88 
89 #include "sampledSurface.H"
90 #include "triSurfaceMesh.H"
91 #include "MeshedSurface.H"
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 namespace Foam
96 {
97 
98  class treeDataFace;
99  class meshSearch;
100 
101 namespace sampledSurfaces
102 {
103 
104 /*---------------------------------------------------------------------------*\
105  Class triSurfaceMesh Declaration
106 \*---------------------------------------------------------------------------*/
107 
108 class triSurfaceMesh
109 :
110  public sampledSurface,
111  public MeshedSurface<face>
112 {
113 public:
114  //- Types of communications
115  enum samplingSource
116  {
117  cells,
118  insideCells,
120  };
121 
122 private:
123 
124  // Private Typedefs
125 
126  typedef MeshedSurface<face> MeshStorage;
128 
129  // Private Data
130 
131  static const NamedEnum<samplingSource, 3> samplingSourceNames_;
132 
133  //- Surface to sample on
134  const Foam::triSurfaceMesh surface_;
135 
136  //- Whether to sample internal cell values or boundary values
137  const samplingSource sampleSource_;
139  //- Track if the surface needs an update
140  mutable bool needsUpdate_;
141 
142  //- Search tree for all non-coupled boundary faces
143  mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
144 
145  //- From local surface triangle to mesh cell/face.
146  labelList sampleElements_;
147 
148  //- Local points to sample per point
149  pointField samplePoints_;
150 
151 
152  // Private Member Functions
153 
154  //- Get tree of all non-coupled boundary faces
155  const indexedOctree<treeDataFace>& nonCoupledboundaryTree() const;
156 
157  //- Sample field on faces
158  template<class Type>
159  tmp<Field<Type>> sampleField
160  (
162  ) const;
163 
164 
165  template<class Type>
167  interpolateField(const interpolation<Type>&) const;
168 
169  bool update(const meshSearch& meshSearcher);
170 
171 public:
172 
173  //- Runtime type information
174  TypeName("triSurfaceMesh");
175 
176 
177  // Constructors
178 
179  //- Construct from components
181  (
182  const word& name,
183  const polyMesh& mesh,
184  const word& surfaceName,
185  const samplingSource sampleSource
186  );
187 
188  //- Construct from dictionary
190  (
191  const word& name,
192  const polyMesh& mesh,
193  const dictionary& dict
194  );
195 
196  //- Construct from triSurface
198  (
199  const word& name,
200  const polyMesh& mesh,
201  const triSurface& surface,
202  const word& sampleSourceName
203  );
204 
205 
206  //- Destructor
207  virtual ~triSurfaceMesh();
208 
209 
210  // Member Functions
211 
212  //- Does the surface need an update?
213  virtual bool needsUpdate() const;
214 
215  //- Mark the surface as needing an update.
216  // May also free up unneeded data.
217  // Return false if surface was already marked as expired.
218  virtual bool expire();
219 
220  //- Update the surface as required.
221  // Do nothing (and return false) if no update was needed
222  virtual bool update();
223 
224  //- Update the surface using a bound box to limit the searching.
225  // For direct use, i.e. not through sample.
226  // Do nothing (and return false) if no update was needed
227  bool update(const treeBoundBox&);
228 
229  //- Points of surface
230  virtual const pointField& points() const
231  {
232  return MeshStorage::points();
233  }
234 
235  //- Faces of surface
236  virtual const faceList& faces() const
237  {
238  return MeshStorage::faces();
239  }
240 
241 
242  //- Sample field on surface
243  virtual tmp<scalarField> sample
244  (
245  const volScalarField&
246  ) const;
247 
248  //- Sample field on surface
250  (
251  const volVectorField&
252  ) const;
253 
254  //- Sample field on surface
256  (
258  ) const;
259 
260  //- Sample field on surface
262  (
263  const volSymmTensorField&
264  ) const;
265 
266  //- Sample field on surface
267  virtual tmp<tensorField> sample
268  (
269  const volTensorField&
270  ) const;
271 
272 
273  //- Interpolate field on surface
275  (
276  const interpolation<scalar>&
277  ) const;
278 
279 
280  //- Interpolate field on surface
282  (
283  const interpolation<vector>&
284  ) const;
285 
286  //- Interpolate field on surface
288  (
290  ) const;
291 
292  //- Interpolate field on surface
294  (
296  ) const;
297 
298  //- Interpolate field on surface
300  (
301  const interpolation<tensor>&
302  ) const;
303 
304  //- Write
305  virtual void print(Ostream&) const;
306 };
307 
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 } // End namespace sampledSurfaces
312 } // End namespace Foam
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 #ifdef NoRepository
318 #endif
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #endif
323 
324 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Name of surface.
triSurfaceMesh(const word &name, const polyMesh &mesh, const word &surfaceName, const samplingSource sampleSource)
Construct from components.
bool interpolate() const
Interpolation requested for surface.
virtual bool update()
Update the surface as required.
Generic GeometricField class.
A surface geometry formed of discrete facets, e.g. triangles and/or quadrilaterals, defined in a file using formats such as Wavefront OBJ, or stereolithography STL.
virtual void print(Ostream &) const
Write.
A class for handling words, derived from string.
Definition: word.H:59
const Field< PointType > & points() const
Return reference to global points.
virtual const faceList & faces() const
Faces of surface.
const polyMesh & mesh() const
Access to the underlying mesh.
virtual bool expire()
Mark the surface as needing an update.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const List< face > & faces() const
Return const access to the faces.
TypeName("triSurfaceMesh")
Runtime type information.
virtual const pointField & points() const
Points of surface.
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
Abstract base class for interpolation.
virtual bool needsUpdate() const
Does the surface need an update?
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
A class for managing temporary objects.
Definition: PtrList.H:53
Triangulated surface description with patch information.
Definition: triSurface.H:66
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
Namespace for OpenFOAM.