[Scilab-users] Problem running xcos in batch mode from Scilab

paul.bignier at scilab-enterprises.com paul.bignier at scilab-enterprises.com
Thu Feb 20 10:35:55 CET 2014


 

 Hello Romain,

 Running your code in 5.4.1 just tells me that 'cpr' variable is unknown
when you call it at line "state=cpr.state;".

 So I replaced "xcos_simulate(scs_m,4)" by "cpr =
xcos_simulate(scs_m,4)" and it runs smooth ("-->cpr" yields an output)
until the end.

 I noted that you modifed cpr.sim.rpar(5) twice, but you probably meant
cpr.sim.rpar(6) the second time?
 cpr.sim.rpar(5)=T; // timestep
 cpr.sim.rpar(5)=0; // initialisation

 Otherwise, I didn't manage to reproduce your bug.

 Regards,
 Paul

 PS: you may want to use the Context to modify a diagram from batch, see
xcos_simulate help page [3]. It is safer to fully recompile Modelica
diagrams between simulations.

On 02/19/2014 11:34 AM, Romain Desbats wrote: 

> Dear Scilab users,
> 
> I am running a simple electrical model in xcos (see attached). This model reads a .csv input file and outputs a variable to the workspace. The model works fine when I compile it and run it by using the menus in xcos.
> 
> What I would like is to run it in batch mode from Scilab in order optimise the model parameters.
> 
> My plan is to use _xcos_simulate_ to compile the diagram, to modify the _cpr_ variable generated by the compilation (to change the model parameters) and than to simulate the model with _scicosim_.
> 
> The problem is that calling the _cpr_ variable after the compilation results in kind of "freezing" the workspace.
> 
> - The variable browser shows "N/A" for all the variables (from image 1 to image 2 attached)
> - Calling _cpr_ does not give any result (image 3 attached)
> 
> Does anyone has any idea of what is happening?
> 
> I am using Scilab 5.4.1.
> 
> My code is as follows:
> 
> // parameters
> data=csvRead('input.csv',';');
> input_current=evstr(data(:,1));
> size1=length(input_current);
> 
> C=1/10000;
> R=12900;
> 
> T=0.0001; // timestep
> 
> time=[0:T:(size1-1)*T]'; // in s
> 
> end_time=time($)+T; // end time in s
> 
> // loading Xcos functions
> loadScicos;
> loadXcosLibs();
> exec(loadpallibs,-1);
> 
> // loading model
> importXcosDiagram('graphic_model.xcos')
> 
> // compilation: scs_m is the result of the import,
> xcos_simulate(scs_m,4) // '4' is to perform compilation
> 
> tf=end_time;
> 
> atol=1.e-8;
> rtol=1.e-9;
> ttol=1.e-10;
> deltat=tf;
> scale=0;
> hmax=0;
> 
> tol=[atol,rtol,ttol,deltat,scale,hmax];
> 
> // PROBLEM COMES WHEN EXECUTING NEXT LINE
> 
> state=cpr.state; // cpr variable came from the compilation
> sim=cpr.sim;
> 
> cpr.sim.rpar(5)=T; // timestep
> cpr.sim.rpar(5)=0; // initialisation
> cpr.sim.rpar(7)=R; // resistance
> cpr.sim.rpar(8)=C; // capacitor
> 
> // initialisation
> [state,t]=scicosim(state,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);
> 
> graph_voltage=graph_voltage.values; // output variable
> 
> Thanks a lot for your help.
> 
> Best regards,
> 
> Romain 
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users [1]

-- 
Paul BIGNIER
Development engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.69
http://www.scilab-enterprises.com [2] 
 

Links:
------
[1] http://lists.scilab.org/mailman/listinfo/users
[2] http://www.scilab-enterprises.com
[3] http://help.scilab.org/docs/5.4.1/en_US/xcos_simulate.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140220/05db82d3/attachment.htm>


More information about the users mailing list