123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /**
- * @file tests/dtss/models.hpp
- * @author The ARTIS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * ARTIS - the multimodeling and simulation environment
- * This file is a part of the ARTIS environment
- *
- * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef TESTS_DTSS_MODELS_HPP
- #define TESTS_DTSS_MODELS_HPP
- #include <artis-star/common/time/DoubleTime.hpp>
- #include <artis-star/common/utils/Trace.hpp>
- #include <artis-star/kernel/dtss/Coordinator.hpp>
- #include <artis-star/kernel/dtss/Dynamics.hpp>
- namespace artis {
- namespace tests {
- namespace dtss {
- class A
- : public artis::dtss::Dynamics<artis::common::DoubleTime,
- A,
- artis::dtss::Parameters<common::DoubleTime>>
- {
- public:
- enum outputs
- {
- OUT
- };
- A(const std::string &name,
- const artis::dtss::Context<artis::common::DoubleTime,
- A,
- artis::dtss::Parameters<common::DoubleTime>> &context)
- :
- artis::dtss::Dynamics<artis::common::DoubleTime,
- A,
- artis::dtss::Parameters<common::DoubleTime>>(
- name, context),
- _value(0)
- {
- output_ports({{OUT, "out"}});
- }
- ~A() override = default;
- void transition(const artis::common::event::Bag<artis::common::DoubleTime> & /* x */,
- const artis::common::DoubleTime::type &t) override
- {
- #ifndef WITH_TRACE
- (void)t;
- #endif
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::TRANSITION,
- common::LevelType::USER);
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- }
- void start(const artis::common::DoubleTime::type &t) override
- {
- #ifndef WITH_TRACE
- (void)t;
- #endif
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::START,
- common::LevelType::USER);
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- }
- artis::common::event::Bag<artis::common::DoubleTime> lambda(const artis::common::DoubleTime::type &t) const override
- {
- #ifndef WITH_TRACE
- (void)t;
- #endif
- artis::common::event::Bag<artis::common::DoubleTime> msgs;
- msgs.push_back(artis::common::event::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::LAMBDA,
- common::LevelType::USER)
- << "messages = " << msgs.to_string();
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- return msgs;
- }
- private:
- double _value;
- };
- class B
- : public artis::dtss::Dynamics<artis::common::DoubleTime,
- B,
- artis::dtss::Parameters<common::DoubleTime>>
- {
- public:
- enum inputs
- {
- IN
- };
- enum outputs
- {
- OUT
- };
- B(const std::string &name,
- const artis::dtss::Context<artis::common::DoubleTime,
- B,
- artis::dtss::Parameters<common::DoubleTime>> &context)
- :
- artis::dtss::Dynamics<artis::common::DoubleTime,
- B,
- artis::dtss::Parameters<common::DoubleTime>>(
- name, context),
- _value(0)
- {
- input_ports({{IN, "in"}});
- output_ports({{OUT, "out"}});
- }
- ~B() override = default;
- void transition(const artis::common::event::Bag<artis::common::DoubleTime> &x,
- const artis::common::DoubleTime::type &t) override
- {
- #ifndef WITH_TRACE
- (void)x;
- (void)t;
- #endif
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::TRANSITION,
- common::LevelType::USER)
- << "x = " << x.to_string();
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- }
- void start(const artis::common::DoubleTime::type &t) override
- {
- #ifndef WITH_TRACE
- (void)t;
- #endif
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::START,
- common::LevelType::USER);
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- }
- artis::common::event::Bag<artis::common::DoubleTime> lambda(
- const artis::common::DoubleTime::type &t) const override
- {
- #ifndef WITH_TRACE
- (void)t;
- #endif
- artis::common::event::Bag<artis::common::DoubleTime> msgs;
- msgs.push_back(artis::common::event::ExternalEvent<artis::common::DoubleTime>(OUT, _value));
- #ifdef WITH_TRACE
- artis::common::Trace<artis::common::DoubleTime>::trace()
- << artis::common::TraceElement<artis::common::DoubleTime>(
- get_name(), t,
- common::FormalismType::DTSS,
- common::FunctionType::LAMBDA,
- common::LevelType::USER)
- << "messages = " << msgs.to_string();
- artis::common::Trace<artis::common::DoubleTime>::trace().flush();
- #endif
- return msgs;
- }
- private:
- double _value;
- };
- }
- }
- } // namespace artis tests dtss
- #endif
|