Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Problem with redeclare in partial classes

Problem with redeclare in partial classes

Hi,

I am starting to use OpenModelica so I am trying to get all the information I can from the forums, but I am not able to solve my problem (very basic, I guess) at all.

I just want to run the simulation of the GTUnit from the ThermoPowerLibrary. Since it is a partial class, I run the simulation and I get the following errors:


[1] 14:27:33 Translation Error
[ThermoPower.Gas: 3270:5-3393:19]: Illegal to instantiate partial class GTunitBase.

[2] 14:27:33 Translation Error
Error occurred while flattening model GTUnitBase_prueba

[3] 14:32:20 Translation Error
[ThermoPower.Gas: 3281:7-3281:78]: Exhaust is partial, name lookup is not allowed in partial classes.

[4] 14:32:20 Translation Error
[ThermoPower.Gas: 3282:7-3282:71]: Air is partial, name lookup is not allowed in partial classes.

So OK, I know that I have to redeclare something, but what? I see that I cannot just rewrite the library file so I have duplicated the GTUnitBase inside my own model and then tried to include in some lines redeclare package Medium = Medium as I have seen in other topics, but a lot of errors appear as well.

Anyway, I cannot figure out how to solve this I would appreciate if someone can orient me on what I should include and where.

You can find attached my model.

Thanks!


GTUnitBase-prueba.mo

Re: Problem with redeclare in partial classes

Since GTunitBase is a partial model you can't declare components of that type, i.e. you can't instantiate it. What you need to do is extend the model, and redeclare the needed bits:

Code:


model MyGTunitBase
  extends ThermoPower.Gas.BaseClasses.GTunitBase(
    redeclare package Air = Some.Air.Medium,
    redeclare package Fuel = Some.Fuel.Medium,
    etc...
  );
end MyGTunitBase;

However, are you sure you want to use GTunitBase? You probably won't be able to use the model like this without additional setup. You might be better of using the GTunit model instead, which already does this. If you want to configure the mediums used in GTunit you can still extend from it like shown above, or you can create a GTunit component since GTunit isn't partial:

Code:


model SomeModel
  ThermoPower.Gas.GTunit gtUnit1(redeclare package Air = Some.Air.Medium, etc..);
end SomeModel;

You might also want to look at the models in ThermoPower.Test, which contains examples of how the models can be used.

Edited by: perost - May-23-19 13:14:12
There are 0 guests and 0 other users also viewing this topic
You are here: