I try to make a parametrised library. I works fine using packages and connectors as parameters.
Using a model as a parameter is also possible. However, if the model is used in the library to build new models using extend, then it is not allowed, what I understand.
I wonder if the library contains a model with inner/outer style of connector, is it then allowed to let the inner model to be a parameter of the library?
Below a simple example to illustrate the problem. TEST is the library and Fish3b is an application. When I run the Example in the library TEST it all works, but when I have a separate application file it does not.
The error text is: cannot find class declaration for AquariumType running JModelica 2.4
package TEST
model FishType1
outer Real T;
Real health;
equation
health = 30-T;
end FishType1;
model FishType2
outer Real T;
Real health;
equation
health = 32-T;
end FishType2;
package Equipment
model AquariumType
replaceable model FishType
end FishType;
FishType fish;
inner Real T;
equation
T = 29;
end AquariumType;
end Equipment;
// Adapt AquariumType model to actual fish
model Aquarium
import TEST.Equipment.AquariumType;
extends AquariumType(redeclare model FishType=FishType2);
end Aquarium;
// Example
model Example
Aquarium aquarium;
end Example;
end TEST;
And below an example of application code that import from library above - and here is some error I think.
encapsulated package Fish3b
model FishType3
outer Real T;
Real health;
equation
health = 34-T;
end FishType3;
// Adapt package Equipment with AquariumType model to actual fish
package Equipment3
import TEST.Equipment;
extends Equipment.AquariumType(redeclare model FishType=FishType3);
end Equipment3;
// Example
model Example
import Fish3b.Equipment3;
Equipment3.AquariumType aquarium;
end Example;
end Fish3b;
Updated the code with input from Hans Olsson before, but slightly different with the corrections suggested above. And I manage to avoid “extend from a replaceable model”, but I am not too sure how critical that is, see my previous comment.
Also, I think I would like to keep the clear identity of the different fishes, and also declare them outside package Equipment.
package TEST3
partial model FishBase
outer Real T;
end FishBase;
model FishType1
extends FishBase;
Real health;
equation
health = 30 - T;
end FishType1;
model FishType2
extends FishBase;
Real health;
equation
health = 32 - T;
end FishType2;
package Equipment
replaceable model FishType
end FishType;
constant Integer dummy = 1;
model AquariumType
FishType fish;
inner Real T;
equation
T = 29;
end AquariumType;
end Equipment;
// Adapt package Equipment to the actual fish
package Equipment3
import TEST3.Equipment;
extends Equipment;
redeclare model FishType=FishType2;
end Equipment3;
// Example
model Example
Equipment3.AquariumType aquarium;
end Example;
end TEST3;
And an example of application code:
encapsulated package T3_Fish3
model FishType3
import TEST3.FishBase;
extends FishBase;
Real health;
equation
health = 34-T;
end FishType3;
// Adapt package Equipment to the actual fish
package Equipment3
import TEST3.Equipment;
extends Equipment(redeclare model FishType=FishType3);
end Equipment3;
// Example
model Example
Equipment3.AquariumType aquarium;
end Example;
end T3_Fish3;