FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
SensorEchosounder.h
1#pragma once
2
263#include "SampleClock.h"
264#include "SensorFrame.h"
265#include "SensorNoise.h"
266
267#include <fhsim/simobject/SimObject.h>
268#include <fstream>
269#include <marenv/marenv.h>
270#include <memory>
271#include <string>
272#include <vector>
273
274namespace environment
275{
276class EnvironmentProvider;
277}
278
279class SensorEchosounder : public SimObject
280{
281public:
283 struct Settings
284 {
285 double pingPeriod = 0.5;
286 double maxRangeDown = 150.0;
287 double maxRangeUp = 150.0;
288 double rayStepSize = 1.0;
289 double rayTolerance = 0.01;
290 double rangeBias = 0.02;
291 double rangeNoiseStd = 0.02;
292 double rangeNoiseRelative = 0.0005;
293
294 double beamWidthDeg = 7.0;
295
296 double binSize = 1.0;
297 double svFloorDb = -140.0;
299
300 unsigned int noiseSeed = 0;
301 };
302
304 struct Reading
305 {
306 double seafloorDistance = 0.0;
307 double seafloorDepth = 0.0;
308 double altitude = 0.0;
309 double valid = 0.0;
310 double pingTime = 0.0;
311 };
312
314 struct Species
315 {
316 std::string name;
317 int handle = -1;
318 double massKg = 0.0;
319 double lengthM = 0.0;
320 double tsRefDb = 0.0;
321 double refFreqkHz = 38.0;
322 double slopeDbPerOctave = 0.0;
323 };
324
330 SensorEchosounder(std::string simObjectName, ISimObjectCreator* creator);
331
343 SensorEchosounder(std::string simObjectName, const Settings& settings);
344
347
355 static double PerturbRange(double trueRange, const Settings& settings, SensorNoise& noise);
356
366 static bool IsValidRaySearch(double rayStepSize, double rayTolerance);
367
375 static bool IsValidMaxRange(double maxRange);
376
383 static double AltitudeOf(double slantRange, const double beamDirection[3]);
384
393 static int BinCountOf(double range, double binSize);
394
402 static double SampleRangeOf(int bin, double binSize, double beamRange);
403
424 static double DownSampleRangeOf(int bin, double binSize, double bottomRange, double clearance);
425
432 static double BottomClearance(double rayTolerance, const double beamDirection[3]);
433
440 static double TargetStrengthDb(const Species& species, double frequencykHz);
441
448 static double BackscatterCrossSection(const Species& species, double frequencykHz);
449
464 static std::string FieldStatusWarning(const std::string& sensorName, const char* beamLabel,
465 const std::string& fieldName, double depth, marenv::Status status);
466
474 static double NoiseFloorLinear(double noiseSvAt1mDb, double absorptionDbPerKm, double range);
475
477 void OdeFcn(const double dT, const double* const adX, double* const adXDot) const override;
478
484 void AcceptedStep(const double dT, const double* const adX) override;
485
492 void FinalSetup(const double dT, const double* const adX, ISimObjectCreator* const creator) override;
493
494#ifdef FH_VISUALIZATION
505 void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) override;
506
512 void RenderUpdate(const double dT, const double* const adX) override;
513#endif
514
516 const Reading& HeldReading() const { return m_reading; }
517
519 const Settings& GetSettings() const { return m_settings; }
520
522 const std::vector<Species>& GetSpecies() const { return m_species; }
523
525 int PingsTaken() const { return m_pingsTaken; }
526
528 const std::vector<double>& Frequencies() const { return m_frequencykHz; }
529
530protected:
532 const double* OutSeafloorDistance(const double dT, const double* const adX);
533
535 const double* OutSeafloorDepth(const double dT, const double* const adX);
536
538 const double* OutAltitude(const double dT, const double* const adX);
539
541 const double* OutValid(const double dT, const double* const adX);
542
544 const double* OutPingTime(const double dT, const double* const adX);
545
546private:
548 struct BeamFieldWarnings
549 {
550 bool outOfRange = false;
551 bool error = false;
552 };
553
558 void ReadFrequencyArrays(ISimObjectCreator* const creator);
559
564 void ReadFileParameters(ISimObjectCreator* const creator);
565
570 void ResolveEnvironment(ISimObjectCreator* const creator);
571
578 void ResolveSpecies(ISimObjectCreator* const creator);
579
585 void Ping(double dT, const double* const adX);
586
595 double MeasureBottom(double dT, const double position[3], const double beamDown[3]);
596
609 void WriteBeam(double dT, const double position[3], const double direction[3],
610 const char* beamLabel, double beamRange, double bottomRange, BeamFieldWarnings& warned);
611
619 static double RangeToSurface(const double position[3], const double direction[3], double maxRange);
620
625 void OpenFileAndWriteHeader(ISimObjectCreator* const creator);
626
628 void Warn(const std::string& text) const;
629
630 SensorFrame m_frame;
631 SampleClock m_pingClock;
632 SensorNoise m_noise;
633 Settings m_settings;
634
635 std::string m_name;
636
637 std::vector<std::string> m_speciesFieldNames;
638 bool m_autoDiscover = false;
639 std::vector<Species> m_species;
640
641 std::vector<double> m_frequencykHz;
642 std::vector<double> m_absorptionDbPerKm;
643 std::vector<double> m_bottomBackscatterDb;
644 std::vector<double> m_noiseSvAt1mDb;
645 std::vector<double> m_svBiasDb;
646
647 bool m_writeFile = true;
648 std::string m_fileName;
649 int m_flushEveryNPings = 20;
650 int m_svPrecision = 2;
651
652 std::unique_ptr<std::ofstream> m_stream;
653
654 environment::EnvironmentProvider* m_environment = nullptr;
655 PrintDuringExec* m_print = nullptr;
656
657 bool m_hasPorts = false;
658 int m_pingsTaken = 0;
659
660 BeamFieldWarnings m_downFieldWarned;
661 BeamFieldWarnings m_upFieldWarned;
662
663 Reading m_reading;
664
666 std::vector<double> m_binConcentration;
667
669 std::string m_row;
670
671#ifdef FH_VISUALIZATION
672 Ogre::SceneManager* m_sceneMgr = nullptr;
673 Ogre::SceneNode* m_beamNode = nullptr;
674 Ogre::ManualObject* m_beamObject = nullptr;
675#endif
676};
Definition SampleClock.h:40
Definition SensorEchosounder.h:280
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:528
static double BackscatterCrossSection(const Species &species, double frequencykHz)
static double SampleRangeOf(int bin, double binSize, double beamRange)
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:525
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)
static double BottomClearance(double rayTolerance, const double beamDirection[3])
SensorEchosounder(std::string simObjectName, const Settings &settings)
static int BinCountOf(double range, double binSize)
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:522
const Reading & HeldReading() const
The reading currently held on the output ports.
Definition SensorEchosounder.h:516
static double DownSampleRangeOf(int bin, double binSize, double bottomRange, double clearance)
~SensorEchosounder() override
Flushes and closes the echogram file, and releases the visualisation geometry.
static bool IsValidMaxRange(double maxRange)
const double * OutPingTime(const double dT, const double *const adX)
The time of the ping the held reading came from, s.
static bool IsValidRaySearch(double rayStepSize, double rayTolerance)
void AcceptedStep(const double dT, const double *const adX) override
const Settings & GetSettings() const
The settings the instrument was built with.
Definition SensorEchosounder.h:519
static std::string FieldStatusWarning(const std::string &sensorName, const char *beamLabel, const std::string &fieldName, double depth, marenv::Status status)
Definition SensorFrame.h:36
Definition SensorNoise.h:39
Status
Definition marenv.h:40
The altimeter reading held on the output ports between pings.
Definition SensorEchosounder.h:305
double valid
One when a bottom was found, zero otherwise.
Definition SensorEchosounder.h:309
double pingTime
The time of the ping this reading came from, s.
Definition SensorEchosounder.h:310
double seafloorDepth
The inferred depth of the seafloor, m.
Definition SensorEchosounder.h:307
double seafloorDistance
The measured slant range to the seafloor, m.
Definition SensorEchosounder.h:306
double altitude
The measured height above the seafloor, m.
Definition SensorEchosounder.h:308
Everything the instrument is configured with.
Definition SensorEchosounder.h:284
double independentSamplesPerBin
The Gamma shape of the speckle.
Definition SensorEchosounder.h:298
double rayTolerance
The convergence tolerance of the ray intersection, m.
Definition SensorEchosounder.h:289
double maxRangeUp
The longest slant range binned upwards, m.
Definition SensorEchosounder.h:287
double rangeNoiseRelative
The relative range noise standard deviation.
Definition SensorEchosounder.h:292
double beamWidthDeg
The full opening angle of the drawn beam, degrees. Visualisation only.
Definition SensorEchosounder.h:294
double rangeBias
The constant offset of the measured range, m.
Definition SensorEchosounder.h:290
double svFloorDb
The lowest Sv ever reported, dB.
Definition SensorEchosounder.h:297
double rayStepSize
The search step of the ray intersection, m.
Definition SensorEchosounder.h:288
unsigned int noiseSeed
The random seed; zero is a perfect instrument.
Definition SensorEchosounder.h:300
double maxRangeDown
The longest slant range searched downwards, m.
Definition SensorEchosounder.h:286
double rangeNoiseStd
The absolute range noise standard deviation, m.
Definition SensorEchosounder.h:291
double binSize
The echogram range bin size, m.
Definition SensorEchosounder.h:296
double pingPeriod
The time between pings, s.
Definition SensorEchosounder.h:285
One species as the acoustic model sees it.
Definition SensorEchosounder.h:315
int handle
The field handle, resolved once in FinalSetup.
Definition SensorEchosounder.h:317
double slopeDbPerOctave
The target strength slope with frequency, dB per octave.
Definition SensorEchosounder.h:322
std::string name
The scalar field name.
Definition SensorEchosounder.h:316
double refFreqkHz
The frequency the target strength was measured at, kHz.
Definition SensorEchosounder.h:321
double tsRefDb
The target strength constant at the reference frequency, dB.
Definition SensorEchosounder.h:320
double lengthM
The median animal length, m.
Definition SensorEchosounder.h:319
double massKg
The mass of one animal, kg.
Definition SensorEchosounder.h:318