modelica - How can I make a string executable? -
i'm trying execute string in modelica. string saved in variable in order able change when need to.
function test input string incomp="resistor.r:=2"; output string outcomp; algorithm outcomp:=incomp; end test; could please
i using dymola.
what need following.
-read component names text file (or input them while executing function) -then change parameters of these components. code example:
function test input string incomp="resistor"; //entered user, or read text file output real result; algorithm incomp.r :=2 ; /*this incorrect since wouldn't understand want enter : resistor.r := 2; */ result := incomp.r ; //in order view result end test;
what trying not possible in modelica. may tools have "reflective api" allows (or perhaps built-in function takes command string , executes it) there no universal api works across tools.
if want run bunch of simulations in dymola different parameter values, can suggest @ least 3 different wants proceed.
- use dde interface send commands dymola. way can formulate parameter values "somehow" (externally dymola) , request dymola run simulations. i'm not sure how rich dde interface is, i'm not sure if need (e.g. reaping results).
- write script file. bit different writing function, same in syntax. example, run "coupledclutches" example several different inertia values, can (in command window):
j in {1.0, 1.1, 1.2, 1.5, 1.8} loop j1.j := j; simulatemodel("modelica.mechanics.rotational.examples.coupledclutches", resultfile="coupledclutches_"+string(j)); end for; - use function (as were) call simulatemodel modifiers, e.g.
function runloop algorithm j in {1.0, 1.1, 1.2, 1.5, 1.8} loop simulatemodel("modelica.mechanics.rotational.examples.coupledclutches(j1(j="+string(j)+"))", resultfile="coupledclutches_"+string(j)); end for; end runloop; - use built-in functions
simulateextendedmodel,simulatemultiextendedmodelpretty same above in cleaner way (typedocument("simulateextendedmodel"),document("simulatemultiextendedmodel")in dymola command window more info on these).
ok, should give start. if none of work whatever reason, update question whatever additional requirements have.
Comments
Post a Comment