What equations are in Python Gekko flowsheet objects?

197 views Asked by At

What are the equations and other details of the built-in Python Gekko flowsheet objects such as the reactor model? Gekko has the compounds that I need for an industrial application of nonlinear Model Predictive Control (MPC) to a gas-phase fluidized-bed polymer (polyethylene) reactor.

from gekko import GEKKO, chemical
m = GEKKO(remote=False)
c = chemical.Properties(m)
c.compound('ethylene')    # primary monomer reactant
c.compound('propylene')   # co-polymer monomer reactant
c.compound('hydrogen')    # melt-index modifier
c.compound('ethane')      # inert
c.compound('propane')     # inert
c.compound('cyclohexene') # density modifier
c.compound('isopentane')  # condensing agent
c.compound('nitrogen')    # pressure control
f = chemical.Flowsheet(m)
r = f.reactor(ni=2)
m.options.SOLVER = 1
m.solve()

This simple reactor model produces the following output:

 --------- APM Model Size ------------
 Each time step contains
   Objects      :  1
   Constants    :  0
   Variables    :  12
   Intermediates:  0
   Connections  :  12
   Equations    :  0
   Residuals    :  0

 Number of state variables:    29
 Number of total equations: -  10
 Number of slack variables: -  0
 ---------------------------------------
 Degrees of freedom       :    19

 ----------------------------------------------
 Steady State Optimization with APOPT Solver
 ----------------------------------------------

 Iter    Objective  Convergence
    0  2.55529E-16  1.38889E+00
    1  2.38753E-25  1.23358E-16
    2  2.38753E-25  1.23358E-16
 Successful solution

 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :  0.026300000000000004 sec
 Objective      :  0.
 Successful solution
 ---------------------------------------------------

How can I find more details about the 10 equations and 29 variables? I am interested in property control (melt index and density) and maximize production rate by adjusting catalyst, hydrogen, and co-monomer (propylene, iso-butene, etc).

1

There are 1 answers

2
John Hedengren On

Gekko outputs a LaTeX file rto_4_latex.tex (or {mode}_4_latex.tex} for other modes) with the model details about equations and variables when you set m.options.DIAGLEVEL to 4 or higher.

from gekko import GEKKO, chemical
m = GEKKO(remote=False)
c = chemical.Properties(m)
c.compound('ethylene')    # primary monomer reactant
c.compound('propylene')   # co-polymer monomer reactant
c.compound('hydrogen')    # melt-index modifier
c.compound('ethane')      # inert
c.compound('propane')     # inert
c.compound('cyclohexene') # density modifier
c.compound('isopentane')  # condensing agent
c.compound('nitrogen')    # pressure control
f = chemical.Flowsheet(m)
r = f.reactor(ni=2)
m.options.SOLVER = 1
m.options.DIAGLEVEL = 4
m.solve()
m.open_folder()

You can also see more information in the many files that it produces when you solve locally with remote=False and open the run directory with m.open_folder().

\documentclass[8pt]{article}
\begin{document}
\title{Model Title}
\author{John D. Hedengren}
\maketitle
\section{equations}

\subsection{Equation 1 }
\texttt{ ss.reactor1.overall\_mole\_balance }
\begin{equation}
0 = {\dot n}_{in} + {\dot r}_{gen} - {\dot n}_{out} - \frac{\partial n}{\partial t}
\end{equation}
Variables
\begin{enumerate}
\item \texttt{ 0.60000E+00 kmol/sec    ss.reactor1.inlet[1].ndot * 2}
\item \texttt{ 0.60000E+00 kmol/sec    ss.reactor1.inlet[2].ndot * 11}
\item \texttt{ 0.12000E+01 kmol/sec    ss.reactor1.outlet.ndot * 19}
\item \texttt{ 0.00000E+00 kmol/sec    ss.v1 * 29}
\end{enumerate}

You can get a PDF document if you compile the LaTeX document with call pdflatex main if you are in Windows and have downloaded texlive. Otherwise, you could put it into the online OverLeaf editor to convert to a PDF. Here are the first two equations of the 7 page document that is created.

PDF of Gekko Model