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  * The distance travelled is obtained by consistency with method JSoundVelocity::getTime.
108  *
109  * \param t_s time [s]
110  * \param z1 depth [m]
111  * \param z2 depth [m]
112  * return distance [m]
113  */
114  virtual double getDistance(const double t_s,
115  const double z1,
116  const double z2) const
117  {
118  const double eps = 1.0e-8;
119 
120  const double v1 = (*this)(z1);
121  const double v2 = (*this)(z2);
122  const double lv = log(v2/v1);
123 
124  if (fabs(lv) > eps)
125  return t_s * fabs((z2 - z1) * b / lv);
126  else
127  return 0.5 * t_s * (v1 + v2);
128  }
129 
130 
131  /**
132  * Get propagation time of sound.
133  *
134  * The propagation time is obtained from the integral \f$\Delta T = \frac{D}{\Delta z} \int\frac{1}{V(z)}dz\f$.
135  *
136  * \param D_m distance [m]
137  * \param z1 depth [m]
138  * \param z2 depth [m]
139  * return time [s]
140  */
141  virtual double getTime(const double D_m,
142  const double z1,
143  const double z2) const
144  {
145  const double eps = 1.0e-8;
146 
147  const double ct = (z2 - z1) / D_m;
148  const double v1 = (*this)(z1);
149  const double v2 = (*this)(z2);
150 
151  if (fabs(ct) > eps)
152  return fabs(log(v2/v1) / (ct*b));
153  else
154  return 2.0 * D_m / (v1 + v2);
155  }
156 
157 
158  /**
159  * Get inverse velocity of sound.
160  *
161  * The inverse velocity is obtained from the propagation time given by method JSoundVelocity::getTime.
162  *
163  * \param D_m distance [m]
164  * \param z1 depth [m]
165  * \param z2 depth [m]
166  * return inverse velocity [s/m]
167  */
168  virtual double getInverseVelocity(const double D_m,
169  const double z1,
170  const double z2) const
171  {
172  const double eps = 1.0e-8;
173 
174  const double ct = (z2 - z1) / D_m;
175  const double v1 = (*this)(z1);
176  const double v2 = (*this)(z2);
177 
178  if (fabs(ct) > eps)
179  return fabs(log(v2/v1) / ((z2 - z1) * b));
180  else
181  return 2.0 / (v1 + v2);
182  }
183 
184 
185  /**
186  * Read sound velocity from input.
187  *
188  * \param in input stream
189  * \param velocity sound velocity
190  * \return input stream
191  */
192  friend inline std::istream& operator>>(std::istream& in, JSoundVelocity& velocity)
193  {
194  if (in >> velocity.a) {
195 
196  in >> velocity.b
197  >> velocity.z0;
198 
199  in.clear();
200  }
201 
202  return in;
203  }
204 
205 
206  /**
207  * Write sound velocity to output.
208  *
209  * \param out output stream
210  * \param velocity sound velocity
211  * \return output stream
212  */
213  friend inline std::ostream& operator<<(std::ostream& out, const JSoundVelocity& velocity)
214  {
215  out << velocity.a << ' ' << velocity.b << ' ' << velocity.z0;
216 
217  return out;
218  }
219 
220  private:
221  double a;
222  double b;
223  double z0;
224  };
225 
226 
227  /**
228  * Function object for velocity of sound.
229  */
230  static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0);
231 }
232 
233 #endif
virtual double getDistance(const double t_s, const double z1, const double z2) const
Get distance travelled by sound.
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.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
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.