Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/totalpredator.cc
[mareframe] / trunk / gadget / totalpredator.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/totalpredator.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "totalpredator.h"
2 :     #include "keeper.h"
3 :     #include "prey.h"
4 :     #include "errorhandler.h"
5 :     #include "gadget.h"
6 :     #include "global.h"
7 :    
8 :     TotalPredator::TotalPredator(CommentStream& infile, const char* givenname,
9 :     const IntVector& Areas, const TimeClass* const TimeInfo, Keeper* const keeper, Formula multscaler)
10 :     : LengthPredator(givenname, Areas, keeper, multscaler) {
11 :    
12 :     type = TOTALPREDATOR;
13 :     keeper->addString("predator");
14 :     keeper->addString(givenname);
15 :     this->readSuitability(infile, TimeInfo, keeper);
16 :     keeper->clearLast();
17 :     keeper->clearLast();
18 :     }
19 :    
20 :     void TotalPredator::Eat(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
21 :    
22 :     int inarea = this->areaNum(area);
23 :     int prey, preyl;
24 :     double tmp, wanttoeat;
25 :     int predl = 0; //JMB there is only ever one length group ...
26 :     wanttoeat = prednumber[inarea][predl].N * multi / TimeInfo->numSubSteps();
27 :     totalcons[inarea][predl] = 0.0;
28 :    
29 :     if (isZero(wanttoeat)) //JMB no predation takes place on this timestep
30 :     return;
31 :    
32 :     //calculate consumption up to a multiplicative constant
33 :     for (prey = 0; prey < this->numPreys(); prey++) {
34 :     if (this->getPrey(prey)->isPreyArea(area)) {
35 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
36 :     (*cons[inarea][prey])[predl][preyl]
37 :     = this->getSuitability(prey)[predl][preyl] * this->getPrey(prey)->getBiomass(area, preyl);
38 :     totalcons[inarea][predl] += (*cons[inarea][prey])[predl][preyl];
39 :     }
40 :     } else {
41 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
42 :     (*cons[inarea][prey])[predl][preyl] = 0.0;
43 :     }
44 :     }
45 :    
46 :     //adjust the consumption by the multiplicative factor
47 :     if (!(isZero(totalcons[inarea][predl]))) {
48 :     tmp = wanttoeat / totalcons[inarea][predl];
49 :     for (prey = 0; prey < this->numPreys(); prey++) {
50 :     if (this->getPrey(prey)->isPreyArea(area)) {
51 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
52 :     (*cons[inarea][prey])[predl][preyl] *= tmp;
53 :    
54 :     //inform the preys of the consumption
55 :     this->getPrey(prey)->addBiomassConsumption(area, (*cons[inarea][prey])[predl]);
56 :     //set the multiplicative constant
57 :     (*predratio[inarea])[prey][predl] += totalcons[inarea][predl];
58 :     if ((TimeInfo->getSubStep() == TimeInfo->numSubSteps()) && (!(isZero((*predratio[inarea])[prey][predl]))))
59 :     (*predratio[inarea])[prey][predl] = wanttoeat / (*predratio[inarea])[prey][predl];
60 :     }
61 :     }
62 :     }
63 :    
64 :     //finally set totalcons to the actual consumption
65 :     totalcons[inarea][predl] = wanttoeat;
66 :     }
67 :    
68 :     void TotalPredator::adjustConsumption(int area, const TimeClass* const TimeInfo) {
69 :     int check, prey, preyl;
70 :     int inarea = this->areaNum(area);
71 :     int predl = 0; //JMB there is only ever one length group ...
72 :     overcons[inarea][predl] = 0.0;
73 :    
74 :     if (isZero(totalcons[inarea][predl])) //JMB no predation takes place on this timestep
75 :     return;
76 :    
77 :     double maxRatio, tmp;
78 :     maxRatio = TimeInfo->getMaxRatioConsumed();
79 :    
80 :     check = 0;
81 :     for (prey = 0; prey < this->numPreys(); prey++) {
82 :     if (this->getPrey(prey)->isPreyArea(area)) {
83 :     check = 1;
84 :     if (this->getPrey(prey)->isOverConsumption(area)) {
85 :     hasoverconsumption[inarea] = 1;
86 :     DoubleVector ratio = this->getPrey(prey)->getRatio(area);
87 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
88 :     if (ratio[preyl] > maxRatio) {
89 :     tmp = maxRatio / ratio[preyl];
90 :     overcons[inarea][predl] += (1.0 - tmp) * (*cons[inarea][prey])[predl][preyl];
91 :     (*cons[inarea][prey])[predl][preyl] *= tmp;
92 :     (*usesuit[inarea][prey])[predl][preyl] *= tmp;
93 :     }
94 :     }
95 :     }
96 :     }
97 :     }
98 :    
99 :     if (!check) { //if no prey found to consume then overcons set to actual consumption
100 :     hasoverconsumption[inarea] = 1;
101 :     overcons[inarea][predl] = totalcons[inarea][predl];
102 :     }
103 :    
104 :     if (hasoverconsumption[inarea]) {
105 :     totalcons[inarea][predl] -= overcons[inarea][predl];
106 :     overconsumption[inarea][predl] += overcons[inarea][predl];
107 :     }
108 :    
109 :     totalconsumption[inarea][predl] += totalcons[inarea][predl];
110 :     for (prey = 0; prey < this->numPreys(); prey++)
111 :     if (this->getPrey(prey)->isPreyArea(area))
112 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
113 :     (*consumption[inarea][prey])[predl][preyl] += (*cons[inarea][prey])[predl][preyl];
114 :     }
115 :    
116 :     void TotalPredator::Print(ofstream& outfile) const {
117 :     outfile << "TotalPredator\n";
118 :     PopPredator::Print(outfile);
119 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge