Virtual Testbed
Ship dynamics simulator for extreme conditions
wave.cc
1 #include <vtestbed/config/real_type.hh>
2 #include <vtestbed/core/cosine_wave.hh>
3 #include <vtestbed/core/linear_wave.hh>
4 #include <vtestbed/core/stokes_wave.hh>
5 #include <vtestbed/guile/macros.hh>
6 #include <vtestbed/guile/traits.hh>
7 
16 
17 namespace {
18  SCM propagating_cosine_type;
19  SCM standing_cosine_type;
20  SCM stokes_type;
21  SCM linear_wave_type;
22  SCM kw_amplitude, kw_length, kw_direction;
23 }
24 
25 namespace vtb {
26 
27  namespace guile {
28 
29  template <> SCM propagating_cosine_traits::type() { return ::propagating_cosine_type; }
30  template <> SCM standing_cosine_traits::type() { return ::standing_cosine_type; }
31  template <> SCM stokes_traits::type() { return ::stokes_type; }
32  template <> SCM linear_wave_traits::type() { return ::linear_wave_type; }
33 
34  template <> void
35  propagating_cosine_traits::define() {
36  ::propagating_cosine_type =
37  define_type<propagating_cosine>("<propagating-cosine-wave>");
38  }
39 
40  template <> void
41  standing_cosine_traits::define() {
42  ::standing_cosine_type = define_type<standing_cosine>("<standing-cosine-wave>");
43  }
44 
45  template <> void
46  stokes_traits::define() {
47  ::stokes_type = define_type<stokes>("<propagating-stokes-wave>");
48  }
49 
50  template <> void
51  linear_wave_traits::define() {
52  ::linear_wave_type = define_type<stokes>("<linear-wave>");
53  }
54 
61  SCM make_wave(SCM type, SCM rest) {
62  using namespace vtb::core;
63  using T = VTB_REAL_TYPE;
64  SCM amplitude = to_scm(T(1)), length = to_scm(T(40)), direction = to_scm(T(0));
65  scm_c_bind_keyword_arguments("make-wave", rest,
66  scm_t_keyword_arguments_flags{},
67  kw_amplitude, &amplitude,
68  kw_length, &length,
69  kw_direction, &direction,
70  SCM_UNDEFINED);
71  if (type == propagating_cosine_type) {
72  propagating_cosine wave(Amplitude<T>(from_scm<T>(amplitude)),
73  Length<T>(from_scm<T>(length)),
74  Direction<T>(from_scm<T>(direction)));
75  return propagating_cosine_traits::make(wave);
76  }
77  if (type == propagating_cosine_type) {
78  standing_cosine wave(Amplitude<T>(from_scm<T>(amplitude)),
79  Length<T>(from_scm<T>(length)),
80  Direction<T>(from_scm<T>(direction)));
81  return standing_cosine_traits::make(wave);
82  }
83  if (type == stokes_type) {
84  stokes wave(Amplitude<T>(from_scm<T>(amplitude)),
85  Length<T>(from_scm<T>(length)),
86  Direction<T>(from_scm<T>(direction)));
87  return stokes_traits::make(wave);
88  }
89  if (type == linear_wave_type) {
90  linear_wave wave(Amplitude<T>(from_scm<T>(amplitude)),
91  Length<T>(from_scm<T>(length)),
92  Direction<T>(from_scm<T>(direction)));
93  return linear_wave_traits::make(wave);
94  }
95  return SCM_UNSPECIFIED;
96  }
97 
98  void wave_define() {
99  kw_amplitude = scm_from_utf8_keyword("amplitude");
100  kw_length = scm_from_utf8_keyword("length");
101  kw_direction = scm_from_utf8_keyword("direction");
102  define_procedure("make-wave", 1, 0, 1, VTB_GUILE_2(make_wave));
103  }
104 
105  }
106 
107 }
Propagating plain wave which has cosine shape.
Definition: cosine_wave.hh:17
Propagating third-order Stokes wave.
Definition: stokes_wave.hh:33
Core components.
Definition: bstream.hh:181
SCM make_wave(SCM type, SCM rest)
Construct wave from amplitude, length and direction using dispersion relation.
Definition: wave.cc:61
Main namespace.
Definition: convert.hh:9
Standing plain wave which has cosine shape.
Definition: cosine_wave.hh:56