FIMS  v0.10.0
Loading...
Searching...
No Matches
growth_products.hpp
Go to the documentation of this file.
1// inst/include/population_dynamics/growth/growth_products.hpp
10#ifndef POPULATION_DYNAMICS_GROWTH_PRODUCTS_HPP
11#define POPULATION_DYNAMICS_GROWTH_PRODUCTS_HPP
12
13#include <cstddef>
14#include <vector>
15#include <stdexcept>
16
17namespace fims_popdy {
18
25template <typename Type>
27 std::size_t n_years = 0;
28 std::size_t n_ages = 0;
29 std::size_t n_sexes = 0;
31 std::vector<Type> mean_LAA;
32 std::vector<Type> sd_LAA;
33 std::vector<Type> mean_WAA;
38 GrowthProducts() = default;
39
46 GrowthProducts(std::size_t years, std::size_t ages, std::size_t sexes) {
47 Resize(years, ages, sexes);
48 }
49
56 void Resize(std::size_t years, std::size_t ages, std::size_t sexes) {
57 n_years = years;
58 n_ages = ages;
59 n_sexes = sexes;
60
61 const std::size_t n = n_years * n_ages * n_sexes;
62
63 mean_LAA.assign(n, static_cast<Type>(0));
64 sd_LAA.assign(n, static_cast<Type>(0));
65 mean_WAA.assign(n, static_cast<Type>(0));
66 }
67
75 inline std::size_t Index(std::size_t y, std::size_t a, std::size_t s) const {
76 // Cheap runtime safety. Keep it here, not sprinkled everywhere.
77 if (y >= n_years || a >= n_ages || s >= n_sexes) {
78 throw std::out_of_range("GrowthProducts index out of range");
79 }
80 return (y * n_ages + a) * n_sexes + s;
81 }
82
90 inline Type& MeanLAA(std::size_t y, std::size_t a, std::size_t s) {
91 return mean_LAA[Index(y, a, s)];
92 }
93
101 inline Type& SdLAA(std::size_t y, std::size_t a, std::size_t s) {
102 return sd_LAA[Index(y, a, s)];
103 }
104
112 inline Type& MeanWAA(std::size_t y, std::size_t a, std::size_t s) {
113 return mean_WAA[Index(y, a, s)];
114 }
115
123 inline const Type& MeanLAA(std::size_t y, std::size_t a,
124 std::size_t s) const {
125 return mean_LAA[Index(y, a, s)];
126 }
127
135 inline const Type& SdLAA(std::size_t y, std::size_t a, std::size_t s) const {
136 return sd_LAA[Index(y, a, s)];
137 }
138
146 inline const Type& MeanWAA(std::size_t y, std::size_t a,
147 std::size_t s) const {
148 return mean_WAA[Index(y, a, s)];
149 }
150
155 inline std::size_t Size() const { return mean_LAA.size(); }
156};
157
158} // namespace fims_popdy
159
160#endif /* POPULATION_DYNAMICS_GROWTH_PRODUCTS_HPP */
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
std::shared_ptr< AgeToLengthConversionBase< Type > > BuildAgeToLengthConversionFleet(const std::shared_ptr< Population< Type > > &population, const std::shared_ptr< Fleet< Type > > &fleet)
Build the active age-to-length conversion for a fleet from the current population and fleet state.
Definition runtime.hpp:44
Growth "products" in a consistent (year, age, sex) space.
Definition growth_products.hpp:26
GrowthProducts()=default
Construct an empty growth-product container.
std::size_t Index(std::size_t y, std::size_t a, std::size_t s) const
Convert a (year, age, sex) triple into the contiguous storage index.
Definition growth_products.hpp:75
GrowthProducts(std::size_t years, std::size_t ages, std::size_t sexes)
Construct and size the growth-product container.
Definition growth_products.hpp:46
Type & MeanLAA(std::size_t y, std::size_t a, std::size_t s)
Access mean length-at-age by reference.
Definition growth_products.hpp:90
const Type & MeanWAA(std::size_t y, std::size_t a, std::size_t s) const
Access mean weight-at-age as a const reference.
Definition growth_products.hpp:146
std::size_t Size() const
Return the total number of cached cells.
Definition growth_products.hpp:155
void Resize(std::size_t years, std::size_t ages, std::size_t sexes)
Resize all cached product arrays.
Definition growth_products.hpp:56
std::vector< Type > mean_LAA
Definition growth_products.hpp:31
const Type & SdLAA(std::size_t y, std::size_t a, std::size_t s) const
Access standard deviation of length-at-age as a const reference.
Definition growth_products.hpp:135
std::size_t n_years
Definition growth_products.hpp:27
Type & MeanWAA(std::size_t y, std::size_t a, std::size_t s)
Access mean weight-at-age by reference.
Definition growth_products.hpp:112
const Type & MeanLAA(std::size_t y, std::size_t a, std::size_t s) const
Access mean length-at-age as a const reference.
Definition growth_products.hpp:123
Type & SdLAA(std::size_t y, std::size_t a, std::size_t s)
Access standard deviation of length-at-age by reference.
Definition growth_products.hpp:101
std::size_t n_sexes
Definition growth_products.hpp:29
std::size_t n_ages
Definition growth_products.hpp:28
std::vector< Type > sd_LAA
Definition growth_products.hpp:32
std::vector< Type > mean_WAA
Definition growth_products.hpp:33