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/linearpredator.cc
[mareframe] / trunk / gadget / linearpredator.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/linearpredator.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "linearpredator.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 :     LinearPredator::LinearPredator(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 = LINEARPREDATOR;
14 :     keeper->addString("predator");
15 :     keeper->addString(givenname);
16 :     this->readSuitability(infile, TimeInfo, keeper);
17 :     keeper->clearLast();
18 :     keeper->clearLast();
19 :     }
20 :    
21 :     void LinearPredator::Eat(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
22 :    
23 :     int inarea = this->areaNum(area);
24 :     int prey, preyl;
25 :     int predl = 0; //JMB there is only ever one length group ...
26 :     totalcons[inarea][predl] = 0.0;
27 :    
28 :     double tmp;
29 :     tmp = prednumber[inarea][predl].N * multi * TimeInfo->getTimeStepSize() / TimeInfo->numSubSteps();
30 :     if (isZero(tmp)) //JMB no predation takes place on this timestep
31 :     return;
32 :     if (tmp > 10.0) //JMB arbitrary value here ...
33 :     handle.logMessage(LOGWARN, "Warning in linearpredator - excessive consumption required");
34 :    
35 :     for (prey = 0; prey < this->numPreys(); prey++) {
36 :     if (this->getPrey(prey)->isPreyArea(area)) {
37 :     (*predratio[inarea])[prey][predl] = tmp;
38 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
39 :     (*cons[inarea][prey])[predl][preyl] = (*predratio[inarea])[prey][predl] *
40 :     this->getSuitability(prey)[predl][preyl] * this->getPrey(prey)->getBiomass(area, preyl);
41 :     totalcons[inarea][predl] += (*cons[inarea][prey])[predl][preyl];
42 :     }
43 :     //inform the preys of the consumption
44 :     this->getPrey(prey)->addBiomassConsumption(area, (*cons[inarea][prey])[predl]);
45 :    
46 :     } else {
47 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
48 :     (*cons[inarea][prey])[predl][preyl] = 0.0;
49 :     }
50 :     }
51 :     }
52 :    
53 :     void LinearPredator::adjustConsumption(int area, const TimeClass* const TimeInfo) {
54 :     int prey, preyl;
55 :     int inarea = this->areaNum(area);
56 :     int predl = 0; //JMB there is only ever one length group ...
57 :     overcons[inarea][predl] = 0.0;
58 :    
59 :     if (isZero(totalcons[inarea][predl])) //JMB no predation takes place on this timestep
60 :     return;
61 :    
62 :     double maxRatio, tmp;
63 :     maxRatio = TimeInfo->getMaxRatioConsumed();
64 :    
65 :     for (prey = 0; prey < this->numPreys(); prey++) {
66 :     if (this->getPrey(prey)->isOverConsumption(area)) {
67 :     hasoverconsumption[inarea] = 1;
68 :     DoubleVector ratio = this->getPrey(prey)->getRatio(area);
69 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++) {
70 :     if (ratio[preyl] > maxRatio) {
71 :     tmp = maxRatio / ratio[preyl];
72 :     overcons[inarea][predl] += (1.0 - tmp) * (*cons[inarea][prey])[predl][preyl];
73 :     (*cons[inarea][prey])[predl][preyl] *= tmp;
74 :     (*usesuit[inarea][prey])[predl][preyl] *= tmp;
75 :     }
76 :     }
77 :     }
78 :     }
79 :    
80 :     if (hasoverconsumption[inarea]) {
81 :     totalcons[inarea][predl] -= overcons[inarea][predl];
82 :     overconsumption[inarea][predl] += overcons[inarea][predl];
83 :     }
84 :    
85 :     totalconsumption[inarea][predl] += totalcons[inarea][predl];
86 :     for (prey = 0; prey < this->numPreys(); prey++)
87 :     if (this->getPrey(prey)->isPreyArea(area))
88 :     for (preyl = 0; preyl < (*cons[inarea][prey])[predl].Size(); preyl++)
89 :     (*consumption[inarea][prey])[predl][preyl] += (*cons[inarea][prey])[predl][preyl];
90 :     }
91 :    
92 :     void LinearPredator::Print(ofstream& outfile) const {
93 :     outfile << "LinearPredator\n";
94 :     PopPredator::Print(outfile);
95 :     }

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

Powered By FusionForge