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 1 - (view) (download)

1 : agomez 1 #include "maturity.h"
2 :     #include "grower.h"
3 :     #include "agebandmatrix.h"
4 :     #include "gadget.h"
5 :    
6 :     /* Update the agebandmatrix to reflect the calculated growth */
7 :     /* Lgrowth contains the ratio of each length group that grows */
8 :     /* by a certain number of length groups, and Wgrowth contains */
9 :     /* the weight increase for each entry in Lgrowth */
10 :    
11 :     /* JMB changed to deal with very small weights a bit better */
12 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleMatrix& Wgrowth) {
13 :     int i, lgrp, grow, maxlgrp;
14 :     double num, wt, tmp;
15 :    
16 :     maxlgrp = Lgrowth.Nrow();
17 :     for (i = 0; i < nrow; i++) {
18 :     //the part that grows to or above the highest length group
19 :     num = 0.0;
20 :     wt = 0.0;
21 :     for (lgrp = v[i]->maxCol() - 1; lgrp >= v[i]->maxCol() - maxlgrp; lgrp--) {
22 :     for (grow = v[i]->maxCol() - lgrp - 1; grow < maxlgrp; grow++) {
23 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
24 :     num += tmp;
25 :     wt += tmp * (Wgrowth[grow][lgrp] + (*v[i])[lgrp].W);
26 :     }
27 :     }
28 :    
29 :     lgrp = v[i]->maxCol() - 1;
30 :     if (isZero(num) || (wt < verysmall)) {
31 :     (*v[i])[lgrp].setToZero();
32 :     } else {
33 :     (*v[i])[lgrp].W = wt / num;
34 :     (*v[i])[lgrp].N = num;
35 :     }
36 :    
37 :     //the central diagonal part of the length division
38 :     for (lgrp = v[i]->maxCol() - 2; lgrp >= v[i]->minCol() + maxlgrp - 1; lgrp--) {
39 :     num = 0.0;
40 :     wt = 0.0;
41 :     for (grow = 0; grow < maxlgrp; grow++) {
42 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
43 :     num += tmp;
44 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
45 :     }
46 :    
47 :     if (isZero(num) || (wt < verysmall)) {
48 :     (*v[i])[lgrp].setToZero();
49 :     } else {
50 :     (*v[i])[lgrp].W = wt / num;
51 :     (*v[i])[lgrp].N = num;
52 :     }
53 :     }
54 :    
55 :     //the lowest part of the length division
56 :     for (lgrp = v[i]->minCol() + maxlgrp - 2; lgrp >= v[i]->minCol(); lgrp--) {
57 :     num = 0.0;
58 :     wt = 0.0;
59 :     for (grow = 0; grow <= lgrp - v[i]->minCol(); grow++) {
60 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
61 :     num += tmp;
62 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
63 :     }
64 :    
65 :     if (isZero(num) || (wt < verysmall)) {
66 :     (*v[i])[lgrp].setToZero();
67 :     } else {
68 :     (*v[i])[lgrp].W = wt / num;
69 :     (*v[i])[lgrp].N = num;
70 :     }
71 :     }
72 :     }
73 :     }
74 :    
75 :     //Same program with certain num of fish made mature.
76 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleMatrix& Wgrowth, Maturity* const Mat, int area) {
77 :    
78 :     int i, lgrp, grow, maxlgrp, age;
79 :     double num, wt, matnum, tmp, ratio;
80 :    
81 :     maxlgrp = Lgrowth.Nrow();
82 :     for (i = 0; i < nrow; i++) {
83 :     age = i + minage;
84 :     num = 0.0;
85 :     wt = 0.0;
86 :     matnum = 0.0;
87 :     for (lgrp = v[i]->maxCol() - 1; lgrp >= v[i]->maxCol() - maxlgrp; lgrp--) {
88 :     for (grow = v[i]->maxCol() - lgrp - 1; grow < maxlgrp; grow++) {
89 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp].W);
90 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
91 :     matnum += (tmp * ratio);
92 :     num += tmp;
93 :     wt += tmp * (Wgrowth[grow][lgrp] + (*v[i])[lgrp].W);
94 :     }
95 :     }
96 :    
97 :     lgrp = v[i]->maxCol() - 1;
98 :     if (isZero(num) || (wt < verysmall)) {
99 :     //no fish grow to this length cell
100 :     (*v[i])[lgrp].setToZero();
101 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
102 :     } else if (isZero(matnum)) {
103 :     //none of the fish that grow to this length cell mature
104 :     (*v[i])[lgrp].W = wt / num;
105 :     (*v[i])[lgrp].N = num;
106 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
107 :     } else if (isEqual(num, matnum) || (matnum > num)) {
108 :     //all the fish that grow to this length cell mature
109 :     (*v[i])[lgrp].setToZero();
110 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
111 :     } else {
112 :     (*v[i])[lgrp].W = wt / num;
113 :     (*v[i])[lgrp].N = num - matnum;
114 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
115 :     }
116 :    
117 :     for (lgrp = v[i]->maxCol() - 2; lgrp >= v[i]->minCol() + maxlgrp - 1; lgrp--) {
118 :     num = 0.0;
119 :     wt = 0.0;
120 :     matnum = 0.0;
121 :     for (grow = 0; grow < maxlgrp; grow++) {
122 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
123 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
124 :     matnum += (tmp * ratio);
125 :     num += tmp;
126 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
127 :     }
128 :    
129 :     if (isZero(num) || (wt < verysmall)) {
130 :     //no fish grow to this length cell
131 :     (*v[i])[lgrp].setToZero();
132 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
133 :     } else if (isZero(matnum)) {
134 :     //none of the fish that grow to this length cell mature
135 :     (*v[i])[lgrp].W = wt / num;
136 :     (*v[i])[lgrp].N = num;
137 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
138 :     } else if (isEqual(num, matnum) || (matnum > num)) {
139 :     //all the fish that grow to this length cell mature
140 :     (*v[i])[lgrp].setToZero();
141 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
142 :     } else {
143 :     (*v[i])[lgrp].W = wt / num;
144 :     (*v[i])[lgrp].N = num - matnum;
145 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
146 :     }
147 :     }
148 :    
149 :     for (lgrp = v[i]->minCol() + maxlgrp - 2; lgrp >= v[i]->minCol(); lgrp--) {
150 :     num = 0.0;
151 :     wt = 0.0;
152 :     matnum = 0.0;
153 :     for (grow = 0; grow <= lgrp - v[i]->minCol(); grow++) {
154 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
155 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
156 :     matnum += (tmp * ratio);
157 :     num += tmp;
158 :     wt += tmp * (Wgrowth[grow][lgrp - grow] + (*v[i])[lgrp - grow].W);
159 :     }
160 :    
161 :     if (isZero(num) || (wt < verysmall)) {
162 :     //no fish grow to this length cell
163 :     (*v[i])[lgrp].setToZero();
164 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
165 :     } else if (isZero(matnum)) {
166 :     //none of the fish that grow to this length cell mature
167 :     (*v[i])[lgrp].W = wt / num;
168 :     (*v[i])[lgrp].N = num;
169 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
170 :     } else if (isEqual(num, matnum) || (matnum > num)) {
171 :     //all the fish that grow to this length cell mature
172 :     (*v[i])[lgrp].setToZero();
173 :     Mat->storeMatureStock(area, age, lgrp, num, wt / num);
174 :     } else {
175 :     (*v[i])[lgrp].W = wt / num;
176 :     (*v[i])[lgrp].N = num - matnum;
177 :     Mat->storeMatureStock(area, age, lgrp, matnum, wt / num);
178 :     }
179 :     }
180 :     }
181 :     }
182 :    
183 :     //fleksibest formulation - weight read in from file (should be positive)
184 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleVector& Weight) {
185 :     int i, lgrp, grow, maxlgrp;
186 :     double num;
187 :    
188 :     maxlgrp = Lgrowth.Nrow();
189 :     for (i = 0; i < nrow; i++) {
190 :     num = 0.0;
191 :     for (lgrp = v[i]->maxCol() - 1; lgrp >= v[i]->maxCol() - maxlgrp; lgrp--)
192 :     for (grow = v[i]->maxCol() - lgrp - 1; grow < maxlgrp; grow++)
193 :     num += (Lgrowth[grow][lgrp] * (*v[i])[lgrp].N);
194 :    
195 :     lgrp = v[i]->maxCol() - 1;
196 :     if (isZero(num)) {
197 :     (*v[i])[lgrp].setToZero();
198 :     } else {
199 :     (*v[i])[lgrp].N = num;
200 :     (*v[i])[lgrp].W = Weight[lgrp];
201 :     }
202 :    
203 :     for (lgrp = v[i]->maxCol() - 2; lgrp >= v[i]->minCol() + maxlgrp - 1; lgrp--) {
204 :     num = 0.0;
205 :     for (grow = 0; grow < maxlgrp; grow++)
206 :     num += (Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N);
207 :    
208 :     if (isZero(num)) {
209 :     (*v[i])[lgrp].setToZero();
210 :     } else {
211 :     (*v[i])[lgrp].N = num;
212 :     (*v[i])[lgrp].W = Weight[lgrp];
213 :     }
214 :     }
215 :    
216 :     for (lgrp = v[i]->minCol() + maxlgrp - 2; lgrp >= v[i]->minCol(); lgrp--) {
217 :     num = 0.0;
218 :     for (grow = 0; grow <= lgrp - v[i]->minCol(); grow++)
219 :     num += (Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N);
220 :    
221 :     if (isZero(num)) {
222 :     (*v[i])[lgrp].setToZero();
223 :     } else {
224 :     (*v[i])[lgrp].N = num;
225 :     (*v[i])[lgrp].W = Weight[lgrp];
226 :     }
227 :     }
228 :     }
229 :     }
230 :    
231 :     //fleksibest formulation - weight read in from file (should be positive)
232 :     //Same program with certain num of fish made mature.
233 :     void AgeBandMatrix::Grow(const DoubleMatrix& Lgrowth, const DoubleVector& Weight, Maturity* const Mat, int area) {
234 :    
235 :     int i, lgrp, grow, maxlgrp, age;
236 :     double num, matnum, tmp, ratio;
237 :    
238 :     maxlgrp = Lgrowth.Nrow();
239 :     for (i = 0; i < nrow; i++) {
240 :     age = i + minage;
241 :     num = 0.0;
242 :     matnum = 0.0;
243 :     for (lgrp = v[i]->maxCol() - 1; lgrp >= v[i]->maxCol() - maxlgrp; lgrp--) {
244 :     for (grow = v[i]->maxCol() - lgrp - 1; grow < maxlgrp; grow++) {
245 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp].W);
246 :     tmp = Lgrowth[grow][lgrp] * (*v[i])[lgrp].N;
247 :     matnum += (tmp * ratio);
248 :     num += tmp;
249 :     }
250 :     }
251 :    
252 :     lgrp = v[i]->maxCol() - 1;
253 :     if (isZero(num)) {
254 :     //no fish grow to this length cell
255 :     (*v[i])[lgrp].setToZero();
256 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
257 :     } else if (isZero(matnum)) {
258 :     //none of the fish that grow to this length cell mature
259 :     (*v[i])[lgrp].W = Weight[lgrp];
260 :     (*v[i])[lgrp].N = num;
261 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
262 :     } else if (isEqual(num, matnum) || (matnum > num)) {
263 :     //all the fish that grow to this length cell mature
264 :     (*v[i])[lgrp].setToZero();
265 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
266 :     } else {
267 :     (*v[i])[lgrp].W = Weight[lgrp];
268 :     (*v[i])[lgrp].N = num - matnum;
269 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
270 :     }
271 :    
272 :     for (lgrp = v[i]->maxCol() - 2; lgrp >= v[i]->minCol() + maxlgrp - 1; lgrp--) {
273 :     num = 0.0;
274 :     matnum = 0.0;
275 :     for (grow = 0; grow < maxlgrp; grow++) {
276 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
277 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
278 :     matnum += (tmp * ratio);
279 :     num += tmp;
280 :     }
281 :    
282 :     if (isZero(num)) {
283 :     //no fish grow to this length cell
284 :     (*v[i])[lgrp].setToZero();
285 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
286 :     } else if (isZero(matnum)) {
287 :     //none of the fish that grow to this length cell mature
288 :     (*v[i])[lgrp].W = Weight[lgrp];
289 :     (*v[i])[lgrp].N = num;
290 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
291 :     } else if (isEqual(num, matnum) || (matnum > num)) {
292 :     //all the fish that grow to this length cell mature
293 :     (*v[i])[lgrp].setToZero();
294 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
295 :     } else {
296 :     (*v[i])[lgrp].W = Weight[lgrp];
297 :     (*v[i])[lgrp].N = num - matnum;
298 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
299 :     }
300 :     }
301 :    
302 :     for (lgrp = v[i]->minCol() + maxlgrp - 2; lgrp >= v[i]->minCol(); lgrp--) {
303 :     num = 0.0;
304 :     matnum = 0.0;
305 :     for (grow = 0; grow <= lgrp - v[i]->minCol(); grow++) {
306 :     ratio = Mat->calcMaturation(age, lgrp, grow, (*v[i])[lgrp - grow].W);
307 :     tmp = Lgrowth[grow][lgrp - grow] * (*v[i])[lgrp - grow].N;
308 :     matnum += (tmp * ratio);
309 :     num += tmp;
310 :     }
311 :    
312 :     if (isZero(num)) {
313 :     //no fish grow to this length cell
314 :     (*v[i])[lgrp].setToZero();
315 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
316 :     } else if (isZero(matnum)) {
317 :     //none of the fish that grow to this length cell mature
318 :     (*v[i])[lgrp].W = Weight[lgrp];
319 :     (*v[i])[lgrp].N = num;
320 :     Mat->storeMatureStock(area, age, lgrp, 0.0, 0.0);
321 :     } else if (isEqual(num, matnum) || (matnum > num)) {
322 :     //all the fish that grow to this length cell mature
323 :     (*v[i])[lgrp].setToZero();
324 :     Mat->storeMatureStock(area, age, lgrp, num, Weight[lgrp]);
325 :     } else {
326 :     (*v[i])[lgrp].W = Weight[lgrp];
327 :     (*v[i])[lgrp].N = num - matnum;
328 :     Mat->storeMatureStock(area, age, lgrp, matnum, Weight[lgrp]);
329 :     }
330 :     }
331 :     }
332 :     }

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

Powered By FusionForge