Jpp  19.1.0
the software that should make you happy
Functions
JBellhop.cc File Reference

Example program for sound ray tracing. More...

#include <iostream>
#include <iomanip>
#include <limits>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "JAcoustics/JSoundVelocity.hh"
#include "JLang/JException.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program for sound ray tracing.

Author
mdejong

Definition in file JBellhop.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 317 of file JBellhop.cc.

318 {
319  using namespace std;
320  using namespace JPP;
321 
322  string outputFile;
323  JSoundVelocity V = getSoundVelocity; // default sound velocity
324  double precision;
325  int debug;
326 
327  try {
328 
329  JParser<> zap("Example program for sound ray tracing.");
330 
331  zap['o'] = make_field(outputFile) = "";
332  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
333  zap['e'] = make_field(precision) = 1.0e-3;
334  zap['d'] = make_field(debug) = 2;
335 
336  zap(argc, argv);
337  }
338  catch(const exception &error) {
339  FATAL(error.what() << endl);
340  }
341 
342 
343  V.set(-3500);
344 
345  const JBellhop bellhop(V, precision);
346 
347  if (outputFile == "") {
348 
349  double x0, z0;
350  double x1, z1;
351  /*
352  x0 = 0.0; z0 = 0.0;
353  x1 = 2000.0; z1 = 10.0;
354 
355  {
356  */
357  //
358  for ( ; ; ) {
359 
360  cout << "> " << flush;
361  cin >> x0 >> z0 >> x1 >> z1;
362  //
363 
364  try {
365 
366  const double D = hypot(x1 - x0, z1 - z0);
367  const sin_t s0 = bellhop(x0, z0, x1, z1);
368  const JBellhop_t result = bellhop(s0, x0, z0, x1, z1);
369 
370  cout << "s " << SCIENTIFIC(12,5) << (x1 - x0) / D << endl;
371  cout << "s0 " << SCIENTIFIC(12,5) << s0.value << ' ' << s0.option << endl;
372  cout << "s1 " << SCIENTIFIC(12,5) << result.s.value << endl;
373  cout << "x' " << FIXED (12,5) << result.x << " [m]" << endl;
374  cout << "z' " << FIXED (12,5) << result.z << " [m]" << endl;
375  cout << "D " << FIXED (12,5) << D << " [m]" << endl;
376  cout << "D' " << FIXED (12,5) << result.d << " [m]" << endl;
377  cout << "t " << FIXED (12,5) << V.getTime(D, z0, z1) << " [s]" << endl;
378  cout << "t' " << FIXED (12,5) << result.t << " [s]" << endl;
379 
380 
381  const double v0 = V(z0);
382  const double v1 = V(z1);
383  const double b = (v1 - v0) / (z1 - z0);
384  const double c = v1 / v0;
385  const double u = (v0 + v1) / v1;
386  const double v = (v0 - v1) / v1;
387  const double st = s0.value;
388 
389  cout << "v0 " << FIXED (12,5) << v0 << " [m/s]" << endl;
390  cout << "v1 " << FIXED (12,5) << v1 << " [m/s]" << endl;
391 
392  double dx = 0.0;
393 
394  if (s0.option) {
395 
396  dx = (sqrt(2.0 + st) * sqrt(0.0 - st) - sqrt(1.0 + c + c * st) * sqrt(1.0 - c - c * st)) * v0 / (1.0 + st) / b;
397 
398  } else {
399 
400  dx = (sqrt(1.0 + st) * sqrt(1.0 - st) - sqrt(1.0 + c * st) * sqrt(1.0 - c * st)) * v0 / ( st ) / b;
401  }
402 
403  cout << "x' " << FIXED (12,5) << dx << " [m]" << endl;
404 
405  const double x = s0.getc();
406  const double y = (s0.option ? c * sqrt(u + st) * sqrt(v - st) : sqrt(1.0 + c * st) * sqrt(1.0 - c * st));
407 
408  cout << "t' " << FIXED (12,5) << (atanh(x) - atanh(y)) / b << endl;
409  }
410  catch(const exception& error) {
411  cerr << error.what() << endl;
412  }
413  }
414 
415  } else {
416 
417  const double x0 = 0.0;
418  const double z0 = 0.0;
419 
420  JQuantile Qx("x");
421  JQuantile Qz("z");
422 
423  TFile out(outputFile.c_str(), "recreate");
424 
425  TH2D h2("h2", NULL, 50, 1.0, 3.5, 50, -1.0, 3.0);
426 
427  for (int ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
428  for (int iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
429 
430  const double x1 = pow(10.0, h2.GetXaxis()->GetBinCenter(ix));
431  const double z1 = pow(10.0, h2.GetYaxis()->GetBinCenter(iy));
432 
433  STATUS("x1 " << FIXED(12,6) << x1 << " [m]" << ' '); DEBUG(endl);
434  STATUS("z1 " << FIXED(12,6) << z1 << " [m]" << '\r'); DEBUG(endl);
435 
436  try {
437 
438  const double D = hypot(x1 - x0, z1 - z0);
439  const sin_t s0 = bellhop(x0, z0, x1, z1);
440  const JBellhop_t result = bellhop(s0, x0, z0, x1, z1);
441 
442  Qx.put(result.x - x1);
443  Qz.put(result.z - z1);
444 
445  h2.SetBinContent(ix, iy, (result.t - V.getTime(D, z0, z1)) * 1.0e6); // [us]
446  }
447  catch(const exception& error) {
448  ERROR(error.what() << endl);
449  }
450  }
451  }
452 
453  Qx.print(cout);
454  Qz.print(cout);
455 
456  out.Write();
457  out.Close();
458  }
459 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Utility class to parse command line options.
Definition: JParser.hh:1698
static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0)
Function object for velocity of sound.
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double u[N+1]
Definition: JPolint.hh:865
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
virtual double getTime(const double D_m, const double z1, const double z2) const override
Get propagation time of sound.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary data structure for running average, standard deviation and quantiles.
Definition: JQuantile.hh:46
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488