Virtual Testbed
Ship dynamics simulator for extreme conditions
flooding_solver.hh
1 #ifndef VTESTBED_CORE_FLOODING_SOLVER_HH
2 #define VTESTBED_CORE_FLOODING_SOLVER_HH
3 
4 #include <vtestbed/core/types.hh>
5 #include <vtestbed/geometry/types.hh>
6 
7 namespace vtb {
8 
9  namespace core {
10 
11  template <class T>
12  class Volume {
13 
14  private:
15  T _volume{};
16  Vector<T,3> _point{T{}};
17 
18  public:
19 
20  Volume() = default;
21  inline Volume(T v, const Vector<T,3>& x): _volume(v), _point(x) {}
22 
23  inline void
24  accumulate(T v, const Vector<T,3>& x) {
25  this->_volume += v;
26  this->_point += x*v;
27  }
28 
29  inline void normalise() { this->_point /= this->_volume; }
30  inline void clear() { this->_point = 0, this->_volume = 0; }
31  inline T volume() const { return this->_volume; }
32  inline const Vector<T,3>& point() const { return this->_point; }
33 
34  };
35 
36  template <class T>
38 
39  public:
42  using vertex_type = Vector<T,3>;
43 
44  private:
45  const polyhedron_type& _polyhedron;
46  bounds_type _z_bounds;
47  vertex_type _centre{T{}};
48  T _volume{};
49  T _level{};
50 
51  public:
52 
53  Flooding_solver(const polyhedron_type& polyhedron);
54 
62  void volume(T new_volume);
63 
71  void level(T new_level);
72 
73  inline const bounds_type& z_bounds() const { return this->_z_bounds; }
74  inline const vertex_type& centre_of_mass() const { return this->_centre; }
75  inline T volume() const { return this->_volume; }
76  inline T level() const { return this->_level; }
77  inline const polyhedron_type& polyhedron() const { return this->_polyhedron; }
78 
79  private:
80 
81  T calc_level();
82  Volume<T> calc_volume(T level);
83 
84  };
85 
86  }
87 
88 }
89 
90 #endif // vim:filetype=cpp
void level(T new_level)
Compute fluid level by specifying its volume.
Main namespace.
Definition: convert.hh:9
void volume(T new_volume)
Compute fluid level by specifying its volume.