- Index
- » Programming
- » Modelica Language
- » Define a parameter with a formula
Define a parameter with a formula
Define a parameter with a formula
Hello
Right now I'm starting with the programming in modelica, but I have some issues defining parameters, because what I want to do is to first giv some parameters to a formula and then with the result of that equatin define a new parameter. the problem is shown here:
class Resistor_cond
parameter Real num = 2;
parameter Real L = 1.5;
parameter Real W = 0.008;
parameter Real H = 0.1;
parameter Real k_bar = 385;
parameter Real nodes = 15;
Real R,L_1(start = 1);
equation
if num == 0 then
L / (4 * (nodes - 1)) = L_1;
L_1 / (H * W * k_bar) = R;
G=1/R;
elseif num == 1 then
L_1 = (3 * L) / (4 * (nodes - 1));
R = L_1 / (H * W * k_bar);
G=1/R;
elseif num == 2 then
L_1 = L / (nodes - 1);
R = L_1 / (H * W * k_bar);
G=1/R;
end if;
parameter Real G(start = 0, unit = "K/W")=1/R;
end Resistor_cond;
I want to convert the variable G into a parameter in order to put it as a parameter for a thermal resistance.
Thank you very much un advance
Re: Define a parameter with a formula
Hello mariomar
G cannot be in that position and has to be declared in the beginning before the equation section.
In addition G cannot be a parameter as it is defined using R, that is a variable.
Now the easiest way is to let G to be a variable instead of a parameter, and to remove the =1/R in the initialization, as you have put the equation G = 1/R.
In addition you can put this equation only once instead of copying it to all if - elseif, iI mean:
Code:
equation
G=1/R;
if num == 0 then
L / (4 * (nodes - 1)) = L_1;
L_1 / (H * W * k_bar) = R;
elseif num == 1 then
L_1 = (3 * L) / (4 * (nodes - 1));
R = L_1 / (H * W * k_bar);
elseif num == 2 then
L_1 = L / (nodes - 1);
R = L_1 / (H * W * k_bar);
end if;
best regards
Koldo
- Index
- » Programming
- » Modelica Language
- » Define a parameter with a formula