## ModelicaAdditions.Blocks.Multiplexer

Combine and split signal connectors of type Real

### Information

This package contains components to combine and split signal connectors of type Real.

This package is not part of the Modelica standard library, because it is planned to have just one multiplexer and one demultiplexer element, once there is better support for vector connectors of unknown length in Modelica.

Main Author:
  Martin Otter
  Deutsches Zentrum für Luft und Raumfahrt e.V. (DLR)
  Institut für Robotik und Mechatronik
  Postfach 1116
  D-82230 Wessling
  Germany
  email: Martin.Otter@dlr.de

Release Notes:

- June 14, 2000 by Martin Otter:
  Realized based on an existing Dymola library of Dieter Moormann.

Copyright © 2000-2002, DLR.

The ModelicaAdditions.Blocks.Multiplexer package is free software; it can be redistributed and/or modified under the terms of the Modelica license, see the license conditions and the accompanying disclaimer in the documentation of package Modelica in file "Modelica/package.mo".

## ModelicaAdditions.Blocks.Multiplexer.ExtractSignal

Extracting signals from an input signal vector

### Information

Extract signals from the input connector and transfer them to the output connector.

The extracting scheme is given by the integer vector 'extract'. This vector specifies, which input signals are taken and in which order they are transfered to the output vector. Note, that the dimension of 'extract' has to match the number of outputs. Additionally, the dimensions of the input connector signals and the output connector signals have to be explicitly defined via the parameters 'nin' and 'nout'.

Example:

         nin = 7 "Number of inputs";
         nout = 4 "Number of outputs";
         extract[nout] = {6,3,3,2} "Extracting vector";

extracts four output signals (nout=4) from the seven elements of the input vector (nin=7):

       output no. 1 is set equal to input no. 6
       output no. 2 is set equal to input no. 3
       output no. 3 is set equal to input no. 3
       output no. 4 is set equal to input no. 2

### Parameters

Name | Default | Description
--- | --- | ---
nin | 1 | Number of inputs
nout | 1 | Number of outputs
extract[nout] | {1} | Extracting vector

### Modelica definition

    block ExtractSignal "Extracting signals from an input signal vector"
      extends Modelica.Blocks.Interfaces.MIMO;
      parameter Integer extract[nout]={1} "Extracting vector";
    equation
      for i in 1:nout loop
        y[i] = u[extract[i]];
      end for;
    end ExtractSignal;

## ModelicaAdditions.Blocks.Multiplexer.Multiplex2

Multiplexer block for two input connectors

### Information

The output connector is the concatenation of the two input connectors. Note, that the dimensions of the input connector signals have to be explicitly defined via parameters n1 and n2.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of input signal connector 1
n2 | 1 | dimension of input signal connector 2

### Modelica definition

    block Multiplex2 "Multiplexer block for two input connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of input signal connector 1";
      parameter Integer n2=1 "dimension of input signal connector 2";
      Modelica.Blocks.Interfaces.InPort inPort1(final n=n1)
        "Connector of Real input signals 1";
      Modelica.Blocks.Interfaces.InPort inPort2(final n=n2)
        "Connector of Real input signals 2";
      Modelica.Blocks.Interfaces.OutPort outPort(final n=n1 + n2)
        "Connector of Real output signals";
    equation
      [outPort.signal] = [inPort1.signal; inPort2.signal];
    end Multiplex2;

## ModelicaAdditions.Blocks.Multiplexer.Multiplex3

Multiplexer block for three input connectors

### Information

The output connector is the concatenation of the three input connectors. Note, that the dimensions of the input connector signals have to be explicitly defined via parameters n1, n2 and n3.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of input signal connector 1
n2 | 1 | dimension of input signal connector 2
n3 | 1 | dimension of input signal connector 3

### Modelica definition

    block Multiplex3 "Multiplexer block for three input connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of input signal connector 1";
      parameter Integer n2=1 "dimension of input signal connector 2";
      parameter Integer n3=1 "dimension of input signal connector 3";
      Modelica.Blocks.Interfaces.InPort inPort1(final n=n1)
        "Connector of Real input signals 1";
      Modelica.Blocks.Interfaces.InPort inPort2(final n=n2)
        "Connector of Real input signals 2";
      Modelica.Blocks.Interfaces.InPort inPort3(final n=n3)
        "Connector of Real input signals 3";
      Modelica.Blocks.Interfaces.OutPort outPort(final n=n1 + n2 + n3)
        "Connector of Real output signals";
    equation
      [outPort.signal] = [inPort1.signal; inPort2.signal; inPort3.signal];
    end Multiplex3;

## ModelicaAdditions.Blocks.Multiplexer.Multiplex4

Multiplexer block for four input connectors

### Information

