Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OMShell returns String but doesn't recognize it

For one of my models, it is required to read the final value of all variables and set them as initial value for the next simulation. My real problem is due to types defined in OMShell. As can be seen in the scripting commands of OpenModelica, there are String type and "VariableName", "TypeName" types. To elaborate the difference:

// The following loads the Standard Modelica Library
>> loadModel(Modelica)
true

// The following throws an error
>> loadModel("Modelica")

The reason is that the loadModel function doesn't expect a string variable. It expects the name of the model. Returning my problem, I tried to use val function as in the following, so that I can give the value as the initial value of the next simulation.

>> final_time := 200;
>> myVarValue := val(myVar, final_time);

This can be done for each variable by using a for-loop, I thought as I have several variables and I realized the problem at this point.

// Get the list of all variables
>> myVarList := readSimulationResultVars(currentSimulationResult);
>> size(myVarList)
{724}

// The problem is that this list contains strings
>> myVarList[1]
"mySubSystem.myComponent.myPin.v"

// Following throws an error as it doesn't expect a string
>> val(myVarList[1], final_time)

How can I remove "" from the string that OMShell returns to me? I need to convert "myVar" to myVar so that I can use it as an input for the functions of OMShell.

like image 969
Falsterbo Avatar asked Jun 21 '26 17:06

Falsterbo


1 Answers

You can use the stringVariableName function.

>>> vars:=OpenModelica.Scripting.readSimulationResultVars(currentSimulationResult)
{"r","time"}
>>> val(stringVariableName(vars[1]), 0.0)
1.0
like image 129
sjoelund.se Avatar answered Jun 24 '26 20:06

sjoelund.se