1 : |
agomez |
1 |
#include "stock.h" |
2 : |
|
|
#include "keeper.h" |
3 : |
|
|
#include "areatime.h" |
4 : |
|
|
#include "naturalm.h" |
5 : |
|
|
#include "grower.h" |
6 : |
|
|
#include "stockprey.h" |
7 : |
|
|
#include "stockpredator.h" |
8 : |
|
|
#include "migration.h" |
9 : |
|
|
#include "maturity.h" |
10 : |
|
|
#include "renewal.h" |
11 : |
|
|
#include "transition.h" |
12 : |
|
|
#include "spawner.h" |
13 : |
|
|
#include "stray.h" |
14 : |
|
|
#include "errorhandler.h" |
15 : |
|
|
#include "gadget.h" |
16 : |
|
|
#include "global.h" |
17 : |
|
|
|
18 : |
|
|
void Stock::Migrate(const TimeClass* const TimeInfo) {
|
19 : |
|
|
if (doesmigrate && migration->isMigrationStep(TimeInfo)) {
|
20 : |
|
|
Alkeys.Migrate(migration->getMigrationMatrix(TimeInfo), tmpMigrate);
|
21 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
22 : |
|
|
tagAlkeys.Migrate(migration->getMigrationMatrix(TimeInfo), Alkeys);
|
23 : |
|
|
}
|
24 : |
|
|
}
|
25 : |
|
|
|
26 : |
|
|
//-------------------------------------------------------------------
|
27 : |
|
|
//Sum up into Growth+Predator and Prey Lengthgroups. Storage is a
|
28 : |
|
|
//vector of PopInfo that stores the sum over each lengthgroup.
|
29 : |
|
|
void Stock::calcNumbers(int area, const TimeClass* const TimeInfo) {
|
30 : |
|
|
int inarea = this->areaNum(area);
|
31 : |
|
|
Alkeys[inarea].sumColumns(tmpPopulation[inarea]);
|
32 : |
|
|
if (doesgrow)
|
33 : |
|
|
grower->Sum(tmpPopulation[inarea], area);
|
34 : |
|
|
if (iseaten) {
|
35 : |
|
|
prey->Sum(Alkeys[inarea], area);
|
36 : |
|
|
if (istagged) {
|
37 : |
|
|
int i;
|
38 : |
|
|
for (i = 0; i < allTags.Size(); i++)
|
39 : |
|
|
allTags[i]->storeConsumptionALK(area, this->getName());
|
40 : |
|
|
}
|
41 : |
|
|
}
|
42 : |
|
|
if (doeseat)
|
43 : |
|
|
((StockPredator*)predator)->Sum(Alkeys[inarea], area);
|
44 : |
|
|
}
|
45 : |
|
|
|
46 : |
|
|
//-------------------------------------------------------------------
|
47 : |
|
|
void Stock::calcEat(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
|
48 : |
|
|
if (doeseat)
|
49 : |
|
|
predator->Eat(area, Area, TimeInfo);
|
50 : |
|
|
}
|
51 : |
|
|
|
52 : |
|
|
void Stock::checkEat(int area, const TimeClass* const TimeInfo) {
|
53 : |
|
|
if (iseaten)
|
54 : |
|
|
prey->checkConsumption(area, TimeInfo);
|
55 : |
|
|
}
|
56 : |
|
|
|
57 : |
|
|
void Stock::adjustEat(int area, const TimeClass* const TimeInfo) {
|
58 : |
|
|
if (doeseat)
|
59 : |
|
|
predator->adjustConsumption(area, TimeInfo);
|
60 : |
|
|
}
|
61 : |
|
|
|
62 : |
|
|
//-------------------------------------------------------------------
|
63 : |
|
|
void Stock::reducePop(int area, const TimeClass* const TimeInfo) {
|
64 : |
|
|
int inarea = this->areaNum(area);
|
65 : |
|
|
|
66 : |
|
|
//Predation
|
67 : |
|
|
if (iseaten)
|
68 : |
|
|
prey->Subtract(Alkeys[inarea], area);
|
69 : |
|
|
|
70 : |
|
|
//Natural mortality
|
71 : |
|
|
if (TimeInfo->numSubSteps() == 1) {
|
72 : |
|
|
Alkeys[inarea].Multiply(naturalm->getProportion(area));
|
73 : |
|
|
} else {
|
74 : |
|
|
//changed to include the possibility of substeps
|
75 : |
|
|
DoubleVector* PropSurviving;
|
76 : |
|
|
PropSurviving = new DoubleVector(naturalm->getProportion(area));
|
77 : |
|
|
double timeratio = 1.0 / TimeInfo->numSubSteps();
|
78 : |
|
|
|
79 : |
|
|
int i;
|
80 : |
|
|
for (i = 0; i < PropSurviving->Size(); i++)
|
81 : |
|
|
(*PropSurviving)[i] = pow((*PropSurviving)[i], timeratio);
|
82 : |
|
|
|
83 : |
|
|
Alkeys[inarea].Multiply(*PropSurviving);
|
84 : |
|
|
delete PropSurviving;
|
85 : |
|
|
}
|
86 : |
|
|
|
87 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
88 : |
|
|
tagAlkeys[inarea].updateAndTagLoss(Alkeys[inarea], tagAlkeys.getTagLoss());
|
89 : |
|
|
}
|
90 : |
|
|
|
91 : |
|
|
//-----------------------------------------------------------------------
|
92 : |
|
|
//Function that updates the length distributions and makes part of the stock Mature.
|
93 : |
|
|
void Stock::Grow(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
|
94 : |
|
|
|
95 : |
|
|
if (!doesgrow)
|
96 : |
|
|
return;
|
97 : |
|
|
|
98 : |
|
|
if (doeseat)
|
99 : |
|
|
grower->calcGrowth(area, Area, TimeInfo, ((StockPredator*)predator)->getFPhi(area),
|
100 : |
|
|
((StockPredator*)predator)->getMaxConsumption(area));
|
101 : |
|
|
else
|
102 : |
|
|
grower->calcGrowth(area, Area, TimeInfo);
|
103 : |
|
|
int inarea = this->areaNum(area);
|
104 : |
|
|
if (grower->getFixedWeights()) {
|
105 : |
|
|
//Weights at length are fixed to the value in the input file
|
106 : |
|
|
grower->implementGrowth(area, LgrpDiv);
|
107 : |
ulcessvp |
4 |
if (doesmature && maturity->isMaturationStep(TimeInfo))
|
108 : |
|
|
Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area), maturity, area);
|
109 : |
|
|
else
|
110 : |
|
|
Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area));
|
111 : |
agomez |
1 |
|
112 : |
|
|
} else {
|
113 : |
|
|
//New weights at length are calculated
|
114 : |
|
|
grower->implementGrowth(area, tmpPopulation[inarea], LgrpDiv);
|
115 : |
|
|
if (doesmature && maturity->isMaturationStep(TimeInfo))
|
116 : |
ulcessvp |
2 |
{
|
117 : |
ulcessvp |
4 |
Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area), maturity, area);
|
118 : |
ulcessvp |
2 |
}
|
119 : |
agomez |
1 |
else
|
120 : |
ulcessvp |
4 |
Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area));
|
121 : |
agomez |
1 |
}
|
122 : |
|
|
|
123 : |
ulcessvp |
4 |
if (istagged && tagAlkeys.numTagExperiments() > 0) {
|
124 : |
|
|
if (doesmature && maturity->isMaturationStep(TimeInfo))
|
125 : |
|
|
tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea], maturity, area);
|
126 : |
|
|
else
|
127 : |
|
|
tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea]);
|
128 : |
agomez |
1 |
}
|
129 : |
ulcessvp |
2 |
|
130 : |
|
|
|
131 : |
agomez |
1 |
}
|
132 : |
|
|
|
133 : |
|
|
//-----------------------------------------------------------------------
|
134 : |
|
|
//A number of Special functions, Spawning, Renewal, Maturation and
|
135 : |
|
|
//Transition to other Stocks, Maturity due to age and increased age.
|
136 : |
|
|
void Stock::updateAgePart1(int area, const TimeClass* const TimeInfo) {
|
137 : |
|
|
if (doesmove && transition->isTransitionStep(TimeInfo)) {
|
138 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
139 : |
|
|
transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
|
140 : |
|
|
else
|
141 : |
|
|
transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], TimeInfo);
|
142 : |
|
|
}
|
143 : |
|
|
}
|
144 : |
|
|
|
145 : |
|
|
void Stock::updateAgePart2(int area, const TimeClass* const TimeInfo) {
|
146 : |
|
|
if (this->isBirthday(TimeInfo)) {
|
147 : |
|
|
Alkeys[this->areaNum(area)].IncrementAge();
|
148 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
149 : |
|
|
tagAlkeys[this->areaNum(area)].IncrementAge(Alkeys[this->areaNum(area)]);
|
150 : |
|
|
}
|
151 : |
|
|
}
|
152 : |
|
|
|
153 : |
|
|
void Stock::updateAgePart3(int area, const TimeClass* const TimeInfo) {
|
154 : |
|
|
if (doesmove && transition->isTransitionStep(TimeInfo)) {
|
155 : |
|
|
if (istagged && transitionTags.Size() > 0) {
|
156 : |
|
|
int i;
|
157 : |
|
|
for (i = 0; i < transitionTags.Size(); i++)
|
158 : |
|
|
transitionTags[i]->updateTransitionStock(TimeInfo);
|
159 : |
|
|
transitionTags.deleteAll();
|
160 : |
|
|
}
|
161 : |
|
|
transition->Move(area, TimeInfo);
|
162 : |
|
|
}
|
163 : |
|
|
|
164 : |
|
|
//JMB - only update the ratio for the tagged stock after all other age updates
|
165 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
166 : |
|
|
tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
|
167 : |
|
|
}
|
168 : |
|
|
|
169 : |
|
|
void Stock::updatePopulationPart1(int area, const TimeClass* const TimeInfo) {
|
170 : |
|
|
if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo)) {
|
171 : |
|
|
spawner->Spawn(Alkeys[this->areaNum(area)], area, TimeInfo);
|
172 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
173 : |
|
|
tagAlkeys[this->areaNum(area)].updateNumbers(Alkeys[this->areaNum(area)]);
|
174 : |
|
|
}
|
175 : |
|
|
}
|
176 : |
|
|
|
177 : |
|
|
void Stock::updatePopulationPart2(int area, const TimeClass* const TimeInfo) {
|
178 : |
|
|
if (doesmature && maturity->isMaturationStep(TimeInfo)) {
|
179 : |
|
|
if (istagged && matureTags.Size() > 0) {
|
180 : |
|
|
int i;
|
181 : |
|
|
for (i = 0; i < matureTags.Size(); i++)
|
182 : |
|
|
matureTags[i]->updateMatureStock(TimeInfo);
|
183 : |
|
|
matureTags.deleteAll();
|
184 : |
|
|
}
|
185 : |
|
|
maturity->Move(area, TimeInfo);
|
186 : |
|
|
}
|
187 : |
|
|
}
|
188 : |
|
|
|
189 : |
|
|
void Stock::updatePopulationPart3(int area, const TimeClass* const TimeInfo) {
|
190 : |
|
|
if (doesrenew && renewal->isRenewalStepArea(area, TimeInfo))
|
191 : |
|
|
renewal->addRenewal(Alkeys[this->areaNum(area)], area, TimeInfo);
|
192 : |
|
|
|
193 : |
|
|
if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo))
|
194 : |
|
|
spawner->addSpawnStock(area, TimeInfo);
|
195 : |
|
|
}
|
196 : |
|
|
|
197 : |
|
|
void Stock::updatePopulationPart4(int area, const TimeClass* const TimeInfo) {
|
198 : |
|
|
if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
|
199 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
200 : |
|
|
stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
|
201 : |
|
|
else
|
202 : |
|
|
stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], TimeInfo);
|
203 : |
|
|
}
|
204 : |
|
|
}
|
205 : |
|
|
|
206 : |
|
|
void Stock::updatePopulationPart5(int area, const TimeClass* const TimeInfo) {
|
207 : |
|
|
if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
|
208 : |
|
|
if (istagged && strayTags.Size() > 0) {
|
209 : |
|
|
int i;
|
210 : |
|
|
for (i = 0; i < strayTags.Size(); i++)
|
211 : |
|
|
strayTags[i]->updateStrayStock(TimeInfo);
|
212 : |
|
|
strayTags.deleteAll();
|
213 : |
|
|
}
|
214 : |
|
|
stray->addStrayStock(area, TimeInfo);
|
215 : |
|
|
}
|
216 : |
|
|
|
217 : |
|
|
//JMB - only update the ratio for the tagged stock after all other population updates
|
218 : |
|
|
if (istagged && tagAlkeys.numTagExperiments() > 0)
|
219 : |
|
|
tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
|
220 : |
|
|
}
|
221 : |
|
|
|
222 : |
|
|
void Stock::Add(const AgeBandMatrix& Addition,
|
223 : |
|
|
const ConversionIndex* const CI, int area, double ratio) {
|
224 : |
|
|
|
225 : |
|
|
Alkeys[this->areaNum(area)].Add(Addition, *CI, ratio);
|
226 : |
|
|
}
|
227 : |
|
|
|
228 : |
|
|
void Stock::Add(const AgeBandMatrixRatioPtrVector& Addition,
|
229 : |
|
|
const ConversionIndex* const CI, int area, double ratio) {
|
230 : |
|
|
|
231 : |
|
|
if (!istagged)
|
232 : |
|
|
return;
|
233 : |
|
|
|
234 : |
|
|
if ((Addition.numTagExperiments() > 0) && (Addition.numTagExperiments() <= tagAlkeys.numTagExperiments())) {
|
235 : |
|
|
tagAlkeys.Add(Addition, this->areaNum(area), *CI, ratio);
|
236 : |
|
|
tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
|
237 : |
|
|
}
|
238 : |
|
|
}
|
239 : |
|
|
|
240 : |
|
|
void Stock::addTags(AgeBandMatrixPtrVector* tagbyagelength, Tags* newtag, double tagloss) {
|
241 : |
|
|
|
242 : |
|
|
if (!istagged)
|
243 : |
|
|
return;
|
244 : |
|
|
|
245 : |
|
|
tagAlkeys.addTag(tagbyagelength, Alkeys, newtag->getName(), tagloss);
|
246 : |
|
|
allTags.resize(newtag);
|
247 : |
|
|
if (doesmature) {
|
248 : |
|
|
maturity->addMaturityTag(newtag->getName());
|
249 : |
|
|
matureTags.resize(newtag);
|
250 : |
|
|
}
|
251 : |
|
|
if (doesmove) {
|
252 : |
|
|
transition->addTransitionTag(newtag->getName());
|
253 : |
|
|
transitionTags.resize(newtag);
|
254 : |
|
|
}
|
255 : |
|
|
if (doesstray) {
|
256 : |
|
|
stray->addStrayTag(newtag->getName());
|
257 : |
|
|
strayTags.resize(newtag);
|
258 : |
|
|
}
|
259 : |
|
|
}
|
260 : |
|
|
|
261 : |
|
|
void Stock::deleteTags(const char* tagname) {
|
262 : |
|
|
|
263 : |
|
|
if (!istagged)
|
264 : |
|
|
return;
|
265 : |
|
|
|
266 : |
|
|
allTags.Delete(tagAlkeys.getTagID(tagname));
|
267 : |
|
|
tagAlkeys.deleteTag(tagname);
|
268 : |
|
|
if (doesmature)
|
269 : |
|
|
maturity->deleteMaturityTag(tagname);
|
270 : |
|
|
if (doesmove)
|
271 : |
|
|
transition->deleteTransitionTag(tagname);
|
272 : |
|
|
if (doesstray)
|
273 : |
|
|
stray->deleteStrayTag(tagname);
|
274 : |
|
|
}
|
275 : |
|
|
|
276 : |
|
|
double Stock::getTotalStockNumber(int area) const {
|
277 : |
|
|
int inarea = this->areaNum(area);
|
278 : |
|
|
if (inarea == -1)
|
279 : |
|
|
return 0.0;
|
280 : |
|
|
|
281 : |
|
|
int age, len;
|
282 : |
|
|
double num = 0.0;
|
283 : |
|
|
for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
|
284 : |
|
|
for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
|
285 : |
|
|
num += (Alkeys[inarea])[age][len].N;
|
286 : |
|
|
|
287 : |
|
|
return num;
|
288 : |
|
|
}
|
289 : |
|
|
|
290 : |
|
|
double Stock::getTotalStockNumberAllAreas() const {
|
291 : |
|
|
int a;
|
292 : |
|
|
double sum = 0.0;
|
293 : |
|
|
for (a = 0; a <= Alkeys.Size(); a++)
|
294 : |
|
|
sum += this->getTotalStockNumber(a);
|
295 : |
|
|
|
296 : |
|
|
return sum;
|
297 : |
|
|
}
|
298 : |
|
|
|
299 : |
|
|
double Stock::getTotalStockBiomass(int area) const {
|
300 : |
|
|
int inarea = this->areaNum(area);
|
301 : |
|
|
if (inarea == -1)
|
302 : |
|
|
return 0.0;
|
303 : |
|
|
|
304 : |
|
|
int age, len;
|
305 : |
|
|
double kilos = 0.0;
|
306 : |
|
|
for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
|
307 : |
|
|
for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
|
308 : |
|
|
kilos += ((Alkeys[inarea])[age][len].N * (Alkeys[inarea])[age][len].W);
|
309 : |
|
|
|
310 : |
|
|
return kilos;
|
311 : |
|
|
}
|
312 : |
|
|
|
313 : |
|
|
double Stock::getTotalStockBiomassAllAreas() const {
|
314 : |
|
|
int a;
|
315 : |
|
|
double sum = 0.0;
|
316 : |
|
|
for (a = 0; a <= Alkeys.Size(); a++)
|
317 : |
|
|
sum += this->getTotalStockBiomass(a);
|
318 : |
|
|
|
319 : |
|
|
return sum;
|
320 : |
|
|
}
|