FIMS  v0.8.1
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
76template <typename Type>
78 static uint32_t id_g;
80 uint32_t id;
82 public:
83#ifdef TMB_MODEL
84 bool do_reporting =
85 true;
86#endif
91 std::string model_type_m;
96 std::set<uint32_t> population_ids;
101 std::vector<std::shared_ptr<fims_popdy::Population<Type>>> populations;
107 std::map<uint32_t, std::shared_ptr<fims_popdy::Fleet<Type>>> fleets;
112 typedef typename std::map<uint32_t,
113 std::shared_ptr<fims_popdy::Fleet<Type>>>::iterator
115
120 typedef typename std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>
122
126 typedef typename DerivedQuantitiesMap::iterator DerivedQuantitiesMapIterator;
127
131 std::shared_ptr<DerivedQuantitiesMap> fleet_derived_quantities;
132
136 std::shared_ptr<DerivedQuantitiesMap> population_derived_quantities;
137
141 typedef typename std::map<uint32_t, std::map<std::string, DimensionInfo>>
143
147 std::shared_ptr<DimensionInfoMap> fleet_dimension_info;
148
152 std::shared_ptr<DimensionInfoMap> population_dimension_info;
153
154#ifdef TMB_MODEL
156#endif
162 fleet_derived_quantities = std::make_shared<DerivedQuantitiesMap>();
163 population_derived_quantities = std::make_shared<DerivedQuantitiesMap>();
164 fleet_dimension_info = std::make_shared<DimensionInfoMap>();
165 population_dimension_info = std::make_shared<DimensionInfoMap>();
166 }
167
181
186 virtual ~FisheryModelBase() {}
187
193 std::map<uint32_t, std::map<std::string, DimensionInfo>> &
197
203 std::map<uint32_t, std::map<std::string, DimensionInfo>> &
207
216
225
232 std::map<std::string, fims::Vector<Type>> &GetFleetDerivedQuantities(
235 throw std::runtime_error(
236 "GetFleetDerivedQuantities: fleet_derived_quantities is null");
237 }
239 auto it = outer.find(fleet_id);
240 if (it == outer.end()) {
241 std::stringstream ss;
242
243 ss << "GetFleetDerivedQuantities: fleet_id " << fleet_id
244 << " not found in fleet_derived_quantities";
245 throw std::out_of_range(ss.str());
246 }
247 return it->second;
248 }
249
259 // Ensure the shared_ptr exists
261 fleet_derived_quantities = std::make_shared<
262 std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>>();
263 }
264
266
267 // Insert only if not already present
268 if (outer.find(fleet_id) == outer.end()) {
269 outer.emplace(fleet_id, std::map<std::string, fims::Vector<Type>>{});
270 }
271 }
272
282 // Ensure the shared_ptr exists
284 population_derived_quantities = std::make_shared<
285 std::map<uint32_t, std::map<std::string, fims::Vector<Type>>>>();
286 }
287
289
290 // Insert only if not already present
291 if (outer.find(population_id) == outer.end()) {
292 outer.emplace(population_id, std::map<std::string, fims::Vector<Type>>{});
293 }
294 }
295
302 std::map<std::string, fims::Vector<Type>> &GetPopulationDerivedQuantities(
305 throw std::runtime_error(
306 "GetPopulationDerivedQuantities: population_derived_quantities is "
307 "null");
308 }
310 auto it = outer.find(population_id);
311 if (it == outer.end()) {
312 std::ostringstream ss;
313 ss << "GetPopulationDerivedQuantities: population_id " << population_id
314 << " not found in population_derived_quantities";
315 throw std::out_of_range(ss.str());
316 }
317 return it->second;
318 }
319
326 std::map<std::string, DimensionInfo> &GetFleetDimensionInfo(
329 }
330
337 std::map<std::string, DimensionInfo> &GetPopulationDimensionInfo(
340 }
341
346 virtual void Initialize() {}
347
352 virtual void Prepare() {}
353
361 virtual void ResetVector(fims::Vector<Type> &v, Type value = 0.0) {
362 std::fill(v.begin(), v.end(), value);
363 }
364
369 virtual void Evaluate() {}
370
375 virtual void Report() {}
376
382 uint32_t GetId() { return this->id; }
383};
384
385template <typename Type>
386uint32_t FisheryModelBase<Type>::id_g = 0;
387
388} // namespace fims_popdy
389#endif
Definition fims_vector.hpp:27
FisheryModelBase is a base class for fishery models in FIMS.
Definition fishery_model_base.hpp:77
std::shared_ptr< DimensionInfoMap > population_dimension_info
Shared pointer for the population dimension information map.
Definition fishery_model_base.hpp:152
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
DerivedQuantitiesMap::iterator DerivedQuantitiesMapIterator
Iterator for the derived quantities map.
Definition fishery_model_base.hpp:126
FisheryModelBase()
Construct a new Fishery Model Base object.
Definition fishery_model_base.hpp:161
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:121
std::vector< std::shared_ptr< fims_popdy::Population< Type > > > populations
A vector of populations in the fishery model.
Definition fishery_model_base.hpp:101
virtual void Evaluate()
Evaluate the model.
Definition fishery_model_base.hpp:369
FisheryModelBase(const FisheryModelBase &other)
Construct a new Fishery Model Base object.
Definition fishery_model_base.hpp:173
void InitializePopulationDerivedQuantities(uint32_t population_id)
Initialize the derived quantities map for a population.
Definition fishery_model_base.hpp:281
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
void InitializeFleetDerivedQuantities(uint32_t fleet_id)
Initialize the derived quantities map for a fleet.
Definition fishery_model_base.hpp:258
std::set< uint32_t > population_ids
Unique identifier for the fishery model.
Definition fishery_model_base.hpp:96
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:232
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:302
std::map< std::string, DimensionInfo > & GetPopulationDimensionInfo(uint32_t population_id)
Get the population dimension information for a specified population.
Definition fishery_model_base.hpp:337
std::shared_ptr< DerivedQuantitiesMap > population_derived_quantities
Shared pointer for the population derived quantities map.
Definition fishery_model_base.hpp:136
virtual void Initialize()
Initialize a model.
Definition fishery_model_base.hpp:346
std::map< uint32_t, std::map< std::string, DimensionInfo > > DimensionInfoMap
Type definitions for dimension information maps.
Definition fishery_model_base.hpp:142
virtual ~FisheryModelBase()
Destroy the Fishery Model Base object.
Definition fishery_model_base.hpp:186
std::map< std::string, DimensionInfo > & GetFleetDimensionInfo(uint32_t fleet_id)
Get the fleet dimension information for a specified fleet.
Definition fishery_model_base.hpp:326
std::map< uint32_t, std::map< std::string, DimensionInfo > > & GetPopulationDimensionInfo()
Get the population dimension information.
Definition fishery_model_base.hpp:204
std::map< uint32_t, std::shared_ptr< fims_popdy::Fleet< Type > > >::iterator fleet_iterator
Fleet-based iterator.
Definition fishery_model_base.hpp:114
std::shared_ptr< DimensionInfoMap > fleet_dimension_info
Shared pointer for the fleet dimension information map.
Definition fishery_model_base.hpp:147
std::shared_ptr< DerivedQuantitiesMap > fleet_derived_quantities
Shared pointer for the fleet derived quantities map.
Definition fishery_model_base.hpp:131
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
virtual void Report()
Report the model results via TMB.
Definition fishery_model_base.hpp:375
std::map< uint32_t, std::map< std::string, DimensionInfo > > & GetFleetDimensionInfo()
Get the fleet dimension information.
Definition fishery_model_base.hpp:194
virtual void Prepare()
Prepare the model.
Definition fishery_model_base.hpp:352
The population dynamics of FIMS.
Definition catch_at_age.hpp:41
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:239
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