#
Dynamic Optimization in JModelica.org^{ †}

^{1}

^{2}

^{*}

^{†}

## Abstract

**:**

## 1. Introduction

_{k}. The integer interval from a ∈ ℤ to b ∈ ℤ (inclusive) is denoted by [a..b].

## 2. Dynamic Optimization

#### 2.1. Problem Formulation

_{0}, t

_{f}] is the sole independent variable: time, $\mathit{x}:[{t}_{0},{t}_{f}]\to {\mathbb{R}}^{{n}_{x}}$ is the differential variable, $\mathit{y}:[{t}_{0},{t}_{f}]\to {\mathbb{R}}^{{n}_{y}}$ is the algebraic variable, $\mathit{u}:[{t}_{0},{t}_{f}]\to {\mathbb{R}}^{{n}_{u}}$ is the control variable, and $\mathit{p}\in {\mathbb{R}}^{{n}_{p}}$ is the vector of parameters to be optimized—that is, the free parameters. For now we also assume that the DAE system is of most index one, meaning that the Jacobian of

**F**is nonsingular with respect to $\dot{\mathit{x}}$ and

**y**. We will comment on the treatment of high-index DAE systems in Section 3.3.2.

_{z}:= 2 · n

_{x}+ n

_{y}+ n

_{u}. The system dynamics are thus fully described by

**F**and

**F**

_{0}can be further restricted by the introduction of variable bounds, as discussed below. We do not consider systems that have integer variables or time delays.

_{0}and t

_{f}may be either free or fixed. Equation (1) has been introduced as a constraint in Equation (2b). Consequently, the optimization variables are not only those generating degrees of freedom (

**u**,

**p**, t

_{0}, and t

_{f}), but also the system variables

**x**(which inherently determines $\dot{\mathit{x}}$) and

**y**. Note that solving the initial equations for the initial state will be done as a part of solving the optimization problem, which for example enables the treatment of problems where the initial state is unknown.

_{f},

**z**(t

_{f}),

**p**), but here we work with a generalized form. The essence of the generalization is that instead of depending on only the terminal state, it depends on the state at a finite, arbitrary number of time points within the time horizon. This gives rise to the notion of timed variables, which we denote by

**z**

_{T}, which we define by first denoting the needed time points by T

_{1}, ${T}_{2},\dots ,{T}_{{n}_{T}}$, where n

_{T}∈ Z is the number of such time points. These time points must be equal to a convex combination of t

_{0}and t

_{f}; that is, for all j there must exist a fixed θ

_{j}∈ [0, 1] such that T

_{j}= (1 − θ

_{j})t

_{0}+ θ

_{j}t

_{f}. For problems with a fixed time horizon, this simply means that T

_{i}∈ [t

_{0}, t

_{f}]. For problems with a free time horizon, this means that the location of the time points depend on the optimal t

_{0}and t

_{f}. We then let

_{1}= t

_{f}. One application of the generalized Mayer term is the formulation of parameter estimation problems, where there typically is measurement data for the system outputs at discrete time points, which is used to penalize the deviation of the model output from the data values at these points. An alternative approach in this case is to interpolate the measurement data to form a continuous-time measurement trajectory. This trajectory can then instead be used to form a Lagrange integrand which penalizes the deviation of the model output from the measurements. The occurrence of the timed variables

**z**

_{T}is not restricted to the Mayer term. The timed variables can also be used in the Lagrange integrand and the constraints, as discussed below. A more common (and also more general) approach to treating timed variables is by introducing multiple phases ([13] Section 3.7), which we do not consider further in this paper.

_{0}, t

_{f}], where ${\mathit{z}}_{L}\in {\left[-\infty ,\infty \right]}^{{n}_{z}}$ and ${\mathit{p}}_{L}\in {\left[-\infty ,\infty \right]}^{{n}_{p}}$ are the lower bounds and ${\mathit{z}}_{U}\in {\left[-\infty ,\infty \right]}^{{n}_{z}}$ and ${\mathit{p}}_{U}\in {\left[-\infty ,\infty \right]}^{{n}_{p}}$ are the upper bounds. The constraints Equation (2d) are path constraints, which are generalizations of the variable bounds. They are separated from the variable bounds, since the bounds can be treated more efficiently by many numerical algorithms. For example, an interior-point algorithm will ensure that the bounds are satisfied even during iteration, thus restricting the domains of the NLP functions. Finally, Equation (2e) is point constraints. These are similar to the path constraints, with the difference being that they are only enforced at specific time points, rather than during the entire time horizon. The time points T

