flow_model.h Source File
|
CPP API
|
flow_model.h
Go to the documentation of this file.
34 // The following functions are not defined anywhere. Their use is to provide type conversions via their return type.
37 // First a list of tuples is generated for each Tag in Tags, where the tuple is either of type tuple<Tag>, or if
38 // Tag == OmittedTag, of type tuple<>. This list is then concatenated, effectively removing OmittedTag.
41 std::declval<std::conditional_t<std::is_same_v<OmittedTag, Tags>, std::tuple<>, std::tuple<Tags>>>()...))
77 // get_flat_flow_index, since a flow is used to determine only the compartment (i.e. Index<Comp>) for the
79 // The remaining indices (those contained in FlowIndex) must still be provided to get an entry of population.
80 // This approach only works with exactly one category of type Comp in PopIndex (hence the assertion below).
82 // Enforce that Comp is a unique Category of PopIndex, since we use Flows (via their source/target) to provide
84 static_assert(FlowIndex::size == PopIndex::size - 1, "Compartments must be used exactly once as population index.");
101 virtual void get_flows(Eigen::Ref<const Eigen::VectorX<FP>> /*pop*/, Eigen::Ref<const Eigen::VectorX<FP>> /*y*/,
112 void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> flows, Eigen::Ref<Eigen::VectorX<FP>> dydt) const
117 // special case where PopIndex only contains Comp, hence FlowIndex has no dimensions to iterate over
138 void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
153 return Eigen::VectorX<FP>::Zero((this->populations.numel() / static_cast<size_t>(Comp::Count)) * Flows::size());
220 inline void get_rhs_impl(Eigen::Ref<const Eigen::VectorX<FP>> flows, Eigen::Ref<Eigen::VectorX<FP>> rhs,
229 rhs[flat_source_population] -= flows[flat_flow_index]; // subtract outflow from source compartment
246 requires(Model m, Eigen::Ref<const Eigen::VectorX<FP>> const_vref, Eigen::Ref<Eigen::VectorX<FP>> vref, FP t) {
A FlowModel is a CompartmentalModel defined by the flows between compartments.
Definition: flow_model.h:74
void get_rhs_impl(Eigen::Ref< const Eigen::VectorX< FP >> flows, Eigen::Ref< Eigen::VectorX< FP >> rhs, const FlowIndex &index) const
Compute the derivatives of the compartments.
Definition: flow_model.h:220
void get_derivatives(Eigen::Ref< const Eigen::VectorX< FP >> flows, Eigen::Ref< Eigen::VectorX< FP >> dydt) const
Compute the right-hand-side of the ODE dydt = f(y, t) from flow values.
Definition: flow_model.h:112
constexpr size_t get_flat_flow_index() const
A flat index into an array of flows (as computed by get_flows), if the only used category in Pop is C...
Definition: flow_model.h:201
FlowModel(Args... args)
Default constructor, forwarding args to Base constructor.
Definition: flow_model.h:93
Eigen::VectorX< FP > get_initial_flows() const
Initial values for flows.
Definition: flow_model.h:151
size_t get_flat_flow_index(const FlowIndex &indices) const
A flat index into an array of flows (as computed by get_flows), given the indices of each category.
Definition: flow_model.h:182
Eigen::VectorX< FP > m_flow_values
Cache to avoid allocation in get_derivatives (using get_flows).
Definition: flow_model.h:208
virtual void get_flows(Eigen::Ref< const Eigen::VectorX< FP >>, Eigen::Ref< const Eigen::VectorX< FP >>, FP, Eigen::Ref< Eigen::VectorX< FP >>) const =0
details::filtered_index_t< Comp, Index, PopIndex > FlowIndex
Definition: flow_model.h:81
void get_derivatives(Eigen::Ref< const Eigen::VectorX< FP >> pop, Eigen::Ref< const Eigen::VectorX< FP >> y, FP t, Eigen::Ref< Eigen::VectorX< FP >> dydt) const final
Compute the right-hand-side f(y, t) of the ODE and store it in dydt.
Definition: flow_model.h:138
An Index with more than one template parameter combines several Index objects.
Definition: index.h:181
decltype(as_index< IndexTemplate >(std::declval< filtered_tuple_t< OmittedTag, decltype(as_tuple(std::declval< Index >()))> >())) filtered_index_t
Definition: flow_model.h:59
std::pair< size_t, size_t > flatten_index(Index const &indices, Index const &dimensions)
Definition: custom_index_array.h:61
decltype(std::tuple_cat(std::declval< std::conditional_t< std::is_same_v< OmittedTag, Tags >, std::tuple<>, std::tuple< Tags >>>()...)) filter_tuple(std::tuple< Tags... >)
std::tuple< Args... > as_tuple(T< Args... >)
T< Args... > as_index(std::tuple< Args... >)
decltype(filter_tuple< OmittedTag >(std::declval< Tuple >())) filtered_tuple_t
Definition: flow_model.h:54
int size(Comm comm)
Return the size of the given communicator.
Definition: miompi.cpp:75
TypeList< Flow< InfectionState::Susceptible, InfectionState::Exposed >, Flow< InfectionState::Exposed, InfectionState::InfectedNoSymptoms >, Flow< InfectionState::InfectedNoSymptoms, InfectionState::InfectedSymptoms >, Flow< InfectionState::InfectedNoSymptoms, InfectionState::Recovered >, Flow< InfectionState::InfectedNoSymptomsConfirmed, InfectionState::InfectedSymptomsConfirmed >, Flow< InfectionState::InfectedNoSymptomsConfirmed, InfectionState::Recovered >, Flow< InfectionState::InfectedSymptoms, InfectionState::InfectedSevere >, Flow< InfectionState::InfectedSymptoms, InfectionState::Recovered >, Flow< InfectionState::InfectedSymptomsConfirmed, InfectionState::InfectedSevere >, Flow< InfectionState::InfectedSymptomsConfirmed, InfectionState::Recovered >, Flow< InfectionState::InfectedSevere, InfectionState::InfectedCritical >, Flow< InfectionState::InfectedSevere, InfectionState::Recovered >, Flow< InfectionState::InfectedSevere, InfectionState::Dead >, Flow< InfectionState::InfectedCritical, InfectionState::Dead >, Flow< InfectionState::InfectedCritical, InfectionState::Recovered > > Flows
Definition: ode_secir/model.h:59
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
concept IsFlowModel
Concept to check if a type is a valid FlowModel.
Definition: flow_model.h:245
typename type_at_index< Index, Types... >::type type_at_index_t
The type at the Index-th position in the list Types.
Definition: metaprogramming.h:118
requires(!std::is_trivial_v< T >) void BinarySerializerObject
Definition: binary_serializer.h:333
Definition: io.h:94
CompartmentalModel is a template for a compartmental model for an array of initial populations and a ...
Definition: compartmental_model.h:59
A Flow defines a possible transition between two Compartments in a FlowModel.
Definition: flow.h:33
Generated by