I am using the Dimensions model
for placing parameters of the system that I use in many different models and call them by using extend
, instead of declaring them again for each model. This is a simple example, but in reality, I have the way more of them.
A simple model with the structure I have:
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;
If I run this example in OMEdit it works without any problem. However, if I run it in OMShell or OMPython / OMCSessionZMQ it doesn't work.
Q - maybe I am using the extends
clause incorrectly? If so, what would be the alternative of declaring parameters once and reusing them in other models?
This is what I get in 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
"
And this is from 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}