/** * @file kernel/pdevs/qss/Derivative.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 . */ #ifndef QSS_DERIVATIVE #define QSS_DERIVATIVE #include #include namespace artis { namespace pdevs { namespace qss { template class Derivative : public artis::pdevs::Dynamics { typedef enum { INIT = 0, WAIT, RESPONSE } State; public: enum inputs { RESET = 0, IN }; enum outputs { OUT = 0 }; enum states { STATE = 0, INPUT_NUMBER, OUTPUT_VALUE, LAST_OUTPUT }; typedef Derivative type; Derivative(const std::string& name, const Context& context) : artis::pdevs::Dynamics(name, context), _external_number(0), _internal_number(0) { DECLARE_STATES(int, ((STATE, &type::_state))); DECLARE_STATES(unsigned int, ((INPUT_NUMBER, &type::_input_number))); DECLARE_STATES(double, ((OUTPUT_VALUE, &type::_output_value), (LAST_OUTPUT, &type::_output_value))); this->input_ports({{RESET, "reset"}, {IN, "in"}}); this->output_port({OUT, "out"}); } virtual ~Derivative() { } int external(const std::string& name, double Dyn::* var) { ++_external_number; this->state_(LAST_OUTPUT + _external_number + 1, name, var); this->input_port({IN + _external_number, name}); return IN + _external_number; } void internal(const std::string& name, double Dyn::* var) { assert(_internal_number == 0); ++_internal_number; this->state_(LAST_OUTPUT + 1, name, var); } virtual double compute() const = 0; virtual void dconf(typename Time::type t, typename Time::type e, const common::Bag