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-2021 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 
66  // Private Data
67 
68 
69  //- Name of surface file
70  const fileName surfName_;
71 
72  //- Points which are outside
73  const pointField outsidePoints_;
74 
75  //- Include cut cells
76  const bool includeCut_;
77 
78  //- Include inside cells
79  const bool includeInside_;
80 
81  //- Include outside cells
82  const bool includeOutside_;
83 
84  //- Determine inside/outside purely using geometric test
85  // (does not allow includeCut)
86  const bool useSurfaceOrientation_;
87 
88  //- If > 0 : include cells with distance from cellCentre to surface
89  // less than nearDist.
90  const scalar nearDist_;
91 
92  //- If > -1 : include cells with normals at nearest surface points
93  // varying more than curvature_.
94  const scalar curvature_;
95 
96  //- triSurface to search on. On pointer since can be external.
97  const triSurface* surfPtr_;
98 
99  //- Search engine on surface.
100  const triSurfaceSearch* querySurfPtr_;
101 
102  //- Whether I allocated above surface ptrs or whether they are
103  // external.
104  const bool IOwnPtrs_;
105 
106 
107  // Private Member Functions
108 
109  //- Find index of nearest triangle to point. Returns triangle or -1 if
110  // not found within search span.
111  // Cache result under pointi.
112  static label getNearest
113  (
114  const triSurfaceSearch& querySurf,
115  const label pointi,
116  const point& pt,
117  const vector& searchSpan,
118  Map<label>& cache
119  );
120 
121  //- Return true if surface normal of nearest points to vertices on
122  // cell differ from that on cell centre. Points cached in
123  // pointToNearest.
124  bool differingPointNormals
125  (
126  const triSurfaceSearch& querySurf,
127  const vector& span,
128  const label celli,
129  const label cellTriI,
130  Map<label>& pointToNearest
131  ) const;
132 
133 
134  //- Depending on surface add to or delete from cellSet.
135  void combine(topoSet& set, const bool add) const;
136 
137  //- Check values at construction time.
138  void checkSettings() const;
139 
140  const triSurfaceSearch& querySurf() const
141  {
142  return *querySurfPtr_;
143  }
144 
145 
146 public:
147 
148  //- Runtime type information
149  TypeName("surfaceToCell");
150 
151  // Constructors
152 
153  //- Construct from components
155  (
156  const polyMesh& mesh,
157  const fileName& surfName,
158  const pointField& outsidePoints,
159  const bool includeCut,
160  const bool includeInside,
161  const bool includeOutside,
162  const bool useSurfaceOrientation,
163  const scalar nearDist,
164  const scalar curvature
165  );
166 
167  //- Construct from components (supplied surface, surfaceSearch)
169  (
170  const polyMesh& mesh,
171  const fileName& surfName,
172  const triSurface& surf,
173  const triSurfaceSearch& querySurf,
174  const pointField& outsidePoints,
175  const bool includeCut,
176  const bool includeInside,
177  const bool includeOutside,
178  const bool useSurfaceOrientation,
179  const scalar nearDist,
180  const scalar curvature
181  );
182 
183  //- Construct from dictionary
185  (
186  const polyMesh& mesh,
187  const dictionary& dict
188  );
189 
190 
191  //- Destructor
192  virtual ~surfaceToCell();
193 
194 
195  // Member Functions
196 
197  virtual sourceType setType() const
198  {
199  return CELLSETSOURCE;
200  }
201 
202  virtual void applyToSet
203  (
204  const topoSetSource::setAction action,
205  topoSet&
206  ) const;
207 
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #endif
218 
219 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling file names.
Definition: fileName.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A topoSetSource to select cells based on relation to surface.
Definition: surfaceToCell.H:63
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
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
virtual ~surfaceToCell()
Destructor.
TypeName("surfaceToCell")
Runtime type information.
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:65
Helper class to search on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:69
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(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dictionary dict