1 : |
agomez |
1 |
#include "spawner.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "keeper.h" |
4 : |
|
|
#include "areatime.h" |
5 : |
|
|
#include "readfunc.h" |
6 : |
|
|
#include "mathfunc.h" |
7 : |
|
|
#include "readword.h" |
8 : |
|
|
#include "readaggregation.h" |
9 : |
|
|
#include "gadget.h" |
10 : |
|
|
#include "global.h" |
11 : |
|
|
|
12 : |
|
|
SpawnData::SpawnData(CommentStream& infile, int maxage, const LengthGroupDivision* const lgrpdiv,
|
13 : |
|
|
const IntVector& Areas, const AreaClass* const Area, const char* givenname,
|
14 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper) : HasName(givenname), LivesOnAreas(Areas) {
|
15 : |
|
|
|
16 : |
|
|
keeper->addString("spawner");
|
17 : |
|
|
int i, tmpint = 0;
|
18 : |
|
|
ratioscale = 1.0; //JMB used to scale the ratios to ensure that they sum to 1
|
19 : |
|
|
|
20 : |
|
|
char text[MaxStrLength];
|
21 : |
|
|
strncpy(text, "", MaxStrLength);
|
22 : |
|
|
ifstream datafile;
|
23 : |
|
|
CommentStream subdata(datafile);
|
24 : |
|
|
functionname = new char[MaxStrLength];
|
25 : |
|
|
strncpy(functionname, "", MaxStrLength);
|
26 : |
|
|
|
27 : |
|
|
spawnLgrpDiv = 0;
|
28 : |
|
|
LgrpDiv = new LengthGroupDivision(*lgrpdiv);
|
29 : |
|
|
if (LgrpDiv->Error())
|
30 : |
|
|
handle.logMessage(LOGFAIL, "Error in spawner - failed to create length group");
|
31 : |
|
|
int numlength = LgrpDiv->numLengthGroups();
|
32 : |
|
|
spawnFirstYear = TimeInfo->getFirstYear();
|
33 : |
|
|
spawnLastYear = TimeInfo->getLastYear();
|
34 : |
|
|
spawnProportion.resize(numlength, 0.0);
|
35 : |
|
|
spawnMortality.resize(numlength, 0.0);
|
36 : |
|
|
spawnWeightLoss.resize(numlength, 0.0);
|
37 : |
|
|
|
38 : |
|
|
infile >> text >> ws;
|
39 : |
|
|
if ((strcasecmp(text, "spawnstep") != 0) && (strcasecmp(text, "spawnsteps") != 0))
|
40 : |
|
|
handle.logFileUnexpected(LOGFAIL, "spawnsteps", text);
|
41 : |
|
|
|
42 : |
|
|
while (isdigit(infile.peek()) && !infile.eof()) {
|
43 : |
|
|
infile >> tmpint >> ws;
|
44 : |
|
|
spawnStep.resize(1, tmpint);
|
45 : |
|
|
}
|
46 : |
|
|
|
47 : |
|
|
for (i = 0; i < spawnStep.Size(); i++)
|
48 : |
|
|
if (spawnStep[i] < 1 || spawnStep[i] > TimeInfo->numSteps())
|
49 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid spawning step", spawnStep[i]);
|
50 : |
|
|
|
51 : |
|
|
infile >> text >> ws;
|
52 : |
|
|
if ((strcasecmp(text, "spawnarea") != 0) && (strcasecmp(text, "spawnareas") != 0))
|
53 : |
|
|
handle.logFileUnexpected(LOGFAIL, "spawnareas", text);
|
54 : |
|
|
|
55 : |
|
|
while (isdigit(infile.peek()) && !infile.eof()) {
|
56 : |
|
|
infile >> tmpint >> ws;
|
57 : |
|
|
spawnArea.resize(1, tmpint);
|
58 : |
|
|
}
|
59 : |
|
|
|
60 : |
|
|
for (i = 0; i < spawnArea.Size(); i++)
|
61 : |
|
|
spawnArea[i] = Area->getInnerArea(spawnArea[i]);
|
62 : |
|
|
|
63 : |
|
|
infile >> text >> ws;
|
64 : |
|
|
//JMB check for optional firstspwanyear and lastspawnyear values
|
65 : |
|
|
if (strcasecmp(text, "firstspawnyear") == 0) {
|
66 : |
|
|
infile >> spawnFirstYear >> text >> ws;
|
67 : |
|
|
if (spawnFirstYear < TimeInfo->getFirstYear())
|
68 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid first spawning year", spawnFirstYear);
|
69 : |
|
|
}
|
70 : |
|
|
if (strcasecmp(text, "lastspawnyear") == 0) {
|
71 : |
|
|
infile >> spawnLastYear >> text >> ws;
|
72 : |
|
|
if (spawnLastYear > TimeInfo->getLastYear())
|
73 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid last spawning year", spawnLastYear);
|
74 : |
|
|
}
|
75 : |
|
|
|
76 : |
|
|
if (strcasecmp(text, "spawnstocksandratios") == 0) {
|
77 : |
|
|
onlyParent = 0;
|
78 : |
|
|
i = 0;
|
79 : |
|
|
infile >> text >> ws;
|
80 : |
|
|
while (strcasecmp(text, "proportionfunction") != 0 && !infile.eof()) {
|
81 : |
|
|
spawnStockNames.resize(new char[strlen(text) + 1]);
|
82 : |
|
|
strcpy(spawnStockNames[i], text);
|
83 : |
|
|
spawnRatio.resize(1, keeper);
|
84 : |
|
|
if (!(infile >> spawnRatio[i]))
|
85 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format for spawn ratio");
|
86 : |
|
|
spawnRatio[i].Inform(keeper);
|
87 : |
|
|
|
88 : |
|
|
infile >> text >> ws;
|
89 : |
|
|
i++;
|
90 : |
|
|
}
|
91 : |
|
|
} else if (strcasecmp(text, "onlyparent") == 0) {
|
92 : |
|
|
onlyParent = 1;
|
93 : |
|
|
infile >> text >> ws;
|
94 : |
|
|
} else
|
95 : |
|
|
handle.logFileUnexpected(LOGFAIL, "spawnstocksandratios or onlyparent", text);
|
96 : |
|
|
|
97 : |
|
|
if (infile.eof())
|
98 : |
|
|
handle.logFileEOFMessage(LOGFAIL);
|
99 : |
|
|
|
100 : |
|
|
if (strcasecmp(text, "proportionfunction") != 0)
|
101 : |
|
|
handle.logFileUnexpected(LOGFAIL, "proportionfunction", text);
|
102 : |
|
|
|
103 : |
|
|
infile >> text >> ws;
|
104 : |
|
|
if (strcasecmp(text, "constant") == 0)
|
105 : |
|
|
fnProportion = new ConstSelectFunc();
|
106 : |
|
|
else if (strcasecmp(text, "straightline") == 0)
|
107 : |
|
|
fnProportion = new StraightSelectFunc();
|
108 : |
|
|
else if (strcasecmp(text, "exponential") == 0)
|
109 : |
|
|
fnProportion = new ExpSelectFunc();
|
110 : |
|
|
else
|
111 : |
|
|
handle.logFileMessage(LOGFAIL, "unrecognised proportion function", text);
|
112 : |
|
|
fnProportion->readConstants(infile, TimeInfo, keeper);
|
113 : |
|
|
|
114 : |
|
|
readWordAndValue(infile, "mortalityfunction", text);
|
115 : |
|
|
if (strcasecmp(text, "constant") == 0)
|
116 : |
|
|
fnMortality = new ConstSelectFunc();
|
117 : |
|
|
else if (strcasecmp(text, "straightline") == 0)
|
118 : |
|
|
fnMortality = new StraightSelectFunc();
|
119 : |
|
|
else if (strcasecmp(text, "exponential") == 0)
|
120 : |
|
|
fnMortality = new ExpSelectFunc();
|
121 : |
|
|
else
|
122 : |
|
|
handle.logFileMessage(LOGFAIL, "unrecognised mortality function", text);
|
123 : |
|
|
fnMortality->readConstants(infile, TimeInfo, keeper);
|
124 : |
|
|
|
125 : |
|
|
readWordAndValue(infile, "weightlossfunction", text);
|
126 : |
|
|
if (strcasecmp(text, "constant") == 0)
|
127 : |
|
|
fnWeightLoss = new ConstSelectFunc();
|
128 : |
|
|
else if (strcasecmp(text, "straightline") == 0)
|
129 : |
|
|
fnWeightLoss = new StraightSelectFunc();
|
130 : |
|
|
else if (strcasecmp(text, "exponential") == 0)
|
131 : |
|
|
fnWeightLoss = new ExpSelectFunc();
|
132 : |
|
|
else
|
133 : |
|
|
handle.logFileMessage(LOGFAIL, "unrecognised weight loss function", text);
|
134 : |
|
|
fnWeightLoss->readConstants(infile, TimeInfo, keeper);
|
135 : |
|
|
|
136 : |
|
|
if (!onlyParent) {
|
137 : |
|
|
infile >> text >> ws;
|
138 : |
|
|
if (strcasecmp(text, "recruitment") != 0)
|
139 : |
|
|
handle.logFileUnexpected(LOGFAIL, "recruitment", text);
|
140 : |
|
|
|
141 : |
|
|
//read in the recruitment function details
|
142 : |
|
|
functionnumber = 0;
|
143 : |
|
|
infile >> functionname >> ws;
|
144 : |
|
|
if (strcasecmp(functionname, "simplessb") == 0) {
|
145 : |
|
|
functionnumber = 1;
|
146 : |
|
|
spawnParameters.resize(1, keeper);
|
147 : |
|
|
} else if (strcasecmp(functionname, "ricker") == 0) {
|
148 : |
|
|
functionnumber = 2;
|
149 : |
|
|
spawnParameters.resize(2, keeper);
|
150 : |
|
|
} else if (strcasecmp(functionname, "bevertonholt") == 0) {
|
151 : |
|
|
functionnumber = 3;
|
152 : |
|
|
spawnParameters.resize(2, keeper);
|
153 : |
|
|
} else if (strcasecmp(functionname, "fecundity") == 0) {
|
154 : |
|
|
functionnumber = 4;
|
155 : |
|
|
spawnParameters.resize(5, keeper);
|
156 : |
|
|
} else if (strcasecmp(functionname, "baleen") == 0) {
|
157 : |
|
|
functionnumber = 5;
|
158 : |
|
|
spawnParameters.resize(4, keeper);
|
159 : |
|
|
} else if (strcasecmp(functionname, "hockeystick") == 0) {
|
160 : |
|
|
functionnumber = 6;
|
161 : |
|
|
spawnParameters.resize(2, keeper);
|
162 : |
|
|
} else
|
163 : |
|
|
handle.logFileMessage(LOGFAIL, "unrecognised recruitment function", functionname);
|
164 : |
|
|
|
165 : |
|
|
spawnParameters.read(infile, TimeInfo, keeper);
|
166 : |
|
|
|
167 : |
|
|
//read in the details about the new stock
|
168 : |
|
|
stockParameters.resize(4, keeper);
|
169 : |
|
|
infile >> text >> ws;
|
170 : |
|
|
if (strcasecmp(text, "stockparameters") != 0)
|
171 : |
|
|
handle.logFileUnexpected(LOGFAIL, "stockparameters", text);
|
172 : |
|
|
stockParameters.read(infile, TimeInfo, keeper);
|
173 : |
|
|
|
174 : |
|
|
//resize spawnNumbers to store details of the spawning stock biomass
|
175 : |
|
|
for (i = 0; i < areas.Size(); i++)
|
176 : |
|
|
spawnNumbers.resize(new DoubleMatrix(maxage + 1, numlength, 0.0));
|
177 : |
|
|
}
|
178 : |
|
|
|
179 : |
|
|
infile >> ws;
|
180 : |
|
|
if (!infile.eof()) {
|
181 : |
|
|
infile >> text >> ws;
|
182 : |
|
|
handle.logFileUnexpected(LOGFAIL, "<end of file>", text);
|
183 : |
|
|
}
|
184 : |
|
|
handle.logMessage(LOGMESSAGE, "Read spawning data file");
|
185 : |
|
|
keeper->clearLast();
|
186 : |
|
|
}
|
187 : |
|
|
|
188 : |
|
|
SpawnData::~SpawnData() {
|
189 : |
|
|
int i;
|
190 : |
|
|
for (i = 0; i < spawnStockNames.Size(); i++)
|
191 : |
|
|
delete[] spawnStockNames[i];
|
192 : |
|
|
for (i = 0; i < spawnNumbers.Size(); i++)
|
193 : |
|
|
delete spawnNumbers[i];
|
194 : |
|
|
for (i = 0; i < CI.Size(); i++)
|
195 : |
|
|
delete CI[i];
|
196 : |
|
|
delete LgrpDiv;
|
197 : |
|
|
delete spawnLgrpDiv;
|
198 : |
|
|
delete fnProportion;
|
199 : |
|
|
delete fnMortality;
|
200 : |
|
|
delete fnWeightLoss;
|
201 : |
|
|
delete[] functionname;
|
202 : |
|
|
}
|
203 : |
|
|
|
204 : |
|
|
void SpawnData::setStock(StockPtrVector& stockvec) {
|
205 : |
|
|
int i, j, index;
|
206 : |
|
|
|
207 : |
|
|
if (onlyParent)
|
208 : |
|
|
return;
|
209 : |
|
|
|
210 : |
|
|
for (i = 0; i < stockvec.Size(); i++)
|
211 : |
|
|
for (j = 0; j < spawnStockNames.Size(); j++)
|
212 : |
|
|
if (strcasecmp(stockvec[i]->getName(), spawnStockNames[j]) == 0)
|
213 : |
|
|
spawnStocks.resize(stockvec[i]);
|
214 : |
|
|
|
215 : |
|
|
if (spawnStocks.Size() != spawnStockNames.Size()) {
|
216 : |
|
|
handle.logMessage(LOGWARN, "Error in spawner - failed to match spawning stocks");
|
217 : |
|
|
for (i = 0; i < stockvec.Size(); i++)
|
218 : |
|
|
handle.logMessage(LOGWARN, "Error in spawner - found stock", stockvec[i]->getName());
|
219 : |
|
|
for (i = 0; i < spawnStockNames.Size(); i++)
|
220 : |
|
|
handle.logMessage(LOGWARN, "Error in spawner - looking for stock", spawnStockNames[i]);
|
221 : |
|
|
handle.logMessage(LOGFAIL, ""); //JMB this will exit gadget
|
222 : |
|
|
}
|
223 : |
|
|
|
224 : |
|
|
//JMB ensure that the ratio vector is indexed in the right order
|
225 : |
|
|
ratioindex.resize(spawnStocks.Size(), 0);
|
226 : |
|
|
for (i = 0; i < spawnStocks.Size(); i++)
|
227 : |
|
|
for (j = 0; j < spawnStockNames.Size(); j++)
|
228 : |
|
|
if (strcasecmp(spawnStocks[i]->getName(), spawnStockNames[j]) == 0)
|
229 : |
|
|
ratioindex[i] = j;
|
230 : |
|
|
|
231 : |
|
|
//JMB check that the spawned stocks are defined on all the areas
|
232 : |
|
|
spawnAge = 9999;
|
233 : |
|
|
double minlength = 9999.0;
|
234 : |
|
|
double maxlength = 0.0;
|
235 : |
|
|
double dl = 9999.0;
|
236 : |
|
|
for (i = 0; i < spawnStocks.Size(); i++) {
|
237 : |
|
|
index = 0;
|
238 : |
|
|
for (j = 0; j < spawnArea.Size(); j++)
|
239 : |
|
|
if (!spawnStocks[i]->isInArea(spawnArea[j]))
|
240 : |
|
|
index++;
|
241 : |
|
|
|
242 : |
|
|
if (index != 0)
|
243 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - spawned stock isnt defined on all areas");
|
244 : |
|
|
|
245 : |
|
|
spawnAge = min(spawnStocks[i]->minAge(), spawnAge);
|
246 : |
|
|
minlength = min(spawnStocks[i]->getLengthGroupDiv()->minLength(), minlength);
|
247 : |
|
|
maxlength = max(spawnStocks[i]->getLengthGroupDiv()->maxLength(), maxlength);
|
248 : |
|
|
dl = min(spawnStocks[i]->getLengthGroupDiv()->dl(), dl);
|
249 : |
|
|
}
|
250 : |
|
|
|
251 : |
|
|
spawnLgrpDiv = new LengthGroupDivision(minlength, maxlength, dl);
|
252 : |
|
|
if (spawnLgrpDiv->Error())
|
253 : |
|
|
handle.logMessage(LOGFAIL, "Error in spawner - failed to create length group");
|
254 : |
|
|
for (i = 0; i < spawnStocks.Size(); i++) {
|
255 : |
|
|
CI.resize(new ConversionIndex(spawnLgrpDiv, spawnStocks[i]->getLengthGroupDiv()));
|
256 : |
|
|
if (CI[i]->Error())
|
257 : |
|
|
handle.logMessage(LOGFAIL, "Error in spawner - error when checking length structure");
|
258 : |
|
|
}
|
259 : |
|
|
|
260 : |
|
|
IntVector minlv(1, 0);
|
261 : |
|
|
IntVector sizev(1, spawnLgrpDiv->numLengthGroups());
|
262 : |
|
|
Storage.resize(areas.Size(), spawnAge, minlv, sizev);
|
263 : |
|
|
for (i = 0; i < Storage.Size(); i++)
|
264 : |
|
|
Storage[i].setToZero();
|
265 : |
|
|
}
|
266 : |
|
|
|
267 : |
|
|
void SpawnData::Spawn(AgeBandMatrix& Alkeys, int area, const TimeClass* const TimeInfo) {
|
268 : |
|
|
|
269 : |
|
|
if (!onlyParent)
|
270 : |
|
|
spawnParameters.Update(TimeInfo);
|
271 : |
|
|
|
272 : |
|
|
int age, len;
|
273 : |
|
|
int inarea = this->areaNum(area);
|
274 : |
|
|
PopInfo pop;
|
275 : |
|
|
for (age = Alkeys.minAge(); age <= Alkeys.maxAge(); age++) {
|
276 : |
|
|
//subtract mortality and reduce the weight of the living ones.
|
277 : |
|
|
for (len = Alkeys.minLength(age); len < Alkeys.maxLength(age); len++) {
|
278 : |
|
|
if (!isZero(spawnProportion[len])) {
|
279 : |
|
|
pop = Alkeys[age][len] * spawnProportion[len];
|
280 : |
|
|
|
281 : |
|
|
//calculate the spawning stock biomass if needed
|
282 : |
|
|
if (!onlyParent)
|
283 : |
|
|
(*spawnNumbers[inarea])[age][len] = calcSpawnNumber(age, len, pop.N, pop.W);
|
284 : |
|
|
|
285 : |
|
|
pop *= exp(-spawnMortality[len]);
|
286 : |
|
|
pop.W -= (spawnWeightLoss[len] * pop.W);
|
287 : |
|
|
Alkeys[age][len] *= (1.0 - spawnProportion[len]);
|
288 : |
|
|
Alkeys[age][len] += pop;
|
289 : |
|
|
}
|
290 : |
|
|
}
|
291 : |
|
|
}
|
292 : |
|
|
}
|
293 : |
|
|
|
294 : |
|
|
void SpawnData::addSpawnStock(int area, const TimeClass* const TimeInfo) {
|
295 : |
|
|
|
296 : |
|
|
if (onlyParent)
|
297 : |
|
|
return;
|
298 : |
|
|
|
299 : |
|
|
int s, age, len;
|
300 : |
|
|
int inarea = this->areaNum(area);
|
301 : |
|
|
double tmp, length, N, total, sum;
|
302 : |
|
|
|
303 : |
|
|
//create a length distribution and mean weight for the new stock
|
304 : |
|
|
stockParameters.Update(TimeInfo);
|
305 : |
|
|
if (handle.getLogLevel() >= LOGWARN) {
|
306 : |
|
|
if (isZero(stockParameters[1]))
|
307 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - invalid standard deviation for spawned stock", this->getName());
|
308 : |
|
|
if (stockParameters[0] < spawnLgrpDiv->minLength())
|
309 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - mean length is less than minimum length for stock", this->getName());
|
310 : |
|
|
if (stockParameters[0] > spawnLgrpDiv->maxLength())
|
311 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - mean length is greater than maximum length for stock", this->getName());
|
312 : |
|
|
}
|
313 : |
|
|
|
314 : |
|
|
sum = 0.0;
|
315 : |
|
|
Storage[inarea].setToZero();
|
316 : |
|
|
if (stockParameters[1] > verysmall) {
|
317 : |
|
|
tmp = 1.0 / (2 * stockParameters[1] * stockParameters[1]);
|
318 : |
|
|
for (len = 0; len < spawnLgrpDiv->numLengthGroups(); len++) {
|
319 : |
|
|
length = spawnLgrpDiv->meanLength(len) - stockParameters[0];
|
320 : |
|
|
N = exp(-(length * length * tmp));
|
321 : |
|
|
Storage[inarea][spawnAge][len].N = N;
|
322 : |
|
|
sum += N;
|
323 : |
|
|
}
|
324 : |
|
|
}
|
325 : |
|
|
|
326 : |
|
|
//calculate the total number of recruits and distribute this through the length groups
|
327 : |
|
|
if (!isZero(sum)) {
|
328 : |
|
|
tmp = 0.0; //JMB dummy temperature of zero
|
329 : |
|
|
total = calcRecruitNumber(tmp, inarea) / sum;
|
330 : |
|
|
for (len = 0; len < spawnLgrpDiv->numLengthGroups(); len++) {
|
331 : |
|
|
length = spawnLgrpDiv->meanLength(len);
|
332 : |
|
|
Storage[inarea][spawnAge][len].N *= total;
|
333 : |
|
|
Storage[inarea][spawnAge][len].W = stockParameters[2] * pow(length, stockParameters[3]);
|
334 : |
|
|
}
|
335 : |
|
|
|
336 : |
|
|
//add this to the spawned stocks
|
337 : |
|
|
for (s = 0; s < spawnStocks.Size(); s++) {
|
338 : |
|
|
if (!spawnStocks[s]->isInArea(area))
|
339 : |
|
|
handle.logMessage(LOGFAIL, "Error in spawner - spawned stock doesnt live on area", area);
|
340 : |
|
|
|
341 : |
|
|
tmp = spawnRatio[ratioindex[s]] * ratioscale;
|
342 : |
|
|
spawnStocks[s]->Add(Storage[inarea], CI[s], area, tmp);
|
343 : |
|
|
}
|
344 : |
|
|
}
|
345 : |
|
|
}
|
346 : |
|
|
|
347 : |
|
|
int SpawnData::isSpawnStepArea(int area, const TimeClass* const TimeInfo) {
|
348 : |
|
|
int i, j;
|
349 : |
|
|
|
350 : |
|
|
if ((TimeInfo->getYear() < spawnFirstYear) || (TimeInfo->getYear() > spawnLastYear))
|
351 : |
|
|
return 0;
|
352 : |
|
|
|
353 : |
|
|
for (i = 0; i < spawnStep.Size(); i++)
|
354 : |
|
|
for (j = 0; j < spawnArea.Size(); j++)
|
355 : |
|
|
if ((spawnStep[i] == TimeInfo->getStep()) && (spawnArea[j] == area))
|
356 : |
|
|
return 1;
|
357 : |
|
|
return 0;
|
358 : |
|
|
}
|
359 : |
|
|
|
360 : |
|
|
void SpawnData::Reset(const TimeClass* const TimeInfo) {
|
361 : |
|
|
int i;
|
362 : |
|
|
|
363 : |
|
|
fnProportion->updateConstants(TimeInfo);
|
364 : |
|
|
if (fnProportion->didChange(TimeInfo)) {
|
365 : |
|
|
for (i = 0; i < LgrpDiv->numLengthGroups(); i++) {
|
366 : |
|
|
spawnProportion[i] = fnProportion->calculate(LgrpDiv->meanLength(i));
|
367 : |
|
|
if (spawnProportion[i] < 0.0) {
|
368 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - function outside bounds", spawnProportion[i]);
|
369 : |
|
|
spawnProportion[i] = 0.0;
|
370 : |
|
|
}
|
371 : |
|
|
if (spawnProportion[i] > 1.0) {
|
372 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - function outside bounds", spawnProportion[i]);
|
373 : |
|
|
spawnProportion[i] = 1.0;
|
374 : |
|
|
}
|
375 : |
|
|
}
|
376 : |
|
|
}
|
377 : |
|
|
|
378 : |
|
|
fnWeightLoss->updateConstants(TimeInfo);
|
379 : |
|
|
if (fnWeightLoss->didChange(TimeInfo)) {
|
380 : |
|
|
for (i = 0; i < LgrpDiv->numLengthGroups(); i++) {
|
381 : |
|
|
spawnWeightLoss[i] = fnWeightLoss->calculate(LgrpDiv->meanLength(i));
|
382 : |
|
|
if (spawnWeightLoss[i] < 0.0) {
|
383 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - function outside bounds", spawnWeightLoss[i]);
|
384 : |
|
|
spawnWeightLoss[i] = 0.0;
|
385 : |
|
|
}
|
386 : |
|
|
if (spawnWeightLoss[i] > 1.0) {
|
387 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - function outside bounds", spawnWeightLoss[i]);
|
388 : |
|
|
spawnWeightLoss[i] = 1.0;
|
389 : |
|
|
}
|
390 : |
|
|
}
|
391 : |
|
|
}
|
392 : |
|
|
|
393 : |
|
|
fnMortality->updateConstants(TimeInfo);
|
394 : |
|
|
if (fnMortality->didChange(TimeInfo)) {
|
395 : |
|
|
for (i = 0; i < LgrpDiv->numLengthGroups(); i++) {
|
396 : |
|
|
spawnMortality[i] = fnMortality->calculate(LgrpDiv->meanLength(i));
|
397 : |
|
|
}
|
398 : |
|
|
}
|
399 : |
|
|
|
400 : |
|
|
//JMB check that the sum of the ratios is 1
|
401 : |
|
|
if ((!onlyParent) && (TimeInfo->getTime() == 1)) {
|
402 : |
|
|
ratioscale = 0.0;
|
403 : |
|
|
for (i = 0; i < spawnRatio.Size(); i++ )
|
404 : |
|
|
ratioscale += spawnRatio[i];
|
405 : |
|
|
|
406 : |
|
|
if (isZero(ratioscale)) {
|
407 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - specified ratios are zero");
|
408 : |
|
|
ratioscale = 1.0;
|
409 : |
|
|
} else if (isEqual(ratioscale, 1.0)) {
|
410 : |
|
|
// do nothing
|
411 : |
|
|
} else {
|
412 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - scaling ratios using", ratioscale);
|
413 : |
|
|
ratioscale = 1.0 / ratioscale;
|
414 : |
|
|
}
|
415 : |
|
|
}
|
416 : |
|
|
|
417 : |
|
|
if (handle.getLogLevel() >= LOGMESSAGE)
|
418 : |
|
|
handle.logMessage(LOGMESSAGE, "Reset spawning data for stock", this->getName());
|
419 : |
|
|
}
|
420 : |
|
|
|
421 : |
|
|
double SpawnData::calcSpawnNumber(int age, int len, double number, double weight) {
|
422 : |
|
|
double temp = 0.0;
|
423 : |
|
|
|
424 : |
|
|
switch (functionnumber) {
|
425 : |
ulcessvp |
2 |
case 1:
|
426 : |
|
|
case 2:
|
427 : |
|
|
case 3:
|
428 : |
|
|
temp = number * weight;
|
429 : |
|
|
break;
|
430 : |
agomez |
1 |
case 4:
|
431 : |
|
|
temp = pow(LgrpDiv->meanLength(len), spawnParameters[1]) * pow(age, spawnParameters[2])
|
432 : |
|
|
* pow(number, spawnParameters[3]) * pow(weight, spawnParameters[4]);
|
433 : |
|
|
break;
|
434 : |
|
|
case 5:
|
435 : |
|
|
temp = number;
|
436 : |
|
|
break;
|
437 : |
|
|
default:
|
438 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - unrecognised recruitment function", functionname);
|
439 : |
|
|
break;
|
440 : |
|
|
}
|
441 : |
|
|
|
442 : |
|
|
return temp;
|
443 : |
|
|
}
|
444 : |
|
|
|
445 : |
|
|
double SpawnData::calcRecruitNumber(double temp, int inarea) {
|
446 : |
|
|
int age, len;
|
447 : |
|
|
double total = 0.0, ssb = 0.0;
|
448 : |
|
|
|
449 : |
|
|
for (age = 0; age < (*spawnNumbers[inarea]).Nrow(); age++)
|
450 : |
|
|
for (len = 0; len < (*spawnNumbers[inarea]).Ncol(age); len++)
|
451 : |
|
|
ssb += (*spawnNumbers[inarea])[age][len];
|
452 : |
|
|
|
453 : |
|
|
switch (functionnumber) {
|
454 : |
|
|
case 1:
|
455 : |
|
|
case 4:
|
456 : |
|
|
total = ssb * spawnParameters[0];
|
457 : |
|
|
break;
|
458 : |
|
|
case 2:
|
459 : |
|
|
total = ssb * spawnParameters[0] * exp(-spawnParameters[1] * ssb);
|
460 : |
|
|
break;
|
461 : |
|
|
case 3:
|
462 : |
|
|
total = ssb * spawnParameters[0] / (spawnParameters[1] + ssb);
|
463 : |
|
|
break;
|
464 : |
|
|
case 5:
|
465 : |
|
|
total = ssb * spawnParameters[0] *
|
466 : |
|
|
max(1 + spawnParameters[1] * (1- pow(ssb / spawnParameters[2],double(spawnParameters[3]))),0.0);
|
467 : |
|
|
break;
|
468 : |
|
|
default:
|
469 : |
|
|
handle.logMessage(LOGWARN, "Warning in spawner - unrecognised recruitment function", functionname);
|
470 : |
|
|
break;
|
471 : |
|
|
}
|
472 : |
|
|
|
473 : |
|
|
return total;
|
474 : |
|
|
}
|
475 : |
|
|
|
476 : |
|
|
void SpawnData::Print(ofstream& outfile) const {
|
477 : |
|
|
|
478 : |
|
|
if (onlyParent) {
|
479 : |
|
|
outfile << "\nSpawning data\n\t** Only modelling the affect on the parent stock **"
|
480 : |
|
|
<< "\n\t** No recruits are created during the spawning process **\n";
|
481 : |
|
|
return;
|
482 : |
|
|
}
|
483 : |
|
|
|
484 : |
|
|
int i;
|
485 : |
|
|
outfile << "\nSpawning data\n\tNames of spawned stocks:";
|
486 : |
|
|
for (i = 0; i < spawnStockNames.Size(); i++)
|
487 : |
|
|
outfile << sep << spawnStockNames[i];
|
488 : |
|
|
outfile << "\n\tRatio spawning into each stock:";
|
489 : |
|
|
for (i = 0; i < spawnRatio.Size(); i++)
|
490 : |
|
|
outfile << sep << (spawnRatio[ratioindex[i]] * ratioscale);
|
491 : |
|
|
outfile << "\n\t";
|
492 : |
|
|
spawnLgrpDiv->Print(outfile);
|
493 : |
|
|
outfile << "\tStored numbers:\n";
|
494 : |
|
|
for (i = 0; i < areas.Size(); i++) {
|
495 : |
|
|
outfile << "\tInternal area " << areas[i] << "\n\tNumbers\n";
|
496 : |
|
|
Storage[i].printNumbers(outfile);
|
497 : |
|
|
outfile << "\tMean weights\n";
|
498 : |
|
|
Storage[i].printWeights(outfile);
|
499 : |
|
|
}
|
500 : |
|
|
}
|