The output connector is the concatenation of the four input connectors. Note, that the dimensions of the input connector signals have to be explicitly defined via parameters n1, n2, n3 and n4.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of input signal connector 1
n2 | 1 | dimension of input signal connector 2
n3 | 1 | dimension of input signal connector 3
n4 | 1 | dimension of input signal connector 4

### Modelica definition

    block Multiplex4 "Multiplexer block for four input connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of input signal connector 1";
      parameter Integer n2=1 "dimension of input signal connector 2";
      parameter Integer n3=1 "dimension of input signal connector 3";
      parameter Integer n4=1 "dimension of input signal connector 4";
      Modelica.Blocks.Interfaces.InPort inPort1(final n=n1)
        "Connector of Real input signals 1";
      Modelica.Blocks.Interfaces.InPort inPort2(final n=n2)
        "Connector of Real input signals 2";
      Modelica.Blocks.Interfaces.InPort inPort3(final n=n3)
        "Connector of Real input signals 3";
      Modelica.Blocks.Interfaces.InPort inPort4(final n=n4)
        "Connector of Real input signals 4";
      Modelica.Blocks.Interfaces.OutPort outPort(final n=n1 + n2 + n3 + n4)
        "Connector of Real output signals";
    equation
      [outPort.signal] = [inPort1.signal; inPort2.signal; inPort3.signal; inPort4.
        signal];
    end Multiplex4;

## ModelicaAdditions.Blocks.Multiplexer.Multiplex5

Multiplexer block for five input connectors

### Information

The output connector is the concatenation of the five input connectors. Note, that the dimensions of the input connector signals have to be explicitly defined via parameters n1, n2, n3, n4 and n5.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of input signal connector 1
n2 | 1 | dimension of input signal connector 2
n3 | 1 | dimension of input signal connector 3
n4 | 1 | dimension of input signal connector 4
n5 | 1 | dimension of input signal connector 5

### Modelica definition

    block Multiplex5 "Multiplexer block for five input connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of input signal connector 1";
      parameter Integer n2=1 "dimension of input signal connector 2";
      parameter Integer n3=1 "dimension of input signal connector 3";
      parameter Integer n4=1 "dimension of input signal connector 4";
      parameter Integer n5=1 "dimension of input signal connector 5";
      Modelica.Blocks.Interfaces.InPort inPort1(final n=n1)
        "Connector of Real input signals 1";
      Modelica.Blocks.Interfaces.InPort inPort2(final n=n2)
        "Connector of Real input signals 2";
      Modelica.Blocks.Interfaces.InPort inPort3(final n=n3)
        "Connector of Real input signals 3";
      Modelica.Blocks.Interfaces.InPort inPort4(final n=n4)
        "Connector of Real input signals 4";
      Modelica.Blocks.Interfaces.InPort inPort5(final n=n5)
        "Connector of Real input signals 5";
      Modelica.Blocks.Interfaces.OutPort outPort(final n=n1 + n2 + n3 + n4 + n5)
         "Connector of Real output signals";
    equation
      [outPort.signal] = [inPort1.signal; inPort2.signal; inPort3.signal; inPort4.
        signal; inPort5.signal];
    end Multiplex5;

## ModelicaAdditions.Blocks.Multiplexer.Multiplex6

Multiplexer block for six input connectors

### Information

The output connector is the concatenation of the six input connectors. Note, that the dimensions of the input connector signals have to be explicitly defined via parameters n1, n2, n3, n4, n5 and n6.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of input signal connector 1
n2 | 1 | dimension of input signal connector 2
n3 | 1 | dimension of input signal connector 3
n4 | 1 | dimension of input signal connector 4
n5 | 1 | dimension of input signal connector 5
n6 | 1 | dimension of input signal connector 6

### Modelica definition

    block Multiplex6 "Multiplexer block for six input connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of input signal connector 1";
      parameter Integer n2=1 "dimension of input signal connector 2";
      parameter Integer n3=1 "dimension of input signal connector 3";
      parameter Integer n4=1 "dimension of input signal connector 4";
      parameter Integer n5=1 "dimension of input signal connector 5";
      parameter Integer n6=1 "dimension of input signal connector 6";
      Modelica.Blocks.Interfaces.InPort inPort1(final n=n1)
        "Connector of Real input signals 1";
      Modelica.Blocks.Interfaces.InPort inPort2(final n=n2)
        "Connector of Real input signals 2";
      Modelica.Blocks.Interfaces.InPort inPort3(final n=n3)
        "Connector of Real input signals 3";
      Modelica.Blocks.Interfaces.InPort inPort4(final n=n4)
        "Connector of Real input signals 4";
      Modelica.Blocks.Interfaces.InPort inPort5(final n=n5)
        "Connector of Real input signals 5";
      Modelica.Blocks.Interfaces.InPort inPort6(final n=n6)
        "Connector of Real input signals 6";
      Modelica.Blocks.Interfaces.OutPort outPort(final n=n1 + n2 + n3 + n4 + n5
             + n6) "Connector of Real output signals";
    equation
      [outPort.signal] = [inPort1.signal; inPort2.signal; inPort3.signal; inPort4.
        signal; inPort5.signal; inPort6.signal];
    end Multiplex6;

