Browse Source

Fix QSS reset

Eric Ramat 1 year ago
parent
commit
24f4e7448a

+ 12 - 13
src/artis-star/kernel/pdevs/qss/Derivative.hpp

@@ -93,14 +93,14 @@ namespace artis {
 
                 virtual double compute() const = 0;
 
-                virtual void dconf(typename Time::type t, typename Time::type e,
+                virtual void dconf(const typename Time::type& t, typename Time::type e,
                         const common::Bag<Time>& bag)
                 {
                     dint(t);
                     dext(t, e, bag);
                 }
 
-                virtual void dint(typename Time::type /* time */)
+                virtual void dint(const typename Time::type& /* time */)
                 {
                     if (_state == RESPONSE) {
                         _last_output = _output_value;
@@ -108,19 +108,18 @@ namespace artis {
                     _state = WAIT;
                 }
 
-                virtual void dext(typename Time::type t, typename Time::type e,
+                virtual void dext(const typename Time::type& t, typename Time::type e,
                         const common::Bag<Time>& bag)
                 {
                     std::for_each(bag.begin(), bag.end(),
                             [this, t, e](const common::ExternalEvent<Time>& event) {
                                 if (event.on_port(RESET)) {
-                                    IntegratorData data;
-
-                                    event.data()(data);
-                                    this->get(LAST_OUTPUT + 1).put(dynamic_cast<Dyn*>(this),
-                                            data.value);
-                                    _output_value = compute();
-                                    _state = RESPONSE;
+                                    if (_input_number == 0) {
+                                        _output_value = compute();
+                                        _state = RESPONSE;
+                                    } else {
+                                        _state = INIT;
+                                    }
                                 } else {
                                     IntegratorData data;
 
@@ -151,7 +150,7 @@ namespace artis {
                             });
                 }
 
-                virtual void start(typename Time::type /* time */)
+                virtual void start(const typename Time::type& /* time */)
                 {
                     _input_number = this->input_port_number() - 1;
                     if (_input_number == 0) {
@@ -162,7 +161,7 @@ namespace artis {
                     }
                 }
 
-                virtual typename Time::type ta(typename Time::type /* time */)
+                virtual typename Time::type ta(const typename Time::type& /* time */)
                 {
                     switch (_state) {
                     case INIT:
@@ -175,7 +174,7 @@ namespace artis {
                     return Time::infinity;
                 }
 
-                virtual common::Bag<Time> lambda(typename Time::type /* time */) const
+                virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
                 {
                     common::Bag<Time> msgs;
 

+ 18 - 10
src/artis-star/kernel/pdevs/qss/Integrator.hpp

@@ -115,7 +115,7 @@ namespace artis {
                     dext(t, e, bag);
                 }
 
-                virtual void dint(typename Time::type time)
+                virtual void dint(const typename Time::type& time)
                 {
                     switch (_state) {
                     case RUNNING: {
@@ -142,11 +142,13 @@ namespace artis {
                     }
                 }
 
-                virtual void dext(typename Time::type t, typename Time::type e,
+                virtual void dext(const typename Time::type& t, const typename Time::type& e,
                         const common::Bag<Time>& bag)
                 {
+                    bool reset = false;
+
                     std::for_each(bag.begin(), bag.end(),
-                            [this, t, e](const common::ExternalEvent<Time>& event) {
+                            [this, t, e, &reset](const common::ExternalEvent<Time>& event) {
                                 if (event.on_port(QUANTA)) {
                                     QuantifierData data;
 
@@ -176,22 +178,28 @@ namespace artis {
 
                                     event.data()(data);
                                     _current_value = data.value;
-                                    _state = INIT;
+                                    reset = true;
+                                    _archive_x_dot.clear();
+                                    _archive_date.clear();
                                 }
                             });
-                    if (_state == RUNNING) {
-                        _current_value = current_value(t);
-                        _expected_value = expected_value(t);
+                    if (reset) {
+                        _state = INIT;
+                    } else {
+                        if (_state == RUNNING) {
+                            _current_value = current_value(t);
+                            _expected_value = expected_value(t);
+                        }
                     }
                 }
 
-                virtual void start(typename Time::type /* time */)
+                virtual void start(const typename Time::type& /* time */)
                 {
                     _current_value = _init_value;
                     _state = INIT;
                 }
 
-                virtual typename Time::type ta(typename Time::type /* time */)
+                virtual typename Time::type ta(const typename Time::type& t)
                 {
                     double current_derivative;
 
@@ -222,7 +230,7 @@ namespace artis {
                     }
                 }
 
-                virtual common::Bag<Time> lambda(typename Time::type /* time */) const
+                virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
                 {
                     common::Bag<Time> msgs;
 

+ 16 - 9
src/artis-star/kernel/pdevs/qss/Quantifier.hpp

@@ -93,14 +93,14 @@ namespace artis {
 
                 virtual ~Quantifier() { }
 
-                virtual void dconf(typename Time::type t, typename Time::type e,
+                virtual void dconf(const typename Time::type& t, const typename Time::type& e,
                         const common::Bag<Time>& bag)
                 {
                     dint(t);
                     dext(t, e, bag);
                 }
 
-                virtual void dint(typename Time::type /* t */)
+                virtual void dint(const typename Time::type& /* t */)
                 {
                     switch (_state) {
                     case INIT:
@@ -113,11 +113,13 @@ namespace artis {
                     }
                 }
 
-                virtual void dext(typename Time::type t, typename Time::type e,
+                virtual void dext(const typename Time::type& t, const typename Time::type& e,
                         const common::Bag<Time>& bag)
                 {
+                    bool reset = false;
+
                     std::for_each(bag.begin(), bag.end(),
-                            [this, t, e](const common::ExternalEvent<Time>& event) {
+                            [this, t, e, &reset](const common::ExternalEvent<Time>& event) {
                                 if (event.on_port(IN)) {
                                     IntegratorData data;
                                     double shifting_factor;
@@ -177,19 +179,24 @@ namespace artis {
                                     }
                                 } else if (event.on_port(RESET)) {
                                     _offset = 0;
-                                    _state = INIT;
+                                    reset = true;
+                                    _archive.clear();
                                 }
                             });
-                    _state = RESPONSE;
+                    if (reset) {
+                        _state = INIT;
+                    } else {
+                        _state = RESPONSE;
+                    }
                 }
 
-                virtual void start(typename Time::type /* time */)
+                virtual void start(const typename Time::type& /* time */)
                 {
                     _offset = 0;
                     _state = INIT;
                 }
 
-                virtual typename Time::type ta(typename Time::type /* time */)
+                virtual typename Time::type ta(const typename Time::type& /* time */)
                 {
                     switch (_state) {
                     case INIT:
@@ -201,7 +208,7 @@ namespace artis {
                     return Time::infinity;
                 }
 
-                virtual common::Bag<Time> lambda(typename Time::type /* time */) const
+                virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
                 {
                     common::Bag<Time> msgs;
                     const QuantifierData data = {_up_threshold, _down_threshold};