Rceattle C++ template
The CEATTLE likelihood: src/TMB/ceattle.cpp and its headers
Loading...
Searching...
No Matches
spr.hpp
Go to the documentation of this file.
1#ifndef SPR_HPP
2#define SPR_HPP
3
4/**
5 * @file spr.hpp
6 * @brief Spawning biomass per recruit, for the Amendment-56 SPR proxies.
7 *
8 * F40% and F35% are the F that leave a target fraction of unfished spawning output per
9 * recruit; the template finds them by penalising SPR(F)/SPR(0) against that fraction
10 * (section 13, JNLL_REFPT_PENALTY). Under Beverton-Holt or Ricker, SPR0 also sets
11 * steepness and R0 and SPRFinit sets R_init (section 6.3), which scales the initial
12 * age structure (section 6.4) -- so these values reach the hindcast and the objective
13 * under any harvest control rule, not just the reference points.
14 *
15 * Both functions work on the female schedule (sex index 0) and report spawning output
16 * per TOTAL recruit: the caller supplies spawning output per fish with maturity
17 * already folded in, and the female fraction separately.
18 *
19 * Not defined under predation, where total mortality carries M2 and so tracks predator
20 * abundance rather than the prey stock alone: data_check() refuses the switch
21 * combinations that would read it.
22 */
23
24
25/**
26 * @brief Survivors at age from one recruit under a fixed mortality schedule.
27 *
28 * The oldest bin is a plus group, so it also accumulates the tail of survivors that
29 * stay in it: `/ (1 - exp(-Z_plus))`. Two unchecked preconditions, kept off the AD
30 * path and unreachable for any age-structured species: `Z.size() >= 2`, since the plus
31 * group reads the age below it, and a plus-group `Z` above zero, or that tail divides
32 * by zero.
33 *
34 * @param Z Total instantaneous mortality at age (yr^-1), length nages >= 2.
35 * @return Numbers at age per recruit.
36 */
37template <class Type>
38vector<Type> per_recruit_survivors(const vector<Type>& Z)
39{
40 int nages = Z.size();
41 vector<Type> n(nages);
42 n.setZero();
43 n(0) = 1.0;
44
45 for(int age = 1; age < nages - 1; age++){
46 n(age) = n(age - 1) * exp(-Z(age - 1));
47 }
48 n(nages - 1) = n(nages - 2) * exp(-Z(nages - 2)) / (1.0 - exp(-Z(nages - 1)));
49
50 return n;
51}
52
53
54/**
55 * @brief Female spawning biomass per recruit, given a survivor schedule.
56 *
57 * @param n Numbers at age per recruit, from per_recruit_survivors().
58 * @param Z The schedule that produced `n`, reused for the mortality served
59 * before spawning within the year.
60 * @param weight Spawning output per fish at age (kg): `spawn_output` (section
61 * 5.7), with maturity and, for a one-sex species, the female
62 * fraction already in it.
63 * @param mature_female Female fraction of a recruit's cohort: the recruitment split
64 * for a two-sex species, 1 otherwise.
65 * @param spawn_month Month of spawning, 0-12; 0 spawns at the start of the year.
66 * @return Spawning biomass per recruit (kg per recruit).
67 */
68template <class Type>
69Type spawning_biomass_per_recruit(const vector<Type>& n,
70 const vector<Type>& Z,
71 const vector<Type>& weight,
72 const vector<Type>& mature_female,
73 Type spawn_month)
74{
75 Type spr = 0.0;
76 for(int age = 0; age < n.size(); age++){
77 spr += n(age) * weight(age) * mature_female(age) *
78 exp(-Z(age) * spawn_month / 12.0);
79 }
80 return spr;
81}
82
83#endif
Type spawning_biomass_per_recruit(const vector< Type > &n, const vector< Type > &Z, const vector< Type > &weight, const vector< Type > &mature_female, Type spawn_month)
Female spawning biomass per recruit, given a survivor schedule.
Definition spr.hpp:69
vector< Type > per_recruit_survivors(const vector< Type > &Z)
Survivors at age from one recruit under a fixed mortality schedule.
Definition spr.hpp:38