## ModelicaAdditions.Blocks.Multiplexer.DeMultiplex2

DeMultiplexer block for two output connectors

### Information

The input connector is splitted up into two output connectors. Note, that the dimensions of the output connector signals have to be explicitly defined via parameters n1 and n2.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of output signal connector 1
n2 | 1 | dimension of output signal connector 2

### Modelica definition

    block DeMultiplex2 "DeMultiplexer block for two output connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of output signal connector 1";
      parameter Integer n2=1 "dimension of output signal connector 2";
      Modelica.Blocks.Interfaces.InPort inPort(final n=n1 + n2)
        "Connector of Real input signals";
      Modelica.Blocks.Interfaces.OutPort outPort1(final n=n1)
        "Connector of Real output signals 1";
      Modelica.Blocks.Interfaces.OutPort outPort2(final n=n2)
        "Connector of Real output signals 2";
    equation
      [inPort.signal] = [outPort1.signal; outPort2.signal];
    end DeMultiplex2;

## ModelicaAdditions.Blocks.Multiplexer.DeMultiplex3

DeMultiplexer block for three output connectors

### Information

The input connector is splitted up into three output connectors. Note, that the dimensions of the output connector signals have to be explicitly defined via parameters n1, n2 and n3.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of output signal connector 1
n2 | 1 | dimension of output signal connector 2
n3 | 1 | dimension of output signal connector 3

### Modelica definition

    block DeMultiplex3 "DeMultiplexer block for three output connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of output signal connector 1";
      parameter Integer n2=1 "dimension of output signal connector 2";
      parameter Integer n3=1 "dimension of output signal connector 3";
      Modelica.Blocks.Interfaces.InPort inPort(final n=n1 + n2 + n3)
        "Connector of Real input signals";
      Modelica.Blocks.Interfaces.OutPort outPort1(final n=n1)
        "Connector of Real output signals 1";
      Modelica.Blocks.Interfaces.OutPort outPort2(final n=n2)
        "Connector of Real output signals 2";
      Modelica.Blocks.Interfaces.OutPort outPort3(final n=n3)
        "Connector of Real output signals 3";
    equation
      [inPort.signal] = [outPort1.signal; outPort2.signal; outPort3.signal];
    end DeMultiplex3;

## ModelicaAdditions.Blocks.Multiplexer.DeMultiplex4

DeMultiplexer block for four output connectors

### Information

The input connector is splitted up into four output connectors. Note, that the dimensions of the output connector signals have to be explicitly defined via parameters n1, n2, n3 and n4.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of output signal connector 1
n2 | 1 | dimension of output signal connector 2
n3 | 1 | dimension of output signal connector 3
n4 | 1 | dimension of output signal connector 4

### Modelica definition

    block DeMultiplex4 "DeMultiplexer block for four output connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of output signal connector 1";
      parameter Integer n2=1 "dimension of output signal connector 2";
      parameter Integer n3=1 "dimension of output signal connector 3";
      parameter Integer n4=1 "dimension of output signal connector 4";
      Modelica.Blocks.Interfaces.InPort inPort(final n=n1 + n2 + n3 + n4)
        "Connector of Real input signals";
      Modelica.Blocks.Interfaces.OutPort outPort1(final n=n1)
        "Connector of Real output signals 1";
      Modelica.Blocks.Interfaces.OutPort outPort2(final n=n2)
        "Connector of Real output signals 2";
      Modelica.Blocks.Interfaces.OutPort outPort3(final n=n3)
        "Connector of Real output signals 3";
      Modelica.Blocks.Interfaces.OutPort outPort4(final n=n4)
        "Connector of Real output signals 4";
    equation
      [inPort.signal] = [outPort1.signal; outPort2.signal; outPort3.signal;
        outPort4.signal];
    end DeMultiplex4;

## ModelicaAdditions.Blocks.Multiplexer.DeMultiplex5

DeMultiplexer block for five output connectors

### Information

The input connector is splitted up into five output connectors. Note, that the dimensions of the output connector signals have to be explicitly defined via parameters n1, n2, n3, n4 and n5.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of output signal connector 1
n2 | 1 | dimension of output signal connector 2
n3 | 1 | dimension of output signal connector 3
n4 | 1 | dimension of output signal connector 4
n5 | 1 | dimension of output signal connector 5

