boundBoxTemplates.C
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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2017 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "boundBox.H"
30#include "FixedList.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
34template<unsigned N>
36(
37 const UList<point>& points,
38 const FixedList<label, N>& indices,
39 bool doReduce
40)
41:
42 boundBox()
43{
44 add(points, indices);
45
46 if (doReduce)
47 {
48 reduce();
49 }
50}
51
52
53// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
54
55template<unsigned N>
57(
59)
60{
61 for (const point& p : points)
62 {
63 add(p);
64 }
65}
66
67
68template<unsigned N>
70(
71 const UList<point>& points,
72 const FixedList<label, N>& indices
73)
74{
75 const label len = points.size();
76
77 // Skip if points is empty
78 if (!len)
79 {
80 return;
81 }
82
83 for (const label pointi : indices)
84 {
85 if (pointi >= 0 && pointi < len)
86 {
87 add(points[pointi]);
88 }
89 }
90}
91
92
93template<class IntContainer>
95(
96 const UList<point>& points,
97 const IntContainer& indices
98)
99{
100 const label len = points.size();
101
102 // Skip if points is empty
103 if (!len)
104 {
105 return;
106 }
107
108 for (const label pointi : indices)
109 {
110 if (pointi >= 0 && pointi < len)
111 {
112 add(points[pointi]);
113 }
114 }
115}
116
117
118template<unsigned N>
120(
121 const UList<point>& points,
122 const FixedList<label, N>& indices
123) const
124{
125 const label len = points.size();
126
127 if (!len)
128 {
129 return true;
130 }
131
132 for (const label pointi : indices)
133 {
134 if (pointi >= 0 && pointi < len)
135 {
136 if (!contains(points[pointi]))
137 {
138 return false;
139 }
140 }
141 }
142
143 return true;
144}
145
146
147template<class IntContainer>
149(
150 const UList<point>& points,
151 const IntContainer& indices
152) const
153{
154 const label len = points.size();
155
156 if (!len)
157 {
158 return true;
159 }
160
161 for (const label pointi : indices)
162 {
163 if (pointi >= 0 && pointi < len)
164 {
165 if (!contains(points[pointi]))
166 {
167 return false;
168 }
169 }
170 }
171
172 return true;
173}
174
175
176template<unsigned N>
178(
179 const UList<point>& points,
180 const FixedList<label, N>& indices
181) const
182{
183 const label len = points.size();
184
185 if (!len)
186 {
187 return true;
188 }
189
190 label failed = 0;
191
192 for (const label pointi : indices)
193 {
194 if (pointi >= 0 && pointi < len)
195 {
196 if (contains(points[pointi]))
197 {
198 return true;
199 }
200
201 ++failed;
202 }
203 }
204
205 return !failed;
206}
207
208
209template<class IntContainer>
211(
212 const UList<point>& points,
213 const IntContainer& indices
214) const
215{
216 const label len = points.size();
217
218 if (!len)
219 {
220 return true;
221 }
222
223 label failed = 0;
224
225 for (const label pointi : indices)
226 {
227 if (pointi >= 0 && pointi < len)
228 {
229 if (contains(points[pointi]))
230 {
231 return true;
232 }
233
234 ++failed;
235 }
236 }
237
238 return !failed;
239}
240
241
242// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
void reduce()
Parallel reduction of min/max values.
Definition: boundBox.C:184
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
void add(const boundBox &bb)
Extend to include the second box.
Definition: boundBoxI.H:191
boundBox()
Construct without any points - an inverted bounding box.
Definition: boundBoxI.H:33
bool containsAny(const UList< point > &points) const
Contains any of the points? (inside or on edge)
Definition: boundBox.C:249
tmp< pointField > points() const
Corner points in an order corresponding to a 'hex' cell.
Definition: boundBox.C:118
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
volScalarField & p
const pointField & points
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)