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

Annotation of /trunk/gadget/stockmemberfunctions.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "stock.h"
2 :     #include "keeper.h"
3 :     #include "areatime.h"
4 :     #include "naturalm.h"
5 :     #include "grower.h"
6 :     #include "stockprey.h"
7 :     #include "stockpredator.h"
8 :     #include "migration.h"
9 :     #include "maturity.h"
10 :     #include "renewal.h"
11 :     #include "transition.h"
12 :     #include "spawner.h"
13 :     #include "stray.h"
14 :     #include "errorhandler.h"
15 :     #include "gadget.h"
16 :     #include "global.h"
17 :    
18 :     void Stock::Migrate(const TimeClass* const TimeInfo) {
19 :     if (doesmigrate && migration->isMigrationStep(TimeInfo)) {
20 :     Alkeys.Migrate(migration->getMigrationMatrix(TimeInfo), tmpMigrate);
21 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
22 :     tagAlkeys.Migrate(migration->getMigrationMatrix(TimeInfo), Alkeys);
23 :     }
24 :     }
25 :    
26 :     //-------------------------------------------------------------------
27 :     //Sum up into Growth+Predator and Prey Lengthgroups. Storage is a
28 :     //vector of PopInfo that stores the sum over each lengthgroup.
29 :     void Stock::calcNumbers(int area, const TimeClass* const TimeInfo) {
30 :     int inarea = this->areaNum(area);
31 :     Alkeys[inarea].sumColumns(tmpPopulation[inarea]);
32 :     if (doesgrow)
33 :     grower->Sum(tmpPopulation[inarea], area);
34 :     if (iseaten) {
35 :     prey->Sum(Alkeys[inarea], area);
36 :     if (istagged) {
37 :     int i;
38 :     for (i = 0; i < allTags.Size(); i++)
39 :     allTags[i]->storeConsumptionALK(area, this->getName());
40 :     }
41 :     }
42 :     if (doeseat)
43 :     ((StockPredator*)predator)->Sum(Alkeys[inarea], area);
44 :     }
45 :    
46 :     //-------------------------------------------------------------------
47 :     void Stock::calcEat(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
48 :     if (doeseat)
49 :     predator->Eat(area, Area, TimeInfo);
50 :     }
51 :    
52 :     void Stock::checkEat(int area, const TimeClass* const TimeInfo) {
53 :     if (iseaten)
54 :     prey->checkConsumption(area, TimeInfo);
55 :     }
56 :    
57 :     void Stock::adjustEat(int area, const TimeClass* const TimeInfo) {
58 :     if (doeseat)
59 :     predator->adjustConsumption(area, TimeInfo);
60 :     }
61 :    
62 :     //-------------------------------------------------------------------
63 :     void Stock::reducePop(int area, const TimeClass* const TimeInfo) {
64 :     int inarea = this->areaNum(area);
65 :    
66 :     //Predation
67 :     if (iseaten)
68 :     prey->Subtract(Alkeys[inarea], area);
69 :    
70 :     //Natural mortality
71 :     if (TimeInfo->numSubSteps() == 1) {
72 :     Alkeys[inarea].Multiply(naturalm->getProportion(area));
73 :     } else {
74 :     //changed to include the possibility of substeps
75 :     DoubleVector* PropSurviving;
76 :     PropSurviving = new DoubleVector(naturalm->getProportion(area));
77 :     double timeratio = 1.0 / TimeInfo->numSubSteps();
78 :    
79 :     int i;
80 :     for (i = 0; i < PropSurviving->Size(); i++)
81 :     (*PropSurviving)[i] = pow((*PropSurviving)[i], timeratio);
82 :    
83 :     Alkeys[inarea].Multiply(*PropSurviving);
84 :     delete PropSurviving;
85 :     }
86 :    
87 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
88 :     tagAlkeys[inarea].updateAndTagLoss(Alkeys[inarea], tagAlkeys.getTagLoss());
89 :     }
90 :    
91 :     //-----------------------------------------------------------------------
92 :     //Function that updates the length distributions and makes part of the stock Mature.
93 :     void Stock::Grow(int area, const AreaClass* const Area, const TimeClass* const TimeInfo) {
94 :    
95 :     if (!doesgrow)
96 :     return;
97 :    
98 :     if (doeseat)
99 :     grower->calcGrowth(area, Area, TimeInfo, ((StockPredator*)predator)->getFPhi(area),
100 :     ((StockPredator*)predator)->getMaxConsumption(area));
101 :     else
102 :     grower->calcGrowth(area, Area, TimeInfo);
103 :    
104 :     int inarea = this->areaNum(area);
105 :     if (grower->getFixedWeights()) {
106 :     //Weights at length are fixed to the value in the input file
107 :     grower->implementGrowth(area, LgrpDiv);
108 :     if (doesmature && maturity->isMaturationStep(TimeInfo))
109 :     Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area), maturity, area);
110 :     else
111 :     Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area));
112 :    
113 :     } else {
114 :     //New weights at length are calculated
115 :     grower->implementGrowth(area, tmpPopulation[inarea], LgrpDiv);
116 :     if (doesmature && maturity->isMaturationStep(TimeInfo))
117 :     Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area), maturity, area);
118 :     else
119 :     Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area));
120 :     }
121 :    
122 :     if (istagged && tagAlkeys.numTagExperiments() > 0) {
123 :     if (doesmature && maturity->isMaturationStep(TimeInfo))
124 :     tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea], maturity, area);
125 :     else
126 :     tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea]);
127 :     }
128 :     }
129 :    
130 :     //-----------------------------------------------------------------------
131 :     //A number of Special functions, Spawning, Renewal, Maturation and
132 :     //Transition to other Stocks, Maturity due to age and increased age.
133 :     void Stock::updateAgePart1(int area, const TimeClass* const TimeInfo) {
134 :     if (doesmove && transition->isTransitionStep(TimeInfo)) {
135 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
136 :     transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
137 :     else
138 :     transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], TimeInfo);
139 :     }
140 :     }
141 :    
142 :     void Stock::updateAgePart2(int area, const TimeClass* const TimeInfo) {
143 :     if (this->isBirthday(TimeInfo)) {
144 :     Alkeys[this->areaNum(area)].IncrementAge();
145 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
146 :     tagAlkeys[this->areaNum(area)].IncrementAge(Alkeys[this->areaNum(area)]);
147 :     }
148 :     }
149 :    
150 :     void Stock::updateAgePart3(int area, const TimeClass* const TimeInfo) {
151 :     if (doesmove && transition->isTransitionStep(TimeInfo)) {
152 :     if (istagged && transitionTags.Size() > 0) {
153 :     int i;
154 :     for (i = 0; i < transitionTags.Size(); i++)
155 :     transitionTags[i]->updateTransitionStock(TimeInfo);
156 :     transitionTags.deleteAll();
157 :     }
158 :     transition->Move(area, TimeInfo);
159 :     }
160 :    
161 :     //JMB - only update the ratio for the tagged stock after all other age updates
162 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
163 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
164 :     }
165 :    
166 :     void Stock::updatePopulationPart1(int area, const TimeClass* const TimeInfo) {
167 :     if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo)) {
168 :     spawner->Spawn(Alkeys[this->areaNum(area)], area, TimeInfo);
169 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
170 :     tagAlkeys[this->areaNum(area)].updateNumbers(Alkeys[this->areaNum(area)]);
171 :     }
172 :     }
173 :    
174 :     void Stock::updatePopulationPart2(int area, const TimeClass* const TimeInfo) {
175 :     if (doesmature && maturity->isMaturationStep(TimeInfo)) {
176 :     if (istagged && matureTags.Size() > 0) {
177 :     int i;
178 :     for (i = 0; i < matureTags.Size(); i++)
179 :     matureTags[i]->updateMatureStock(TimeInfo);
180 :     matureTags.deleteAll();
181 :     }
182 :     maturity->Move(area, TimeInfo);
183 :     }
184 :     }
185 :    
186 :     void Stock::updatePopulationPart3(int area, const TimeClass* const TimeInfo) {
187 :     if (doesrenew && renewal->isRenewalStepArea(area, TimeInfo))
188 :     renewal->addRenewal(Alkeys[this->areaNum(area)], area, TimeInfo);
189 :    
190 :     if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo))
191 :     spawner->addSpawnStock(area, TimeInfo);
192 :     }
193 :    
194 :     void Stock::updatePopulationPart4(int area, const TimeClass* const TimeInfo) {
195 :     if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
196 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
197 :     stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
198 :     else
199 :     stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], TimeInfo);
200 :     }
201 :     }
202 :    
203 :     void Stock::updatePopulationPart5(int area, const TimeClass* const TimeInfo) {
204 :     if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
205 :     if (istagged && strayTags.Size() > 0) {
206 :     int i;
207 :     for (i = 0; i < strayTags.Size(); i++)
208 :     strayTags[i]->updateStrayStock(TimeInfo);
209 :     strayTags.deleteAll();
210 :     }
211 :     stray->addStrayStock(area, TimeInfo);
212 :     }
213 :    
214 :     //JMB - only update the ratio for the tagged stock after all other population updates
215 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
216 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
217 :     }
218 :    
219 :     void Stock::Add(const AgeBandMatrix& Addition,
220 :     const ConversionIndex* const CI, int area, double ratio) {
221 :    
222 :     Alkeys[this->areaNum(area)].Add(Addition, *CI, ratio);
223 :     }
224 :    
225 :     void Stock::Add(const AgeBandMatrixRatioPtrVector& Addition,
226 :     const ConversionIndex* const CI, int area, double ratio) {
227 :    
228 :     if (!istagged)
229 :     return;
230 :    
231 :     if ((Addition.numTagExperiments() > 0) && (Addition.numTagExperiments() <= tagAlkeys.numTagExperiments())) {
232 :     tagAlkeys.Add(Addition, this->areaNum(area), *CI, ratio);
233 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
234 :     }
235 :     }
236 :    
237 :     void Stock::addTags(AgeBandMatrixPtrVector* tagbyagelength, Tags* newtag, double tagloss) {
238 :    
239 :     if (!istagged)
240 :     return;
241 :    
242 :     tagAlkeys.addTag(tagbyagelength, Alkeys, newtag->getName(), tagloss);
243 :     allTags.resize(newtag);
244 :     if (doesmature) {
245 :     maturity->addMaturityTag(newtag->getName());
246 :     matureTags.resize(newtag);
247 :     }
248 :     if (doesmove) {
249 :     transition->addTransitionTag(newtag->getName());
250 :     transitionTags.resize(newtag);
251 :     }
252 :     if (doesstray) {
253 :     stray->addStrayTag(newtag->getName());
254 :     strayTags.resize(newtag);
255 :     }
256 :     }
257 :    
258 :     void Stock::deleteTags(const char* tagname) {
259 :    
260 :     if (!istagged)
261 :     return;
262 :    
263 :     allTags.Delete(tagAlkeys.getTagID(tagname));
264 :     tagAlkeys.deleteTag(tagname);
265 :     if (doesmature)
266 :     maturity->deleteMaturityTag(tagname);
267 :     if (doesmove)
268 :     transition->deleteTransitionTag(tagname);
269 :     if (doesstray)
270 :     stray->deleteStrayTag(tagname);
271 :     }
272 :    
273 :     double Stock::getTotalStockNumber(int area) const {
274 :     int inarea = this->areaNum(area);
275 :     if (inarea == -1)
276 :     return 0.0;
277 :    
278 :     int age, len;
279 :     double num = 0.0;
280 :     for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
281 :     for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
282 :     num += (Alkeys[inarea])[age][len].N;
283 :    
284 :     return num;
285 :     }
286 :    
287 :     double Stock::getTotalStockNumberAllAreas() const {
288 :     int a;
289 :     double sum = 0.0;
290 :     for (a = 0; a <= Alkeys.Size(); a++)
291 :     sum += this->getTotalStockNumber(a);
292 :    
293 :     return sum;
294 :     }
295 :    
296 :     double Stock::getTotalStockBiomass(int area) const {
297 :     int inarea = this->areaNum(area);
298 :     if (inarea == -1)
299 :     return 0.0;
300 :    
301 :     int age, len;
302 :     double kilos = 0.0;
303 :     for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
304 :     for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
305 :     kilos += ((Alkeys[inarea])[age][len].N * (Alkeys[inarea])[age][len].W);
306 :    
307 :     return kilos;
308 :     }
309 :    
310 :     double Stock::getTotalStockBiomassAllAreas() const {
311 :     int a;
312 :     double sum = 0.0;
313 :     for (a = 0; a <= Alkeys.Size(); a++)
314 :     sum += this->getTotalStockBiomass(a);
315 :    
316 :     return sum;
317 :     }

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

Powered By FusionForge