Marine systems simulation
IndividualFish.h
1#ifndef INDIVIDUAL_FISH_H
2#define INDIVIDUAL_FISH_H
3
4#include "sfh/math/math.h"
5#include "sfh/math/array.h"
6#include "sfh/text.h"
7#include "sfh/linalg.h"
8#include "sfh/constants.h"
9#include "sfh/util/diagnostic.h"
10#include "sfh/sim.h"
11#include "sfh/sim/Quaternion.h"
12#include "CEnvironment.h"
13#include <CPrintDuringExec.h>
14
15#include "compact_data_representations.h"
16
17#include <random>
18
19#include <CPrintDuringExec.h>
20#include <CEnvironment.h>
21#include "DebModel.h"
22#include "FishParameters.h"
23#include "eigen_matrix_defs.h"
24#include "../particles/PelletField.h"
25#include "../environment/VerticalAbioticEnvironment.h"
26#include "FishCage.h"
27#include "Z_Tree.h"
28
29
31 Fish::DebModel m_debModel;
34 CEnvironment *m_env;
35 VerticalAbioticEnvironment *m_abioticEnvironment;
36 Grid::FastNeighbourLookup m_spatial_map;
37 Fish::FishCage m_cage;
38 std::vector<Fish::IndividualFish>* m_individuals;
39 int m_base_state_index;
40 bool m_surfRespActive;
41 bool m_wallRespActive;
42 bool m_feedRespActive;
43 bool m_tempRespActive;
44 bool m_lightRespActive;
45 bool m_nbRespActive;
46 bool m_stochRespActive;
47 bool m_wvelRespActive;
48
49 //============================================================================ biao_dev
50 int m_ObstacleNum;
51 double m_ObstaclePrefDis;
52 Fish::vec3 m_ObstaclePos;
53 Fish::vec3 m_ObstacleVel;
54 //============================================================================ biao_dev
55};
56
57
101namespace Fish{
102 static const int g_NumStatesPerFish = 10;
103
105 {
106 public:
107
108 void Init(FishResources *fishResources, std::mt19937& rng, const double* states);
109
110 void calculateDerivative(
111 int index,
112 const double T,
113 const double* const X,
114 double * const XDot,
115 std::mt19937& rng,
116 std::vector<int>& ingestionList,
117 bool& obstacle
118 //============================================================================ herman_dev
119 //, const double delta_T
120 //============================================================================ herman_dev
121 );
122
123 vec3 Position(){return m_Position;}
124 vec3 Velocity(){return m_Velocity;}
125 double BodyLength(){return m_Length;}
126 double CharacteristicVelocity(){return m_characteristicVelocityFactor;}
127
128
129 char BehaviouralState(){return m_behaviouralState;}
130 void UpdateStates(const double* states);
131 void WriteStates(double* states);
132
133 int entropy();
134
135 inline static double forward_scanning_distance(const vec3& P0, const vec3& V0,const vec3& P1,const vec3& V1) {
136 vec3 dP = P1 - P0;
137 vec3 dV = V1 - V0;
138 double d = dP.norm();
139 double x = dP.dot(dV);
140 return d + x/(x*x+1.0);
141 }
142
143 //============================================================================ biao_dev
144 //void mass_gain(const double& fMass){m_Mass = fMass/1000.0;}
145
146 vec3 VelocityRel() {return m_VelocityRel;}
147 double GetDEBG0() {return m_debG0;}
148 double GetDEBE0() {return m_debE0;}
149 double GetDEBV0() {return m_debV0;}
150 //============================================================================ biao_dev
151
152
153#ifdef FH_VISUALIZATION
154 Eigen::Vector3f Color();
155 Eigen::Vector3f m_rgb;
156#endif
157
158 protected:
160 behaviour_vote(){direction.setZero();vote_gain=0.0;}
161 behaviour_vote(const vec3& d, double g){direction = d; vote_gain = g;}
162 vec3 direction;
163 double vote_gain;
164 };
165
166 behaviour_vote containment_behaviour(Fish::FishCage& cage, Fish::FishParameters& parameters, vec3& current, double surface_elevation, double& wallcur, double& walldis); // keep inside net and below surface. if this vote is 100%, all other behavioural patterns are neglected.
167 behaviour_vote temperature_behaviour();
168 behaviour_vote light_behaviour();
169 //behaviour_vote temperature_and_light_behaviour(); // seek equilibrium.
170 behaviour_vote schooling_behaviour(Fish::FishParameters& parameters, int index); // avoid overcrowding. converge towards dominating swimming direction.
171 behaviour_vote feed_behaviour(const double T, const double* const X, std::mt19937& rng); // approach feed if hungry and food is present
172 //============================================================================ herman_dev
173 behaviour_vote wandering_behaviour(Fish::FishParameters& parameters, std::mt19937& rng, const double T
174 //, const double delta_T
175 ); // slightly random, keep momentum, converge towards ideal swimming speed.
176 //============================================================================ herman_dev
177
178
179
180 //inline Fish::FishCage& CAGE(){return m_ptr->m_cage;}
181 //inline Fish::FishParameters& PARAMS(){return m_ptr->m_par;}
182 //inline PelletField* PELLETS(){return m_ptr->m_pellets;}
183 //inline CEnvironment* ENV(){return m_ptr->m_env;}
184 //inline VerticalAbioticEnvironment* ABIOTICENV(){return m_ptr->m_abioticEnvironment;}
185
186 // Functions
187 //void surfaceBehaviour (vec3& posDot,double surfaceElevation,vec2& quotas);
188 //void netWallBehaviour (vec3& posDot,vec2& quotas);
189 //void feedBehaviour (vec3& posDot,double T, const double* const feedData,vec2& quotas);
190 //void temperatureBehaviour (vec3& posDot, vec2& quotas);
191 //void lightLevelBehaviour (vec3& posDot, vec2& quotas);
192 //void neighborBehaviour (vec3& posDot,vec2& quotas, int current_global_index);
193 //void stochasticBehaviour (vec3& posDot,vec2& quotas,std::mt19937& rng);
194 //void waterVelocityBehaviour (vec3& posDot, vec3& waterVel,vec2& quotas);
195
196 //void getNewBehaviouralState (double T,const double* const feedData, std::mt19937& rng);
197 //double getAppetite();
198
199 // Variables
200 FishResources* m_ptr;
201
202 // Auxiliary variables
205
206 // dynamic state variables
208 vec3 m_Velocity;
209 double m_debG;
210 double m_debE;
211 double m_debV;
212 double m_Length;
213
214 char m_behaviouralState; // 0 = normal, 1 = satiated, 2 = approach feed, 3 = capture feed, 4 = manipulate feed
215 CompactData::Duration m_manipulateTime;
216 CompactData::Temperature m_prefTemperatureLow;
217 CompactData::Temperature m_prefTemperatureHigh;
218 CompactData::Speed m_characteristicVelocityFactor;
219 CompactData::Speed m_maxSustainableVelocityFactor;
220
221 bool outside_net;
222
223 //============================================================================ biao_dev
224 /*double m_Mass;
225 double m_DargA;*/
226
227 behaviour_vote obstacle_behaviour(bool& obstacle);
228 bool m_obsInt;
229
230 behaviour_vote schooling_behaviour_h(Fish::FishParameters& parameters, int index, const double T);
231 behaviour_vote schooling_behaviour_v(Fish::FishParameters& parameters, int index);
232
233 vec3 m_VelocityRel;
234 double m_debG0;
235 double m_debE0;
236 double m_debV0;
237 //============================================================================ biao_dev
238 };
239}
240#endif
Definition: CEnvironment.h:10
Definition: DebModel.h:61
Definition: FishCage.h:17
Definition: FishParameters.h:30
Definition: IndividualFish.h:105
float m_startTimeManipulation
Last timestamp at which the fish evaluated whether it experiences satiation or hunger.
Definition: IndividualFish.h:204
vec3 m_Position
Timestamp at which the fish commenced present feed manipulation.
Definition: IndividualFish.h:207
float m_lastEvaluationOfSatiation
pointer to all common resources, f.i. DebModel, FishParameters, RNG, etc.
Definition: IndividualFish.h:203
Definition: Z_Tree.h:41
Definition: PelletField.h:48
Definition: VerticalAbioticEnvironment.h:39
Definition: compact_data_representations.h:126
Definition: compact_data_representations.h:40
Definition: compact_data_representations.h:13
Definition: IndividualFish.h:30
PelletField * m_pellets
Contains all parameters or factors required to compute parameters.
Definition: IndividualFish.h:33
Definition: IndividualFish.h:159