1 : |
agomez |
1 |
#include "effortpredator.h" |
2 : |
|
|
#include "keeper.h" |
3 : |
|
|
#include "prey.h" |
4 : |
|
|
#include "mathfunc.h" |
5 : |
|
|
#include "errorhandler.h" |
6 : |
|
|
#include "gadget.h" |
7 : |
|
|
#include "global.h" |
8 : |
|
|
|
9 : |
|
|
EffortPredator::EffortPredator(CommentStream& infile, const char* givenname,
|
10 : |
|
|
const IntVector& Areas, const TimeClass* const TimeInfo, Keeper* const keeper, Formula multscaler)
|
11 : |
|
|
: LengthPredator(givenname, Areas, keeper, multscaler) {
|
12 : |
|
|
|
13 : |
|
|
type = EFFORTPREDATOR;
|
14 : |
|
|
keeper->addString("predator");
|
15 : |
|
|
keeper->addString(givenname);
|
16 : |
|
|
|
17 : |
|
|
//first read in the suitability parameters
|
18 : |
|
|
this->readSuitability(infile, TimeInfo, keeper);
|
19 : |
|
|
|
20 : |
|
|
//now we read in the catchability parameters - should be one for each prey
|
21 : |
|
|
keeper->addString("catchability");
|
22 : |
|
|
int i, count = 0;
|
23 : |
|
|
char text[MaxStrLength];
|
24 : |
|
|
strncpy(text, "", MaxStrLength);
|
25 : |
|
|
infile >> text >> ws;
|
26 : |
|
|
while ((strcasecmp(text, "amount") != 0) && !infile.eof()) {
|
27 : |
|
|
for (i = 0; i < preference.Size(); i++) {
|
28 : |
|
|
if (strcasecmp(text, this->getPreyName(i)) == 0) {
|
29 : |
|
|
infile >> preference[i] >> ws;
|
30 : |
|
|
count++;
|
31 : |
|
|
}
|
32 : |
|
|
}
|
33 : |
|
|
infile >> text >> ws;
|
34 : |
|
|
}
|
35 : |
|
|
if (count != preference.Size())
|
36 : |
|
|
handle.logMessage(LOGFAIL, "Error in effortpredator - missing catchability data");
|
37 : |
|
|
preference.Inform(keeper);
|
38 : |
|
|
keeper->clearLast();
|
39 : |
|
|
|
40 : |
|
|
keeper->clearLast();
|
41 : |
|
|
keeper->clearLast();
|
42 : |
|
|
}
|
43 : |
|
|
|
44 : |
|
|
void EffortPredator::Eat(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
|
45 : |
|
|
|
46 : |
|
|
int inarea = this->areaNum(area);
|
47 : |
|
|
int prey, preyl;
|
48 : |
|
|
int predl = 0; //JMB there is only ever one length group ...
|
49 : |
|
|
totalcons[inarea][predl] = 0.0;
|
50 : |
|
|
|
51 : |
|
|
double tmp;
|
52 : |
|
|
tmp = prednumber[inarea][predl].N * multi * TimeInfo->getTimeStepSize() / TimeInfo->numSubSteps();
|
53 : |
|
|
if (isZero(tmp)) //JMB no predation takes place on this timestep
|
54 : |
|
|
return;
|
55 : |
|
|
|
56 : |
|
|
for (prey = 0; prey < this->numPreys(); prey++) {
|
57 : |
|
|
if (this->getPrey(prey)->isPreyArea(area)) {
|
58 : |
|
|
(*predratio[inarea])[prey][predl] = tmp * preference[prey];
|
59 : |
|
|
if ((*predratio[inarea])[prey][predl] > 10.0) //JMB arbitrary value here ...
|
60 : |
|
|
handle.logMessage(LOGWARN, "Warning in effortpredator - excessive consumption required");
|
61 : |
|
|
for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
|
62 : |
|
|
(*cons[inarea][prey])[predl][preyl] = (*predratio[inarea])[prey][predl] *
|
63 : |
|
|
this->getSuitability(prey)[predl][preyl] * this->getPrey(prey)->getBiomass(area, preyl);
|
64 : |
|
|
totalcons[inarea][predl] += (*cons[inarea][prey])[predl][preyl];
|
65 : |
|
|
}
|
66 : |
|
|
//inform the preys of the consumption
|
67 : |
|
|
this->getPrey(prey)->addBiomassConsumption(area, (*cons[inarea][prey])[predl]);
|
68 : |
|
|
|
69 : |
|
|
} else {
|
70 : |
|
|
for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
|
71 : |
|
|
(*cons[inarea][prey])[predl][preyl] = 0.0;
|
72 : |
|
|
}
|
73 : |
|
|
}
|
74 : |
|
|
}
|
75 : |
|
|
|
76 : |
|
|
void EffortPredator::adjustConsumption(int area, const TimeClass* const TimeInfo) {
|
77 : |
|
|
int prey, preyl;
|
78 : |
|
|
int inarea = this->areaNum(area);
|
79 : |
|
|
int predl = 0; //JMB there is only ever one length group ...
|
80 : |
|
|
overcons[inarea][predl] = 0.0;
|
81 : |
|
|
|
82 : |
|
|
if (isZero(totalcons[inarea][predl])) //JMB no predation takes place on this timestep
|
83 : |
|
|
return;
|
84 : |
|
|
|
85 : |
|
|
double maxRatio, tmp;
|
86 : |
|
|
maxRatio = TimeInfo->getMaxRatioConsumed();
|
87 : |
|
|
|
88 : |
|
|
for (prey = 0; prey < this->numPreys(); prey++) {
|
89 : |
|
|
if (this->getPrey(prey)->isOverConsumption(area)) {
|
90 : |
|
|
hasoverconsumption[inarea] = 1;
|
91 : |
|
|
DoubleVector ratio = this->getPrey(prey)->getRatio(area);
|
92 : |
|
|
for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
|
93 : |
|
|
if (ratio[preyl] > maxRatio) {
|
94 : |
|
|
tmp = maxRatio / ratio[preyl];
|
95 : |
|
|
overcons[inarea][predl] += (1.0 - tmp) * (*cons[inarea][prey])[predl][preyl];
|
96 : |
|
|
(*cons[inarea][prey])[predl][preyl] *= tmp;
|
97 : |
|
|
(*usesuit[inarea][prey])[predl][preyl] *= tmp;
|
98 : |
|
|
}
|
99 : |
|
|
}
|
100 : |
|
|
}
|
101 : |
|
|
}
|
102 : |
|
|
|
103 : |
|
|
if (hasoverconsumption[inarea]) {
|
104 : |
|
|
totalcons[inarea][predl] -= overcons[inarea][predl];
|
105 : |
|
|
overconsumption[inarea][predl] += overcons[inarea][predl];
|
106 : |
|
|
}
|
107 : |
|
|
|
108 : |
|
|
totalconsumption[inarea][predl] += totalcons[inarea][predl];
|
109 : |
|
|
for (prey = 0; prey < this->numPreys(); prey++)
|
110 : |
|
|
if (this->getPrey(prey)->isPreyArea(area))
|
111 : |
|
|
for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
|
112 : |
|
|
(*consumption[inarea][prey])[predl][preyl] += (*cons[inarea][prey])[predl][preyl];
|
113 : |
|
|
}
|
114 : |
|
|
|
115 : |
|
|
void EffortPredator::Print(ofstream& outfile) const {
|
116 : |
|
|
outfile << "EffortPredator\n";
|
117 : |
|
|
PopPredator::Print(outfile);
|
118 : |
|
|
}
|