FIMS  v0.10.0
Loading...
Searching...
No Matches
runtime.hpp
Go to the documentation of this file.
1
9#ifndef POPULATION_DYNAMICS_AGE_TO_LENGTH_CONVERSION_RUNTIME_HPP
10#define POPULATION_DYNAMICS_AGE_TO_LENGTH_CONVERSION_RUNTIME_HPP
11
12#include <cstddef>
13#include <memory>
14#include <sstream>
15#include <stdexcept>
16
17#include "base.hpp"
18#include "fixed.hpp"
19#include "derived.hpp"
21
22namespace fims_popdy {
23
42template <typename Type>
43std::shared_ptr<AgeToLengthConversionBase<Type>>
45 const std::shared_ptr<Population<Type>>& population,
46 const std::shared_ptr<Fleet<Type>>& fleet) {
47 if (population == nullptr || fleet == nullptr) {
48 return nullptr;
49 }
50
51 if (!fleet->requires_age_length_mapping || fleet->n_lengths == 0) {
52 return nullptr;
53 }
54
56 std::dynamic_pointer_cast<GrowthDerivedObservationBase<Type>>(
57 population->growth)) {
58 std::shared_ptr<AgeToLengthConversionBase<Type>>
60 std::make_shared<AgeToLengthConversionDerived<Type>>(
61 fleet, growth_observation,
62 population->size_distribution_provider);
63
64 if (age_to_length_conversion_derived->IsActive() &&
65 age_to_length_conversion_derived->PrepareForCurrentState()) {
67 "Growth-derived age-to-length conversion successfully set to fleet " +
68 fims::to_string(fleet->id) + " for population " +
69 fims::to_string(population->id));
71 }
72 return nullptr;
73 }
74
75 std::shared_ptr<AgeToLengthConversionBase<Type>>
77 std::make_shared<AgeToLengthConversionFixed<Type>>(fleet);
78
79 if (age_to_length_conversion_fixed->IsActive() &&
80 age_to_length_conversion_fixed->PrepareForCurrentState()) {
81 FIMS_INFO_LOG("Fixed age-to-length matrix successfully set to fleet " +
82 fims::to_string(fleet->id));
84 }
85
86 return nullptr;
87}
88
104template <typename Type>
106 const std::shared_ptr<Population<Type>>& population,
107 const std::shared_ptr<Fleet<Type>>& fleet) {
108 if (fleet == nullptr) {
109 throw std::runtime_error(
110 "Fleet pointer was null while resolving age-to-length conversion.");
111 }
112
113 if (population == nullptr) {
114 throw std::runtime_error(
115 "Population pointer was null while resolving age-to-length "
116 "conversion.");
117 }
118
119 if (!fleet->requires_age_length_mapping || fleet->n_lengths == 0) {
120 return;
121 }
122
123 std::shared_ptr<GrowthDerivedObservationBase<Type>> growth_observation =
124 std::dynamic_pointer_cast<GrowthDerivedObservationBase<Type>>(
125 population->growth);
126
127 if (fleet->age_to_length_conversion_model != nullptr) {
128 if (growth_observation != nullptr) {
129 std::shared_ptr<AgeToLengthConversionDerived<Type>>
131 std::dynamic_pointer_cast<AgeToLengthConversionDerived<Type>>(
132 fleet->age_to_length_conversion_model);
133
134 if (age_to_length_conversion_derived != nullptr &&
136 age_to_length_conversion_derived->PrepareForCurrentState()) {
137 return;
138 }
139 } else if (fleet->age_to_length_conversion_model->IsActive() &&
140 fleet->age_to_length_conversion_model
141 ->PrepareForCurrentState()) {
142 return;
143 }
144 }
145
146 fleet->age_to_length_conversion_model =
148
149 if (fleet->age_to_length_conversion_model != nullptr) {
150 return;
151 }
152
153 std::stringstream ss;
154 ss << "Fleet " << fleet->GetId()
155 << " has length composition bins but no usable age-to-length conversion "
156 "path.";
157
158 if (growth_observation != nullptr) {
159 ss << " This population uses a growth-derived-capable growth object, so "
160 << "the growth-derived age-to-length conversion path with population "
161 "size-provider support "
162 << "was required and could not be built or prepared.";
163 } else {
164 ss << " Provide a valid fixed age-to-length conversion matrix for this "
165 << "fleet or use a supported growth-derived-capable growth object.";
166 }
167
168 FIMS_ERROR_LOG(ss.str());
169 throw std::runtime_error(ss.str());
170}
171
183template <typename Type>
185 const std::shared_ptr<Population<Type>>& population) {
186 if (population == nullptr) {
187 throw std::runtime_error(
188 "Population pointer was null while resolving age-to-length "
189 "conversions.");
190 }
191
192 for (size_t i = 0; i < population->fleets.size(); ++i) {
194 }
195}
196
197} // namespace fims_popdy
198
199#endif
Declares the AgeToLengthConversionBase class which is the base class for all age-length key functors.
Generic capability interface for growth models that can feed the growth-derived age-to-length convers...
Definition growth_model_adapter.hpp:26
#define FIMS_INFO_LOG(MESSAGE)
Record an info-log entry with metadata.
Definition def.hpp:636
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
Declares the AgeToLengthConversionDerived class, which implements AgeToLengthConversionBase by mappin...
Declares the AgeToLengthConversionFixed class, which implements AgeToLengthConversionBase using a fle...
The population dynamics of FIMS.
Definition catch_at_age.hpp:45
void EnsurePopulationFleetAgeToLengthConversion(const std::shared_ptr< Population< Type > > &population)
Ensure all fleets linked to a population have a usable age-to-length conversion.
Definition runtime.hpp:184
std::shared_ptr< AgeToLengthConversionBase< Type > > BuildAgeToLengthConversionFleet(const std::shared_ptr< Population< Type > > &population, const std::shared_ptr< Fleet< Type > > &fleet)
Build the active age-to-length conversion for a fleet from the current population and fleet state.
Definition runtime.hpp:44
void EnsureAgeToLengthConversionFleet(const std::shared_ptr< Population< Type > > &population, const std::shared_ptr< Fleet< Type > > &fleet)
Ensure a fleet has an active age-to-length conversion before length-based calculations.
Definition runtime.hpp:105
Defines the Population class and its fields and methods.
Base class for all fleets.
Definition fleet.hpp:26
Population class. Contains subpopulations that are divided into generic partitions (e....
Definition population.hpp:27