OpenModelica / OMMatlab

Matlab scripting OpenModelica interface
12 stars 4 forks source link

FATAL Problem, Lin-Sim sequential use #24

Closed MohammadHadiAlizadeh closed 1 year ago

MohammadHadiAlizadeh commented 1 year ago

Please consider the following model & Matlab script:

model test8
parameter Real[1,3] x_P;
parameter Real[1,3] y_P;
  Real[1,3] x;
Real[1,3] y(start=y_P);

 input Real u;

equation

der(x)=x.^0.1 .+u;
y=2*x;

initial equation
x=x_P;

end test8;
clear all
import OMMatlab.*

omc=OMMatlab();
omc.ModelicaSystem("test8.mo","test8");
%% Setting input
omc.setInputs("u=2");

%% initiallizing the system (initial equation)
for i=1:3
    omc.setParameters("x_P_1_"+num2str(i)+"_="+mat2str(1));
end

%% Simulate

 %omc.setSimulationOptions(["startTime=0","stopTime=1"]);
  omc.setSimulationOptions(["startTime=0","stopTime=0"]); % Problematic
 omc.simulate()
 r=omc.getSolutions("x[1,2]");

 %% reinitialize & linearize
 for i=1:3
    omc.setParameters("x_P_1_"+num2str(i)+"_="+mat2str(2));
 end

  omc.setLinearizationOptions(["startTime=0","stopTime=1"]);
 b= omc.linearize();

When we use simulation options as omc.setSimulationOptions(["startTime=0","stopTime=1"]); the sequential use of simulation and linearization completes successfully.

But if we set the simulation options as omc.setSimulationOptions(["startTime=0","stopTime=0"]); ( in case we want to initialize the model and get the initial states only), the simulation finishes successfully. But when it comes to run linearization, the process does not stop and fills the Windows drive(C:\ in my PC) completely (like an infinity loop for data generation)!!!!!!!

However, both the linearization and simulation have simple mathematical solutions in each case!

casella commented 1 year ago

Ouch, this shouldn't happen. @arun3688 can you please have a look.

arun3688 commented 1 year ago

@MohammadHadiAlizadeh @casella I can reproduce the problem in Matlab, based on the initial testing, i can see the configurations works directly from the mos script,

loadFile("test8.mo"); getErrorString();
simulate(test8, startTime=0, stopTime=0, simflags="-override=x_P[1,1]=1,x_P[1,2]=1,x_P[1,3]=1"); getErrorString();
linearize(test8, startTime=0, stopTime=1, simflags="-override=x_P[1,1]=2,x_P[1,2]=2,x_P[1,3]=2"); getErrorString()

Based on initial debugging, i see that if the stopTime is same for both linearize and simulation, then OMMatlab works fine.

I guess, there is some problem in the csv file when setting the inputs, I will debug more and fix it.

arun3688 commented 1 year ago

@MohammadHadiAlizadeh The issue is fixed with this commit https://github.com/OpenModelica/OMMatlab/commit/837c33c4d53fe6df07b77ae298236200ada19439, pull the changes from master and test it. The problem with infinity loop for data generation happened due to setting linearization options i.e stopTime in two different places, especially in overrideFile

MohammadHadiAlizadeh commented 1 year ago

@arun3688 , thanks. I'm closing the issue.