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