Reputation: 457
I want to set a default variable name T (=xx) inside a model - drag that model into a new model and define there the variable xx. I get the error message: Use of undeclared variable xx.
This is the sub-model
model test
parameter Real T = xx;
Real f;
equation
f = T + time;
end test;
this is the full model
model fullmodel
parameter Real xx = 12;
Test Test1;
end fullmodel;
My question: How would you do that in Modelica? I need for my model 100 of the same models and i want to set a few parameters (diamter, lenghts, etc.) per default to a variable name and then define just this variables. I know i could propagate the variable - but it would be nice, if i just have to drag the model and then defining the parameters. Thank you for your help!
Upvotes: 3
Views: 376
Reputation: 9421
Another possibility if you have multiple instances of the same model and you don't want to repeat the modification is to do something like this:
model test
parameter Real T;
parameter Real S=1;
Real f;
equation
f = S*(T + time);
end test;
model fullmodel
parameter Real xx = 12;
// Create an "alias" model using a short class definition that
// includes a modification (for all instances of PreConfig).
model PreConfig = Test1(T=xx);
// Now create instances (potentially with their own unique values
// for some parameters
PreConfig pc1(S=1), pc2(S=2), pc3(S=3);
end fullmodel;
As I mentioned in the comment above, another implementation of fullmodel
that uses an array would look like this:
model fullmodel
parameter Integer n = 100;
parameter Real xx = 12;
// Create 100 instances of Test1. Each on has the same
// value for T, but they each have different values for
// S
Test1 tarray[n](each T=xx, S=linspace(0, 1, n));
end fullmodel;
Upvotes: 2
Reputation: 4231
Alternatively you can do this using inner/outer:
model Test
outer parameter Real xx;
parameter Real T = xx;
Real f;
equation
f = T + time;
end Test;
model fullmodel
inner parameter Real xx = 12;
Test test1;
end fullmodel;
Upvotes: 2
Reputation: 4231
You should be able to do something like:
model test
parameter Real T;
Real f;
equation
f = T + time;
end test;
model fullmodel
parameter Real xx = 12;
Test Test1(T = xx);
end fullmodel;
Upvotes: 3