From ea66f82fd32d40f426e9156cf135ce8b57daff23 Mon Sep 17 00:00:00 2001 From: Christine Stawitz - NOAA <47904621+ChristineStawitz-NOAA@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:53:25 +0000 Subject: [PATCH] add fleet length structure objects --- .../population_dynamics/fleet/fleet.hpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/inst/include/population_dynamics/fleet/fleet.hpp b/inst/include/population_dynamics/fleet/fleet.hpp index 9ca0db58..feaa34c6 100644 --- a/inst/include/population_dynamics/fleet/fleet.hpp +++ b/inst/include/population_dynamics/fleet/fleet.hpp @@ -27,6 +27,7 @@ struct Fleet : public fims_model_object::FIMSObject { static uint32_t id_g; /*!< reference id for fleet object*/ size_t nyears; /*!< the number of years in the model*/ size_t nages; /*!< the number of ages in the model*/ + size_t nlengths; // selectivity int fleet_selectivity_id_m = -999; /*!< id of selectivity component*/ @@ -45,6 +46,7 @@ struct Fleet : public fims_model_object::FIMSObject { fims::Vector catch_at_age; /*! catch_index; /*! age_composition; /*! length_composition; /*! observed_catch_lpdf; /*! { fims::Vector expected_index_lpdf; /*! catch_numbers_at_age; /*! catch_numbers_at_length; /*! proportion_catch_numbers_at_age; /*! catch_weight_at_age; /*! proportion_catch_numbers_at_length; /*! { * @param nyears The number of years in the model. * @param nages The number of ages in the model. */ - void Initialize(int nyears, int nages) { + void Initialize(int nyears, int nages, int nlengths = 0) { this->nyears = nyears; this->nages = nages; + this->nlengths = nlengths; catch_at_age.resize(nyears * nages); catch_numbers_at_age.resize(nyears * nages); + catch_numbers_at_length.resize(nyears * nlengths); catch_weight_at_age.resize(nyears * nages); catch_index.resize(nyears); // assume index is for all ages. expected_catch.resize(nyears); expected_index.resize(nyears); age_composition.resize(nyears * nages); + length_composition.resize(nyears * nlengths); log_Fmort.resize(nyears); Fmort.resize(nyears); @@ -113,6 +120,7 @@ struct Fleet : public fims_model_object::FIMSObject { std::fill(catch_index.begin(), catch_index.end(), 0); /** { 0); /**q = fims_math::exp(this->log_q); @@ -151,6 +163,24 @@ struct Fleet : public fims_model_object::FIMSObject { } } + /** + * Evaluate the proportion of catch numbers at age. + */ + void evaluate_length_comp() { + for (size_t y = 0; y < this->nyears; y++) { + Type sum = 0.0; + for (size_t l = 0; l < this->nlengths; l++) { + size_t i_length_year = y * this->nlengths + l; + sum += this->catch_numbers_at_length[i_length_year]; + } + for (size_t l = 0; l < this->nlengths; l++) { + size_t i_length_year = y * this->nlengths + l; + this->proportion_catch_numbers_at_length[i_length_year] = this->catch_numbers_at_length[i_length_year] / sum; + + } + } + } + /** * Evaluate the log of the expected index. */