OmlCustomBlock

The behavior of this block can be user-defined in OML language.

    OmlCustomBlock

Library

Activate/CustomBlocks

Description

The OMLCustom block provides a generic interface for specifying its properties and defining its simulation function. The simulation function is specified as an OML code and stored as a block parameter. The OML code is used during simulation.

Compared to creating and using new blocks, Custom blocks have the advantage of not requiring any library management operations. But even though their look and feel may be customized to some extent (in particular by encapsulating them in a masked Super Block) Custom blocks are not always the best solution. With Custom blocks, there is no mechanism for automatically upgrading the code of Custom blocks as there is for library blocks.

The CCustomBlock block also provide the option of not including the source code of the simulation function. An OML file defining the function and its name may used as block parameters instead. If a file is not specified Twin Activate assumes that the function is already defined in the environment.

Block Simulation Function

Block simulation functions are called by the Twin Activate simulator during simulation to perform different tasks, such as updating the output or the state. Simulation functions have two arguments: block and flag. The task to be realized is specified by the argument flag. The argument block is a the block’s data structure to be passed to the APIs to get and set block data.

Block Parameter GUI

CCustomBlock block's parameter GUIs provide an interactive user interface to define block properties. You can define the number and types of inputs and outputs, the states and simulation parameters and other properties. The interface also gives access to an editor for writing the block’s simulation code.

Developing a simulation code requires a knowledge of the APIs needed to get and set block data, for example for reading block inputs and writing block outputs. The CCustomBlock block provide a utility to generate a skeleton of the simulation code by taking into account the block properties specified by the user. This significantly facilitates the development of the simulation code.

Block inputs, outputs and simulation parameters are named and the code skeleton generator takes into account this information in order to provide a code where the user, in most cases, simply needs to add instructions involving the provided names as program variables. These variables are already declared and initialized when needed.

Alternative

The MathExpression and MatrixExpression blocks should be considered before using Custom blocks since they provide even simpler ways to express the dynamical behavior of a block. They are however limited to expressing stateless dynamics: block outputs depend on block inputs alone, and the expressions support a fixed set of functions that cannot be extended by the user.

Parameters

OmlCustomBlock_0

NameLabelDescriptionData TypeValid Values

nin

Number of input ports

Number

inports

Input port parameters

Structure

inports/inrow

Row size

Cell of scalars

inports/incol

Column size

Cell of scalars

inports/it

Type

Cell of strings

'double'
'complex'
'int32'
'int16'
'int8'
'uint32'
'uint16'
'uint8'
'boolean'
'inherit'

inports/depu

Feedthrough

Cell of scalars

0
1

inports/name

Name

Cell of strings

nevin

Number of input event ports

Number

nout

Number of output ports

Number

outports

Output port parameters

Structure

outports/outrow

Row size

Cell of scalars

outports/outcol

Column size

Cell of scalars

outports/ot

Type

Cell of strings

'double'
'complex'
'int32'
'int16'
'int8'
'uint32'
'uint16'
'uint8'
'boolean'
'inherit'

outports/name

Name

Cell of strings

nevout

Number of output event ports

Number

evoutports

Initial firing values

Structure

evoutports/fir

Firing(<0 for no firing)

Cell of scalars

OmlCustomBlock_1

NameLabelDescriptionData TypeValid Values

xx

Initial continuous state

Vector

xd

Initial state derivative

Vector

z

Initial discrete state

Vector

noz

Number of initial object states

Number

ozparams

Initial object states

Structure

ozparams/oztyp

Type

Cell of strings

'double'
'complex'
'int32'
'int16'
'int8'
'uint32'
'uint16'
'uint8';
'int64'
'uint64'
'boolean'

ozparams/ozvalue

Value

Cell of matrices

ozparams/name

Name

Cell of strings

OmlCustomBlock_2

NameLabelDescriptionData TypeValid Values

rpar

Real parameters vector

Vector

ipar

Integer parameters vector

Vector

nopar

Number of object parameters

Number

oparparams

Object parameters

Structure

oparparams/opartyp

Type

Cell of strings

'double'
'complex'
'int32'
'int16'
'int8'
'uint32'
'uint16'
'uint8'
'boolean'
'int64'
'uint64'
'string'

oparparams/oparvalue

Value

oparparams/name

Name

Cell of strings

OmlCustomBlock_3

NameLabelDescriptionData TypeValid Values

inlined

Inlined OML code

Number

0
1

code

Function code

String

fcn

Function

Structure

fcn/slib

OML file path

Cell of strings

fcn/epoint

OML function name

Cell of strings

impl

Implicit block (function)

Number

0
1

OmlCustomBlock_4

NameLabelDescriptionData TypeValid Values

nmode

Number of modes

Scalar

nzcr

Number of zero-crossings

Scalar

dept

Activation mode

String

'Always
Active
mode'
'Initially
Active
mode'
'Standard
mode'

Ports

NameTypeDescriptionIO TypeNumber

Port 1

explicit

output

nout

Port 2

explicit

input

nin

Port 3

activation

input

nevin

Port 4

activation

output

nevout

Example

Several demo models are available in demo browser in folder Activate/Custom blocks/OMLCustomBlock.

See Also