Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::VF::voxel
28
29Description
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
37Usage
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
62SourceFiles
63 voxelRaySearchEngine.C
64
65SeeAlso
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
81namespace Foam
82{
83
84namespace VF
85{
86
87/*---------------------------------------------------------------------------*\
88 Class voxel Declaration
89\*---------------------------------------------------------------------------*/
90
91class 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
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
230public:
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 k
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An OFstream that keeps track of vertices and provides convenience output methods for OBJ files.
Definition OBJstream.H:58
Base class for ray search engines.
const fvMesh & mesh() const noexcept
Reference to the mesh.
const labelList & patchIDs() const noexcept
List of participating patch IDs.
raySearchEngine(const raySearchEngine &)=delete
No copy construct.
Ray search engine based on discretising space into uniform voxels.
label voxeli(const labelVector ijk) const noexcept
pointIndexHit hit(const point &origin, const vector &dir) const
voxel(const fvMesh &mesh, const dictionary &dict)
Constructor.
virtual void shootRays(labelList &rayStartFaceOut, labelList &rayEndFaceOut) const
Shoot rays; returns lists of ray start and end faces.
labelVector nijk() const noexcept
labelVector ijk(const label voxeli) const noexcept
label nVoxel() const noexcept
virtual ~voxel()=default
Destructor.
TypeName("voxel")
Runtime type information.
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Triangulated surface description with patch information.
Definition triSurface.H:74
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
A namespace for various viewFactor model implementations.
Namespace for OpenFOAM.
PointHit< point > pointHit
A PointHit with a 3D point.
Definition pointHit.H:51
List< label > labelList
A List of labels.
Definition List.H:62
Vector< label > labelVector
Vector of labels.
Definition labelVector.H:47
uint8_t direction
Definition direction.H:49
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
Vector< scalar > vector
Definition vector.H:57
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
dictionary dict
volScalarField & e
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68