FIMS  v0.8.0
Loading...
Searching...
No Matches
fishery_model_base.hpp
Go to the documentation of this file.
1
9#ifndef FIMS_MODELS_FISHERY_MODEL_BASE_HPP
10#define FIMS_MODELS_FISHERY_MODEL_BASE_HPP
11
12#include "../../common/model_object.hpp"
13#include "../../common/fims_math.hpp"
14#include "../../common/fims_vector.hpp"
15#include "../../population_dynamics/population/population.hpp"
20namespace fims_popdy {
21
26 std::string name;
27 int ndims;
36
47
56
61 if (this != &other) {
62 name = other.name;
63 ndims = other.ndims;
64 dims = other.dims;
65 dim_names = other.dim_names;
66 se_values_m = other.se_values_m;
67 }
68 return *this;
69 }
70};
71
82 std::string name;
90 size_t start_m;
94 size_t length_m;
95
100
109 UncertaintyReportInfo(const std::string &name, uint32_t id, size_t start,
110 size_t length)
111 : name(name), id_m(id), start_m(start), length_m(length) {}
112
122};
123
128template <typename Type>
130 static uint32_t id_g;
132 uint32_t id;
134 public:
135#ifdef TMB_MODEL
136 bool do_reporting =
137 true;
138#endif
143 std::string model_type_m;
148 std::set<uint32_t> population_ids;
153 std::vector<std::shared_ptr<fims_popdy::Population<Type>>> populations;
159 std::map<uint32_t, std::shared_ptr<fims_popdy::Fleet<Type>>> fleets;
164 typedef typename std::map<uint32_t,
165 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
167
172 typedef typename std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>
174
178 typedef typename DerivedQuantitiesMap::iterator DerivedQuantitiesMapIterator;
179
183 std::shared_ptr<DerivedQuantitiesMap> fleet_derived_quantities;
184
188 std::shared_ptr<DerivedQuantitiesMap> population_derived_quantities;
189
193 typedef typename std::map<uint32_t, std::map<std::string, DimensionInfo>>
195
199 std::shared_ptr<DimensionInfoMap> fleet_dimension_info;
200
204 std::shared_ptr<DimensionInfoMap> population_dimension_info;
205
209 typedef
210 typename std::map<uint32_t, std::map<std::string, UncertaintyReportInfo>>
212
216 std::shared_ptr<UncertaintyReportInfoMap> fleet_uncertainty_report_info;
217
222 std::shared_ptr<UncertaintyReportInfoMap> population_uncertainty_report_info;
223
224#ifdef TMB_MODEL
226#endif
232 fleet_derived_quantities = std::make_shared<DerivedQuantitiesMap>();
233 population_derived_quantities = std::make_shared<DerivedQuantitiesMap>();
234 fleet_dimension_info = std::make_shared<DimensionInfoMap>();
235 population_dimension_info = std::make_shared<DimensionInfoMap>();
236 }
237
251
256 virtual ~FisheryModelBase() {}
257
263 std::map<uint32_t, std::map<std::string, DimensionInfo>> &
267
273 std::map<uint32_t, std::map<std::string, DimensionInfo>> &
277
286
295
302 std::map<std::string, fims::Vector<Type>> &GetFleetDerivedQuantities(
305 throw std::runtime_error(
306 "GetFleetDerivedQuantities: fleet_derived_quantities is null");
307 }
309 auto it = outer.find(fleet_id);
310 if (it == outer.end()) {
311 std::stringstream ss;
312
313 ss << "GetFleetDerivedQuantities: fleet_id " << fleet_id
314 << " not found in fleet_derived_quantities";
315 throw std::out_of_range(ss.str());
316 }
317 return it->second;
318 }
319
329 // Ensure the shared_ptr exists
331 fleet_derived_quantities = std::make_shared<
332 std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>>();
333 }
334
336
337 // Insert only if not already present
338 if (outer.find(fleet_id) == outer.end()) {
339 outer.emplace(fleet_id, std::map<std::string, fims::Vector<Type>>{});
340 }
341 }
342
352 // Ensure the shared_ptr exists
354 population_derived_quantities = std::make_shared<
355 std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>>();
356 }
357
359
360 // Insert only if not already present
361 if (outer.find(population_id) == outer.end()) {
362 outer.emplace(population_id, std::map<std::string, fims::Vector<Type>>{});
363 }
364 }
365
372 std::map<std::string, fims::Vector<Type>> &GetPopulationDerivedQuantities(
375 throw std::runtime_error(
376 "GetPopulationDerivedQuantities: population_derived_quantities is "
377 "null");
378 }
380 auto it = outer.find(population_id);
381 if (it == outer.end()) {
382 std::ostringstream ss;
383 ss << "GetPopulationDerivedQuantities: population_id " << population_id
384 << " not found in population_derived_quantities";
385 throw std::out_of_range(ss.str());
386 }
387 return it->second;
388 }
389
396 std::map<std::string, DimensionInfo> &GetFleetDimensionInfo(
399 }
400
407 std::map<std::string, DimensionInfo> &GetPopulationDimensionInfo(
410 }
411
418
425
432 std::map<std::string, UncertaintyReportInfo> &GetFleetUncertaintyReportInfo(
435 }
436
444 std::map<std::string, UncertaintyReportInfo> &
448
453 virtual void Initialize() {}
454
459 virtual void Prepare() {}
460
468 virtual void ResetVector(fims::Vector<Type> &v, Type value = 0.0) {
469 std::fill(v.begin(), v.end(), value);
470 }
471
476 virtual void Evaluate() {}
477
482 virtual void Report() {}
483
489 uint32_t GetId() { return this->id; }
490};
491
492template <typename Type>
493uint32_t FisheryModelBase<Type>::id_g = 0;
494
495} // namespace fims_popdy
496#endif
Definition fims_vector.hpp:27
FisheryModelBase is a base class for fishery models in FIMS.
Definition fishery_model_base.hpp:129
std::shared_ptr< DimensionInfoMap > population_dimension_info
Shared pointer for the population dimension information map.
Definition fishery_model_base.hpp:204
UncertaintyReportInfoMap & GetPopulationUncertaintyReportInfo()
Get the population uncertainty report information.
Definition fishery_model_base.hpp:422
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
DerivedQuantitiesMap::iterator DerivedQuantitiesMapIterator
Iterator for the derived quantities map.
Definition fishery_model_base.hpp:178
FisheryModelBase()
Construct a new Fishery Model Base object.
Definition fishery_model_base.hpp:231
std::map< uint32_t, std::map< std::string, fims::Vector< Type > > > DerivedQuantitiesMap
Type definitions for derived quantities and dimension information maps.
Definition fishery_model_base.hpp:173
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > populations
A vector of populations in the fishery model.
Definition fishery_model_base.hpp:153
virtual void Evaluate()
Evaluate the model.
Definition fishery_model_base.hpp:476
FisheryModelBase(const FisheryModelBase &other)
Construct a new Fishery Model Base object.
Definition fishery_model_base.hpp:243
std::shared_ptr< UncertaintyReportInfoMap > population_uncertainty_report_info
Shared pointer for the population uncertainty report information map.
Definition fishery_model_base.hpp:222
void InitializePopulationDerivedQuantities(uint32_t population_id)
Initialize the derived quantities map for a population.
Definition fishery_model_base.hpp:351
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
void InitializeFleetDerivedQuantities(uint32_t fleet_id)
Initialize the derived quantities map for a fleet.
Definition fishery_model_base.hpp:328
std::set< uint32_t > population_ids
Unique identifier for the fishery model.
Definition fishery_model_base.hpp:148
std::map< std::string, fims::Vector< Type > > & GetFleetDerivedQuantities(uint32_t fleet_id)
Get the fleet derived quantities for a specified fleet.
Definition fishery_model_base.hpp:302
std::map< std::string, fims::Vector< Type > > & GetPopulationDerivedQuantities(uint32_t population_id)
Get the population derived quantities for a specified population.
Definition fishery_model_base.hpp:372
std::map< std::string, DimensionInfo > & GetPopulationDimensionInfo(uint32_t population_id)
Get the population dimension information for a specified population.
Definition fishery_model_base.hpp:407
std::shared_ptr< UncertaintyReportInfoMap > fleet_uncertainty_report_info
Shared pointer for the uncertainty report information map.
Definition fishery_model_base.hpp:216
std::shared_ptr< DerivedQuantitiesMap > population_derived_quantities
Shared pointer for the population derived quantities map.
Definition fishery_model_base.hpp:188
virtual void Initialize()
Initialize a model.
Definition fishery_model_base.hpp:453
std::map< uint32_t, std::map< std::string, DimensionInfo > > DimensionInfoMap
Type definitions for dimension information maps.
Definition fishery_model_base.hpp:194
virtual ~FisheryModelBase()
Destroy the Fishery Model Base object.
Definition fishery_model_base.hpp:256
std::map< std::string, DimensionInfo > & GetFleetDimensionInfo(uint32_t fleet_id)
Get the fleet dimension information for a specified fleet.
Definition fishery_model_base.hpp:396
std::map< uint32_t, std::map< std::string, UncertaintyReportInfo > > UncertaintyReportInfoMap
Type definition for the uncertainty report information map.
Definition fishery_model_base.hpp:211
std::map< uint32_t, std::map< std::string, DimensionInfo > > & GetPopulationDimensionInfo()
Get the population dimension information.
Definition fishery_model_base.hpp:274
std::map< std::string, UncertaintyReportInfo > & GetPopulationUncertaintyReportInfo(uint32_t population_id)
Get the population uncertainty report information for a specified population.
Definition fishery_model_base.hpp:445
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Fleet-based iterator.
Definition fishery_model_base.hpp:166
std::map< std::string, UncertaintyReportInfo > & GetFleetUncertaintyReportInfo(uint32_t fleet_id)
Get the fleet uncertainty report information for a specified fleet.
Definition fishery_model_base.hpp:432
std::shared_ptr< DimensionInfoMap > fleet_dimension_info
Shared pointer for the fleet dimension information map.
Definition fishery_model_base.hpp:199
std::shared_ptr< DerivedQuantitiesMap > fleet_derived_quantities
Shared pointer for the fleet derived quantities map.
Definition fishery_model_base.hpp:183
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
virtual void Report()
Report the model results via TMB.
Definition fishery_model_base.hpp:482
std::map< uint32_t, std::map< std::string, DimensionInfo > > & GetFleetDimensionInfo()
Get the fleet dimension information.
Definition fishery_model_base.hpp:264
UncertaintyReportInfoMap & GetFleetUncertaintyReportInfo()
Get the fleet uncertainty report information.
Definition fishery_model_base.hpp:415
virtual void Prepare()
Prepare the model.
Definition fishery_model_base.hpp:459
The population dynamics of FIMS.
Definition catch_at_age.hpp:41
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:279
FIMSObject struct that defines member types and returns the unique id.
Definition model_object.hpp:25
Structure to hold dimension information for derived quantities.
Definition fishery_model_base.hpp:25
fims::Vector< int > dims
Definition fishery_model_base.hpp:28
std::string name
Definition fishery_model_base.hpp:26
DimensionInfo()
Default constructor for dimension information.
Definition fishery_model_base.hpp:35
DimensionInfo(const DimensionInfo &other)
Definition fishery_model_base.hpp:51
int ndims
Definition fishery_model_base.hpp:27
fims::Vector< double > se_values_m
Definition fishery_model_base.hpp:30
DimensionInfo(const std::string &name, const fims::Vector< int > &dims, const fims::Vector< std::string > &dim_names)
Constructor with parameters.
Definition fishery_model_base.hpp:44
DimensionInfo & operator=(const DimensionInfo &other)
Assignment operator for DimensionInfo.
Definition fishery_model_base.hpp:60
fims::Vector< std::string > dim_names
Definition fishery_model_base.hpp:29
Definition fishery_model_base.hpp:78
UncertaintyReportInfo(const UncertaintyReportInfo &other)
Copy constructor.
Definition fishery_model_base.hpp:117
std::string name
Definition fishery_model_base.hpp:82
uint32_t id_m
Definition fishery_model_base.hpp:86
UncertaintyReportInfo()
Default constructor for UncertaintyReportInfo.
Definition fishery_model_base.hpp:99
UncertaintyReportInfo(const std::string &name, uint32_t id, size_t start, size_t length)
Constructor with parameters.
Definition fishery_model_base.hpp:109
size_t start_m
Definition fishery_model_base.hpp:90
size_t length_m
Definition fishery_model_base.hpp:94