# Use of Basic Elements III – Orthogonal Collocation on Finite Elements

This example shows how to implement orthogonal collocation by hand in MOSAICmodeling.

### Model description

The model is fairly simple as it consists of only one differential equation:

Therein, is the differentiated variable, is a parameter, and is time. If we apply orthogonal collocation on this differential equation, we obtain

Finally, if we divide the time horizon into several finite elements, we have the following discretization. In addition, we need a equation that enforces continuity between the finite elements:

In the discretized equations, is a collocation coefficient equal to the derivative of the j-th lagrange basis polynomial at the c-th collocation point. The index marks the finite elements and is the length of the i-th finite element. Optionally, the time can also be discretized although it usually does not explicitly appear in chemical engineering applications:

### Model workflow

#### Notation

Once again, we begin by setting up the notation. Therefore, perform the following steps:

1. Go to the Notation tab in the “Model” section
3. Add the base names below by clicking on “+ Name” at the bottom, entering these names, adding a description of the variable and confirming it
4. Go to the Indicies tab and add the index below
5. Once you have added all variables and symbols, click on “Save” at the top of the editor and save your notation at a suitable location in your folder structure
##### Base names
• , collocation point
• , collocation coefficient, i.e., derivative of lagrange basis polynomial
• , parameter
• , length of finite element
• , time
• , state variable
##### Indices
• , Index of collocation points 1..NC
• , Index of finite elements 1..NI
• , Index of lagrange basis polynomials 1..NJ

The notation is available with ID 8480.

#### Equations

Go to the Equation tab. Proceed as follows:

1. Load the notation you just created
2. Add an informative description of the current equation
3. Type the first model equation in LaTeX style into the window MosaicTex. For the differential operator, you must use \diff{Var}{IndependentVariable}
4. Save the equation at a suitable location in your folder structure
5. Click on “New” at the top of the editor and repeat the steps 1 and 2
6. Enter the remaining model equations for the discretized forms and save them as well

The equations have IDs 8481, 8486, 8490, 8497, and 8492.

#### Equation systems

Now, we will combine our equations to three equation system. To this end, go to the Equation System tab and carry on as described below:

3. Go to the tab Connected Elements and click on “+ EQU/EQS” at the bottom of the editor
4. In the opening popup window, select your differential equation and confirm
5. Save your equation system with this single differential equation
6. Repeat the steps 1-5 with the single discretized equation and the discretized form with finite elements in combination with the continuity equation

The resulting three equation systems have the IDs 8482, 8487, and 8491.

### Simulation workflow

Start by going to the “Simulation” section of MOSAICmodeling.

#### Equation systems and Indexing

Here, we describe the following steps in a simultaneous way. In MOSAICmodeling, you would rather set up the simulations sequentially: go to the tab Equation System and select the first of your newly saved equation system from above. For this system, you do not have to specify and indices.

For the discretized version of the equation system, you need to specify the number of collocation points (NC = 3) and the number of lagrange basis polynomials (NJ = 3). For the discretized version on multiple finite elements, you also need to set an appropriate number of finite elements. Here, we choose NI = 5. For the latter two systems, click on Confirm Index Data to instantiate the systems.

#### Specifications and solution

Go to the tab Specifications and then select the tab Variables. For the ODE system, proceed as follows:

2. In the specification window, you can see all possible variable classifications. Select ALL VARIABLES at the top. You should now see the four variables that are part of your model
3. Change the entry in the column Type for to Design Value
4. Change the type classification of the variables to state variable.  The variable should already be classified as differential value. Your degree of freedom should now be zero
5. Assign the values given in Table 1 to the three variables
6. Save your variable specification by clicking on the “Save” button above the calculation of the degrees of freedom
7. Save your simulation by clicking on “Save” at the top of the editor

For the discretized ODE, do as follows:

2. In the specification window, you can see all possible variable classifications. Select ALL VARIABLES at the top. You should now see the four variables that are part of your model
3. Change the entry in the column Type for , , , , , and to Design Value
4. Assign the other six variables and as ITERATION_VALUE
5. Assign the values given in Table 1 to the variables
6. Save your variable specification by clicking on the “Save” button above the calculation of the degrees of freedom
7. Save your simulation by clicking on “Save” at the top of the editor

For the discretized ODE on finite elements, take the following steps: