<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body style='font-family: Verdana,Geneva,sans-serif'>
<p><br /> Hello Romain,<br /><br /> Running your code in 5.4.1 just tells me that 'cpr' variable is unknown when you call it at line <span style="font-size: small;">"state=cpr.state;"</span>.<br /><br /> So I replaced <span style="font-size: small;">"xcos_simulate(scs_m,4)"</span> by <span style="font-size: small;">"cpr = xcos_simulate(scs_m,4)"</span> and it runs smooth ("-->cpr" yields an output) until the end.<br /><br /> I noted that you modifed cpr.sim.rpar(5) twice, but you probably meant cpr.sim.rpar(6) the second time?<br /><span style="font-size: small;"> cpr.sim.rpar(5)=T; // timestep<br /> cpr.sim.rpar(5)=0; // initialisation</span><br /><br /> Otherwise, I didn't manage to reproduce your bug.<br /><br /> Regards,<br /> Paul<br /><br /> PS: you may want to use the Context to modify a diagram from batch, see xcos_simulate <a href="http://help.scilab.org/docs/5.4.1/en_US/xcos_simulate.html">help page</a>. It is safer to fully recompile Modelica diagrams between simulations.<br /><br /><br /></p>
<div class="moz-cite-prefix">On 02/19/2014 11:34 AM, Romain Desbats wrote:</div>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px">
<div style="font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000;">Dear Scilab users,<br /><br /> 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.<br /><br /> What I would like is to run it in batch mode from Scilab in order optimise the model parameters.<br /><br /> My plan is to use <em>xcos_simulate</em> to compile the diagram, to modify the <em>cpr</em> variable generated by the compilation (to change the model parameters) and than to simulate the model with <em>scicosim</em>.<br /><br /> The problem is that calling the <em>cpr</em> variable after the compilation results in kind of "freezing" the workspace.<br /><br /> - The variable browser shows "N/A" for all the variables (from image 1 to image 2 attached)<br /> - Calling <em>cpr</em> does not give any result (image 3 attached)<br /><br /> Does anyone has any idea of what is happening?<br /><br /> I am using Scilab 5.4.1.<br /><br /> My code is as follows:<br /><br /><span style="font-size: small;">// parameters<br /> data=csvRead('input.csv',';');<br /> input_current=evstr(data(:,1));<br /> size1=length(input_current);<br /><br /> C=1/10000;<br /> R=12900;<br /><br /> T=0.0001; // timestep<br /><br /> time=[0:T:(size1-1)*T]'; // in s<br /><br /> end_time=time($)+T; // end time in s<br /><br /> // loading Xcos functions<br /> loadScicos;<br /> loadXcosLibs();<br /> exec(loadpallibs,-1);<br /><br /> // loading model<br /> importXcosDiagram('graphic_model.xcos')<br /><br /> // compilation: scs_m is the result of the import,<br /> xcos_simulate(scs_m,4) // '4' is to perform compilation<br /><br /> tf=end_time;<br /><br /> atol=1.e-8;<br /> rtol=1.e-9;<br /> ttol=1.e-10;<br /> deltat=tf;<br /> scale=0;<br /> hmax=0;<br /><br /> tol=[atol,rtol,ttol,deltat,scale,hmax];<br /><br /> // PROBLEM COMES WHEN EXECUTING NEXT LINE<br /><br /> state=cpr.state; // cpr variable came from the compilation<br /> sim=cpr.sim;<br /><br /> cpr.sim.rpar(5)=T; // timestep<br /> cpr.sim.rpar(5)=0; // initialisation<br /> cpr.sim.rpar(7)=R; // resistance<br /> cpr.sim.rpar(8)=C; // capacitor<br /><br /> // initialisation<br /> [state,t]=scicosim(state,0,tf,sim,'start',tol);<br /> // run<br /> [state,t]=scicosim(state,t,tf,sim,'run',tol)<br /> //end<br /> [state,t]=scicosim(state,t,tf,sim,'finish',tol);<br /><br /> graph_voltage=graph_voltage.values; // output variable</span><br /><br /> Thanks a lot for your help.<br /><br /><span id="DWT143" class="addrBubble-selected" style="position: static; overflow: visible;"><span><span id="DWT143_select" class="addrBubbleHide"></span></span></span>Best regards,<br /><br />
<div><span></span><span style="font-size: xx-small;"><span style="font-size: small;">Romain</span></span></div>
</div>
<br /><fieldset class="mimeAttachmentHeader"></fieldset><br />
<pre>_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<p> </p>
<pre class="moz-signature">--
Paul BIGNIER
Development engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.69
<a class="moz-txt-link-freetext" href="http://www.scilab-enterprises.com">http://www.scilab-enterprises.com</a> </pre>
</body></html>