Marine systems simulation
Loading...
Searching...
No Matches
PelletField.h
1
10
11#ifndef PelletField_H
12#define PelletField_H
13
14#include <iostream>
15#include <Eigen/Eigen>
16#include <string>
17#include <sstream>
18
19#include "SpreaderModel.h"
20#include "SimpleFish.h"
21
22#include <EnvironmentProvider.h>
23
24#include <SimObject.h>
25
26#include "sfh/util/diagnostic.h"
27#include "sfh/text.h"
28#include "sfh/constants.h"
29#include "sfh/math.h"
30
31#include <math.h>
32#include <vector>
33
34using std::vector;
35
36#ifdef FH_VISUALIZATION
37#include <OgreBoxEmitter.h>
38#endif
39
45class PelletField : public SimObject
46{
47public:
48
49 static const int USE_SIMPLE_FISH_MODEL = 0;
50
52 PelletField(std::string sSimObjectName, ISimObjectCreator* pCreator );
54 void FinalSetup(const double T, const double *const X, ISimObjectCreator* const creator);
55
56 void InitialConditionSetup(const double T, const double *const currentIC, double* const updatedIC, ISimObjectCreator* const creator);
57
58 void OdeFcn(const double dT, const double* const adX, double* const adXDot, const bool bIsMajorTimeStep);
59
60 int getIndex(int x, int y, int z);
61
62 void calcAdvectAndDiff(double T, const double* const adX,double* const adXDot);
63
64 void calcAdvectAndDiffWorker(double T, double dt, const double* const adX, double* const adXDot, int kstart, int kend);
65
66 int* getIndexFromPos(Eigen::Vector3d position);
67
68 double getConcentration(Eigen::Vector3d position, const double* const X);
69
70 double getConcentrationAndGradient(Eigen::Vector3d position, const double* const X, double* gradient);
71
72 double removePellet(Eigen::Vector3d position, const double* const X, IStateUpdater* updater);
73
74 double getPelletWeight();
75
76 double getTotalFeed(const double *const X);
77
78 double superbeeAdv(double dt, double dx, double c_ll, double c_l, double c_c, double c_r, double c_rr, double v_l, double v_r);
79
80 bool checkSign(double value, bool signToTest);
81
82 double minmod(double v1, double v2);
83
84 double maxmod(double v1, double v2);
85
86 void PreOdeFcn(const double T, const double *const X, IStateUpdater* updater);
87
88 const virtual double* ConcAtRefPos(const double T, const double *const X, int iPos); // Output function for concentration at reference position
89 const virtual double *concOutputAtStaticPos(const double dT, const double *const adX, int iExtNode);
90
91 // BS
92 const virtual double* OutputIngestion(const double T, const double* const X); // Output function for ingestion
93
94#ifdef FH_VISUALIZATION
96 virtual void RenderInit(Ogre::Root* const ogreRoot, ISimObjectCreator* const creator);
97
99 virtual void RenderUpdate(const double T, const double* const X);
100
101 void CloudRenderInit(Ogre::SceneManager* sceneMgr);
102 void RenderCloud(const double T, const double* const X);
103#endif
104
105
106protected:
107
108 std::vector<std::string> SplitString(std::string sData,std::string separator);
109 virtual const double* Position(const double dT, const double* const adX);
110
111 double getAtPos(int i, int j, int k, const double* const X);
112
113 ISimObjectCreator* m_pCreator;
114
115 // Pointer to state vector:
116 const double* local_adX;
117 double* local_adXdot;
118
119 // Input
120 int m_nRefPosOutputs;
121 ISignalPort **m_refPos;
122 double *m_concAtRefPos;
123
124 // State vector:
125 int m_state_feed;
126 int m_numThreads; // Number of parallel threads to use
127 int m_bstates; // Number of bookkeeping states
128 int m_iwaste; // Index of state value for total accumulated waste
129 int m_iingestion; // Index of state value for total accumulated ingestion
130 int m_nfishstates, m_isimplefish; // Number of states, and index of first state value for simple fish model
131
132 double m_time_last = -1;
133 double m_dx, m_sinkingSpeed, m_diffKappaXY, m_diffKappaZ;
134 int m_imax, m_jmax, m_kmax; // Grid dimensions
135 double m_cageRad, m_cageCylDepth, m_cageTotDepth; // Cage dimensions
136 int m_feederCenterX, m_feederCenterY, m_feederType, m_feederTilt;
137 double m_feederAirSpeed, m_feederAngle;
138
139 double m_simpleFishN, m_simpleFishW, m_simpleFishStd; // Settings for simple fish population
140 int m_feedingLevel; // Vertical level of feeding input
141 double m_feedingRateMult; // Total feeding rate
142 double m_pelletWeight; // Pellet weight (g)
143 double m_totalFeed; // Total feed in grid (g)
144 double m_temperature;
145
146 vector<double> m_advect, m_diffus, m_feeding;
147 vector<vector<double>> m_feedingRate;
148
149 //bool ***m_mask;
150 bool *m_mask;
151
152 vector<vector<vector<vector<double>>>> m_currentField;
153
154 vector<vector<int>> m_cellOffsets;
155
156 int m_readCurrentField, m_outputcounter;
157
158 SpreaderModel* m_spreaderModel;
159 SimpleFish* m_simpleFish; // Simple fish ingestion model
160 int m_nStaticSensorPoints;
161 ISignalPort **m_staticPosInputs;
162 double* m_staticPosOutputs;
163 //ISignalPort *m_InEngineControl;
164
165 environment::EnvironmentProvider* m_environment;
166
167 // Keeping track of cage centre possition
170 ISignalPort* m_cageCentreNED;
173 int m_di_grid;
174 int m_dj_grid;
175 int m_di_gLast;
176 int m_dj_gLast;
178 double* m_cageCentre;
179 void setVarValFromInputPort(ISignalPort* inputPort, double* varVal, int nVal ,const double T, const double* const X);
180
181 // NEW: feeding regime
186 ISignalPort* m_feedRateIn;
187 std::string m_startDateString;
188 double m_prevTextOutputTime;
189
190 int m_pelletsEaten;
191
192
193 // BS
194 double m_IngestionRate[3];
195 double m_CurrentReduction;
196 double m_UpdateStepSize;
197 int m_UpdateNum;
198 int m_SINum;
199
200 // PC_dev ============================================
203
204#ifdef FH_VISUALIZATION
205
206 double m_visParticleSize;
207 double m_visParticleMultiplier;
208 double m_visSinkingSpeedMultiplier;
209 double m_visParticleTimeToLive;
210 double m_visParticleFadeRate;
211 int m_visParticleQuota;
212 double m_visAngleSpread;
213 std::string m_visParticleColor;
214
215 std::string m_sMaterial;
216 std::string m_sMeshName;
217 double m_dScale;
218 Ogre::Entity* m_pRenderEntity;
219 Ogre::SceneNode* m_pRenderNode;
220 Ogre::SceneManager* m_pSceneMgr;
221
222 Ogre::ParticleSystem* m_particleSystem;
223 Ogre::SceneNode* m_particleNode;
224 Ogre::ParticleEmitter* m_particleEmitter;
225#endif
226};
227
228
229#endif
Definition PelletField.h:46
float * m_gridCentre
Grid centre in cartesian coordinates. Fixed during simulation if m_boolMoveGrid equals false....
Definition PelletField.h:171
ISignalPort * m_feedRateIn
Signal port. Input port receiving feeding rate in g/s, (grams/second).
Definition PelletField.h:186
float * m_gridCentreInit
Grid centre in cartesian coordinates. Initial value.
Definition PelletField.h:172
bool m_useTankFeeding
Boolean. True if tank feeding pattern should be used.
Definition PelletField.h:201
int * m_dij_tot
Total movement of grid centre (since initialization) in grid coordinates (i,j).
Definition PelletField.h:177
bool m_boolVarFeedRate
Feeding (time and rate) determined by input during simulation.
Definition PelletField.h:184
std::string m_startDateString
String describing the start date for the data to be used.
Definition PelletField.h:187
double ** m_feedingRegime
Feeding regime with first dimension being m_nFeedingPeriods and second dimension being [startup time ...
Definition PelletField.h:183
double * m_cageCentre
Time dependent centre postion of cage. Updated by input port m_cageCentreNED.
Definition PelletField.h:178
double m_dynFeedRate
Feeding rate (g/s, grams/second) set by input port.
Definition PelletField.h:185
bool m_boolMoveGrid
Boolean. If true, the grid is moving with the centre of the grid. m_gridCentre will be equal to m_cag...
Definition PelletField.h:169
bool m_boolCagePos
Boolean indicating whether time dependent cage position is received or not.
Definition PelletField.h:168
void setVarValFromInputPort(ISignalPort *inputPort, double *varVal, int nVal, const double T, const double *const X)
Internal (to PelletField) function setting varVal equal to inputPort.
int m_nFeedingPeriods
Number of feeding periods in feeding regime.
Definition PelletField.h:182
PelletField(std::string sSimObjectName, ISimObjectCreator *pCreator)
The constructor sets the pointer to the output object and the parser object.
bool m_useFeedAsExperimentalO2Proxy
Boolean. True if feed distribution model shall be used as O2 level proxy.
Definition PelletField.h:202
ISignalPort * m_cageCentreNED
Input port receiving (x,y,z) coordinates in NED frame of cage top position. x and y are used in the c...
Definition PelletField.h:170
Definition SimpleFish.h:28
Definition SpreaderModel.h:21