boundBoxTemplates.C
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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "boundBox.H"
27 #include "FixedList.H"
28 #include "PstreamReduceOps.H"
29 
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<unsigned Size>
35 (
36  const UList<point>& points,
37  const FixedList<label, Size>& indices,
38  const bool doReduce
39 )
40 :
41  min_(Zero),
42  max_(Zero)
43 {
44  // a FixedList is never empty
45  if (points.empty())
46  {
47  if (doReduce && Pstream::parRun())
48  {
49  // Use values that get overwritten by reduce minOp, maxOp below
50  min_ = point(vGreat, vGreat, vGreat);
51  max_ = point(-vGreat, -vGreat, -vGreat);
52  }
53  }
54  else
55  {
56  min_ = points[indices[0]];
57  max_ = points[indices[0]];
58 
59  for (unsigned i=1; i < Size; ++i)
60  {
61  min_ = ::Foam::min(min_, points[indices[i]]);
62  max_ = ::Foam::max(max_, points[indices[i]]);
63  }
64  }
65 
66  // Reduce parallel information
67  if (doReduce)
68  {
69  reduce(min_, minOp<point>());
70  reduce(max_, maxOp<point>());
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
76 
77 template<unsigned Size>
79 (
80  const UList<point>& points,
81  const FixedList<label, Size>& indices
82 ) const
83 {
84  // a FixedList is never empty
85  if (points.empty())
86  {
87  return false;
88  }
89 
90  forAll(indices, i)
91  {
92  if (!contains(points[indices[i]]))
93  {
94  return false;
95  }
96  }
97 
98  return true;
99 }
100 
101 
102 template<unsigned Size>
104 (
105  const UList<point>& points,
106  const FixedList<label, Size>& indices
107 ) const
108 {
109  // a FixedList is never empty
110  if (points.empty())
111  {
112  return false;
113  }
114 
115  forAll(indices, i)
116  {
117  if (contains(points[indices[i]]))
118  {
119  return true;
120  }
121  }
122 
123  return false;
124 }
125 
126 
127 // ************************************************************************* //
boundBox()
Construct null, setting points to zero.
Definition: boundBoxI.H:32
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
Inter-processor communication reduction functions.
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
bool contains(const point &) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:170
static const zero Zero
Definition: zero.H:97
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
vector point
Point is a vector.
Definition: point.H:41
bool containsAny(const UList< point > &) const
Contains any of the points? (inside or on edge)
Definition: boundBox.C:261