models.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 1
  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. 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. artis::common::DoubleTime::type start(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. return 0;
  81. }
  82. artis::common::Bag<artis::common::DoubleTime> lambda(artis::common::DoubleTime::type t) const override
  83. {
  84. #ifndef WITH_TRACE
  85. (void)t;
  86. #endif
  87. artis::common::Bag<artis::common::DoubleTime> msgs;
  88. msgs.push_back(artis::common::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
  89. #ifdef WITH_TRACE
  90. artis::common::Trace<artis::common::DoubleTime>::trace()
  91. << artis::common::TraceElement<artis::common::DoubleTime>(
  92. get_name(), t,
  93. common::FormalismType::DTSS,
  94. common::FunctionType::LAMBDA,
  95. common::LevelType::USER)
  96. << "messages = " << msgs.to_string();
  97. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  98. #endif
  99. return msgs;
  100. }
  101. private:
  102. double _value;
  103. };
  104. class B
  105. : public artis::dtss::Dynamics<artis::common::DoubleTime, B, artis::dtss::Parameters<common::DoubleTime>> {
  106. public:
  107. enum inputs {
  108. IN
  109. };
  110. enum outputs {
  111. OUT
  112. };
  113. B(const std::string& name,
  114. const artis::dtss::Context<artis::common::DoubleTime, B, artis::dtss::Parameters<common::DoubleTime>>& context)
  115. :
  116. artis::dtss::Dynamics<artis::common::DoubleTime, B, artis::dtss::Parameters<common::DoubleTime>>(
  117. name, context),
  118. _value(0)
  119. {
  120. input_ports({{IN, "in"}});
  121. output_ports({{OUT, "out"}});
  122. }
  123. ~B() override = default;
  124. void transition(const artis::common::Bag<artis::common::DoubleTime>& x,
  125. artis::common::DoubleTime::type t) override
  126. {
  127. #ifndef WITH_TRACE
  128. (void)x;
  129. (void)t;
  130. #endif
  131. #ifdef WITH_TRACE
  132. artis::common::Trace<artis::common::DoubleTime>::trace()
  133. << artis::common::TraceElement<artis::common::DoubleTime>(
  134. get_name(), t,
  135. common::FormalismType::DTSS,
  136. common::FunctionType::TRANSITION,
  137. common::LevelType::USER)
  138. << "x = " << x.to_string();
  139. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  140. #endif
  141. }
  142. artis::common::DoubleTime::type start(artis::common::DoubleTime::type t) override
  143. {
  144. #ifndef WITH_TRACE
  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::START,
  153. common::LevelType::USER);
  154. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  155. #endif
  156. return 0;
  157. }
  158. artis::common::Bag<artis::common::DoubleTime> lambda(
  159. artis::common::DoubleTime::type t) const override
  160. {
  161. #ifndef WITH_TRACE
  162. (void)t;
  163. #endif
  164. artis::common::Bag<artis::common::DoubleTime> msgs;
  165. msgs.push_back(artis::common::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
  166. #ifdef WITH_TRACE
  167. artis::common::Trace<artis::common::DoubleTime>::trace()
  168. << artis::common::TraceElement<artis::common::DoubleTime>(
  169. get_name(), t,
  170. common::FormalismType::DTSS,
  171. common::FunctionType::LAMBDA,
  172. common::LevelType::USER)
  173. << "messages = " << msgs.to_string();
  174. artis::common::Trace<artis::common::DoubleTime>::trace().flush();
  175. #endif
  176. return msgs;
  177. }
  178. private:
  179. double _value;
  180. };
  181. }
  182. }
  183. } // namespace artis tests dtss
  184. #endif