surfaceToCell.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) 2018-2024 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::surfaceToCell
29 
30 Description
31  A \c topoSetCellSource to select cells based on
32  relation to a surface given by an external file.
33 
34  \c surfaceToCell can select:
35  - all cells inside/outside/cut by a surface
36  - all cells inside/outside surface (\c useSurfaceOrientation,
37  requires closed surface)
38  - cells with centre nearer than XXX to surface
39  - cells with centre nearer than XXX to surface \b and with normal
40  at nearest point to centre and cell-corners differing by
41  more than YYY (i.e. point of high curvature)
42 
43  Operands:
44  \table
45  Operand | Type | Location
46  input | triSurface | $FOAM_CASE/constant/triSurface/<file>
47  output | cellSet | $FOAM_CASE/constant/polyMesh/sets/<set>
48  \endtable
49 
50 Usage
51  Minimal example by using \c system/topoSetDict.actions:
52  \verbatim
53  {
54  // Mandatory (inherited) entries
55  name <name>;
56  type cellSet;
57  action <action>;
58 
59  // Mandatory entries
60  source surfaceToCell;
61  file <surfaceFileName>;
62  outsidePoints
63  (
64  (<p1x> <p1y> <p1z>)
65  (<p2x> <p2y> <p2z>)
66  ...
67  );
68  includeCut false;
69  includeInside false;
70  includeOutside true;
71  nearDistance 0.5;
72  curvature 1.0;
73 
74  // Optional entries
75  useSurfaceOrientation false;
76  fileType stl;
77  scale 2.0;
78  }
79  \endverbatim
80 
81  where the entries mean:
82  \table
83  Property | Description | Type | Req'd | Dflt
84  name | Name of cellSet | word | yes | -
85  type | Type name: cellSet | word | yes | -
86  action | Action applied on cells - see below | word | yes | -
87  source | Source name: surfaceToCell | word | yes | -
88  file | The surface "filename" | word | yes | -
89  outsidePoints | List of points that define outside of the surface <!--
90  --> | vectorList | yes | -
91  includeCut | Flag to include cut cells | bool | yes | -
92  includeInside | Flag to include inside cells | bool | yes | -
93  includeOutside | Flag to include outside cells | bool | yes | -
94  useSurfaceOrientation | Flag to use inherently the orientation of <!--
95  --> the surface | bool | no | false
96  nearDistance | Near distance to the surface | scalar | yes | -
97  curvature | Surface curvature | scalar | yes | -
98  fileType | The format of the surface file | word | no | ""
99  scale | Surface scaling factor | scalar | no | -1
100  \endtable
101 
102  Options for the \c action entry:
103  \verbatim
104  new | Create a new cellSet from selected cells
105  add | Add selected cells into this cellSet
106  subtract | Remove selected cells from this cellSet
107  \endverbatim
108 
109 See also
110  - Foam::topoSetSource
111  - Foam::topoSetCellSource
112 
113 SourceFiles
114  surfaceToCell.C
115 
116 \*---------------------------------------------------------------------------*/
117 
118 #ifndef Foam_surfaceToCell_H
119 #define Foam_surfaceToCell_H
120 
121 #include "topoSetCellSource.H"
122 #include "refPtr.H"
123 #include "Map.H"
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 namespace Foam
128 {
129 
130 // Forward Declarations
131 class triSurface;
132 class triSurfaceSearch;
133 
134 /*---------------------------------------------------------------------------*\
135  Class surfaceToCell Declaration
136 \*---------------------------------------------------------------------------*/
137 
138 class surfaceToCell
139 :
140  public topoSetCellSource
141 {
142  // Private Data
143 
144  //- Add usage string
145  static addToUsageTable usage_;
146 
147  //- Name of surface file
148  const fileName surfName_;
149 
150  //- Points which are outside
151  const pointField outsidePoints_;
152 
153  //- Include cut cells
154  const bool includeCut_;
155 
156  //- Include inside cells
157  const bool includeInside_;
158 
159  //- Include outside cells
160  const bool includeOutside_;
161 
162  //- Determine inside/outside purely using geometric test
163  // (does not allow includeCut)
164  const bool useSurfaceOrientation_;
165 
166  //- If > 0 : include cells with distance from cellCentre to surface
167  // less than nearDist.
168  const scalar nearDist_;
169 
170  //- If > -1 : include cells with normals at nearest surface points
171  // varying more than curvature_.
172  const scalar curvature_;
173 
174  //- triSurface to search on (can be external reference)
175  const refPtr<triSurface> surfPtr_;
176 
177  //- Search engine on surface.
178  const refPtr<triSurfaceSearch> querySurfPtr_;
179 
180 
181  // Private Member Functions
182 
183  //- Find index of nearest triangle to point. Returns triangle or -1 if
184  // not found within search span.
185  // Cache result under pointi.
186  static label getNearest
187  (
188  const triSurfaceSearch& querySurf,
189  const label pointi,
190  const point& pt,
191  const vector& searchSpan,
192  Map<label>& cache
193  );
194 
195  //- Return true if surface normal of nearest points to vertices on
196  // cell differ from that on cell centre. Points cached in
197  // pointToNearest.
198  bool differingPointNormals
199  (
200  const triSurfaceSearch& querySurf,
201  const vector& span,
202  const label celli,
203  const label cellTriI,
204  Map<label>& pointToNearest
205  ) const;
206 
207 
208  //- Depending on surface add to or delete from cellSet.
209  void combine(topoSet& set, const bool add) const;
210 
211  //- Check values at construction time.
212  void checkSettings() const;
213 
214  const triSurfaceSearch& querySurf() const
215  {
216  return *querySurfPtr_;
217  }
218 
219 
220 public:
221 
222  //- Runtime type information
223  TypeName("surfaceToCell");
224 
225  // Constructors
226 
227  //- Construct from components
229  (
230  const polyMesh& mesh,
231  const fileName& surfName,
232  const pointField& outsidePoints,
233  const bool includeCut,
234  const bool includeInside,
235  const bool includeOutside,
236  const bool useSurfaceOrientation,
237  const scalar nearDist,
238  const scalar curvature
239  );
240 
241  //- Construct from components (supplied surface, surfaceSearch)
243  (
244  const polyMesh& mesh,
245  const fileName& surfName,
246  const triSurface& surf,
247  const triSurfaceSearch& querySurf,
248  const pointField& outsidePoints,
249  const bool includeCut,
250  const bool includeInside,
251  const bool includeOutside,
252  const bool useSurfaceOrientation,
253  const scalar nearDist,
254  const scalar curvature
255  );
256 
257  //- Construct from dictionary
258  surfaceToCell(const polyMesh& mesh, const dictionary& dict);
259 
260  //- Construct from Istream
261  surfaceToCell(const polyMesh& mesh, Istream& is);
262 
263 
264  //- Destructor
265  virtual ~surfaceToCell();
266 
267 
268  // Member Functions
269 
270  virtual void applyToSet
271  (
272  const topoSetSource::setAction action,
273  topoSet&
274  ) const;
275 };
276 
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 } // End namespace Foam
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
dictionary dict
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Apply specified action to the topoSet.
virtual ~surfaceToCell()
Destructor.
Helper class to search on triSurface.
TypeName("surfaceToCell")
Runtime type information.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const polyMesh & mesh() const noexcept
Reference to the mesh.
setAction
Enumeration defining various actions.
Vector< scalar > vector
Definition: vector.H:57
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
surfaceToCell(const polyMesh &mesh, const fileName &surfName, const pointField &outsidePoints, const bool includeCut, const bool includeInside, const bool includeOutside, const bool useSurfaceOrientation, const scalar nearDist, const scalar curvature)
Construct from components.
vector point
Point is a vector.
Definition: point.H:37
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Triangulated surface description with patch information.
Definition: triSurface.H:71
Namespace for OpenFOAM.