Browse Source

Verify ta >= 0

Eric Ramat 1 year ago
parent
commit
2e87262c3f

+ 12 - 2
src/artis-star/kernel/devs/Simulator.hpp

@@ -131,7 +131,12 @@ namespace artis {
 
                 _dynamics.start(t);
                 type::_tl = t;
-                type::_tn = type::_tl + _dynamics.ta(t);
+
+                typename Time::type duration = _dynamics.ta(t);
+
+                assert(ta >= 0);
+
+                type::_tn = type::_tl + duration;
 
 #ifdef WITH_TRACE
                 common::Trace<Time>::trace()
@@ -252,7 +257,12 @@ namespace artis {
                     _dynamics.dext(t, t - type::_tl, type::get_bag().at(0));
                 }
                 type::_tl = t;
-                type::_tn = type::_tl + _dynamics.ta(t);
+
+                typename Time::type duration = _dynamics.ta(t);
+
+                assert(ta >= 0);
+
+                type::_tn = type::_tl + duration;
                 type::clear_bag();
 
 #ifdef WITH_TRACE

+ 18 - 3
src/artis-star/kernel/fddevs/Simulator.hpp

@@ -135,7 +135,12 @@ namespace artis {
 
                 _dynamics.initial_state(t);
                 type::_tl = t;
-                type::_tn = type::_tl + _dynamics.tau(t);
+
+                typename Time::type duration = _dynamics.tau(t);
+
+                assert(ta >= 0);
+
+                type::_tn = type::_tl + duration;
 
 #ifdef WITH_TRACE
                 common::Trace<Time>::trace()
@@ -259,14 +264,24 @@ namespace artis {
                 if (t == type::_tn) {
                     if (type::event_number() == 0) {
                         _dynamics.delta_tau(t);
-                        type::_tn = t + _dynamics.tau(t);
+
+                        typename Time::type duration = _dynamics.tau(t);
+
+                        assert(ta >= 0);
+
                         type::_tl = t;
+                        type::_tn = type::_tl + duration;
                     }
                 } else {
                     _dynamics.delta_x(t, t - type::_tl, type::get_bag());
                     if (not _dynamics.rho(t, type::get_bag())) {
-                        type::_tn = t + _dynamics.tau(t);
+
+                        typename Time::type duration = _dynamics.tau(t);
+
+                        assert(ta >= 0);
+
                         type::_tl = t;
+                        type::_tn = type::_tl + duration;
                     }
                 }
                 type::clear_bag();

+ 12 - 2
src/artis-star/kernel/pdevs/Simulator.hpp

@@ -133,7 +133,12 @@ namespace artis {
 
                 _dynamics.start(t);
                 type::_tl = t;
-                type::_tn = type::_tl + _dynamics.ta(t);
+
+                typename Time::type duration = _dynamics.ta(t);
+
+                assert(ta >= 0);
+
+                type::_tn = type::_tl + duration;
 
 #ifdef WITH_TRACE
                 common::Trace<Time>::trace()
@@ -265,7 +270,12 @@ namespace artis {
                 } else {
                     _dynamics.dext(t, t - type::_tl, type::get_bag());
                 }
-                type::_tn = t + _dynamics.ta(t);
+
+                typename Time::type duration = _dynamics.ta(t);
+
+                assert(ta >= 0);
+
+                type::_tn = type::_tl + duration;
                 type::_tl = t;
                 type::clear_bag();