Virtual Testbed
Ship dynamics simulator for extreme conditions
stokes_wave.hh
1 #ifndef VTESTBED_CORE_STOKES_WAVE_HH
2 #define VTESTBED_CORE_STOKES_WAVE_HH
3 
4 #include <stdexcept>
5 
6 #include <vtestbed/base/constants.hh>
7 #include <vtestbed/core/wave.hh>
8 
9 namespace vtb {
10 
11  namespace core {
12 
13  template <class T, int N>
14  inline Frequency<T>
15  stokes_wave_angular_frequency(
16  const blitz::TinyVector<T,N>& k,
17  Amplitude<T> amplitude
18  ) {
19  using std::sqrt;
20  constexpr auto g = base::constants<T>::g();
21  const T k_length{length(k)};
22  const T steepness = amplitude * k_length;
23  return Frequency<T>{sqrt(g*k_length*(T{1} +steepness*steepness))};
24  }
25 
32  template <class T, int N>
33  class Propagating_stokes_wave: public Wave_base<T,N> {
34 
35  public:
36  using typename Wave_base<T,N>::vec;
37 
38  public:
39 
40  Propagating_stokes_wave() = default;
41  ~Propagating_stokes_wave() = default;
43  Propagating_stokes_wave& operator=(const Propagating_stokes_wave&) = default;
44 
45  inline
48  amplitude,
49  k,
50  stokes_wave_angular_frequency(k, amplitude)
51  ) {}
52 
53  inline
58  ):
60  amplitude,
61  wave_number<T,N-1>(length, direction)
62  ) {}
63 
64 
66  inline T
67  operator()(const vec& x, T t) const noexcept {
68  using blitz::dot;
69  using std::cos;
70  const T steepness = this->amplitude() * length(this->wave_number());
71  const T theta = dot(this->wave_number(), x) - this->angular_frequency()*t;
72  return this->amplitude() * (
73  cos(theta)
74  + T(0.5) * steepness * cos(T(2)*theta)
75  + (T(3)/T(8)) * steepness * steepness * cos(T(3)*theta)
76  );
77  }
78 
79  inline Grid<T,3>
80  acf_grid() const {
81  throw std::runtime_error("not implemented");
82  }
83 
84  };
85 
86  }
87 
88 }
89 
90 #endif // vim:filetype=cpp
T angular_frequency() const noexcept
Get wave angular frequency.
Definition: core/wave.hh:102
static constexpr const T g()
Gravitational acceleration.
Definition: constants.hh:15
const vec & wave_number() const noexcept
Get wave numbers for each dimension.
Definition: core/wave.hh:96
Propagating third-order Stokes wave.
Definition: stokes_wave.hh:33
vec length() const noexcept
Get wave length.
Definition: core/wave.hh:108
T direction() const noexcept
Get wave direction in radians.
Definition: core/wave.hh:120
T length(const blitz::TinyVector< T, N > &x)
Computes vector length without overflow.
Definition: blitz.hh:471
T amplitude() const noexcept
Get wave amplitude.
Definition: core/wave.hh:90
Main namespace.
Definition: convert.hh:9
T sqrt(T... args)
T operator()(const vec &x, T t) const noexcept
Returns wavy surface elevation at point x.
Definition: stokes_wave.hh:67
Base class for water waves.
Definition: core/types.hh:49