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

How to setup Variable Initial Value?

How to setup Variable Initial Value?

Dear everyone,

I am using OpenModelica, and meet a problem.

In my model, I initialize each variable with C0, such as
Real C[N](each start = C0)

However, I need C0 to change at some certain time. For example, I use "for loop".  At the beginning of each loop, I want to update the value of C0.

How can I do this ?

Many thanks!

Re: How to setup Variable Initial Value?

Since you use C0 as a start-value, it is required to be a parameter expression. Parameter expressions can never change, so what you try to do is impossible.

Re: How to setup Variable Initial Value?

You can probably do this using bindings and maybe you need reinit and when equations.
It depends if you have continuous variables or discrete ones.

Code:


Real C0 = somevalue;
Real C[N] = fill(C0, N) ;
equation
when time > 10 then
  reinit(C0, someothervalue);
end when;
// for loop ...

Re: How to setup Variable Initial Value?

Thank you!

Is there some function like 'xlsread' and "xlswrite" in matlab?
Since I want to simulate a large number of loops, and the result of step j is the initialization of step j+1
Do you have any idea about this?

Re: How to setup Variable Initial Value?

Because my model is very complex consisting of 21 partial differential algebraic equations, and I want simulate it for hundreds of cycles, I cannot update the initial values by hand.

Could you give me some suggestion?

There are 0 guests and 0 other users also viewing this topic
You are here: