Modelica
fr - eng


ModelicaBlocks - Creating and using Modelica blocks in Scicos

Module

Modelica Blocks in Scicos

First method: Using a Modelica generic block (available in the Others palette). Using this block, you do not need writing the interfacing function for the block, just define the input/output variable names and variable types and then write the Modelica program.

Second method: Beside your Modelica program, you need to define an interfacing function for your block. In the interfacing function, the name of the joint Modelica model, input/output variable names, input/output types (explicit or implicit), as well as the dialog box for modifying the the block parameters in Scicos can be defined. Several examples of Modelica blocks are available in Electrical and Thermo-Hydraulics palettes.

Remind that, once the interfacing function built, it should be loaded in Scilab, by executing this command in Scilab:

getf("myblock.sci");

You can load your block using "add new block" item in the "Edit" menu of Scicos.

Modelica Libraries in Scicos

The Modelica model corresponding to the Scicos block is defined inside a Modelica package. The directory where Modelica packages are located should be declared with the "modelica_libs" variable. e.g., if you have defined your Modelica fiels in the MyModelicalibs, you should execute this command in Scilab to inform the Modelica compiler about the location of Modelica libraries:

modelica_libs=[modelica_libs,'MyModelicalibs']

The Modelica compiler looks for all Modelica files in the directories given by "modelica_libs" and use them for compile the main Modelica model generated by Scicos.

External Functions

You can define and use external functions in your Modelica model. External functions can be written in C or Fortran languages. In order to use an external function in a Modeli model, the Modelica function prototype defining inputs and output of the external function, the header file (*.h) of the external function, and a *.DLL (Windows) or *.SO (Unix) library are required.

Example of a Modelica function prototype:

function Optimal
   input Real x;
   input Real y;
   output Real Optimal_out;
external;
end Optimal;

Example of a header file (Optimal.h):

#include "Maths.h"
double Optimal(double x,double y);

The modelica compiler looks for required external libraries in the directories given by "modelica_libs". The user can place the Modelica model, the header file, and the libraries in a directory e.g., Mylibs and then in Scilab execute the command:

modelica_libs=[modelica_libs,'Mylibs']

Authors

Masoud Najafi INRIA