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 2 - (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 : ulcessvp 2 // ofstream outfile;
104 :     // outfile.open("aaa", ios::out);
105 :     // grower->getLengthIncrease_(area).Print(outfile);
106 :     // int a;
107 :     // cout << "3-----------------" << endl;
108 :     // cin >> a;
109 : agomez 1 int inarea = this->areaNum(area);
110 :     if (grower->getFixedWeights()) {
111 :     //Weights at length are fixed to the value in the input file
112 :     grower->implementGrowth(area, LgrpDiv);
113 : ulcessvp 2 //FIXME
114 :     // if (doesmature && maturity->isMaturationStep(TimeInfo))
115 :     // Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area), maturity, area);
116 :     // else
117 :     // Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeight(area));
118 : agomez 1
119 :     } else {
120 :     //New weights at length are calculated
121 : ulcessvp 2 // ofstream outfile1;
122 :     // outfile1.open("aaa", ios::out);
123 :     // grower->getLengthIncrease_(area).Print(outfile1);
124 :     // cout << "4-----------------" << endl;
125 :     // cin >> a;
126 : agomez 1 grower->implementGrowth(area, tmpPopulation[inarea], LgrpDiv);
127 : ulcessvp 2 // ofstream outfile2;
128 :     // outfile2.open("aaa", ios::out);
129 :     // grower->getLengthIncrease_(area).Print(outfile2);
130 :     // cout << "5-----------------" << endl;
131 :     // cin >> a;
132 : agomez 1 if (doesmature && maturity->isMaturationStep(TimeInfo))
133 : ulcessvp 2 {
134 :     //FIXME// Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area), maturity, area);
135 :     }
136 : agomez 1 else
137 : ulcessvp 2 Alkeys[inarea].Grow(grower->getLengthIncrease_(area), grower->getWeightIncrease_(area));
138 :     //Alkeys[inarea].Grow(grower->getLengthIncrease(area), grower->getWeightIncrease(area));
139 : agomez 1 }
140 :    
141 : ulcessvp 2 if (istagged && tagAlkeys.numTagExperiments() > 0) { //FIXME
142 :     // if (doesmature && maturity->isMaturationStep(TimeInfo))
143 :     // tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea], maturity, area);
144 :     // else
145 :     // tagAlkeys[inarea].Grow(grower->getLengthIncrease(area), Alkeys[inarea]);
146 : agomez 1 }
147 : ulcessvp 2
148 :    
149 : agomez 1 }
150 :    
151 :     //-----------------------------------------------------------------------
152 :     //A number of Special functions, Spawning, Renewal, Maturation and
153 :     //Transition to other Stocks, Maturity due to age and increased age.
154 :     void Stock::updateAgePart1(int area, const TimeClass* const TimeInfo) {
155 :     if (doesmove && transition->isTransitionStep(TimeInfo)) {
156 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
157 :     transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
158 :     else
159 :     transition->storeTransitionStock(area, Alkeys[this->areaNum(area)], TimeInfo);
160 :     }
161 :     }
162 :    
163 :     void Stock::updateAgePart2(int area, const TimeClass* const TimeInfo) {
164 :     if (this->isBirthday(TimeInfo)) {
165 :     Alkeys[this->areaNum(area)].IncrementAge();
166 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
167 :     tagAlkeys[this->areaNum(area)].IncrementAge(Alkeys[this->areaNum(area)]);
168 :     }
169 :     }
170 :    
171 :     void Stock::updateAgePart3(int area, const TimeClass* const TimeInfo) {
172 :     if (doesmove && transition->isTransitionStep(TimeInfo)) {
173 :     if (istagged && transitionTags.Size() > 0) {
174 :     int i;
175 :     for (i = 0; i < transitionTags.Size(); i++)
176 :     transitionTags[i]->updateTransitionStock(TimeInfo);
177 :     transitionTags.deleteAll();
178 :     }
179 :     transition->Move(area, TimeInfo);
180 :     }
181 :    
182 :     //JMB - only update the ratio for the tagged stock after all other age updates
183 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
184 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
185 :     }
186 :    
187 :     void Stock::updatePopulationPart1(int area, const TimeClass* const TimeInfo) {
188 :     if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo)) {
189 :     spawner->Spawn(Alkeys[this->areaNum(area)], area, TimeInfo);
190 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
191 :     tagAlkeys[this->areaNum(area)].updateNumbers(Alkeys[this->areaNum(area)]);
192 :     }
193 :     }
194 :    
195 :     void Stock::updatePopulationPart2(int area, const TimeClass* const TimeInfo) {
196 :     if (doesmature && maturity->isMaturationStep(TimeInfo)) {
197 :     if (istagged && matureTags.Size() > 0) {
198 :     int i;
199 :     for (i = 0; i < matureTags.Size(); i++)
200 :     matureTags[i]->updateMatureStock(TimeInfo);
201 :     matureTags.deleteAll();
202 :     }
203 :     maturity->Move(area, TimeInfo);
204 :     }
205 :     }
206 :    
207 :     void Stock::updatePopulationPart3(int area, const TimeClass* const TimeInfo) {
208 :     if (doesrenew && renewal->isRenewalStepArea(area, TimeInfo))
209 :     renewal->addRenewal(Alkeys[this->areaNum(area)], area, TimeInfo);
210 :    
211 :     if (doesspawn && spawner->isSpawnStepArea(area, TimeInfo))
212 :     spawner->addSpawnStock(area, TimeInfo);
213 :     }
214 :    
215 :     void Stock::updatePopulationPart4(int area, const TimeClass* const TimeInfo) {
216 :     if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
217 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
218 :     stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], tagAlkeys[this->areaNum(area)], TimeInfo);
219 :     else
220 :     stray->storeStrayingStock(area, Alkeys[this->areaNum(area)], TimeInfo);
221 :     }
222 :     }
223 :    
224 :     void Stock::updatePopulationPart5(int area, const TimeClass* const TimeInfo) {
225 :     if (doesstray && stray->isStrayStepArea(area, TimeInfo)) {
226 :     if (istagged && strayTags.Size() > 0) {
227 :     int i;
228 :     for (i = 0; i < strayTags.Size(); i++)
229 :     strayTags[i]->updateStrayStock(TimeInfo);
230 :     strayTags.deleteAll();
231 :     }
232 :     stray->addStrayStock(area, TimeInfo);
233 :     }
234 :    
235 :     //JMB - only update the ratio for the tagged stock after all other population updates
236 :     if (istagged && tagAlkeys.numTagExperiments() > 0)
237 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
238 :     }
239 :    
240 :     void Stock::Add(const AgeBandMatrix& Addition,
241 :     const ConversionIndex* const CI, int area, double ratio) {
242 :    
243 :     Alkeys[this->areaNum(area)].Add(Addition, *CI, ratio);
244 :     }
245 :    
246 :     void Stock::Add(const AgeBandMatrixRatioPtrVector& Addition,
247 :     const ConversionIndex* const CI, int area, double ratio) {
248 :    
249 :     if (!istagged)
250 :     return;
251 :    
252 :     if ((Addition.numTagExperiments() > 0) && (Addition.numTagExperiments() <= tagAlkeys.numTagExperiments())) {
253 :     tagAlkeys.Add(Addition, this->areaNum(area), *CI, ratio);
254 :     tagAlkeys[this->areaNum(area)].updateRatio(Alkeys[this->areaNum(area)]);
255 :     }
256 :     }
257 :    
258 :     void Stock::addTags(AgeBandMatrixPtrVector* tagbyagelength, Tags* newtag, double tagloss) {
259 :    
260 :     if (!istagged)
261 :     return;
262 :    
263 :     tagAlkeys.addTag(tagbyagelength, Alkeys, newtag->getName(), tagloss);
264 :     allTags.resize(newtag);
265 :     if (doesmature) {
266 :     maturity->addMaturityTag(newtag->getName());
267 :     matureTags.resize(newtag);
268 :     }
269 :     if (doesmove) {
270 :     transition->addTransitionTag(newtag->getName());
271 :     transitionTags.resize(newtag);
272 :     }
273 :     if (doesstray) {
274 :     stray->addStrayTag(newtag->getName());
275 :     strayTags.resize(newtag);
276 :     }
277 :     }
278 :    
279 :     void Stock::deleteTags(const char* tagname) {
280 :    
281 :     if (!istagged)
282 :     return;
283 :    
284 :     allTags.Delete(tagAlkeys.getTagID(tagname));
285 :     tagAlkeys.deleteTag(tagname);
286 :     if (doesmature)
287 :     maturity->deleteMaturityTag(tagname);
288 :     if (doesmove)
289 :     transition->deleteTransitionTag(tagname);
290 :     if (doesstray)
291 :     stray->deleteStrayTag(tagname);
292 :     }
293 :    
294 :     double Stock::getTotalStockNumber(int area) const {
295 :     int inarea = this->areaNum(area);
296 :     if (inarea == -1)
297 :     return 0.0;
298 :    
299 :     int age, len;
300 :     double num = 0.0;
301 :     for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
302 :     for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
303 :     num += (Alkeys[inarea])[age][len].N;
304 :    
305 :     return num;
306 :     }
307 :    
308 :     double Stock::getTotalStockNumberAllAreas() const {
309 :     int a;
310 :     double sum = 0.0;
311 :     for (a = 0; a <= Alkeys.Size(); a++)
312 :     sum += this->getTotalStockNumber(a);
313 :    
314 :     return sum;
315 :     }
316 :    
317 :     double Stock::getTotalStockBiomass(int area) const {
318 :     int inarea = this->areaNum(area);
319 :     if (inarea == -1)
320 :     return 0.0;
321 :    
322 :     int age, len;
323 :     double kilos = 0.0;
324 :     for (age = Alkeys[inarea].minAge(); age <= Alkeys[inarea].maxAge(); age++)
325 :     for (len = Alkeys[inarea].minLength(age); len < Alkeys[inarea].maxLength(age); len++)
326 :     kilos += ((Alkeys[inarea])[age][len].N * (Alkeys[inarea])[age][len].W);
327 :    
328 :     return kilos;
329 :     }
330 :    
331 :     double Stock::getTotalStockBiomassAllAreas() const {
332 :     int a;
333 :     double sum = 0.0;
334 :     for (a = 0; a <= Alkeys.Size(); a++)
335 :     sum += this->getTotalStockBiomass(a);
336 :    
337 :     return sum;
338 :     }

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

Powered By FusionForge