8#ifndef FIMS_MODELS_CATCH_AT_AGE_HPP
9#define FIMS_MODELS_CATCH_AT_AGE_HPP
43template <
typename Type>
65 typedef typename std::map<std::string, fims::Vector<Type>>::iterator
73 std::map<std::string, fims::Vector<Type>>>::iterator
81 std::map<std::string, fims::Vector<size_t>>>::iterator
88 std::map<std::string, fims::Vector<Type>>>::iterator
97 std::map<std::string, fims::Vector<size_t>>>::iterator
105 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
112 typename std::map<std::string, fims::Vector<Type>>::iterator
dq_iterator;
127 std::stringstream
ss;
128 ss <<
"caa_" << this->
GetId() <<
"_";
129 this->name_m =
ss.str();
169 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
171 if (
fleet->log_q.size() == 0) {
172 fleet->log_q.resize(1);
173 fleet->log_q[0] =
static_cast<Type>(0.0);
186 std::shared_ptr<fims_popdy::Population<Type>> &
population =
198 for (
size_t age = 0;
age < population->n_ages;
age++) {
219 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
228 for (
size_t i = 0;
i < fleet->log_q.size();
i++) {
271 std::map<std::string, fims::Vector<Type>> &
dq_ =
305 std::map<std::string, fims::Vector<Type>> &
dq_ =
346 std::map<std::string, fims::Vector<Type>> &
dq_ =
397 std::map<std::string, fims::Vector<Type>> &
dq_ =
434 std::map<std::string, fims::Vector<Type>> &
dq_ =
458 std::map<std::string, fims::Vector<Type>> &
dq_ =
461 dq_[
"unfished_biomass"][
year] +=
485 std::map<std::string, fims::Vector<Type>> &
dq_ =
488 dq_[
"spawning_biomass"][
year] +=
512 std::map<std::string, fims::Vector<Type>> &
dq_ =
515 dq_[
"unfished_spawning_biomass"][
year] +=
539 std::map<std::string, fims::Vector<Type>> &
dq_ =
542 dq_[
"spawning_biomass"][
year] /
dq_[
"unfished_spawning_biomass"][0];
570 std::map<std::string, fims::Vector<Type>> &
dq_ =
576 dq_[
"proportion_mature_at_age"][0] *
581 dq_[
"proportion_mature_at_age"][
a] *
624 std::map<std::string, fims::Vector<Type>> &
dq_ =
640 fims_math::log(
population->recruitment->evaluate_mean(
666 std::map<std::string, fims::Vector<Type>> &
dq_ =
691 std::map<std::string, fims::Vector<Type>> &
pdq_ =
695 std::map<std::string, fims::Vector<Type>> &
fdq_ =
699 pdq_[
"total_landings_weight"][
year] +=
705 pdq_[
"total_landings_numbers"][
year] +=
733 std::map<std::string, fims::Vector<Type>> &
fdq_ =
762 std::map<std::string, fims::Vector<Type>> &
pdq_ =
766 std::map<std::string, fims::Vector<Type>> &
fdq_ =
770 fdq_[
"landings_numbers_at_age"][
i_age_year] +=
800 std::map<std::string, fims::Vector<Type>> &
fdq_ =
831 std::map<std::string, fims::Vector<Type>> &
pdq_ =
835 std::map<std::string, fims::Vector<Type>> &
fdq_ =
865 std::map<std::string, fims::Vector<Type>> &
fdq_ =
880 std::map<std::string, fims::Vector<Type>> &
fdq_ =
883 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
884 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
895 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
903 if (
fleet->fleet_observed_landings_data_id_m == -999) {
920 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
922 fleet->observed_agecomp_data->na_value) {
927 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
933 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
948 std::map<std::string, fims::Vector<Type>> &
fdq_ =
951 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
953 if (
fleet->n_lengths > 0) {
954 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
964 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
966 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
985 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
987 fleet->observed_lengthcomp_data->na_value) {
992 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
998 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
1014 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1016 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1018 for (
size_t i = 0;
i <
fdq_[
"index_numbers"].size();
i++) {
1019 if (
fleet->observed_index_units ==
"number") {
1020 fdq_[
"index_expected"][
i] =
fdq_[
"index_numbers"][
i];
1022 fdq_[
"index_expected"][
i] =
fdq_[
"index_weight"][
i];
1024 fdq_[
"log_index_expected"][
i] =
log(
fdq_[
"index_expected"][
i]);
1035 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1037 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1039 for (
size_t i = 0;
i <
fdq_[
"landings_weight"].size();
i++) {
1040 if (
fleet->observed_landings_units ==
"number") {
1041 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_numbers"][
i];
1043 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_weight"][
i];
1045 fdq_[
"log_landings_expected"][
i] =
log(
fdq_[
"landings_expected"][
i]);
1075 std::shared_ptr<fims_popdy::Population<Type>> &
population =
1077 std::map<std::string, fims::Vector<Type>> &
pdq_ =
1122 pdq_[
"expected_recruitment"][
y] =
1125 fims_math::exp(
population->recruitment->log_rzero[0]);
1136 fims_math::exp(
population->recruitment->log_rzero[0]);
1194 int n_fleets = this->
fleets.size();
1198 report_vectors.clear();
1276 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1343 vector<Type> spawning_biomass_ratio =
1370 vector<Type> lengthcomp_proportion =
1373 vector<Type> log_landings_expected =
1383 FIMS_REPORT_F_(
"proportion_mature_at_age", proportion_mature_at_age_p,
1387 FIMS_REPORT_F_(
"total_landings_numbers", total_landings_numbers_p,
1392 FIMS_REPORT_F_(
"unfished_numbers_at_age", unfished_numbers_at_age_p,
1394 FIMS_REPORT_F_(
"unfished_spawning_biomass", unfished_spawning_biomass_p,
1396 FIMS_REPORT_F_(
"spawning_biomass_ratio", spawning_biomass_ratio_p,
1424 FIMS_REPORT_F_(
"index_numbers_at_length", index_numbers_at_length_f,
1430 FIMS_REPORT_F_(
"landings_numbers_at_age", landings_numbers_at_age_f,
1432 FIMS_REPORT_F_(
"landings_numbers_at_length", landings_numbers_at_length_f,
1435 FIMS_REPORT_F_(
"landings_weight_at_age", landings_weight_at_age_f,
1464 typename std::map<std::string, fims::Vector<fims::Vector<Type>>>::iterator
1468 auto &
x =
rvit->second;
1484 this->
of->reportvector.push(res,
rvit->first.c_str());
CatchAtAge is a class containing a catch-at-age model, which is just one of many potential fishery mo...
Definition catch_at_age.hpp:53
void CalculateSpawningBiomassRatio(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t year)
Calculate the spawning biomass ratio for a population and year.
Definition catch_at_age.hpp:537
std::map< std::string, fims::Vector< Type > >::iterator dq_iterator
Iterate through derived quantities.
Definition catch_at_age.hpp:112
std::map< std::string, fims::Vector< Type > >::iterator derived_quantities_iterator
Iterate the derived quantities.
Definition catch_at_age.hpp:66
Type CalculateSBPR0(std::shared_ptr< fims_popdy::Population< Type > > &population)
Calculates equilibrium spawning biomass per recruit.
Definition catch_at_age.hpp:568
virtual void Initialize()
Definition catch_at_age.hpp:153
std::vector< Type > ages
Definition catch_at_age.hpp:121
void CalculateUnfishedNumbersAA(std::shared_ptr< fims_popdy::Population< Type > > &population, 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 catch_at_age.hpp:343
void CalculateBiomass(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates biomass for a population.
Definition catch_at_age.hpp:431
std::map< std::string, fims::Vector< fims::Vector< Type > > > report_vectors
A map of report vectors for the object. used to populate the report_vectors map in for submodule para...
Definition catch_at_age.hpp:118
std::set< uint32_t > & GetPopulationIds()
Get the population ids of the model.
Definition catch_at_age.hpp:245
std::map< uint32_t, std::map< std::string, fims::Vector< size_t > > >::iterator population_derived_quantities_dims_iterator
Used to iterate through population-based derived quantities dimensions.
Definition catch_at_age.hpp:98
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Iterate through fleets.
Definition catch_at_age.hpp:106
void CalculateIndexWeightAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t year, size_t age)
Calculates biomass of fish for the index for a given fleet from a population.
Definition catch_at_age.hpp:860
void evaluate_age_comp()
Definition catch_at_age.hpp:877
void evaluate_length_comp()
Definition catch_at_age.hpp:945
virtual ~CatchAtAge()
Destroy the Catch At Age object.
Definition catch_at_age.hpp:147
CatchAtAge(const CatchAtAge &other)
Copy constructor for the CatchAtAge class.
Definition catch_at_age.hpp:138
void CalculateSpawningBiomass(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates spawning biomass for a population.
Definition catch_at_age.hpp:482
CatchAtAge()
Definition catch_at_age.hpp:126
virtual void Evaluate()
Evaluate the model.
Definition catch_at_age.hpp:1050
std::string name_m
The name of the model.
Definition catch_at_age.hpp:59
void CalculateUnfishedSpawningBiomass(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculated unfished spawning biomass for a population.
Definition catch_at_age.hpp:509
void CalculateIndex(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates the index for a fleet from a population.
Definition catch_at_age.hpp:797
void CalculateUnfishedBiomass(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates the unfished biomass for a population.
Definition catch_at_age.hpp:455
std::map< uint32_t, std::map< std::string, fims::Vector< Type > > >::iterator fleet_derived_quantities_iterator
Used to iterate through fleet-based derived quantities.
Definition catch_at_age.hpp:74
void CalculateMaturityAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t age)
Calculates maturity at age, in proportion, for a population.
Definition catch_at_age.hpp:663
std::map< uint32_t, std::map< std::string, fims::Vector< Type > > >::iterator population_derived_quantities_iterator
Used to iterate through population-based derived quantities.
Definition catch_at_age.hpp:89
void CalculateNumbersAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t i_agem1_yearm1, size_t age)
Calculates numbers at age for a population.
Definition catch_at_age.hpp:300
void CalculateLandingsNumbersAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates numbers of fish for the landings for a given fleet from a population, year and age.
Definition catch_at_age.hpp:759
void CalculateRecruitment(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t i_dev)
Calculates expected recruitment for a population.
Definition catch_at_age.hpp:621
void evaluate_landings()
Definition catch_at_age.hpp:1032
virtual void Report()
Definition catch_at_age.hpp:1193
void AddPopulation(uint32_t id)
Definition catch_at_age.hpp:240
void CalculateLandingsWeightAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t year, size_t age)
Calculates weight at age of the landings for a given fleet from a population.
Definition catch_at_age.hpp:728
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > & GetPopulations()
Definition catch_at_age.hpp:252
std::map< uint32_t, std::map< std::string, fims::Vector< size_t > > >::iterator fleet_derived_quantities_dims_iterator
Used to iterate through fleet-based derived quantities dimensions.
Definition catch_at_age.hpp:82
void CalculateLandings(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t year, size_t age)
Calculates total catch (landings) by fleet and population for a given year by aggregating age-specifi...
Definition catch_at_age.hpp:688
void CalculateMortality(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates total mortality for a population.
Definition catch_at_age.hpp:394
void CalculateIndexNumbersAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t year, size_t age)
Calculates the numbers for the index for a fleet from a population.
Definition catch_at_age.hpp:828
void CalculateInitialNumbersAA(std::shared_ptr< fims_popdy::Population< Type > > &population, size_t i_age_year, size_t age)
Calculates initial numbers at age for index and age.
Definition catch_at_age.hpp:268
virtual void Prepare()
Definition catch_at_age.hpp:184
void evaluate_index()
Definition catch_at_age.hpp:1011
FisheryModelBase is a base class for fishery models in FIMS.
Definition fishery_model_base.hpp:77
uint32_t GetId()
Get the Id object.
Definition fishery_model_base.hpp:382
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > > fleets
A map of fleets in the fishery model, indexed by fleet id. Unique instances to eliminate duplicate in...
Definition fishery_model_base.hpp:107
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > populations
A vector of populations in the fishery model.
Definition fishery_model_base.hpp:101
std::string model_type_m
A string specifying the model type.
Definition fishery_model_base.hpp:91
DerivedQuantitiesMap & GetFleetDerivedQuantities()
Get the fleet derived quantities.
Definition fishery_model_base.hpp:213
std::set< uint32_t > population_ids
Unique identifier for the fishery model.
Definition fishery_model_base.hpp:96
DerivedQuantitiesMap & GetPopulationDerivedQuantities()
Get the population derived quantities.
Definition fishery_model_base.hpp:222
virtual void ResetVector(fims::Vector< Type > &v, Type value=0.0)
Reset a vector from start to end with a value.
Definition fishery_model_base.hpp:361
Defines the base class for all fishery models within the FIMS framework.
#define ADREPORT_F(name, F)
TMB macro that reports variables and uncertainties.
Definition interface.hpp:78
The population dynamics of FIMS.
Definition catch_at_age.hpp:41
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:239
Population class. Contains subpopulations that are divided into generic partitions (e....
Definition population.hpp:25