Jpp - the software that should make you happy
 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 
8 #include "JSystem/JStat.hh"
9 #include "JLang/JStringStream.hh"
10 
12 
13 
14 /**
15  * \file
16  *
17  * Sound velocity.
18  * \author mdejong
19  */
20 namespace JACOUSTICS {}
21 namespace JPP { using namespace JACOUSTICS; }
22 
23 namespace JACOUSTICS {
24 
25  /**
26  * Implementation for velocity of sound.
27  *
28  * Note that
29  * - z-axis is pointing upwards; and
30  * - velocity is defined at a given depth.
31  *
32  * It is assumed that the dependence of the sound velocity on the depth is non-zero.\n
33  * The depth is commonly referred to as the seabed.
34  */
35  struct JSoundVelocity :
37  {
38  /**
39  * Constructor.
40  *
41  * Note that depth is negative.
42  *
43  * \param a velocity [m/s]
44  * \param b d(v)/d(z) [m/s/m]
45  * \param z0 depth [m]
46  */
47  JSoundVelocity(const double a, const double b, const double z0) :
48  a (a),
49  b (b),
50  z0(z0)
51  {}
52 
53 
54  /**
55  * Set depth.
56  *
57  * Note that depth is negative.
58  *
59  * \param z0 depth [m]
60  * \return this sound velocity
61  */
62  JSoundVelocity& set(const double z0)
63  {
64  this->a += this->b * (z0 - this->z0);
65  this->z0 = z0;
66 
67  return *this;
68  }
69 
70 
71  /**
72  * Get sound velocity at given depth.
73  *
74  * Note that depth is negative.
75  *
76  * \param z0 depth [m]
77  * \return sound velocity
78  */
79  JSoundVelocity operator[](const double z0) const
80  {
81  return JSoundVelocity(*this).set(z0);
82  }
83 
84 
85  /**
86  * Get velocity of sound.
87  *
88  * \return velocity [m/s]
89  */
90  virtual double operator()() const
91  {
92  return a;
93  }
94 
95 
96  /**
97  * Get velocity of sound at given depth relative to seabed.
98  *
99  * \param z depth [m]
100  * \return velocity [m/s]
101  */
102  virtual double operator()(const double z) const
103  {
104  return a + b * z;
105  }
106 
107 
108  /**
109  * Get distance travelled by sound.
110  *
111  * The distance travelled is obtained by consistency with method JSoundVelocity::getTime.
112  *
113  * \param t_s time [s]
114  * \param z1 depth [m]
115  * \param z2 depth [m]
116  * return distance [m]
117  */
118  virtual double getDistance(const double t_s,
119  const double z1,
120  const double z2) const
121  {
122  const double eps = 1.0e-8;
123 
124  const double v1 = (*this)(z1);
125  const double v2 = (*this)(z2);
126  const double lv = log(v2/v1);
127 
128  if (fabs(lv) > eps)
129  return t_s * fabs((z2 - z1) * b / lv);
130  else
131  return 0.5 * t_s * (v1 + v2);
132  }
133 
134 
135  /**
136  * Get propagation time of sound.
137  *
138  * The propagation time is obtained from the integral \f$\Delta T = \frac{D}{\Delta z} \int\frac{1}{V(z)}dz\f$.
139  *
140  * \param D_m distance [m]
141  * \param z1 depth [m]
142  * \param z2 depth [m]
143  * return time [s]
144  */
145  virtual double getTime(const double D_m,
146  const double z1,
147  const double z2) const
148  {
149  const double eps = 1.0e-8;
150 
151  const double ct = (z2 - z1) / D_m;
152  const double v1 = (*this)(z1);
153  const double v2 = (*this)(z2);
154 
155  if (fabs(ct) > eps)
156  return fabs(log(v2/v1) / (ct*b));
157  else
158  return 2.0 * D_m / (v1 + v2);
159  }
160 
161 
162  /**
163  * Get inverse velocity of sound.
164  *
165  * The inverse velocity is obtained from the propagation time given by method JSoundVelocity::getTime.
166  *
167  * \param D_m distance [m]
168  * \param z1 depth [m]
169  * \param z2 depth [m]
170  * return inverse velocity [s/m]
171  */
172  virtual double getInverseVelocity(const double D_m,
173  const double z1,
174  const double z2) const
175  {
176  const double eps = 1.0e-8;
177 
178  const double ct = (z2 - z1) / D_m;
179  const double v1 = (*this)(z1);
180  const double v2 = (*this)(z2);
181 
182  if (fabs(ct) > eps)
183  return fabs(log(v2/v1) / ((z2 - z1) * b));
184  else
185  return 2.0 / (v1 + v2);
186  }
187 
188 
189  /**
190  * Read sound velocity from input.
191  *
192  * \param in input stream
193  * \param velocity sound velocity
194  * \return input stream
195  */
196  friend inline std::istream& operator>>(std::istream& in, JSoundVelocity& velocity)
197  {
198  using namespace JPP;
199 
200  JStringStream is(in);
201 
202  if (getFileStatus(is.str().c_str())) {
203  is.load();
204  }
205 
206  if (is >> velocity.a) {
207 
208  is >> velocity.b
209  >> velocity.z0;
210 
211  is.clear();
212  }
213 
214  return in;
215  }
216 
217 
218  /**
219  * Write sound velocity to output.
220  *
221  * \param out output stream
222  * \param velocity sound velocity
223  * \return output stream
224  */
225  friend inline std::ostream& operator<<(std::ostream& out, const JSoundVelocity& velocity)
226  {
227  out << velocity.a << ' ' << velocity.b << ' ' << velocity.z0;
228 
229  return out;
230  }
231 
232  private:
233  double a;
234  double b;
235  double z0;
236  };
237 
238 
239  /**
240  * Function object for velocity of sound.
241  */
242  static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0);
243 }
244 
245 #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.
is
Definition: JDAQCHSM.chsm:167
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.
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
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 CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
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.
File status.