Comparison of Syntax

Main.CompareModelingLanguages History

Hide minor edits - Show changes to output

June 02, 2017, at 01:33 PM by 45.56.3.173 -
Deleted line 107:
June 16, 2015, at 06:13 AM by 45.56.3.184 -
Changed line 1 from:
(:title Comparison of Dynamic Modeling Language Syntax:)
to:
(:title Comparison of Syntax:)
June 16, 2015, at 06:11 AM by 45.56.3.184 -
Changed line 62 from:
</span></div><br><br><br><br><br><br>
to:
</span></div><br><br><br><br><br><br><br><br><br><br><br><br>
June 16, 2015, at 06:11 AM by 45.56.3.184 -
Changed line 62 from:
</span></div><br><br>
to:
</span></div><br><br><br><br><br><br>
June 16, 2015, at 06:10 AM by 45.56.3.184 -
Deleted lines 18-22:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<title>Exported from Notepad++</title>
Deleted lines 48-49:
</head>
<body>
Changed lines 62-63 from:
</span></div><br><br></body>
</html
>
to:
</span></div><br><br>
June 16, 2015, at 06:09 AM by 45.56.3.184 -
Changed line 69 from:
</span></div></body>
to:
</span></div><br><br></body>
June 16, 2015, at 06:08 AM by 45.56.3.184 -
Changed lines 18-30 from:
  Parameters
  percent_open
  c1 = 0.25    ! m^3/sec
  c2 = 0.14    ! m^1.5/sec
  Variables
  inlet_flow  ! m^3/sec
  outlet_flow  ! m^3/sec
  volume      ! m^3
  Equations
  inlet_flow  = a1 * percent_open
  outlet_flow = a2 * SQRT(volume)
  $volume = inlet_flow - outlet_flow
  200 < volume < 5000
