You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone. I am trying to solve an NLP on a Dymola model imported as FMU through the DaeBuilder class. I can simulate in Matlab the imported system getting the same results as Dymola. However, i cannot solve optimizations. I notice that the jacobians of the system are not as i would expect (too many elements equal to zero).
Investigating, i found that these problems of Jacobians occur even for simpler models. I tried to reproduce the CasADi example "race_car" with dynamics obtained from an FMU imported from Dymola (Model exchange with FMI 2.0 specification).
Here the Modelica code :
model race_car
Real pos;
Real speed;
input Real u;
equation
der(pos) = speed;
der(speed) = u - speed;
end race_car;
And here is the Matlab code to load the FMU:
import casadi.*
clear all;close all;clc;
% Define the name of the Modelica file and FMU file
modelName = 'race_car';
fmu_file = fullfile(pwd, strcat(modelName, '.fmu'));
% Path for the unzipped FMU
if exist(modelName, 'dir') == 7
% Folder exists, so delete it
rmdir(modelName, 's'); % 's' flag to delete recursively
else
end
% Unzip the FMU file
unzip(fmu_file, modelName);
dae = DaeBuilder('race_car',modelName);
f = dae.create('f',{'x','u'},{'ode'});
Jx_fun = dae.create('J',{'x','u'},{'jac_ode_x'});
Jx = full(Jx_fun([0;1],1));
The first row of the ODE Jacobian (Jx) It should have been [ 0, 1] instead it was [ 0, 0].
Through some manipulations I can get the right Jacobian but I can't figure out why. I have found three different ways:
Change the first differential equation within the modelica code from der(pos) = speed to der(pos) = (pos – pos) + speed
Reverse the order of states declaration (and diff. Equations) within the modelica code from x = [ pos, speed] to x = [ speed, pos]
Manually edit in the modelDescription.xml file the variable indexes and their dependencies to change the variables order
from [pos, der(pos), speed, der(speed), u] to [pos, speed, der(pos), der(speed), u]
These solutions do not work with my model and anyway do not seem like a right way to go. Therefore, I would like to understand if possible where these problems arise from to try to avoid them with my model.
Has anyone already encountered these kinds of problems?
Thank you all.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone. I am trying to solve an NLP on a Dymola model imported as FMU through the DaeBuilder class. I can simulate in Matlab the imported system getting the same results as Dymola. However, i cannot solve optimizations. I notice that the jacobians of the system are not as i would expect (too many elements equal to zero).
Investigating, i found that these problems of Jacobians occur even for simpler models. I tried to reproduce the CasADi example "race_car" with dynamics obtained from an FMU imported from Dymola (Model exchange with FMI 2.0 specification).
Here the Modelica code :
And here is the Matlab code to load the FMU:
The first row of the ODE Jacobian (Jx) It should have been [ 0, 1] instead it was [ 0, 0].
Through some manipulations I can get the right Jacobian but I can't figure out why. I have found three different ways:
der(pos) = speed
toder(pos) = (pos – pos) + speed
x = [ pos, speed]
tox = [ speed, pos]
from
[pos, der(pos), speed, der(speed), u]
to[pos, speed, der(pos), der(speed), u]
These solutions do not work with my model and anyway do not seem like a right way to go. Therefore, I would like to understand if possible where these problems arise from to try to avoid them with my model.
Has anyone already encountered these kinds of problems?
Thank you all.
Beta Was this translation helpful? Give feedback.
All reactions