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 Equation

Initial Equation

Hi

I am trying to give some initial values to the variables through initial equation section. But the intial values are not being set to the variables and the intial equations are getting bypassed. This is the code which I have developed

model sam
  annotation(Diagram(coordinateSystem(extent = {{ -100, -100},{100,100}})));
  parameter Real W_inic = 17.5;
  parameter Real T_in = 60;
  parameter Real rho_l = 983.2;
  parameter Real lat_heat = 2260;
  parameter Real C = 4.187;
  parameter Real V = 10;
  parameter Real P_out = 2;
  parameter Real a = 9.2807;
  parameter Real b = 2788.51;
  parameter Real c = 220.79;
  parameter Real ti = 500;
  parameter Real cg = 0.005;
  parameter Real P_vic = 4.7;
  parameter Real T_zero = 273.16;
  parameter Real xvz = 0.7;
  parameter Real xva = 0.3;
  parameter Real xvw = 0.5;
  parameter Real mwt = 78;
  parameter Real m_lic = (rho_l * V) / 2;
  parameter Real kv = W_inic / (xvz * sqrt(P_vic * (P_vic - P_out)));
  parameter Real Tl_temp = b / (a - log(P_vic)) - c;
  parameter Real q = W_inic * (C * (Tl_temp - T_in) + lat_heat);
  parameter Real r = 8.314 / mwt;
  parameter Real Ts = 0.01;
  Real xv;
  Real m_total(fixed = false);
  Real W_in,W_out;
  Real m_l(fixed = false);
  Real P_v(fixed = true);
  Real rho_v;
  Real V_v(fixed = true, start = 0);
  Real Q_total(fixed = false);
  Real m_v(fixed = false);
  Real T_l(fixed = false);

equation
  xv = 0;
  der(m_total) = W_in - W_out;
  der(Q_total) = q + W_in * C * T_in - W_out * (C * T_l + lat_heat);
  m_l = m_total - m_v;
  Q_total = m_l * C * T_l + m_v * (C * T_l + lat_heat);
  W_in = 0;
  W_out = kv * xv * sqrt(abs(P_v * (P_v - P_out))) * sign(P_v - P_out);
  P_v = exp(a - b / (c + T_l));
  0 = P_v - rho_v * r * (T_l + T_zero);
  rho_v = m_v / V_v;
  V_v = V - m_l / rho_l;

initial equation
  P_v = P_vic;
  T_l = 60;
  V_v = 0;
  m_l = (rho_l * V) / 2;
  m_v = 0;
  Q_total = m_l * C * T_l + m_v * (C * T_l + lat_heat);
  W_out = 0;
  rho_v = (P_v * V_v) / (r * (T_l + T_zero));
end sam;

But the values are being simulated as if the initial equations were not present. For example, the value of V_v starts at 5 instead of 0, P_v starts around 0.5 instead of 4.7

Any help/suggestion will be very helpful

Thank you

John

Re: Initial Equation

$ ./sam
ERROR: Division by zero in partial equation: m_v / V_v because V_v == 0.
Error in initialization. System of initial equations are not consistent.

There are 0 guests and 0 other users also viewing this topic