to:
(:html:)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
font-family: 'Courier New';
font-size: 10pt;
color: #000000;
}
.sc0 {
}
.sc2 {
font-style: italic;
color: #008000;
}
.sc3 {
font-weight: bold;
font-style: italic;
color: #800000;
}
.sc5 {
font-weight: bold;
font-style: italic;
color: #0080FF;
}
.sc6 {
font-weight: bold;
font-style: italic;
color: #004000;
}
.sc24 {
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc5">Parameters</span><span class="sc24">
  </span><span class="sc0">percent_open</span><span class="sc24">
  </span><span class="sc0">a1</span><span class="sc24"> </span><span class="sc6">=</span><span class="sc24"> </span><span class="sc3">0.25</span><span class="sc24">    </span><span class="sc2">! m^3/sec
</span><span class="sc24">  </span><span class="sc0">a2</span><span class="sc24"> </span><span class="sc6">=</span><span class="sc24"> </span><span class="sc3">0.14</span><span class="sc24">    </span><span class="sc2">! m^1.5/sec
</span><span class="sc5">Variables</span><span class="sc24">
  </span><span class="sc0">inlet_flow</span><span class="sc24">  </span><span class="sc2">! m^3/sec
</span><span class="sc24">  </span><span class="sc0">outlet_flow</span><span class="sc24">  </span><span class="sc2">! m^3/sec
</span><span class="sc24">  </span><span class="sc0">volume</span><span class="sc24">      </span><span class="sc2">! m^3
</span><span class="sc5">Equations</span><span class="sc24">
  </span><span class="sc0">inlet_flow</span><span class="sc24">  </span><span class="sc6">=</span><span class="sc24"> </span><span class="sc0">a1</span><span class="sc24"> </span><span class="sc0">*</span><span class="sc24"> </span><span class="sc0">percent_open</span><span class="sc24">
  </span><span class="sc0">outlet_flow</span><span class="sc24"> </span><span class="sc6">=</span><span class="sc24"> </span><span class="sc0">a2</span><span class="sc24"> </span><span class="sc0">*</span><span class="sc24"> </span><span class="sc0">SQRT(volume)</span><span class="sc24">
  </span><span class="sc0">$volume</span><span class="sc24"> </span><span class="sc6">=</span><span class="sc24"> </span><span class="sc0">inlet_flow</span><span class="sc24"> </span><span class="sc0">-</span><span class="sc24"> </span><span class="sc0">outlet_flow</span><span class="sc24">
  </span><span class="sc3">200</span><span class="sc24"> </span><span class="sc6">&lt;</span><span class="sc24"> </span><span class="sc0">volume</span><span class="sc24"> </span><span class="sc6">&lt;</span><span class="sc24"> </span><span class="sc3">5000</span><span class="sc24">
</span></div></body>
</html>
(:htmlend:)
June 16, 2015, at 06:05 AM by 45.56.3.184 -
Changed lines 20-22 from:
   a1 = 0.25    ! m^3/sec
  a2 = 0.14    ! m^1.5/sec
to:
   c1 = 0.25    ! m^3/sec
  c2 = 0.14    ! m^1.5/sec
Deleted line 25:
June 16, 2015, at 06:03 AM by 45.56.3.184 -
Changed lines 17-28 from:
  a2 = 0.14   ! m^1.5/sec

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

 Equations
  inlet_flow  = a1 * percent_open
  outlet_flow = a2 * SQRT(volume)
  $volume = inlet_flow - outlet_flow
  200 < volume < 5000
to:

  Parameters
   percent_open
  a1 = 0.25    ! m^3/sec
   a2 = 0.14    ! m^1.5/sec

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

  Equations
  inlet_flow  = a1 * percent_open
  outlet_flow = a2 * SQRT(volume)
  $volume = inlet_flow - outlet_flow
 
  200 < volume < 5000
June 16, 2015, at 06:03 AM by 45.56.3.184 -
Deleted lines 16-18:
 Parameters
  percent_open ! %
  a1 = 0.25    ! m^3/sec
June 16, 2015, at 06:02 AM by 45.56.3.184 -
Changed lines 19-21 from:
  c1 = 0.25    ! m^3/sec
  c2 = 0.14    ! m^1.5/sec
to:
  a1 = 0.25    ! m^3/sec
  a2 = 0.14    ! m^1.5/sec
Changed lines 28-29 from:
  inlet_flow  = c1 * percent_open
  outlet_flow = c2 * SQRT(volume)
to:
  inlet_flow  = a1 * percent_open
  outlet_flow = a2 * SQRT(volume)
June 16, 2015, at 06:01 AM by 45.56.3.184 -
Added line 18:
  percent_open ! %
Deleted line 20:
  percent_open ! %
June 16, 2015, at 06:00 AM by 45.56.3.184 -
Changed lines 17-40 from:
 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
to:
 Parameters
  c1 = 0.25
   ! m^3/sec
 
c2 = 0.14    ! m^1.5/sec
  percent_open ! %

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

 Equations
  inlet_flow
  = c1 * percent_open
  outlet_flow = c2 * SQRT(volume)
  $volume = inlet_flow - outlet_flow
  200 < volume < 5000
June 16, 2015, at 05:59 AM by 45.56.3.184 -
Changed line 16 from:
!!! Tank Model in APMonitor
to:
!!! Tank Model in [[https://apmonitor.com|APMonitor]]
Changed lines 18-20 from:

  Constants
  ! valve (c1) and outflow (c2) constants
to:
  Constants ! valve (c1) and outflow (c2) constants
June 16, 2015, at 05:57 AM by 45.56.3.184 -
Added line 18:
Changed lines 44-45 from:
!!! Tank Model in MATLAB
to:
!!! Tank Model in [[https://mathworks.com|MATLAB]]
Changed lines 73-74 from:
 if (volume < low_volume) & (percent_open < (c_outflow * low_volume^0.5)/c_inflow),
to:
 low_open = c_outflow * low_volume^0.5)/c_inflow;
 if
(volume < low_volume) & (percent_open < low_open),
Changed lines 79-80 from:
 if (volume > high_volume) & (percent_open > (c_outflow * high_volume^0.5)/c_inflow),
to:
 high_open = c_outflow * high_volume^0.5)/c_inflow;
 if
(volume > high_volume) & (percent_open > high_open),
Changed lines 84-85 from:
!!! Tank Model in gProms
to:
!!! Tank Model in [[https://www.psenterprise.com/gproms.html|gProms]]
Changed lines 126-127 from:
!!! Tank Model in Modelica
to:
!!! Tank Model in [[https://www.modelica.org/|Modelica]]
Changed lines 136-138 from:
  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)
";
to:
  inlet_flow = c1 * percent_open "Inlet flow";
  outlet_flow = c2 * volume^0.5
"Outlet flow";
  der(volume) = inlet_flow - outlet_flow "Mass balance";
June 16, 2015, at 05:50 AM by 45.56.3.184 -
Added lines 1-136:
(:title Comparison of Dynamic Modeling Language Syntax:)
(:keywords modeling language, differential algebraic equations, nonlinear control, dynamic estimation, parameter estimation, dynamic optimization, engineering optimization, MATLAB, Python, differential, algebraic:)
(:description Comparison of APMonitor, MATLAB, gProms, Modelica:)

!! Tank Model

The same dynamic tank model is written in the following 4 modeling languages for a direct comparison between the syntax for the solution of differential and algebraic equations.

* APMonitor
* MATLAB
* gProms
* Modelica

Attach:tank_diagram.png

!!! Tank Model in APMonitor
 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;