Reputation: 11
I have two models (A&B) in Modelica and I want to call a parameter from the model A in the model B. In fact, model A calculates the value of a parameter and I need to get access to that value in the model B. How can I do it?
I tried "extends" command to connect two models but components are also connected, but I need only that specific parameter.
Upvotes: 1
Views: 378
Reputation: 188
You can use dot notation to reference "public" variables between instances of classes in models.
In the following example model "Test", is an instance of model A (named "a") and an instance of model B (named "b"). The value of parameter "pB" is modified go get its value from the calculated parameter "sA" from the instance of model A.
model Test
model A
parameter Real pA = 1.234;
final parameter Real sA = 2*pA;
end A;
model B
parameter Real pB = 4.321;
final parameter Real sB = pB/2;
Real x;
equation
x = sB;
end B;
A a;
B b(pB = a.sA);
end Test;
Simulating this model, the value of variable "b.x" is 1.234. This is because the value of "sA" is twice "pA" and the value of "sB" is half "pB" and the modifier equates "pB" to "a.sA".
So we have used dot notation to refer to the parameter "sA" to modify the value of parameter "pB". Without this modifier we would see the value of x to be around 2.16 instead.
Upvotes: 7