models.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file tests/qss/models.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-2019 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 TESTS_QSS_MODELS_HPP
  26. #define TESTS_QSS_MODELS_HPP 1
  27. #include <artis-star/common/time/DoubleTime.hpp>
  28. #include <artis-star/common/utils/Trace.hpp>
  29. #include <artis-star/kernel/pdevs/qss/Derivative.hpp>
  30. namespace artis {
  31. namespace tests {
  32. namespace qss {
  33. class Constant : public artis::pdevs::qss::Derivative<common::DoubleTime, Constant> {
  34. public:
  35. Constant(const std::string& name,
  36. const artis::pdevs::Context<common::DoubleTime, Constant, artis::common::NoParameters>& context)
  37. :
  38. artis::pdevs::qss::Derivative<common::DoubleTime, Constant>(name,
  39. context) { }
  40. ~Constant() override = default;
  41. double compute() const override { return 0.5; }
  42. };
  43. struct ParabolaParameters {
  44. double alpha;
  45. };
  46. class Parabola : public artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters> {
  47. public:
  48. Parabola(const std::string& name,
  49. const artis::pdevs::Context<common::DoubleTime, Parabola, ParabolaParameters>& context)
  50. :
  51. artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters>(name,
  52. context), _alpha(context.parameters().alpha) { }
  53. ~Parabola() override = default;
  54. double compute() const override { return _alpha * input(IN); }
  55. private:
  56. double _alpha;
  57. };
  58. struct PreyPredatorParameters {
  59. double a;
  60. double b;
  61. double d;
  62. double e;
  63. };
  64. class Predator : public artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters> {
  65. public:
  66. enum inputs {
  67. IN_X = IN + 1
  68. };
  69. Predator(const std::string& name,
  70. const artis::pdevs::Context<common::DoubleTime, Predator, PreyPredatorParameters>& context)
  71. :
  72. artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters>(name,
  73. context), _b(context.parameters().b), _d(context.parameters().d), _e(context.parameters().e) {
  74. input_port({IN_X, "in_x"});
  75. }
  76. ~Predator() override = default;
  77. double compute() const override { return _b * _d * input(IN_X) * input(IN) - _e * input(IN); }
  78. private:
  79. double _b;
  80. double _d;
  81. double _e;
  82. };
  83. class Prey : public artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters> {
  84. public:
  85. enum inputs {
  86. IN_Y = IN + 1
  87. };
  88. Prey(const std::string& name,
  89. const artis::pdevs::Context<common::DoubleTime, Prey, PreyPredatorParameters>& context)
  90. :
  91. artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters>(name,
  92. context), _a(context.parameters().a), _b(context.parameters().b) {
  93. input_port({IN_Y, "in_y"});
  94. }
  95. ~Prey() override = default;
  96. double compute() const override { return _a * input(IN) - _b * input(IN_Y) * input(IN); }
  97. private:
  98. double _a;
  99. double _b;
  100. };
  101. }
  102. }
  103. } // namespace artis tests qss
  104. #endif