1 : |
agomez |
1 |
#include "growthcalc.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "areatime.h" |
4 : |
|
|
#include "keeper.h" |
5 : |
|
|
#include "readfunc.h" |
6 : |
|
|
#include "readword.h" |
7 : |
|
|
#include "gadget.h" |
8 : |
|
|
#include "global.h" |
9 : |
|
|
|
10 : |
|
|
// ********************************************************
|
11 : |
|
|
// Functions for GrowthCalcBase
|
12 : |
|
|
// ********************************************************
|
13 : |
|
|
GrowthCalcBase::GrowthCalcBase(const IntVector& Areas) : LivesOnAreas(Areas) {
|
14 : |
|
|
}
|
15 : |
|
|
|
16 : |
|
|
// ********************************************************
|
17 : |
|
|
// Functions for GrowthCalcA
|
18 : |
|
|
// ********************************************************
|
19 : |
|
|
GrowthCalcA::GrowthCalcA(CommentStream& infile, const IntVector& Areas,
|
20 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper)
|
21 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(9) {
|
22 : |
|
|
|
23 : |
|
|
keeper->addString("growthcalcA");
|
24 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
25 : |
|
|
|
26 : |
|
|
char text[MaxStrLength];
|
27 : |
|
|
strncpy(text, "", MaxStrLength);
|
28 : |
|
|
infile >> text >> ws;
|
29 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
30 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
31 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
32 : |
|
|
keeper->clearLast();
|
33 : |
|
|
}
|
34 : |
|
|
|
35 : |
|
|
void GrowthCalcA::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
36 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
37 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
38 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
39 : |
|
|
|
40 : |
|
|
growthPar.Update(TimeInfo);
|
41 : |
|
|
double tempL = TimeInfo->getTimeStepSize() * growthPar[0] *
|
42 : |
|
|
(growthPar[2] * Area->getTemperature(area, TimeInfo->getTime()) + growthPar[3]);
|
43 : |
|
|
double tempW = TimeInfo->getTimeStepSize() * growthPar[4] *
|
44 : |
|
|
(growthPar[7] * Area->getTemperature(area, TimeInfo->getTime()) + growthPar[8]);
|
45 : |
|
|
|
46 : |
|
|
int i;
|
47 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
48 : |
|
|
Lgrowth[i] = tempL * pow(LgrpDiv->meanLength(i), growthPar[1]) * Fphi[i];
|
49 : |
|
|
if (Lgrowth[i] < 0.0)
|
50 : |
|
|
Lgrowth[i] = 0.0;
|
51 : |
|
|
|
52 : |
|
|
if (numGrow[i].W < verysmall || isZero(tempW))
|
53 : |
|
|
Wgrowth[i] = 0.0;
|
54 : |
|
|
else
|
55 : |
|
|
Wgrowth[i] = tempW * pow(numGrow[i].W, growthPar[5]) * (Fphi[i] - growthPar[6]);
|
56 : |
|
|
}
|
57 : |
|
|
}
|
58 : |
|
|
|
59 : |
|
|
// ********************************************************
|
60 : |
|
|
// Functions for GrowthCalcB
|
61 : |
|
|
// ********************************************************
|
62 : |
|
|
GrowthCalcB::GrowthCalcB(CommentStream& infile, const IntVector& Areas,
|
63 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper,
|
64 : |
|
|
const AreaClass* const Area, const CharPtrVector& lenindex)
|
65 : |
|
|
: GrowthCalcBase(Areas) {
|
66 : |
|
|
|
67 : |
|
|
char datafilename[MaxStrLength];
|
68 : |
|
|
strncpy(datafilename, "", MaxStrLength);
|
69 : |
|
|
ifstream datafile;
|
70 : |
|
|
CommentStream subdata(datafile);
|
71 : |
|
|
|
72 : |
|
|
int i;
|
73 : |
|
|
for (i = 0; i < Areas.Size(); i++) {
|
74 : |
|
|
lgrowth.resize(new FormulaMatrix(TimeInfo->numTotalSteps() + 1, lenindex.Size(), 0.0));
|
75 : |
|
|
wgrowth.resize(new FormulaMatrix(TimeInfo->numTotalSteps() + 1, lenindex.Size(), 0.0));
|
76 : |
|
|
}
|
77 : |
|
|
|
78 : |
|
|
keeper->addString("growthcalcB");
|
79 : |
|
|
|
80 : |
|
|
readWordAndValue(infile, "lengthgrowthfile", datafilename);
|
81 : |
|
|
datafile.open(datafilename, ios::in);
|
82 : |
|
|
handle.checkIfFailure(datafile, datafilename);
|
83 : |
|
|
handle.Open(datafilename);
|
84 : |
|
|
readGrowthAmounts(subdata, TimeInfo, Area, lgrowth, lenindex, Areas);
|
85 : |
|
|
handle.Close();
|
86 : |
|
|
datafile.close();
|
87 : |
|
|
datafile.clear();
|
88 : |
|
|
|
89 : |
|
|
readWordAndValue(infile, "weightgrowthfile", datafilename);
|
90 : |
|
|
datafile.open(datafilename, ios::in);
|
91 : |
|
|
handle.checkIfFailure(datafile, datafilename);
|
92 : |
|
|
handle.Open(datafilename);
|
93 : |
|
|
readGrowthAmounts(subdata, TimeInfo, Area, wgrowth, lenindex, Areas);
|
94 : |
|
|
handle.Close();
|
95 : |
|
|
datafile.close();
|
96 : |
|
|
datafile.clear();
|
97 : |
|
|
|
98 : |
|
|
for (i = 0; i < Areas.Size(); i++) {
|
99 : |
|
|
(*lgrowth[i]).Inform(keeper);
|
100 : |
|
|
(*wgrowth[i]).Inform(keeper);
|
101 : |
|
|
}
|
102 : |
|
|
|
103 : |
|
|
keeper->clearLast();
|
104 : |
|
|
}
|
105 : |
|
|
|
106 : |
|
|
GrowthCalcB::~GrowthCalcB() {
|
107 : |
|
|
int a;
|
108 : |
|
|
for (a = 0; a < lgrowth.Size(); a++) {
|
109 : |
|
|
delete lgrowth[a];
|
110 : |
|
|
delete wgrowth[a];
|
111 : |
|
|
}
|
112 : |
|
|
}
|
113 : |
|
|
|
114 : |
|
|
void GrowthCalcB::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
115 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
116 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
117 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
118 : |
|
|
|
119 : |
|
|
int i, inarea = this->areaNum(area);
|
120 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
121 : |
|
|
Lgrowth[i] = (*lgrowth[inarea])[TimeInfo->getTime()][i];
|
122 : |
|
|
Wgrowth[i] = (*wgrowth[inarea])[TimeInfo->getTime()][i];
|
123 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && ((Lgrowth[i] < 0.0) || (Wgrowth[i] < 0.0)))
|
124 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - negative growth parameter");
|
125 : |
|
|
}
|
126 : |
|
|
}
|
127 : |
|
|
|
128 : |
|
|
// ********************************************************
|
129 : |
|
|
// Functions for GrowthCalcC
|
130 : |
|
|
// ********************************************************
|
131 : |
|
|
GrowthCalcC::GrowthCalcC(CommentStream& infile, const IntVector& Areas,
|
132 : |
|
|
const TimeClass* const TimeInfo, const LengthGroupDivision* const LgrpDiv,
|
133 : |
|
|
Keeper* const keeper, const char* refWeightFile)
|
134 : |
|
|
: GrowthCalcBase(Areas), numWeightGrowthConstants(6), numLengthGrowthConstants(9) {
|
135 : |
|
|
|
136 : |
|
|
keeper->addString("growthcalcC");
|
137 : |
|
|
wgrowthPar.resize(numWeightGrowthConstants, keeper);
|
138 : |
|
|
lgrowthPar.resize(numLengthGrowthConstants, keeper);
|
139 : |
|
|
refWeight.resize(LgrpDiv->numLengthGroups(), 0.0);
|
140 : |
|
|
|
141 : |
|
|
int i, j;
|
142 : |
|
|
char text[MaxStrLength];
|
143 : |
|
|
strncpy(text, "", MaxStrLength);
|
144 : |
|
|
infile >> text >> ws;
|
145 : |
|
|
if (strcasecmp(text, "wgrowthparameters") != 0)
|
146 : |
|
|
handle.logFileUnexpected(LOGFAIL, "wgrowthparameters", text);
|
147 : |
|
|
wgrowthPar.read(infile, TimeInfo, keeper);
|
148 : |
|
|
|
149 : |
|
|
infile >> text >> ws;
|
150 : |
|
|
if (strcasecmp(text, "lgrowthparameters") != 0)
|
151 : |
|
|
handle.logFileUnexpected(LOGFAIL, "lgrowthparameters", text);
|
152 : |
|
|
lgrowthPar.read(infile, TimeInfo, keeper);
|
153 : |
|
|
|
154 : |
|
|
//read information on reference weights.
|
155 : |
|
|
keeper->addString("referenceweights");
|
156 : |
|
|
ifstream subfile;
|
157 : |
|
|
subfile.open(refWeightFile, ios::in);
|
158 : |
|
|
handle.checkIfFailure(subfile, refWeightFile);
|
159 : |
|
|
handle.Open(refWeightFile);
|
160 : |
|
|
CommentStream subcomment(subfile);
|
161 : |
|
|
DoubleMatrix tmpRefW;
|
162 : |
|
|
readRefWeights(subcomment, tmpRefW);
|
163 : |
|
|
handle.Close();
|
164 : |
|
|
subfile.close();
|
165 : |
|
|
subfile.clear();
|
166 : |
|
|
|
167 : |
|
|
//Interpolate the reference weights. First there are some error checks.
|
168 : |
|
|
if (LgrpDiv->meanLength(0) < tmpRefW[0][0] ||
|
169 : |
|
|
LgrpDiv->meanLength(LgrpDiv->numLengthGroups() - 1) > tmpRefW[tmpRefW.Nrow() - 1][0])
|
170 : |
|
|
handle.logFileMessage(LOGFAIL, "lengths for reference weights must span the range of growth lengths");
|
171 : |
|
|
|
172 : |
|
|
double ratio, tmplen;
|
173 : |
|
|
int pos = 0;
|
174 : |
|
|
for (j = 0; j < LgrpDiv->numLengthGroups(); j++) {
|
175 : |
|
|
tmplen = LgrpDiv->meanLength(j);
|
176 : |
|
|
for (i = pos; i < tmpRefW.Nrow() - 1; i++) {
|
177 : |
|
|
if (((tmplen > tmpRefW[i][0]) || (isEqual(tmplen, tmpRefW[i][0]))) &&
|
178 : |
|
|
((tmplen < tmpRefW[i + 1][0]) || (isEqual(tmplen, tmpRefW[i + 1][0])))) {
|
179 : |
|
|
|
180 : |
|
|
ratio = (tmplen - tmpRefW[i][0]) / (tmpRefW[i + 1][0] - tmpRefW[i][0]);
|
181 : |
|
|
refWeight[j] = tmpRefW[i][1] + ratio * (tmpRefW[i + 1][1] - tmpRefW[i][1]);
|
182 : |
|
|
pos = i;
|
183 : |
|
|
}
|
184 : |
|
|
}
|
185 : |
|
|
}
|
186 : |
|
|
keeper->clearLast();
|
187 : |
|
|
keeper->clearLast();
|
188 : |
|
|
}
|
189 : |
|
|
|
190 : |
|
|
/* Von Bertalanffy growth function. dw/dt = a*w^n - b*w^m;
|
191 : |
|
|
* As a generalisation a and b are made temperature dependent so the
|
192 : |
|
|
* final form of the function is
|
193 : |
|
|
* dw/dt = a0*exp(a1*T)*((w/a2)^a4 - (w/a3)^a5)
|
194 : |
|
|
* For no temperature dependency a1 = 0 */
|
195 : |
|
|
void GrowthCalcC::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
196 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
197 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
198 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
199 : |
|
|
|
200 : |
|
|
wgrowthPar.Update(TimeInfo);
|
201 : |
|
|
lgrowthPar.Update(TimeInfo);
|
202 : |
|
|
|
203 : |
|
|
//JMB - first some error checking
|
204 : |
|
|
if (handle.getLogLevel() >= LOGWARN) {
|
205 : |
|
|
if (isZero(wgrowthPar[2]) || isZero(wgrowthPar[3]))
|
206 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is zero");
|
207 : |
|
|
if (isZero(lgrowthPar[6]) || isZero(lgrowthPar[7]))
|
208 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is zero");
|
209 : |
|
|
if (lgrowthPar[5] < 0.0)
|
210 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is negative");
|
211 : |
|
|
}
|
212 : |
|
|
|
213 : |
|
|
int i;
|
214 : |
|
|
double fx;
|
215 : |
|
|
double ratio = lgrowthPar[0] + lgrowthPar[8] * (lgrowthPar[1] + lgrowthPar[2] * lgrowthPar[8]);
|
216 : |
|
|
double tempW = TimeInfo->getTimeStepSize() * wgrowthPar[0] *
|
217 : |
|
|
exp(wgrowthPar[1] * Area->getTemperature(area, TimeInfo->getTime()));
|
218 : |
|
|
|
219 : |
|
|
for (i = 0; i < Wgrowth.Size(); i++) {
|
220 : |
|
|
if (numGrow[i].W < verysmall || isZero(tempW)) {
|
221 : |
|
|
Wgrowth[i] = 0.0;
|
222 : |
|
|
Lgrowth[i] = 0.0;
|
223 : |
|
|
} else {
|
224 : |
|
|
Wgrowth[i] = tempW * (pow(numGrow[i].W / wgrowthPar[2], wgrowthPar[4]) -
|
225 : |
|
|
pow(numGrow[i].W / wgrowthPar[3], wgrowthPar[5]));
|
226 : |
|
|
|
227 : |
|
|
if (Wgrowth[i] < verysmall) {
|
228 : |
|
|
Wgrowth[i] = 0.0;
|
229 : |
|
|
Lgrowth[i] = 0.0;
|
230 : |
|
|
} else {
|
231 : |
|
|
fx = lgrowthPar[3] + (lgrowthPar[4] * (numGrow[i].W - ratio * refWeight[i]) / numGrow[i].W);
|
232 : |
|
|
if (fx > lgrowthPar[5])
|
233 : |
|
|
fx = lgrowthPar[5];
|
234 : |
|
|
if (fx < verysmall)
|
235 : |
|
|
Lgrowth[i] = 0.0;
|
236 : |
|
|
else
|
237 : |
|
|
Lgrowth[i] = fx * Wgrowth[i] / (lgrowthPar[6] * lgrowthPar[7] *
|
238 : |
|
|
pow(LgrpDiv->meanLength(i), lgrowthPar[7] - 1.0));
|
239 : |
|
|
}
|
240 : |
|
|
}
|
241 : |
|
|
}
|
242 : |
|
|
}
|
243 : |
|
|
|
244 : |
|
|
// ********************************************************
|
245 : |
|
|
// Functions for GrowthCalcD
|
246 : |
|
|
// ********************************************************
|
247 : |
|
|
GrowthCalcD::GrowthCalcD(CommentStream& infile, const IntVector& Areas,
|
248 : |
|
|
const TimeClass* const TimeInfo, const LengthGroupDivision* const LgrpDiv,
|
249 : |
|
|
Keeper* const keeper, const char* refWeightFile)
|
250 : |
|
|
: GrowthCalcBase(Areas), numWeightGrowthConstants(6), numLengthGrowthConstants(8) {
|
251 : |
|
|
|
252 : |
|
|
keeper->addString("growthcalcD");
|
253 : |
|
|
wgrowthPar.resize(numWeightGrowthConstants, keeper);
|
254 : |
|
|
lgrowthPar.resize(numLengthGrowthConstants, keeper);
|
255 : |
|
|
refWeight.resize(LgrpDiv->numLengthGroups(), 0.0);
|
256 : |
|
|
|
257 : |
|
|
int i, j;
|
258 : |
|
|
char text[MaxStrLength];
|
259 : |
|
|
strncpy(text, "", MaxStrLength);
|
260 : |
|
|
infile >> text >> ws;
|
261 : |
|
|
if (strcasecmp(text, "wgrowthparameters") != 0)
|
262 : |
|
|
handle.logFileUnexpected(LOGFAIL, "wgrowthparameters", text);
|
263 : |
|
|
wgrowthPar.read(infile, TimeInfo, keeper);
|
264 : |
|
|
|
265 : |
|
|
infile >> text >> ws;
|
266 : |
|
|
if (strcasecmp(text, "lgrowthparameters") != 0)
|
267 : |
|
|
handle.logFileUnexpected(LOGFAIL, "lgrowthparameters", text);
|
268 : |
|
|
lgrowthPar.read(infile, TimeInfo, keeper);
|
269 : |
|
|
|
270 : |
|
|
//read information on reference weights.
|
271 : |
|
|
keeper->addString("referenceweights");
|
272 : |
|
|
ifstream subfile;
|
273 : |
|
|
subfile.open(refWeightFile, ios::in);
|
274 : |
|
|
handle.checkIfFailure(subfile, refWeightFile);
|
275 : |
|
|
handle.Open(refWeightFile);
|
276 : |
|
|
CommentStream subcomment(subfile);
|
277 : |
|
|
DoubleMatrix tmpRefW;
|
278 : |
|
|
readRefWeights(subcomment, tmpRefW);
|
279 : |
|
|
handle.Close();
|
280 : |
|
|
subfile.close();
|
281 : |
|
|
subfile.clear();
|
282 : |
|
|
|
283 : |
|
|
//Interpolate the reference weights. First there are some error checks.
|
284 : |
|
|
if (LgrpDiv->meanLength(0) < tmpRefW[0][0] ||
|
285 : |
|
|
LgrpDiv->meanLength(LgrpDiv->numLengthGroups() - 1) > tmpRefW[tmpRefW.Nrow() - 1][0])
|
286 : |
|
|
handle.logFileMessage(LOGFAIL, "lengths for reference weights must span the range of growth lengths");
|
287 : |
|
|
|
288 : |
|
|
double ratio, tmplen;
|
289 : |
|
|
int pos = 0;
|
290 : |
|
|
for (j = 0; j < LgrpDiv->numLengthGroups(); j++) {
|
291 : |
|
|
tmplen = LgrpDiv->meanLength(j);
|
292 : |
|
|
for (i = pos; i < tmpRefW.Nrow() - 1; i++) {
|
293 : |
|
|
if (((tmplen > tmpRefW[i][0]) || (isEqual(tmplen, tmpRefW[i][0]))) &&
|
294 : |
|
|
((tmplen < tmpRefW[i + 1][0]) || (isEqual(tmplen, tmpRefW[i + 1][0])))) {
|
295 : |
|
|
|
296 : |
|
|
ratio = (tmplen - tmpRefW[i][0]) / (tmpRefW[i + 1][0] - tmpRefW[i][0]);
|
297 : |
|
|
refWeight[j] = tmpRefW[i][1] + ratio * (tmpRefW[i + 1][1] - tmpRefW[i][1]);
|
298 : |
|
|
pos = i;
|
299 : |
|
|
}
|
300 : |
|
|
}
|
301 : |
|
|
}
|
302 : |
|
|
keeper->clearLast();
|
303 : |
|
|
keeper->clearLast();
|
304 : |
|
|
}
|
305 : |
|
|
|
306 : |
|
|
/* Growth function from Jones 1978. Found from experiment in captivity.
|
307 : |
|
|
* Jones formula only applies to weight increase. The length increase
|
308 : |
|
|
* part is derived from the weight increase part by assuming a formula
|
309 : |
|
|
* w = a*l^b. If the weight is below the curve no length increase takes place
|
310 : |
|
|
* but instead the weight increases until it reaches the curve. */
|
311 : |
|
|
void GrowthCalcD::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
312 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
313 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
314 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
315 : |
|
|
|
316 : |
|
|
wgrowthPar.Update(TimeInfo);
|
317 : |
|
|
lgrowthPar.Update(TimeInfo);
|
318 : |
|
|
|
319 : |
|
|
//JMB - first some error checking
|
320 : |
|
|
if (handle.getLogLevel() >= LOGWARN) {
|
321 : |
|
|
if (isZero(wgrowthPar[0]))
|
322 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is zero");
|
323 : |
|
|
if (isZero(lgrowthPar[6]) || isZero(lgrowthPar[7]))
|
324 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is zero");
|
325 : |
|
|
if (lgrowthPar[5] < 0.0)
|
326 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is negative");
|
327 : |
|
|
}
|
328 : |
|
|
|
329 : |
|
|
int i;
|
330 : |
|
|
double ratio, fx;
|
331 : |
|
|
double tempC = TimeInfo->getTimeStepSize() / wgrowthPar[0];
|
332 : |
|
|
double tempW = TimeInfo->getTimeStepSize() * wgrowthPar[2] *
|
333 : |
|
|
exp(wgrowthPar[4] * Area->getTemperature(area, TimeInfo->getTime()) + wgrowthPar[5]);
|
334 : |
|
|
|
335 : |
|
|
for (i = 0; i < Wgrowth.Size(); i++) {
|
336 : |
|
|
if (numGrow[i].W < verysmall) {
|
337 : |
|
|
Wgrowth[i] = 0.0;
|
338 : |
|
|
Lgrowth[i] = 0.0;
|
339 : |
|
|
} else {
|
340 : |
|
|
Wgrowth[i] = Fphi[i] * MaxCon[i] * tempC / (pow(numGrow[i].W, wgrowthPar[1])) -
|
341 : |
|
|
tempW * pow(numGrow[i].W, wgrowthPar[3]);
|
342 : |
|
|
|
343 : |
|
|
if (Wgrowth[i] < verysmall) {
|
344 : |
|
|
Wgrowth[i] = 0.0;
|
345 : |
|
|
Lgrowth[i] = 0.0;
|
346 : |
|
|
} else {
|
347 : |
|
|
ratio = lgrowthPar[0] + Fphi[i] * (lgrowthPar[1] + lgrowthPar[2] * Fphi[i]);
|
348 : |
|
|
fx = lgrowthPar[3] + (lgrowthPar[4] * (numGrow[i].W - ratio * refWeight[i]) / numGrow[i].W);
|
349 : |
|
|
if (fx > lgrowthPar[5])
|
350 : |
|
|
fx = lgrowthPar[5];
|
351 : |
|
|
if (fx < verysmall)
|
352 : |
|
|
Lgrowth[i] = 0.0;
|
353 : |
|
|
else
|
354 : |
|
|
Lgrowth[i] = fx * Wgrowth[i] / (lgrowthPar[6] * lgrowthPar[7] *
|
355 : |
|
|
pow(LgrpDiv->meanLength(i), lgrowthPar[7] - 1.0));
|
356 : |
|
|
}
|
357 : |
|
|
}
|
358 : |
|
|
}
|
359 : |
|
|
}
|
360 : |
|
|
|
361 : |
|
|
// ********************************************************
|
362 : |
|
|
// Functions for GrowthCalcE
|
363 : |
|
|
// ********************************************************
|
364 : |
|
|
GrowthCalcE::GrowthCalcE(CommentStream& infile, const IntVector& Areas,
|
365 : |
|
|
const TimeClass* const TimeInfo, const LengthGroupDivision* const LgrpDiv,
|
366 : |
|
|
Keeper* const keeper, const char* refWeightFile)
|
367 : |
|
|
: GrowthCalcBase(Areas), numWeightGrowthConstants(6), numLengthGrowthConstants(9) {
|
368 : |
|
|
|
369 : |
|
|
keeper->addString("growthcalcE");
|
370 : |
|
|
wgrowthPar.resize(numWeightGrowthConstants, keeper);
|
371 : |
|
|
lgrowthPar.resize(numLengthGrowthConstants, keeper);
|
372 : |
|
|
refWeight.resize(LgrpDiv->numLengthGroups(), 0.0);
|
373 : |
|
|
yearEffect.resize(TimeInfo->getLastYear() - TimeInfo->getFirstYear() + 1, keeper);
|
374 : |
|
|
stepEffect.resize(TimeInfo->numSteps(), keeper);
|
375 : |
|
|
areaEffect.resize(Areas.Size(), keeper);
|
376 : |
|
|
|
377 : |
|
|
int i, j;
|
378 : |
|
|
char text[MaxStrLength];
|
379 : |
|
|
strncpy(text, "", MaxStrLength);
|
380 : |
|
|
infile >> text >> ws;
|
381 : |
|
|
if (strcasecmp(text, "wgrowthparameters") != 0)
|
382 : |
|
|
handle.logFileUnexpected(LOGFAIL, "wgrowthparameters", text);
|
383 : |
|
|
wgrowthPar.read(infile, TimeInfo, keeper);
|
384 : |
|
|
|
385 : |
|
|
infile >> text >> ws;
|
386 : |
|
|
if (strcasecmp(text, "lgrowthparameters") != 0)
|
387 : |
|
|
handle.logFileUnexpected(LOGFAIL, "lgrowthparameters", text);
|
388 : |
|
|
lgrowthPar.read(infile, TimeInfo, keeper);
|
389 : |
|
|
|
390 : |
|
|
infile >> text >> ws;
|
391 : |
|
|
if (strcasecmp(text, "yeareffect") != 0)
|
392 : |
|
|
handle.logFileUnexpected(LOGFAIL, "yeareffect", text);
|
393 : |
|
|
for (i = 0; i < yearEffect.Size(); i++)
|
394 : |
|
|
if (!(infile >> yearEffect[i]))
|
395 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format of yeareffect vector");
|
396 : |
|
|
yearEffect.Inform(keeper);
|
397 : |
|
|
|
398 : |
|
|
infile >> text >> ws;
|
399 : |
|
|
if (strcasecmp(text, "stepeffect") != 0)
|
400 : |
|
|
handle.logFileUnexpected(LOGFAIL, "stepeffect", text);
|
401 : |
|
|
for (i = 0; i < stepEffect.Size(); i++)
|
402 : |
|
|
if (!(infile >> stepEffect[i]))
|
403 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format of stepeffect vector");
|
404 : |
|
|
stepEffect.Inform(keeper);
|
405 : |
|
|
|
406 : |
|
|
infile >> text >> ws;
|
407 : |
|
|
if (strcasecmp(text, "areaeffect") != 0)
|
408 : |
|
|
handle.logFileUnexpected(LOGFAIL, "areaeffect", text);
|
409 : |
|
|
for (i = 0; i < areaEffect.Size(); i++)
|
410 : |
|
|
if (!(infile >> areaEffect[i]))
|
411 : |
|
|
handle.logFileMessage(LOGFAIL, "invalid format of areaeffect vector");
|
412 : |
|
|
areaEffect.Inform(keeper);
|
413 : |
|
|
|
414 : |
|
|
//read information on reference weights.
|
415 : |
|
|
keeper->addString("referenceweights");
|
416 : |
|
|
ifstream subfile;
|
417 : |
|
|
subfile.open(refWeightFile, ios::in);
|
418 : |
|
|
handle.checkIfFailure(subfile, refWeightFile);
|
419 : |
|
|
handle.Open(refWeightFile);
|
420 : |
|
|
CommentStream subcomment(subfile);
|
421 : |
|
|
DoubleMatrix tmpRefW;
|
422 : |
|
|
readRefWeights(subcomment, tmpRefW);
|
423 : |
|
|
handle.Close();
|
424 : |
|
|
subfile.close();
|
425 : |
|
|
subfile.clear();
|
426 : |
|
|
|
427 : |
|
|
//Interpolate the reference weights.
|
428 : |
|
|
if (LgrpDiv->meanLength(0) < tmpRefW[0][0] ||
|
429 : |
|
|
LgrpDiv->meanLength(LgrpDiv->numLengthGroups() - 1) > tmpRefW[tmpRefW.Nrow() - 1][0])
|
430 : |
|
|
handle.logFileMessage(LOGFAIL, "lengths for reference weights must span the range of growth lengths");
|
431 : |
|
|
|
432 : |
|
|
double ratio, tmplen;
|
433 : |
|
|
int pos = 0;
|
434 : |
|
|
for (j = 0; j < LgrpDiv->numLengthGroups(); j++) {
|
435 : |
|
|
tmplen = LgrpDiv->meanLength(j);
|
436 : |
|
|
for (i = pos; i < tmpRefW.Nrow() - 1; i++) {
|
437 : |
|
|
if (((tmplen > tmpRefW[i][0]) || (isEqual(tmplen, tmpRefW[i][0]))) &&
|
438 : |
|
|
((tmplen < tmpRefW[i + 1][0]) || (isEqual(tmplen, tmpRefW[i + 1][0])))) {
|
439 : |
|
|
|
440 : |
|
|
ratio = (tmplen - tmpRefW[i][0]) / (tmpRefW[i + 1][0] - tmpRefW[i][0]);
|
441 : |
|
|
refWeight[j] = tmpRefW[i][1] + ratio * (tmpRefW[i + 1][1] - tmpRefW[i][1]);
|
442 : |
|
|
pos = i;
|
443 : |
|
|
}
|
444 : |
|
|
}
|
445 : |
|
|
}
|
446 : |
|
|
keeper->clearLast();
|
447 : |
|
|
keeper->clearLast();
|
448 : |
|
|
}
|
449 : |
|
|
|
450 : |
|
|
/* Growthfunction to be tested for capelin.
|
451 : |
|
|
* The weight growth here is given by the formula
|
452 : |
|
|
* dw/dt = a0*factor(year)*factor(area)*factor(Step)*w^a1 - a2*w^a3
|
453 : |
|
|
* This is Von Bertanlanffy equation with possibility to make the growth
|
454 : |
|
|
* year, area and Step dependent. 3 vectors were added to the class
|
455 : |
|
|
* YearEffect
|
456 : |
|
|
* AreaEffect
|
457 : |
|
|
* StepEffect
|
458 : |
|
|
* Length increase is upgraded in the same way as earlier. */
|
459 : |
|
|
void GrowthCalcE::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
460 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
461 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
462 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
463 : |
|
|
|
464 : |
|
|
wgrowthPar.Update(TimeInfo);
|
465 : |
|
|
lgrowthPar.Update(TimeInfo);
|
466 : |
|
|
|
467 : |
|
|
//JMB - first some error checking
|
468 : |
|
|
if (handle.getLogLevel() >= LOGWARN) {
|
469 : |
|
|
if (isZero(wgrowthPar[2]) || isZero(wgrowthPar[3]))
|
470 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is zero");
|
471 : |
|
|
if (isZero(lgrowthPar[6]) || isZero(lgrowthPar[7]))
|
472 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is zero");
|
473 : |
|
|
if (lgrowthPar[5] < 0.0)
|
474 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is negative");
|
475 : |
|
|
}
|
476 : |
|
|
|
477 : |
|
|
int i;
|
478 : |
|
|
double fx;
|
479 : |
|
|
double factor = yearEffect[TimeInfo->getYear() - TimeInfo->getFirstYear()] *
|
480 : |
|
|
stepEffect[TimeInfo->getStep() - 1] * areaEffect[this->areaNum(area)];
|
481 : |
|
|
double ratio = lgrowthPar[0] + lgrowthPar[8] * (lgrowthPar[1] + lgrowthPar[2] * lgrowthPar[8]);
|
482 : |
|
|
double tempW = factor * TimeInfo->getTimeStepSize() * wgrowthPar[0] *
|
483 : |
|
|
exp(wgrowthPar[1] * Area->getTemperature(area, TimeInfo->getTime()));
|
484 : |
|
|
|
485 : |
|
|
for (i = 0; i < Wgrowth.Size(); i++) {
|
486 : |
|
|
if (numGrow[i].W < verysmall || isZero(tempW)) {
|
487 : |
|
|
Wgrowth[i] = 0.0;
|
488 : |
|
|
Lgrowth[i] = 0.0;
|
489 : |
|
|
} else {
|
490 : |
|
|
Wgrowth[i] = tempW * (pow(numGrow[i].W / wgrowthPar[2], wgrowthPar[4]) -
|
491 : |
|
|
pow(numGrow[i].W / wgrowthPar[3], wgrowthPar[5]));
|
492 : |
|
|
|
493 : |
|
|
if (Wgrowth[i] < verysmall) {
|
494 : |
|
|
Wgrowth[i] = 0.0;
|
495 : |
|
|
Lgrowth[i] = 0.0;
|
496 : |
|
|
} else {
|
497 : |
|
|
fx = lgrowthPar[3] + (lgrowthPar[4] * (numGrow[i].W - ratio * refWeight[i]) / numGrow[i].W);
|
498 : |
|
|
if (fx > lgrowthPar[5])
|
499 : |
|
|
fx = lgrowthPar[5];
|
500 : |
|
|
if (fx < verysmall)
|
501 : |
|
|
Lgrowth[i] = 0.0;
|
502 : |
|
|
else
|
503 : |
|
|
Lgrowth[i] = fx * Wgrowth[i] / (lgrowthPar[6] * lgrowthPar[7] *
|
504 : |
|
|
pow(LgrpDiv->meanLength(i), lgrowthPar[7] - 1.0));
|
505 : |
|
|
}
|
506 : |
|
|
}
|
507 : |
|
|
}
|
508 : |
|
|
}
|
509 : |
|
|
|
510 : |
|
|
// ********************************************************
|
511 : |
|
|
// Functions for GrowthCalcF
|
512 : |
|
|
// ********************************************************
|
513 : |
|
|
/* The Norwegian Growthfunction Equations 6 and 7 on page 7 in
|
514 : |
|
|
* Description of a multispecies model for the Barents Sea.
|
515 : |
|
|
* parameter # 0 corresponds to C4 in the equation etc. */
|
516 : |
|
|
GrowthCalcF::GrowthCalcF(CommentStream& infile, const IntVector& Areas,
|
517 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper,
|
518 : |
|
|
const AreaClass* const Area, const CharPtrVector& lenindex)
|
519 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(2) {
|
520 : |
|
|
|
521 : |
|
|
keeper->addString("growthcalcF");
|
522 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
523 : |
|
|
|
524 : |
|
|
int i;
|
525 : |
|
|
char text[MaxStrLength];
|
526 : |
|
|
strncpy(text, "", MaxStrLength);
|
527 : |
|
|
infile >> text >> ws;
|
528 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
529 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
530 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
531 : |
|
|
|
532 : |
|
|
for (i = 0; i < Areas.Size(); i++)
|
533 : |
|
|
wgrowth.resize(new FormulaMatrix(TimeInfo->numTotalSteps() + 1, lenindex.Size(), 0.0));
|
534 : |
|
|
|
535 : |
|
|
ifstream datafile;
|
536 : |
|
|
CommentStream subdata(datafile);
|
537 : |
|
|
readWordAndValue(infile, "weightgrowthfile", text);
|
538 : |
|
|
datafile.open(text, ios::in);
|
539 : |
|
|
handle.checkIfFailure(datafile, text);
|
540 : |
|
|
handle.Open(text);
|
541 : |
|
|
readGrowthAmounts(subdata, TimeInfo, Area, wgrowth, lenindex, Areas);
|
542 : |
|
|
handle.Close();
|
543 : |
|
|
datafile.close();
|
544 : |
|
|
datafile.clear();
|
545 : |
|
|
|
546 : |
|
|
for (i = 0; i < Areas.Size(); i++)
|
547 : |
|
|
(*wgrowth[i]).Inform(keeper);
|
548 : |
|
|
|
549 : |
|
|
keeper->clearLast();
|
550 : |
|
|
}
|
551 : |
|
|
|
552 : |
|
|
GrowthCalcF::~GrowthCalcF() {
|
553 : |
|
|
int a;
|
554 : |
|
|
for (a = 0; a < wgrowth.Size(); a++)
|
555 : |
|
|
delete wgrowth[a];
|
556 : |
|
|
}
|
557 : |
|
|
|
558 : |
|
|
void GrowthCalcF::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
559 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
560 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
561 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
562 : |
|
|
|
563 : |
|
|
growthPar.Update(TimeInfo);
|
564 : |
|
|
int i, t, inarea;
|
565 : |
|
|
t = TimeInfo->getTime();
|
566 : |
|
|
inarea = this->areaNum(area);
|
567 : |
|
|
double kval = 1.0 - exp(-growthPar[1] * TimeInfo->getTimeStepSize());
|
568 : |
|
|
|
569 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
570 : |
|
|
Lgrowth[i] = (growthPar[0] - LgrpDiv->meanLength(i)) * kval;
|
571 : |
|
|
Wgrowth[i] = (*wgrowth[inarea])[t][i];
|
572 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (Wgrowth[i] < 0.0))
|
573 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is negative");
|
574 : |
|
|
}
|
575 : |
|
|
}
|
576 : |
|
|
|
577 : |
|
|
// ********************************************************
|
578 : |
|
|
// Functions for GrowthCalcG
|
579 : |
|
|
// ********************************************************
|
580 : |
|
|
GrowthCalcG::GrowthCalcG(CommentStream& infile, const IntVector& Areas,
|
581 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper,
|
582 : |
|
|
const AreaClass* const Area, const CharPtrVector& lenindex)
|
583 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(2) {
|
584 : |
|
|
|
585 : |
|
|
keeper->addString("growthcalcG");
|
586 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
587 : |
|
|
|
588 : |
|
|
int i;
|
589 : |
|
|
char text[MaxStrLength];
|
590 : |
|
|
strncpy(text, "", MaxStrLength);
|
591 : |
|
|
infile >> text >> ws;
|
592 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
593 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
594 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
595 : |
|
|
|
596 : |
|
|
for (i = 0; i < Areas.Size(); i++)
|
597 : |
|
|
wgrowth.resize(new FormulaMatrix(TimeInfo->numTotalSteps() + 1, lenindex.Size(), 0.0));
|
598 : |
|
|
|
599 : |
|
|
ifstream datafile;
|
600 : |
|
|
CommentStream subdata(datafile);
|
601 : |
|
|
readWordAndValue(infile, "weightgrowthfile", text);
|
602 : |
|
|
datafile.open(text, ios::in);
|
603 : |
|
|
handle.checkIfFailure(datafile, text);
|
604 : |
|
|
handle.Open(text);
|
605 : |
|
|
readGrowthAmounts(subdata, TimeInfo, Area, wgrowth, lenindex, Areas);
|
606 : |
|
|
handle.Close();
|
607 : |
|
|
datafile.close();
|
608 : |
|
|
datafile.clear();
|
609 : |
|
|
|
610 : |
|
|
for (i = 0; i < Areas.Size(); i++)
|
611 : |
|
|
(*wgrowth[i]).Inform(keeper);
|
612 : |
|
|
|
613 : |
|
|
keeper->clearLast();
|
614 : |
|
|
}
|
615 : |
|
|
|
616 : |
|
|
GrowthCalcG::~GrowthCalcG() {
|
617 : |
|
|
int a;
|
618 : |
|
|
for (a = 0; a < wgrowth.Size(); a++)
|
619 : |
|
|
delete wgrowth[a];
|
620 : |
|
|
}
|
621 : |
|
|
|
622 : |
|
|
void GrowthCalcG::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
623 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
624 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
625 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
626 : |
|
|
|
627 : |
|
|
//written by kgf 24/10 00
|
628 : |
|
|
//Gives linear growth (growthPar[0] == 0) or
|
629 : |
|
|
//growth decreasing with length (growthPar[0] < 0)
|
630 : |
|
|
growthPar.Update(TimeInfo);
|
631 : |
|
|
int i, t, inarea;
|
632 : |
|
|
t = TimeInfo->getTime();
|
633 : |
|
|
inarea = this->areaNum(area);
|
634 : |
|
|
double kval = growthPar[1] * TimeInfo->getTimeStepSize();
|
635 : |
|
|
|
636 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar[0] > 0.0))
|
637 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - growth parameter is positive");
|
638 : |
|
|
|
639 : |
|
|
if (isZero(growthPar[0])) {
|
640 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
641 : |
|
|
Lgrowth[i] = kval;
|
642 : |
|
|
Wgrowth[i] = (*wgrowth[inarea])[t][i];
|
643 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (Wgrowth[i] < 0.0))
|
644 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is negative");
|
645 : |
|
|
}
|
646 : |
|
|
} else if (isEqual(growthPar[0], 1.0)) {
|
647 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
648 : |
|
|
Lgrowth[i] = kval * LgrpDiv->meanLength(i);
|
649 : |
|
|
Wgrowth[i] = (*wgrowth[inarea])[t][i];
|
650 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (Wgrowth[i] < 0.0))
|
651 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is negative");
|
652 : |
|
|
}
|
653 : |
|
|
} else {
|
654 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++) {
|
655 : |
|
|
Lgrowth[i] = kval * pow(LgrpDiv->meanLength(i), growthPar[0]);
|
656 : |
|
|
Wgrowth[i] = (*wgrowth[inarea])[t][i];
|
657 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (Wgrowth[i] < 0.0))
|
658 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is negative");
|
659 : |
|
|
}
|
660 : |
|
|
}
|
661 : |
|
|
}
|
662 : |
|
|
|
663 : |
|
|
// ********************************************************
|
664 : |
|
|
// Functions for GrowthCalcH
|
665 : |
|
|
// ********************************************************
|
666 : |
|
|
GrowthCalcH::GrowthCalcH(CommentStream& infile, const IntVector& Areas,
|
667 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper)
|
668 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(4) {
|
669 : |
|
|
|
670 : |
|
|
keeper->addString("growthcalcH");
|
671 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
672 : |
|
|
|
673 : |
|
|
char text[MaxStrLength];
|
674 : |
|
|
strncpy(text, "", MaxStrLength);
|
675 : |
|
|
infile >> text >> ws;
|
676 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
677 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
678 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
679 : |
|
|
keeper->clearLast();
|
680 : |
|
|
}
|
681 : |
|
|
|
682 : |
|
|
/* Simplified 2 parameter length based Von Bertalanffy growth function
|
683 : |
|
|
* compare with GrowthCalcC for the more complex weight based version */
|
684 : |
|
|
void GrowthCalcH::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
685 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
686 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
687 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
688 : |
|
|
|
689 : |
|
|
growthPar.Update(TimeInfo);
|
690 : |
|
|
//JMB - first some error checking
|
691 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar.didChange(TimeInfo))) {
|
692 : |
|
|
if (isZero(growthPar[1]) || isZero(growthPar[2]))
|
693 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - growth parameter is zero");
|
694 : |
|
|
if (LgrpDiv->maxLength() > growthPar[0])
|
695 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length greater than length infinity");
|
696 : |
|
|
}
|
697 : |
|
|
|
698 : |
|
|
double mult = 1.0 - exp(-growthPar[1] * TimeInfo->getTimeStepSize());
|
699 : |
|
|
int i;
|
700 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++)
|
701 : |
|
|
Lgrowth[i] = (growthPar[0] - LgrpDiv->meanLength(i)) * mult;
|
702 : |
|
|
}
|
703 : |
|
|
|
704 : |
ulcessvp |
2 |
|
705 : |
|
|
|
706 : |
|
|
void GrowthCalcH::calcGrowth(int area, double* Lgrowth, double* Wgrowth,
|
707 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
708 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
709 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv, int size) {
|
710 : |
|
|
|
711 : |
|
|
growthPar.Update(TimeInfo);
|
712 : |
|
|
//JMB - first some error checking
|
713 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar.didChange(TimeInfo))) {
|
714 : |
|
|
if (isZero(growthPar[1]) || isZero(growthPar[2]))
|
715 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - growth parameter is zero");
|
716 : |
|
|
if (LgrpDiv->maxLength() > growthPar[0])
|
717 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length greater than length infinity");
|
718 : |
|
|
}
|
719 : |
|
|
|
720 : |
|
|
double mult = 1.0 - exp(-growthPar[1] * TimeInfo->getTimeStepSize());
|
721 : |
|
|
int i;
|
722 : |
|
|
for (i = 0; i < size; i++)
|
723 : |
|
|
Lgrowth[i] = (growthPar[0] - LgrpDiv->meanLength(i)) * mult;
|
724 : |
|
|
}
|
725 : |
|
|
|
726 : |
|
|
|
727 : |
|
|
|
728 : |
|
|
|
729 : |
|
|
|
730 : |
agomez |
1 |
// ********************************************************
|
731 : |
|
|
// Functions for GrowthCalcI
|
732 : |
|
|
// ********************************************************
|
733 : |
|
|
GrowthCalcI::GrowthCalcI(CommentStream& infile, const IntVector& Areas,
|
734 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper)
|
735 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(6) {
|
736 : |
|
|
|
737 : |
|
|
keeper->addString("growthcalcI");
|
738 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
739 : |
|
|
|
740 : |
|
|
char text[MaxStrLength];
|
741 : |
|
|
strncpy(text, "", MaxStrLength);
|
742 : |
|
|
infile >> text >> ws;
|
743 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
744 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
745 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
746 : |
|
|
keeper->clearLast();
|
747 : |
|
|
}
|
748 : |
|
|
|
749 : |
|
|
/* Simplified 4 parameter Jones growth function
|
750 : |
|
|
* compare with GrowthCalcD for the more complex version */
|
751 : |
|
|
void GrowthCalcI::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
752 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
753 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
754 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
755 : |
|
|
|
756 : |
|
|
growthPar.Update(TimeInfo);
|
757 : |
|
|
//JMB - first some error checking
|
758 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar.didChange(TimeInfo))) {
|
759 : |
|
|
if (isZero(growthPar[0]) || isZero(growthPar[1]))
|
760 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - weight growth parameter is zero");
|
761 : |
|
|
if (isZero(growthPar[4]) || isZero(growthPar[5]))
|
762 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length growth parameter is zero");
|
763 : |
|
|
}
|
764 : |
|
|
|
765 : |
|
|
double tempC = TimeInfo->getTimeStepSize() * growthPar[0];
|
766 : |
|
|
double tempW = TimeInfo->getTimeStepSize() * growthPar[1] *
|
767 : |
|
|
exp(growthPar[3] * Area->getTemperature(area, TimeInfo->getTime()));
|
768 : |
|
|
|
769 : |
|
|
int i;
|
770 : |
|
|
for (i = 0; i < Wgrowth.Size(); i++) {
|
771 : |
|
|
if (numGrow[i].W < verysmall) {
|
772 : |
|
|
Wgrowth[i] = 0.0;
|
773 : |
|
|
Lgrowth[i] = 0.0;
|
774 : |
|
|
} else {
|
775 : |
|
|
Wgrowth[i] = tempC * Fphi[i] * MaxCon[i] - tempW * pow(numGrow[i].W, growthPar[2]);
|
776 : |
|
|
|
777 : |
|
|
if (Wgrowth[i] < verysmall) {
|
778 : |
|
|
Wgrowth[i] = 0.0;
|
779 : |
|
|
Lgrowth[i] = 0.0;
|
780 : |
|
|
} else {
|
781 : |
|
|
Lgrowth[i] = Wgrowth[i] / (growthPar[4] * growthPar[5] *
|
782 : |
|
|
pow(LgrpDiv->meanLength(i), growthPar[5] - 1.0));
|
783 : |
|
|
}
|
784 : |
|
|
}
|
785 : |
|
|
}
|
786 : |
|
|
}
|
787 : |
|
|
|
788 : |
|
|
// ********************************************************
|
789 : |
|
|
// Functions for GrowthCalcJ
|
790 : |
|
|
// ********************************************************
|
791 : |
|
|
GrowthCalcJ::GrowthCalcJ(CommentStream& infile, const IntVector& Areas,
|
792 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper)
|
793 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(5) {
|
794 : |
|
|
|
795 : |
|
|
keeper->addString("GrowthCalcJ");
|
796 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
797 : |
|
|
|
798 : |
|
|
char text[MaxStrLength];
|
799 : |
|
|
strncpy(text, "", MaxStrLength);
|
800 : |
|
|
infile >> text >> ws;
|
801 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
802 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
803 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
804 : |
|
|
keeper->clearLast();
|
805 : |
|
|
}
|
806 : |
|
|
|
807 : |
|
|
/* Simplified 2 parameter length based Von Bertalanffy growth function
|
808 : |
|
|
* compare with GrowthCalcC for the more complex weight based version
|
809 : |
|
|
* with a non-zero value for t0 (compare to GrowthCalcH for simpler version */
|
810 : |
|
|
void GrowthCalcJ::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
811 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
812 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
813 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
814 : |
|
|
|
815 : |
|
|
growthPar.Update(TimeInfo);
|
816 : |
|
|
//JMB - first some error checking
|
817 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar.didChange(TimeInfo))) {
|
818 : |
|
|
if (isZero(growthPar[1]) || isZero(growthPar[2]))
|
819 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - growth parameter is zero");
|
820 : |
|
|
if (LgrpDiv->maxLength() > growthPar[0])
|
821 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length greater than length infinity");
|
822 : |
|
|
}
|
823 : |
|
|
|
824 : |
|
|
double mult = 1.0 - exp(-growthPar[1] * TimeInfo->getTimeStepSize());
|
825 : |
|
|
int i;
|
826 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++)
|
827 : |
|
|
Lgrowth[i] = (growthPar[0] - LgrpDiv->meanLength(i)) * mult;
|
828 : |
|
|
}
|
829 : |
|
|
|
830 : |
|
|
// ********************************************************
|
831 : |
|
|
// Functions for GrowthCalcK
|
832 : |
|
|
// ********************************************************
|
833 : |
|
|
GrowthCalcK::GrowthCalcK(CommentStream& infile, const IntVector& Areas,
|
834 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper)
|
835 : |
|
|
: GrowthCalcBase(Areas), numGrowthConstants(5) {
|
836 : |
|
|
|
837 : |
|
|
keeper->addString("GrowthCalcK");
|
838 : |
|
|
growthPar.resize(numGrowthConstants, keeper);
|
839 : |
|
|
|
840 : |
|
|
char text[MaxStrLength];
|
841 : |
|
|
strncpy(text, "", MaxStrLength);
|
842 : |
|
|
infile >> text >> ws;
|
843 : |
|
|
if (strcasecmp(text, "growthparameters") != 0)
|
844 : |
|
|
handle.logFileUnexpected(LOGFAIL, "growthparameters", text);
|
845 : |
|
|
growthPar.read(infile, TimeInfo, keeper);
|
846 : |
|
|
keeper->clearLast();
|
847 : |
|
|
}
|
848 : |
|
|
|
849 : |
|
|
/* Simplified length based Gompertz growth function */
|
850 : |
|
|
void GrowthCalcK::calcGrowth(int area, DoubleVector& Lgrowth, DoubleVector& Wgrowth,
|
851 : |
|
|
const PopInfoVector& numGrow, const AreaClass* const Area,
|
852 : |
|
|
const TimeClass* const TimeInfo, const DoubleVector& Fphi,
|
853 : |
|
|
const DoubleVector& MaxCon, const LengthGroupDivision* const LgrpDiv) {
|
854 : |
|
|
|
855 : |
|
|
growthPar.Update(TimeInfo);
|
856 : |
|
|
//JMB - first some error checking
|
857 : |
|
|
if ((handle.getLogLevel() >= LOGWARN) && (growthPar.didChange(TimeInfo))) {
|
858 : |
|
|
if (isZero(growthPar[1]) || isZero(growthPar[2]))
|
859 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - growth parameter is zero");
|
860 : |
|
|
if (LgrpDiv->maxLength() > growthPar[0])
|
861 : |
|
|
handle.logMessage(LOGWARN, "Warning in growth calculation - length greater than length infinity");
|
862 : |
|
|
}
|
863 : |
|
|
|
864 : |
|
|
double mult = 1.0 - exp(-growthPar[1] * TimeInfo->getTimeStepSize());
|
865 : |
|
|
int i;
|
866 : |
|
|
for (i = 0; i < Lgrowth.Size(); i++)
|
867 : |
|
|
Lgrowth[i] = (growthPar[0] - LgrpDiv->meanLength(i)) * mult;
|
868 : |
|
|
}
|