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();
155 if (this->
populations[
p]->proportion_female.size() == 0) {
171 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
173 if (
fleet->log_q.size() == 0) {
174 fleet->log_q.resize(1);
175 fleet->log_q[0] =
static_cast<Type>(0.0);
188 std::shared_ptr<fims_popdy::Population<Type>> &
population =
200 for (
size_t age = 0;
age < population->n_ages;
age++) {
216 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
225 for (
size_t i = 0;
i < fleet->log_q.size();
i++) {
268 std::map<std::string, fims::Vector<Type>> &
dq_ =
302 std::map<std::string, fims::Vector<Type>> &
dq_ =
343 std::map<std::string, fims::Vector<Type>> &
dq_ =
394 std::map<std::string, fims::Vector<Type>> &
dq_ =
431 std::map<std::string, fims::Vector<Type>> &
dq_ =
434 dq_[
"biomass"][
year] +=
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] +=
511 std::map<std::string, fims::Vector<Type>> &
dq_ =
514 dq_[
"unfished_spawning_biomass"][
year] +=
538 std::map<std::string, fims::Vector<Type>> &
dq_ =
541 dq_[
"spawning_biomass"][
year] /
dq_[
"unfished_spawning_biomass"][0];
569 std::map<std::string, fims::Vector<Type>> &
dq_ =
575 population->proportion_female.get_force_scalar(0) *
576 dq_[
"proportion_mature_at_age"][0] *
581 population->proportion_female.get_force_scalar(
a) *
582 dq_[
"proportion_mature_at_age"][
a] *
626 std::map<std::string, fims::Vector<Type>> &
dq_ =
642 fims_math::log(
population->recruitment->evaluate_mean(
668 std::map<std::string, fims::Vector<Type>> &
dq_ =
693 std::map<std::string, fims::Vector<Type>> &
pdq_ =
697 std::map<std::string, fims::Vector<Type>> &
fdq_ =
701 pdq_[
"total_landings_weight"][
year] +=
707 pdq_[
"total_landings_numbers"][
year] +=
735 std::map<std::string, fims::Vector<Type>> &
fdq_ =
764 std::map<std::string, fims::Vector<Type>> &
pdq_ =
768 std::map<std::string, fims::Vector<Type>> &
fdq_ =
772 fdq_[
"landings_numbers_at_age"][
i_age_year] +=
802 std::map<std::string, fims::Vector<Type>> &
fdq_ =
833 std::map<std::string, fims::Vector<Type>> &
pdq_ =
837 std::map<std::string, fims::Vector<Type>> &
fdq_ =
867 std::map<std::string, fims::Vector<Type>> &
fdq_ =
882 std::map<std::string, fims::Vector<Type>> &
fdq_ =
885 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
886 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
897 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
905 if (
fleet->fleet_observed_landings_data_id_m == -999) {
922 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
924 fleet->observed_agecomp_data->na_value) {
929 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
935 if (
fleet->fleet_observed_agecomp_data_id_m != -999) {
950 std::map<std::string, fims::Vector<Type>> &
fdq_ =
953 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
955 if (
fleet->n_lengths > 0) {
956 for (
size_t y = 0;
y <
fleet->n_years;
y++) {
966 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
968 for (
size_t a = 0;
a <
fleet->n_ages;
a++) {
987 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
989 fleet->observed_lengthcomp_data->na_value) {
994 for (
size_t l = 0;
l <
fleet->n_lengths;
l++) {
1000 if (
fleet->fleet_observed_lengthcomp_data_id_m != -999) {
1016 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1018 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1020 for (
size_t i = 0;
i <
fdq_[
"index_numbers"].size();
i++) {
1021 if (
fleet->observed_index_units ==
"number") {
1022 fdq_[
"index_expected"][
i] =
fdq_[
"index_numbers"][
i];
1024 fdq_[
"index_expected"][
i] =
fdq_[
"index_weight"][
i];
1026 fdq_[
"log_index_expected"][
i] =
log(
fdq_[
"index_expected"][
i]);
1037 std::map<std::string, fims::Vector<Type>> &
fdq_ =
1039 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1041 for (
size_t i = 0;
i <
fdq_[
"landings_weight"].size();
i++) {
1042 if (
fleet->observed_landings_units ==
"number") {
1043 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_numbers"][
i];
1045 fdq_[
"landings_expected"][
i] =
fdq_[
"landings_weight"][
i];
1047 fdq_[
"log_landings_expected"][
i] =
log(
fdq_[
"landings_expected"][
i]);
1077 std::shared_ptr<fims_popdy::Population<Type>> &
population =
1079 std::map<std::string, fims::Vector<Type>> &
pdq_ =
1124 pdq_[
"expected_recruitment"][
y] =
1127 fims_math::exp(
population->recruitment->log_rzero[0]);
1138 fims_math::exp(
population->recruitment->log_rzero[0]);
1196 int n_fleets = this->
fleets.size();
1200 report_vectors.clear();
1278 std::shared_ptr<fims_popdy::Fleet<Type>> &
fleet = (*fit).second;
1345 vector<Type> spawning_biomass_ratio =
1372 vector<Type> lengthcomp_proportion =
1375 vector<Type> log_landings_expected =
1385 FIMS_REPORT_F_(
"proportion_mature_at_age", proportion_mature_at_age_p,
1389 FIMS_REPORT_F_(
"total_landings_numbers", total_landings_numbers_p,
1394 FIMS_REPORT_F_(
"unfished_numbers_at_age", unfished_numbers_at_age_p,
1396 FIMS_REPORT_F_(
"unfished_spawning_biomass", unfished_spawning_biomass_p,
1398 FIMS_REPORT_F_(
"spawning_biomass_ratio", spawning_biomass_ratio_p,
1426 FIMS_REPORT_F_(
"index_numbers_at_length", index_numbers_at_length_f,
1432 FIMS_REPORT_F_(
"landings_numbers_at_age", landings_numbers_at_age_f,
1434 FIMS_REPORT_F_(
"landings_numbers_at_length", landings_numbers_at_length_f,
1437 FIMS_REPORT_F_(
"landings_weight_at_age", landings_weight_at_age_f,
1466 typename std::map<std::string, fims::Vector<fims::Vector<Type>>>::iterator
1470 auto &
x =
rvit->second;
1486 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:536
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:567
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:340
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:428
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:242
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:862
void evaluate_age_comp()
Definition catch_at_age.hpp:879
void evaluate_length_comp()
Definition catch_at_age.hpp:947
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:480
CatchAtAge()
Definition catch_at_age.hpp:126
virtual void Evaluate()
Evaluate the model.
Definition catch_at_age.hpp:1052
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:508
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:799
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: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:665
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:297
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:761
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:623
void evaluate_landings()
Definition catch_at_age.hpp:1034
virtual void Report()
Definition catch_at_age.hpp:1195
void AddPopulation(uint32_t id)
Definition catch_at_age.hpp:237
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:730
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > & GetPopulations()
Definition catch_at_age.hpp:249
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:690
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:391
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:830
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:265
virtual void Prepare()
Definition catch_at_age.hpp:186
void evaluate_index()
Definition catch_at_age.hpp:1013
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