.. _userDefinedDynamics: User Defined Dynamics ============================= In Flow360, users are now able to specify arbitrary dynamics. In what follows, an example for a Proportional-Integral (PI) controller and an example for Aero-Structural Interaction (ASI) are given. PI controller for angle of attack to control lift coefficient -------------------------------------------------------------------------- In this example, we add a controller to :ref:`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, :code:`alphaAngle` , is estimated. To this end, a PI controller is defined under *userDefinedDynamics* in the configuration file as: .. literalinclude:: Files/alphaController.json :linenos: The complete case configuration file can be downloaded here: `Flow360.json `_. Some of the parameters are dicussed in more detail here: 1. **dynamicsName**: This is a name selected by the user for the dynamics. The results of user-defined dynamics are saved to *udd_dynamicsName_v2.csv*. 2. **constants**: This includes a list of all the constants related to this dynamics. These constants will be used in the equations for :code:`updateLaw` and :code:`outputVars`. In the above-mentioned example, :code:`CLTarget`, :code:`Kp`, and :code:`Ki` are the target value of the lift coefficient, the proportional gain of the controller, and the integral gain of the controller, respectively. 3. **outputVars**: Each :code:`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., :code:`state[0]`). 4. **stateVarsInitialValue**: There are two state variables for this controller. The first one, :code:`state[0]`, is the angle of attack computed by the controller, and the second one, :code:`state[1]`, is the summation of error :code:`(CLTarget - CL)` over iterations. The initial values of :code:`state[0]` and :code:`state[1]` are set to :code:`alphaAngle` and :code:`0`, respectively. 5. **updateLaw**: The expressions for the state variables are specified here. The first and the second expressions correspond to equations for :code:`state[0]` and :code:`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. 6. **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 :code:`CL` is calcualted. As seen in the configuration file, the boundary name for the No-Slip boundary condition is :code:`"1"`. The following figure shows the values of lift coefficient, :code:`CL`, and angle of attack, :code:`alphaAngle`, versus the steps, :code:`pseudoStep`. As specified in the configuration file, the initial value of angle of attack is :code:`3.06`. With the specified user-defined dynamics, :code:`alphaAngle` is adjusted to a final value of :code:`4.61` so that :code:`CL = 0.4` is achieved. .. _fig1_alphaController: .. figure:: Figures/alphaControllerResults.png :scale: 35% :align: center Results of alphaController for om6Wing case study. 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. .. _fig2_flutterMotion: .. figure:: Figures/plateFlutterMotion.gif :scale: 130% :align: center Flutter motion of the plate under aerodynamic and structural forces. The userDefinedDynamics section of the case JSON is presented below: .. literalinclude:: Files/ASI.json :linenos: The complete case configuration file can be downloaded here: `Flow360.json `_. For this case the dynamics of the plate is: .. math:: :label: def_dynamics-1 \ddot{\theta} = \left[ \tau_y - K \cdot \left( \theta-\theta_0 \right) - 2\zeta\omega_N I \dot{\theta} \right]/I .. math:: :label: def_dynamics-2 \dot{\theta} -\dot{\theta}_0= \int_{0}^{t} \ddot{\theta}\left(t'\right) \, dt' .. math:: :label: def_dynamics-3 \theta -\theta_0 = \int_{0}^{t} \dot{\theta}\left(t'\right) \, dt' which cooresponds to the three :code:`updateLaw` shown above. Below is a table for the symbols and their respective physical meannings: .. table:: :widths: 25 50 +-------------------+-------------------------------------------------------------------------------+ | Symbol | Description | +===================+===============================================================================+ | :math:`\theta` | Rotation angle of the plate in radius. | +-------------------+-------------------------------------------------------------------------------+ | :math:`\tau_y` | Aerodynamic moment exerted on the plate. | +-------------------+-------------------------------------------------------------------------------+ | :math:`K` | Stiffness of the spring attached to the plate at the structural support. | +-------------------+-------------------------------------------------------------------------------+ | :math:`\zeta` | Structural damping ratio. | +-------------------+-------------------------------------------------------------------------------+ | :math:`\omega_N` | Structural natural angular frequency. | +-------------------+-------------------------------------------------------------------------------+ | :math:`I` | Structural moment of inertia. | +-------------------+-------------------------------------------------------------------------------+ In the :code:`inputVars`, the :code:`rotMomentY` is the Y component of the rotational moment by the aerodynamic force. The moment is calculated around :ref:`momentCenter `. Note that :code:`OutputVars` follows the format of :code:`VarName[slidingInterfaceName] : Relation to state variable`. In this case the name of sliding interface is :code:`plate`. :math:`\ddot{\theta}`, :math:`\dot{\theta}`, :math:`\theta`, are assigned as the first, second and third state variables, respectively.