_{j}that were used to generalize the Mayer term are also used to formulate the point constraints. The path constraints may also depend on the timed variables. The number of time points n

_{T}is thus not only the number of time points involved in the Mayer term, but also includes the number of time points needed to formulate the Lagrange term as well as the path and point constraints.

_{0}, the path constraint functions

**g**

_{e}and

**g**

_{i}as well as the point constraint functions

**G**

_{e}and

**G**

_{i}must all be twice continuously differentiable with respect to the arguments that correspond to any of DOP variables. For example,

**F**must be twice continuously differentiable with respect to its second argument, corresponding to the system variables

**z**, but not with respect to its first argument, corresponding to the explicit time dependence. These continuity requirements are needed to apply techniques based on Newton’s method to find a solution to first-order optimality conditions. Equation (2c)–(2e) are optional, whereas Equations (2a) and (2b) are necessary to get a sensible DOP (although Equation (2a) can be removed to obtain a feasibility problem). No assumptions of linearity or convexity are made. The problem will thus in general be nonconvex and we will not endeavor to find a global optimum. We will instead use first-order necessary optimality conditions to find a local optimum.

#### 2.2. Numerical Methods

_{f}and iteratively updates the control based on sensitivities. The numerical robustness of single shooting can be improved by dividing the time horizon into subintervals. Single shooting is then applied within each subinterval, by introducing the subinterval boundary values as variables and imposing linking constraints between the subintervals. This is called multiple shooting, which essentially decouple the dynamics between the subintervals.

## 3. Related Software and Languages

#### 3.1. Tools for Dynamic Optimization

#### 3.2. Modelica and Optimica

#### 3.3. Software Used to Implement Framework

#### 3.3.1. CasADi

**C**omputer algebra system with

**A**utomatic

**D**ifferentaion) is a low-level tool for efficiently computing derivatives using AD and is tailored for dynamic optimization. Once a symbolic representation of an NLP has been created using CasADi primitives, the needed derivatives are efficiently and conveniently obtained and sparsity patterns are preserved. CasADi also offers interfaces to numerical optimization solvers, allowing for seamless integration with for example IPOPT and WORHP.

#### 3.3.2. The JModelica.org Compiler

#### 3.3.3. Nonlinear Programming and Linear Solvers

## 4. Direct Local Collocation

#### 4.1. Collocation Polynomials

_{e}elements. Let h

_{i}denote the length of element i, which has been normalized so that the sum of all element lengths is one. This normalization facilitates the solution of problems with free endpoints by keeping the normalized element lengths constant and instead varying t

_{0}and t

_{f}. The time is normalized in element i according to

_{i}is the mesh point (right boundary) of element i. This normalization enables a treatment of the below interpolation conditions that is homogeneous across elements.

**z**is approximated using a polynomial in the local time τ denoted by

_{c}collocation points, which in this work are restricted to be the same for all elements. We use Lagrange interpolation polynomials to represent the collocation polynomials, using the collocation points as interpolation points. Let τ

_{k}∈ [0, 1] denote collocation point k ∈ [1..n

_{c}], and let ${z}_{i}{}_{,k}=({\dot{\mathit{x}}}_{i,k},{\mathit{x}}_{i,k},{\mathit{y}}_{i,k},{\mathit{u}}_{i,k})\in {\mathbb{R}}^{{n}_{z}}$ denote the value of

**z**

_{i}(τ

_{k}).

**x**needs to be continuous on [t

_{0}, t

_{f}], we introduce an additional interpolation point at the start of each element for the corresponding collocation polynomials, denoted by τ

_{0}:= 0. We thus get the collocation polynomials

_{k}are the Lagrange basis polynomials, respectively with and without the additional interpolation point τ

_{0}. The basis polynomials are defined as

_{i,k}= z

_{i}(τ

_{k}).

**x**

_{i}is differentiated with respect to time. Using Equations (4) and (5), and the chain rule, we obtain

_{k}, with different numerical properties, in particular regarding stability and order of convergence. The most common ones are called Gauss, Radau and Lobatto collocation [37]. The framework in JModelica.org has support for Radau and Gauss points. For the sake of brevity, we will in the next subsection present a transcription based on Radau collocation. The Radau collocation scheme always places a collocation point at the end of each element, and the rest are chosen in a manner that maximizes numerical accuracy.

#### 4.2. Transcription of the Dynamic Optimization Problem

_{0}, t

_{f}], which is infinite-dimensional, is thus reduced to a domain of finite dimension by approximating the trajectory

**z**by a piecewise polynomial function.

**z**

_{i,k}, the differential variable values at the start of each element,

**x**

_{i}

_{,0}, the free parameters,

**p**, the initial condition values,

**z**

_{1,0}:=

**z**(t

_{0}), and t

_{0}and t

_{f}if they are free. We thus let

**z**

_{T}during the transcription. The first is to approximate

**z**(T

_{j}) by the value of its corresponding collocation polynomial, that is,

**z**

_{i}(τ(T

_{j})). A less general approach is to assume that every time point T

_{j}coincides with some collocation point t

_{i,k}; that is, there exists a map

**Γ**: [1..n

_{T}] → [1..n

_{e}] × [1..n

_{c}] such that T

_{j}= t

_{Γ(}

_{j}

_{)}. We can then proceed to transcribe

**z**

_{T}, defined by Equation (3), into

**Γ**. It is also more user-friendly, since it does not force the user to align the element mesh with the time points T

_{j}. On the other hand, the latter approach is more efficient for large n

_{T}, which is typical for parameter estimation problems. The two approaches also have distinct numerical properties, which are outside the scope of this paper to analyze. Henceforth we adopt the latter approach, which assumes the existence of

**Γ**.

**Γ**, the Mayer term of the Bolza functional is straightforward to transcribe as

_{k}are given by

_{0}, t

_{f}], it is only enforced at the collocation points. Thus

**z**

_{1,0}, the initial conditions in Equation (2b) are seemingly straightforward to transcribe into

**F**

_{0}(t

_{0},

**z**

_{1,0},

**p**) = 0. However, this introduces an additional degree of freedom due to

**u**

_{1,0}, which is governed by neither the DAE system nor the initial conditions in Equation (7b). Rather, since

**u**

_{1,0}is not used to parametrize the collocation polynomial

**u**

_{1}, its value is already determined by the collocation point values

**u**

_{1},

_{k}. The transcription of the initial conditions thus also gives rise to the extrapolation constraint in Equation (7c). Furthermore, the implicit initial equations need to be solved in conjunction with the DAE system at the start time t

_{0}, which is why most of the constraints are not only enforced at the collocation points (i, k) ∈ [1..n

_{e}] × [1..n

_{c}], but also at the start point (i, k) = (1, 0).

**Γ**, the point constraints in Equation (2e) can be transcribed into Equation (7f).

**x**and $\dot{\mathit{x}}$, which is implicit in the dynamic setting, we enforce Equation (6) at all the collocation points, giving us the additional constraints in Equation (7g). These are not enforced at the start time t

_{0}, where the differential variable derivative $\dot{\mathit{x}}$ instead is determined by the DAE system and initial conditions. Finally, to get a continuous trajectory for the differential variable

**x**, we add the constraints in Equation (7h).

## 5. Practical Aspects and Additional Features

#### 5.1. Initialization

**u**,

**p**, t

_{0}and t

_{f}—the system can then be simulated to generate initial guesses for all of the variables. This also has the added benefit of generating initial guesses in the form of complete trajectories, rather than constant values, which may be highly beneficial.

#### 5.2. Problem Scaling

_{j}for the scaled variable ${\tilde{Z}}_{j}$ according to ${Z}_{j}={d}_{j}{\tilde{Z}}_{j}+{e}_{j}$. By an appropriate choice of d

_{j}and e

_{j}, the new variable ${\tilde{Z}}_{j}$ will have magnitude one. There are three strategies available in the framework for choosing d

_{j}and e

_{j}, with the possibility of applying different strategies for each individual DOP variable.

#### Time-Invariant Linear Scaling

_{j}= 0 and d

_{j}to the nominal value of the DOP variable corresponding to Z

_{j}. This nominal value is defined either by the absolute value of the nominal attribute of the DOP variable, which typically is set by the user, or computed based on the initial guess. If the initial guess is given as a trajectory, the nominal value is chosen as the maximum absolute value of the trajectory over time. Otherwise, the nominal value is simply the absolute value of the constant initial guess.

#### Time-Invariant Affine Scaling

_{j}and e

_{j}such that the scaled trajectory has a minimum value of 0 and a maximum value of 1. Let ${Z}_{j}^{\mathrm{max}}$ and ${Z}_{j}^{\mathrm{min}}$ denote the maximum and minimum value, respectively, for the initial guess trajectory of the DOP variable corresponding to Z

_{j}. The scaling factors are then chosen as

#### Time-Variant Linear Scaling

_{j}= 0 and d

_{j}to be the absolute value of the initial guess for Z

_{j}. It is thus only different from the time-invariant linear scaling when initial guesses for the DOP variables are provided in the form of trajectories rather than constant values.

_{j}for all of the strategies, since d

_{j}= 0 does not work and values relatively close to zero are prone to make matters worse unless chosen with great care. The framework attempts to detect these cases and fall back to more conservative scaling strategies for the problematic variables.

#### 5.3. Discretization Verification

_{e}, collocation points n

_{c}, and the element lengths h

_{i}need to be chosen. While methods exist for automating these choices by taking discretization error into account, either by repeatedly solving the problem and updating the discretization [40] or introducing the element lengths as NLP variables and bounds or penalties on the discretization error estimate [41], these are computationally expensive and may not be tractable. The framework thus forces the user to choose the discretization and fixing it a priori.

**u**and

**p**to simulate the system, using numerical integrators with adaptive step length, and verify that the simulation does not significantly differ from the trajectories obtained from the optimization. It is then important to keep in mind that the simulation should be performed using the collocation polynomials

**u**

_{i}, rather than for example linearly interpolating the collocation points

**u**

_{i,k}, for increased accuracy and also that the interpolated values may not satisfy the input bounds.

#### 5.4. Control Discretization

**u**are desirable in the DOP in Equation (2), in particular constraining it to be piecewise constant. This is necessary to for example take into account that modern controllers usually are digital, which is especially important when using MPC, where the input signals are kept constant between each sample. This is supported in the framework by optionally enforcing

**u**

_{i}to be constant for all i and also possibly equal to

**u**

_{i}

_{+1}for some i; that is, only allowing changes in the control at a user-specified subset of the element boundaries. It is then also possible to add additional penalties or constraints on the difference in the control values between the element boundaries. This corresponds to penalizing or constraining the control signal derivative in the case that the control is not enforced to be piecewise constant.

#### 5.5. Algorithmic Differentiation Graphs

## 6. Implementation

## 7. Examples

#### 7.1. Van der Pol Oscillator

_{0}= 0 to t

_{f}= 10

#### 7.2. Distillation Column

_{vol}[l/h]. There are positivity bounds on the flux out of the condenser and reboiler, which are algebraic variables. These bounds put implicit upper limits on the two system inputs.

## 8. Conclusions

## Acknowledgments

## Author Contributions

## Conflicts of Interest

## References

- Sällberg, E.; Lind, A.; Velut, S.; Åkesson, J.; Gallardo Yances, S.; Link, K. Start-Up Optimization of a Combined Cycle Power Plant, Proceedings of the 9th International Modelica Conference, Munich, Germany, 3–5 September 2012.
- Prata, A.; Oldenburg, J.; Kroll, A.; Marquardt, W. Integrated scheduling and dynamic optimization of grade transitions for a continuous polymerization reactor. Comput. Chem. Eng.
**2008**, 32, 463–476. [Google Scholar] - Ilzhoefer, A.; Houska, B.; Diehl, M. Nonlinear MPC of kites under varying wind conditions for a new class of large-scale wind power generators. Int. J. Robust Nonlinear Control
**2007**, 17, 1590–1599. [Google Scholar] - Zavala, V.M. Inference of building occupancy signals using moving horizon estimation and Fourier regularization. J. Proc. Cont.
**2014**, 24, 714–722. [Google Scholar] - Allgöwer, F.; Badgwell, T.A.; Qin, J.S.; Rawlings, J.B.; Wright, S.J. Nonlinear Predictive Control and Moving Horizon Estimation—An Introductory Overview. In Advances in Control: Highlights of ECC ’99; Frank, P.M., Ed.; Springer: Berlin, Germany, 1999; pp. 391–449. [Google Scholar]
- Åkesson, J.; Årzén, K.E.; Gäfvert, M.; Bergdahl, T.; Tummescheit, H. Modeling and optimization with Optimica and JModelica.org—Languages and tools for solving large-scale dynamic optimization problems. Comput. Chem. Eng.
**2010**, 34, 1737–1749. [Google Scholar] - JModelica.org User Guide. Available online: http://www.jmodelica.org/page/236 accessed on 16 June 2015.
- Fritzson, P. Principles of Object-Oriented Modeling and Simulation with Modelica 2.1; Wiley-IEEE Press: Piscataway, NJ, USA, 2004. [Google Scholar]
- Åkesson,, J. Optimica—An Extension of Modelica Supporting Dynamic Optimization, Proceedings of the 6th International Modelica Conference, Bielefeld, Germany, 3–4 March 2008.
- Wächter, A.; Biegler, L.T. On the implementation of a primal-dual interior point filter line search algorithm for large-scale nonlinear programming. Math. Program.
**2006**, 106, 25–57. [Google Scholar] - Büskens, C.; Wassel, D. The ESA NLP Solver WORHP. In Modeling and Optimization in Space Engineering; Fasano, G., Pintér, J.D., Eds.; Springer: New York, NY, USA, 2013; Volume 73, pp. 85–110. [Google Scholar]
- Liberzon, D. Calculus of Variations and Optimal Control Theory: A Concise Introduction; Princeton University Press: Princeton, NJ, USA, 2012. [Google Scholar]
- Betts, J.T. Practical Methods for Optimal Control and Estimation Using Nonlinear Programming, 2nd ed; Society for Industrial and Applied Mathematics: Philadelphia, PA, USA, 2010. [Google Scholar]
- Bertsekas, D.P. Dynamic Programming and Optimal Control, 3rd ed; Athena Scientific: Belmont, MA, USA, 2005; Volume 1. [Google Scholar]
- Betts, J.T. Survey of numerical methods for trajectory optimization. J. Guid. Contr. Dynam.
**1998**, 21, 193–207. [Google Scholar] - Rao, A.V. A Survey of Numerical Methods for Optimal Control, Proceedings of the 2009 AAS/AIAA Astrodynamics Specialists Conference, Pittsburgh, PA, USA, 9–13 August 2009.
- Fourer, R.; Gay, D.M.; Kernighan, B.W. AMPL: A Modeling Language for Mathematical Programming; Duxbury Press Brooks Cole Publishing: Pacific Grove, CA, USA, 2003. [Google Scholar]
- Brooke, A.; Kendrick, D.A.; Meeraus, A.; Rosenthal, R.E. GAMS: A User’s Guide; Scientific Press: Redwood City, CA, USA, 1988. [Google Scholar]
- Hart, W.E.; Laird, C.; Watson, J.P.; Woodruff, D.L. Pyomo – Optimization Modeling in Python; Springer: Berlin, Germany, 2012. [Google Scholar]
- Houska, B.; Ferreau, H.J.; Diehl, M. ACADO toolkit—An open-source framework for automatic control and dynamic optimization. Optimal Control Appl. Methods
**2011**, 32, 298–312. [Google Scholar] - Tomlab Optimization. PROPT. Available online: http://tomdyn.com accessed on 16 June 2015.
- Holmström, K. The TOMLAB Optimization Environment in Matlab. Adv. Model. Optim.
**1999**, 1, 47–69. [Google Scholar] - Hedengren, J.D. APMonitor. Available online: http://apmonitor.com accessed on 16 June 2015.
- Process Systems Enterprise. gPROMS. Available online: http://www.psenterprise.com/gproms accessed on 16 June 2015.
- Bachmann, B.; Ochel, L.; Ruge, V.; Gebremedhin, M.; Fritzson, P.; Nezhadali, V.; Eriksson, L.; Sivertsson, M. Parallel Multiple-Shooting and Collocation Optimization with OpenModelica, Proceedings of the 9th International Modelica Conference, Munich, Germany, 3–5 September 2012.
- Pytlak, R.; Tarnawski, T.; Fajdek, B.; Stachura, M. Interactive dynamic optimization server—connecting one modelling language with many solvers. Optim. Methods Softw.
**2014**, 29, 1118–1138. [Google Scholar] - ITEA. Model Driven Physical Systems Operation. Available online: https://itea3.org/project/modrio.html accessed on 16 June 2015.
- Andersson, J. A General-Purpose Software Framework for Dynamic Optimization. Ph.D. Thesis, KU Leuven, Leuven, Belgium, October 2013. [Google Scholar]
- Andersson, J.; Åkesson, J.; Casella, F.; Diehl, M. Integration of CasADi and JModelica.org, Proceedings of the 8th International Modelica Conference, Dresden, Germany, 20–22 March 2011.
- Magnusson, F.; Åkesson, J. Collocation Methods for Optimization in a Modelica Environment, Proceedings of the 9th International Modelica Conference, Munich, Germany, 3–5 September 2012.
- Åkesson, J.; Ekman, T.; Hedin, G. Implementation of a Modelica compiler using JastAdd attribute grammars. Sci. Comput. Program.
**2010**, 75, 21–38. [Google Scholar] - Ekman, T.; Hedin, G. The JastAdd system—modular extensible compiler construction. Sci. Comput. Program.
**2007**, 69, 14–26. [Google Scholar] - Mattsson, S.E.; Söderlind, G. Index Reduction in Differential-Algebraic Equations Using Dummy Derivatives. SIAM J. Sci. Comput.
**1993**, 14, 677–692. [Google Scholar] - Lennernäs, B. A CasADi Based Toolchain for JModelica.org. M.Sc. Thesis, Lund University, Lund, Sweden, 2013. [Google Scholar]
- HSL. A collection of Fortran codes for large scale scientific computation. Available online: http://www.hsl.rl.ac.uk accessed on 16 June 2015.
- Biegler, L.T. Nonlinear Programming: Concepts, Algorithms, and Applications to Chemical Processes; Mathematical Optimization Society and the Society for Industrial and Applied Mathematics: Philadelphia, PA, USA, 2010. [Google Scholar]
- Hairer, E.; Wanner, G. Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems, 2nd ed; Springer-Verlag: Berlin, Germany, 1996. [Google Scholar]
- Rodriguez, J.S. Large-scale dynamic optimization using code generation and parallel computing. M.Sc. Thesis, KTH Royal Institute of Technology, Stockholm, Sweden, 2014. [Google Scholar]
- Magnusson, F. Collocation Methods in JModelica.org. M.Sc. Thesis, Lund University, Lund, Sweden, February 2012. [Google Scholar]
- Betts, J.T.; Huffman, W.P. Mesh refinement in direct transcription methods for optimal control. Optim. Control Appl. Methods
**1998**, 19, 1–21. [Google Scholar] - Vasantharajan, S.; Biegler, L.T. Simultaneous strategies for optimization of differential-algebraic systems with enforcement of error criteria. Comput. Chem. Eng.
**1990**, 14, 1083–1100. [Google Scholar] - JModelica.org source code. Available online: https://svn.jmodelica.org and in particular https://svn.jmodelica.org/trunk/Python/src/pyjmi/optimization/casadi_collocation.py?p=6606 accessed on 16 June 2015.
- Dassault Systèmes. Dymola. Available online: http://www.dymola.com accessed on 16 June 2015.
- Pfeiffer, A.; Bausch-Gall, I.; Otter, M. Proposal for a Standard Time Series File Format in HDF5, Proceedings of the 9th International Modelica Conference, Munich, Germany, 3–5 September 2012.
- Holmqvist, A.; Törndahl, T.; Magnusson, F.; Zimmermann, U.; Stenström, S. Dynamic parameter estimation of atomic layer deposition kinetics applied to in situ quartz crystal microbalance diagnostics. Chem. Eng. Sci.
**2014**, 111, 15–33. [Google Scholar] - De Coninck, R.; Magnusson, F.; Åkesson, J.; Helsen, L. Grey-Box Building Models for Model Order Reduction and Control, Proceedings of the 10th International Modelica Conference, Lund, Sweden, 10–12 March 2014.
- Vande Cavey, M.; De Coninck, R.; Helsen, L. Setting Up a Framework for Model Predictive Control with Moving Horizon State Estimation Using JModelica, Proceedings of the 10th International Modelica Conference, Lund, Sweden, 10–12 March 2014.
- Larsson, P.O.; Casella, F.; Magnusson, F.; Andersson, J.; Diehl, M.; Akesson, J. A Framework for Nonlinear Model-Predictive Control Using Object-Oriented Modeling with a Case Study in Power Plant Start-Up, Proceedings of the 2013 IEEE Multi-Conference on Systems and Control, Hyderabad, India, 27–30 August 2013.
- Berntorp, K.; Olofsson, B.; Lundahl, K.; Nielsen, L. Models and methodology for optimal trajectory generation in safety-critical road-vehicle manoeuvres. Veh. Syst. Dyn.
**2014**, 52, 1304–1332. [Google Scholar] - Hunter, J.D. Matplotlib: A 2D Graphics Environment. Comput. Sci. Eng.
**2007**, 9, 90–95. [Google Scholar] - Diehl, M. Real-Time Optimization for Large Scale Nonlinear Processes. Ph.D. Thesis, Heidelberg University, Heidelberg, Germany, July 2001. [Google Scholar]
- Hedengren, J.D. A Nonlinear Model Library for Dynamics and Control, 2008. Available online: http://www.hedengren.net/research/Publications/Cache_2008/NonlinearModelLibrary.pdf accessed on 16 June 2015.
- Magnusson, F.; Berntorp, K.; Olofsson, B.; Åkesson, J. Symbolic Transformations of Dynamic Optimization Problems, Proceedings of the 10th International Modelica Conference, Lund, Sweden, 10–12 March 2014.

