12#ifndef POPULATION_DYNAMICS_AGE_TO_LENGTH_CONVERSION_FIXED_HPP
13#define POPULATION_DYNAMICS_AGE_TO_LENGTH_CONVERSION_FIXED_HPP
34template <
typename Type>
38 std::weak_ptr<Fleet<Type>>
fleet;
46 : AgeToLengthConversionBase<Type>(),
fleet(
fleet) {}
61 std::shared_ptr<Fleet<Type>> fleet_ptr =
fleet.lock();
65 if (fleet_ptr ==
nullptr) {
73 return fleet_ptr->n_ages > 0 && fleet_ptr->n_lengths > 0 &&
74 HasValidSize(*fleet_ptr);
84 static bool HasValidSize(
const Fleet<Type>& fleet_ref) {
87 return matrix_size == table_size ||
88 matrix_size == fleet_ref.
n_years * table_size;
109 std::shared_ptr<Fleet<Type>> fleet_ptr =
fleet.lock();
116 if (fleet_ptr ==
nullptr || fleet_ptr->n_ages == 0 ||
117 fleet_ptr->n_lengths == 0 || age >= fleet_ptr->n_ages ||
118 !HasValidSize(*fleet_ptr)) {
121 const size_t table_size = fleet_ptr->n_ages * fleet_ptr->n_lengths;
122 const bool has_table_per_year =
123 fleet_ptr->age_to_length_conversion.size() != table_size;
124 if (has_table_per_year && year >= fleet_ptr->n_years) {
129 out_row.
resize(fleet_ptr->n_lengths);
133 const size_t year_offset = has_table_per_year ? year * table_size : 0;
134 const size_t row_offset = year_offset + age * fleet_ptr->n_lengths;
137 for (
size_t l = 0; l < fleet_ptr->n_lengths; ++l) {
138 out_row[l] = fleet_ptr->age_to_length_conversion[row_offset + l];
Declares the AgeToLengthConversionBase class which is the base class for all age-length key functors.
Definition fims_vector.hpp:27
void resize(size_t s)
Changes the number of elements stored.
Definition fims_vector.hpp:401
Declare the fleet functor class which is the base class for all fleet functors.
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
AgeToLengthConversionFixed(const std::shared_ptr< Fleet< Type > > &fleet)
Constructor.
Definition fixed.hpp:45
std::weak_ptr< Fleet< Type > > fleet
Definition fixed.hpp:38
virtual bool BuildAgeToLengthConversionRow(size_t year, size_t age, fims::Vector< Type > &out_row) const override
Builds the fixed age-to-length conversion row for a given age.
Definition fixed.hpp:106
virtual ~AgeToLengthConversionFixed()
Destructor.
Definition fixed.hpp:51
virtual bool PrepareForCurrentState() override
Prepare the fixed-matrix age-to-length conversion for the current model state.
Definition fixed.hpp:97
virtual bool IsActive() const override
Returns whether this fixed-matrix age-to-length conversion is active and usable.
Definition fixed.hpp:58
Base class for all fleets.
Definition fleet.hpp:26
size_t n_years
Definition fleet.hpp:28
size_t n_ages
Definition fleet.hpp:29
fims::Vector< Type > age_to_length_conversion
Definition fleet.hpp:83
size_t n_lengths
Definition fleet.hpp:30