Modeling and Simulation of Differential Equations in Scicos

Modeling and Simulation of Differential Equations in Scicos

Modeling and Simulation of Differential Equations in Scicos Modeling and simulation of differential equations in Scicos Masoud Najafi Ramine Nikoukhah INRIA-Rocquencourt, Domaine de Voluceau, 78153, Le Chesnay Cedex France Abstract ferential Equations (ODE) or Differential Algebraic Equation (DAE) and applies an ODE or a DAE solver Block diagram method is an old approach for the mod- in order to perform a simulation. A block diagram sys- eling and simulation of differential equations. Model- tem representation can only be used to model ODEs ing and simulation of some kind of differential equa- and a special class of DAEs, while the solvers used in tions such as differential-algebraic equations (DAE) is Scicos support a larger class of DAEs [9]. In this paper cumbersome, difficult, or even impossible with this we will explain the way Scicos environment has been approach. Scicos which is a modeling and simula- developed to write and simulate a large class of differ- tion software based on Block diagram approach has re- ential equations, called hybrid differential equations. cently been developed to simulate Modelica programs. To get an idea what a Scicos model looks like, a model In this paper, it will be explained the way different of a simple control system implemented in Scicos has classes of DAE can easily be specified in Modelica and been shown in Figure 1. In Figure 1 the Clock block simulated in Scicos. Keywords: hybrid differential equations; numerical solver; simulation; Modelica; Scicos Num(s) Num(s) sinusoid −−−−− −−−−− generator 1 Introduction Den(s) Den(s) Reference Controller Plant Scilab1 is a free, and open-source software for sci- 3 entific calculation. Scicos2 is a toolbox of Scilab Feedback and provides an environment for modeling and sim- ulation of dynamical systems [6, 4]. For many ap- Figure 1: A Scicos model of a control system plications, the Scilab/Scicos environment provides an open-source alternative to Matlab/Simulink and Ma- generates a periodic activation signal (event) that acti- trixX [14, 15]. Scicos includes a graphical editor for vates the Scope block. At event times the scope reads constructing models by interconnecting blocks, repre- its input signal and displays them. senting predefined or user defined functions, a com- piler, a simulator, and code generation facilities. A Scicos block diagram is composed of blocks and con- 2 Mathematical Background nection links. A block corresponds to an operation and by interconnecting blocks through links, we can con- A differential equation expressed either by an Ordi- struct a model, or an algorithm. nary Differential Equations (ODE), i.e., The Scicos blocks represent elementary systems that ¡ ¢ £ can be used as model building blocks. They can have x˙ f x ¢ u t several inputs and outputs, continuous-time states, discrete-time states, zero-crossing functions, etc. Sci- where x˙ denotes the derivative of x, the state variables, cos allows customization with regard to incorporating with respect to the time variable t, and u is the input user C, Fortran, or Scilab codes. Scicos translates the vector variable, or by Differential Algebraic Equations block diagram model into a system of Ordinary Dif- (DAE) [2, 3, 5], i.e., ¤ ¡ 1 ¢ ¢ £ www.scilab.org x˙ f x ¢ y u t ¡ 2 (1) ¢ ¢ £ www.scicos.org 0 g x ¢ y u t The Modelica Association 177 Modelica 2006, September 4th – 5th M. Najafi, R. Nikoukhah where (1-a) is the differential part and (1-b) is the al- DASKR and LSODAR require that the system be suffi- gebraic part of the DAE. The equation set (1) is a semi- ciently smooth over an integration period. This means explicit DAE, where the differential and the algebraic that simulator must make sure to stop and reinitialize parts are decomposed. If we cast (1) in the form of the solver at each potential point of non-smoothness (discontinuity, discontinuity in the derivative, etc.) of ¡ x §¦ the ODE/DAE. These ODE/DAEs require some addi- ¢ £¥¢ 0 F z˙ ¢ z t z (2) y ¨ tional solver features, such as event detection or root finding. This system is called a fully implicit DAE. Note that if Event detection: The ability to detect the time when a ∂F is non-singular, then it is possible to formally solve discontinuity occurs, or more precisely, the time when ∂z˙ z˙ as a function of z in order to obtain an ODE. How- a function crosses some given value (by default con- ever, if it is singular, this is no longer possible and the sidered zero) is of capital importance in simulation of solution z has to satisfy certain algebraic constraints. DAEs. For this purpose, the discontinuity function is given to the solver as a zero-crossing function. When DAEs are characterized by their index. The index of a zero-crossing occurs, the solver stops the integration a DAE , e.g.,(2), is the smallest number of differenti- and returns the exact crossing time to the main pro- ation of (2) to obtain an ODE by algebraic manipula- gram. So, it is important to halt the solver and restart at tions [7]. In general, the higher the index, the greater the discontinuity point. The numerical solver can also the numerical difficulty one encounters, when trying provide the direction in which a function has crossed to integrate the DAE numerically. In a semi-explicit the zero. index-1 DAE (1), variables whose derivatives appear in DAE are called differential variables and the other ones are called algebraic, i.e., x in (1-a) is differential 2.2 Discontinuity handling in the simulator and y in (1-b) is algebraic [16, 17]. of Scicos DAEs may have discontinuities or may be variable 2.1 Numerical solvers of Scicos structure or may change at certain points in time. Such types of DAEs are called hybrid DAEs. A hybrid DAE In order to integrate differential equations or simu- is a way of describing non-smooth multi-model sys- late any model, Scicos uses two numerical solvers; tems in terms of a finite number of smooth systems. Lsodar [8, 16] and DASKR [16, 2]. Lsodar is an The idea is to divide the state space of the system into ODE solver which is used when the Scicos diagram different regions. It is assumed that the system is de- represents an ODE. If a diagram represents a DAE, scribed in terms of a single smooth DAE within each DASKR is used. DASKR is a variable step, variable region. A simple example of a multi-model DAE is: order index-1 DAE solver. The solver properties dis- ¡ ¡ ¡ © cussed here are those of DASKR and LSODAR; how- £ ¢ ¢ ¢ £ g x £ 0 f1 x˙ x u t 0 ¡ ever these properties are common to most modern (3) ¢ ¢ ¢ £ f2 x˙ x u t 0 solvers. The most important of these properties will be explained in the following subsections [11]. where the DAE has two models: the first one is on ¡ ¡ £ Consistent initial condition: Most of the problems in when g x £ 0 and the second is when the condition using standard solvers are common to both ODE and is not true. This switching may cause a discontinuity in DAE solvers. However, there is an additional difficulty the signals, so they cannot be integrated by the numeri- with the DAE case: the problem of re-initialization and cal solvers. In order to cope with this problem, the dis- finding consistent initial conditions. Simulation of an continuity should be detected and the solver be reini- ODE can be started from any initial state, but simula- tialized after the discontinuity point. To detect and lo- tion of a DAE should be started from a consistent ini- calize the discontinuity time, solvers use zero-crossing tial state. This is an additional difficulty in simulation functions that cross zero over the discontinuity point. ¡ of DAEs. For example, for (3), we use g x £ as the zero-crossing Continuity criteria for numerical solver: DASKR function [11]. and LSODAR use a variable order variable step-size For localizing the discontinuity point, the simulator as- BDF (backward differentiation formula) method to in- sociates Mode variables with each zero-crossing func- tegrate. The BDF methods normally need continuity tions in Scicos. Mode variables are used to assign in variables and their derivatives [1]. Consequently, and fix an ODE/DAE in every time interval between The Modelica Association 178 Modelica 2006, September 4th – 5th Modeling and Simulation of Differential Equations in Scicos each two discontinuities. In general, when the nu- Block diagram consists of blocks that are connected by merical solver is called, the system of equation should arrows and each block is a transducer that transforms not be changed. During integration, the zero-crossing the incoming signals to one or more output signals. functions that indicate the conditions for the model A block can represent simple arithmetic operations or change are examined by the solver. In case of any functions without memory, but also operations whose zero-crossing, the Mode variables should be updated results are dependent on previous inputs to the block, to feed another ODE/DAE to the solver. It should be i.e., with memory. Several software tools such as Sci- note that Mode variables are defined in the Scicos sim- cos, Simulink, SystemBuild, etc. use block diagram ulator and is transparent to the user. In Scicos, a Mode method to model and simulate dynamical systems. As variable is assigned systematically to each discontinu- an example the diagram in Figure 2 displays the graph- ity point, characterized by an If-then-Else block. ical representation of equation (5). 2 Scicos considers the system (3) in the following form: 1 2 -, 2 4 5 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us