Hi Johan,

First, sorry for the delay I tagged your mails to be read later but took some 
time to reach them 😊. Your last mail bumped the full conversation.

To better understand the simulation time, let me describe you what happens when 
you click play. After creating the schema you basically have a set of blocks 
with parameter values set at edition time and a set of links that connect 
blocks. Before simulation happens there is still work to do:
 1. As parameters can change the structure of blocks, we need to 
refresh/evaluate all blocks to set a parameters to the current values.
 2. A flatten copy is created to resolve inputs/outputs ports on subsystem
 3. The schedule of the graph is computed and a "compiled" cpr structure is 
created

On the simulation phase, you can only use this cpr structure to run ODE solvers 
on your system and produce results.

If you want to do multiple simulation of the same system changing only 
parameters *and* keeping the same diagram structure, I suggest you to use `Info 
= scicos_simulate(scs_m, Info)` where Info is defined as : Info = list(%tcur, 
%cpr, alreadyran, needstart, needcompile, %state0) . This seems not documented 
enough.

You can update parameters on Info(2) , the cpr, or Info(6) , the states, by 
yourself. This will remove all "compilation time" without using the internal 
scicosim  and let you change final time or filter parameters for example. For 
customers, we used this approach to do some optimization on filter coefficient.

Hope this will help you,
Regards,

Clément


-----Original Message-----
From: users <users-boun...@lists.scilab.org> On Behalf Of johan64
Sent: Sunday, February 28, 2021 12:56 PM
To: users@lists.scilab.org
Subject: Re: [Scilab-users] 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
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to