我正在使用Dimensions model
for 放置我在许多不同模型中使用的系统参数并通过 using 调用它们extend
,而不是为每个模型再次声明它们。这是一个简单的例子,但实际上,我有更多方法。
一个具有我所拥有结构的简单模型:
package Main
model Dimensions
final parameter Modelica.SIunits.Length x = 10;
final parameter Modelica.SIunits.Length y = 5;
end Dimensions;
package Test_env
extends Main.Dimensions;
model Test_model
Real z;
equation
z = x + y;
end Test_model;
end Test_env;
end Main;
如果我在OMEdit中运行此示例,它可以正常工作。但是,如果我在OMShell或OMPython / OMCSessionZMQ中运行它,它就不起作用。
问- 也许我extends
错误地使用了该子句?如果是这样,那么声明一次参数并在其他模型中重用它们的替代方法是什么?
这就是我在OMShell中得到的:
>> loadFile("D:/1.Modelica/Simulations/Main.mo")
true
>> getClassNames()
{Main}
>> getClassNames(Main)
{Dimensions,Test_env}
>> getClassNames(Main.Test_env)
{Test_model}
>> simulate(Main.Test_env.Test_model, startTime=0, stopTime=1, numberOfIntervals=500, tolerance=1e-4, method="dassl", outputFormat="mat"); getErrorString()
record SimulationResult
resultFile = "",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 0.0001, method = 'dassl', fileNamePrefix = 'Main.Test_env.Test_model', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
messages = "Failed to build model: Main.Test_env.Test_model",
timeFrontend = 0.0110966,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0111225
end SimulationResult;
"[D:/1.Modelica/Simulations/Main.mo:3:5-3:45:writable] Error: Class Modelica.SIunits.Length not found in scope Main.Dimensions.
[D:/1.Modelica/Simulations/Main.mo:1:1-18:9:writable] Error: Class Test_env.Test_model not found in scope Main.
Error: Class Main.Test_env.Test_model not found in scope .
Error: Error occurred while flattening model Main.Test_env.Test_model
"
这是来自OMPython / OMCSessionZMQ:
omc.sendExpression('simulate(Main.Test_env.Test_model, stopTime=1.0)')
---------------------------------------------------------------------------
{'resultFile': '',
'simulationOptions': "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'Main.Test_env.Test_model', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
'messages': 'Failed to build model: Main.Test_env.Test_model',
'timeFrontend': 0.0018766,
'timeBackend': 0.0,
'timeSimCode': 0.0,
'timeTemplates': 0.0,
'timeCompile': 0.0,
'timeSimulation': 0.0,
'timeTotal': 0.0018919}