Message Boards Message Boards

0
|
4859 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Integrator step value problem for an FMU exported by System Modeler

Posted 3 years ago

I'm developing a program that should simulate FMU's, it is based on the FMU SDK. It can be found in: https://fmi-standard.org/downloads/

I've developed a simple model in SM just to test some program features. The model is attached to the post. I've exported a Co-Simulation FMU (2.0) with DASSL solver from the model and executed it in my program. The problem is when I set the step for the function DoStep to 0.1 or 0.01 the simulation gets stuck at the DoStep function.

while (time < t_end)
{     

    if (step > t_end - time) step = t_end - time;

    fmi2Flag = fmu_sim->fmu.doStep(fmu_sim->c, time, step, fmi2True);
    if (fmi2Flag == fmi2Discard) {
        fmi2Boolean b;
        // check if model requests to end simulation
        if (fmi2OK != fmu_sim->fmu.getBooleanStatus(fmu_sim->c, fmi2Terminated, &b)) {
            return error("could not complete simulation of the model. getBooleanStatus return other than fmi2OK");
        }
        if (b == fmi2True) {
            return error("the model requested to end the simulation");
        }
        return error("could not complete simulation of the model - fmi2Discard");
    }
    if (fmi2Flag != fmi2OK) return error("could not complete simulation of the model - ERROR!");

    printf("time: %.10f\n",time);

    time += step;

}

I found that the error is related to the block IntegerStep1:

enter image description here

The function get stuck at the time step immediately before the step start time. I tried different values, for example: if I put a start time of 7 then it gets stuck at 6.9 for a 0.1 step or gets stuck at 6.99 for a 0.01 step. if I put a start time of 10 then it gets stuck at 9.9 for a 0.1 step or gets stuck at 9.99 for a 0.01 step. Doesn't matter simulation end time. However, if I change the step value for different values than those two everything works. Also, if put something like 0.10000000001 or 0.010000001, it works fine as well.

What is strange is that for the boolean step start time in the model there is no error.

After all the test, I tried to open the FMU in SM and execute it with a 0.1 and 0.01 step and it worked well, I'm not sure what I can be missing in the program.

System information:

Product version: 12.1.0.8
Client: Model Center
Client version: 12.1.0.30
Client creation date: 2020-03-02T13:38:32.855263
Client build revisions: S:2b715d78e, J:6a53ed2a2, L:41ddb1b72
Client build type: 64 bit
Kernel version: 12.1.0.34
Kernel creation date: 2020-03-02T13:39:13.038056
Kernel build revisions: S:2b715d78e, J:6a53ed2a2, L:41ddb1b72
Platform: Ubuntu 14.04.6 LTS

Attachments:
POSTED BY: Michel Oliveira
3 Replies
Posted 3 years ago
POSTED BY: Updating Name
Posted 3 years ago

What is strange is that for the boolean step start time in the model there is no error.

If you look at the implementation in MSL they differ slightly so that might be the explanation why you see different behaviour.

After all the test, I tried to open the FMU in SM and execute it with a 0.1 and 0.01 step and it worked well, I'm not sure what I can be missing in the program.

The FMI2 CS API is quite small and simple so I really don't have any good ideas for why it works in System Modeler and not in your program. The only guess I could come up with is that are you by any chance using float for your time and step variables? Maybe the reduced precision could cause issues since your communication point coincides with the event time when the integer step starts.

Otto

POSTED BY: Updating Name

Thanks for the answer.

The only guess I could come up with is that are you by any chance using float for your time and step variables?

I forgot to put in the previous post but the type of time and step is double.
I have another testing model (attached) that is quite similar and it works with that step values. And this second model have an integerStep as well.

EDIT: I tried to vary the integerStep height parameter, I found that the problem occurs only for odd values. Also, I tried the same test in the model attached in this post, found the same problem.

EDIT2: I removed the integer to real and integer to real conversion parts of the model and the problem doesn't happens anymore. I replaced them with a integer sum block. So, in some way, the step value of 0.1 and 0.01, integerStep block and conversion blocks doesn't properly work together for my simulation code. Now is like this:

enter image description here

Attachments:
POSTED BY: Michel Oliveira
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract