models.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * @file tests/dtss/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_DTSS_MODELS_HPP
  26. #define TESTS_DTSS_MODELS_HPP
  27. #include <artis-star/common/time/DoubleTime.hpp>
  28. #include <artis-star/common/utils/Trace.hpp>
  29. #include <artis-star/kernel/dtss/Coordinator.hpp>
  30. #include <artis-star/kernel/dtss/Dynamics.hpp>
  31. namespace artis {
  32. namespace tests {
  33. namespace dtss {
  34. class A
  35. : public artis::dtss::Dynamics<artis::common::DoubleTime,
  36. A,
  37. artis::dtss::Parameters<common::DoubleTime>> {
  38. public:
  39. enum outputs {
  40. OUT
  41. };
  42. A(const std::string &name,
  43. const artis::dtss::Context<artis::common::DoubleTime,
  44. A,
  45. artis::dtss::Parameters<common::DoubleTime>> &context)
  46. :
  47. artis::dtss::Dynamics<artis::common::DoubleTime,
  48. A,
  49. artis::dtss::Parameters<common::DoubleTime>>(
  50. name, context),
  51. _value(0) {
  52. output_ports({{OUT, "out"}});
  53. }
  54. ~A() override = default;
  55. void transition(const artis::common::Bag<artis::common::DoubleTime> & /* x */,
  56. const artis::common::DoubleTime::type &t) override {
  57. #ifndef WITH_TRACE
  58. (void)t;
  59. #endif
  60. #ifdef WITH_TRACE
  61. artis::common::Trace<artis::common::DoubleTime>::trace()
  62. << artis::common::TraceElement<artis::common::DoubleTime>(
  63. get_name(), t,
  64. common::FormalismType::DTSS,
  65. common::FunctionType::TRANSITION,
  66. common::LevelType::USER);
  67. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  68. #endif
  69. }
  70. void start(const artis::common::DoubleTime::type &t) override {
  71. #ifndef WITH_TRACE
  72. (void)t;
  73. #endif
  74. #ifdef WITH_TRACE
  75. artis::common::Trace<artis::common::DoubleTime>::trace()
  76. << artis::common::TraceElement<artis::common::DoubleTime>(
  77. get_name(), t,
  78. common::FormalismType::DTSS,
  79. common::FunctionType::START,
  80. common::LevelType::USER);
  81. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  82. #endif
  83. }
  84. artis::common::Bag<artis::common::DoubleTime> lambda(const artis::common::DoubleTime::type &t) const override {
  85. #ifndef WITH_TRACE
  86. (void)t;
  87. #endif
  88. artis::common::Bag<artis::common::DoubleTime> msgs;
  89. msgs.push_back(artis::common::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
  90. #ifdef WITH_TRACE
  91. artis::common::Trace<artis::common::DoubleTime>::trace()
  92. << artis::common::TraceElement<artis::common::DoubleTime>(
  93. get_name(), t,
  94. common::FormalismType::DTSS,
  95. common::FunctionType::LAMBDA,
  96. common::LevelType::USER)
  97. << "messages = " << msgs.to_string();
  98. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  99. #endif
  100. return msgs;
  101. }
  102. private:
  103. double _value;
  104. };
  105. class B
  106. : public artis::dtss::Dynamics<artis::common::DoubleTime,
  107. B,
  108. artis::dtss::Parameters<common::DoubleTime>> {
  109. public:
  110. enum inputs {
  111. IN
  112. };
  113. enum outputs {
  114. OUT
  115. };
  116. B(const std::string &name,
  117. const artis::dtss::Context<artis::common::DoubleTime,
  118. B,
  119. artis::dtss::Parameters<common::DoubleTime>> &context)
  120. :
  121. artis::dtss::Dynamics<artis::common::DoubleTime,
  122. B,
  123. artis::dtss::Parameters<common::DoubleTime>>(
  124. name, context),
  125. _value(0) {
  126. input_ports({{IN, "in"}});
  127. output_ports({{OUT, "out"}});
  128. }
  129. ~B() override = default;
  130. void transition(const artis::common::Bag<artis::common::DoubleTime> &x,
  131. const artis::common::DoubleTime::type &t) override {
  132. #ifndef WITH_TRACE
  133. (void)x;
  134. (void)t;
  135. #endif
  136. #ifdef WITH_TRACE
  137. artis::common::Trace<artis::common::DoubleTime>::trace()
  138. << artis::common::TraceElement<artis::common::DoubleTime>(
  139. get_name(), t,
  140. common::FormalismType::DTSS,
  141. common::FunctionType::TRANSITION,
  142. common::LevelType::USER)
  143. << "x = " << x.to_string();
  144. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  145. #endif
  146. }
  147. void start(const artis::common::DoubleTime::type &t) override {
  148. #ifndef WITH_TRACE
  149. (void)t;
  150. #endif
  151. #ifdef WITH_TRACE
  152. artis::common::Trace<artis::common::DoubleTime>::trace()
  153. << artis::common::TraceElement<artis::common::DoubleTime>(
  154. get_name(), t,
  155. common::FormalismType::DTSS,
  156. common::FunctionType::START,
  157. common::LevelType::USER);
  158. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  159. #endif
  160. }
  161. artis::common::Bag<artis::common::DoubleTime> lambda(
  162. const artis::common::DoubleTime::type &t) const override {
  163. #ifndef WITH_TRACE
  164. (void)t;
  165. #endif
  166. artis::common::Bag<artis::common::DoubleTime> msgs;
  167. msgs.push_back(artis::common::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
  168. #ifdef WITH_TRACE
  169. artis::common::Trace<artis::common::DoubleTime>::trace()
  170. << artis::common::TraceElement<artis::common::DoubleTime>(
  171. get_name(), t,
  172. common::FormalismType::DTSS,
  173. common::FunctionType::LAMBDA,
  174. common::LevelType::USER)
  175. << "messages = " << msgs.to_string();
  176. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  177. #endif
  178. return msgs;
  179. }
  180. private:
  181. double _value;
  182. };
  183. }
  184. }
  185. } // namespace artis tests dtss
  186. #endif