models.hpp 6.4 KB

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