Professional Documents
Culture Documents
Paper presented at the 4th International Modelica Conference, March 7-8, 2005,
Hamburg University of Technology, Hamburg-Harburg, Germany,
organized by The Modelica Association and the Department of Thermodynamics, Hamburg University
of Technology
Program Committee
Local Organization: Gerhard Schmitz, Katrin Prölß, Wilson Casas, Henning Knigge, Jens Vasel, Stefan
Wischhusen, TuTech Innovation GmbH
SCICOS: a general purpose modeling and simulation environment
Abstract
Partial support for Modelica is now provided by the
general purpose dynamical system simulator Scicos.
In particular it is now possible to use component mod-
els in Scicos diagrams where the dynamics of the com-
ponent has been described in Modelica. This paper
presents this new extension of Scicos.
KEYWORDS: Dynamic system simulation; Simulation
software; Component level modeling; Scilab; Model-
ica
Modelica to C translator
blocks, Scicos groups all implicit blocks into a single Objective Caml and included in the Scilab distribution.
one may use it like an ordinary compiler e.g., like a C Modelica file
compiler. By default, modelicac comes with a module Modelica generated by scicos
that generates C code for the Scilab target. However, Libraries *.mo
The following tasks are fulfilled by modelicac to sim- 4. Finding strongly connected components in the re-
plify and generate a C source file from a Modelica sulting oriented graph (using Tarjan’s algorithm
source code and library object code files: for instance)
Obtaining a flat model by replacing an aggrega-
tion of sub-models by the set of all their variables 5. Sorting the resulting nodes in a topological order.
and equations merged together and replacing connec-
Each strongly connected component represents a sub-
tion equations by ordinary equations. Symbolic ma-
nipulations in modelicac are performed using classical system of the whole system and it is now possible to
acyclic graph manipulation techniques perform symbolic simplification steps in order to re-
duce the number of variables in the system.
Simplification of trivial or unnecessary equations us-
ing symbolic manipulations e.g. in the following sys-
tem 3.4.2 Modelicac simplification strategy
cos x sin y 0 Symbolic simplifications typically involve variants of
cos x
sin y 0 the Gauss method (to solve linear systems) and sim-
z
x
y 0 ple symbolic simplification methods based on a set of
f x y z v
0 predetermined patterns (for efficiency reasons) to try
to solve the remaining equations. In modelicac we fo-
the first two equations are fully non-linear and only cused on the second class of simplification methods.
the numerical solver can solve the system for x and y. The problem when trying to solve a set of non-linear
But the third equation is trivial and z can be obtained equations is to determine a coupling in the bipartite
in terms of x and y, so in the rest of equations z is graph described above that triggers as many simpli-
replaced by x y. Most of the variables used to con- fications as possible. So the Ford and Fulkerson (or
nect Modelica components (”connection variables”), equivalent) method is not enough for our purposes: in-
are eliminated in this way. stead of taking the first encountered coupling, we want
Causality analysis, i.e. computation of system’s Ja- in addition that the coupling satisfy a given criterion
cobian matrix. It will be explained further. (e.g. maximizing the potential number of simplifica-
tions in the system). Hence the use of a variant of the
3.4.1 Causality analysis Hungarian method which can be seen in modelicac as
a method for finding a coupling based on an additional
Causality analysis performs a few operations in order constraint called the ”satisfaction”. Practically, that is
to find the so-called ”strongly connected components” done in modelicac by associating a set of pairs (vari-
of a system of equations viewed as a directed bipartite able, weight) with each equation: given an equation,
graph [13]: each weight indicates whether the equation is ”easy” to
solve with respect to its associated variable or not. For
1. Constructing a bipartite graph whose nodes on instance, if an equation contains only one variable, the
the left represent variables in the system and weight associated with that variable is low whereas the
number of zero-crossings = 0
I/O direct dependency = false
*/
#include <math.h>
#include <scicos/scicos_block.h>
if (flag == 0) {
tion and invokes modelicac to convert Modelica code res[0] = x[1]-xd[0]*rpar[0];
into C code. In Fig. 9 there is a model of an electrical res[1] = x[0]+xd[1]*rpar[1]-x[2];
v1=get_scicos_time();
circuit modeled in Scicos. Here is its Modelica class res[2] = x[1]+x[2]*rpar[3]+sin(6.28318530718*v1*rpar[4])*u[0][0];
} else if (flag == 1) {
automatically generated by Scicos: if (get_phase_simulation() == 1) {
y[0][0] = x[1]; /* main.B8.vo */
y[1][0] = -x[2]; /* main.B9.vo */
} else {
class imppart_rlc y[0][0] = x[1]; /* main.B8.vo */
y[1][0] = -x[2]; /* main.B9.vo */
parameter Real P1=0.0001; }
parameter Real P2=0.1; } else if (flag == 2 && nevprt < 0) {
} else if (flag == 4) {
parameter Real P3=25.0; x[0] = 0.0; /* main.B1.i */
x[1] = rpar[2]; /* main.B2.v */
parameter Real P4=0.2; x[2] = 0.0; /* main.B6.p.i */
parameter Real P5=50.0; Set_Jacobian_flag(1);
} else if (flag == 6) {
Inductor B1(L=P1); } else if (flag == 7) {
property[0] = 1; /* main.B1.i (state variable) */
Capacitor B2(C=P2, v(start=P3)); property[1] = 1; /* main.B2.v (state variable) */
property[2] = -1; /* main.B6.p.i (algebraic variable) */
Ground B3; set_pointer_xproperty(property);
VoltageSensor B4; } else if (flag == 9) {
} else if (flag == 10) {
CurrentSensor B5; v0 = Get_Jacobian_parameter();
res[0] = -rpar[0]*v0;
Resistor B6(R=P4); res[1] = 1.0;
VVsourceAC B7(f=P5); res[2] = 0.0;
res[3] = 1.0;
OutPutPort B8; res[4] = rpar[1]*v0;
res[5] = 1.0;
OutPutPort B9; res[6] = 0.0;
res[7] = -1.0;
InPutPort B10; res[8] = rpar[3];
equation res[9] = 0.0;
res[10] = 0.0;
connect (B5.p,B3.p); res[11] = sin(6.28318530718*get_scicos_time()*rpar[4])
res[12] = 0.0;
connect (B7.p,B3.p); res[13] = 0.0;
connect (B2.p,B1.p); res[14] = 1.0;
res[15] = 0.0;
connect (B4.p,B1.p); res[16] = 0.0;
res[17] = -1.0;
connect (B6.n,B1.p); res[18] = 0.0;
res[19] = 0.0;
connect (B2.n,B1.n); set_block_error(0);
connect (B4.n,B1.n); }
return;
connect (B5.n,B1.n); }
connect (B7.n,B6.p);
B4.v = B8.vi;
B5.i = B9.vi;
B10.vo = B7.VA;
Conclusion
end imppart_rlc;
The use of Modelica in Scicos provides a versatile
For this model modelicac generates a C code. This C modeling and simulation tool.
code is incrementally linked with Scicos to be used as
a standard block.
/*
References
number of discrete variables = 0
number of variables = 3
number of inputs = 1 [1] C. Bunks, J. P. Chancelier, F. Delebecque, C.
number of outputs = 2
number of modes = 0 Gomez(ed.), M. Goursat, R. Nikoukhah and
[4] R. Nikoukhah and S. Steer, Hybrid systems: [15] R. N IKOUKHAH AND S. S TEER , ”C ONDI -
modeling and simulation, COSY: M ATHEMAT- TIONING IN HYBRID SYSTEM FORMALISM ”,
ICAL M ODELLING OF C OMPLEX S YSTEM, International Conference Automation of Mixed
Lund, Sweden, Sept. 1996. Processes:A D P M Hybrid Dynamic Systems,
D ORTMUND , G ERMANY, 2000.
[5] A. Benveniste, Compositional and Uniform
Modeling of Hybrid Systems, IEEE Trans. Au- [16] W EIS , P IERRE , L EROY, X AVIER , Le Langage
tomat. Control, AC-43, 1998. CAML, 2 ND ED , D UNOD P RESS , 1999
[6] R. Nikoukhah and S. Steer, Scicos: A Dynamic
System Builder and Simulator, User’s Guide -
Version 1.0, INRIA Technical Report, RT-0207,
June 1997.