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