Comments (2)
Your assessment is correct. The current event handler implicitly assumes that there is at most one zero-crossing event during a single simulation step. If that assumption is correct, _find_event_time
will properly detect only events with the desired direction, as the direction has been previously checked in _find_active_events
.
If that assumption is not correct, we would need a different way of detecting events in any case, e.g., by subsampling the simulation interval or by using interval search. This will be adressed in #32.
from modypy.
Properly split the issues. #32 now only addresses handling of Zeno behaviour, and this one addresses event detection and localization.
There are several strategies for event detection and localization. Zhang et al, 2008 (https://doi.org/10.3182/20080706-5-KR-1001.01346) provides a good entry point.
The main issues are
- dependable detection of zero-crossings, specifically when an even number of zero-crossings occur over the time interval of the respective integration step, and
- efficient localization of the zero-crossings, specifically the crossing with the minimum time index.
The current approach cannot detect even numbers of zero crossings and cannot guarantee the detection of the actual first crossing matching the direction criterion set for the event.
Zhang et al mention three major approaches:
- Step size feedback control using the dynamics of the zero-crossing function (Park and Barton, 1996, https://doi.org/10.1145/232807.232809),
- subsampling of the integration step and application of the classical sign-change check in combination with a classical root-finding algorithm (mentioned without reference by Zhang et al, 2008), and
- detection and localization using interval arithmetics (Pantelides et al, 1988, https://doi.org/10.1016/0098-1354(88)85062-2).
While the step size feedback-control-based approach can guarantee the proper detection and localisation of a single event, it requires modification of the integrator. Specifically, it requires a solver for differential-algebraic-equations, which currently is not available, at least not in scipy. An integration of the state-of-the-art DASKR solver (Brown, Hindmarsh and Petzold, 1998, https://doi.org/10.1137/S1064827595289996) into scipy would help here.
Zhang et al introduce the subsampling approach as the most efficient in their list, without going into detail about the reasons. The approach merely shifts the issue of the original approach (no detection of even-numbered sign changes, no guarantee for finding the first zero-crossing, handling direction constraints). However, it is clearly the simplest of the approaches in terms of implementation and may prove sufficient for most applications.
The approach by Pantelides et al uses interval arithmetic for filtering and the convergence-properties of the Newton-Rhapson-root-finding method combined in the Krawczyk Operator to implement a divide-and-conquer approach for localisation of unique roots. Successively subdividing the time interval of interest and using an interval-convergence check, the method can determine whether a given interval does not contain any roots or a unique root. If neither can be guaranteed, the interval is split and the test is repeated on the new parts. The approach is a bit more involved and requires a polynomial interpolation of the event function with respect to time - introducing possible inaccuracies as well - but for a given class of event functions it can be guaranteed to be correct.
Both the interval-based approach by Pantelides et al and the subsampling approach mentioned by Zhang et al have high potential for implementation. For that, new implementations of the _EventDetector
class implementing the different strategies can be created and the Simulator
class can be parameterized further to enable users to select a suitable event detection strategy.
from modypy.
Related Issues (20)
- Check whether Simulator can be simplified by using scipy.integrate.solve_ivp HOT 1
- Try to keep integrator instance if no reset of integration time occurred
- Investigate improved handling of Zeno behaviour
- Add terminator-event support
- Allow modelling clock-jitter
- Add introduction on mixed systems to the documentation
- Make SimulationResult iterable
- Describe the simulator main loop in the documentation
- Add a Simulator option to suppress intermediate samples
- Allow specifying event sources that lead to yielding intermediate samples
- Introduce basic operators for signals
- Implement discrete-time IIR filter component
- Introduce generic wrapping of functions into signals HOT 1
- Introduce "Time" signal
- Document access to old system state in state updaters
- State, signal and event matrices are inconsistent with numpy broadcasting rules
- Investigate using `scipy.signal.sosfilt` for more efficient filtering HOT 1
- Allow construction of LTIs from `scipy.signal.lti` objects.
- Update for Python 3.10/3.11, drop 3.6/3.7 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modypy.