123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /**
- * @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:
- 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) { }
- ~Parabola() override = default;
- double compute() const override { return _alpha * input(IN); }
- private:
- double _alpha;
- };
- 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
- };
- 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) {
- input_port({IN_X, "in_x"});
- }
- ~Predator() override = default;
- double compute() const override { return _b * _d * input(IN_X) * input(IN) - _e * input(IN); }
- private:
- double _b;
- double _d;
- double _e;
- };
- class Prey : public artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters> {
- public:
- enum inputs {
- IN_Y = IN + 1
- };
- 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) {
- input_port({IN_Y, "in_y"});
- }
- ~Prey() override = default;
- double compute() const override { return _a * input(IN) - _b * input(IN_Y) * input(IN); }
- private:
- double _a;
- double _b;
- };
- }
- }
- } // namespace artis tests qss
- #endif
|