Alpha Controller#
This script demonstrates the implementation of a User Defined Dynamic (UDD) to dynamically adjust the angle of attack (alpha) to achieve a target lift coefficient. The example utilizes a Proportional-Integral (PI) controller logic embedded within the UDD framework. The simulation is configured for the ONERA M6 wing geometry, showcasing how UDDs can be employed for active flow control objectives.
1import flow360 as fl
2from flow360.examples import OM6wing
3
4OM6wing.get_files()
5
6project = fl.Project.from_volume_mesh(
7 OM6wing.mesh_filename, name="Tutorial UDD alpha controller from Python"
8)
9
10volume_mesh = project.volume_mesh
11
12with fl.SI_unit_system:
13 params = fl.SimulationParams(
14 reference_geometry=fl.ReferenceGeometry(
15 area=1.15315,
16 moment_center=[0, 0, 0],
17 moment_length=[1.47601, 0.80167, 1.47601],
18 ),
19 operating_condition=fl.operating_condition_from_mach_reynolds(
20 reynolds=11.72e6,
21 mach=0.84,
22 project_length_unit=0.80167 * fl.u.m,
23 temperature=297.78,
24 alpha=3.06 * fl.u.deg,
25 beta=0 * fl.u.deg,
26 ),
27 models=[
28 fl.Wall(surfaces=[volume_mesh["1"]]),
29 fl.SlipWall(surfaces=[volume_mesh["2"]]),
30 fl.Freestream(surfaces=[volume_mesh["3"]]),
31 ],
32 time_stepping=fl.Steady(
33 max_steps=2000,
34 ),
35 user_defined_dynamics=[
36 fl.UserDefinedDynamic(
37 name="alphaController",
38 input_vars=["CL"],
39 constants={"CLTarget": 0.4, "Kp": 0.2, "Ki": 0.002},
40 output_vars={"alphaAngle": "if (pseudoStep > 500) state[0]; else alphaAngle;"},
41 state_vars_initial_value=["alphaAngle", "0.0"],
42 update_law=[
43 "if (pseudoStep > 500) state[0] + Kp * (CLTarget - CL) + Ki * state[1]; else state[0];",
44 "if (pseudoStep > 500) state[1] + (CLTarget - CL); else state[1];",
45 ],
46 input_boundary_patches=[volume_mesh["1"]],
47 )
48 ],
49 outputs=[
50 fl.VolumeOutput(
51 output_fields=[
52 "vorticity",
53 "Cp",
54 "mut",
55 "qcriterion",
56 "Mach",
57 ]
58 ),
59 fl.SurfaceOutput(
60 surfaces=volume_mesh["1"],
61 output_fields=[
62 "primitiveVars",
63 "Cp",
64 "Cf",
65 "CfVec",
66 "yPlus",
67 ],
68 ),
69 ],
70 )
71
72project.run_case(params=params, name="Case of tutorial UDD alpha controller from Python")
Notes#
The
fl.UserDefinedDynamic
class is used to implement the PI controller logic for adjusting the angle of attack based on the lift coefficient.The controller aims to match the calculated lift coefficient (
CL
) with a predefined target value (CLTarget
).The control logic within the
update_law
is activated only after an initial stabilization period (pseudoStep > 500
).