surfaceToCell.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::surfaceToCell
26 
27 Description
28  A topoSetSource to select cells based on relation to surface.
29 
30  Selects:
31  - all cells inside/outside/cut by surface
32  - all cells inside/outside surface ('useSurfaceOrientation', requires closed
33  surface)
34  - cells with centre nearer than XXX to surface
35  - cells with centre nearer than XXX to surface \b and with normal
36  at nearest point to centre and cell-corners differing by
37  more than YYY (i.e., point of high curvature)
38 
39 SourceFiles
40  surfaceToCell.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef surfaceToCell_H
45 #define surfaceToCell_H
46 
47 #include "topoSetSource.H"
48 #include "Map.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 class triSurfaceSearch;
55 class triSurface;
56 
57 /*---------------------------------------------------------------------------*\
58  Class surfaceToCell Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class surfaceToCell
62 :
63  public topoSetSource
64 {
65  // Private Data
66 
67  //- Name of surface file
68  const fileName surfName_;
69 
70  //- Points which are outside
71  const List<point> outsidePoints_;
72 
73  //- Include cut cells
74  const bool includeCut_;
75 
76  //- Include inside cells
77  const bool includeInside_;
78 
79  //- Include outside cells
80  const bool includeOutside_;
81 
82  //- Determine inside/outside purely using geometric test
83  // (does not allow includeCut)
84  const bool useSurfaceOrientation_;
85 
86  //- If > 0 : include cells with distance from cellCentre to surface
87  // less than nearDist.
88  const scalar nearDist_;
89 
90  //- If > -1 : include cells with normals at nearest surface points
91  // varying more than curvature_.
92  const scalar curvature_;
93 
94  //- triSurface to search on. On pointer since can be external.
95  const triSurface* surfPtr_;
96 
97  //- Search engine on surface.
98  const triSurfaceSearch* querySurfPtr_;
99 
100  //- Whether I allocated above surface ptrs or whether they are
101  // external.
102  const bool IOwnPtrs_;
103 
104 
105  // Private Member Functions
106 
107  //- Find index of nearest triangle to point. Returns triangle or -1 if
108  // not found within search span.
109  // Cache result under pointi.
110  static label getNearest
111  (
112  const triSurfaceSearch& querySurf,
113  const label pointi,
114  const point& pt,
115  const vector& searchSpan,
116  Map<label>& cache
117  );
118 
119  //- Return true if surface normal of nearest points to vertices on
120  // cell differ from that on cell centre. Points cached in
121  // pointToNearest.
122  bool differingPointNormals
123  (
124  const triSurfaceSearch& querySurf,
125  const vector& span,
126  const label celli,
127  const label cellTriI,
128  Map<label>& pointToNearest
129  ) const;
130 
131 
132  //- Depending on surface add to or delete from cellSet.
133  void combine(topoSet& set, const bool add) const;
134 
135  //- Check values at construction time.
136  void checkSettings() const;
137 
138  const triSurfaceSearch& querySurf() const
139  {
140  return *querySurfPtr_;
141  }
142 
143 
144 public:
145 
146  //- Runtime type information
147  TypeName("surfaceToCell");
148 
149 
150  // Constructors
151 
152  //- Construct from components
154  (
155  const polyMesh& mesh,
156  const fileName& surfName,
157  const pointField& outsidePoints,
158  const bool includeCut,
159  const bool includeInside,
160  const bool includeOutside,
161  const bool useSurfaceOrientation,
162  const scalar nearDist,
163  const scalar curvature
164  );
165 
166  //- Construct from components (supplied surface, surfaceSearch)
168  (
169  const polyMesh& mesh,
170  const fileName& surfName,
171  const triSurface& surf,
172  const triSurfaceSearch& querySurf,
173  const pointField& outsidePoints,
174  const bool includeCut,
175  const bool includeInside,
176  const bool includeOutside,
177  const bool useSurfaceOrientation,
178  const scalar nearDist,
179  const scalar curvature
180  );
181 
182  //- Construct from dictionary
184  (
185  const polyMesh& mesh,
186  const dictionary& dict
187  );
188 
189 
190  //- Destructor
191  virtual ~surfaceToCell();
192 
193 
194  // Member Functions
195 
196  virtual sourceType setType() const
197  {
198  return CELLSETSOURCE;
199  }
200 
201  virtual void applyToSet
202  (
203  const topoSetSource::setAction action,
204  topoSet&
205  ) const;
206 };
207 
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace Foam
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #endif
216 
217 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling file names.
Definition: fileName.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A topoSetSource to select cells based on relation to surface.
Definition: surfaceToCell.H:63
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.
virtual sourceType setType() const
TypeName("surfaceToCell")
Runtime type information.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~surfaceToCell()
Destructor.
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:71
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh() const
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Helper class to search on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:68
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dictionary dict