2

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.

yaska
  • 225
  • 3
  • 7

1 Answers1

5

I modified your model to make it work directly by introducing some variables and changing some parameters. Which resulted to be:

model FCU

  Modelica.Blocks.Continuous.LimPID PI(k = 0.1, Ti = 1, yMax = 1, yMin = 1e-4);

  parameter Real faultTime = 1000;
  parameter Integer faultMode = 1;

  Real val;
  Real fs;

equation 
  PI.u_s = 21; // set-point for zone temperature
  PI.u_m = 20.9999; // no feedback as no system available  

  if time<faultTime then
    PI.y = val;
    PI.y = fs;
  else
    if faultMode == 0 then
      PI.y = val;
      PI.y = fs;
    elseif faultMode == 1 then
      PI.y = val;
      fs = 1e-4;
    else
     assert(false,"Unknown faultMode");
    end if;
  end if;
  annotation (experiment(StopTime=2000), uses(Modelica(version="3.2.2")));
end FCU;

The result below (simulated in Dymola) seem to be what I would expect. Result

Hope this helps...

Scott G
  • 2,194
  • 1
  • 14
  • 24
Markus A.
  • 6,300
  • 10
  • 26
  • 1
    Looks like it misses the else case. – tbeu Nov 28 '17 at 12:55
  • 2
    Since faultMode is an integer parameter there is no need for the else-case, but I agree "if faultMode==1 then ... else " would be cleaner. – Hans Olsson Nov 28 '17 at 15:10
  • 1
    From the Modelica 3.4 Specification, Section 8.3.4: If-equations in equation sections which do not have exclusively parameter expressions as switching conditions shall have the same number of equations in each branch. – matth Nov 29 '17 at 08:34