8th 8th Vienna Vienna International International Conference Conference on on Mathematical Mathematical Modelling Modelling February -- 20, University of Vienna, February 18International 20, 2015. 2015. Vienna Vienna University of Technology, Technology, Vienna, 8th Vienna18 Conference on Mathematical Modelling 8th Vienna International Conference on Mathematical Modelling Austria Available online atVienna, www.sciencedirect.com Austria February 18 - 20, 2015. Vienna University of Technology, February 18 - 20, 2015. Vienna University of Technology, Vienna, Austria Austria
ScienceDirect
IFAC-PapersOnLine 48-1 (2015) 204–209
Optimal Startup Control of a Steam Power Optimal Control of Power Optimal Startup Control of a a Steam Steam Power Plant Startup Using the JModelica Platform Plant Using the JModelica Platform Plant Using the JModelica Platform ∗∗ F. Felgner ∗ ∗ G. Frey ∗ ∗ F. Belkhir ∗∗ D. Kraus Cabo ∗∗ ∗ ∗∗ ∗ ∗ F. Belkhir ∗ D. Kraus Cabo ∗∗ F. Felgner ∗ G. Frey ∗ F. Belkhir D. Kraus Cabo F. Felgner G. Frey ∗ ∗ Chair of Automation, Saarland University, Building A5 1,Germany ∗ e-mail:{fethi.belkhir, felix.felgner, georg.frey}@aut.uni-saarland.de ∗ Chair of Automation, Saarland University, Building A5 1,Germany Chair∗∗ of Automation, Saarland University, Building A5 1,Germany ∗∗ ETSEIB, Polytechnic University of Catalonia, Spain, e-mail:{fethi.belkhir, felix.felgner, georg.frey}@aut.uni-saarland.de e-mail:{fethi.belkhir, felix.felgner, georg.frey}@aut.uni-saarland.de ∗∗ e-mail:
[email protected] Polytechnic University ∗∗ ETSEIB, ETSEIB, Polytechnic University of of Catalonia, Catalonia, Spain, Spain, e-mail:
[email protected] e-mail:
[email protected] Abstract: In this contribution, a step toward the immediate usage of Modelica models in the Abstract: In contribution, a toward usage the solution of optimal problems is demonstrated. For this purpose, model of amodels steam in boiler Abstract: In this this control contribution, a step step toward the the immediate immediate usage of ofaModelica Modelica models in the in a power plant taken from literature was implemented in the high-level modeling language solution of optimal control problems is demonstrated. For this purpose, a model of a steam boiler solution of optimal control problems is demonstrated. For this purpose, a model of a steam boiler in plant taken from implemented in the modeling language Modelica. optimal problem was of the steam boiler is formulated solved in a a power powerThe plant taken control from literature literature was implemented in start-up the high-level high-level modelingand language Modelica. The optimal control problem of the steam boiler start-up is formulated and using the JModelica framework with the Optimica extension. The results demonstrate the effort Modelica. The optimal control problem of the steam boiler start-up is formulated and solved solved using the JModelica framework with the Optimica extension. The results demonstrate the saved in solving an optimal control problem when using the JModelica framework in comparison using the JModelica framework with the Optimica extension. The results demonstrate the effort effort to individual, case-specifically arranged solutions. saved in an problem when saved in solving solving an optimal optimal control control problem when using using the the JModelica JModelica framework framework in in comparison comparison to individual, case-specifically arranged solutions. to individual, case-specifically arranged solutions. © 2015, IFAC (International Federation of Automatic Control) Hosting by Elsevier Ltd. All rights reserved. Keywords: Modelica, Optimica, JModelica, Dynamic Optimization, Power Plants Control, Optimal Control. Keywords: Modelica, Keywords: Modelica, Optimica, Optimica, JModelica, JModelica, Dynamic Dynamic Optimization, Optimization, Power Power Plants Plants Control, Control, Optimal Control. Optimal Control. 1. INTRODUCTION than interfacing the model with a third-party tool for optimal control problem solving, in (Franke et al., 1. INTRODUCTION than the with third-party tool for 1. INTRODUCTION than interfacing interfacing the model model withas,aa e.g., third-party tool for and Vogelbacher, 2006). optimal control problem solving, as, e.g., in (Franke et al., The rapid increase in physical system complexity, size, 2003),(Franke optimal control problem solving, as, e.g., in (Franke et al., this contribution, a test case is provided which demon2003),(Franke and 2006). and the development of a multitude The heterogeneity, rapid increase increaseled in to physical system complexity, complexity, size, In 2003),(Franke and Vogelbacher, Vogelbacher, 2006). The rapid in physical system size, strates how a high-level Modelica model can be fully inIn this contribution, a test case is which demonand heterogeneity, led to the development of a multitude simulation software tools to manage such complexity and this contribution, a test case is provided provided which demonand heterogeneity, led to the development of a multitude In tegrated with JModelica and the Optimica extension, to strates how a high-level Modelica model can be fully simulation software tools to system manageinsuch such complexity and strates how a high-level Modelica model can be fully ingain knowledge about theto a more structured insimulation software tools manage complexity and tegrated with JModelica and the Optimica extension, formulate an optimal start-up control problem for a steam manner. This can be either in a form of libraries undergain knowledge knowledge about about the the system system in in aa more more structured structured tegrated with JModelica and the Optimica extension, to to gain formulate an optimal control problem for plants in start-up a user-friendly requiring less lying the physics of the different parts of the system or power manner. This can be either in a form of libraries underformulate an boiler optimal start-up controlmanner problem for a a steam steam manner. This can be either in a form of libraries underand programming efforts.manner power boiler in lying the the physics physics of the themodels. different parts of the the system or interfacing ready-to-use simulation Anparts example of such highpower plants plants boiler in aa user-friendly user-friendly manner requiring requiring less less lying of different of system or This paper is organized as follows: Section 2 presents the interfacing and programming efforts. ready-to-use simulation models. An example of such highlevel simulation language supporting the above mentioned interfacing and programming efforts. ready-to-use simulation models. An example of such high1 1. This as Section 22 presents the model of the steam boiler. 3 gives functionalities Modelicasupporting level simulation simulationislanguage language supporting the above above mentioned mentioned mathematical This paper paper is is organized organized as follows: follows: SectionSection presents the level the 1 mathematical model of the steam boiler. Section 3 gives Modelica is nowadays considered to be the most promising a brief description of the JModelica framework as well as functionalities is Modelica 1. mathematical model of the steam boiler. Section 3 gives functionalities is Modelica . the Optimica extension. In Section 4 an optimal control aa brief description of the JModelica framework as well object-oriented, equation-based programming language Modelica is nowadays considered to be the most promising brief description of the JModelica framework as well as as Modelica is nowadays considered to be the most promising problem is formulated start-up Finally, the the Optimica extension. Section 44 an optimal control within both academia and industry to construct computerobject-oriented, equation-based programming language the Optimica extension.forIn Inthe Section ancase. optimal control object-oriented, equation-based programming language problem formulated for case. based for complex industrial processescomputeror other obtained results are summed in Section 5. Finally, within both and to problem is is formulated for the theupstart-up start-up case. Finally, the the within models both academia academia and industry industry to construct construct computerobtained results are summed up in Section 5. related engineering applications. Traditionally, the main based models for complex industrial processes or other summed up in Section 5. based models for complex industrial processes or other obtained results are 2. PROCESS MODEL target such modelsapplications. is simulation,Traditionally, which aims atthe answerrelated main relatedofengineering engineering applications. Traditionally, the main 2. ing questions about the system without making experitarget of is which at 2. PROCESS PROCESS MODEL MODEL target of such such models models is simulation, simulation, which aims aims at answeranswerThe design and dynamic behavior of a steam boiler unit is ments on the real system (Fritzson, 2010). However, in the ing questions about the system without making experiing questions about the system without making experi- very complex nature. Nevertheless, the main dynamics The design and behavior boiler unit last decades, has been a strong trendHowever, towards in using ments on real (Fritzson, 2010). the design andindynamic dynamic behavior of of aa steam steam boiler unit is is ments on the the there real system system (Fritzson, 2010). However, in the The of the process over a wide operating range and under difvery complex in nature. Nevertheless, the main dynamics the Modelica models in dynamic optimization problems last decades, there has been a strong trend towards using complex in nature. Nevertheless, the main dynamics last decades, there has been a strong trend towards using very conditions can be captured by aunder lumpedof process aa wide range difto economic performance of the process in ferent the Modelica in optimization problems of the the transient process over over wide operating operating range and and under diftheimprove Modelicathemodels models in dynamic dynamic optimization problems ferent transient conditions can be captured by a lumpedparameter modeling approach under some simplifying as˚kesson a cost-effective way ( A et al., 2010), (Franke and to improve the economic performance of the process in ferent transient conditions can be captured by a lumpedto improve the economic performance of the process in sumptions: parameter modeling approach under some simplifying ˚ Vogelbacher, 2006). a cost-effective way ( A kesson et al., 2010), (Franke and modeling approach under some simplifying asasa cost-effective way (˚ Akesson et al., 2010), (Franke and parameter sumptions: In order to bridge the gap between the efficient highVogelbacher, 2006). sumptions: • The steam boiler is adiabatic. Vogelbacher, 2006). level modeling language that between Modelicathe offers and stateIn to the efficient high•• The are in equilibrium. steam is In order order to bridge bridge the gap gap between the efficient highThe vapor-liquid steam boiler boiler phases is adiabatic. adiabatic. of-the art dynamic optimization algorithms, the stateopenlevel modeling language that Modelica offers •• Pressure and temperature arein in both phases. The vapor-liquid phases equilibrium. level modeling language that Modelica offers and and stateThe vapor-liquid phases are are inuniform equilibrium. source platform was algorithms, established to of-the art the open•• Pressure and temperature are uniform in both phases. of-the JModelica.org art dynamic dynamic optimization optimization algorithms, theprovide openPressure aand temperature are uniform both phases. significant amount of work in has been dedia compact environment dedicated the simulation and In literature, source JModelica.org platform was established to source JModelica.org platform was to established to provide provide cated to derive suitable models. These models range from In literature, a significant amount of work has been dedioptimization of Modelica models (Andersson et al., 2011) a a compact compact environment environment dedicated dedicated to to the the simulation simulation and and In literature, a significant amount of work has been dedivery complex and detailed models, to data-driven mod˚ cated to derive suitable models. These models range from of Modelica models (Andersson et al., 2011) (optimization A kesson et al., 2010). Therefore, the intention of the optimization of Modelica models (Andersson et al., 2011) cated to derive suitable models. These models range from els based on measurements from the plant. Among these very complex and detailed models, to data-driven modJModelica platform is to let the modeler focus on the ((˚ A kesson et al., 2010). Therefore, the intention of complex and detailed models, to data-driven mod˚ Akesson et al., 2010). Therefore, the intention of the very works, there models aiming model-based plantthese conels based on measurements from plant. formulation of the optimal hand,on rather JModelica is let modeler the based on are measurements fromatthe the plant. Among Among these JModelica platform platform is to to control let the theproblem modeleratfocus focus on the els trol, see (Maffezzoni, 1997), (Adam and Marchetti, 1999), works, there are models aiming at model-based plant formulation of there are models aiming at model-based plant conconformulation of the the optimal optimal control control problem problem at at hand, hand, rather rather works, 1 Modelica is a non-proprietary, object-oriented modeling language trol, see (Maffezzoni, (Adam and ˚str¨om and1999), (Tyss∅, (Casella1997), and Leva, 2005), A Bell, 1 Modelica is a non-proprietary, object-oriented modeling language trol, see1981), (Maffezzoni, 1997), (Adam and (Marchetti, Marchetti, 1999), ˚ 1 Modelica 2000) name (Casella a few. and of a named Modelica (Tyss∅, of a non-profit non-profit organization named Modelica Association. Association. is aorganization non-proprietary, object-oriented modeling language ˚ 1 Modelica (Tyss∅,to1981), 1981), (Casella and Leva, Leva, 2005), 2005), ((A Astr¨ str¨oom m and and Bell, Bell, is a non-proprietary, object-oriented modeling language 2000) to name a few. of a non-profit organization named Modelica Association. 2000) to name a few. of a non-profit organization named Modelica Association.
Copyright © 2015, IFAC 204 Copyright © 2015, 2015,IFAC IFAC (International Federation of Automatic Control) 204Hosting by Elsevier Ltd. All rights reserved. 2405-8963 © Copyright 2015,responsibility IFAC 204Control. Peer review©under of International Federation of Automatic Copyright © 2015, IFAC 204 10.1016/j.ifacol.2015.05.050
MATHMOD 2015 February 18 - 20, 2015. Vienna, Austria
F. Belkhir et al. / IFAC-PapersOnLine 48-1 (2015) 204–209
˚str¨ The steam boiler model from (A om and Bell, 2000) is selected here. This is primarily due to its compactness, familiarity to control theorists, and to compare the results obtained in this contribution with the optimal start-up trajectories in (Franke et al., 2003). 2.1 Mass Balance The integral balance on the total mass of the boiler can be given by eq. 1:
∂ρw ∂ρs Vw (l) + Vs ∂p ∂p
dVw (l) dp + (ρw − ρs ) dt dt = qw − qs ,
2.2 Energy Balance Similarly, the energy balance is given by eq. 2 and by taking into account that the metal tube temperature denoted by Tm equals to the saturated temperature Ts of water inside the boiler-drum, i.e. TD = Ts (p). dVw dp + A12 = Q˙ + qw hw − qs hs , dt dt
(2)
with ∂ρs ∂ρw ∂hs ∂hw + ρs + Vw hw + ρw A11 = Vs hs ∂p ∂p ∂p ∂p ∂Ts − V + mt cp ∂p A12 = ρw hw + ρs hs where Q˙ the heat flow, V the water-steam volume, hs and hw the steam and water enthalpies, cp the metal specific heat capacity. Finally, the thermal stress is given by (Franke et al., 2003): dTD , k = const., (3) σD = k dt 2.3 Optimal Control Formulation In general, the derived dynamic process model will take the following form (Bequette, 2003): ˙ x(t) = f (x(t), z(t), p(t), u(t)) (4a) y(t) = g (x(t), z(t), p(t), u(t)) , (4b) where x ∈ Rnx is the vector of dynamic states, z ∈ Rnz the vector of disturbance variables, p ∈ Rnp the vector of parameters, and y ∈ Rny the vector of output variables. The optimal control problem is to find a set of admissible control u∗ , causing the system given by eq. 4 to follow an admissible trajectory x∗ , that minimizes a cost function denoted by J subject to path and terminal constraints given in eq. 5, see (Kirk, 2012). 205
tf
L[t, x(t), u(t)]dt → min, t0
u(t)
s.t. (5) x(t0 ) = x0 , ˙ = f [x(t), u(t)] , ∀t ∈ [t0 , tf ] : x(t) ∀t ∈ [t0 , tf ] : h [x(t), u(t)] � 0, φ(x(tf )) = 0, where φ(x(tf )) and L[t, x(t), u(t)] are the Meyer and the Lagrange term, respectively. 3. SIMULATION AND OPTIMIZATION FRAMEWORK
(1)
where ρw and ρs are the density of water and vapor, Vw the water volume, Vs the steam volume in the drum, l the liquid-level, p the pressure, qw and qs the inlet water flow rate and the steam flow rate, respectively.
A11
J = φ(x(tf )) +
205
3.1 JModelica JModelica is an open-source platform based on Modelica models, focused on dynamic optimization and simulation of complex systems. The architecture of the JModelica platform is shown in Fig. 1. It consists mainly of two parts: compiler and the JModelica model Interface runtime library(JMI). The compilers are used for translating Modelica and Optimica extensions into C and XML code, which are well suitable for efficient numerical evaluation. All required interfaces are provided for a time-efficient Modelica models integration with the platform in comparison to(Franke and Vogelbacher, 2006) The interface is based on Python, a free open-source and frequently used language within the scientific community, as it permits high-level scripting of complex tasks in an easy way. Some of its packages such as, Numpy and Scipy, can be imported to perform all the numerical computing needed, including the Matplotlib package to get Matlablike plots. The JModelica platform uses a simultaneous optimization algorithm based on orthogonal collocation using Lagrange polynomials and Radau points. The process makes it possible to transfer differential algebraic equations (DAE) used in the dynamic model, into a large-scale NLP 2 problem. Then, the problem can be solved with the IPOPT 3 solver, which offers different options to improve the numerical evaluation of the model which can be changed in the Python script file (see Listing. 1). At present, a drawback of JModelica is that the water model of the Modelica standard Media library is not supported; so another tuned media model for the water must be defined. It is an important point in the simulation because of the coexistence of different phases in the drum boiler. A polynomial approximation of the water properties is used in this paper, which have been successfully validated against the standard Media model. 3.2 Optimica Extension The Optimica extension was developed in order to provide the user with a tool to formulate optimization problems. The Modelica language itself lacks constructs to implement an optimal control problem (OCP). Adding 2 3
Nonlinear Programming Interior Point OPTimizer
MATHMOD 2015 206 February 18 - 20, 2015. Vienna, Austria
F. Belkhir et al. / IFAC-PapersOnLine 48-1 (2015) 204–209
Fig. 1. Overview of the JModelica.org Platform adapted from (˚ Akesson et al., 2010). little constructs for expressing an objective cost function, constraints, and parameters to the Modelica model via the Optimica extension is all that is needed to solve an OCP with JModelica. In comparison to individual, casespecifically arranged solutions such as in (Franke and Vogelbacher, 2006), a very less programming and interfacing are needed. There are only few essential necessary elements to specify an optimization problem. Inside the new specialized class optimization both Optimica and Modelica constructs can be used. This class can contain component and variable declarations from a Modelica model as well as local classes, equations, and constraints. Some of the class attributes for the specialized class optimization are objective, startTime and finalTime which defines the objective cost function and the optimization interval. Built-in attributes such as free, fixed and initialGuess can also be set. The constraints are given in the constraint section, which can be set as inequality constraints (see Listing. 2).
The improved start-up can be formulated as an OCP 4 , by minimizing a quadratic cost function subject to the boiler dynamics and imposed hard-constraints on the system: tf J= α(psat − pref )2 + β(qs − qs,ref )2 dt → min, (6) t0
u(t)
where pref =180bar, qs,ref =185kg/s and the weighting values α = 10−3 and β = 10−4 . The hard-constraint to be satisfied over the time horizon [t0 ,tf ] are 0 ≤ Q˙ ≤ 500MW, (7) 0 ≤ Yvalve ≤ 1, and dQ˙ (8) − 25MW/min ≤ ≤ 25MW/min dt (9) − 10N/mm2 ≤ σD ≤ 10N/mm2 The final constraint avoids an excessive thermal-stress on the boiler’s thick-walled part. Therefore, the goal of ˙ the OCP is to find optimal control trajectories Q(t) and Yvalve (t), such that eq. 6 is minimized and the constraints given by (7),(8),(9) are respected.
4. MODEL IMPLEMENTATION AND OPTIMIZATION SET-UP
5. OPTIMIZATION OF THE PROCESS
The steam boiler described by the equations given in the subsections 2.1 and 2.2 was implemented in Modelica as shown in Fig. 2. In classical start-up strategies in heat recovery units, the goal is to achieve a given pressure and temperature references for the steam in a short period of time, to fulfil the short-term load of the electric grid in case of a deregulated energy market. This is achieved by applying a ramp to the firing fuel flow and restricting the fuel rate of change within a critical interval, see eq. 6. Usually, another crucial limiting factor for a fast start-up procedure is the thermal-stress on the boiler’s thick-walled part. 206
The infinite-dimensional optimal control problem given in the previous section is translated into a finite dimensional nonlinear programming problem, using a simultaneous collection method implemented in the CasADi package, by approximating both control and state profiles with a Lagrange polynomial based on Radau points. This results into a large-scale non-linear optimization problem. Algorithm based on Sequential Quadratic Programming (SQP) or interior method, such as IPOPT provides an efficient solution method for the NLP problem. The first and second derivatives, as well as the sensitivity information required 4
Optimal Control Problem
MATHMOD 2015 February 18 - 20, 2015. Vienna, Austria
F. Belkhir et al. / IFAC-PapersOnLine 48-1 (2015) 204–209
207
Fig. 2. Modelica implementation of the steam boiler using polynomial approximation for computing the water/steam thermodynamic properties. by IPOPT are automatically generated by CasADi. In this paper, the software used is JModelica v.1.14 as well as IPOPT v.3.8.11 running with the linear MA57 solver, which performs better than the standard MUMPS solver, have been selected. The optimization time interval is set to one hour. The PC used is an Intel Core i5-3210M, 2.5 GHz, with 8GB RAM. Last but not least, the simulation trajectories were used to provide a good initial guess for the solver. Table1 shows some results after NLP problem solving using the JModelica framework. The obtained optimized trajectories are illustrated in Fig.1. The figures clearly show that by solving the startup problem as an OCP, the steam production is achieved within a shorter time to fulfil turbine inlet parameters, compared to classical start-up strategy, and without violating the imposed hard-constraint on the thermal-stress of thick-walled component, which increases its lifetime consumption. Table 1. Execution and NLP function evaluation times Nr. of variables Nr. of objective function evaluation Nr. of Lagrange Hessian evaluation NLP function evaluations time Initialization time Solution time Total time
value 7595 1090 290 1.96 1.25 7.01 8.27
unit [-] [-] [-] [sec] [sec] [sec] [sec]
6. CONCLUSION In this contribution, The high-level object-oriented modeling language Modelica was fully extended by the Optimica 207
extension to account for optimal control problems when using the Modelica models. This was demonstrated by solving an optimal start-up control problem of steam boiler using the JModelica framework, where the objective is to achieve a reference pressure and steam flow rate in a shorter time in order to fulfil the turbine inlet parameters, by taking the thermal-stress on the boiler’s thick-walled component as the most limiting constraint during the start-up phase. The procedure clearly shows that with a given Modelica process model, the optimization procedure requires only inserting several problem-specific settings into given Python and Optimica templates, leading to a reduced effort when formulating optimal control problems. REFERENCES Adam, E. and Marchetti, J. (1999). Dynamic simulation of large boilers with natural recirculation. Computers & chemical engineering, 23(8), 1031–1040. ˚ Akesson, J., ˚ Arz´en, K.E., G¨afvert, M., Bergdahl, T., and Tummescheit, H. (2010). Modeling and optimization with optimica and jmodelica.org languages and tools for solving large-scale dynamic optimization problems. Computers & Chemical Engineering, 34(11), 1737–1749. Andersson, J., ˚ Akesson, J., Casella, F., and Diehl, M. (2011). Integration of casadi and jmodelica. org. In 8th International Modelica Conference, 75. ˚ Astr¨om, K.J. and Bell, R.D. (2000). Drum-boiler dynamics. Automatica, 36(3), 363–378. Bequette, B.W. (2003). Process control: modeling, design, and simulation. Prentice Hall Professional. Casella, F. and Leva, A. (2005). Object-oriented modelling & simulation of power plants with modelica. In Decision and Control, 2005 and 2005 European Control
MATHMOD 2015 208 February 18 - 20, 2015. Vienna, Austria
F. Belkhir et al. / IFAC-PapersOnLine 48-1 (2015) 204–209
Fig. 3. Comparison between the classical start-up (green-dashed line) and the optimized start-up (red-dashed). The orange-dashed line represents constraints on the physical system. The yellow box shows that the reference set-point is reached after 22 min for the non-optimized start-up in comparison to the optimized start-up strategy. Conference. CDC-ECC’05. 44th IEEE Conference on, 7597–7602. IEEE. Franke, R., Rode, M., and Kr¨ uger, K. (2003). On-line optimization of drum boiler startup. In Proceedings of the 3rd International Modelica Conference, Link¨ oping. Franke, R. and Vogelbacher, L. (2006). Nonlinear model predictive control for cost optimal startup of steam power plants (nichtlineare modellpr¨ adiktive regelung zum kostenoptimalen anfahren von dampfkraftwerken). at–Automatisierungstechnik, 54(12), 630–637. Fritzson, P. (2010). Principles of object-oriented modeling and simulation with Modelica 2.1. John Wiley & Sons. Kirk, D.E. (2012). Optimal control theory: an introduction. Courier Dover Publications. Maffezzoni, C. (1997). Boiler-turbine dynamics in powerplant control. Control Engineering Practice, 5(3), 301– 312. Tyss∅, A. (1981). Modelling and parameter estimation of a ship boiler. Automatica, 17(1), 157–166.
208
#! / u s r / b i n / env python # −∗− c o d i n g : u t f −8 −∗− # Import l i b r a r y f o r path m a n i p u l a t i o n s i m p o r t o s . path # Import n u m e r i c a l l i b r a r i e s i m p o r t numpy a s N import m a tp l o tl i b . pyplot as p l t from s c i p y . i o . matlab i m p o r t savemat # Import th e needed J M o d e l i c a . o r g Python methods from p y m o d e l i c a i m p o r t c o m p i l e f m u from pyfmi i m p o r t l o a d f m u from pyjmi i m p o r t g e t f i l e s p a t h d e f run ( w i t h p l o t s=True ) : ### 1 . Compute i n i t i a l g u e s s t r a j e c t o r i e s by means o f s i m u l a t i o n # L o c a te th e M o d e l i c a and Optimica code f i l e p a t h s = ( o s . path . j o i n ( g e t f i l e s p a t h ( ) , ” P r o c e s s M o d e l . mo” ) , o s . path . j o i n ( g e t f i l e s p a t h ( ) , ” Optimica . mop” ) ) # Compile th e o p t i m i z a t i o n i n i t i a l i z a t i o n model i n i t s i m f m u = c o m p i l e f m u ( ” Optimica . S i m u l a t i o n ” , f i l e p a t h s , s e p a r a t e p r o c e s s =True )
MATHMOD 2015 February 18 - 20, 2015. Vienna, Austria
if
F. Belkhir et al. / IFAC-PapersOnLine 48-1 (2015) 204–209
# Load th e model i n i t s i m m o d e l = load fmu ( i n i t s i m f m u ) # Simulate i n i t r e s = init sim model . simulate ( start time =0. , f i n a l t i m e =3600.) # Extract var i abl e p r o f i l e s i n i t s i m p l a n t p = i n i t r e s [ ’ plant . drumboiler .p’ ] i ni t s i m pl ant m f l ow = i n i t r e s [ ’ plant . valve .q w ’] i n i t s i m p l a n t l o a d = i n i t r e s [ ’ p l a n t . Qdot ’ ] i n i t s i m p l a n t v a l v e= i n i t r e s [ ’ p l a n t . Y v a l v e ’] i n i t s i m p l a n t T s= i n i t r e s [ ’ p l a n t . d r u m b o i l e r . sat . T s ’ ] i n i t s i m t i m e = i n i t r e s [ ’ time ’ ] i n i t s i m s i g m a= i n i t r e s [ ’ p l a n t . d r u m b o i l e r . sigma ’ ] i n i t s i m V s t= i n i t r e s [ ’ p l a n t . d r u m b o i l e r . Vv ’ ] # P l o t th e i n i t i a l g u e s s t r a j e c t o r i e s i f with plots : savemat ( ” i n i t i a l g u e s s . mat” , mdict={ ’ time ’ : i n i t s i m t i m e , ’ Qdot ’ : i n i t s i m p l a n t l o a d , ’ Y valve ’ : i n i t s i m p l a n t v a l v e }) ### 2 . S o l v e th e o p t i m a l c o n t r o l problem # Compile model from pyjmi i m p o r t transfer to casadi interface op = t r a n s f e r t o c a s a d i i n t e r f a c e ( ” Optimica . OCP” , f i l e p a t h s ) # S e t J M o d e l i c a . o r g and IPOPT o p t i o n s o p t o p t s = op . o p t i m i z e o p t i o n s ( ) o p t o p t s [ ’ IPOPT options ’ ] [ ’ m a x i t e r ’ ] = 500 # Max number o f i t e r a t i o n s o p t o p t s [ ’ IPOPT options ’ ] [ ’ l i n e a r s o l v e r ’ ]= ’ ma57 ’ # S o l v e r used by IPOPT o p t o p t s [ ’ IPOPT options ’ ] [ ’ m a 5 7 p r e a l l o c ’ ]= 10 # Amount o f memory used by Python o p t o p t s [ ’ n e ’ ] = 50 # Number o f f i n i t e elements opt opts [ ’ i n i t t r a j ’ ] = i n i t r e s . r es ul t data # S i m u l a t i o n r e s u l t i s used a s i n i t i a l trajectory opt opts [ ’ nominal traj ’ ] = i n i t r e s . result data # S o l v e th e o p t i m a l c o n t r o l problem o p t r e s = op . o p t i m i z e ( o p t i o n s=o p t o p t s ) # Extract var i abl e p r o f i l e s opt plant p = opt r es [ ’ plant . drumboiler . p ’ ] opt plant m flow = opt r es [ ’ plant . valve . q w ’ ] o p t p l a n t l o a d = o p t r e s [ ’ p l a n t . Qdot ’ ] o p t p l a n t v a l v e=o p t r e s [ ’ p l a n t . Y v a l v e ’ ] o p t p l a n t T s a t=o p t r e s [ ’ p l a n t . d r u m b o i l e r . s a t .T s’] o p t t i m e = o p t r e s [ ’ time ’ ] o p t p l a n t s i g m a=o p t r e s [ ’ p l a n t . d r u m b o i l e r . sigma ’ ] # P l o t th e o p t i m i z e d t r a j e c t o r i e s i f with plots : savemat ( ” OptimizedCurves . mat” , mdict={ ’ time ’ : o p t ti m e , ’ Qdot ’ : opt Qdot p , ’ Y valve ’ : o p t p l a n t v a l v e }) n a m e ==” m a i n ” : run ( )
209
Package Optimica // Used f o r model s i m u l a t i o n c o n n e c t o r R e a l C o n n e c to r =Real ; model S i m u l a t i o n Process . Optimization . t e s t plant ; R e a l C o n n e c to r u ; R e a l C o n n e c to r vv ; equation u= i f time <=2700 th e n 1 4 8 1 4 8 . 1 4 8 ∗ time e l s e 400 e6 ; vv= 1 ; c o n n e c t ( vv , p l a n t . Y v a l v e ) ; c o n n e c t ( u , p l a n t . Qdot ) ; end Optimica optimization OCP ( objective= w1 ∗ ( ( p r e f −p l a n t . d r u m b o i l e r . p ) /1 e6 ) ˆ2+ w2∗ ( q s r e f −p l a n t . v a l v e . q w ) ˆ 2 , startTime=0 , finalTime =3600) // Set−p o i n t t r a j e c t o r i e s p a r a m e te r Real p r e f =1.8 e7 ; p a r a m e te r Real q s r e f= 1 8 5 ; // Model i n s t a n c e Process . Optimization . t e s t plant ; // C o n n e c to r s Modelica . Blocks . I n t e r f a c e s . RealInput v ( f r e e=tr u e , min=0 ,max=1)= p l a n t . Y v a l v e ; M o d e l i c a . B l o c k s . I n t e r f a c e s . R e a l I n p u t du ( f r e e=tr u e , min=Lb , max=Ub) ; R e a l C o n n e c to r u ( s t a r t =0 , f i x e d=t r u e ) ; equation d e r ( u )=du ; c o n n e c t ( u , p l a n t . Qdot ) ; constraint p l a n t . d r u m b o i l e r . p ( s ta r tT i m e ) =101325; v ( s ta r tT i m e ) =0; u>=0; u<=500 e6 ; p l a n t . d r u m b o i l e r . sigma >=−10; p l a n t . d r u m b o i l e r . sigma <=10; p l a n t . d r u m b o i l e r . sigma ( s ta r tT i m e ) =0; end OCP;
Listing 2. Optimica *.mop file extension for the steam boiler case. The Optimica constructs are emphasized in bold.
Listing 1. User Python script for individual optimal control problems setting.
209