[Scilab-users] xcos_simulate()

classic Classic list List threaded Threaded
2 messages Options
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] xcos_simulate()

Hi,

 

My xcos model becomes quite large and takes time to compile. In order to launch batches and optimisation process, it seems possible to compile the model juste one time.

However, I meet the same difficulties as described in this post :

 

<a href="http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274&quot;&gt;http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274

 

Indeed, the following script...

  ___________________________________

loadXcosLibs;

importXcosDiagram("C:\Users\johan\OneDrive\Micro entreprise\Technique\Kayak guide\Modélisation\Scilab\optimisation"+"\modèle physique et commande simple_10_opti.zcos");

tic();

xcos_simulate(scs_m, 4);

disp("méthode 2",toc());

 

tic();

%cpr = xcos_compile(scs_m);

disp( "Durée compilation",toc());

 

tic();

xcos_simulate(scs_m,1)

disp( "méthode 1",toc());

  ___________________________________

 

...gives the following results :

 ___________________________________

"scicos_simulate step 1"

   50.813412 s

 

  "scicos_simulate step 2"

   57.440604 s

 

  "xcos_simulate(scs_m, 4) méthode 2"

   58.808546 s

 

  "Compilation duration"

   55.615238 s

 

  "xcos_simulate(scs_m,1) méthode 1"

   61.133700 s

 ______________________________


It seems the compilation step is done in all these cases.

 

Thank you for your time and for your help


Johan


note 1 : when the final time of the simulation is set from 20s to 200s, the execution time increases about 15s

 

note 2 : according to the windows task manager, CPUs seem to be used about 30% during compilation and about 100% during simulation which takes few seconds


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

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
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users