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

Annotation of /trunk/gadget/grow.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : agomez 1 #include "maturity.h"
2 :     #include "grower.h"
3 :     #include "agebandmatrix.h"
4 :     #include "gadget.h"
5 : ulcessvp 2 #include "doublematrix.h"
6 :     #include "matrix.h"
7 : agomez 1
8 :     /* Update the agebandmatrix to reflect the calculated growth */
9 :     /* Lgrowth contains the ratio of each length group that grows */
10 :     /* by a certain number of length groups, and Wgrowth contains */
11 :     /* the weight increase for each entry in Lgrowth */
12 :    
13 : ulcessvp 2
14 :     void AgeBandMatrix::Grow(const Matrix& Lgrowth, const Matrix& Wgrowth) {
15 :     int i, lgrp, grow, maxlgrp;
16 :     double num, wt, tmp;
17 :     // ofstream outfile;
18 :     // outfile.open("aaa", ios::out);
19 :     // _Lgrowth.Print(outfile);
20 :     // int a;
21 :     // cout << "1-----------------" << endl;
22 :     // cin >> a;
23 :    
24 :    
25 :     maxlgrp = Lgrowth.Nrow();
26 :    
27 :    
28 :     // double** lGrowth = ToMatrix(Lgrowth, maxlgrp, aux);
29 :     // double** wGrowth = ToMatrix(Wgrowth, maxlgrp, aux);
30 :    
31 :    
32 :     for (i = 0; i < nrow; i++) {
33 :     int maxCol = v[i]->maxCol();
34 :     int minCol = v[i]->minCol();
35 :     //the part that grows to or above the highest length group
36 :     num = 0.0;
37 :     wt = 0.0;
38 :    
39 :     for (lgrp = maxCol - 1; lgrp >= maxCol - maxlgrp; lgrp--) {
40 :     for (grow = maxCol - lgrp - 1; grow < maxlgrp; grow++) {
41 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
42 :     num += tmp;
43 :     wt += tmp * (Wgrowth[grow][lgrp] + (*v[i])[lgrp].W);
44 :     }
45 :     }
46 :     // cout << "wt1:" << wt << endl;
47 :    
48 :     lgrp = maxCol - 1;
49 :     if (isZero(num) || (wt < verysmall)) {
50 :     (*v[i])[lgrp].setToZero();
51 :     } else {
52 :     (*v[i])[lgrp].W = wt / num;
53 :     (*v[i])[lgrp].N = num;
54 :     }
55 :    
56 :    
57 :     //the central diagonal part of the length division
58 :     for (lgrp = maxCol - 2; lgrp >= minCol + maxlgrp - 1; lgrp--) {
59 :     num = 0.0;
60 :     wt = 0.0;
61 :     for (grow = 0; grow < maxlgrp; grow++) {
62 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
63 :     num += tmp;
64 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
65 :     }
66 :     // cout << "wt2:" << wt << endl;
67 :     if (isZero(num) || (wt < verysmall)) {
68 :     (*v[i])[lgrp].setToZero();
69 :     } else {
70 :     (*v[i])[lgrp].W = wt / num;
71 :     (*v[i])[lgrp].N = num;
72 :     }
73 :     }
74 :    
75 :    
76 :     //the lowest part of the length division
77 :     for (lgrp = minCol + maxlgrp - 2; lgrp >= minCol; lgrp--) {
78 :     num = 0.0;
79 :     wt = 0.0;
80 :     for (grow = 0; grow <= lgrp - minCol; grow++) {
81 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
82 :     num += tmp;
83 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
84 :     }
85 :    
86 :     if (isZero(num) || (wt < verysmall)) {
87 :     (*v[i])[lgrp].setToZero();
88 :     } else {
89 :     (*v[i])[lgrp].W = wt / num;
90 :     (*v[i])[lgrp].N = num;
91 :     }
92 :     }
93 :     // cout << "wt3:" << wt << endl;
94 :     }
95 :     }
96 :    
97 :    
98 :    
99 :    
100 :    
101 :    
102 :    
103 :    
104 :    
105 :     /********************************************************************************/
106 :    
107 : agomez 1 /* JMB changed to deal with very small weights a bit better */
108 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleMatrix& Wgrowth) {
109 :     int i, lgrp, grow, maxlgrp;
110 :     double num, wt, tmp;
111 :    
112 :     maxlgrp = Lgrowth.Nrow();
113 : ulcessvp 2
114 :     // double** lGrowth = ToMatrix(Lgrowth, maxlgrp, aux);
115 :     // double** wGrowth = ToMatrix(Wgrowth, maxlgrp, aux);
116 :    
117 :    
118 : agomez 1 for (i = 0; i < nrow; i++) {
119 : ulcessvp 2 int maxCol = v[i]->maxCol();
120 :     int minCol = v[i]->minCol();
121 : agomez 1 //the part that grows to or above the highest length group
122 :     num = 0.0;
123 :     wt = 0.0;
124 : ulcessvp 2
125 :     for (lgrp = maxCol - 1; lgrp >= maxCol - maxlgrp; lgrp--) {
126 :     for (grow = maxCol - lgrp - 1; grow < maxlgrp; grow++) {
127 : agomez 1 tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
128 :     num += tmp;
129 :     wt += tmp * (Wgrowth[grow][lgrp] + (*v[i])[lgrp].W);
130 :     }
131 :     }
132 :    
133 : ulcessvp 2 lgrp = maxCol - 1;
134 : agomez 1 if (isZero(num) || (wt < verysmall)) {
135 :     (*v[i])[lgrp].setToZero();
136 :     } else {
137 :     (*v[i])[lgrp].W = wt / num;
138 :     (*v[i])[lgrp].N = num;
139 :     }
140 :    
141 : ulcessvp 2
142 : agomez 1 //the central diagonal part of the length division
143 : ulcessvp 2 for (lgrp = maxCol - 2; lgrp >= minCol + maxlgrp - 1; lgrp--) {
144 : agomez 1 num = 0.0;
145 :     wt = 0.0;
146 :     for (grow = 0; grow < maxlgrp; grow++) {
147 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
148 :     num += tmp;
149 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
150 :     }
151 :    
152 :     if (isZero(num) || (wt < verysmall)) {
153 :     (*v[i])[lgrp].setToZero();
154 :     } else {
155 :     (*v[i])[lgrp].W = wt / num;
156 :     (*v[i])[lgrp].N = num;
157 :     }
158 :     }
159 :    
160 :     //the lowest part of the length division
161 : ulcessvp 2 for (lgrp = minCol + maxlgrp - 2; lgrp >= minCol; lgrp--) {
162 : agomez 1 num = 0.0;
163 :     wt = 0.0;
164 : ulcessvp 2 for (grow = 0; grow <= lgrp - minCol; grow++) {
165 : agomez 1 tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
166 :     num += tmp;
167 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
168 :     }
169 :    
170 :     if (isZero(num) || (wt < verysmall)) {
171 :     (*v[i])[lgrp].setToZero();
172 :     } else {
173 :     (*v[i])[lgrp].W = wt / num;
174 :     (*v[i])[lgrp].N = num;
175 :     }
176 :     }
177 :     }
178 :     }
179 :    
180 :     //Same program with certain num of fish made mature.
181 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleMatrix& Wgrowth, Maturity* const Mat, int area) {
182 :    
183 :     int i, lgrp, grow, maxlgrp, age;
184 :     double num, wt, matnum, tmp, ratio;
185 :    
186 : ulcessvp 2
187 : agomez 1 maxlgrp = Lgrowth.Nrow();
188 :     for (i = 0; i < nrow; i++) {
189 : ulcessvp 2 int maxCol = v[i]->maxCol();
190 :     int minCol = v[i]->minCol();
191 : agomez 1 age = i + minage;
192 :     num = 0.0;
193 :     wt = 0.0;
194 :     matnum = 0.0;
195 : ulcessvp 2 for (lgrp = maxCol - 1; lgrp >= maxCol - maxlgrp; lgrp--) {
196 :     for (grow = maxCol - lgrp - 1; grow < maxlgrp; grow++) {
197 : agomez 1 ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp].W);
198 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
199 :     matnum += (tmp * ratio);
200 :     num += tmp;
201 :     wt += tmp * (Wgrowth[grow][lgrp] + (*v[i])[lgrp].W);
202 :     }
203 :     }
204 :    
205 : ulcessvp 2 lgrp = maxCol - 1;
206 : agomez 1 if (isZero(num) || (wt < verysmall)) {
207 :     //no fish grow to this length cell
208 :     (*v[i])[lgrp].setToZero();
209 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
210 :     } else if (isZero(matnum)) {
211 :     //none of the fish that grow to this length cell mature
212 :     (*v[i])[lgrp].W = wt / num;
213 :     (*v[i])[lgrp].N = num;
214 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
215 :     } else if (isEqual(num, matnum) || (matnum > num)) {
216 :     //all the fish that grow to this length cell mature
217 :     (*v[i])[lgrp].setToZero();
218 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
219 :     } else {
220 :     (*v[i])[lgrp].W = wt / num;
221 :     (*v[i])[lgrp].N = num - matnum;
222 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
223 :     }
224 :    
225 : ulcessvp 2
226 :     for (lgrp = maxCol - 2; lgrp >= minCol + maxlgrp - 1; lgrp--) {
227 : agomez 1 num = 0.0;
228 :     wt = 0.0;
229 :     matnum = 0.0;
230 :     for (grow = 0; grow < maxlgrp; grow++) {
231 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
232 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
233 :     matnum += (tmp * ratio);
234 :     num += tmp;
235 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
236 :     }
237 :    
238 :     if (isZero(num) || (wt < verysmall)) {
239 :     //no fish grow to this length cell
240 :     (*v[i])[lgrp].setToZero();
241 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
242 :     } else if (isZero(matnum)) {
243 :     //none of the fish that grow to this length cell mature
244 :     (*v[i])[lgrp].W = wt / num;
245 :     (*v[i])[lgrp].N = num;
246 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
247 :     } else if (isEqual(num, matnum) || (matnum > num)) {
248 :     //all the fish that grow to this length cell mature
249 :     (*v[i])[lgrp].setToZero();
250 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
251 :     } else {
252 :     (*v[i])[lgrp].W = wt / num;
253 :     (*v[i])[lgrp].N = num - matnum;
254 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
255 :     }
256 :     }
257 :    
258 : ulcessvp 2 for (lgrp = minCol + maxlgrp - 2; lgrp >= minCol; lgrp--) {
259 : agomez 1 num = 0.0;
260 :     wt = 0.0;
261 :     matnum = 0.0;
262 : ulcessvp 2 for (grow = 0; grow <= lgrp - minCol; grow++) {
263 : agomez 1 ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
264 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
265 :     matnum += (tmp * ratio);
266 :     num += tmp;
267 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
268 :     }
269 :    
270 :     if (isZero(num) || (wt < verysmall)) {
271 :     //no fish grow to this length cell
272 :     (*v[i])[lgrp].setToZero();
273 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
274 :     } else if (isZero(matnum)) {
275 :     //none of the fish that grow to this length cell mature
276 :     (*v[i])[lgrp].W = wt / num;
277 :     (*v[i])[lgrp].N = num;
278 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
279 :     } else if (isEqual(num, matnum) || (matnum > num)) {
280 :     //all the fish that grow to this length cell mature
281 :     (*v[i])[lgrp].setToZero();
282 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
283 :     } else {
284 :     (*v[i])[lgrp].W = wt / num;
285 :     (*v[i])[lgrp].N = num - matnum;
286 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
287 :     }
288 :     }
289 :     }
290 :     }
291 :    
292 :     //fleksibest formulation - weight read in from file (should be positive)
293 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleVector& Weight) {
294 :     int i, lgrp, grow, maxlgrp;
295 :     double num;
296 :    
297 :     maxlgrp = Lgrowth.Nrow();
298 : ulcessvp 2
299 : agomez 1 for (i = 0; i < nrow; i++) {
300 : ulcessvp 2 int maxCol = v[i]->maxCol();
301 :     int minCol = v[i]->minCol();
302 : agomez 1 num = 0.0;
303 : ulcessvp 2 for (lgrp = maxCol - 1; lgrp >= maxCol - maxlgrp; lgrp--)
304 :     for (grow = maxCol - lgrp - 1; grow < maxlgrp; grow++)
305 : agomez 1 num += (Lgrowth[grow][lgrp] * (*v[i])[lgrp].N);
306 :    
307 : ulcessvp 2 lgrp = maxCol - 1;
308 : agomez 1 if (isZero(num)) {
309 :     (*v[i])[lgrp].setToZero();
310 :     } else {
311 :     (*v[i])[lgrp].N = num;
312 :     (*v[i])[lgrp].W = Weight[lgrp];
313 :     }
314 :    
315 : ulcessvp 2 for (lgrp = maxCol - 2; lgrp >= minCol + maxlgrp - 1; lgrp--) {
316 : agomez 1 num = 0.0;
317 :     for (grow = 0; grow < maxlgrp; grow++)
318 :     num += (Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N);
319 :    
320 :     if (isZero(num)) {
321 :     (*v[i])[lgrp].setToZero();
322 :     } else {
323 :     (*v[i])[lgrp].N = num;
324 :     (*v[i])[lgrp].W = Weight[lgrp];
325 :     }
326 :     }
327 :    
328 : ulcessvp 2 for (lgrp = minCol + maxlgrp - 2; lgrp >= minCol; lgrp--) {
329 : agomez 1 num = 0.0;
330 : ulcessvp 2 for (grow = 0; grow <= lgrp - minCol; grow++)
331 : agomez 1 num += (Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N);
332 :    
333 :     if (isZero(num)) {
334 :     (*v[i])[lgrp].setToZero();
335 :     } else {
336 :     (*v[i])[lgrp].N = num;
337 :     (*v[i])[lgrp].W = Weight[lgrp];
338 :     }
339 :     }
340 :     }
341 :     }
342 :    
343 :     //fleksibest formulation - weight read in from file (should be positive)
344 :     //Same program with certain num of fish made mature.
345 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleVector& Weight, Maturity* const Mat, int area) {
346 :    
347 :     int i, lgrp, grow, maxlgrp, age;
348 :     double num, matnum, tmp, ratio;
349 :    
350 :     maxlgrp = Lgrowth.Nrow();
351 : ulcessvp 2
352 : agomez 1 for (i = 0; i < nrow; i++) {
353 : ulcessvp 2 int maxCol = v[i]->maxCol();
354 :     int minCol = v[i]->minCol();
355 : agomez 1 age = i + minage;
356 :     num = 0.0;
357 :     matnum = 0.0;
358 : ulcessvp 2 for (lgrp = maxCol - 1; lgrp >= maxCol - maxlgrp; lgrp--) {
359 :     for (grow = maxCol - lgrp - 1; grow < maxlgrp; grow++) {
360 : agomez 1 ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp].W);
361 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
362 :     matnum += (tmp * ratio);
363 :     num += tmp;
364 :     }
365 :     }
366 :    
367 : ulcessvp 2 lgrp = maxCol - 1;
368 : agomez 1 if (isZero(num)) {
369 :     //no fish grow to this length cell
370 :     (*v[i])[lgrp].setToZero();
371 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
372 :     } else if (isZero(matnum)) {
373 :     //none of the fish that grow to this length cell mature
374 :     (*v[i])[lgrp].W = Weight[lgrp];
375 :     (*v[i])[lgrp].N = num;
376 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
377 :     } else if (isEqual(num, matnum) || (matnum > num)) {
378 :     //all the fish that grow to this length cell mature
379 :     (*v[i])[lgrp].setToZero();
380 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
381 :     } else {
382 :     (*v[i])[lgrp].W = Weight[lgrp];
383 :     (*v[i])[lgrp].N = num - matnum;
384 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
385 :     }
386 :    
387 : ulcessvp 2 for (lgrp = maxCol - 2; lgrp >= minCol + maxlgrp - 1; lgrp--) {
388 : agomez 1 num = 0.0;
389 :     matnum = 0.0;
390 :     for (grow = 0; grow < maxlgrp; grow++) {
391 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
392 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
393 :     matnum += (tmp * ratio);
394 :     num += tmp;
395 :     }
396 :    
397 :     if (isZero(num)) {
398 :     //no fish grow to this length cell
399 :     (*v[i])[lgrp].setToZero();
400 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
401 :     } else if (isZero(matnum)) {
402 :     //none of the fish that grow to this length cell mature
403 :     (*v[i])[lgrp].W = Weight[lgrp];
404 :     (*v[i])[lgrp].N = num;
405 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
406 :     } else if (isEqual(num, matnum) || (matnum > num)) {
407 :     //all the fish that grow to this length cell mature
408 :     (*v[i])[lgrp].setToZero();
409 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
410 :     } else {
411 :     (*v[i])[lgrp].W = Weight[lgrp];
412 :     (*v[i])[lgrp].N = num - matnum;
413 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
414 :     }
415 :     }
416 :    
417 : ulcessvp 2 for (lgrp = minCol + maxlgrp - 2; lgrp >= minCol; lgrp--) {
418 : agomez 1 num = 0.0;
419 :     matnum = 0.0;
420 : ulcessvp 2 for (grow = 0; grow <= lgrp - minCol; grow++) {
421 : agomez 1 ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
422 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
423 :     matnum += (tmp * ratio);
424 :     num += tmp;
425 :     }
426 :    
427 :     if (isZero(num)) {
428 :     //no fish grow to this length cell
429 :     (*v[i])[lgrp].setToZero();
430 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
431 :     } else if (isZero(matnum)) {
432 :     //none of the fish that grow to this length cell mature
433 :     (*v[i])[lgrp].W = Weight[lgrp];
434 :     (*v[i])[lgrp].N = num;
435 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
436 :     } else if (isEqual(num, matnum) || (matnum > num)) {
437 :     //all the fish that grow to this length cell mature
438 :     (*v[i])[lgrp].setToZero();
439 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
440 :     } else {
441 :     (*v[i])[lgrp].W = Weight[lgrp];
442 :     (*v[i])[lgrp].N = num - matnum;
443 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
444 :     }
445 :     }
446 :     }
447 :     }

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

Powered By FusionForge