Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Equation not satisfied in long simulation

Equation not satisfied in long simulation

Hey I'm having a problem with a longish simulation (1 year, 60 sec intervals).  It seems like a bug, as I'm not getting any errors, but I haven't narrowed it down enough to concisely explain the problem in a bug report.  I'm here looking for general suggestions about how I can go about diagnosing/fixing the problem.

I have a very simple equation in one of my models (derivative of energy equals power):

Code:

der(E) = p

After running the simulation (no errors with the default logging), and viewing the results, I see at times that a positive value of der(E) has no affect on E (it doesn't increase as expected).  In other sections of the simulation it works perfectly.

I have identified the time where the first mismatch occurs.  If I run the simulation starting just before the first mismatch (with the appropriate initial conditions so it comparable), the problem doesn't occur.  See the attached plots which show the difference between the two simulations for the region of interest, with the top plot working as expected.  Notice in the bottom plot how E doesn't change.

https://www.openmodelica.org/images/agorapro/attachments/4559/mini_equation-mismatch.png

Has anyone had a similar problem?  Do you have any general advice for where I should look?

I'm trying to diagnose the problem by reading the source code and outputting more detailed debugging info.  I'm also trying to trim the model down to the smallest subset which still has trouble so that I can share it for others to try.  So far I haven't had much luck with either.

Thanks

Edited by: pppsco - Sep-10-15 05:12:48

Re: Equation not satisfied in long simulation

Have you tried using a different numerical solver?

Re: Equation not satisfied in long simulation

No but I have now.  Rungekutta seems to work correctly (at least by scanning the plot by eye).  I was originally using DASSL.

So it appears like there is a problem with DASSL.  One other thing I tried earlier was to change the way the Jacobians were calculated, but it didn't fix the problem.

I'd like to continue to try and debug the problem, but for now what am I forgoing if I adopt the rungekutta method?  Is it speed, accuracy or poorer convergence?

Re: Equation not satisfied in long simulation

It's an explicit method, so you don't get a solution within an error tolerance. You get whatever accuracy that your stepsize and model gives you. For some models, RK4 works very well. On stiff models, not good at all. You also can get no indication that your error tolerance is violated. The method can be very fast for some models.

Re: Equation not satisfied in long simulation

Thanks for the info.

Back on the original problem.  Based on what you have seen does this seem like a failing of the numerical algorithm in dassl (wrong algorithm for the problem), a bug in dassl or a bug in the om interface to dassl?  If the algorithm was struggling with the problem I would have expected it to produce some kind of errors.  This is especially the case because it is an implicit method right?

Off topic again:  I see that the C++ runtime has an interface to IDA.  What is the state of the C++ simulation runtime, is it still in "beta"?  Is it expected to replace the C runtime or just be an alternative?  I got the source to compile on a simple problem (complication was very slow with clang++), but it would fail to compile on a more complicated model.

Thanks again for your help.  I plan on getting more involved with the OM community as I'm working on an open source tool that can be used by researchers to easily simulate and optimise solar thermal power plants using novel designs and working fluids.  Not much to show for it yet, however we plan on using OM as a core component for simulation and likely also optimisation.

Cheers

Re: Equation not satisfied in long simulation

When I turn on LOG_SOLVER for the dassl I get:

|                 | |       | | solver: DASSL
|                 | |       | | | 84457 steps taken
|                 | |       | | | 110857 calls of functionODE
|                 | |       | | | 51853 evaluations of jacobian
|                 | |       | | |  4631 error test failures
|                 | |       | | |     0 convergence test failures

Are the "error test failures" anything to be worried about?  I seem to get them in both simulations (the broken long one and the short working one).

Re: Equation not satisfied in long simulation

The C++ runtime is not a priority of the core development team, but it is used by some of our industrial partners and mostly maintained to support their models. Other models might not work. And yes, it uses a lot of templates and similar, so it needs to re-compile more code than the C runtime every time you run a model.

As for dassl, it sometimes fails if the number of intervals are too many. It works very well in many cases, but not for all problems.

Re: Equation not satisfied in long simulation

So what is it about too many intervals that causes a problem?  Is it because the chosen interval size is so small that the equations barely change between steps or is it that the DASSL algorithm doesn't like long simulations not matter what the underlying equations are?  With my limited knowledge on the subject, the only explanation I can think of for these is that either it is somehow having trouble scaling the problem for the range of time values used, or it is a bug in the solver.  Do you know if someone has been investigating this problem?

Re: Equation not satisfied in long simulation

There are some bugs with event handling and trying to calculate what is a small value to detect events, for example. Some of these kind of values in OM depend on the step size.

Re: Equation not satisfied in long simulation

Hello pppsco,

pppsco wrote:


I have identified the time where the first mismatch occurs.  If I run the simulation starting just before the first mismatch (with the appropriate initial conditions so it comparable), the problem doesn't occur.  See the attached plots which show the difference between the two simulations for the region of interest, with the top plot working as expected.  Notice in the bottom plot how E doesn't change.

It seems there are some events missed. Are other variable, which may influence the events also the same?

pppsco wrote:


When I turn on LOG_SOLVER for the dassl I get:

|                 | |       | | solver: DASSL
|                 | |       | | | 84457 steps taken
|                 | |       | | | 110857 calls of functionODE
|                 | |       | | | 51853 evaluations of jacobian
|                 | |       | | |  4631 error test failures
|                 | |       | | |     0 convergence test failures

Are the "error test failures" anything to be worried about?  I seem to get them in both simulations (the broken long one and the short working one).

The "error test failures" is related to the step size control algorithm and just state that the algorithm has chosen 4631 times a step size which was too large to stay with the trajectory within the given tolerances.  So that is nothing to worry about, as long as the number is not too large. If it would get too large it's just an indicator for performance issues.

Could you try to run the model with Dassl and deactivate internal root finding algorithm, then a external root finding will be used. (There is check box)

so long.
Willi

Re: Equation not satisfied in long simulation

Hey wbraun,

The first event that happens in that time window is at around 7000 for the working simulation (reading output from LOG_EVENTS).  This coincides with the first discrete drop in the derivative.  But already before this time there is an error.  From 3000 to 7000 the derivatives are positive, but in the second plot the energy E doesn't change.

In the second plot the events don't trigger at 7000 and beyond because they are dependent on E, which doesn't change.  So it doesn't seem like the problem is a missed event.  From the start of the time window up to 7000 all other variables are the same, except possibly some small numerical difference.

I just tried the `-dasslnoRootFinding` flag.  Same results.

Any other ideas?

Thanks for the help.

Re: Equation not satisfied in long simulation

Hey,

hm, without the model to play with, I'm not sure where to search.
So would it be possible for you to provide your model
(perhaps in private via email.)

so long.
Willi

Re: Equation not satisfied in long simulation

Hey,

hm, without the model to play with, I'm not sure where to search.
So would it be possible for you to provide your model
(perhaps in private via email.)

so long.
Willi

Re: Equation not satisfied in long simulation

Please report bugs here.

There are 0 guests and 0 other users also viewing this topic
You are here: