Stefan Kuntsche, Sanam Sabeti Adibpour

This tutorial introduces the use of indices in function appliances. It is recommended that you work through the previous tutorial first.

Equation system

Equations

(1)

(2)

Function

(3)

Notation ‘nota x’

Base Names:

Name | Description |
---|---|

parameter a | |

parameter A | |

parameter b | |

parameter B | |

additional value s (new) | |

value x | |

value y |

Indices:

Name | Description |
---|---|

index of 1..N (new) |

Problem description

Maximum value:

Design variables and the corresponding values

Iteration variables and initialization values

Expected results

The following general function will be used:

Function ‘mean value’

(4)

Notation ‘nota mean value’

Base Names:

Name | Description |
---|---|

mean value | |

value one | |

value two |

**Creating the equations** The equations are created as usual (see section *Basics*). The basic work flow for this is:

- Create and store the notation as it is given above for the equations. If you have just done the tutorial part
*Use of Functions I*you may extend the equation you created there and use it here. Otherwise, create a new notation and enter the symbols specified below ‘nota_x’ into it. - Create and store the equations (1) and (2) using the above notation.

**Creating the function **First the general function (4) must be created. This general function will be used to reflect relation (3). If you have done the tutorial part *Use of Functions I* you may use the function created there. Otherwise follow the instructions given there to create the function.

**Creating the equation system** For detailed help see section Basics. The basic work flow is:

- Add the notation, here you should use the same notation as you did for the equations (‘nota x’).
- Add the equations created in the previous steps.

**Adding and applying the function** To use the general function created above, it must be added to the equation system and applied to the variables concerned. In this context, applying means specifying which variable names in the equation system are supposed to be the corresponding input and output variables. In this example the applied variables contain indices. MOSAICmodeling can deal with indexed expressions and during the evaluation of the equation system the function is applied for every instance of the index.

- Open the Equation System in the Model Bar.
- Activate the tab
and press**Functions****[Add Function]** - Take a look at the new dialog window named
.**Add Function Usage** - In this dialog press
on the upper right hand side and choose the function you created and stored during the previous steps. The field**[Select]**should now display the function (4).**Preview** - On the left hand side of the dialog you see the
and the**Output Naming**as they are defined in the function. The latter are will be linked to the desired variable names as they appear in the equation system, the so called**Input Namings***applied namings*. - On the right hand side of the dialog there is a section called
that contains the tables**Applications (Function Calls)**,**Output Variable**, and**Input Variables****Parameters.** - Press
to create a new function application.**[Add Application]** - Take a look at the new dialog window called
**Edit Function Appliance** - In this dialog double click the field
or click**Applied Naming**below that field. This opens another dialog where you can enter the naming of the output variable in the equation system.**[Edit Output]** - Enter y_{i} into the
area and press**Tex Expression**and then**[Render]**.**[OK]** - Double click into the table row of the variable naming o or select this row and click
. Again a dialog is shown where a variable naming can be entered.**[Edit Input]** - Enter a_{i} into the
area and press**Tex Expression**and then**[Render]**.**[OK]** - In the same way specify b_{i} as the applied naming for p.
- Press
in the**[OK]**dialog.**Edit Function Appliance** - In the
dialog the new function appliance should now be shown in the tables in the**Edit Function Usage**section.**Applications** - Press
in the**[OK]**dialog.**Edit Function Usage** - Save the equation system.

**Evaluating the equation system**

- Go to the
Bar.**Simulation** - Select the tab
and load the equation system created in the previous steps.**Equation System** - In the tab
specify the index maximum value for i as 2 (by entering it into the cell**Indexing**).**Max Val** - Activate the tab
. You will see four equations in the sub tab**Instantiated System**, two of which contain instances of . Although it is not explicitly visible here, the function has been applied according to the indices to each set of , and .**Equations** - Go to the sub tab
and select the function on the left hand side to display the function applications on the right hand side. As you can see, the function calculates the value for two different variables (, ) based on the one application for , that has been specified in the equation system editor.**Functions** - Select the tab
and then**Specification**. You will find that the variables named and have been automatically classified as**Variable Specification***calculated variables*. - Manually classify the variables , , and as design variables by moving them into the corresponding table and give them the values specified in the problem description indicated in the beginning of this section.
- Save the variable specification list
- Enter a description
- Save the evaluation/simulation
- Open the tab
, click**Evaluation**and then**[Generate Code]**.**[Evaluate]** - Have a look at the output of the solver given in the tab
.**Results**