APMonitor
{{Short description|Modelling language for algebraic equations}}
{{Infobox Software
| name = APMonitor
| logo = APMonitor_Logo2.png
| logo size = 100px
| screenshot =
| caption = APMonitor Web-based Interface
| developer = APMonitor
| latest_release_version = v1.0.1
| latest_release_date = {{release date|2022|01|31}}
| operating_system = Cross-platform
| genre = Technical computing
| license = Proprietary, BSD
| website = [http://www.apmonitor.com APMonitor product page]
| repo = https://github.com/APMonitor/
}}
Advanced process monitor (APMonitor) is a modeling language for differential algebraic (DAE) equations.{{cite journal|last=J.D. Hedengren |author2=R. Asgharzadeh Shishavan |author3=K.M. Powell |author4=T.F. Edgar |title=Nonlinear modeling, estimation and predictive control in APMonitor|journal=Computers & Chemical Engineering|year=2014|volume=70|issue=5|pages=133–148|doi=10.1016/j.compchemeng.2014.04.013|url=https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2687&context=facpub}} It is a free web-service or local server for solving representations of physical systems in the form of implicit DAE models. APMonitor is suited for large-scale problems and solves linear programming, integer programming, nonlinear programming, nonlinear mixed integer programming, dynamic simulation,{{cite journal | last=Hedengren | first=J. | title=A Nonlinear Model Library for Dynamics and Control | journal=CACHE (Computer Aids for Chemical Engineering) News | year=2008 | url=http://www.hedengren.net/research/Publications/Cache_2008/NonlinearModelLibrary.pdf}} moving horizon estimation,{{cite journal | last=Spivey | first=B. | title=Monitoring of Process Fouling Using First-Principles Modeling and Moving Horizon Estimation | journal=Proc. Applications of Computer Algebra (ACA) Conference | year=2009}} and nonlinear model predictive control.{{cite journal | last=Ramlal | first=J. | title=Moving Horizon Estimation for an Industrial Gas Phase Polymerization Reactor | journal=IFAC Symposium on Nonlinear Control Systems Design (NOLCOS) | year=2007 | url=http://apmonitor.com/Documents/mhe.pdf | access-date=2010-03-29 | archive-url=https://web.archive.org/web/20090920070424/http://apmonitor.com/Documents/mhe.pdf | archive-date=2009-09-20 | url-status=dead }} APMonitor does not solve the problems directly, but calls nonlinear programming solvers such as APOPT, BPOPT, IPOPT, MINOS, and SNOPT. The APMonitor API provides exact first and second derivatives of continuous functions to the solvers through automatic differentiation and in sparse matrix form.
Programming language integration
Julia, MATLAB, Python are mathematical programming languages that have APMonitor integration through web-service APIs. The GEKKO Optimization Suite is a recent extension of APMonitor with complete Python integration. The interfaces are built-in optimization toolboxes or modules to both load and process solutions of optimization problems. APMonitor is an object-oriented modeling language and optimization suite that relies on programming languages to load, run, and retrieve solutions. APMonitor models and data are compiled at run-time and translated into objects that are solved by an optimization engine such as APOPT or IPOPT. The optimization engine is not specified by APMonitor, allowing several different optimization engines to be switched out. The simulation or optimization mode is also configurable to reconfigure the model for dynamic simulation, nonlinear model predictive control, moving horizon estimation or general problems in mathematical optimization.
As a first step in solving the problem, a mathematical model is expressed in terms of variables and equations such as the Hock & Schittkowski Benchmark Problem #71W. Hock and K. Schittkowski, Test Examples for Nonlinear Programming Codes, Lecture Notes in Economics and Mathematical Systems, Vol. 187, Springer 1981. used to test the performance of nonlinear programming solvers. This particular optimization problem has an objective function and subject to the inequality constraint and equality constraint . The four variables must be between a lower bound of 1 and an upper bound of 5. The initial guess values are . This mathematical model is translated into the APMonitor modeling language in the following text file.
! file saved as hs71.apm
Variables
x1 = 1, >=1, <=5
x2 = 5, >=1, <=5
x3 = 5, >=1, <=5
x4 = 1, >=1, <=5
End Variables
Equations
minimize x1*x4*(x1+x2+x3) + x3
x1*x2*x3*x4 > 25
x1^2 + x2^2 + x3^2 + x4^2 = 40
End Equations
The problem is then solved in Python by first installing the APMonitor package with pip install APMonitor or from the following Python code.
- Install APMonitor
import pip
pip.main(["install", "APMonitor"])
Installing a Python is only required once for any module. Once the APMonitor package is installed, it is imported and the apm_solve function solves the optimization problem. The solution is returned to the programming language for further processing and analysis.
- Python example for solving an optimization problem
from APMonitor.apm import *
- Solve optimization problem
sol = apm_solve("hs71", 3)
- Access solution
x1 = sol["x1"]
x2 = sol["x2"]
Similar interfaces are available for MATLAB and Julia with minor differences from the above syntax. Extending the capability of a modeling language is important because significant pre- or post-processing of data or solutions is often required when solving complex optimization, dynamic simulation, estimation, or control problems.
High index DAEs
The highest order of a derivative that is necessary to return a DAE to ODE form is called the differentiation index. A standard way for dealing with high-index DAEs is to differentiate the equations to put them in index-1 DAE or ODE form (see Pantelides algorithm). However, this approach can cause a number of undesirable numerical issues such as instability. While the syntax is similar to other modeling languages such as gProms, APMonitor solves DAEs of any index without rearrangement or differentiation.{{cite journal | last=Harney | first=D. | title=Numerical evaluation of the stability of stationary points of index-2 differential-algebraic equations: Applications to reactive flash and reactive distillation systems | journal=Computers & Chemical Engineering | year=2013 | doi=10.1016/j.compchemeng.2012.09.021 | volume=49 | pages=61–69}} As an example, an index-3 DAE is shown below for the pendulum motion equations and lower index rearrangements can return this system of equations to ODE form (see [http://apmonitor.com/wiki/index.php/Apps/PendulumMotion Index 0 to 3 Pendulum example]).
=Pendulum motion (index-3 DAE form)=
Model pendulum
Parameters
m = 1
g = 9.81
s = 1
End Parameters
Variables
x = 0
y = -s
v = 1
w = 0
lam = m*(1+s*g)/2*s^2
End Variables
Equations
x^2 + y^2 = s^2
$x = v
$y = w
m*$v = -2*x*lam
m*$w = -m*g - 2*y*lam
End Equations
End Model
Applications in APMonitor Modeling Language
Many physical systems are naturally expressed by differential algebraic equation. Some of these include:
- cell cultures
- chemical reactors
- cogeneration (power and heat){{cite journal | last=Mojica | first=J. | title=Optimal combined long-term facility design and short-term operational strategy for CHP capacity investments | journal=Energy | year=2017 | doi=10.1016/j.energy.2016.12.009 | volume=118 | pages=97–115| bibcode=2017Ene...118...97M | url=https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2932&context=facpub }}
- distillation columns
- drilling automation{{cite journal | last=Eaton | first=A. | title=Real time model identification using multi-fidelity models in managed pressure drilling | journal=Computers & Chemical Engineering | year=2017 | doi=10.1016/j.compchemeng.2016.11.008 | volume=97 | pages=76–84}}
- essential oil steam distillation{{cite journal | last=Valderrama | first=F. | title=An optimal control approach to steam distillation of essential oils from aromatic plants | journal=Computers & Chemical Engineering | volume=117 | pages=25–31 | year=2018 | doi=10.1016/j.compchemeng.2018.05.009 }}
- friction stir welding{{cite thesis |degree=M.Sc. |first=Isak |last=Nielsen |title=Modeling and Control of Friction Stir Welding in 5 cm thick Copper Canisters |publisher=Linköping University |year=2012 |url=http://liu.diva-portal.org/smash/record.jsf?pid=diva2:535544&rvn=4}}
- hydrate formation in deep-sea pipelines{{cite journal | last=Brower | first=D. | title=Fiber Optic Monitoring of Subsea Equipment | journal=OMAE 2012 Proceedings, Rio de Janeiro, Brazil | year=2012 | url=http://hedengren.net/research/Publications/OMAE_2012/Brower_Hedengren_OMAE_2012.pdf}}
- infectious disease spread
- oscillators
- severe slugging control{{cite journal | last=Eaton | first=A. | title=Post-installed fiber optic pressure sensors on subsea production risers for severe slugging control | journal=OMAE 2015 Proceedings, St. John's, Canada | year=2015 | url=http://apm.byu.edu/prism/uploads/Projects/Eaton_OMAE15.pdf}}
- solar thermal energy production{{cite journal | last=Powell | first=K. | title=Dynamic Optimization of a Hybrid Solar Thermal and Fossil Fuel System | journal=Solar Energy | year=2014 | doi=10.1016/j.solener.2014.07.004 | volume=108 | pages=210–218| bibcode=2014SoEn..108..210P }}
- solid oxide fuel cells{{cite journal | last=Spivey | first=B. | title=Dynamic Modeling of Reliability Constraints in Solid Oxide Fuel Cells and Implications for Advanced Control | journal=AIChE Annual Meeting Proceedings, Salt Lake City, Utah | year=2010 | url=http://apmonitor.com/wiki/uploads/Apps/sofc.pdf}}{{cite journal | last=Spivey | first=B. | title=Dynamic modeling, simulation, and MIMO predictive control of a tubular solid oxide fuel cell | journal=Journal of Process Control | year=2012 | doi=10.1016/j.jprocont.2012.01.015 | volume=22 | issue=8 | pages=1502–1520}}
- space shuttle launch simulation
- Unmanned Aerial Vehicles (UAVs){{cite journal | last=Sun | first=L. | title=Optimal Trajectory Generation using Model Predictive Control for Aerially Towed Cable Systems | journal=Journal of Guidance, Control, and Dynamics | volume=37 | issue=2 | pages=525–539 | year=2013 | url=http://apm.byu.edu/prism/uploads/Members/sun_2013.pdf| bibcode=2014JGCD...37..525S | doi=10.2514/1.60820 }}
Models for a direct current (DC) motor and blood glucose response of an insulin dependent patient are listed below. They are representative of differential and algebraic equations encountered in many branches of science and engineering.
=Direct current (DC) motor=
Parameters
! motor parameters (dc motor)
v = 36 ! input voltage to the motor (volts)
rm = 0.1 ! motor resistance (ohms)
lm = 0.01 ! motor inductance (henrys)
kb = 6.5e-4 ! back emf constant (volt·s/rad)
kt = 0.1 ! torque constant (N·m/a)
jm = 1.0e-4 ! rotor inertia (kg m2)
bm = 1.0e-5 ! mechanical damping (linear model of friction: bm * dth)
! load parameters
jl = 1000*jm ! load inertia (1000 times the rotor)
bl = 1.0e-3 ! load damping (friction)
k = 1.0e2 ! spring constant for motor shaft to load
b = 0.1 ! spring damping for motor shaft to load
End Parameters
Variables
i = 0 ! motor electric current (amperes)
dth_m = 0 ! rotor angular velocity sometimes called omega (radians/sec)
th_m = 0 ! rotor angle, theta (radians)
dth_l = 0 ! wheel angular velocity (rad/s)
th_l = 0 ! wheel angle (radians)
End Variables
Equations
lm*$i - v = -rm*i - kb *$th_m
jm*$dth_m = kt*i - (bm+b)*$th_m - k*th_m + b *$th_l + k*th_l
jl*$dth_l = b *$th_m + k*th_m - (b+bl)*$th_l - k*th_l
dth_m = $th_m
dth_l = $th_l
End Equations
=Blood glucose response of an insulin dependent patient=
! Model source:
! A. Roy and R.S. Parker. “Dynamic Modeling of Free Fatty
! Acids, Glucose, and Insulin: An Extended Minimal Model,”
! Diabetes Technology and Therapeutics 8(6), 617-626, 2006.
Parameters
p1 = 0.068 ! 1/min
p2 = 0.037 ! 1/min
p3 = 0.000012 ! 1/min
p4 = 1.3 ! mL/(min·µU)
p5 = 0.000568 ! 1/mL
p6 = 0.00006 ! 1/(min·µmol)
p7 = 0.03 ! 1/min
p8 = 4.5 ! mL/(min·µU)
k1 = 0.02 ! 1/min
k2 = 0.03 ! 1/min
pF2 = 0.17 ! 1/min
pF3 = 0.00001 ! 1/min
n = 0.142 ! 1/min
VolG = 117 ! dL
VolF = 11.7 ! L
! basal parameters for Type-I diabetic
Ib = 0 ! Insulin (µU/mL)
Xb = 0 ! Remote insulin (µU/mL)
Gb = 98 ! Blood Glucose (mg/dL)
Yb = 0 ! Insulin for Lipogenesis (µU/mL)
Fb = 380 ! Plasma Free Fatty Acid (µmol/L)
Zb = 380 ! Remote Free Fatty Acid (µmol/L)
! insulin infusion rate
u1 = 3 ! µU/min
! glucose uptake rate
u2 = 300 ! mg/min
! external lipid infusion
u3 = 0 ! mg/min
End parameters
Intermediates
p9 = 0.00021 * exp(-0.0055*G) ! dL/(min*mg)
End Intermediates
Variables
I = Ib
X = Xb
G = Gb
Y = Yb
F = Fb
Z = Zb
End variables
Equations
! Insulin dynamics
$I = -n*I + p5*u1
! Remote insulin compartment dynamics
$X = -p2*X + p3*I
! Glucose dynamics
$G = -p1*G - p4*X*G + p6*G*Z + p1*Gb - p6*Gb*Zb + u2/VolG
! Insulin dynamics for lipogenesis
$Y = -pF2*Y + pF3*I
! Plasma-free fatty acid (FFA) dynamics
$F = -p7*(F-Fb) - p8*Y*F + p9 * (F*G-Fb*Gb) + u3/VolF
! Remote FFA dynamics
$Z = -k2*(Z-Zb) + k1*(F-Fb)
End Equations
See also
References
{{reflist}}
External links
- [http://apmonitor.com APMonitor home page]
- [http://apmonitor.com/do Dynamic optimization course] with APMonitor
- [http://apmonitor.com/wiki APMonitor documentation]
- [http://apmonitor.com/wiki/index.php/Main/APMonitorReferences APMonitor citations]
- [http://apmonitor.com/online/view_pass.php Online solution engine] with IPOPT
- [http://apmonitor.com/compare.htm Comparison] of popular modeling language syntax
- Download [http://apmonitor.com/wiki/index.php/Main/MATLAB APM MATLAB], [http://apmonitor.com/wiki/index.php/Main/PythonApp APM Python], or [http://apmonitor.com/wiki/index.php/Main/JuliaOpt APM Julia] client for APMonitor
- Download [http://apmonitor.com/wiki/index.php/Main/APMonitorServer APMonitor Server (Windows)]
- Download [http://apmonitor.com/wiki/index.php/Main/APMonitorServerLinux APMonitor Server (Linux)]
{{Mathematical optimization software}}
{{DEFAULTSORT:Apmonitor}}