-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient handling zero-crossing surfaces #588
Comments
Regular design webmeeting: Christian: What are the values for directions? |
@KarlWernersson : What is your opinion on this? |
It this like the master telling a co-simulation FMU when the ball is going to bounce?
In my opinion, FMUs used to contain specialized "know how" in terms of model and solvers. So for me this is like taking some resposibility from the exporting tool to fully support the simulation of a given phenomena and makes end user more dependent on the features of a "master". |
The main motivation behind this proposal is to avoid state-event detection conflict between the solver and the FMU. As a very simple example, suppose that an event-indicator (with previous positive value) becomes negative or almost zero withing this condition Abs(EI(i))<=EPS1 where EPS1 is the epsilon used by the solver to declare a state-event. If this condition happens, the solver considers this as a state-event and pushes the FMU into the event mode. An important point to notice is that this proposal is just an EXTRA INFORMATION delivered by the solver to the FMU and creates no backward incompatibility. |
I agree that there can be an issue, and we need to have a good solution. As indicated in #587 I believe we need to be sure how to handle the "event state" of the FMU (referred to as "with previous positive value"). Note that I don't see any issue if the event-indicator becomes almost zero. I believe the FMU should be responsible for maintaining that state. Above there was some discussion whether the FMU could just reported if the event had occurred (and internalize the event indicator). The answer is that it doesn't work well - for efficient detection the master need to find the exact event points - and for efficiency reasons that requires interpolation of a smooth function, and a binary signal isn't smooth. I don't think the FMU has enough information to interpolate on its own. |
Regular design meeting: Decision : Move to future. |
After a quick read of #1042, I'd say the proposal by @masoud-najafi here might be solution that removes the ambiguities in the cause of entering event move. In model exchange, it is the importer that's doing that, so there can be no ambiguity. It shouldn't be guesswork for the FMU to redo the work of the importer and detect events (at least those happening in continuous time mode). As @jbernalr mentioned, a co-simulation FMU is responsible for doing the state event detection, so there's no ambiguity there. My 2 cents is that if the flags get removed (as they should be, proposed in #1042), then this extra function should be introduced for model exchange. |
PS - The example in modelica/Reference-FMUs#229 currently uses the flags as a way of knowing that a clock has to be activated. This is unambiguous because the FMU only has one event, and one clock. If the FMU had two clocks (and two event indicators), then the FMU's implementation would have to be more complex to resolve the ambiguity when entering event mode. So, should this new function go forward, we could extend the above example to exemplify this. |
In the current FMI-3 specification, as well as in FMI-1 and FMI-2, in order to find and handle the state-events, the integrator monitors the zero-crossing surfaces during the numerical integration using the fmiXGetEventIndicators function in the continuous-time mode. Once the integrator finds a crossing, integration is stopped and the FMU is pushed into the Event mode to handle the state-event.
In the event-mode, the FMU should evaluate and compare its zero-crossing surfaces and find crossed surfaces and trigger the correspoding state event.
In many cases, due to numerical errors, this procedure is troublesome and errornous, and the simulator or the FMU needs to introduce a small threshold to avoid or reduce the effects of numerical errors.
What is proposed here is to give the integrator (simulator) the right to pass the vector of crossed zero-crossings to the FMU. In this way, the FMU need not reevluate the surfaces and numerical errors will be avoided. This is more important when state-events are linked to clock ticks.
What is needed is just a new API to pass crossed surfaces as well as their direction into the FMU:
if ticket (#587) is accepted for FMi-3, this API is good:
fmi3Status fmi3SetStateEvent(fmi3Component c,
const fmi3ValueReference vr[], size_t nvr,
const fmi3Int8 direction[], size_t nDirections);
otherwise this API should be used:
fmi3Status fmi3SetStateEvent(fmi3Component c, const fmi3Int8 direction[], size_t nzc); // size of direction is nz (number of zero-crossings)
The text was updated successfully, but these errors were encountered: