Dynamic Optimization of Modelica Models – Language Extensions and Tools

更新时间:2023-05-19 02:07:33 阅读: 评论:0

Dynamic Optimization of Modelica Models–Language Extensions and Tools
Johan˚A kesson
Department of Automatic Control
Faculty of Engineering
Lund University
Sweden
jakesson@control.lth.
Abstract.The Modelica language is currently gaining incread inter-
est,both in industry and in academia.Modelica is an object-oriented,
general purpo modeling language,targeted at modeling of complex
physical systems.While the main usage of models developed in Mod-
elica is simulation,veral other usages emerge.Examples of such us-
刷把ages are dynamic optimization,model reduction,calibration,verification
and code generation for embedded systems.This paper reports the cur-
rent status of the JModelica project,in which an extensible,Java-bad
Modelica compiler is being developed.In addition,an extension of the
Modelica language directed towards dynamic optimization,Optimica,is
discusd.
1Introduction
High-level modeling languages are receiving incread industrial and academic interest within veral domains,such as chemical engineering,thermo-fluid sys-tems and automotive systems.One such modeling language is Modelica,[8]. Modelica is an open language,specifically targeted at multi-domain modeling and model re-u.Key features of Modelica include object oriented modeling, decla
rative equation-bad modeling,and a component model enabling acausal connections of submodels,as well as support for hybrid/discrete behaviour. The features have proven very applicable to large-scale modeling problems in variousfields.
While there exist very efficient software tools for simulation of Modelica models,tool support for static and dynamic optimization is generally weak.Fur-thermore,specification of optimization problems is not supported by Modelica. Since Modelica models reprent an increasingly important ast for many com-panies,it is of interest to investigate how Modelica models can be ud also for optimization.
This contribution gives an overview of a project,entitled JModelica,tar-geted at i)defining an extension of Modelica,Optimica,which enables high-level formulation of optimization problems,ii)developing prototype tools for translating a Modelica model and a complementary Optimica description into a
141
reprentation suited for numerical algorithms,and iii)performing ca studies demonstrating the potential of the concept.
The project integrates dynamic modeling and optimization with computer science and numerical algorithms.One of the main benefits of the suggested ap-proach is that the high-level descriptions are automatically translated into an intermediate reprentation by the compiler front-end.This intermediate rep-rentation can then be further translated to interface with different numerical algorithms.The ur is therefore relieved from the burden of managing the often cumbersome API:s of numerical algorithms.Theflexibility of the architecture also enables the ur to lect the algorithm most suitable for the problem at hand.
2Software Tools
In order to demonstrate the propod concept,prototype software tools are being developed.In esnce,the task of the software is to read the Modelica and Opti-mica source code and then translate,automatically,the model and optimization descriptions into a format which can be ud by a numerical algorithm.The core of the software is a compiler front-end,referred to as the JModelica compiler, which translates a subt of Modelica into aflat model description.In addition, an extended front-end,bad on the JModelica compiler,supporting afirst pro-totype of the Optimica extension has been developed.The extended compiler is referred to as the Optimica compiler.In addition,a back-end for generation of efficient code for dynamic optimization has been developed.
2.1Development Environment
巧虎星期天The JModelica compiler is developed using the Java-bad compiler construction tool JastAdd,[7].JastAdd is a development environment targeted at implemen-tation of the mantics of computer programming languages,and has also been explicitly designed with modular and extensible compiler construction in mind. The core concepts ud in JastAdd are object orientation,static aspect orienta-tion,and reference attributed grammars[6].
雅虎首页The JastAdd system is bad on an object oriented specification of an ab-stract grammar(AG),from which standard Java class are generated.Seman-tic behaviour is added in aspects,which are uful for organizing cross-cutting behaviour.It is natural to structure the implementation of different mantic functions,such as name analysis(the task of binding identifiers to declarations) and type putation of the types of expressions),into parate modules.However,since the implementation of,for example,name analysis,typ-ically affects a large number of class,the object-oriented paradigm does not inherently offer support for this kind of modularization.In JastAdd,this prob-lem is overcome by allowing definition of behaviour,in the form of inter-type declarations,in parate aspects,which are then woven into the AG class.The
142
resulting class contain only Java code,and can be compiled by a standard Java compiler.
The choice of JastAdd is natural in this project,since its main focus is extensions of the Modelica language.In particular,the methodology adopted by JastAdd enables the implementations of the core language compiler and the extensions to be parated.It is then possible to build the core compiler alone, or with one or more extensions.As a notable example,a full Java1.4compiler, and a fully modular extension to also support Java1.5have been implemented in JastAdd,[3].For an overview of the JModelica compiler implementation, including some performance benchmarks,e[1].
2.2Code Generation to AMPL
Currently,the front-end of the JModelica/Optimica compiler supports a sub-t of Modelica and a basic version of Optimica.In addition,a code-generation back-end for AMPL,[4],has been developed.AMPL is a language intended for formulation of algebraic optimization problems.Accordingly,the compiler performs automatic transcription of the original continuous-time problem into an algebraic formulation which can be encoded in AMPL.In the transcription procedure,the problem is discretized by means of a simultaneous optimization approach bad on collocation overfinite elements,e for example.,[2]for an overview.Finally,the automatically generate
经典耽美文
d AMPL description may be exe-cuted and solved by a numerical NLP algorithm.For this purpo we have ud IPOPT,[9].
2.3Project Status
This paper describes the current status of the JModelica project,as of June2007. Currently,the JModelica compiler supports a limited subt of Modelica,which includes class,components,inheritance,value modifications,connect-claus and partial support for arrays.The functionality of the Optimica compiler will be described in detail in the next ction.
3Optimica
A key issue is the definition of syntax and mantics of the Modelica extension, Optimica.Optimica should provide the ur with language constructs that en-able formulation of a wide range of optimization problems,such as parameter estimation,optimal control and state estimation bad on Modelica models.
At the core of Optimica are the basic optimization elements such as cost functions and constraints.It is also possible to specify bounds on variables in the Modelica model as well as marking variables a
nd parameters as optimization ,to express what to optimize over.While this type of information reprents a canonical optimization formulation,the ur is often required to supply additional information,related to the numerical method which is ud to
143
solve the problem.In this category we ,specification of transcription method,discretization of control variables and initial guess.Optimica should also enable convenient specification of the quantities.
The current preliminary specification of the Optimica language admits for-mulation of dynamic optimization problems on the following form:
min u(t),p t f
L(x(t),u(t),p)dt+φ(x(t f))
subject to
f(˙x,x,u,p)=0
c i(x(t),u(t),p)≤0,c e(x(t),u(t),p)=0
c fe(x(t f),u(t f),p)=0,c fi(x(t f),u(t f),p)≤0
地球半径
c0e(x(0),u(0),p)=0,c0i(x(0),u(0),p)≤0
(1)
The dynamic constraint f(˙x,x,u,p)=0is expresd using Modelica,and Opti-mica is ud for everything el.
3.1The Optimica Extension
The anatomy of an Optimica description of an optimization problem is similar to a simple Modelica model,and consists of three ctions.In thefirst ction, information relevant for formulation of the optimization problem may be su-perimpod on elements in the Modelica model.For example,variable bounds and initial guess can be specified.In addition,it is possible to mark Model-ica parameters and initial conditions of dynamic variables as free optimization variables.In the cond ction,referred to as optimization,the cost function and the optimization horizon can be specified.In the third ction,referred to as subject to the constraints of the problem is given.
In the current version of Optimica,the content of a Modelica class is implic-itly assumed to be prent in the scope of an Optimica class.This is equivalent to the Optimica class extending from the corresponding Modelica class.In fu-ture versions of Optimica,this implicit assumption will be removed in favor of allowing explicit extends statements as well as component declarations in the Optimica description.
In esnce,Optimica supports four constructs:
–Superimpo information on Modelica variables.Commonly,it is de-sirable to superimpo optimization-related information on variable declara-tions in the Modelica model.For this purpo,a new construct is introduced: [oq]component_access[modification]
where the name component
an existing declaration;modifications given in this construct are merged with tho of the original declaration.In Modelica,this construct corresponds to
a redeclare modification,which may change the prefix of a variable as well
as add modifications.This new construct can therefore be viewed as a sim-
plified and shorthand alias for a redeclare modification.The introduction of
a new language construct is motivated by the need for a compact and effi-cient way to superimpo information on variables,without having to u the more involved component redeclaration mechanism.In addition,the current version of Optimica does not support component declarations,which makes the propod construct convenient.
Bounds on variables,both inputs and states,and parameters can be ex-presd using the construct
[oq]varName(lowerBound=-1,upperBound=1);
where varName refers to a variable or parameter in the Modelica model.The optional prefix oq(Optimization Quantity)is ud to let a Modelica param-eter or variable be free in the optimization.The effect of using the oq prefix
for a variable is that the binding expression,if any,of the corresponding declaration is removed.
It is also possible to specify an initial guess for a variable or parameter in Optimica:
varName(lowerBound=-1,upperBound=1,initialGuess=0);
The initial guess is a constant expression,which is ud to initialize variables and optimization parameters.If an initial guessfile is supplied upon com-pilation,the initial guess in the Optimica description has priority over the one in thefile.Also notice that the initial guess has no effect for a Modelica parameter if the oq prefix is not specified.
It is also possible to specify bounds and initial guess for derivatives of vari-ables:
der(varName)(lowerBound=-1,upperBound=1,initalGuess=0.3);
Dynamic variables by default havefixed initial conditions,specified by the start-attribute given in the corresponding Modelica variable declaration.The following construct enables free initial conditions:
varName(freeInitial(lowerBound=[-0.01;-0.001;-0.01;-0.001],
upperBound=[0.01;0.001;0.01;0.001],
initialGuess=[0.001;0;0;0])=true);
where there the variable varName in this ca is an array variable.Notice that upper and lower bound as well as initial guess(optional)for the variable can be given in the same construct:
varName(lowerBound=-3,upperBound=3,initialGuess=1,
freeInitial(lowerBound=-2,upperBound=2,initialGuess=0)=true);
145
–Specification of grid.The solution of the optimization problem is defined
on a grid,consisting of a number of time points.The accuracy(and usually
execution time)is incread if a grid with more points is ud.Due to the
nature of the transcription scheme ud in the Optimica compiler,it is more
natural to specify the number of elements of the grid.The number of points
is then given by three times the number of elements,since a third order
collocation method is ud.A grid withfixedfinal time is specified by the
construct
grid(finalTime=fixedFinalTime(finalTime=tf),nbrElements=n_el);
机械工程制图and a grid with freefinal time is specified by
grid(finalTime=openFinalTime(initialGuess=tf_ig,lowerBound=tf_lb,
天的组词upperBound=tf_ub),nbrElements=n_el);
By specifying a freefinal time,it is possible to formulate minimum time
problems.
A static optimization problem is defined by using the construct:
grid(static=true);
In this ca,all der-operators in the model are replaced by zero.
Notice that the grid construct must reside in an optimization ction.
权威英语
–Definition of cost function.The cost function is specified in the optimization ction using the construct
minimize(lagrangeIntegrand=li_exp,terminalCost=tc_exp);
The argument lagrangeIntegrand corresponds to the integrand expression
in the Lagrange cost function,L and terminalCost corresponds toφ.
–Specification of constraints In the subject to ction,path,initial and
terminal constraints can be specified.A terminal constraint is introduced
using the prefix terminal and an initial constraint is introduced by the
prefix initial.Examples of constraints are
y<=x^2;//Path constraint
initial cos(x)>=0.4//Initial constraint
terminal y=4;//Terminal constraint
3.22D Double Integrator Example
Consider the following model of a two dimensional double integrator:
¨x(t)=u x(t)
(2)
¨y(t)=u y(t)
We would like tofind trajectories that transfer the state of the system from (−1.5,0)to(1.5,0)in shortest possible time.In addition,we would like to impo
146

本文发布于:2023-05-19 02:07:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/688820.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:地球   机械工程   半径   制图
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图