Virtual Testbed
Ship dynamics simulator for extreme conditions
compartment.hh
1 #ifndef VTESTBED_CORE_COMPARTMENT_HH
2 #define VTESTBED_CORE_COMPARTMENT_HH
3 
4 #include <iosfwd>
5 #include <string>
6 #include <vector>
7 
8 #include <vtestbed/base/constants.hh>
9 #include <vtestbed/core/types.hh>
10 #include <vtestbed/geometry/polyhedron.hh>
11 
12 
13 namespace vtb {
14 
15  namespace core {
16 
17  template <class T>
18  class Compartment {
19 
20  public:
21  using vec3 = Vector3<T>;
23  using face_array = Array<face_type,1>;
25 
26  private:
27  polyhedron_type _polyhedron;
28  T _flooded_volume{};
29  vec3 _centre{T{}};
30  std::string _name;
31  bool _fire = false;
32 
33  public:
34 
35  inline const std::string& name() const { return this->_name; }
36  inline void name(const std::string& rhs) { this->_name = rhs; }
37  inline const polyhedron_type& polyhedron() const { return this->_polyhedron; }
38  inline void polyhedron(const polyhedron_type& rhs) { this->_polyhedron = rhs; }
39  inline void polyhedron(polyhedron_type&& rhs) { this->_polyhedron = std::move(rhs); }
40  inline T flooded_volume() const { return this->_flooded_volume; }
41  T flooded_volume(T rhs);
42  inline void fire(bool rhs) { this->_fire = rhs; }
43  inline bool fire() const { return this->_fire; }
44  inline bool flooding() const { return this->_flooded_volume > 0; }
45  inline const vec3& flooded_mass_centre() const { return this->_centre; }
46  void calc_flooded_mass_centre();
47 
48  inline T
49  flooded_mass() const {
50  using constants = base::constants<T>;
51  return this->_flooded_volume*constants::water_density();
52  }
53 
54  void box(const vec3& x0, const vec3& x1);
55 
56  template <class X>
57  friend std::ostream&
58  operator<<(std::ostream& out, const Compartment<X>& rhs);
59 
60  };
61 
62  template <class T>
64  operator<<(std::ostream& out, const Compartment<T>& rhs);
65 
66  template <class T>
67  class Compartment_array: public std::vector<Compartment<T>> {
68 
69  private:
71  using polyhedron_type = typename Compartment<T>::polyhedron_type;
72 
73  public:
74  using value_type = typename base_type::value_type;
75  using pointer = typename base_type::pointer;
76  using const_pointer = typename base_type::const_pointer;
77  using reference = typename base_type::reference;
78  using const_reference = typename base_type::const_reference;
79  using iterator = typename base_type::iterator;
80  using const_iterator = typename base_type::const_iterator;
81  using size_type = typename base_type::size_type;
82  using difference_type = typename base_type::difference_type;
83  using reverse_iterator = typename base_type::reverse_iterator;
84  using const_reverse_iterator = typename base_type::const_reverse_iterator;
85 
86  public:
87 
88  using base_type::base_type;
89  using base_type::operator=;
90  using base_type::operator[];
91 
92  auto find(const std::string& name) -> iterator;
93 
94  static Compartment_array
95  generate(const polyhedron_type& hull, const int3& nrooms);
96 
97  };
98 
99  }
100 
101 }
102 
103 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9