269#include "SampleClock.h"
270#include "SensorFrame.h"
271#include "SensorNoise.h"
274#include <fhsim/simobject/SimObject.h>
276#include <marenv/marenv.h>
284class EnvironmentProvider;
388 static double AltitudeOf(
double slantRange,
const double beamDirection[3]);
437 static double BeamPattern(
double offAxisRad,
double beamWidthDeg);
446 static void SampleDirections(
const double axis[3],
int beamSamples,
double ringAngleRad, std::vector<std::array<double, 3>>& directions);
456 static int DetectBottomBin(
const std::vector<double>& svLinear,
double binSize,
double beamRange,
double minRange,
double thresholdDb);
468 static double IntegrateOverWindow(std::span<const double> perBin,
double binSize,
double beamRange,
double windowStart,
double windowEnd);
489 static double NoiseFloorLinear(
double noiseSvAt1mDb,
double absorptionDbPerKm,
double range);
492 void OdeFcn(
const double dT,
const double*
const adX,
double*
const adXDot)
const override;
505 void FinalSetup(
const double dT,
const double*
const adX, ISimObjectCreator*
const creator)
override;
507#ifdef FH_VISUALIZATION
517 void RenderInit(Ogre::Root*
const ogreRoot, ISimObjectCreator*
const creator)
override;
523 void RenderUpdate(
const double dT,
const double*
const adX)
override;
533 const std::vector<Species>&
GetSpecies()
const {
return m_species; }
539 const std::vector<double>&
Frequencies()
const {
return m_frequencykHz; }
547 const double*
OutAltitude(
const double dT,
const double*
const adX);
549 const double*
OutValid(
const double dT,
const double*
const adX);
551 const double*
OutPingTime(
const double dT,
const double*
const adX);
553 const double*
OutSa(
const double dT,
const double*
const adX,
const int index);
561 bool outOfRange =
false;
568 void ReadFrequencyArrays(ISimObjectCreator*
const creator);
571 void PrepareFrequencyConstants();
576 void ReadFileParameters(ISimObjectCreator*
const creator);
581 void RefuseRemovedParameters(ISimObjectCreator*
const creator);
586 void ResolveEnvironment(ISimObjectCreator*
const creator);
591 void ResolveSpecies(ISimObjectCreator*
const creator);
597 void Ping(
double dT,
const double*
const adX);
606 double MeasureBottom(
double dT,
const double position[3],
const double beamDown[3]);
615 void UpdateAbsorption(
double dT,
const double position[3],
const double direction[3],
double beamRange);
624 void FormPingColumns(
double dT,
const double position[3],
const double direction[3],
double bottomRange);
632 void WriteRow(
double dT,
const double position[3],
size_t channel,
const std::vector<double>& svLinear);
637 void OpenFileAndWriteHeader(ISimObjectCreator*
const creator);
640 void Warn(
const std::string& text)
const;
649 std::vector<std::string> m_speciesFieldNames;
650 bool m_autoDiscover =
false;
651 std::vector<Species> m_species;
652 std::string m_parameterLibrary;
654 std::vector<double> m_frequencykHz;
655 std::vector<double> m_beamWidthDeg;
656 std::vector<double> m_absorptionDbPerKm;
657 bool m_absorptionGiven =
false;
658 std::vector<double> m_bottomBackscatterDb;
659 std::vector<double> m_noiseSvAt1mDb;
660 std::vector<double> m_svBiasDb;
662 bool m_writeFile =
true;
663 std::string m_fileName;
664 int m_flushEveryNPings = 20;
665 int m_svPrecision = 2;
667 std::unique_ptr<std::ofstream> m_stream;
669 environment::EnvironmentProvider* m_environment =
nullptr;
670 PrintDuringExec* m_print =
nullptr;
672 bool m_hasPorts =
false;
673 int m_pingsTaken = 0;
675 FieldWarnings m_fieldWarned;
678 std::vector<double> m_sa;
679 std::vector<double> m_integratedBiomass;
681 double m_halfWidthRad = 0.0;
682 std::vector<double> m_ringWeight;
683 std::vector<double> m_svBiasLinear;
684 std::vector<double> m_bottomBackscatterLinear;
687 std::vector<std::array<double, 3>> m_directions;
689 std::vector<double> m_axisConcentration;
691 std::vector<double> m_ringConcentration;
693 std::vector<std::vector<double>> m_svLinear;
697#ifdef FH_VISUALIZATION
698 Ogre::SceneManager* m_sceneMgr =
nullptr;
699 Ogre::SceneNode* m_beamNode =
nullptr;
700 Ogre::ManualObject* m_beamObject =
nullptr;
Definition SampleClock.h:40
Definition SensorEchosounder.h:288
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.
static int DetectBottomBin(const std::vector< double > &svLinear, double binSize, double beamRange, double minRange, double thresholdDb)
const std::vector< double > & Frequencies() const
The operating frequencies, kHz.
Definition SensorEchosounder.h:539
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:536
static double BeamPattern(double offAxisRad, double beamWidthDeg)
const double * OutSeafloorDistance(const double dT, const double *const adX)
The measured slant range to the seafloor, m.
static double BottomClearance(double rayTolerance, const double beamDirection[3])
static double IntegrateOverWindow(std::span< const double > perBin, double binSize, double beamRange, double windowStart, double windowEnd)
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.
const double * OutSa(const double dT, const double *const adX, const int index)
sa over the Integration window at one frequency, m^2/m^2.
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:533
const Reading & HeldReading() const
The reading currently held on the output ports.
Definition SensorEchosounder.h:527
static void SampleDirections(const double axis[3], int beamSamples, double ringAngleRad, std::vector< std::array< double, 3 > > &directions)
static std::string FieldStatusWarning(const std::string &sensorName, const std::string &fieldName, double depth, marenv::Status status)
static double DownSampleRangeOf(int bin, double binSize, double bottomRange, double clearance)
const double * OutIntegratedBiomass(const double dT, const double *const adX, const int index)
The Integrated biomass of one species field, kg/m^2.
~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:530
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:317
double valid
One when a bottom was found, zero otherwise.
Definition SensorEchosounder.h:321
double pingTime
The time of the ping this reading came from, s.
Definition SensorEchosounder.h:322
double seafloorDepth
The inferred depth of the seafloor, m.
Definition SensorEchosounder.h:319
double seafloorDistance
The measured slant range to the seafloor, m.
Definition SensorEchosounder.h:318
double altitude
The measured height above the seafloor, m.
Definition SensorEchosounder.h:320
Everything the instrument is configured with.
Definition SensorEchosounder.h:292
double independentSamplesPerBin
The Gamma shape of the speckle.
Definition SensorEchosounder.h:306
double rayTolerance
The convergence tolerance of the ray intersection, m.
Definition SensorEchosounder.h:296
double rangeNoiseRelative
The relative range noise standard deviation.
Definition SensorEchosounder.h:299
double beamWidthDeg
The widest full beam opening angle, degrees; the drawn cone and the sampling ring.
Definition SensorEchosounder.h:301
double minRange
The start of the Integration window, the near-field limit, m.
Definition SensorEchosounder.h:308
double rangeBias
The constant offset of the measured range, m.
Definition SensorEchosounder.h:297
double bottomOffset
The Integration window ends this far short of the detected bottom, m.
Definition SensorEchosounder.h:309
double svFloorDb
The lowest Sv ever reported, dB.
Definition SensorEchosounder.h:305
int beamSamples
The samples across the beam per range bin: the axis, then a ring.
Definition SensorEchosounder.h:302
double bottomThresholdDb
The Sv a bin needs to be detected as the bottom, dB.
Definition SensorEchosounder.h:310
double rayStepSize
The search step of the ray intersection, m.
Definition SensorEchosounder.h:295
unsigned int noiseSeed
The random seed; zero is a perfect instrument.
Definition SensorEchosounder.h:312
double maxRangeDown
The longest slant range searched and binned, m.
Definition SensorEchosounder.h:294
double rangeNoiseStd
The absolute range noise standard deviation, m.
Definition SensorEchosounder.h:298
double binSize
The echogram range bin size, m.
Definition SensorEchosounder.h:304
double pingPeriod
The time between pings, s.
Definition SensorEchosounder.h:293
One Species Concentration field as the acoustic model sees it.
Definition SensorEchosounder.h:327
int handle
The field handle, resolved once in FinalSetup.
Definition SensorEchosounder.h:329
std::string name
The scalar field name.
Definition SensorEchosounder.h:328
double lengthCm
The field's mean length, cm.
Definition SensorEchosounder.h:331
std::string speciesKey
The field's species, a key of the Parameter library.
Definition SensorEchosounder.h:330
std::vector< double > sigmaBsPerKg
sigma_bs per kg at each frequency, m^2/kg.
Definition SensorEchosounder.h:332