Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
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
11
12
13/**
14 * \file
15 *
16 * Sound velocity.
17 * \author mdejong
18 */
19namespace JACOUSTICS {}
20namespace JPP { using namespace JACOUSTICS; }
21
22namespace JACOUSTICS {
23
24 /**
25 * Implementation for depth dependend velocity of sound.
26 *
27 * Note that
28 * - z-axis is pointing upwards; and
29 * - velocity is defined at a given depth.
30 *
31 * It is assumed that the dependence of the sound velocity on the depth is non-zero.\n
32 * The depth is commonly referred to as the seabed.
33 */
36 {
37 /**
38 * Constructor.
39 *
40 * Note that the depth is relative to the sea surface and therefore should be negative.
41 *
42 * \param a velocity [m/s]
43 * \param b d(v)/d(z) [m/s/m]
44 * \param z0 depth [m]
45 */
46 JSoundVelocity(const double a, const double b, const double z0) :
47 a (a),
48 b (b),
49 z0(z0)
50 {}
51
52
53 /**
54 * Set depth.
55 *
56 * Note that the depth is relative to the sea surface and therefore should be negative.
57 *
58 * \param z0 depth [m]
59 * \return this sound velocity
60 */
61 JSoundVelocity& set(const double z0)
62 {
63 this->a += this->b * (z0 - this->z0);
64 this->z0 = z0;
65
66 return *this;
67 }
68
69
70 /**
71 * Get sound velocity at given depth.
72 *
73 * Note that the depth is relative to the sea surface and therefore should be negative.
74 *
75 * \param z0 depth [m]
76 * \return sound velocity
77 */
78 JSoundVelocity operator[](const double z0) const
79 {
80 return JSoundVelocity(*this).set(z0);
81 }
82
83
84 /**
85 * Get velocity of sound at seabed.
86 *
87 * \return velocity [m/s]
88 */
89 virtual double operator()() const override
90 {
91 return a;
92 }
93
94
95 /**
96 * Get velocity of sound at given depth relative to seabed.
97 *
98 * \param z depth [m]
99 * \return velocity [m/s]
100 */
101 virtual double operator()(const double z) const override
102 {
103 return a + b * z;
104 }
105
106
107 /**
108 * Get distance travelled by sound.
109 *
110 * The distance travelled is obtained by consistency with method JSoundVelocity::getTime.\n
111 * Note that the depth is relative to the seabed.
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 override
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$.\n
139 * Note that the depth is relative to the seabed.
140 *
141 * \param D_m distance [m]
142 * \param z1 depth [m]
143 * \param z2 depth [m]
144 * \return time [s]
145 */
146 virtual double getTime(const double D_m,
147 const double z1,
148 const double z2) const override
149 {
150 const double eps = 1.0e-8;
151
152 const double ct = (z2 - z1) / D_m;
153 const double v1 = (*this)(z1);
154 const double v2 = (*this)(z2);
155
156 if (fabs(ct) > eps)
157 return fabs(log(v2/v1) / (ct*b));
158 else
159 return 2.0 * D_m / (v1 + v2);
160 }
161
162
163 /**
164 * Get inverse velocity of sound.
165 *
166 * The inverse velocity is obtained from the propagation time given by method JSoundVelocity::getTime.\n
167 * Note that the depth is relative to the seabed.
168 *
169 * \param D_m distance [m]
170 * \param z1 depth [m]
171 * \param z2 depth [m]
172 * \return inverse velocity [s/m]
173 */
174 virtual double getInverseVelocity(const double D_m,
175 const double z1,
176 const double z2) const override
177 {
178 const double eps = 1.0e-8;
179
180 const double ct = (z2 - z1) / D_m;
181 const double v1 = (*this)(z1);
182 const double v2 = (*this)(z2);
183
184 if (fabs(ct) > eps)
185 return fabs(log(v2/v1) / ((z2 - z1) * b));
186 else
187 return 2.0 / (v1 + v2);
188 }
189
190
191 /**
192 * Read sound velocity from input.
193 *
194 * \param in input stream
195 * \param velocity sound velocity
196 * \return input stream
197 */
198 friend inline std::istream& operator>>(std::istream& in, JSoundVelocity& velocity)
199 {
200 using namespace JPP;
201
202 JStringStream is(in);
203
204 if (is >> velocity.a) {
205
206 is >> velocity.b
207 >> velocity.z0;
208
209 is.clear();
210 }
211
212 return in;
213 }
214
215
216 /**
217 * Write sound velocity to output.
218 *
219 * \param out output stream
220 * \param velocity sound velocity
221 * \return output stream
222 */
223 friend inline std::ostream& operator<<(std::ostream& out, const JSoundVelocity& velocity)
224 {
225 out << velocity.a << ' ' << velocity.b << ' ' << velocity.z0;
226
227 return out;
228 }
229
230 private:
231 double a;
232 double b;
233 double z0;
234 };
235
236
237 /**
238 * Function object for velocity of sound.
239 */
240 static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0);
241}
242
243#endif
Abstract sound velocity.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Auxiliary classes and methods for acoustic position calibration.
static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0)
Function object for velocity of sound.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Interface for depth dependend velocity of sound.
Implementation for depth dependend velocity of sound.
virtual double getDistance(const double t_s, const double z1, const double z2) const override
Get distance travelled by sound.
virtual double operator()(const double z) const override
Get velocity of sound at given depth relative to seabed.
friend std::ostream & operator<<(std::ostream &out, const JSoundVelocity &velocity)
Write sound velocity to output.
JSoundVelocity operator[](const double z0) const
Get sound velocity at given depth.
virtual double getTime(const double D_m, const double z1, const double z2) const override
Get propagation time of sound.
JSoundVelocity & set(const double z0)
Set depth.
virtual double getInverseVelocity(const double D_m, const double z1, const double z2) const override
Get inverse velocity of sound.
JSoundVelocity(const double a, const double b, const double z0)
Constructor.
virtual double operator()() const override
Get velocity of sound at seabed.
friend std::istream & operator>>(std::istream &in, JSoundVelocity &velocity)
Read sound velocity from input.