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-2026 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  //- Update the surface as required.
214  // Do nothing (and return false) if no update was needed
215  virtual bool update();
216 
217  //- Points of surface
218  virtual const pointField& points() const
219  {
221  }
222 
223  //- Faces of surface
224  virtual const faceList& faces() const
225  {
227  }
228 
229  //- Sample field on the surface's faces
230  #define DEFINE_SAMPLE(Type, nullArg) \
231  virtual tmp<Field<Type>> sample \
232  ( \
233  const VolField<Type>& \
234  ) const;
236  #undef DEFINE_SAMPLE
237 
238  //- Interpolate field to the surface's points
239  #define DEFINE_INTERPOLATE(Type, nullArg) \
240  virtual tmp<Field<Type>> interpolate \
241  ( \
242  const interpolation<Type>& \
243  ) const;
245  #undef DEFINE_INTERPOLATE
246 
247  //- Update for mesh point-motion
248  virtual void movePoints();
249 
250  //- Update topology using the given map
251  virtual void topoChange(const polyTopoChangeMap&);
252 
253  //- Update from another mesh using the given map
254  virtual void mapMesh(const polyMeshMap&);
255 
256  //- Redistribute or update using the given distribution map
257  virtual void distribute(const polyDistributionMap&);
258 
259  //- Write
260  virtual void print(Ostream&) const;
261 };
262 
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 } // End namespace sampledSurfaces
267 } // End namespace Foam
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #ifdef NoRepository
273 #endif
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
Generic GeometricField class.
const List< Face > & faces() const
Return const access to the faces.
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.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
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.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void movePoints()
Update for mesh point-motion.
samplingSource
Types of communications.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
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:68
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
#define DEFINE_SAMPLE(Type, nullArg)
Sample field on the surface's faces.
#define DEFINE_INTERPOLATE(Type, nullArg)
Interpolate field to the surface's points.
dictionary dict