Virtual Testbed
Ship dynamics simulator for extreme conditions
wave_numbers.hh
1 #ifndef VTESTBED_CORE_WAVE_NUMBERS_HH
2 #define VTESTBED_CORE_WAVE_NUMBERS_HH
3 
4 #include <limits>
5 #include <ostream>
6 #include <vector>
7 
8 #include <vtestbed/base/blitz.hh>
9 #include <vtestbed/base/minmaxmean.hh>
10 #include <vtestbed/core/grid.hh>
11 
12 namespace vtb {
13 
14  namespace core {
15 
16  template <class T>
17  struct Wave_statistics {
18 
19  vtb::base::Mean<T> length;
21  vtb::base::Mean<T> height;
22 
23  inline void clear() { length.clear(), number.clear(), height.clear(); }
24 
25  template <class X>
26  friend std::ostream&
27  operator<<(std::ostream& out, const Wave_statistics<X>& rhs);
28 
29  };
30 
31  template <class T>
33  operator<<(std::ostream& out, const Wave_statistics<T>& rhs);
34 
35  template <class T, int N>
36  using Wave_statistics_vector =
37  blitz::TinyVector<Wave_statistics<T>,N>;
38 
44  template <class T>
45  struct Wave_half {
46 
47  T length;
48  T number;
49  T height;
50 
51  inline
52  Wave_half(T lambda, T k, T h):
53  length(lambda), number(k), height(h) {}
54 
55  template <class X>
56  friend std::ostream&
57  operator<<(std::ostream& out, const Wave_half<X>& rhs);
58 
59  };
60 
61  template <class T>
63  operator<<(std::ostream& out, const Wave_half<T>& rhs);
64 
72  template <class T>
74  find_extrema(blitz::Array<T,1> func, const Grid<T,1>& grid);
75 
82  template <class T>
84  find_wave_halves(const std::vector<blitz::TinyVector<T,2>>& extrema);
85 
93  template <class T>
94  void
96  const std::vector<Wave_half<T>>& halves,
97  T& min_wave_number,
98  T& max_wave_number
99  );
100 
101  template <class T>
102  inline Grid<T,1>
104  Grid<T,1> grid{
107  {2}
108  };
109  find_wave_number_range<T>(halves, grid.lbound(0), grid.ubound(0));
110  return grid;
111  }
112 
113  template <class T, int N>
114  Grid<T,N>
115  wave_number_grid(const Wave_statistics_vector<T,N>& waves);
116 
117  template <class T>
118  Wave_statistics_vector<T,2>
119  wave_statistics(blitz::Array<T,2> surface, const Grid<T,2>& grid);
120 
121  template <class T>
122  Wave_statistics<T>
123  temporal_wave_statistics(
124  blitz::Array<T,1> surface,
125  const Grid<T,1>& grid
126  );
127 
133  template <class T>
134  Grid<T,2>
135  find_wave_number_range(blitz::Array<T,2> surface, const Grid<T,2>& grid);
136 
137  }
138 
139 }
140 
141 #endif // vim:filetype=cpp
A half of the wave with length, number and height of the full wave.
Definition: wave_numbers.hh:45
std::vector< blitz::TinyVector< T, 2 > > find_extrema(blitz::Array< T, 1 > func, const Grid< T, 1 > &grid)
Find coordinates of minima and maxima of a function.
Definition: wave_numbers.cc:48
std::vector< Wave_half< T > > find_wave_halves(const std::vector< blitz::TinyVector< T, 2 >> &extrema)
Find wave halves from function extrema computed previously.
T min(T... args)
Estimates sample mean without overflows.
Definition: mean.hh:20
A region defined by start and end index and lower and upper bound for each dimension.
Definition: core/grid.hh:25
T max(T... args)
void find_wave_number_range(const std::vector< Wave_half< T >> &halves, T &min_wave_number, T &max_wave_number)
Find minimum and maximum wave number from wave halves computed previously.
Main namespace.
Definition: convert.hh:9