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/Foreach.hpp"
8 #include "common/Builder.hpp"
10 
11 #include "math/Consts.hpp"
13 
14 #include "mesh/Mesh.hpp"
15 #include "mesh/BoundingBox.hpp"
16 #include "mesh/Field.hpp"
17 #include "mesh/Entities.hpp"
18 #include "mesh/Region.hpp"
19 #include "mesh/Connectivity.hpp"
20 #include "mesh/Space.hpp"
21 
23 
24 namespace cf3 {
25 namespace mesh {
26 
27  using namespace common;
28  using namespace math::Consts;
29 
31 
33 
34 BoundingBox::BoundingBox(const std::string& name) :
35  common::Component(name),
36  math::BoundingBox()
37 {
38 }
39 
41 
42 void BoundingBox::build(const Region& region)
43 {
44  // Find dimension
45  Uint dim=0;
46  boost_foreach(const Entities& entities, find_components_recursively<Entities>(region))
47  {
48  dim = entities.element_type().dimension();
49  break;
50  }
51 
52  // find bounding box coordinates for region 1 and region 2
53  min().resize(dim);
54  max().resize(dim);
55  min().setConstant(real_max());
56  max().setConstant(real_min());
57  boost_foreach(const Entities& entities, find_components_recursively<Entities>(region))
58  {
59  const Field& coordinates = entities.geometry_fields().coordinates();
60  const Connectivity& connectivity = entities.geometry_space().connectivity();
61  const Uint nb_elem = entities.size();
62  for (Uint e=0; e<nb_elem; ++e)
63  {
64  boost_foreach(const Uint node, connectivity[e])
65  {
66  for (Uint d=0; d<dim; ++d)
67  {
68  min()[d] = std::min(min()[d], coordinates[node][d]);
69  max()[d] = std::max(max()[d], coordinates[node][d]);
70  }
71  }
72  }
73  }
74  update_properties();
75 }
76 
78 
79 void BoundingBox::build(const Mesh& mesh)
80 {
81  build(mesh.geometry_fields().coordinates());
82 }
83 
85 
86 void BoundingBox::build(const Field& coordinates)
87 {
88  // Find dimension
89  Uint dim=coordinates.row_size();
90 
91  // find bounding box coordinates for region 1 and region 2
92  min().resize(dim);
93  max().resize(dim);
94  min().setConstant(real_max());
95  max().setConstant(real_min());
97  {
98  for (Uint d=0; d<dim; ++d)
99  {
100  min()[d] = std::min(min()[d], coords[d]);
101  max()[d] = std::max(max()[d], coords[d]);
102  }
103  }
104  update_properties();
105 }
106 
108 
109 void BoundingBox::update_properties()
110 {
111  std::vector<Real> min_vec(dim());
112  std::vector<Real> max_vec(dim());
113  math::copy(min(),min_vec);
114  math::copy(max(),max_vec);
115  properties()["minimum"]=min_vec;
116  properties()["maximum"]=max_vec;
117 }
118 
120 
121 } // mesh
122 } // cf3
const RealVector & min() const
minimum coordinates, defining one corner of the bounding box
Definition: BoundingBox.hpp:61
std::string name(ComponentWrapper &self)
ArrayT & array()
Definition: Table.hpp:92
Helper class to create the Builder and place it in the factory.
Definition: Builder.hpp:212
Space & geometry_space() const
Definition: Entities.hpp:94
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
cf3::common::ComponentBuilder< BoundingBox, Component, LibMesh > BoundingBox_Builder
Definition: BoundingBox.cpp:30
ElementType & element_type() const
return the elementType
Definition: Entities.cpp:116
#define boost_foreach
lowercase version of BOOST_FOREACH
Definition: Foreach.hpp:16
const Field & coordinates() const
Definition: Dictionary.cpp:481
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Dictionary & geometry_fields() const
Const access to the coordinates.
Definition: Entities.hpp:63
Uint size() const
return the number of elements
Definition: Entities.cpp:161
Real min(const Real a, const Real b)
Minimum between two scalars.
Definition: Terminals.hpp:234
properties()["description"]
TableConstRow< Real >::type ConstRow
the const type of a row in the internal structure of the table
Definition: Table.hpp:59
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
Uint row_size(Uint i=0) const
Definition: Table.hpp:133
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
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
Dictionary & geometry_fields() const
Definition: Mesh.cpp:339
Base class for defining CF components.
Definition: Component.hpp:82
Uint dimension() const
Definition: ElementType.hpp:82
Connectivity & connectivity()
connectivity table to dictionary entries
Definition: Space.hpp:110
Uint dim() const
dimension of the bounding box
Definition: BoundingBox.hpp:73
Send comments to:
COOLFluiD Web Admin