31 #ifndef _adevs_event_locators_h_ 32 #define _adevs_event_locators_h_ 33 #include "adevs_hybrid.h" 54 enum Mode { INTERPOLATE, BISECTION, DISCONTINUOUS };
57 bool find_events(
bool* events,
const double* qstart,
double* qend,
64 int sign(
double x)
const 66 if (x < 0.0)
return -1;
67 else if (x > 0.0)
return 1;
74 double err_tol,
Mode mode):
86 delete [] z[0];
delete [] z[1];
91 const double* qstart,
double* qend,
ode_solver<X>* solver,
double& h)
100 bool event_in_interval =
false, found_event =
false;
103 for (
int i = 0; i < this->sys->
numEvents(); i++)
106 if (sign(z[1][i]) != sign(z[0][i]))
111 ((mode != DISCONTINUOUS) && (fabs(z[1][i]) <= err_tol)) ||
113 ((mode == DISCONTINUOUS) && (h <= err_tol))
116 events[i] = found_event =
true;
121 if (mode == INTERPOLATE)
123 double tcandidate = z[0][i]*h/(z[0][i]-z[1][i]);
125 if (tcandidate < h/4.0) tcandidate = h/4.0;
126 if (tcandidate < tguess) tguess = tcandidate;
128 event_in_interval =
true;
133 if (event_in_interval)
135 if (mode == BISECTION || mode == DISCONTINUOUS) h /= 2.0;
137 for (
int i = 0; i < this->sys->
numVars(); i++)
141 else return found_event;
150 template <
typename X>
163 template <
typename X>
176 template <
typename X>
int numEvents() const
Get the number of state events.
Definition: adevs_hybrid.h:54
Mode
Definition: adevs_event_locators.h:54
bool find_events(bool *, const double *, double *, ode_solver< X > *, double &)
Definition: adevs_event_locators.h:196
Definition: adevs_event_locators.h:164
Definition: adevs_event_locators.h:44
Definition: adevs_event_locators.h:190
Definition: adevs_hybrid.h:406
Definition: adevs_event_locators.h:151
int numVars() const
Get the number of state variables.
Definition: adevs_hybrid.h:52
Definition: adevs_fmi.h:56
virtual void advance(double *q, double h)=0
Definition: adevs_event_locators.h:177
bool find_events(bool *events, const double *qstart, double *qend, ode_solver< X > *solver, double &h)
Definition: adevs_event_locators.h:90
virtual void state_event_func(const double *q, double *z)=0
Compute the state event functions for state q and put them in z.
Definition: adevs_hybrid.h:45
Definition: adevs_hybrid.h:377