# User Defined Dynamics

## Contents

# 2.4. User Defined Dynamics#

In Flow360, users are able to specify arbitrary dynamics. This section provides an example for a Proportional-Integral (PI) controller and an example for Aero-Structural Interaction (ASI).

## 2.4.1. PI Controller for Angle of Attack to Control Lift Coefficient#

In this example, we add a controller to om6Wing case study. Based on the entries of the configuration file in this case study, the resulting value of the lift coefficient, *CL*, obtained from the simulation is ~0.26. Our objective is to add a controller to this case study such that for a given target value of *CL* (e.g., 0.4), the required angle of attack, `alphaAngle`

, is estimated. To this end, a PI controller is defined under `userDefinedDynamics`

in the configuration file as:

```
1"userDefinedDynamics": [
2 {
3 "dynamicsName": "alphaController",
4 "inputVars": [
5 "CL"
6 ],
7 "constants": {
8 "CLTarget": 0.4,
9 "Kp": 0.2,
10 "Ki": 0.002
11 },
12 "outputVars": {
13 "alphaAngle": "if (pseudoStep > 500) state[0]; else alphaAngle;"
14 },
15 "stateVarsInitialValue": [
16 "alphaAngle",
17 "0.0"
18 ],
19 "updateLaw": [
20 "if (pseudoStep > 500) state[0] + Kp * (CLTarget - CL) + Ki * state[1]; else state[0];",
21 "if (pseudoStep > 500) state[1] + (CLTarget - CL); else state[1];"
22 ],
23 "inputBoundaryPatches": [
24 "1"
25 ]
26 }
27]
```

More details for some of the parameters are explained below:

**dynamicsName**: This is a name given by the user for the dynamics. The results of user-defined dynamics are saved to “udd_dynamicsName_v2.csv”.**constants**: This includes a list of all the constants related to this UDD. These constants will be used in the equations for`updateLaw`

and`outputVars`

. In the above-mentioned example,`CLTarget`

,`Kp`

, and`Ki`

are the target value of the lift coefficient, the proportional gain of the controller, and the integral gain of the controller, respectively.**outputVars**: Each`outputVars`

consists of the variable name and the relations between the variable and the state variables. For this example, we set the output variable equal to the angle of attack calculated by the controller after the first 500 pseudoSteps (i.e.,`state[0]`

).**stateVarsInitialValue**: There are two state variables for this controller. The first one,`state[0]`

, is the angle of attack computed by the controller, and the second one,`state[1]`

, is the summation of error`(CLTarget - CL)`

over iterations. The initial values of`state[0]`

and`state[1]`

are set to`alphaAngle`

and`0`

, respectively.

The equation for the control system can be thus writen as:

where the superscript \(n\) denotes pseudo step, `alphaAngle`

(\(\alpha\)) is `state[0]`

and the integration of error (\(e\)) is `state[1]`

.

**updateLaw**: The expressions for the state variables are specified here. The first and the second expressions correspond to equations for`state[0]`

and`state[1]`

, respectively. The conditional statement forces the controller not to be run for the first 500 pseudoSteps. This ensures that the flow field is established to some extent before the controller is initialized.**inputBoundaryPatches**: The related boundary conditions for the inputs of the user-defined dynamics are specified here. In this example, the noSlipWall boundary conditions are where`CL`

is calcualted. As seen in the configuration file, the boundary name for the No-Slip boundary condition is`"1"`

.

The following figure shows the values of lift coefficient, `CL`

, and angle of attack, `alphaAngle`

, versus the steps, `pseudoStep`

. As specified in the configuration file, the initial value of angle of attack is `3.06`

. With the specified user-defined dynamics, `alphaAngle`

is adjusted to a final value of `4.61`

so that `CL = 0.4`

is achieved.

## 2.4.2. Dynamic Grid Rotation using Structural Aerodynamic Load#

In this example, we present an illustrative case where a flat plate rotates while being subjected to a rotational spring moment and damper as well as aerodynamic loads. Below is a video showing the flutter motion of the plate.

The `userDefinedDynamics`

section of the case JSON is presented below:

```
1{
2 "userDefinedDynamics": [
3 {
4 "dynamicsName": "dynamicTheta",
5 "inputVars": [
6 "rotMomentY"
7 ],
8 "constants": {
9 "I": 0.443768309310345,
10 "zeta": 4.0,
11 "K": 0.0161227107,
12 "omegaN": 0.190607889,
13 "theta0": 0.0872664626
14 },
15 "outputVars": {
16 "omegaDot[plate]": "state[0];",
17 "omega[plate]": "state[1];",
18 "theta[plate]": "state[2];"
19 },
20 "stateVarsInitialValue": [
21 "0.0",
22 "0.0",
23 "1.39626340e-01"
24 ],
25 "updateLaw": [
26 "if (pseudoStep == 0) (rotMomentY - K * ( state[2] - theta0 ) - 2 * zeta * omegaN * I *state[1] ) / I; else state[0];",
27 "if (pseudoStep == 0) state[1] + state[0] * timeStepSize; else state[1];",
28 "if (pseudoStep == 0) state[2] + state[1] * timeStepSize; else state[2];"
29 ],
30 "inputBoundaryPatches": [
31 "plateBlock/noSlipWall"
32 ]
33 }
34 ]
35}
```

For this case the dynamics of the plate are:

which cooresponds to the three `updateLaw`

arguments in the above JSON input file. The symbols are defined in the table below.

Symbol |
Description |
---|---|

\(\theta\) |
Rotation angle of the plate in radius. |

\(\tau_y\) |
Aerodynamic moment exerted on the plate. |

\(K\) |
Stiffness of the spring attached to the plate at the structural support. |

\(\zeta\) |
Structural damping ratio. |

\(\omega_N\) |
Structural natural angular frequency. |

\(I\) |
Structural moment of inertia. |

In the `inputVars`

, the `rotMomentY`

is the y-component of the rotational moment by the aerodynamic force. The moment is calculated relative to the momentCenter.

Note that `OutputVars`

follows the format of `VarName[slidingInterfaceName] : relation_to_state_variable`

. In this case, the name of sliding interface is `plate`

. The first, second and third state of rotation angle of the plate are \(\ddot{\theta}\), \(\dot{\theta}\), and \(\theta\), respectively.