OMShell returns 字符串但无法识别

OMShell returns String but doesn't recognize it

对于我的一个模型,需要读取所有变量的最终值并将其设置为下一次模拟的初始值。我真正的问题是由于 OMShell 中定义的类型。在OpenModelica的the scripting commands中可以看到,有String类型和"VariableName"、"TypeName"类型。详细说明区别:

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

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

原因是 loadModel 函数不需要字符串变量。它需要模型的名称。返回我的问题,我尝试使用 val 函数,如下所示,以便我可以将值作为下一次模拟的初始值。

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

这可以通过使用 for 循环 为每个变量完成,我认为我有几个变量,此时我意识到了问题。

// 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)

如何从 OMShell returns 给我的字符串中删除“”?我需要将 "myVar" 转换为 myVar 以便我可以将其用作 OMShell 函数的输入。

您可以使用stringVariableName函数。

>>> vars:=OpenModelica.Scripting.readSimulationResultVars(currentSimulationResult)
{"r","time"}
>>> val(stringVariableName(vars[1]), 0.0)
1.0