@@ -403,13 +403,13 @@ class MobilityEdge
403
403
404
404
private:
405
405
MobilityParameters<FP> m_parameters;
406
- TimeSeries<double > m_mobile_population;
407
- TimeSeries<double > m_return_times;
406
+ TimeSeries<FP > m_mobile_population;
407
+ TimeSeries<FP > m_return_times;
408
408
bool m_return_mobile_population;
409
- double m_t_last_dynamic_npi_check = -std::numeric_limits<double >::infinity();
410
- std::pair<double , SimulationTime> m_dynamic_npi = {-std::numeric_limits<double >::max (), SimulationTime (0 )};
409
+ FP m_t_last_dynamic_npi_check = -std::numeric_limits<FP >::infinity();
410
+ std::pair<FP , SimulationTime> m_dynamic_npi = {-std::numeric_limits<FP >::max (), SimulationTime (0 )};
411
411
std::vector<std::vector<size_t >> m_saved_compartment_indices; // groups of indices from compartments to save
412
- TimeSeries<double > m_mobility_results; // save results from edges + entry for the total number of commuters
412
+ TimeSeries<FP > m_mobility_results; // save results from edges + entry for the total number of commuters
413
413
414
414
/* *
415
415
* @brief Computes a condensed version of `m_mobile_population` and stores it in `m_mobility_results`.
@@ -419,11 +419,11 @@ class MobilityEdge
419
419
*
420
420
* @param[in] t The current time.
421
421
*/
422
- void add_mobility_result_time_point (const double t);
422
+ void add_mobility_result_time_point (const FP t);
423
423
};
424
424
425
425
template <typename FP>
426
- void MobilityEdge<FP>::add_mobility_result_time_point(const double t)
426
+ void MobilityEdge<FP>::add_mobility_result_time_point(const FP t)
427
427
{
428
428
const size_t save_indices_size = this ->m_saved_compartment_indices .size ();
429
429
if (save_indices_size > 0 ) {
@@ -435,7 +435,7 @@ void MobilityEdge<FP>::add_mobility_result_time_point(const double t)
435
435
std::transform (this ->m_saved_compartment_indices .begin (), this ->m_saved_compartment_indices .end (),
436
436
condensed_values.data (), [&last_value](const auto & indices) {
437
437
return std::accumulate (indices.begin (), indices.end (), 0.0 ,
438
- [&last_value](double sum, auto i) {
438
+ [&last_value](FP sum, auto i) {
439
439
return sum + last_value[i];
440
440
});
441
441
});
@@ -563,7 +563,7 @@ template <class Sim>
563
563
void MobilityEdge<FP>::apply_mobility(FP t, FP dt, SimulationNode<Sim>& node_from, SimulationNode<Sim>& node_to)
564
564
{
565
565
// check dynamic npis
566
- if (m_t_last_dynamic_npi_check == -std::numeric_limits<double >::infinity ()) {
566
+ if (m_t_last_dynamic_npi_check == -std::numeric_limits<FP >::infinity ()) {
567
567
m_t_last_dynamic_npi_check = node_from.get_t0 ();
568
568
}
569
569
@@ -574,8 +574,8 @@ void MobilityEdge<FP>::apply_mobility(FP t, FP dt, SimulationNode<Sim>& node_fro
574
574
auto exceeded_threshold = dyn_npis.get_max_exceeded_threshold (inf_rel);
575
575
if (exceeded_threshold != dyn_npis.get_thresholds ().end () &&
576
576
(exceeded_threshold->first > m_dynamic_npi.first ||
577
- t > double (m_dynamic_npi.second ))) { // old NPI was weaker or is expired
578
- auto t_end = SimulationTime (t + double (dyn_npis.get_duration ()));
577
+ t > FP (m_dynamic_npi.second ))) { // old NPI was weaker or is expired
578
+ auto t_end = SimulationTime (t + FP (dyn_npis.get_duration ()));
579
579
m_dynamic_npi = std::make_pair (exceeded_threshold->first , t_end);
580
580
implement_dynamic_npis (
581
581
m_parameters.get_coefficients (), exceeded_threshold->second , SimulationTime (t), t_end, [this ](auto & g) {
@@ -673,8 +673,8 @@ void apply_mobility(FP t, FP dt, MobilityEdge<FP>& mobilityEdge, SimulationNode<
673
673
*/
674
674
template <typename FP, class Sim >
675
675
GraphSimulation<Graph<SimulationNode<Sim>, MobilityEdge<FP>>, FP, FP,
676
- void (*)(double , double , mio::MobilityEdge<>&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
677
- void (*)(double , double , mio::SimulationNode<Sim>&)>
676
+ void (*)(FP, FP , mio::MobilityEdge<FP >&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
677
+ void (*)(FP, FP , mio::SimulationNode<Sim>&)>
678
678
make_mobility_sim (FP t0, FP dt, const Graph<SimulationNode<Sim>, MobilityEdge<FP>>& graph)
679
679
{
680
680
return make_graph_sim (t0, dt, graph, static_cast <void (*)(FP, FP, SimulationNode<Sim>&)>(&advance_model<Sim>),
@@ -684,8 +684,8 @@ make_mobility_sim(FP t0, FP dt, const Graph<SimulationNode<Sim>, MobilityEdge<FP
684
684
685
685
template <typename FP, class Sim >
686
686
GraphSimulation<Graph<SimulationNode<Sim>, MobilityEdge<FP>>, FP, FP,
687
- void (*)(double , double , mio::MobilityEdge<>&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
688
- void (*)(double , double , mio::SimulationNode<Sim>&)>
687
+ void (*)(FP, FP , mio::MobilityEdge<FP >&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
688
+ void (*)(FP, FP , mio::SimulationNode<Sim>&)>
689
689
make_mobility_sim (FP t0, FP dt, Graph<SimulationNode<Sim>, MobilityEdge<FP>>&& graph)
690
690
{
691
691
return make_graph_sim (t0, dt, std::move (graph),
@@ -696,6 +696,40 @@ make_mobility_sim(FP t0, FP dt, Graph<SimulationNode<Sim>, MobilityEdge<FP>>&& g
696
696
697
697
/* * @} */
698
698
699
+ /* *
700
+ * Create a graph simulation without mobility.
701
+ *
702
+ * Note that we set the time step of the graph simulation to infinity since we do not require any exchange between the
703
+ * nodes. Hence, in each node, the simulation runs until tmax when advancing the simulation without interruption.
704
+ *
705
+ * @param t0 Start time of the simulation.
706
+ * @param graph Set up for graph-based simulation.
707
+ * @{
708
+ */
709
+ template <typename FP, class Sim >
710
+ auto make_no_mobility_sim (FP t0, Graph<SimulationNode<Sim>, MobilityEdge<FP>>& graph)
711
+ {
712
+ using GraphSim =
713
+ GraphSimulation<Graph<SimulationNode<Sim>, MobilityEdge<FP>>, FP, FP,
714
+ void (*)(FP, FP, mio::MobilityEdge<FP>&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
715
+ void (*)(FP, FP, mio::SimulationNode<Sim>&)>;
716
+ return GraphSim (t0, std::numeric_limits<FP>::infinity (), graph, &advance_model<Sim>,
717
+ [](FP, FP, MobilityEdge<FP>&, SimulationNode<Sim>&, SimulationNode<Sim>&) {});
718
+ }
719
+
720
+ template <typename FP, class Sim >
721
+ auto make_no_mobility_sim (FP t0, Graph<SimulationNode<Sim>, MobilityEdge<FP>>&& graph)
722
+ {
723
+ using GraphSim =
724
+ GraphSimulation<Graph<SimulationNode<Sim>, MobilityEdge<FP>>, FP, FP,
725
+ void (*)(FP, FP, mio::MobilityEdge<FP>&, mio::SimulationNode<Sim>&, mio::SimulationNode<Sim>&),
726
+ void (*)(FP, FP, mio::SimulationNode<Sim>&)>;
727
+ return GraphSim (t0, std::numeric_limits<FP>::infinity (), std::move (graph), &advance_model<Sim>,
728
+ [](FP, FP, MobilityEdge<FP>&, SimulationNode<Sim>&, SimulationNode<Sim>&) {});
729
+ }
730
+
731
+ /* * @} */
732
+
699
733
} // namespace mio
700
734
701
735
#endif // METAPOPULATION_MOBILITY_INSTANT_H
0 commit comments