MultiGraphManager.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file qss/MultiGraphManager.hpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef ARTIS_STAR_ADDONS_QSS_MULTI_GRAPH_MANAGER
  26. #define ARTIS_STAR_ADDONS_QSS_MULTI_GRAPH_MANAGER
  27. #include <artis-star/kernel/pdevs/GraphManager.hpp>
  28. #include <artis-star/kernel/qss/MultiDerivative.hpp>
  29. #include <artis-star/kernel/qss/Integrator.hpp>
  30. #include <artis-star/kernel/qss/Quantifier.hpp>
  31. namespace artis::addons::qss {
  32. template<class DerivativeParameters>
  33. struct MultiQSSParameters {
  34. std::vector <artis::qss::IntegratorParameters> integrators;
  35. std::vector <artis::qss::QuantifierParameters> quantifiers;
  36. DerivativeParameters derivative;
  37. };
  38. template<class Time,
  39. class Derivative,
  40. class DerivativeParameters = artis::common::NoParameters>
  41. class MultiGraphManager :
  42. public artis::pdevs::GraphManager<Time,
  43. MultiQSSParameters<DerivativeParameters>,
  44. artis::common::NoParameters> {
  45. public:
  46. struct submodel {
  47. enum values {
  48. S_Derivative = 0, S_Integrator = 1, S_Quantifier = 1000
  49. };
  50. };
  51. struct input {
  52. enum values {
  53. RESET
  54. };
  55. };
  56. MultiGraphManager(common::Coordinator <Time> *coordinator,
  57. const MultiQSSParameters<DerivativeParameters> &parameters,
  58. const artis::common::NoParameters &graph_parameters)
  59. :
  60. artis::pdevs::GraphManager<Time,
  61. MultiQSSParameters<DerivativeParameters>,
  62. artis::common::NoParameters>(
  63. coordinator, parameters, graph_parameters),
  64. _derivative("d", parameters.derivative) {
  65. this->add_child(submodel::S_Derivative, &_derivative);
  66. coordinator->input_port({input::RESET, "reset"});
  67. this->in({coordinator, input::RESET})
  68. >> this->in({&_derivative, Derivative::input::RESET});
  69. for (unsigned int index = 0; index < _derivative.dynamics().variable_number(); ++index) {
  70. _integrators.push_back(new IntegratorSimulator("i_" + std::to_string(index),
  71. parameters.integrators[index]));
  72. _quantifiers.push_back(new QuantifierSimulator("q_" + std::to_string(index),
  73. parameters.quantifiers[index]));
  74. this->add_child(submodel::S_Integrator + index, _integrators.back());
  75. this->add_child(submodel::S_Quantifier + index, _quantifiers.back());
  76. coordinator->output_port({index, "out_" + std::to_string(index)});
  77. this->in({coordinator, input::RESET})
  78. >> this->in({_integrators.back(), Integrator<Time>::input::RESET});
  79. this->in({coordinator, input::RESET})
  80. >> this->in({_quantifiers.back(), Quantifier<Time>::input::RESET});
  81. this->out({&_derivative, index})
  82. >> this->in({_integrators.back(), Integrator<Time>::input::X_DOT});
  83. this->out({_integrators.back(), Integrator<Time>::output::OUT})
  84. >> this->in({_quantifiers.back(), Quantifier<Time>::input::IN});
  85. this->out({_quantifiers.back(), Quantifier<Time>::output::OUT})
  86. >> this->in({_integrators.back(), Integrator<Time>::input::QUANTA});
  87. this->out({_integrators.back(), Integrator<Time>::output::OUT})
  88. >> this->out({coordinator, index});
  89. this->out({_integrators.back(), Integrator<Time>::output::OUT})
  90. >> this->in({&_derivative, Derivative::input::INTERNAL + index});
  91. }
  92. }
  93. ~MultiGraphManager() override {
  94. std::for_each(_integrators.begin(), _integrators.end(), std::default_delete<IntegratorSimulator>());
  95. std::for_each(_quantifiers.begin(), _quantifiers.end(), std::default_delete<QuantifierSimulator>());
  96. }
  97. artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> *derivative() { return &_derivative; }
  98. private:
  99. typedef artis::pdevs::Simulator<Time, artis::qss::Integrator<Time>,
  100. artis::qss::IntegratorParameters> IntegratorSimulator;
  101. typedef std::vector<IntegratorSimulator *> IntegratorSimulators;
  102. typedef artis::pdevs::Simulator<Time, artis::qss::Quantifier<Time>,
  103. artis::qss::QuantifierParameters> QuantifierSimulator;
  104. typedef std::vector<QuantifierSimulator *> QuantifierSimulators;
  105. artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> _derivative;
  106. IntegratorSimulators _integrators;
  107. QuantifierSimulators _quantifiers;
  108. };
  109. }
  110. #endif