### Modelica definition

    block DeMultiplex5 "DeMultiplexer block for five output connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of output signal connector 1";
      parameter Integer n2=1 "dimension of output signal connector 2";
      parameter Integer n3=1 "dimension of output signal connector 3";
      parameter Integer n4=1 "dimension of output signal connector 4";
      parameter Integer n5=1 "dimension of output signal connector 5";
      Modelica.Blocks.Interfaces.InPort inPort(final n=n1 + n2 + n3 + n4 + n5)
        "Connector of Real input signals";
      Modelica.Blocks.Interfaces.OutPort outPort1(final n=n1)
        "Connector of Real output signals 1";
      Modelica.Blocks.Interfaces.OutPort outPort2(final n=n2)
        "Connector of Real output signals 2";
      Modelica.Blocks.Interfaces.OutPort outPort3(final n=n3)
        "Connector of Real output signals 3";
      Modelica.Blocks.Interfaces.OutPort outPort4(final n=n4)
        "Connector of Real output signals 4";
      Modelica.Blocks.Interfaces.OutPort outPort5(final n=n5)
        "Connector of Real output signals 5";
    equation
      [inPort.signal] = [outPort1.signal; outPort2.signal; outPort3.signal;
        outPort4.signal; outPort5.signal];
    end DeMultiplex5;

## ModelicaAdditions.Blocks.Multiplexer.DeMultiplex6

DeMultiplexer block for six output connectors

### Information

The input connector is splitted up into six output connectors. Note, that the dimensions of the output connector signals have to be explicitly defined via parameters n1, n2, n3, n4, n5 and n6.

### Parameters

Name | Default | Description
--- | --- | ---
n1 | 1 | dimension of output signal connector 1
n2 | 1 | dimension of output signal connector 2
n3 | 1 | dimension of output signal connector 3
n4 | 1 | dimension of output signal connector 4
n5 | 1 | dimension of output signal connector 5
n6 | 1 | dimension of output signal connector 6

### Modelica definition

    block DeMultiplex6 "DeMultiplexer block for six output connectors"
      extends Modelica.Blocks.Interfaces.BlockIcon;
      parameter Integer n1=1 "dimension of output signal connector 1";
      parameter Integer n2=1 "dimension of output signal connector 2";
      parameter Integer n3=1 "dimension of output signal connector 3";
      parameter Integer n4=1 "dimension of output signal connector 4";
      parameter Integer n5=1 "dimension of output signal connector 5";
      parameter Integer n6=1 "dimension of output signal connector 6";
      Modelica.Blocks.Interfaces.InPort inPort(final n=n1 + n2 + n3 + n4 + n5 +
            n6) "Connector of Real input signals";
      Modelica.Blocks.Interfaces.OutPort outPort1(final n=n1)
        "Connector of Real output signals 1";
      Modelica.Blocks.Interfaces.OutPort outPort2(final n=n2)
        "Connector of Real output signals 2";
      Modelica.Blocks.Interfaces.OutPort outPort3(final n=n3)
        "Connector of Real output signals 3";
      Modelica.Blocks.Interfaces.OutPort outPort4(final n=n4)
        "Connector of Real output signals 4";
      Modelica.Blocks.Interfaces.OutPort outPort5(final n=n5)
        "Connector of Real output signals 5";
      Modelica.Blocks.Interfaces.OutPort outPort6(final n=n6)
        "Connector of Real output signals 6";
    equation
      [inPort.signal] = [outPort1.signal; outPort2.signal; outPort3.signal;
        outPort4.signal; outPort5.signal; outPort6.signal];
    end DeMultiplex6;

## ModelicaAdditions.Blocks.Multiplexer.Extractor

Extract scalar signal out of signal vector dependent on IntegerInPort index

### Information

This block extracts a scalar output signal out the vector of input signals dependent on the Integer value of the additional inPort index:

        y = u [ i(t) ] ;

with time t and i(t) = index.signal[1].

### Parameters

Name | Default | Description
--- | --- | ---
nin | 1 | Number of inputs
allowOutOfRange | false | May index be out of range
outOfRangeValue | 1e10 | Output if index out of range

### Modelica definition

    block Extractor
      "Extract scalar signal out of signal vector dependent on IntegerInPort index"

      extends Modelica.Blocks.Interfaces.MISO;

      parameter Boolean allowOutOfRange=false "May index be out of range";
      parameter Real outOfRangeValue=1e10 "Output if index out of range";

      Modelica.Blocks.Interfaces.IntegerInPort index(final n=1);
    protected
      Real k[nin];
    equation
      when {initial(),change(index.signal[1])} then
        for i in 1:nin loop
          k[i] = if index.signal[1] == i then 1 else 0;
        end for;
      end when;

      y = if not allowOutOfRange or index.signal[1] > 0 and index.signal[1] < nin
         + 1 then k*u else outOfRangeValue;
    end Extractor;