1 : |
agomez |
1 |
#include "naturalm.h" |
2 : |
|
|
#include "readfunc.h" |
3 : |
|
|
#include "areatime.h" |
4 : |
|
|
#include "readword.h" |
5 : |
|
|
#include "keeper.h" |
6 : |
|
|
#include "errorhandler.h" |
7 : |
|
|
#include "gadget.h" |
8 : |
|
|
#include "global.h" |
9 : |
|
|
|
10 : |
|
|
NaturalMortality::NaturalMortality(CommentStream& infile, int minage, int numage,
|
11 : |
|
|
const char* givenname, const IntVector& Areas, const TimeClass* const TimeInfo,
|
12 : |
|
|
Keeper* const keeper) : HasName(givenname), LivesOnAreas(Areas) {
|
13 : |
|
|
|
14 : |
|
|
minStockAge = minage;
|
15 : |
|
|
readoption = 0;
|
16 : |
|
|
proportion.AddRows(areas.Size(), numage, 0.0);
|
17 : |
|
|
keeper->addString("naturalmortality");
|
18 : |
|
|
|
19 : |
|
|
infile >> ws;
|
20 : |
|
|
char c = infile.peek();
|
21 : |
|
|
if ((c == 'm') || (c == 'M')) {
|
22 : |
|
|
//JMB experimental mortality function
|
23 : |
|
|
readoption = 1;
|
24 : |
|
|
char text[MaxStrLength];
|
25 : |
|
|
strncpy(text, "", MaxStrLength);
|
26 : |
|
|
readWordAndValue(infile, "mortalityfunction", text);
|
27 : |
|
|
if (strcasecmp(text, "constant") == 0)
|
28 : |
|
|
fnMortality = new ConstSelectFunc();
|
29 : |
|
|
else if (strcasecmp(text, "straightline") == 0)
|
30 : |
|
|
fnMortality = new StraightSelectFunc();
|
31 : |
|
|
else if (strcasecmp(text, "exponential") == 0)
|
32 : |
|
|
fnMortality = new ExpSelectFunc();
|
33 : |
|
|
else
|
34 : |
|
|
handle.logFileMessage(LOGFAIL, "unrecognised mortality function", text);
|
35 : |
|
|
fnMortality->readConstants(infile, TimeInfo, keeper);
|
36 : |
|
|
|
37 : |
|
|
} else {
|
38 : |
|
|
mortality.setsize(numage);
|
39 : |
|
|
mortality.read(infile, TimeInfo, keeper);
|
40 : |
|
|
}
|
41 : |
|
|
|
42 : |
|
|
keeper->clearLast();
|
43 : |
|
|
}
|
44 : |
|
|
|
45 : |
|
|
NaturalMortality::~NaturalMortality() {
|
46 : |
|
|
if (readoption == 1)
|
47 : |
|
|
delete fnMortality;
|
48 : |
|
|
}
|
49 : |
|
|
|
50 : |
|
|
void NaturalMortality::Reset(const TimeClass* const TimeInfo) {
|
51 : |
|
|
if (readoption == 0) {
|
52 : |
|
|
mortality.Update(TimeInfo);
|
53 : |
|
|
if (mortality.didChange(TimeInfo) || TimeInfo->didStepSizeChange()) {
|
54 : |
|
|
int i, j;
|
55 : |
|
|
for (i = 0; i < proportion.Nrow(); i++) {
|
56 : |
|
|
for (j = 0; j < proportion.Ncol(i); j++) {
|
57 : |
|
|
if (mortality[j] > verysmall)
|
58 : |
|
|
proportion[i][j] = exp(-mortality[j] * TimeInfo->getTimeStepSize());
|
59 : |
|
|
else
|
60 : |
|
|
proportion[i][j] = 1.0; //use mortality rate 0
|
61 : |
|
|
}
|
62 : |
|
|
}
|
63 : |
|
|
|
64 : |
|
|
if (handle.getLogLevel() >= LOGMESSAGE)
|
65 : |
|
|
handle.logMessage(LOGMESSAGE, "Reset natural mortality data for stock", this->getName());
|
66 : |
|
|
}
|
67 : |
|
|
|
68 : |
|
|
} else if (readoption == 1) {
|
69 : |
|
|
//JMB experimental mortality function
|
70 : |
|
|
fnMortality->updateConstants(TimeInfo);
|
71 : |
|
|
if (fnMortality->didChange(TimeInfo) || TimeInfo->didStepSizeChange()) {
|
72 : |
|
|
int i, j;
|
73 : |
|
|
double m;
|
74 : |
|
|
for (i = 0; i < proportion.Nrow(); i++) {
|
75 : |
|
|
for (j = 0; j < proportion.Ncol(i); j++) {
|
76 : |
|
|
m = fnMortality->calculate(double(minStockAge + j));
|
77 : |
|
|
if (m > verysmall)
|
78 : |
|
|
proportion[i][j] = exp(-m * TimeInfo->getTimeStepSize());
|
79 : |
|
|
else
|
80 : |
|
|
proportion[i][j] = 1.0; //use mortality rate 0
|
81 : |
|
|
}
|
82 : |
|
|
}
|
83 : |
|
|
|
84 : |
|
|
if (handle.getLogLevel() >= LOGMESSAGE)
|
85 : |
|
|
handle.logMessage(LOGMESSAGE, "Reset natural mortality data for stock", this->getName());
|
86 : |
|
|
}
|
87 : |
|
|
|
88 : |
|
|
} else
|
89 : |
|
|
handle.logMessage(LOGFAIL, "Error in natural mortality - unrecognised mortality function", readoption);
|
90 : |
|
|
}
|
91 : |
|
|
|
92 : |
|
|
void NaturalMortality::Print(ofstream& outfile) {
|
93 : |
|
|
int i;
|
94 : |
|
|
outfile << "Natural mortality\n\t";
|
95 : |
|
|
if (readoption == 0) {
|
96 : |
|
|
for (i = 0; i < mortality.Size(); i++)
|
97 : |
|
|
outfile << mortality[i] << sep;
|
98 : |
|
|
outfile << endl;
|
99 : |
|
|
|
100 : |
|
|
} else if (readoption == 1) {
|
101 : |
|
|
double m;
|
102 : |
|
|
for (i = 0; i < proportion.Ncol(); i++) {
|
103 : |
|
|
m = fnMortality->calculate(double(minStockAge + i));
|
104 : |
|
|
outfile << m << sep;
|
105 : |
|
|
}
|
106 : |
|
|
outfile << endl;
|
107 : |
|
|
|
108 : |
|
|
} else
|
109 : |
|
|
handle.logMessage(LOGFAIL, "Error in natural mortality - unrecognised mortality function", readoption);
|
110 : |
|
|
}
|