voxelRaySearchEngine.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) 2023-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::VF::voxel
28 
29 Description
30  Ray search engine based on discretising space into uniform voxels
31 
32  Voxels are refined using 2x2x2 refinement.
33 
34  The number of rays per face is supplied by the user, whereby rays are
35  issued uniformly across a hemisphere.
36 
37 Usage
38  Minimal example by using \c <constant>/viewFactorsDict:
39  \verbatim
40  // Mandatory entries
41  nRayPerFace <label>;
42 
43  // Optional entries
44  nTriPerVoxelMax <label>;
45  depthMax <label>;
46 
47  // Inherited entries
48  ...
49  \endverbatim
50 
51  where the entries mean:
52  \table
53  Property | Description | Type | Reqd | Deflt
54  nRayPerFace | Number of rays issued per face | label | yes | -
55  nRayPerFace | Target number of triangles per voxel | label | no | 50
56  depthMax | Maximum voxel refinement depth | label | no | 5
57  \endtable
58 
59  The inherited entries are elaborated in:
60  - \link raySearchEngine.H \endlink
61 
62 SourceFiles
63  voxelRaySearchEngine.C
64 
65 SeeAlso
66 - Foam::VF::raySearchEngine
67 
68 \*---------------------------------------------------------------------------*/
69 
70 #ifndef Foam_vf_voxelRaySearchEngine_H
71 #define Foam_vf_voxelRaySearchEngine_H
72 
73 #include "raySearchEngine.H"
74 #include "labelVector.H"
75 #include "OBJstream.H"
76 #include "pointIndexHit.H"
77 #include "triSurface.H"
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 
84 namespace VF
85 {
86 
87 /*---------------------------------------------------------------------------*\
88  Class voxel Declaration
89 \*---------------------------------------------------------------------------*/
90 
91 class voxel
92 :
93  public raySearchEngine
94 {
95  // Private Data
96 
97  //- Triangulation of view factor patches
98  triSurface surface_;
99 
100  //- Triangle to mesh face addressing
101  labelList triToGlobalFace_;
102 
103  //- Surface bounding box
104  boundBox bb0_;
105 
106  //- Span of surface bounding box
107  vector span0_;
108 
109  //- Voxel discretisation
110  labelVector nijk_;
111 
112  //- Voxel dimensions
113  vector dxyz_;
114 
115  //- Number of rays issued per face
116  const label nRayPerFace_;
117 
118  //- Maximum number of triangles per voxel (trigger to refine voxels)
119  const label nTriPerVoxelMax_;
120 
121  //- Maximum depth of voxel refinement. Note: voxels are refined 2x2x2
122  const label depthMax_;
123 
124  //- List of triangle per voxel
125  List<DynamicList<label>> objects_;
126 
127  //- List of triangle bounding boxes
128  List<boundBox> objectBbs_;
129 
130 
131  // Private Member Functions
132 
133  inline bool outOfBounds(const labelVector& ijk, const label dir) const;
134 
135  inline point localPosition(const vector& globalPosition) const;
136 
137  inline point globalPosition(const vector& localPosition) const;
138 
139  inline void setVoxelDims(const label i, const label j, const label k);
140 
141  inline void refineVoxelDims();
142 
143  inline point voxelMin
144  (
145  const label i,
146  const label j,
147  const label k
148  ) const;
149 
150  inline point voxelMax
151  (
152  const label i,
153  const label j,
154  const label k
155  ) const;
156 
157  inline constexpr label sign0(const scalar x) const;
158 
159  //- Set triangulation based on original mesh
160  void setTriangulation(const fvMesh& mesh);
161 
162  //- Set the participating face vertices when simplifying edges
163  static labelList setFaceVertexHits
164  (
165  const fvMesh& mesh,
166  const labelList& patchIDs
167  );
168 
169  //- Set triangulation based on agglomeration
170  void setCoarseTriangulation(const fvMesh& mesh);
171 
172  //- Broadcast triangulation across all procs
173  void broadcast();
174 
175  void refineObjects
176  (
177  List<DynamicList<label>>& objects,
178  const label triMax
179  );
180 
181  label addBbToVoxels
182  (
183  const boundBox& bb,
184  const label trii,
185  List<DynamicList<label>>& objects
186  ) const;
187 
188  void voxelise
189  (
190  List<DynamicList<label>>& objects,
191  const label trii0,
192  const label depth
193  );
194 
195  pointHit rayTriIntersect
196  (
197  const label trii,
198  const point& origin,
199  const vector& direction
200  ) const;
201 
202  pointIndexHit hitObject
203  (
204  const label voxeli,
205  const point& origin,
206  const vector& direction,
207  const vector& t,
208  const scalar minDistance = 1e-6
209  ) const;
210 
211  void writeBox
212  (
213  OBJstream& os,
214  bool lines,
215  const boundBox& bb
216  ) const;
217 
218  void writeVoxels(const word& fName) const;
219 
220  void writeTriBoundBoxes(const word& fName) const;
221 
222  void writeHitObjects
223  (
224  const label voxeli,
225  const point& origin,
226  const vector& dir
227  ) const;
228 
229 
230 public:
231 
232  //- Runtime type information
233  TypeName("voxel");
234 
235  //- Constructor
236  voxel(const fvMesh& mesh, const dictionary& dict);
237 
238  //- Destructor
239  virtual ~voxel() = default;
240 
241 
242  // Public Member Functions
243 
244  inline labelVector nijk() const noexcept;
245 
246  inline label nVoxel() const noexcept;
247 
248  inline label voxeli(const labelVector ijk) const noexcept;
249 
250  inline label voxeli
251  (
252  const label i,
253  const label j,
254  const label k
255  ) const noexcept;
256 
257  inline labelVector ijk(const label voxeli) const noexcept;
258 
259  pointIndexHit hit(const point& origin, const vector& dir) const;
260 
261  pointIndexHit hit(const label tri0, const vector& dir) const;
262 
263  virtual void shootRays
264  (
265  labelList& rayStartFaceOut,
266  labelList& rayEndFaceOut
267  ) const;
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace VF
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #include "voxelRaySearchEngineI.H"
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
label nVoxel() const noexcept
dictionary dict
uint8_t direction
Definition: direction.H:46
TypeName("voxel")
Runtime type information.
labelVector ijk(const label voxeli) const noexcept
virtual ~voxel()=default
Destructor.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
label voxeli(const labelVector ijk) const noexcept
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
Definition: pointIndexHit.H:44
label k
Boltzmann constant.
const fvMesh & mesh() const noexcept
Reference to the mesh.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
voxel(const fvMesh &mesh, const dictionary &dict)
Constructor.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void shootRays(labelList &rayStartFaceOut, labelList &rayEndFaceOut) const
Shoot rays; returns lists of ray start and end faces.
Vector< scalar > vector
Definition: vector.H:57
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition: pointHit.H:43
const direction noexcept
Definition: Scalar.H:258
const labelList & patchIDs() const noexcept
List of participating patch IDs.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files...
Definition: OBJstream.H:55
OBJstream os(runTime.globalPath()/outputName)
pointIndexHit hit(const point &origin, const vector &dir) const
labelVector nijk() const noexcept
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.