sampledTriSurface.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-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 Class
25  Foam::sampledSurfaces::triSurface
26 
27 Description
28  A sampledSurface from a triSurface. 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 triSurface;
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  sampledTriSurface.C
83 
84 \*---------------------------------------------------------------------------*/
85 
86 #ifndef sampledTriSurface_H
87 #define sampledTriSurface_H
88 
89 #include "sampledSurface.H"
91 #include "MeshedSurface.H"
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 namespace Foam
96 {
97 
98 class treeDataFace;
99 
100 namespace sampledSurfaces
101 {
102 
103 /*---------------------------------------------------------------------------*\
104  Class triSurface Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 class triSurface
108 :
109  public sampledSurface,
110  public MeshedSurface<face>
111 {
112 public:
113 
114  // Public Typedefs
115 
116  //- Types of communications
117  enum samplingSource
118  {
119  cells,
120  insideCells,
122  };
123 
124  //- Names of communication types
125  static const NamedEnum<samplingSource, 3> samplingSourceNames_;
126 
127 
128 private:
129 
130  // Private Data
131 
132  //- Surface to sample on
133  const searchableSurfaces::triSurface surface_;
134 
135  //- Whether to sample internal cell values or boundary values
136  const samplingSource sampleSource_;
137 
138  //- Track if the surface needs an update
139  mutable bool needsUpdate_;
140 
141  //- Search tree for all non-coupled boundary faces
142  mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
143 
144  //- From local surface triangle to mesh cell/face.
145  labelList sampleElements_;
146 
147  //- Local points to sample per point
148  pointField samplePoints_;
149 
150 
151  // Private Member Functions
152 
153  //- Get tree of all non-coupled boundary faces
154  const indexedOctree<treeDataFace>& nonCoupledboundaryTree() const;
155 
156  //- Sample field on surface
157  template<class Type>
158  tmp<Field<Type>> sampleField
159  (
160  const VolField<Type>& vField
161  ) const;
162 
163  //- Interpolate field on surface
164  template<class Type>
166  interpolateField(const interpolation<Type>&) const;
167 
168 
169 public:
170 
171  //- Runtime type information
172  TypeName("triSurface");
173 
174 
175  // Constructors
176 
177  //- Construct from components
178  triSurface
179  (
180  const word& name,
181  const polyMesh& mesh,
182  const word& surfaceName,
183  const samplingSource sampleSource
184  );
185 
186  //- Construct from dictionary
187  triSurface
188  (
189  const word& name,
190  const polyMesh& mesh,
192  );
193 
194  //- Construct from triSurface
195  triSurface
196  (
197  const word& name,
198  const polyMesh& mesh,
199  const Foam::triSurface& surface,
200  const word& sampleSourceName
201  );
202 
203 
204  //- Destructor
205  virtual ~triSurface();
206 
207 
208  // Member Functions
209 
210  //- Does the surface need an update?
211  virtual bool needsUpdate() const;
212 
213  //- Mark the surface as needing an update.
214  // May also free up unneeded data.
215  // Return false if surface was already marked as expired.
216  virtual bool expire();
217 
218  //- Update the surface as required.
219  // Do nothing (and return false) if no update was needed
220  virtual bool update();
221 
222  //- Points of surface
223  virtual const pointField& points() const
224  {
226  }
227 
228  //- Faces of surface
229  virtual const faceList& faces() const
230  {
232  }
233 
234 
235  //- Sample field on surface
236  virtual tmp<scalarField> sample
237  (
238  const volScalarField&
239  ) const;
240 
241  //- Sample field on surface
243  (
244  const volVectorField&
245  ) const;
246 
247  //- Sample field on surface
249  (
251  ) const;
252 
253  //- Sample field on surface
255  (
256  const volSymmTensorField&
257  ) const;
258 
259  //- Sample field on surface
260  virtual tmp<tensorField> sample
261  (
262  const volTensorField&
263  ) const;
264 
265 
266  //- Interpolate field on surface
268  (
269  const interpolation<scalar>&
270  ) const;
271 
272  //- Interpolate field on surface
274  (
275  const interpolation<vector>&
276  ) const;
277 
278  //- Interpolate field on surface
280  (
282  ) const;
283 
284  //- Interpolate field on surface
286  (
288  ) const;
289 
290  //- Interpolate field on surface
292  (
293  const interpolation<tensor>&
294  ) const;
295 
296  //- Write
297  virtual void print(Ostream&) const;
298 };
299 
300 
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 
303 } // End namespace sampledSurfaces
304 } // End namespace Foam
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 #ifdef NoRepository
310 #endif
311 
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 
314 #endif
315 
316 // ************************************************************************* //
Generic GeometricField class.
const List< Face > & faces() const
Return const access to the faces.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const Field< PointType > & points() const
Return reference to global points.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Non-pointer based hierarchical recursive searching.
Definition: indexedOctree.H:72
Abstract base class for interpolation.
Definition: interpolation.H:55
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
bool interpolate() const
Interpolation requested for surface.
const word & name() const
Name of surface.
const polyMesh & mesh() const
Access to the underlying mesh.
triSurface(const word &name, const polyMesh &mesh, const word &surfaceName, const samplingSource sampleSource)
Construct from components.
static const NamedEnum< samplingSource, 3 > samplingSourceNames_
Names of communication types.
samplingSource
Types of communications.
virtual tmp< scalarField > sample(const volScalarField &) const
Sample field on surface.
virtual bool expire()
Mark the surface as needing an update.
virtual bool needsUpdate() const
Does the surface need an update?
virtual bool update()
Update the surface as required.
virtual void print(Ostream &) const
Write.
virtual const faceList & faces() const
Faces of surface.
TypeName("triSurface")
Runtime type information.
virtual const pointField & points() const
Points of surface.
A surface geometry formed of discrete facets, e.g. triangles and/or quadrilaterals,...
A class for managing temporary objects.
Definition: tmp.H:55
Triangulated surface description with patch information.
Definition: triSurface.H:69
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
dictionary dict