#2356 closed defect (fixed)
ExternalObject: constructor arguments must not be variables
Reported by: | Owned by: | Andreas Hofmann | |
---|---|---|---|
Priority: | critical | Milestone: | 1.9.0 |
Component: | Frontend | Version: | 1.9.0Beta |
Keywords: | ExternalObject | Cc: |
Description
Hi,
using externalObjects with variables as inputs causes the model flattening to fail.
ErrorMessage:
OpenModelica requires that all external objects input arguments are possible to evaluate before initialization in order to avoid odd run-time failures, but a is a variable.
According to the Modelica Specs 3.3 (p.158) there should be no problem using variables. Testing in Dymola using pedantic mode gave no problems.
Attachments (1)
Change History (8)
by , 11 years ago
Attachment: | externalObjectProb.zip added |
---|
comment:1 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in r17300. I made the error just a warning and now this model works.
comment:2 by , 11 years ago
Actually, what was the problem? I tested it using the old omc, and it was fine. The linked model uses a parameter as expected.
And this is required since before the first use of the external object, only parameters can be known at the model level (only use of non-parameters are using external objects in functions).
comment:3 by , 11 years ago
If you are using (in the added model) a instead of b it does not work. Unfortunately I forgot to change the input argument from b back to a. I am sorry about that.
comment:4 by , 11 years ago
Yes, the attached model uses a parameter.
But in the model I added as test to r17300 the input to the external object is a variable.
I don't know exactly what the specification says about this, but an external object constructor is just a function call, so it should be possible to use a variable I guess.
The question is what do you want to model. This seems a bit weird that you want to use a variable in a constructor to an external object. How is this supposed to be handled in the initialization I have no idea. I mean what is the value of the variable when you call the constructor. And also, the question is when do you call the constructor? Before the initialization? After it? So I guess this might not give you the correct results (or the ones you expect).
comment:5 by , 11 years ago
The constructor function is called exactly once before the first use of the object. For each completely constructed object, the destructor is called exactly once, after the last use of the object, even if an error occurs. The constructor shall have exactly one output argument in which the constructed type derived from ExternalObject is returned. The destructor shall have no output arguments and the only input argument of the destructor shall be of the type derived from ExternalObject. It is not legal to call explicitly the constructor and destructor functions.
This implies that the input has to be a parameter expression that is not dependent on any parameter that uses this external object to initialize.
There is nothing explicitly about parameters since you could construct and destruct an external object inside a function call.
comment:6 by , 11 years ago
I am working on some kind of a ContactLibrary. There I have a ContactBody and a ContactWorld. Since they are connected by an inside-connector I cannot set them to be parameters.
Like sjoelund.se said, I think there was nothing in the Modelica Specs forbidding to use variables. And as far as the pedantic mode in Dymola uses the Modelica Specs it seems not to cause any trouble.
comment:7 by , 11 years ago
Well, maybe Dymola does the check in the backend and has removed the use of the variable a. It is a constant expression after all...
Example demonstrating the problem (created in OMEdit)