COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
BoundingBox.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #include "common/PE/Comm.hpp"
8 
9 #include "math/Consts.hpp"
10 #include "math/BoundingBox.hpp"
12 
14 
15 namespace cf3 {
16 namespace math {
17 
18  using namespace common;
19  using namespace math::Consts;
20 
22 
24 {
25 }
26 
28 
30 {
31  m_bounding_min.resize(min.size());
32  m_bounding_max.resize(max.size());
33  m_bounding_min = min;
34  m_bounding_max = max;
35 }
36 
38 
39 BoundingBox::BoundingBox(const std::vector<Real>& min, const std::vector<Real>& max)
40 {
41  m_bounding_min.resize(min.size());
42  m_bounding_max.resize(max.size());
43  math::copy(min,m_bounding_min);
44  math::copy(max,m_bounding_max);
45 }
46 
48 
49 void BoundingBox::define(const BoundingBox& other)
50 {
51  define(other.min(),other.max());
52 }
53 
55 
57 {
58  m_bounding_min.resize(min.size());
59  m_bounding_max.resize(max.size());
60  m_bounding_min = min;
61  m_bounding_max = max;
62 }
63 
65 
66 void BoundingBox::define(const std::vector<Real>& min, const std::vector<Real>& max)
67 {
68  m_bounding_min.resize(min.size());
69  m_bounding_max.resize(max.size());
70  math::copy(min,m_bounding_min);
71  math::copy(max,m_bounding_max);
72 }
73 
75 
76 void BoundingBox::extend(const RealVector &point)
77 {
78  if (!dim())
79  {
80  m_bounding_min.resize(point.size()); m_bounding_min.setConstant(real_max());
81  m_bounding_max.resize(point.size()); m_bounding_max.setConstant(real_min());
82  }
83  cf3_assert(point.size() == dim());
84  for (Uint d=0; d<dim(); ++d)
85  {
86  m_bounding_min[d] = std::min(m_bounding_min[d], point[d]);
87  m_bounding_max[d] = std::max(m_bounding_max[d], point[d]);
88  }
89 
90 }
91 
93 
95 {
96  if (PE::Comm::instance().is_active())
97  {
98  // Find global minimum and global maximum
99  std::vector<Real> bounding_min(dim());
100  std::vector<Real> bounding_max(dim());
101  math::copy(min(),bounding_min);
102  math::copy(max(),bounding_max);
103  PE::Comm::instance().all_reduce(PE::min(),bounding_min,bounding_min);
104  PE::Comm::instance().all_reduce(PE::max(),bounding_max,bounding_max);
105 
106  // Copy global minimum and global maximum in bounding box
107  math::copy(bounding_min,min());
108  math::copy(bounding_max,max());
109  }
110 }
111 
113 
114 bool BoundingBox::contains(const RealVector& coordinate) const
115 {
116  bool inside=true;
117  for (Uint d=0; d<coordinate.size(); ++d)
118  {
119  inside = inside && (coordinate[d]>=m_bounding_min[d] && coordinate[d]<=m_bounding_max[d]);
120  }
121  return inside;
122 }
123 
125 
126 } // math
127 } // cf3
const RealVector & min() const
minimum coordinates, defining one corner of the bounding box
Definition: BoundingBox.hpp:61
void extend(const RealVector &point)
Extend BoundingBox, given a point.
Definition: BoundingBox.cpp:76
void copy(const std::vector< Real > &vector, RealMatrix &realmatrix)
Copy std::vector to dynamic RealMatrix types.
const RealVector & max() const
maximum coordinates, defining one corner of the bounding box
Definition: BoundingBox.hpp:64
#define cf3_assert(a)
Definition: Assertions.hpp:93
void make_global()
Expand bounding box to encompass all processors.
Definition: BoundingBox.cpp:94
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
Real min(const Real a, const Real b)
Minimum between two scalars.
Definition: Terminals.hpp:234
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Real real_max()
Returns the maximum number representable with the chosen precision.
Definition: Consts.hpp:36
void define(const BoundingBox &other)
Define bounding box with other bounding box.
Definition: BoundingBox.cpp:49
Real real_min()
Definition of the minimum number representable with the chosen precision.
Definition: Consts.hpp:38
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
Bounding box defined by minimum and maximum coordinates.
Definition: BoundingBox.hpp:24
bool contains(const RealVector &coordinate) const
Check if coordinate falls inside the bounding box.
Send comments to:
COOLFluiD Web Admin