[Scilab-users] xcos_simulate()

johan64 johan.lafitte at gmail.com
Sun Feb 28 12:55:46 CET 2021


Hi,

I am sorry, there is a mistake in my first post. Please, don't care about
the script described in italic.

My need is to compile my xcos diagram one time, simulate, then change
context parameters and run other simulations (in order to perform parametric
optimization on a large xcos model with many parameters and about 10-15
state variables).

I did some research and tests. To sum up :

1/xcos_simulate(scs_m,needcompile) : According to the Scilab Help,
needcompil is "DEPRECATED". Therefore, compilation is needed each times.

//////////////////////////////
2/scicos_simulate(scs_m,Info). I tried the PID optimization example method.
https://wiki.scilab.org/Xcos/Examples/PID
<https://wiki.scilab.org/Xcos/Examples/PID>  

Execute my model with
///Lancement de la simulation 
disp("lancement")
 tic(); 
Info=scicos_simulate(scs_m,list())  
disp( "Durée simulation1",toc());  
tic(); 
Info=scicos_simulate(scs_m,Info) 
 disp( "Durée simulation2",toc())/

Gives

/"lancement"    
"Durée simulation1"     83.604448    
"Durée simulation2"     81.738820/
Therefore, I win just 2 seconds with this method

/////////////////////////////////////////////////////
3/scicosim(); It seems to be the holy grail.
/
disp("lancement")
tic();
cpr=xcos_simulate(scs_m,4)
//cpr = xcos_compile(scs_m);
disp( "Simulation time 1 =",toc());
//Exploitation des données de compilation
state0=cpr.state; // cpr variable came from the compilation
sim=cpr.sim;
//Paramètre de simulation
tf=111;
atol=1.e-6;
rtol=1.e-6;
ttol=1.e-10;
deltat=tf;
scale=0;
solver=0;
hmax=0.1;

tol=[atol,rtol,ttol,deltat,scale,solver,hmax];

//Enregistrement des résultats
//save(pathu_result);

tic();
// initialisation
[state,t]=scicosim(state0,0,tf,sim,'start',tol);
// run
[state,t]=scicosim(state,t,tf,sim,'run',tol)
//end
[state,t]=scicosim(state,t,tf,sim,'finish',tol);
disp("Simulation time 2"+" = ",toc());
/
Gives
/
"Simulation time 1 ="

   83.815849

  "Simulation time 2 = "

   0.9816021
/ 

I win about 83 seconds!!! 

Unfortunately, after running xcos_simulate one time, I don't find simple way
to change context parameters without launch xcos_simulate again (using
scs_m.props.context...) which wastes simulation time.
cpr.sim.rpar seems to contain block parameters but without symbolic
expression.

does anyone have an idea?

Thank you for your help






--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html



More information about the users mailing list