models.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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
  47. : public artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters> {
  48. public:
  49. Parabola(const std::string& name,
  50. const artis::pdevs::Context<common::DoubleTime, Parabola, ParabolaParameters>& context)
  51. :
  52. artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters>(
  53. name,
  54. context), _alpha(context.parameters().alpha)
  55. {
  56. internal("X", &Parabola::_x);
  57. }
  58. ~Parabola() override = default;
  59. double compute() const override { return _alpha * _x; }
  60. private:
  61. double _alpha;
  62. double _x;
  63. };
  64. struct PreyPredatorParameters {
  65. double a;
  66. double b;
  67. double d;
  68. double e;
  69. };
  70. class Predator
  71. : public artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters> {
  72. public:
  73. unsigned int IN_X;
  74. Predator(const std::string& name,
  75. const artis::pdevs::Context<common::DoubleTime, Predator, PreyPredatorParameters>& context)
  76. :
  77. artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters>(
  78. name,
  79. context), _b(context.parameters().b), _d(context.parameters().d),
  80. _e(context.parameters().e)
  81. {
  82. internal("Y", &Predator::_y);
  83. IN_X = external("X", &Predator::_x);
  84. }
  85. ~Predator() override = default;
  86. double compute() const override { return _b * _d * _x * _y - _e * _y; }
  87. private:
  88. // parameters
  89. double _b;
  90. double _d;
  91. double _e;
  92. // state
  93. double _x;
  94. double _y;
  95. };
  96. class Prey
  97. : public artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters> {
  98. public:
  99. unsigned int IN_Y;
  100. Prey(const std::string& name,
  101. const artis::pdevs::Context<common::DoubleTime, Prey, PreyPredatorParameters>& context)
  102. :
  103. artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters>(
  104. name,
  105. context), _a(context.parameters().a), _b(context.parameters().b)
  106. {
  107. internal("X", &Prey::_x);
  108. IN_Y = external("Y", &Prey::_y);
  109. }
  110. ~Prey() override = default;
  111. double compute() const override { return _a * _x - _b * _y * _x; }
  112. private:
  113. // parameters
  114. double _a;
  115. double _b;
  116. // state
  117. double _x;
  118. double _y;
  119. };
  120. }
  121. }
  122. } // namespace artis tests qss
  123. #endif