models.hpp 8.0 KB

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