Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save start / initial guess values in OpenModelica & implement initial values from file

There is an option in Dymola "Save start values in the model", which allows one to re-use these parameters in order to tune the simulation.

I was looking for a similar possibility in OpenModelica, but so far I wasn't able to figure it out. Particularly, I am building a model with ThermoSysPro, which is rather sensitive to the change of initial values. My model has several vertical pipes (upstream, downstream), so it fails quite easily.

1. Is it possible to save initial / start / guess values in OpenModelica?

2. What would be the ways of implementing / taking these values in the model? (let's say I have density - ρ, enthalpy - h, temperature - T and so on. Just for simplification purposes for Modelica newbie)

------UPDATE------

In my case, I have two approaches to start / initial values: (ThermoSysPro - TSP)

Approach 1 - Run the simulation for 1s without changing default start-values given in TSP by introducing desired boundary conditions or close ones that it would run successfully.

Gather the generated initial values and add them as start-values (time-consuming when one has a lot of components).

For components such as “volume” or any other component that is not discretized it is enough to give these values under the “Initialization” section in the component or in the “Text view” window e.g. Q(start = 0.3); P(start = xxx).

But in case of discretized components, such as “pipe” it has to be done via “Text view” by using the operator each e.g. Q(each start = 0.3). However, the operator “each” disappears when one changes any parameter of the component via “Diagram view”, so it has to be given as follows:

•   Q(start = {0.3 for i in 1:componentName.Ns+1}) 
•   Q(start = fill(0.3, componentName.Ns+1))
•   Q(start = {x1, x2, x3, x4, … xi})

Ns + 1 - for hydraulic nodes / Ns – for thermal nodes

PROBLEM

P.1.1 - Normally, one should write:

Q(start = fill(0.3, Ns+1), fixed = fill(true/false, Ns+1)) 

But it is the same story as with operator each, after changing any parameter of the component via “Diagram view”, the attribute fixed changes automatically to fixed=false, although an array is needed. I tried creating a Boolean parameter and using array comprehension but I always get the same outcome. Any advice or workaround?

P.1.2 – I cannot see any improvement (speed up / better results / or something else) of simulations, after adapting the generated start-values instead of using default ones. Also, after adapting too many of them, I start getting initialization problems – which should be opposite for my understanding. So, I am not sure how I should be using/declaring start-values properly? Maybe the problem is that I do not explicitly add fixed = true/false?

Approach 2 – calculate start-values based on the boundary conditions by using Modelica functions. So firstly, I calculate start-values of multiple parameters (normally I do for pressure and enthalpy). e.g.

parameter Modelica.SIunits.Enthalpy init_enthalpy[Ns+1] = {Modelica.Media.Water.WaterIF97_base.specificEnthalpy_pT(P[i], T) for i in 1:Ns+1}

and then add it for specific component as:

h(start = init_enthalpy)

PROBLEM:

P2.1 With the ThermoPower library this approach works perfectly, but with ThermoSysPro, I am having difficulties, as there are so many parameters that can be given for initialization. How many parameters generally should be given or how to locate the most important ones that definitely should be given?

P2.2 Is there a difference between declaring start / initial values in the initial equation section and calculating it as a parameter (like above)?

P2.3 By indicating that start-value is either fixed=true / false wouldn’t mean that you are using the so-called "inverse problem"?

like image 359
Tomillo Avatar asked Feb 25 '26 03:02

Tomillo


1 Answers

I am not aware if the option of automated saving of initial values is available jet, but in general you can set initial values of variables either with an initial equation or you can change the start attribute of a variable. If it is a state you have to set the fixed attribute to true such that it will be considered for initialization.

model test
  Real a(start=10, fixed=true);
  Real b;
initial equation
  b = 20;
equation
  der(a) = cos(time);
  der(b) = sin(time);
end test;

Nonlinear iteration variables for nonlinear systems and discrete variables also need to have start values.

like image 168
kabdelhak Avatar answered Feb 27 '26 22:02

kabdelhak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!