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

initial conditions in openmodelica

initial conditions in openmodelica

Dear everyone,

I am using OpenModelica, and meet a problem.

In my model, I initialize each variable with certain value, such as
Real T(start = T0)

However, I need T0 to change at each iteration in for loop in ordre to solve an ODE. For example, I use "for loop".  At the beginning of each loop, I want to update the value of T.

How can I do this ?

Many thanks!

Re: initial conditions in openmodelica

Code:


algorithm
  for ... loop
    T := ...;

Edited by: sjoelund.se - Apr-23-21 12:12:59

Re: initial conditions in openmodelica

sjoelund.se,
 
   thank you for your answer,

   In fact, I would like to assign a value for the initial temperature for each iteration, knowing that these values are saved in an array.

  So I want the Tint takes a new value from the array for each iteration, in order to solve an ODE.



HOOOOPING that I have described the problem correctly and you have understood my question.

thanks



Code:

model temperartureModel


parameter Real Tint=17.5;
Real T(start=Tint);

parameter Real [6,9] data={{22.3,    26.6,    27.7,    30.7,    29.8,    31.3,    19.5,    539,    0.3},
{26.5,    27.7,    29.3,    27.9,    29.8,    31.3,    19.6,    535,    0.8},
{26.9,    27.7,    28.1,    29.3,    29.9,    31.3,    19.7,    478,    1.6},
{27.3,    28.5,    28.3,    29.6,    29.9,    31.4,    19.7,    482,    2.3},
{27.3,    28.0,    28.0,    29.5,    29.8,    31.4,    19.7,    500,    2.5},
{27.4,    28.1,    28.6,    29.6,    29.8,    31.3,    19.8,    548,    2.5}};
//

/*
other parameters


*/
equation
for i in 1: N_mesure loop

der(T) = (q_punto_r_g_sky + q_r_g_gr * (Ta - T) + q_conv_g * (Ta - T) - q_cd_g_pv * (T - Tint) + alfa_fg * G * Ag) * (1 / Cg);

// others equations
end for

end temperartureModel;

Edited by: Abderezakabidi - Apr-23-21 16:29:39

Re: initial conditions in openmodelica

When you write:

Code:


Real T(start=T0, fixed=true);

It means that T has start value T0 at initialization. You cannot change that T0 in a for loop. If you have a for lopp in an algorithm or equation section that cannot affect the initialization anymore. Only start=value or initial algorithm or initial equation section can affect the initialization problem.

What you want seems to be like starting the same model with different T0 in a for loop. If this is what you want let us know and we'll give you some solutions for that.

Re: initial conditions in openmodelica

adrpo wrote:

What you want seems to be like starting the same model with different T0 in a for loop. If this is what you want let us know and we'll give you some solutions for that.

Having an array instead would probably be the easiest way of doing that.

Re: initial conditions in openmodelica

adrpo,

  thannnnk you,
  very well explained, I understood your answer.

  in truth, I'm trying to translate a model from Matlab to OpenModelica.

   I managed to translate all parameters, constants, equations ... etc. but my problem is that I cannot translate this instruction which is used to solve ODE.in

Code:



t_7,T_7]=ode45('Modello3',tspan,T0_7);
//
Modello3 is the function that contain ODE
.....

I know that there is DASSL solver for ode in openmodelica but I don't know how does it works

Code:



T0_7=[16.2+273.15 16.2+273.15 16.2+273.15 16.2+273.15  16.2+273.15 16.2+273.15  32+273.15 ];
t0=0;                %Istante di tempo iniziale
tf=60;              %Istante di tempo finale
tspan=t0:1:t0+tf-1;

for i=1:1:N_misure

[t_7,T_7]=ode45('Modello3',tspan,T0_7);
//
Modello3 is the function that contain ODE
.....

T0_7=T_7(length(T_7), : ) ;

t0=t0+length(T_7);
end

Edited by: Abderezakabidi - Apr-24-21 13:42:41
There are 0 guests and 0 other users also viewing this topic
You are here: