Jpp 19.3.0-rc.2
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
8#include "JSystem/JStat.hh"
10
12
13
14/**
15 * \file
16 *
17 * Sound velocity.
18 * \author mdejong
19 */
20namespace JACOUSTICS {}
21namespace JPP { using namespace JACOUSTICS; }
22
23namespace JACOUSTICS {
24
25 /**
26 * Implementation for depth dependend 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 */
37 {
38 /**
39 * Constructor.
40 *
41 * Note that the depth is relative to the sea surface and therefore should be 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 the depth is relative to the sea surface and therefore should be 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 the depth is relative to the sea surface and therefore should be 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 at seabed.
87 *
88 * \return velocity [m/s]
89 */
90 virtual double operator()() const override
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 override
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.\n
112 * Note that the depth is relative to the seabed.
113 *
114 * \param t_s time [s]
115 * \param z1 depth [m]
116 * \param z2 depth [m]
117 * \return distance [m]
118 */
119 virtual double getDistance(const double t_s,
120 const double z1,
121 const double z2) const override
122 {
123 const double eps = 1.0e-8;
124
125 const double v1 = (*this)(z1);
126 const double v2 = (*this)(z2);
127 const double lv = log(v2/v1);
128
129 if (fabs(lv) > eps)
130 return t_s * fabs((z2 - z1) * b / lv);
131 else
132 return 0.5 * t_s * (v1 + v2);
133 }
134
135
136 /**
137 * Get propagation time of sound.
138 *
139 * The propagation time is obtained from the integral \f$\Delta T = \frac{D}{\Delta z} \int\frac{1}{V(z)}dz\f$.\n
140 * Note that the depth is relative to the seabed.
141 *
142 * \param D_m distance [m]
143 * \param z1 depth [m]
144 * \param z2 depth [m]
145 * \return time [s]
146 */
147 virtual double getTime(const double D_m,
148 const double z1,
149 const double z2) const override
150 {
151 const double eps = 1.0e-8;
152
153 const double ct = (z2 - z1) / D_m;
154 const double v1 = (*this)(z1);
155 const double v2 = (*this)(z2);
156
157 if (fabs(ct) > eps)
158 return fabs(log(v2/v1) / (ct*b));
159 else
160 return 2.0 * D_m / (v1 + v2);
161 }
162
163
164 /**
165 * Get inverse velocity of sound.
166 *
167 * The inverse velocity is obtained from the propagation time given by method JSoundVelocity::getTime.\n
168 * Note that the depth is relative to the seabed.
169 *
170 * \param D_m distance [m]
171 * \param z1 depth [m]
172 * \param z2 depth [m]
173 * \return inverse velocity [s/m]
174 */
175 virtual double getInverseVelocity(const double D_m,
176 const double z1,
177 const double z2) const override
178 {
179 const double eps = 1.0e-8;
180
181 const double ct = (z2 - z1) / D_m;
182 const double v1 = (*this)(z1);
183 const double v2 = (*this)(z2);
184
185 if (fabs(ct) > eps)
186 return fabs(log(v2/v1) / ((z2 - z1) * b));
187 else
188 return 2.0 / (v1 + v2);
189 }
190
191
192 /**
193 * Read sound velocity from input.
194 *
195 * \param in input stream
196 * \param velocity sound velocity
197 * \return input stream
198 */
199 friend inline std::istream& operator>>(std::istream& in, JSoundVelocity& velocity)
200 {
201 using namespace JPP;
202
203 JStringStream is(in);
204
205 if (getFileStatus(is.str().c_str())) {
206 is.load();
207 }
208
209 if (is >> velocity.a) {
210
211 is >> velocity.b
212 >> velocity.z0;
213
214 is.clear();
215 }
216
217 return in;
218 }
219
220
221 /**
222 * Write sound velocity to output.
223 *
224 * \param out output stream
225 * \param velocity sound velocity
226 * \return output stream
227 */
228 friend inline std::ostream& operator<<(std::ostream& out, const JSoundVelocity& velocity)
229 {
230 out << velocity.a << ' ' << velocity.b << ' ' << velocity.z0;
231
232 return out;
233 }
234
235 private:
236 double a;
237 double b;
238 double z0;
239 };
240
241
242 /**
243 * Function object for velocity of sound.
244 */
245 static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0);
246}
247
248#endif
Abstract sound velocity.
File status.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
void load()
Load data from file with name corresponding to current contents.
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.