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:
[table sort=”desc,asc”]
Name, Description
,parameter a
,parameter A
,parameter b
,parameter B
,additional value s (new)
,value x
,value y
[/table]
Indices:
[table sort=”desc,asc”]
Name, Description
,index of
1..N (new)
[/table]
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:
[table sort=”desc,asc”]
Name, Description
,mean value
,value one
,value two
[/table]
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 Functions and press [Add Function]
- Take a look at the new dialog window named Add Function Usage.
- In this dialog press [Select] on the upper right hand side and choose the function you created and stored during the previous steps. The field Preview should now display the function (4).
- On the left hand side of the dialog you see the Output Naming and the Input Namings 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 applied namings.
- On the right hand side of the dialog there is a section called Applications (Function Calls) that contains the tables Output Variable, Input Variables, and Parameters.
- Press [Add Application] to create a new function application.
- Take a look at the new dialog window called Edit Function Appliance
- In this dialog double click the field Applied Naming or click [Edit Output] below that field. This opens another dialog where you can enter the naming of the output variable in the equation system.
- Enter y_{i} into the Tex Expression area and press [Render] and then [OK].
- Double click into the table row of the variable naming o or select this row and click [Edit Input]. Again a dialog is shown where a variable naming can be entered.
- Enter a_{i} into the Tex Expression area and press [Render] and then [OK].
- In the same way specify b_{i} as the applied naming for p.
- Press [OK] in the Edit Function Appliance dialog.
- In the Edit Function Usage dialog the new function appliance should now be shown in the tables in the Applications section.
- Press [OK] in the Edit Function Usage dialog.
- Save the equation system.
Evaluating the equation system
- Go to the Simulation Bar.
- Select the tab Equation System and load the equation system created in the previous steps.
- In the tab Indexing specify the index maximum value for i as 2 (by entering it into the cell Max Val).
- Activate the tab Instantiated System. You will see four equations in the sub tab Equations, 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
.
- Go to the sub tab Functions 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.
- Select the tab Specification and then Variable Specification. You will find that the variables named
and
have been automatically classified as 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 Evaluation, click [Generate Code] and then [Evaluate].
- Have a look at the output of the solver given in the tab Results.