From 7b1cf8ddc067aaf6679bee47dea8f22c2a52e970 Mon Sep 17 00:00:00 2001 From: Christine Stawitz Date: Tue, 24 Oct 2023 18:33:25 +0000 Subject: [PATCH] Docs: run Doxygen --- docs/population_8hpp_source.html | 762 +++++++++++++------------ docs/rcpp__population_8hpp_source.html | 2 +- 2 files changed, 384 insertions(+), 380 deletions(-) diff --git a/docs/population_8hpp_source.html b/docs/population_8hpp_source.html index 319f93f..aac379c 100644 --- a/docs/population_8hpp_source.html +++ b/docs/population_8hpp_source.html @@ -253,428 +253,432 @@
233  inline void CalculateNumbersAA(size_t i_age_year, size_t i_agem1_yearm1,
234  size_t age) {
235  // using Z from previous age/year
-
236  this->numbers_at_age[i_age_year] = this->numbers_at_age[i_agem1_yearm1] *
-
237  (fims::exp(-this->mortality_Z[i_agem1_yearm1]));
-
238  FIMS_LOG << " z at i_agem1_yearm1 = " << i_agem1_yearm1 << " is "
-
239  << this->mortality_Z[i_agem1_yearm1] << std::endl;
-
240  // Plus group calculation
-
241  if (age == (this->nages - 1)) {
-
242  this->numbers_at_age[i_age_year] =
-
243  this->numbers_at_age[i_age_year] +
-
244  this->numbers_at_age[i_agem1_yearm1 + 1] *
-
245  (fims::exp(-this->mortality_Z[i_agem1_yearm1 + 1]));
-
246  }
-
247  }
-
248 
-
256  inline void CalculateUnfishedNumbersAA(size_t i_age_year, size_t i_agem1_yearm1,
-
257  size_t age) {
-
258  // using M from previous age/year
-
259  this->unfished_numbers_at_age[i_age_year] =
-
260  this->unfished_numbers_at_age[i_agem1_yearm1] *
-
261  (fims::exp(-this->M[i_agem1_yearm1]));
-
262  FIMS_LOG << "survival rate at index " << i_agem1_yearm1 << " is "
-
263  << fims::exp(-(this->M[i_agem1_yearm1])) << std::endl;
-
264  // Plus group calculation
-
265  if (age == (this->nages - 1)) {
-
266  this->unfished_numbers_at_age[i_age_year] =
-
267  this->unfished_numbers_at_age[i_age_year] +
-
268  this->unfished_numbers_at_age[i_agem1_yearm1 + 1] *
-
269  (fims::exp(-this->M[i_agem1_yearm1 + 1]));
-
270  }
-
271  }
-
272 
-
280  void CalculateBiomass(size_t i_age_year, size_t year, size_t age) {
-
281  this->biomass[year] +=
-
282  this->numbers_at_age[i_age_year] * growth->evaluate(ages[age]);
-
283  FIMS_LOG << " age " << ages[age] << std::endl;
-
284  FIMS_LOG << "growth evaluate: " << growth->evaluate(ages[age])
-
285  << " biomass inputs----- +++\n";
-
286  }
-
287 
-
296  void CalculateUnfishedBiomass(size_t i_age_year, size_t year, size_t age) {
-
297  this->unfished_biomass[year] += this->unfished_numbers_at_age[i_age_year] *
-
298  this->growth->evaluate(ages[age]);
-
299  }
-
300 
-
308  void CalculateSpawningBiomass(size_t i_age_year, size_t year, size_t age) {
-
309  this->spawning_biomass[year] +=
-
310  this->proportion_female * this->numbers_at_age[i_age_year] *
-
311  this->proportion_mature_at_age[i_age_year] * growth->evaluate(ages[age]);
-
312  FIMS_LOG << " proportion female " << this->proportion_female << " "
-
313  << " mature age " << age << " is "
-
314  << this->proportion_mature_at_age[i_age_year] << " "
-
315  << " numbers at age " << this->numbers_at_age[i_age_year] << " "
-
316  << " growth " << growth->evaluate(ages[age]) << " "
-
317  << " spawning biomass " << this->spawning_biomass[year] << " "
-
318  << " spawning biomass inputs----- +++\n";
-
319  }
-
320 
-
329  void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year,
-
330  size_t age) {
-
331  this->unfished_spawning_biomass[year] +=
-
332  this->proportion_female * this->unfished_numbers_at_age[i_age_year] *
-
333  this->proportion_mature_at_age[i_age_year] *
-
334  this->growth->evaluate(ages[age]);
-
335  }
-
336 
-
342  Type CalculateSBPR0() {
-
343  std::vector<Type> numbers_spr(this->nages, 1.0);
-
344  Type phi_0 = 0.0;
-
345  phi_0 += numbers_spr[0] * this->proportion_female *
-
346  this->proportion_mature_at_age[0] *
-
347  this->growth->evaluate(ages[0]);
-
348  for (size_t a = 1; a < (this->nages - 1); a++) {
-
349  numbers_spr[a] = numbers_spr[a - 1] * fims::exp(-this->M[a]);
-
350  phi_0 += numbers_spr[a] * this->proportion_female *
-
351  this->proportion_mature_at_age[a] *
-
352  this->growth->evaluate(ages[a]);
-
353  }
-
354 
-
355  numbers_spr[this->nages - 1] =
-
356  (numbers_spr[nages - 2] * fims::exp(-this->M[nages - 2])) /
-
357  (1 - fims::exp(-this->M[this->nages - 1]));
-
358  phi_0 += numbers_spr[this->nages - 1] * this->proportion_female *
-
359  this->proportion_mature_at_age[this->nages - 1] *
-
360  this->growth->evaluate(ages[this->nages - 1]);
-
361  return phi_0;
-
362  }
-
363 
-
370  void CalculateRecruitment(size_t i_age_year, size_t year) {
-
371  FIMS_LOG << "recruitment 1" << std::endl;
-
372  Type phi0 = CalculateSBPR0();
-
373  FIMS_LOG << "recruitment 2" << std::endl;
-
374  FIMS_LOG << "phi0 = " << phi0 << std::endl;
-
375  FIMS_LOG << "spawning biomass = " << this->spawning_biomass[year]
-
376  << std::endl;
-
377  FIMS_LOG << "rec devs = " << this->recruitment->recruit_deviations[year - 1]
+
236  this->numbers_at_age[i_age_year] =
+
237  this->numbers_at_age[i_agem1_yearm1] *
+
238  (fims::exp(-this->mortality_Z[i_agem1_yearm1]));
+
239  FIMS_LOG << " z at i_agem1_yearm1 = " << i_agem1_yearm1 << " is "
+
240  << this->mortality_Z[i_agem1_yearm1] << std::endl;
+
241  // Plus group calculation
+
242  if (age == (this->nages - 1)) {
+
243  this->numbers_at_age[i_age_year] =
+
244  this->numbers_at_age[i_age_year] +
+
245  this->numbers_at_age[i_agem1_yearm1 + 1] *
+
246  (fims::exp(-this->mortality_Z[i_agem1_yearm1 + 1]));
+
247  }
+
248  }
+
249 
+
257  inline void CalculateUnfishedNumbersAA(size_t i_age_year,
+
258  size_t i_agem1_yearm1, size_t age) {
+
259  // using M from previous age/year
+
260  this->unfished_numbers_at_age[i_age_year] =
+
261  this->unfished_numbers_at_age[i_agem1_yearm1] *
+
262  (fims::exp(-this->M[i_agem1_yearm1]));
+
263  FIMS_LOG << "survival rate at index " << i_agem1_yearm1 << " is "
+
264  << fims::exp(-(this->M[i_agem1_yearm1])) << std::endl;
+
265  // Plus group calculation
+
266  if (age == (this->nages - 1)) {
+
267  this->unfished_numbers_at_age[i_age_year] =
+
268  this->unfished_numbers_at_age[i_age_year] +
+
269  this->unfished_numbers_at_age[i_agem1_yearm1 + 1] *
+
270  (fims::exp(-this->M[i_agem1_yearm1 + 1]));
+
271  }
+
272  }
+
273 
+
281  void CalculateBiomass(size_t i_age_year, size_t year, size_t age) {
+
282  this->biomass[year] +=
+
283  this->numbers_at_age[i_age_year] * growth->evaluate(ages[age]);
+
284  FIMS_LOG << " age " << ages[age] << std::endl;
+
285  FIMS_LOG << "growth evaluate: " << growth->evaluate(ages[age])
+
286  << " biomass inputs----- +++\n";
+
287  }
+
288 
+
297  void CalculateUnfishedBiomass(size_t i_age_year, size_t year, size_t age) {
+
298  this->unfished_biomass[year] += this->unfished_numbers_at_age[i_age_year] *
+
299  this->growth->evaluate(ages[age]);
+
300  }
+
301 
+
309  void CalculateSpawningBiomass(size_t i_age_year, size_t year, size_t age) {
+
310  this->spawning_biomass[year] += this->proportion_female *
+
311  this->numbers_at_age[i_age_year] *
+
312  this->proportion_mature_at_age[i_age_year] *
+
313  growth->evaluate(ages[age]);
+
314  FIMS_LOG << " proportion female " << this->proportion_female << " "
+
315  << " mature age " << age << " is "
+
316  << this->proportion_mature_at_age[i_age_year] << " "
+
317  << " numbers at age " << this->numbers_at_age[i_age_year] << " "
+
318  << " growth " << growth->evaluate(ages[age]) << " "
+
319  << " spawning biomass " << this->spawning_biomass[year] << " "
+
320  << " spawning biomass inputs----- +++\n";
+
321  }
+
322 
+
331  void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year,
+
332  size_t age) {
+
333  this->unfished_spawning_biomass[year] +=
+
334  this->proportion_female * this->unfished_numbers_at_age[i_age_year] *
+
335  this->proportion_mature_at_age[i_age_year] *
+
336  this->growth->evaluate(ages[age]);
+
337  }
+
338 
+
344  Type CalculateSBPR0() {
+
345  std::vector<Type> numbers_spr(this->nages, 1.0);
+
346  Type phi_0 = 0.0;
+
347  phi_0 += numbers_spr[0] * this->proportion_female *
+
348  this->proportion_mature_at_age[0] *
+
349  this->growth->evaluate(ages[0]);
+
350  for (size_t a = 1; a < (this->nages - 1); a++) {
+
351  numbers_spr[a] = numbers_spr[a - 1] * fims::exp(-this->M[a]);
+
352  phi_0 += numbers_spr[a] * this->proportion_female *
+
353  this->proportion_mature_at_age[a] *
+
354  this->growth->evaluate(ages[a]);
+
355  }
+
356 
+
357  numbers_spr[this->nages - 1] =
+
358  (numbers_spr[nages - 2] * fims::exp(-this->M[nages - 2])) /
+
359  (1 - fims::exp(-this->M[this->nages - 1]));
+
360  phi_0 += numbers_spr[this->nages - 1] * this->proportion_female *
+
361  this->proportion_mature_at_age[this->nages - 1] *
+
362  this->growth->evaluate(ages[this->nages - 1]);
+
363  return phi_0;
+
364  }
+
365 
+
372  void CalculateRecruitment(size_t i_age_year, size_t year) {
+
373  FIMS_LOG << "recruitment 1" << std::endl;
+
374  Type phi0 = CalculateSBPR0();
+
375  FIMS_LOG << "recruitment 2" << std::endl;
+
376  FIMS_LOG << "phi0 = " << phi0 << std::endl;
+
377  FIMS_LOG << "spawning biomass = " << this->spawning_biomass[year]
378  << std::endl;
-
379  FIMS_LOG << "rec eval = "
-
380  << this->recruitment->evaluate(this->spawning_biomass[year - 1],
-
381  phi0)
-
382  << std::endl;
-
383  this->numbers_at_age[i_age_year] =
-
384  this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0) *
-
385  this->recruitment->recruit_deviations[year];
-
386  this->expected_recruitment[year] = this->numbers_at_age[i_age_year];
-
387  FIMS_LOG << " numbers at age at indexya " << i_age_year << " is "
-
388  << this->numbers_at_age[i_age_year] << std::endl;
-
389  }
-
390 
-
397  void CalculateCatch(size_t year, size_t age) {
-
398  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
-
399  if (this->fleets[fleet_]->is_survey == false) {
-
400  size_t index_yf = year * this->nfleets +
-
401  fleet_; // index by fleet and years to dimension fold
-
402  size_t i_age_year = year * this->nages + age;
-
403 
-
404  FIMS_LOG << " fleet " << fleet_ << " year " << year << " age " << age
-
405  << std::endl;
-
406  this->expected_catch[index_yf] +=
-
407  this->fleets[fleet_]->catch_weight_at_age[i_age_year];
-
408 
-
409  FIMS_LOG << "expected catch: " << this->expected_catch[index_yf]
-
410  << std::endl;
-
411  FIMS_LOG << "----------------------------------------------"
+
379  FIMS_LOG << "rec devs = " << this->recruitment->recruit_deviations[year - 1]
+
380  << std::endl;
+
381  FIMS_LOG << "rec eval = "
+
382  << this->recruitment->evaluate(this->spawning_biomass[year - 1],
+
383  phi0)
+
384  << std::endl;
+
385  this->numbers_at_age[i_age_year] =
+
386  this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0) *
+
387  this->recruitment->recruit_deviations[year];
+
388  this->expected_recruitment[year] = this->numbers_at_age[i_age_year];
+
389  FIMS_LOG << " numbers at age at indexya " << i_age_year << " is "
+
390  << this->numbers_at_age[i_age_year] << std::endl;
+
391  }
+
392 
+
399  void CalculateCatch(size_t year, size_t age) {
+
400  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
+
401  if (this->fleets[fleet_]->is_survey == false) {
+
402  size_t index_yf = year * this->nfleets +
+
403  fleet_; // index by fleet and years to dimension fold
+
404  size_t i_age_year = year * this->nages + age;
+
405 
+
406  FIMS_LOG << " fleet " << fleet_ << " year " << year << " age " << age
+
407  << std::endl;
+
408  this->expected_catch[index_yf] +=
+
409  this->fleets[fleet_]->catch_weight_at_age[i_age_year];
+
410 
+
411  FIMS_LOG << "expected catch: " << this->expected_catch[index_yf]
412  << std::endl;
-
413 
-
414  fleets[fleet_]->expected_catch[year] +=
-
415  this->fleets[fleet_]->catch_weight_at_age[i_age_year];
-
416  }
-
417  }
-
418  }
-
419 
-
427  void CalculateIndex(size_t i_age_year, size_t year, size_t age) {
-
428  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
-
429  Type index_;
-
430  // I = qN (N is total numbers), I is an index in numbers
-
431  if (this->fleets[fleet_]->is_survey == false) {
-
432  index_ = this->fleets[fleet_]->catch_numbers_at_age[i_age_year] *
-
433  growth->evaluate(ages[age]);
-
434  } else {
-
435  FIMS_LOG << "fleet " << fleet_ << " is a survey" << std::endl;
-
436  index_ = this->fleets[fleet_]->q *
-
437  this->fleets[fleet_]->selectivity->evaluate(ages[age]) *
-
438  this->numbers_at_age[i_age_year] *
-
439  growth->evaluate(ages[age]); // this->weight_at_age[age];
-
440  }
-
441  fleets[fleet_]->expected_index[year] += index_;
-
442  FIMS_LOG << " expected index in year " << year << " is "
-
443  << fleets[fleet_]->expected_index[year] << std::endl;
-
444  }
-
445  }
-
446 
-
456  void CalculateCatchNumbersAA(size_t i_age_year, size_t year, size_t age) {
-
457  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
-
458  // make an intermediate value in order to set multiple members (of
-
459  // current and fleet objects) to that value.
-
460  Type catch_; // catch_ is used to avoid using the c++ keyword catch
-
461  // Baranov Catch Equation
-
462  if (this->fleets[fleet_]->is_survey == false) {
-
463  catch_ = (this->fleets[fleet_]->Fmort[year] *
-
464  this->fleets[fleet_]->selectivity->evaluate(ages[age])) /
-
465  this->mortality_Z[i_age_year] * this->numbers_at_age[i_age_year] *
-
466  (1 - fims::exp(-(this->mortality_Z[i_age_year])));
-
467  } else {
-
468  catch_ = (this->fleets[fleet_]->selectivity->evaluate(ages[age])) *
-
469  this->numbers_at_age[i_age_year];
-
470  }
-
471  FIMS_LOG << " F " << fleet_ << " " << this->fleets[fleet_]->Fmort[year]
-
472  << std::endl;
-
473  FIMS_LOG << " selectivity "
-
474  << this->fleets[fleet_]->selectivity->evaluate(ages[age])
+
413  FIMS_LOG << "----------------------------------------------"
+
414  << std::endl;
+
415 
+
416  fleets[fleet_]->expected_catch[year] +=
+
417  this->fleets[fleet_]->catch_weight_at_age[i_age_year];
+
418  }
+
419  }
+
420  }
+
421 
+
429  void CalculateIndex(size_t i_age_year, size_t year, size_t age) {
+
430  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
+
431  Type index_;
+
432  // I = qN (N is total numbers), I is an index in numbers
+
433  if (this->fleets[fleet_]->is_survey == false) {
+
434  index_ = this->fleets[fleet_]->catch_numbers_at_age[i_age_year] *
+
435  growth->evaluate(ages[age]);
+
436  } else {
+
437  FIMS_LOG << "fleet " << fleet_ << " is a survey" << std::endl;
+
438  index_ = this->fleets[fleet_]->q *
+
439  this->fleets[fleet_]->selectivity->evaluate(ages[age]) *
+
440  this->numbers_at_age[i_age_year] *
+
441  growth->evaluate(ages[age]); // this->weight_at_age[age];
+
442  }
+
443  fleets[fleet_]->expected_index[year] += index_;
+
444  FIMS_LOG << " expected index in year " << year << " is "
+
445  << fleets[fleet_]->expected_index[year] << std::endl;
+
446  }
+
447  }
+
448 
+
458  void CalculateCatchNumbersAA(size_t i_age_year, size_t year, size_t age) {
+
459  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
+
460  // make an intermediate value in order to set multiple members (of
+
461  // current and fleet objects) to that value.
+
462  Type catch_; // catch_ is used to avoid using the c++ keyword catch
+
463  // Baranov Catch Equation
+
464  if (this->fleets[fleet_]->is_survey == false) {
+
465  catch_ = (this->fleets[fleet_]->Fmort[year] *
+
466  this->fleets[fleet_]->selectivity->evaluate(ages[age])) /
+
467  this->mortality_Z[i_age_year] *
+
468  this->numbers_at_age[i_age_year] *
+
469  (1 - fims::exp(-(this->mortality_Z[i_age_year])));
+
470  } else {
+
471  catch_ = (this->fleets[fleet_]->selectivity->evaluate(ages[age])) *
+
472  this->numbers_at_age[i_age_year];
+
473  }
+
474  FIMS_LOG << " F " << fleet_ << " " << this->fleets[fleet_]->Fmort[year]
475  << std::endl;
-
476  FIMS_LOG << " catch " << catch_ << std::endl;
-
477  // this->catch_numbers_at_age[i_age_yearf] += catch_;
-
478  // catch_numbers_at_age for the fleet module has different
-
479  // dimensions (year/age, not year/fleet/age)
-
480  this->fleets[fleet_]->catch_numbers_at_age[i_age_year] += catch_;
-
481  }
-
482  }
-
483 
-
491  void CalculateCatchWeightAA(size_t year, size_t age) {
-
492  int i_age_year = year * this->nages + age;
-
493  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
-
494  FIMS_LOG << " fleet " << fleet_ << std::endl;
-
495  FIMS_LOG << " catchnaa "
-
496  << this->fleets[fleet_]->catch_numbers_at_age[year] << std::endl;
-
497  FIMS_LOG << " weight " << this->growth->evaluate(ages[age]) << std::endl;
-
498  this->fleets[fleet_]->catch_weight_at_age[i_age_year] =
-
499  this->fleets[fleet_]->catch_numbers_at_age[i_age_year] *
-
500  this->growth->evaluate(ages[age]); // this->weight_at_age[age];
-
501  FIMS_LOG << " catch_waa "
-
502  << this->fleets[fleet_]->catch_weight_at_age[i_age_year]
-
503  << std::endl;
-
504  }
-
505  }
-
506 
-
514  void CalculateMaturityAA(size_t i_age_year, size_t age) {
-
515  // this->maturity is pointing to the maturity module, which has
-
516  // an evaluate function. -> can be nested.
-
517  FIMS_LOG << " age " << age << std::endl;
-
518  FIMS_LOG << " ages size " << this->ages.size() << std::endl;
-
519  FIMS_LOG << " i_age_year " << i_age_year << std::endl;
-
520  FIMS_LOG << "p mature" << this->proportion_mature_at_age[i_age_year]
-
521  << std::endl;
-
522  FIMS_LOG << this->ages[age] << std::endl;
-
523  this->proportion_mature_at_age[i_age_year] =
-
524  this->maturity->evaluate(ages[age]);
-
525 
-
526  FIMS_LOG << "p mature set to " << this->proportion_mature_at_age[i_age_year]
-
527  << std::endl;
-
528  }
-
529 
-
534  void Evaluate() {
-
535  /*
-
536  Sets derived vectors to zero
-
537  Performs parameters transformations
-
538  Sets recruitment deviations to mean 0.
-
539  */
-
540  Prepare();
-
541  /*
-
542  start at year=0, age=0;
-
543  here year 0 is the estimated initial stock structure and age 0 are recruits
-
544  loops start at zero with if statements inside to specify unique code for
-
545  initial structure and recruitment 0 loops. Could also have started loops at
-
546  1 with initial structure and recruitment setup outside the loops.
-
547 
-
548  year loop is extended to <= nyears because SSB is calculted as the start of
-
549  the year value and by extending one extra year we get estimates of the
-
550  population structure at the end of the final year. An alternative approach
-
551  would be to keep initial numbers at age in it's own vector and each year to
-
552  include the population structure at the end of the year. This is likely a
-
553  null point given that we are planning to modify to an event/stanza based
-
554  structure in later milestones which will elimitate this confusion by
-
555  explicity referencing the exact date (or period of averaging) at which any
-
556  calculation or output is being made.
-
557  */
-
558  for (size_t y = 0; y <= this->nyears; y++) {
-
559  for (size_t a = 0; a < this->nages; a++) {
-
560  /*
-
561  index naming defines the dimensional folding structure
-
562  i.e. i_age_year is referencing folding over years and ages.
-
563  */
-
564  size_t i_age_year = y * this->nages + a;
-
565  /*
-
566  Mortality rates are not estimated in the final year which is
-
567  used to show expected stock structure at the end of the model period.
-
568  This is because biomass in year i represents biomass at the start of
-
569  the year.
-
570  Should we add complexity to track more values such as start,
-
571  mid, and end biomass in all years where, start biomass=end biomass of
-
572  the previous year? Referenced above, this is probably not worth
-
573  exploring as later milestone changes will eliminate this confusion.
-
574  */
-
575  if (y < this->nyears) {
-
576  /*
-
577  First thing we need is total mortality aggregated across all fleets
-
578  to inform the subsequent catch and change in numbers at age
-
579  calculations. This is only calculated for years < nyears as these are
-
580  the model estimated years with data. The year loop extends to
-
581  y=nyears so that population numbers at age and SSB can be calculated
-
582  at the end of the last year of the model
-
583  */
-
584  CalculateMortality(i_age_year, y, a);
-
585  }
-
586  CalculateMaturityAA(i_age_year, a);
-
587  /* if statements needed because some quantities are only needed
-
588  for the first year and/or age, so these steps are included here.
-
589  */
-
590  if (y == 0) {
-
591  // Initial numbers at age is a user input or estimated parameter
-
592  // vector.
-
593  CalculateInitialNumbersAA(i_age_year, a);
-
594 
-
595  if (a == 0) {
-
596  // this->numbers_at_age[i_age_year] = this->recruitment->rzero;
-
597  this->unfished_numbers_at_age[i_age_year] =
-
598  fims::exp(this->recruitment->log_rzero);
-
599  } else {
-
600  CalculateUnfishedNumbersAA(i_age_year, a - 1, a);
-
601  }
-
602 
-
603  /*
-
604  Fished and unfished biomass vectors are summing biomass at
-
605  age across ages.
-
606  */
-
607 
-
608  CalculateBiomass(i_age_year, y, a);
-
609 
-
610  CalculateUnfishedBiomass(i_age_year, y, a);
-
611 
-
612  /*
-
613  Fished and unfished spawning biomass vectors are summing biomass at
-
614  age across ages to allow calculation of recruitment in the next year.
-
615  */
-
616 
-
617  CalculateSpawningBiomass(i_age_year, y, a);
-
618 
-
619  CalculateUnfishedSpawningBiomass(i_age_year, y, a);
-
620 
-
621  /*
-
622  Expected recruitment in year 0 is numbers at age 0 in year 0.
-
623  */
-
624 
-
625  this->expected_recruitment[i_age_year] = this->numbers_at_age[i_age_year];
-
626 
-
627  } else {
-
628  if (a == 0) {
-
629  // Set the nrecruits for age a=0 year y (use pointers instead of
-
630  // functional returns) assuming fecundity = 1 and 50:50 sex ratio
-
631  FIMS_LOG << "Recruitment: " << std::endl;
-
632  CalculateRecruitment(i_age_year, y);
-
633  this->unfished_numbers_at_age[i_age_year] =
-
634  fims::exp(this->recruitment->log_rzero);
-
635 
-
636  } else {
-
637  size_t i_agem1_yearm1 = (y - 1) * nages + (a - 1);
-
638  CalculateNumbersAA(i_age_year, i_agem1_yearm1, a);
-
639  CalculateUnfishedNumbersAA(i_age_year, i_agem1_yearm1, a);
-
640  }
-
641  CalculateBiomass(i_age_year, y, a);
-
642  CalculateSpawningBiomass(i_age_year, y, a);
-
643 
-
644  FIMS_LOG << "index ya: " << i_age_year << std::endl;
-
645  CalculateUnfishedBiomass(i_age_year, y, a);
-
646  CalculateUnfishedSpawningBiomass(i_age_year, y, a);
-
647  }
-
648 
-
649  /*
-
650  Here composition, total catch, and index values are calculated for all
-
651  years with reference data. They are not calculated for y=nyears as there
-
652  is this is just to get final population structure at the end of the
-
653  terminal year.
-
654  */
-
655  if (y < this->nyears) {
-
656  FIMS_LOG << i_age_year << std::endl;
-
657  CalculateCatchNumbersAA(i_age_year, y, a);
-
658 
-
659  CalculateCatchWeightAA(y, a);
-
660  FIMS_LOG << "year " << y << " and age " << a << std::endl;
-
661  CalculateCatch(y, a);
-
662  CalculateIndex(i_age_year, y, a);
-
663  }
-
664  }
-
665  }
-
666  FIMS_LOG << "NAA\n";
-
667  for (size_t i = 0; i < nyears; i++) {
-
668  for (size_t j = 0; j < nages; j++) {
-
669  FIMS_LOG << numbers_at_age[i * nages + j] << "\t";
-
670  }
-
671  FIMS_LOG << "\n";
-
672  }
-
673 
-
674  FIMS_LOG << "CAA\n";
-
675  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
-
676  FIMS_LOG << "Fleet " << fleet_ + 1 << "\n";
-
677  for (size_t i = 0; i < nyears; i++) {
-
678  for (size_t j = 0; j < nages; j++) {
-
679  FIMS_LOG << fleets[fleet_]->catch_numbers_at_age[i * nages + j]
-
680  << "\t";
-
681  }
-
682  FIMS_LOG << "\n";
-
683  }
-
684  }
-
685  }
-
686 };
-
687 template <class Type>
-
688 uint32_t Population<Type>::id_g = 0;
-
689 
-
690 } // namespace fims
-
691 
-
692 #endif /* FIMS_POPULATION_DYNAMICS_POPULATION_HPP */
+
476  FIMS_LOG << " selectivity "
+
477  << this->fleets[fleet_]->selectivity->evaluate(ages[age])
+
478  << std::endl;
+
479  FIMS_LOG << " catch " << catch_ << std::endl;
+
480  // this->catch_numbers_at_age[i_age_yearf] += catch_;
+
481  // catch_numbers_at_age for the fleet module has different
+
482  // dimensions (year/age, not year/fleet/age)
+
483  this->fleets[fleet_]->catch_numbers_at_age[i_age_year] += catch_;
+
484  }
+
485  }
+
486 
+
494  void CalculateCatchWeightAA(size_t year, size_t age) {
+
495  int i_age_year = year * this->nages + age;
+
496  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
+
497  FIMS_LOG << " fleet " << fleet_ << std::endl;
+
498  FIMS_LOG << " catchnaa "
+
499  << this->fleets[fleet_]->catch_numbers_at_age[year] << std::endl;
+
500  FIMS_LOG << " weight " << this->growth->evaluate(ages[age]) << std::endl;
+
501  this->fleets[fleet_]->catch_weight_at_age[i_age_year] =
+
502  this->fleets[fleet_]->catch_numbers_at_age[i_age_year] *
+
503  this->growth->evaluate(ages[age]); // this->weight_at_age[age];
+
504  FIMS_LOG << " catch_waa "
+
505  << this->fleets[fleet_]->catch_weight_at_age[i_age_year]
+
506  << std::endl;
+
507  }
+
508  }
+
509 
+
517  void CalculateMaturityAA(size_t i_age_year, size_t age) {
+
518  // this->maturity is pointing to the maturity module, which has
+
519  // an evaluate function. -> can be nested.
+
520  FIMS_LOG << " age " << age << std::endl;
+
521  FIMS_LOG << " ages size " << this->ages.size() << std::endl;
+
522  FIMS_LOG << " i_age_year " << i_age_year << std::endl;
+
523  FIMS_LOG << "p mature" << this->proportion_mature_at_age[i_age_year]
+
524  << std::endl;
+
525  FIMS_LOG << this->ages[age] << std::endl;
+
526  this->proportion_mature_at_age[i_age_year] =
+
527  this->maturity->evaluate(ages[age]);
+
528 
+
529  FIMS_LOG << "p mature set to " << this->proportion_mature_at_age[i_age_year]
+
530  << std::endl;
+
531  }
+
532 
+
537  void Evaluate() {
+
538  /*
+
539  Sets derived vectors to zero
+
540  Performs parameters transformations
+
541  Sets recruitment deviations to mean 0.
+
542  */
+
543  Prepare();
+
544  /*
+
545  start at year=0, age=0;
+
546  here year 0 is the estimated initial stock structure and age 0 are recruits
+
547  loops start at zero with if statements inside to specify unique code for
+
548  initial structure and recruitment 0 loops. Could also have started loops at
+
549  1 with initial structure and recruitment setup outside the loops.
+
550 
+
551  year loop is extended to <= nyears because SSB is calculted as the start of
+
552  the year value and by extending one extra year we get estimates of the
+
553  population structure at the end of the final year. An alternative approach
+
554  would be to keep initial numbers at age in it's own vector and each year to
+
555  include the population structure at the end of the year. This is likely a
+
556  null point given that we are planning to modify to an event/stanza based
+
557  structure in later milestones which will elimitate this confusion by
+
558  explicity referencing the exact date (or period of averaging) at which any
+
559  calculation or output is being made.
+
560  */
+
561  for (size_t y = 0; y <= this->nyears; y++) {
+
562  for (size_t a = 0; a < this->nages; a++) {
+
563  /*
+
564  index naming defines the dimensional folding structure
+
565  i.e. i_age_year is referencing folding over years and ages.
+
566  */
+
567  size_t i_age_year = y * this->nages + a;
+
568  /*
+
569  Mortality rates are not estimated in the final year which is
+
570  used to show expected stock structure at the end of the model period.
+
571  This is because biomass in year i represents biomass at the start of
+
572  the year.
+
573  Should we add complexity to track more values such as start,
+
574  mid, and end biomass in all years where, start biomass=end biomass of
+
575  the previous year? Referenced above, this is probably not worth
+
576  exploring as later milestone changes will eliminate this confusion.
+
577  */
+
578  if (y < this->nyears) {
+
579  /*
+
580  First thing we need is total mortality aggregated across all fleets
+
581  to inform the subsequent catch and change in numbers at age
+
582  calculations. This is only calculated for years < nyears as these are
+
583  the model estimated years with data. The year loop extends to
+
584  y=nyears so that population numbers at age and SSB can be calculated
+
585  at the end of the last year of the model
+
586  */
+
587  CalculateMortality(i_age_year, y, a);
+
588  }
+
589  CalculateMaturityAA(i_age_year, a);
+
590  /* if statements needed because some quantities are only needed
+
591  for the first year and/or age, so these steps are included here.
+
592  */
+
593  if (y == 0) {
+
594  // Initial numbers at age is a user input or estimated parameter
+
595  // vector.
+
596  CalculateInitialNumbersAA(i_age_year, a);
+
597 
+
598  if (a == 0) {
+
599  // this->numbers_at_age[i_age_year] = this->recruitment->rzero;
+
600  this->unfished_numbers_at_age[i_age_year] =
+
601  fims::exp(this->recruitment->log_rzero);
+
602  } else {
+
603  CalculateUnfishedNumbersAA(i_age_year, a - 1, a);
+
604  }
+
605 
+
606  /*
+
607  Fished and unfished biomass vectors are summing biomass at
+
608  age across ages.
+
609  */
+
610 
+
611  CalculateBiomass(i_age_year, y, a);
+
612 
+
613  CalculateUnfishedBiomass(i_age_year, y, a);
+
614 
+
615  /*
+
616  Fished and unfished spawning biomass vectors are summing biomass at
+
617  age across ages to allow calculation of recruitment in the next year.
+
618  */
+
619 
+
620  CalculateSpawningBiomass(i_age_year, y, a);
+
621 
+
622  CalculateUnfishedSpawningBiomass(i_age_year, y, a);
+
623 
+
624  /*
+
625  Expected recruitment in year 0 is numbers at age 0 in year 0.
+
626  */
+
627 
+
628  this->expected_recruitment[i_age_year] =
+
629  this->numbers_at_age[i_age_year];
+
630 
+
631  } else {
+
632  if (a == 0) {
+
633  // Set the nrecruits for age a=0 year y (use pointers instead of
+
634  // functional returns) assuming fecundity = 1 and 50:50 sex ratio
+
635  FIMS_LOG << "Recruitment: " << std::endl;
+
636  CalculateRecruitment(i_age_year, y);
+
637  this->unfished_numbers_at_age[i_age_year] =
+
638  fims::exp(this->recruitment->log_rzero);
+
639 
+
640  } else {
+
641  size_t i_agem1_yearm1 = (y - 1) * nages + (a - 1);
+
642  CalculateNumbersAA(i_age_year, i_agem1_yearm1, a);
+
643  CalculateUnfishedNumbersAA(i_age_year, i_agem1_yearm1, a);
+
644  }
+
645  CalculateBiomass(i_age_year, y, a);
+
646  CalculateSpawningBiomass(i_age_year, y, a);
+
647 
+
648  FIMS_LOG << "index ya: " << i_age_year << std::endl;
+
649  CalculateUnfishedBiomass(i_age_year, y, a);
+
650  CalculateUnfishedSpawningBiomass(i_age_year, y, a);
+
651  }
+
652 
+
653  /*
+
654  Here composition, total catch, and index values are calculated for all
+
655  years with reference data. They are not calculated for y=nyears as there
+
656  is this is just to get final population structure at the end of the
+
657  terminal year.
+
658  */
+
659  if (y < this->nyears) {
+
660  FIMS_LOG << i_age_year << std::endl;
+
661  CalculateCatchNumbersAA(i_age_year, y, a);
+
662 
+
663  CalculateCatchWeightAA(y, a);
+
664  FIMS_LOG << "year " << y << " and age " << a << std::endl;
+
665  CalculateCatch(y, a);
+
666  CalculateIndex(i_age_year, y, a);
+
667  }
+
668  }
+
669  }
+
670  FIMS_LOG << "NAA\n";
+
671  for (size_t i = 0; i < nyears; i++) {
+
672  for (size_t j = 0; j < nages; j++) {
+
673  FIMS_LOG << numbers_at_age[i * nages + j] << "\t";
+
674  }
+
675  FIMS_LOG << "\n";
+
676  }
+
677 
+
678  FIMS_LOG << "CAA\n";
+
679  for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) {
+
680  FIMS_LOG << "Fleet " << fleet_ + 1 << "\n";
+
681  for (size_t i = 0; i < nyears; i++) {
+
682  for (size_t j = 0; j < nages; j++) {
+
683  FIMS_LOG << fleets[fleet_]->catch_numbers_at_age[i * nages + j]
+
684  << "\t";
+
685  }
+
686  FIMS_LOG << "\n";
+
687  }
+
688  }
+
689  }
+
690 };
+
691 template <class Type>
+
692 uint32_t Population<Type>::id_g = 0;
+
693 
+
694 } // namespace fims
+
695 
+
696 #endif /* FIMS_POPULATION_DYNAMICS_POPULATION_HPP */
std::ofstream FIMS_LOG("fims.log")
FIMSObject struct that defines member types and returns the unique id.
Definition: model_object.hpp:25
Population class. Contains subpopulations that are divided into generic partitions (eg....
Definition: population.hpp:36
-
void CalculateUnfishedNumbersAA(size_t i_age_year, size_t i_agem1_yearm1, size_t age)
Calculates unfished numbers at age at year and age specific indices.
Definition: population.hpp:256
+
void CalculateUnfishedNumbersAA(size_t i_age_year, size_t i_agem1_yearm1, size_t age)
Calculates unfished numbers at age at year and age specific indices.
Definition: population.hpp:257
std::shared_ptr< fims::MaturityBase< Type > > maturity
Definition: population.hpp:100
std::vector< Type > expected_recruitment
Definition: population.hpp:86
-
void CalculateCatchWeightAA(size_t year, size_t age)
Calculates expected catch weight at age for each fleet for a given year and age.
Definition: population.hpp:491
-
void Evaluate()
Executes the population loop.
Definition: population.hpp:534
+
void CalculateCatchWeightAA(size_t year, size_t age)
Calculates expected catch weight at age for each fleet for a given year and age.
Definition: population.hpp:494
+
void Evaluate()
Executes the population loop.
Definition: population.hpp:537
void CalculateNumbersAA(size_t i_age_year, size_t i_agem1_yearm1, size_t age)
Calculates numbers at age at year and age specific indices.
Definition: population.hpp:233
-
void CalculateIndex(size_t i_age_year, size_t year, size_t age)
Adds to the expected population indices by fleet.
Definition: population.hpp:427
+
void CalculateIndex(size_t i_age_year, size_t year, size_t age)
Adds to the expected population indices by fleet.
Definition: population.hpp:429
std::vector< Type > weight_at_age
Definition: population.hpp:67
std::shared_ptr< fims::RecruitmentBase< Type > > recruitment
Definition: population.hpp:90
std::vector< Type > M
Definition: population.hpp:56
-
void CalculateCatchNumbersAA(size_t i_age_year, size_t year, size_t age)
Calculates catch in numbers at age for each fleet for a given year and age, then adds the value to th...
Definition: population.hpp:456
+
void CalculateCatchNumbersAA(size_t i_age_year, size_t year, size_t age)
Calculates catch in numbers at age for each fleet for a given year and age, then adds the value to th...
Definition: population.hpp:458
std::vector< double > ages
Definition: population.hpp:58
size_t nages
Definition: population.hpp:43
int maturity_id
Definition: population.hpp:98
const Type proportion_female
Definition: population.hpp:47
std::vector< Type > unfished_spawning_biomass
Definition: population.hpp:79
-
void CalculateCatch(size_t year, size_t age)
Adds to exiting expected total catch by fleet in weight.
Definition: population.hpp:397
+
void CalculateCatch(size_t year, size_t age)
Adds to exiting expected total catch by fleet in weight.
Definition: population.hpp:399
std::vector< Type > biomass
Definition: population.hpp:75
std::vector< std::shared_ptr< fims::Fleet< Type > > > fleets
Definition: population.hpp:105
int growth_id
Definition: population.hpp:93
std::vector< Type > proportion_mature_at_age
Definition: population.hpp:81
-
void CalculateRecruitment(size_t i_age_year, size_t year)
Calculates expected recruitment for a given year.
Definition: population.hpp:370
+
void CalculateRecruitment(size_t i_age_year, size_t year)
Calculates expected recruitment for a given year.
Definition: population.hpp:372
std::vector< Type > log_init_naa
Definition: population.hpp:52
size_t nyears
Definition: population.hpp:41
ParameterVector log_M
Definition: population.hpp:53
ParameterVector mortality_F
Definition: population.hpp:60
std::shared_ptr< fims::GrowthBase< Type > > growth
Definition: population.hpp:95
void CalculateInitialNumbersAA(size_t i_age_year, size_t a)
Calculates initial numbers at age for index and age.
Definition: population.hpp:196
-
void CalculateMaturityAA(size_t i_age_year, size_t age)
Calculates expected proportion of individuals mature at a selected ageage.
Definition: population.hpp:514
+
void CalculateMaturityAA(size_t i_age_year, size_t age)
Calculates expected proportion of individuals mature at a selected ageage.
Definition: population.hpp:517
void Initialize(int nyears, int nseasons, int nages)
Initialize values. Called once at the start of model run.
Definition: population.hpp:123
size_t nseasons
Definition: population.hpp:42
std::vector< double > years
Definition: population.hpp:59
std::vector< Type > numbers_at_age
Definition: population.hpp:69
void Prepare()
Prepare to run the population loop. Called at each model iteration, and used to zero out derived quan...
Definition: population.hpp:154
-
void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year, size_t age)
Adds to existing yearly unfished spawning biomass estimates the biomass for a specified year and age.
Definition: population.hpp:329
+
void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year, size_t age)
Adds to existing yearly unfished spawning biomass estimates the biomass for a specified year and age.
Definition: population.hpp:331
std::vector< Type > unfished_biomass
Definition: population.hpp:77
static uint32_t id_g
Definition: population.hpp:40
std::vector< Type > unfished_numbers_at_age
Definition: population.hpp:72
std::vector< Type > expected_numbers_at_age
Definition: population.hpp:83
-
void CalculateBiomass(size_t i_age_year, size_t year, size_t age)
Calculates biomass.
Definition: population.hpp:280
+
void CalculateBiomass(size_t i_age_year, size_t year, size_t age)
Calculates biomass.
Definition: population.hpp:281
std::vector< Type > spawning_biomass
Definition: population.hpp:76
int fleet_id
Definition: population.hpp:103
-
void CalculateSpawningBiomass(size_t i_age_year, size_t year, size_t age)
Calculates spawning biomass.
Definition: population.hpp:308
+
void CalculateSpawningBiomass(size_t i_age_year, size_t year, size_t age)
Calculates spawning biomass.
Definition: population.hpp:309
typename ModelTraits< Type >::ParameterVector ParameterVector
Definition: population.hpp:39
std::vector< Type > expected_catch
Definition: population.hpp:85
void CalculateMortality(size_t i_age_year, size_t year, size_t age)
Calculates total mortality at an index, year, and age.
Definition: population.hpp:208
std::vector< Type > mortality_Z
Definition: population.hpp:63
-
Type CalculateSBPR0()
Calculates equilibrium spawning biomass per recruit.
Definition: population.hpp:342
+
Type CalculateSBPR0()
Calculates equilibrium spawning biomass per recruit.
Definition: population.hpp:344
size_t nfleets
Definition: population.hpp:44
-
void CalculateUnfishedBiomass(size_t i_age_year, size_t year, size_t age)
Adds to existing yearly unfished biomass estimates the biomass for a specified year and age.
Definition: population.hpp:296
+
void CalculateUnfishedBiomass(size_t i_age_year, size_t year, size_t age)
Adds to existing yearly unfished biomass estimates the biomass for a specified year and age.
Definition: population.hpp:297
int recruitment_id
recruitment
Definition: population.hpp:88
diff --git a/docs/rcpp__population_8hpp_source.html b/docs/rcpp__population_8hpp_source.html index 1cd771d..93d08de 100644 --- a/docs/rcpp__population_8hpp_source.html +++ b/docs/rcpp__population_8hpp_source.html @@ -243,7 +243,7 @@
Rcpp::NumericVector log_M
Definition: rcpp_population.hpp:63
static std::shared_ptr< Information< T > > GetInstance()
Definition: information.hpp:125
Population class. Contains subpopulations that are divided into generic partitions (eg....
Definition: population.hpp:36
-
void Evaluate()
Executes the population loop.
Definition: population.hpp:534
+
void Evaluate()
Executes the population loop.
Definition: population.hpp:537