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_ =
437 dq_[
"biomass"][
year] +=
459 std::map<std::string, fims::Vector<Type>> &
dq_ =
462 dq_[
"unfished_biomass"][
year] +=
486 std::map<std::string, fims::Vector<Type>> &
dq_ =
489 dq_[
"spawning_biomass"][
year] +=
513 std::map<std::string, fims::Vector<Type>> &
dq_ =
516 dq_[
"unfished_spawning_biomass"][
year] +=
540 std::map<std::string, fims::Vector<Type>> &
dq_ =
543 dq_[
"spawning_biomass"][
year] /
dq_[
"unfished_spawning_biomass"][0];
571 std::map<std::string, fims::Vector<Type>> &
dq_ =
577 dq_[
"proportion_mature_at_age"][0] *
582 dq_[
"proportion_mature_at_age"][
a] *
625 std::map<std::string, fims::Vector<Type>> &
dq_ =
641 fims_math::log(
population->recruitment->evaluate_mean(
667 std::map<std::string, fims::Vector<Type>> &
dq_ =
692 std::map<std::string, fims::Vector<Type>> &
pdq_ =
696 std::map<std::string, fims::Vector<Type>> &
fdq_ =
700 pdq_[
"total_landings_weight"][
year] +=
706 pdq_[
"total_landings_numbers"][
year] +=
734 std::map<std::string, fims::Vector<Type>> &
fdq_ =
763 std::map<std::string, fims::Vector<Type>> &
pdq_ =
767 std::map<std::string, fims::Vector<Type>> &
fdq_ =
771 fdq_[
"landings_numbers_at_age"][
i_age_year] +=
801 std::map<std::string, fims::Vector<Type>> &
fdq_ =
832 std::map<std::string, fims::Vector<Type>> &
pdq_ =
836 std::map<std::string, fims::Vector<Type>> &
fdq_ =
866 std::map<std::string, fims::Vector<Type>> &
fdq_ =
881 std::map<std::string, fims::Vector<Type>> &
fdq_ =
884 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
885 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
896 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
904 if (
fleet->fleet_observed_landings_data_id_m == -999) {
921 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
923 fleet->observed_agecomp_data->na_value) {
928 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
934 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
949 std::map<std::string, fims::Vector<Type>> &
fdq_ =
952 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
954 if (
fleet->n_lengths > 0) {
955 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
965 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
967 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
986 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
988 fleet->observed_lengthcomp_data->na_value) {
993 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
999 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
1015 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1017 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1019 for (
size_t i = 0;
i <
fdq_[
"index_numbers"].size();
i++) {
1020 if (
fleet->observed_index_units ==
"number") {
1021 fdq_[
"index_expected"][
i] =
fdq_[
"index_numbers"][
i];
1023 fdq_[
"index_expected"][
i] =
fdq_[
"index_weight"][
i];
1025 fdq_[
"log_index_expected"][
i] =
log(
fdq_[
"index_expected"][
i]);
1036 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1038 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1040 for (
size_t i = 0;
i <
fdq_[
"landings_weight"].size();
i++) {
1041 if (
fleet->observed_landings_units ==
"number") {
1042 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_numbers"][
i];
1044 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_weight"][
i];
1046 fdq_[
"log_landings_expected"][
i] =
log(
fdq_[
"landings_expected"][
i]);
1076 std::shared_ptr<fims_popdy::Population<Type>> &
population =
1078 std::map<std::string, fims::Vector<Type>> &
pdq_ =
1123 pdq_[
"expected_recruitment"][
y] =
1126 fims_math::exp(
population->recruitment->log_rzero[0]);
1137 fims_math::exp(
population->recruitment->log_rzero[0]);
1195 int n_fleets = this->
fleets.size();
1199 report_vectors.clear();
1277 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1344 vector<Type> spawning_biomass_ratio =
1371 vector<Type> lengthcomp_proportion =
1374 vector<Type> log_landings_expected =
1384 FIMS_REPORT_F_(
"proportion_mature_at_age", proportion_mature_at_age_p,
1388 FIMS_REPORT_F_(
"total_landings_numbers", total_landings_numbers_p,
1393 FIMS_REPORT_F_(
"unfished_numbers_at_age", unfished_numbers_at_age_p,
1395 FIMS_REPORT_F_(
"unfished_spawning_biomass", unfished_spawning_biomass_p,
1397 FIMS_REPORT_F_(
"spawning_biomass_ratio", spawning_biomass_ratio_p,
1425 FIMS_REPORT_F_(
"index_numbers_at_length", index_numbers_at_length_f,
1431 FIMS_REPORT_F_(
"landings_numbers_at_age", landings_numbers_at_age_f,
1433 FIMS_REPORT_F_(
"landings_numbers_at_length", landings_numbers_at_length_f,
1436 FIMS_REPORT_F_(
"landings_weight_at_age", landings_weight_at_age_f,
1465 typename std::map<std::string, fims::Vector<fims::Vector<Type>>>::iterator
1469 auto &
x =
rvit->second;
1485 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:538
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:569
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:861
void evaluate_age_comp()
Definition catch_at_age.hpp:878
void evaluate_length_comp()
Definition catch_at_age.hpp:946
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:483
CatchAtAge()
Definition catch_at_age.hpp:126
virtual void Evaluate()
Evaluate the model.
Definition catch_at_age.hpp:1051
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:510
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:798
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:456
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:664
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:760
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:622
void evaluate_landings()
Definition catch_at_age.hpp:1033
virtual void Report()
Definition catch_at_age.hpp:1194
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:729
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:689
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:829
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:1012
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:79
The population dynamics of FIMS.
Definition catch_at_age.hpp:41
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:235
Population class. Contains subpopulations that are divided into generic partitions (e....
Definition population.hpp:25