- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Function resolution problem
Function resolution problem
Function resolution problem
The following piece of Modelica works fine in Dymola, but fails in OpenModelica (1.8.1):
Code:
within ;
package TestPackage
model Test
protected
TestPackage.Wrapper wrapper;
Real dummy;
equation
dummy = wrapper.Container.f();
end Test;
model Wrapper
package P = TestPackage.Container;
end Wrapper;
package Container
function f
output Real y;
algorithm
y := 1;
end f;
end Container;
annotation (uses(Modelica(version="3.2")));
end TestPackage;
The error message from OMC is
Code:
>> loadModel(Modelica)
true
>> loadFile("TestPackage.mo")
true
>> simulate(TestPackage.Test)
record SimulationResult
resultFile = "",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'TestPackage.Test', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = ''",
messages = "Simulation failed for model: TestPackage.Test
[TestPackage.mo:11:2-11:31:writable] Error: Class wrapper.Container.f not found in scope TestPackage.Test (looking for a function or record).
Error: Error occurred while flattening model TestPackage.Test
",
timeFrontend = 0.0,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0
end SimulationResult;
If I replace the function Container.f with (for example) a constant or if I remove the Container layer (and put the function directly into the Test model) then it works. What exactly is the problem here?
Re: Function resolution problem
Hi Florian,
The error message is correct, the wrapper instance does not contain a Container class so wrapper.Container.f cannot be found. I assume you meant to call wrapper.P.f() instead? Unfortunately that will also fail, since we currently have some issues with calling functions via instances. We are working of fixing that, but at the moment I cannot give an estimate when this might be fixed.
- perost
- 114 Posts
Re: Function resolution problem
Hi perost,
you are right. I forgot to rename the variable while cleaning the code. It should be
Code:
wrapper.P.f()
Can you tell me more about the issues OpenModelica 1.8.1 has with calling functions via instances? E.g. is it in general impossible to do this using OMC 1.8.1. or are there special cases that do/do not work?
Re: Function resolution problem
I think the issue is mostly with calls where the first identifier is an instance, the last a function and one or more classes in between. Calling a function in this manner is actually a new feature introduced in the soon to be released Modelica 3.3 specification, even though Dymola has supported this for a long time. Calling a function via an instance without any other classes in between should work fine in OM.
- perost
- 114 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Function resolution problem