Comparison of Modeling Language Syntax


Tank Model Diagram and Equations





Tank Model in APMonitor Modeling Language
Model tank

 Constants
  ! valve (c1) and outflow (c2) constants
  c1 = 0.25    ! m^3/sec
  c2 = 0.14    ! m^1.5/sec
 End Constants

 Parameters
  percent_open ! %
 End Parameters

 Variables
  inlet_flow   ! m^3/sec
  outlet_flow  ! m^3/sec
  volume       ! m^3
 End Variables

 Equations
  inlet_flow  = c1 * percent_open
  outlet_flow = c2 * SQRT(volume)
  $volume = inlet_flow - outlet_flow
  200 < volume < 5000
 End Equations

End Model


Tank Model in MATLAB
function xdot = tank(t,x)

global u

% Input (1):
% Inlet Valve State (% Open)
percent_open = u;

% State (1):
% Volume in the Tank (m^3)
volume = x;

% Parameters (2):
% Inflow Constant (m^3/sec)
c1 = 0.25;
% Outflow Constant (m^1.5/sec)
c2 = 0.14;

% Intermediate variables
inlet_flow = (c1 * percent_open);
outlet_flow = (c2 * volume^0.5);

% Compute xdot (dx/dt)
xdot(1,1) = inlet_flow - outlet_flow;

% adjust xdot to remain within constraints
low_volume = 200;
if (volume < low_volume) & (percent_open < (c_outflow * low_volume^0.5)/c_inflow),
   xdot(1,1) = 0;
end

high_volume = 5000;
if (volume > high_volume) & (percent_open > (c_outflow * high_volume^0.5)/c_inflow),
   xdot(1,1) = 0;
end


Tank Model in gProms
MODEL Tank

  DECLARE
    TYPE
      Vol  =  500.0  :  200.0  :  5000  UNIT = "m^3"
  END

  PARAMETER
    # parameters can be specified at run-time
    #   with Tank.c1 := 0.25;
    #        Tank.c2 := 0.14;
    c1           AS REAL
    c2           AS REAL

  VARIABLE
    # Volume in the Tank (m^3)
    volume       AS Vol

    # Inlet flow (m^3/sec)
    inlet_flow   AS REAL

    # Outlet flow (m3/sec)
    outlet_flow  AS REAL

    # Inlet Valve State (% Open)
    percent_open AS REAL

  EQUATION

    # Inlet flow is a linear function of valve position
    inlet_flow = c1 * percent_open ;

    # Square root pressure drop flow relation
    outlet_flow = c2 * SQRT ( volume ) ;

    # Mass balance (assuming constant density)
    $volume = inlet_flow - outlet_flow ;

END # Model Tank


Tank Model in Modelica

model Tank
  parameter Real c1=0.25 "Inflow Constant";
  parameter Real c2=0.14 "Outflow Constant";
  Real percent_open "Percent Open";
  Real inlet_flow "Inlet Flow";
  Real outlet_flow "Outlet Flow";
  Real volume "Tank Volume";
equation
  inlet_flow = c1 * percent_open "Inlet flow as a linear function of valve position";
  outlet_flow = c2 * volume^0.5 "Outlet flow as a square root function of volume";
  der(volume) = inlet_flow - outlet_flow "Mass balance (assuming constant density)";
end Tank;