FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SensorEchosounder.h
1#pragma once
2
260#include "SampleClock.h"
261#include "SensorFrame.h"
262#include "SensorNoise.h"
263
264#include <fhsim/simobject/SimObject.h>
265#include <fstream>
266#include <memory>
267#include <string>
268#include <vector>
269
270namespace environment
271{
272class EnvironmentProvider;
273}
274
275class SensorEchosounder : public SimObject
276{
277public:
279 struct Settings
280 {
281 double pingPeriod = 0.5;
282 double maxRangeDown = 150.0;
283 double maxRangeUp = 150.0;
284 double rayStepSize = 1.0;
285 double rayTolerance = 0.01;
286 double rangeBias = 0.02;
287 double rangeNoiseStd = 0.02;
288 double rangeNoiseRelative = 0.0005;
289
290 double beamWidthDeg = 7.0;
291
292 double binSize = 1.0;
293 double svFloorDb = -140.0;
295
296 unsigned int noiseSeed = 0;
297 };
298
300 struct Reading
301 {
302 double seafloorDistance = 0.0;
303 double seafloorDepth = 0.0;
304 double altitude = 0.0;
305 double valid = 0.0;
306 double pingTime = 0.0;
307 };
308
310 struct Species
311 {
312 std::string name;
313 int handle = -1;
314 double massKg = 0.0;
315 double lengthM = 0.0;
316 double tsRefDb = 0.0;
317 double refFreqkHz = 38.0;
318 double slopeDbPerOctave = 0.0;
319 };
320
326 SensorEchosounder(std::string simObjectName, ISimObjectCreator* creator);
327
339 SensorEchosounder(std::string simObjectName, const Settings& settings);
340
343
351 static double PerturbRange(double trueRange, const Settings& settings, SensorNoise& noise);
352
359 static double AltitudeOf(double slantRange, const double beamDirection[3]);
360
367 static int BinIndexOf(double range, double binSize);
368
375 static double TargetStrengthDb(const Species& species, double frequencykHz);
376
383 static double BackscatterCrossSection(const Species& species, double frequencykHz);
384
392 static double NoiseFloorLinear(double noiseSvAt1mDb, double absorptionDbPerKm, double range);
393
395 void OdeFcn(const double dT, const double* const adX, double* const adXDot) const override;
396
402 void AcceptedStep(const double dT, const double* const adX) override;
403
410 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator) override;
411
412#ifdef FH_VISUALIZATION
423 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) override;
424
430 void RenderUpdate(const double dT, const double* const adX) override;
431#endif
432
434 const Reading& HeldReading() const { return m_reading; }
435
437 const Settings& GetSettings() const { return m_settings; }
438
440 const std::vector<Species>& GetSpecies() const { return m_species; }
441
443 int PingsTaken() const { return m_pingsTaken; }
444
446 const std::vector<double>& Frequencies() const { return m_frequencykHz; }
447
448protected:
450 const double* OutSeafloorDistance(const double dT, const double* const adX);
451
453 const double* OutSeafloorDepth(const double dT, const double* const adX);
454
456 const double* OutAltitude(const double dT, const double* const adX);
457
459 const double* OutValid(const double dT, const double* const adX);
460
462 const double* OutPingTime(const double dT, const double* const adX);
463
464private:
469 void ReadFrequencyArrays(ISimObjectCreator* const creator);
470
475 void ReadFileParameters(ISimObjectCreator* const creator);
476
481 void ResolveEnvironment(ISimObjectCreator* const creator);
482
489 void ResolveSpecies(ISimObjectCreator* const creator);
490
496 void Ping(double dT, const double* const adX);
497
506 double MeasureBottom(double dT, const double position[3], const double beamDown[3]);
507
518 void WriteBeam(double dT, const double position[3], const double direction[3],
519 const char* beamLabel, double beamRange, double bottomRange);
520
528 static double RangeToSurface(const double position[3], const double direction[3], double maxRange);
529
534 void OpenFileAndWriteHeader(ISimObjectCreator* const creator);
535
537 void Warn(const std::string& text) const;
538
539 SensorFrame m_frame;
540 SampleClock m_pingClock;
541 SensorNoise m_noise;
542 Settings m_settings;
543
544 std::string m_name;
545
546 std::vector<std::string> m_speciesFieldNames;
547 bool m_autoDiscover = false;
548 std::vector<Species> m_species;
549
550 std::vector<double> m_frequencykHz;
551 std::vector<double> m_absorptionDbPerKm;
552 std::vector<double> m_bottomBackscatterDb;
553 std::vector<double> m_noiseSvAt1mDb;
554 std::vector<double> m_svBiasDb;
555
556 bool m_writeFile = true;
557 std::string m_fileName;
558 int m_flushEveryNPings = 20;
559 int m_svPrecision = 2;
560
561 std::unique_ptr<std::ofstream> m_stream;
562
563 environment::EnvironmentProvider* m_environment = nullptr;
564 PrintDuringExec* m_print = nullptr;
565
566 bool m_hasPorts = false;
567 int m_pingsTaken = 0;
568
569 Reading m_reading;
570
572 std::vector<double> m_binConcentration;
573
575 std::string m_row;
576
577#ifdef FH_VISUALIZATION
578 Ogre::SceneManager* m_sceneMgr = nullptr;
579 Ogre::SceneNode* m_beamNode = nullptr;
580 Ogre::ManualObject* m_beamObject = nullptr;
581#endif
582};
Definition SampleClock.h:40
Definition SensorEchosounder.h:276
static double NoiseFloorLinear(double noiseSvAt1mDb, double absorptionDbPerKm, double range)
const double * OutSeafloorDepth(const double dT, const double *const adX)
The inferred depth of the seafloor, m.
const double * OutAltitude(const double dT, const double *const adX)
The measured height above the seafloor, m.
const double * OutValid(const double dT, const double *const adX)
One when the last ping found a bottom, zero otherwise.
const std::vector< double > & Frequencies() const
The operating frequencies, kHz.
Definition SensorEchosounder.h:446
static double BackscatterCrossSection(const Species &species, double frequencykHz)
static double AltitudeOf(double slantRange, const double beamDirection[3])
void FinalSetup(const double dT, const double *const adX, ISimObjectCreator *const creator) override
static double PerturbRange(double trueRange, const Settings &settings, SensorNoise &noise)
int PingsTaken() const
The number of pings taken so far.
Definition SensorEchosounder.h:443
const double * OutSeafloorDistance(const double dT, const double *const adX)
The measured slant range to the seafloor, m.
static double TargetStrengthDb(const Species &species, double frequencykHz)
SensorEchosounder(std::string simObjectName, const Settings &settings)
void OdeFcn(const double dT, const double *const adX, double *const adXDot) const override
Writes no derivatives: this SimObject declares no states.
SensorEchosounder(std::string simObjectName, ISimObjectCreator *creator)
const std::vector< Species > & GetSpecies() const
The species entering the acoustic model, in file column order.
Definition SensorEchosounder.h:440
const Reading & HeldReading() const
The reading currently held on the output ports.
Definition SensorEchosounder.h:434
~SensorEchosounder() override
Flushes and closes the echogram file, and releases the visualisation geometry.
const double * OutPingTime(const double dT, const double *const adX)
The time of the ping the held reading came from, s.
void AcceptedStep(const double dT, const double *const adX) override
const Settings & GetSettings() const
The settings the instrument was built with.
Definition SensorEchosounder.h:437
static int BinIndexOf(double range, double binSize)
Definition SensorFrame.h:36
Definition SensorNoise.h:39
The altimeter reading held on the output ports between pings.
Definition SensorEchosounder.h:301
double valid
One when a bottom was found, zero otherwise.
Definition SensorEchosounder.h:305
double pingTime
The time of the ping this reading came from, s.
Definition SensorEchosounder.h:306
double seafloorDepth
The inferred depth of the seafloor, m.
Definition SensorEchosounder.h:303
double seafloorDistance
The measured slant range to the seafloor, m.
Definition SensorEchosounder.h:302
double altitude
The measured height above the seafloor, m.
Definition SensorEchosounder.h:304
Everything the instrument is configured with.
Definition SensorEchosounder.h:280
double independentSamplesPerBin
The Gamma shape of the speckle.
Definition SensorEchosounder.h:294
double rayTolerance
The convergence tolerance of the ray intersection, m.
Definition SensorEchosounder.h:285
double maxRangeUp
The longest slant range binned upwards, m.
Definition SensorEchosounder.h:283
double rangeNoiseRelative
The relative range noise standard deviation.
Definition SensorEchosounder.h:288
double beamWidthDeg
The full opening angle of the drawn beam, degrees. Visualisation only.
Definition SensorEchosounder.h:290
double rangeBias
The constant offset of the measured range, m.
Definition SensorEchosounder.h:286
double svFloorDb
The lowest Sv ever reported, dB.
Definition SensorEchosounder.h:293
double rayStepSize
The search step of the ray intersection, m.
Definition SensorEchosounder.h:284
unsigned int noiseSeed
The random seed; zero is a perfect instrument.
Definition SensorEchosounder.h:296
double maxRangeDown
The longest slant range searched downwards, m.
Definition SensorEchosounder.h:282
double rangeNoiseStd
The absolute range noise standard deviation, m.
Definition SensorEchosounder.h:287
double binSize
The echogram range bin size, m.
Definition SensorEchosounder.h:292
double pingPeriod
The time between pings, s.
Definition SensorEchosounder.h:281
One species as the acoustic model sees it.
Definition SensorEchosounder.h:311
int handle
The field handle, resolved once in FinalSetup.
Definition SensorEchosounder.h:313
double slopeDbPerOctave
The target strength slope with frequency, dB per octave.
Definition SensorEchosounder.h:318
std::string name
The scalar field name.
Definition SensorEchosounder.h:312
double refFreqkHz
The frequency the target strength was measured at, kHz.
Definition SensorEchosounder.h:317
double tsRefDb
The target strength constant at the reference frequency, dB.
Definition SensorEchosounder.h:316
double lengthM
The median animal length, m.
Definition SensorEchosounder.h:315
double massKg
The mass of one animal, kg.
Definition SensorEchosounder.h:314