8#ifndef FIMS_MODELS_CATCH_AT_AGE_HPP
9#define FIMS_MODELS_CATCH_AT_AGE_HPP
43template <
typename Type>
63 typedef typename std::map<std::string, fims::Vector<Type>>::iterator
71 std::map<std::string, fims::Vector<Type>>>::iterator
79 std::map<std::string, fims::Vector<size_t>>>::iterator
86 std::map<std::string, fims::Vector<Type>>>::iterator
95 std::map<std::string, fims::Vector<size_t>>>::iterator
103 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
110 typename std::map<std::string, fims::Vector<Type>>::iterator
dq_iterator;
125 std::stringstream
ss;
126 ss <<
"caa_" << this->
GetId() <<
"_";
127 this->name_m =
ss.str();
167 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
169 if (
fleet->log_q.size() == 0) {
170 fleet->log_q.resize(1);
171 fleet->log_q[0] =
static_cast<Type>(0.0);
184 std::shared_ptr<fims_popdy::Population<Type>> &
population =
196 for (
size_t age = 0;
age < population->n_ages;
age++) {
217 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
226 for (
size_t i = 0;
i < fleet->log_q.size();
i++) {
269 std::map<std::string, fims::Vector<Type>> &
dq_ =
303 std::map<std::string, fims::Vector<Type>> &
dq_ =
344 std::map<std::string, fims::Vector<Type>> &
dq_ =
395 std::map<std::string, fims::Vector<Type>> &
dq_ =
432 std::map<std::string, fims::Vector<Type>> &
dq_ =
456 std::map<std::string, fims::Vector<Type>> &
dq_ =
459 dq_[
"unfished_biomass"][
year] +=
483 std::map<std::string, fims::Vector<Type>> &
dq_ =
486 dq_[
"spawning_biomass"][
year] +=
510 std::map<std::string, fims::Vector<Type>> &
dq_ =
513 dq_[
"unfished_spawning_biomass"][
year] +=
537 std::map<std::string, fims::Vector<Type>> &
dq_ =
540 dq_[
"spawning_biomass"][
year] /
dq_[
"unfished_spawning_biomass"][0];
568 std::map<std::string, fims::Vector<Type>> &
dq_ =
574 dq_[
"proportion_mature_at_age"][0] *
579 dq_[
"proportion_mature_at_age"][
a] *
622 std::map<std::string, fims::Vector<Type>> &
dq_ =
638 fims_math::log(
population->recruitment->evaluate_mean(
664 std::map<std::string, fims::Vector<Type>> &
dq_ =
697 std::map<std::string, fims::Vector<Type>> &
pdq_ =
701 std::map<std::string, fims::Vector<Type>> &
fdq_ =
705 pdq_[
"total_landings_weight"][
year] +=
711 pdq_[
"total_landings_numbers"][
year] +=
742 std::map<std::string, fims::Vector<Type>> &
fdq_ =
780 std::map<std::string, fims::Vector<Type>> &
pdq_ =
784 std::map<std::string, fims::Vector<Type>> &
fdq_ =
788 fdq_[
"landings_numbers_at_age"][
i_age_year] +=
826 std::map<std::string, fims::Vector<Type>> &
fdq_ =
865 std::map<std::string, fims::Vector<Type>> &
pdq_ =
869 std::map<std::string, fims::Vector<Type>> &
fdq_ =
902 std::map<std::string, fims::Vector<Type>> &
fdq_ =
917 std::map<std::string, fims::Vector<Type>> &
fdq_ =
920 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
921 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
932 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
940 if (
fleet->fleet_observed_landings_data_id_m == -999) {
957 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
959 fleet->observed_agecomp_data->na_value) {
964 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
970 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
985 std::map<std::string, fims::Vector<Type>> &
fdq_ =
988 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
990 if (
fleet->n_lengths > 0) {
991 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
1001 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
1003 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
1022 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
1024 fleet->observed_lengthcomp_data->na_value) {
1029 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
1035 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
1051 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1053 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1055 for (
size_t i = 0;
i <
fdq_[
"index_numbers"].size();
i++) {
1056 if (
fleet->observed_index_units ==
"number") {
1057 fdq_[
"index_expected"][
i] =
fdq_[
"index_numbers"][
i];
1059 fdq_[
"index_expected"][
i] =
fdq_[
"index_weight"][
i];
1061 fdq_[
"log_index_expected"][
i] =
log(
fdq_[
"index_expected"][
i]);
1072 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1074 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1076 for (
size_t i = 0;
i <
fdq_[
"landings_weight"].size();
i++) {
1077 if (
fleet->observed_landings_units ==
"number") {
1078 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_numbers"][
i];
1080 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_weight"][
i];
1082 fdq_[
"log_landings_expected"][
i] =
log(
fdq_[
"landings_expected"][
i]);
1112 std::shared_ptr<fims_popdy::Population<Type>> &
population =
1114 std::map<std::string, fims::Vector<Type>> &
pdq_ =
1159 pdq_[
"expected_recruitment"][
y] =
1162 fims_math::exp(
population->recruitment->log_rzero[0]);
1173 fims_math::exp(
population->recruitment->log_rzero[0]);
1231 int n_fleets = this->
fleets.size();
1235 report_vectors.clear();
1288 this->
populations[
p]->create_report_vectors(report_vectors);
1293 this->
populations[
p]->maturity->create_report_vectors(report_vectors);
1294 this->
populations[
p]->growth->create_report_vectors(report_vectors);
1295 this->
populations[
p]->recruitment->create_report_vectors(
1336 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1405 vector<Type> spawning_biomass_ratio =
1433 vector<Type> lengthcomp_proportion =
1436 vector<Type> log_landings_expected =
1446 FIMS_REPORT_F_(
"proportion_mature_at_age", proportion_mature_at_age_p,
1450 FIMS_REPORT_F_(
"total_landings_numbers", total_landings_numbers_p,
1455 FIMS_REPORT_F_(
"unfished_numbers_at_age", unfished_numbers_at_age_p,
1457 FIMS_REPORT_F_(
"unfished_spawning_biomass", unfished_spawning_biomass_p,
1461 FIMS_REPORT_F_(
"spawning_biomass_ratio", spawning_biomass_ratio_p,
1491 FIMS_REPORT_F_(
"index_numbers_at_length", index_numbers_at_length_f,
1497 FIMS_REPORT_F_(
"landings_numbers_at_age", landings_numbers_at_age_f,
1499 FIMS_REPORT_F_(
"landings_numbers_at_length", landings_numbers_at_length_f,
1502 FIMS_REPORT_F_(
"landings_weight_at_age", landings_weight_at_age_f,
1531 typename std::map<std::string, fims::Vector<fims::Vector<Type>>>::iterator
1535 auto &x =
rvit->second;
1551 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:51
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:535
std::map< std::string, fims::Vector< Type > >::iterator dq_iterator
Iterate through derived quantities.
Definition catch_at_age.hpp:110
std::map< std::string, fims::Vector< Type > >::iterator derived_quantities_iterator
Iterate the derived quantities.
Definition catch_at_age.hpp:64
Type CalculateSBPR0(std::shared_ptr< fims_popdy::Population< Type > > &population)
Calculates equilibrium spawning biomass per recruit.
Definition catch_at_age.hpp:566
virtual void Initialize()
Definition catch_at_age.hpp:151
std::vector< Type > ages
Definition catch_at_age.hpp:119
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:341
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:429
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:116
std::set< uint32_t > & GetPopulationIds()
Get the population ids of the model.
Definition catch_at_age.hpp:243
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:96
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Iterate through fleets.
Definition catch_at_age.hpp:104
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:897
void evaluate_age_comp()
Definition catch_at_age.hpp:914
void evaluate_length_comp()
Definition catch_at_age.hpp:982
virtual ~CatchAtAge()
Destroy the Catch At Age object.
Definition catch_at_age.hpp:145
CatchAtAge(const CatchAtAge &other)
Copy constructor for the CatchAtAge class.
Definition catch_at_age.hpp:136
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:480
CatchAtAge()
Definition catch_at_age.hpp:124
virtual void Evaluate()
Evaluate the model.
Definition catch_at_age.hpp:1087
std::string name_m
The name of the model.
Definition catch_at_age.hpp:57
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:507
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:823
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:453
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:72
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:661
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:87
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:298
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:777
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:619
void evaluate_landings()
Definition catch_at_age.hpp:1069
virtual void Report()
Definition catch_at_age.hpp:1230
void AddPopulation(uint32_t id)
Definition catch_at_age.hpp:238
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:737
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > & GetPopulations()
Definition catch_at_age.hpp:250
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:80
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:694
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:392
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:862
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:266
virtual void Prepare()
Definition catch_at_age.hpp:182
void evaluate_index()
Definition catch_at_age.hpp:1048
FisheryModelBase is a base class for fishery models in FIMS.
Definition fishery_model_base.hpp:129
uint32_t GetId()
Get the Id object.
Definition fishery_model_base.hpp:489
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:159
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > populations
A vector of populations in the fishery model.
Definition fishery_model_base.hpp:153
std::string model_type_m
A string specifying the model type.
Definition fishery_model_base.hpp:143
DerivedQuantitiesMap & GetFleetDerivedQuantities()
Get the fleet derived quantities.
Definition fishery_model_base.hpp:283
std::set< uint32_t > population_ids
Unique identifier for the fishery model.
Definition fishery_model_base.hpp:148
DerivedQuantitiesMap & GetPopulationDerivedQuantities()
Get the population derived quantities.
Definition fishery_model_base.hpp:292
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:468
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:279
Population class. Contains subpopulations that are divided into generic partitions (e....
Definition population.hpp:25