Marine systems simulation
Samplifier.h
1#ifndef SAMPLIFIER_H
2#define SAMPLIFIER_H
3
4#include "SimObject.h"
5
6#include <sfh/util/CircularBuffer.h>
7
8#include <memory>
9#include <mutex>
10#include <random>
11#include <vector>
12
84class Samplifier : public SimObject
85{
86 public:
87 Samplifier(const string& simObjectName, ISimObjectCreator* const creator);
88 ~Samplifier(){};
89
90 virtual void OdeFcn(const double T, const double* const X, double* const XDot, const bool IsMajorTimeStep);
91 virtual void InitialConditionSetup(const double T, const double* const currentIC, double* const updatedIC, ISimObjectCreator* const creator);
92 virtual void FinalSetup(const double T, const double* const X, ISimObjectCreator* const creator) { m_IsSettingUp = false; };
93 const double* Output(const double T, const double* const X, const int Index);
94
95#ifdef FH_VISUALIZATION
96 // The rendering is not used.
97 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator) { }
98
99 // The rendering is not used.
100 virtual void RenderUpdate(const double T, const double* const X) { }
101#endif
102
103 protected:
104 std::unique_ptr<ISignalPort*[]> m_Input_i;
105 void SetOutputPortValues(const double T, const double* const X);
106 ICommonComputation* m_SetOutputPortValues;
107
108 private:
109 bool isOutlier(double probability);
110 bool fiftyFifty();
111 double getNoise(const int PortNo, const int PortIndex);
112
113 bool m_IsSettingUp;
114 int m_PortWidth, m_seed, m_DummyIndex;
115 std::unique_ptr<int[]> m_PortSize_i;
116
117 std::vector<std::unique_ptr<double[]>> m_noiseBias;
118 std::vector<std::unique_ptr<double[]>> m_noiseStdDev;
119 std::vector<std::unique_ptr<double[]>> m_samplingPeriod;
120 std::vector<std::unique_ptr<double[]>> m_signalSampleTime;
121 std::vector<std::unique_ptr<double[]>> m_firstSampleTime;
122 std::vector<std::unique_ptr<double[]>> m_outlierProbability;
123 std::vector<std::unique_ptr<double[]>> m_lossProbability;
124 std::vector<std::unique_ptr<int[]>> m_lostSamples;
125 std::vector<std::unique_ptr<int[]>> m_avgLostSamples;
126 std::vector<std::unique_ptr<double[]>> m_timeDelay;
127 std::vector<std::unique_ptr<double[]>> m_WriteBuffer;
128 std::vector<std::unique_ptr<double[]>> m_ReadBuffer;
129
130 std::mutex m_SignalResource;
131 std::vector<std::unique_ptr<CircularBuffer<std::pair<double, double>, 1024>[]>> m_measurementBuffer;
132
133 std::mt19937 m_generator;
134 std::uniform_real_distribution<double> m_uniform;
135 std::vector<std::unique_ptr<std::normal_distribution<double>[]>> m_normals;
136};
137
138
139#endif // include guard
Definition: Samplifier.h:85