**Figure 1.**Numerical methods for dynamic optimization. Indirect methods establish optimality conditions first and then discretize the differential equations, whereas direct methods first discretize and then optimize. Both categories of methods use essentially the same discretization techniques, of which the most common ones are single shooting, multiple shooting, and collocation.

**Figure 2.**The compilation process in JModelica.org for DOPs. The process starts with the user-provided Modelica and Optimica code and ends with a symbolic representation of the DOP in CasADi Interface, which serves as an interface between dynamic optimization algorithms and the Modelica and Optimica code.

**Figure 3.**The framework surrounding the implemented collocation framework in JModelica.org. The framework starts with a representation of the DOP in CasADi Interface generated by the compiler. The DOP is then discretized by the collocation framework into an NLP, which is solved by either IPOPT or WORHP.

**Figure 4.**Optimal control of the Van der Pol oscillator. The initial state is (0, 1) and the objective is a quadratic penalty on the state and input.

**Figure 5.**Control of a distillation column after a reflux breakdown. The vertical dashed lines mark the end of the breakdown, after which the optimal control starts. The horizontal dashed lines mark the reference values, which is the steady state before breakdown.

© 2015 by the authors; licensee MDPI, Basel, Switzerland This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Magnusson, F.; Åkesson, J.
Dynamic Optimization in JModelica.org. *Processes* **2015**, *3*, 471-496.
https://doi.org/10.3390/pr3020471

**AMA Style**

Magnusson F, Åkesson J.
Dynamic Optimization in JModelica.org. *Processes*. 2015; 3(2):471-496.
https://doi.org/10.3390/pr3020471

**Chicago/Turabian Style**

Magnusson, Fredrik, and Johan Åkesson.
2015. "Dynamic Optimization in JModelica.org" *Processes* 3, no. 2: 471-496.
https://doi.org/10.3390/pr3020471