123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /**
- * @file tests/qss/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-2019 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_QSS_MODELS_HPP
- #define TESTS_QSS_MODELS_HPP 1
- #include <artis-star/common/time/DoubleTime.hpp>
- #include <artis-star/common/utils/Trace.hpp>
- #include <artis-star/kernel/pdevs/qss/Derivative.hpp>
- namespace artis {
- namespace tests {
- namespace qss {
- class Constant : public artis::pdevs::qss::Derivative<common::DoubleTime, Constant> {
- public:
- Constant(const std::string& name,
- const artis::pdevs::Context<common::DoubleTime, Constant, artis::common::NoParameters>& context)
- :
- artis::pdevs::qss::Derivative<common::DoubleTime, Constant>(name,
- context) { }
- ~Constant() override = default;
- double compute() const override { return 0.5; }
- };
- struct ParabolaParameters {
- double alpha;
- };
- class Parabola
- : public artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters> {
- public:
- enum states {
- X = LAST_OUTPUT + 1
- };
- Parabola(const std::string& name,
- const artis::pdevs::Context<common::DoubleTime, Parabola, ParabolaParameters>& context)
- :
- artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters>(
- name,
- context), _alpha(context.parameters().alpha)
- {
- DECLARE_STATES(double, ((X, &Parabola::_x)));
- }
- ~Parabola() override = default;
- double compute() const override { return _alpha * _x; }
- private:
- double _alpha;
- double _x;
- };
- struct PreyPredatorParameters {
- double a;
- double b;
- double d;
- double e;
- };
- class Predator
- : public artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters> {
- public:
- enum inputs {
- IN_X = IN + 1
- };
- enum states {
- Y = LAST_OUTPUT + 1, X
- };
- Predator(const std::string& name,
- const artis::pdevs::Context<common::DoubleTime, Predator, PreyPredatorParameters>& context)
- :
- artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters>(
- name,
- context), _b(context.parameters().b), _d(context.parameters().d),
- _e(context.parameters().e)
- {
- DECLARE_STATES(double, ((X, &Predator::_x), (Y, &Predator::_y)));
- input_port({IN_X, "in_x"});
- }
- ~Predator() override = default;
- double compute() const override { return _b * _d * _x * _y - _e * _y; }
- private:
- // parameters
- double _b;
- double _d;
- double _e;
- // state
- double _x;
- double _y;
- };
- class Prey
- : public artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters> {
- public:
- enum inputs {
- IN_Y = IN + 1
- };
- enum states {
- X = LAST_OUTPUT + 1, Y
- };
- Prey(const std::string& name,
- const artis::pdevs::Context<common::DoubleTime, Prey, PreyPredatorParameters>& context)
- :
- artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters>(
- name,
- context), _a(context.parameters().a), _b(context.parameters().b)
- {
- DECLARE_STATES(double, ((X, &Prey::_x), (Y, &Prey::_y)));
- input_port({IN_Y, "in_y"});
- }
- ~Prey() override = default;
- double compute() const override { return _a * _x - _b * _y * _x; }
- private:
- // parameters
- double _a;
- double _b;
- // state
- double _x;
- double _y;
- };
- }
- }
- } // namespace artis tests qss
- #endif
|