Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSoundVelocity.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JSOUNDVELOCITY__
2 #define __JACOUSTICS__JSOUNDVELOCITY__
3 
4 #include <istream>
5 #include <ostream>
6 #include <cmath>
7 
9 
10 
11 /**
12  * \file
13  *
14  * Sound velocity.
15  * \author mdejong
16  */
17 namespace JACOUSTICS {}
18 namespace JPP { using namespace JACOUSTICS; }
19 
20 namespace JACOUSTICS {
21 
22  /**
23  * Implementation for velocity of sound.
24  *
25  * Note that
26  * - z-axis is pointing upwards; and
27  * - velocity is defined at a given depth.
28 
29  * The depth is commonly referred to as the seabed.
30  */
31  struct JSoundVelocity :
33  {
34  /**
35  * Constructor.
36  *
37  * Note that depth is negative.
38  *
39  * \param a velocity [m/s]
40  * \param b d(v)/d(z) [m/s/m]
41  * \param z0 depth [m]
42  */
43  JSoundVelocity(const double a, const double b, const double z0) :
44  a (a),
45  b (b),
46  z0(z0)
47  {}
48 
49 
50  /**
51  * Set depth.
52  *
53  * Note that depth is negative.
54  *
55  * \param z0 depth [m]
56  * \return this sound velocity
57  */
58  JSoundVelocity& set(const double z0)
59  {
60  this->a += this->b * (z0 - this->z0);
61  this->z0 = z0;
62 
63  return *this;
64  }
65 
66 
67  /**
68  * Get sound velocity at given depth.
69  *
70  * Note that depth is negative.
71  *
72  * \param z0 depth [m]
73  * \return sound velocity
74  */
75  JSoundVelocity operator[](const double z0) const
76  {
77  return JSoundVelocity(*this).set(z0);
78  }
79 
80 
81  /**
82  * Get velocity of sound.
83  *
84  * \return velocity [m/s]
85  */
86  virtual double operator()() const
87  {
88  return a;
89  }
90 
91 
92  /**
93  * Get velocity of sound at given depth relative to seabed.
94  *
95  * \param z depth [m]
96  * \return velocity [m/s]
97  */
98  virtual double operator()(const double z) const
99  {
100  return a + b * z;
101  }
102 
103 
104  /**
105  * Get distance travelled by sound.
106  *
107  * \param t_s time [s]
108  * \param z1 depth [m]
109  * \param z2 depth [m]
110  * return distance [m]
111  */
112  virtual double getDistance(const double t_s,
113  const double z1,
114  const double z2) const
115  {
116  const double eps = 1.0e-8;
117 
118  const double v1 = (*this)(z1);
119  const double v2 = (*this)(z2);
120  const double lv = log(v2/v1);
121 
122  if (fabs(lv) > eps)
123  return t_s * fabs((z2 - z1) * b / lv);
124  else
125  return 0.5 * t_s * (v1 + v2);
126  }
127 
128 
129  /**
130  * Get propagation time of sound.
131  *
132  * \param D_m distance [m]
133  * \param z1 depth [m]
134  * \param z2 depth [m]
135  * return time [s]
136  */
137  virtual double getTime(const double D_m,
138  const double z1,
139  const double z2) const
140  {
141  const double eps = 1.0e-8;
142 
143  const double ct = (z2 - z1) / D_m;
144  const double v1 = (*this)(z1);
145  const double v2 = (*this)(z2);
146 
147  if (fabs(ct) > eps)
148  return fabs(log(v2/v1) / (ct*b));
149  else
150  return 2.0 * D_m / (v1 + v2);
151  }
152 
153 
154  /**
155  * Get inverse velocity of sound.
156  *
157  * \param D_m distance [m]
158  * \param z1 depth [m]
159  * \param z2 depth [m]
160  * return inverse velocity [s/m]
161  */
162  virtual double getInverseVelocity(const double D_m,
163  const double z1,
164  const double z2) const
165  {
166  const double eps = 1.0e-8;
167 
168  const double ct = (z2 - z1) / D_m;
169  const double v1 = (*this)(z1);
170  const double v2 = (*this)(z2);
171 
172  if (fabs(ct) > eps)
173  return fabs(log(v2/v1) / ((z2 - z1) * b));
174  else
175  return 2.0 / (v1 + v2);
176  }
177 
178 
179  /**
180  * Read sound velocity from input.
181  *
182  * \param in input stream
183  * \param velocity sound velocity
184  * \return input stream
185  */
186  friend inline std::istream& operator>>(std::istream& in, JSoundVelocity& velocity)
187  {
188  if (in >> velocity.a) {
189 
190  in >> velocity.b
191  >> velocity.z0;
192 
193  in.clear();
194  }
195 
196  return in;
197  }
198 
199 
200  /**
201  * Write sound velocity to output.
202  *
203  * \param out output stream
204  * \param velocity sound velocity
205  * \return output stream
206  */
207  friend inline std::ostream& operator<<(std::ostream& out, const JSoundVelocity& velocity)
208  {
209  out << velocity.a << ' ' << velocity.b << ' ' << velocity.z0;
210 
211  return out;
212  }
213 
214  private:
215  double a;
216  double b;
217  double z0;
218  };
219 
220 
221  /**
222  * Function object for velocity of sound.
223  */
224  static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0);
225 }
226 
227 #endif
virtual double getDistance(const double t_s, const double z1, const double z2) const
Get distance travelled by sound.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
JSoundVelocity(const double a, const double b, const double z0)
Constructor.
virtual double getTime(const double D_m, const double z1, const double z2) const
Get propagation time of sound.
Abstract sound velocity.
static const JSoundVelocity getSoundVelocity(1541.0,-17.0e-3,-2000.0)
Function object for velocity of sound.
virtual double getInverseVelocity(const double D_m, const double z1, const double z2) const
Get inverse velocity of sound.
Implementation for velocity of sound.
JSoundVelocity operator[](const double z0) const
Get sound velocity at given depth.
friend std::istream & operator>>(std::istream &in, JSoundVelocity &velocity)
Read sound velocity from input.
Interface for velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
virtual double operator()(const double z) const
Get velocity of sound at given depth relative to seabed.
virtual double operator()() const
Get velocity of sound.
friend std::ostream & operator<<(std::ostream &out, const JSoundVelocity &velocity)
Write sound velocity to output.