Virtual Testbed
Ship dynamics simulator for extreme conditions
plain_wave_generator_openmp.cc
1 #include <vtestbed/config/real_type.hh>
2 #include <vtestbed/config/openmp.hh>
3 #include <vtestbed/core/cosine_wave.hh>
4 #include <vtestbed/core/stokes_wave.hh>
5 #include <vtestbed/core/plain_wave_generator.hh>
6 
7 namespace vtb {
8 
9  namespace core {
10 
11  template <class T, int N, class Wave>
13  public Plain_wave_generator<T,N,Wave,Policy::OpenMP> {
14 
15  private:
17  using typename base_type::grid_type;
18  using typename base_type::array_type;
19 
20  public:
22 
23  void generate(const grid_type& grid, array_type& result) override {
24  generate_wave<T,N,Wave>(grid, result, this->wave());
25  }
26 
27  };
28 
29  template <class T, int N>
31  make_plain_wave_generator_openmp(std::any wave);
32 
33  }
34 
35 }
36 
37 #define VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(T,N,Wave) \
38 template <> \
39 auto \
40 vtb::core::make_plain_wave_generator(const Wave<T,N>& wave) \
41 -> std::unique_ptr<Plain_wave_generator<T,N,Wave<T,N>,Policy::OpenMP>> { \
42  return std::unique_ptr<Plain_wave_generator<T,N,Wave<T,N>,Policy::OpenMP>>( \
43  new Plain_wave_generator_openmp<T,N,Wave<T,N>>(wave) \
44  ); \
45 } \
46 template <> \
47 auto \
48 vtb::core::make_plain_wave_generator() \
49 -> std::unique_ptr<Plain_wave_generator<T,N,Wave<T,N>,Policy::OpenMP>> { \
50  return std::unique_ptr<Plain_wave_generator<T,N,Wave<T,N>,Policy::OpenMP>>( \
51  new Plain_wave_generator_openmp<T,N,Wave<T,N>>() \
52  ); \
53 }
54 
55 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(VTB_REAL_TYPE,3,vtb::core::Propagating_cosine_wave)
56 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(VTB_REAL_TYPE,3,vtb::core::Standing_cosine_wave)
57 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(VTB_REAL_TYPE,3,vtb::core::Propagating_stokes_wave)
58 #if defined(VTB_REAL_TYPE_FLOAT)
59 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(double,3,vtb::core::Propagating_cosine_wave);
60 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(double,3,vtb::core::Standing_cosine_wave);
61 VTB_MAKE_PLAIN_WAVE_SURFACE_GENERATOR(double,3,vtb::core::Propagating_stokes_wave);
62 #endif
63 
64 template <class T, int N>
66 vtb::core::make_plain_wave_generator_openmp(std::any wave) {
68  using propagating_cosine = Propagating_cosine_wave<T,N>;
69  using standing_cosine = Standing_cosine_wave<T,N>;
70  using propagating_stokes = Propagating_stokes_wave<T,N>;
71  if (wave.type() == typeid(propagating_cosine)) {
72  return pointer(new Plain_wave_generator_openmp<T,N,propagating_cosine>(
73  std::any_cast<propagating_cosine>(wave)));
74  }
75  if (wave.type() == typeid(standing_cosine)) {
76  return pointer(new Plain_wave_generator_openmp<T,N,standing_cosine>(
77  std::any_cast<standing_cosine>(wave)));
78  }
79  if (wave.type() == typeid(propagating_stokes)) {
80  return pointer(new Plain_wave_generator_openmp<T,N,propagating_stokes>(
81  std::any_cast<propagating_stokes>(wave)));
82  }
83  throw std::invalid_argument("bad wave");
84 }
85 
87 vtb::core::make_plain_wave_generator_openmp<VTB_REAL_TYPE,3>(std::any wave);
88 #if defined(VTB_REAL_TYPE_FLOAT)
90 vtb::core::make_plain_wave_generator_openmp<double,3>(std::any wave);
91 #endif
Propagating plain wave which has cosine shape.
Definition: cosine_wave.hh:17
Propagating third-order Stokes wave.
Definition: stokes_wave.hh:33
A region defined by start and end index and lower and upper bound for each dimension.
Definition: core/grid.hh:25
Wavy surface generator that produces elevation grid for individual wave.
Main namespace.
Definition: convert.hh:9
Standing plain wave which has cosine shape.
Definition: cosine_wave.hh:56
Base class for wavy surface generators.
Definition: core/types.hh:50