How to implement nested if statements in Modelica?

Viewed 2470

I am trying to implement a fault inclusive model of an HVAC system. The fault starts at a user defined time, in this case faultTime = 1000. However, the first part of the if statement is not implemented at all. The following is a snippet of code that is relevant to the question

fcuModel FCU;
Modelica.Blocks.Continuous.LimPID PI(k = 300, Ti = 1, yMax = 1, yMin = 1e-4);
parameter Real faultTime = 1000;
// fault modes: 0-normal, 1-fan failed, 2-valve stuck shut...
parameter Integer faultMode = 1;
equation
  connect(PI.u_m,FCU.Ts_zon); // connects zone temperature to PID measurement
  PI.u_s = 21; // set-point for zone temperature
  if time<faultTime then
    PI.y = FCU.val;
    PI.y = FCU.fs;
  else
    if faultMode == 0 then
      PI.y = FCU.val;
      PI.y = FCU.fs;
    elseif faultMode == 1 then
      PI.y = FCU.val;
      FCU.fs = 1e-4;
    end if;
  end if;  

When I simulate, it runs without error but the it directly goes to the equations under faultMode == 1, without simulating the fault-free state for the first 1000 seconds.

1 Answers
Related