voxelRaySearchEngineI.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 \*---------------------------------------------------------------------------*/
27 
28 bool Foam::VF::voxel::outOfBounds
29 (
30  const labelVector& ijk,
31  const label dir
32 ) const
33 {
34  return (ijk[dir] < 0 || ijk[dir] >= nijk_[dir]);
35 };
36 
37 
38 Foam::point Foam::VF::voxel::localPosition(const vector& globalPosition) const
39 {
40  return globalPosition - bb0_.min();
41 }
42 
43 
44 Foam::point Foam::VF::voxel::globalPosition(const vector& localPosition) const
45 {
46  return bb0_.min() + localPosition;
47 }
48 
49 
50 void Foam::VF::voxel::setVoxelDims(const label i, const label j, const label k)
51 {
52  nijk_[0] = max(1, i);
53  nijk_[1] = max(1, j);
54  nijk_[2] = max(1, k);
55 
56  dxyz_[0] = span0_[0]/nijk_[0];
57  dxyz_[1] = span0_[1]/nijk_[1];
58  dxyz_[2] = span0_[2]/nijk_[2];
59 }
60 
61 
62 void Foam::VF::voxel::refineVoxelDims()
63 {
64  nijk_ *= 2;
65 
66  // Do not refine empty direction for 2D
67  const auto& solutionD = mesh_.solutionD();
68  for (direction d=0; d<3; ++d)
69  {
70  if (solutionD[d] == -1)
71  {
72  nijk_[d] = 1;
73  }
74  }
75 
76  setVoxelDims(nijk_[0], nijk_[1], nijk_[2]);
77 }
78 
79 
80 Foam::point Foam::VF::voxel::voxelMin
81 (
82  const label i,
83  const label j,
84  const label k
85 ) const
86 {
87  return point(i*dxyz_[0], j*dxyz_[1], k*dxyz_[2]);
88 }
89 
90 
91 Foam::point Foam::VF::voxel::voxelMax
92 (
93  const label i,
94  const label j,
95  const label k
96 ) const
97 {
98  return voxelMin(i+1, j+1, k+1);
99 }
100 
101 
102 constexpr Foam::label Foam::VF::voxel::sign0(const scalar x) const
103 {
104  if (x > 0) return 1;
105  if (x < 0) return -1;
106  return 0;
107 };
108 
111 {
112  return nijk_;
113 }
114 
115 
117 {
118  return nijk_[0]*nijk_[1]*nijk_[2];
119 }
120 
121 
122 Foam::label Foam::VF::voxel::voxeli
123 (
124  const labelVector ijk
125 ) const noexcept
126 {
127  return voxeli(ijk[0], ijk[1], ijk[2]);
128 }
129 
130 
131 Foam::label Foam::VF::voxel::voxeli
132 (
133  const label i,
134  const label j,
135  const label k
136 ) const noexcept
137 {
138  return i + (nijk_[0]*(j + (nijk_[1]*k)));
139 }
140 
141 
142 Foam::labelVector Foam::VF::voxel::ijk(const label voxeli) const noexcept
143 {
144  const label nx = nijk_[0];
145  const label ny = nijk_[1];
146 
147  const label i = voxeli%nx;
148  const label k = voxeli/nx/ny;
149  const label j = (voxeli/nx)%ny;
150 
151  return labelVector(i, j, k);
152 }
153 
154 
155 // ************************************************************************* //
label nVoxel() const noexcept
uint8_t direction
Definition: direction.H:46
labelVector ijk(const label voxeli) const noexcept
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
label voxeli(const labelVector ijk) const noexcept
label k
Boltzmann constant.
Vector< scalar > vector
Definition: vector.H:57
const direction noexcept
Definition: scalarImpl.H:255
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
labelVector nijk() const noexcept
vector point
Point is a vector.
Definition: point.H:37
Vector< label > labelVector
Vector of labels.
Definition: labelVector.H:47