forked from chawkiabd/Dynamic-Morphing-Wing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2D_Downward.C
218 lines (142 loc) · 8.37 KB
/
2D_Downward.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*********************************************************************/
/* UDF for 2D Downward Dynamic Morphing Flap.
Chawki Abdessemed, UWE Bristol
Up/Down = name shown in Fluent GUI
*/
/*********************************************************************/
#include "udf.h"
#define Thick 0.12 /*Airfoil thickness 12/100 in NACA 0012 */
#define FTT 0.20001 /*Time in s when the moprhing starts*/
#define chord 0.2286 /*Airfoil chord*/
DEFINE_GRID_MOTION(Up, domain, dt, time, dtime)
{
Thread *tf = DT_THREAD (dt);
face_t f;
Node *node_p;
real x, y,z,thickness,camber,theta,yupper,dy_c,x_s,xupper,W_te,T_max,Tmorph,freq;
int n;
freq = 6; /*Morphing frequency*/
Tmorph= 1/(4*freq); /*Time in s needed for the morphing*/
T_max = FTT+Tmorph; /*Flow time in s when the morphing stops*/
W_te= 0.05*chord; /*Maximum flap deflection */
x_s = 0.75*chord; /*location where the morphing starts */
/* Set/activate the deforming flag on adjacent cell zone, which */
/* means that the cells adjacent to the deforming wall will also be */
/* deformed, in order to avoid skewness. */
SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));
/* Loop over the deforming boundary zone's faces; */
/* inner loop loops over all nodes of a given face; */
/* Thus, since one node can belong to several faces, one must guard */
/* against operating on a given node more than once: */
begin_f_loop (f, tf)
{
f_node_loop (f, tf, n)
{
node_p = F_NODE (f, tf, n);
/* Update the current node only if it has not been */
/* previously visited: */
if (NODE_POS_NEED_UPDATE (node_p))
{
/* Set flag to indicate that the current node's */
/* position has been updated, so that it will not be */
/* updated during a future pass through the loop: */
NODE_POS_UPDATED (node_p);
x = NODE_X (node_p);
z = NODE_Z (node_p);
/*Airfoil thickness distribution */
thickness= (chord*Thick / 0.2) * (0.2969*sqrt(x/chord)-0.1260*x/chord-0.3516*pow((x/chord),2) + 0.2843*pow((x/chord),3)-0.1036*pow((x/chord),4));
/*Loop over the morphing portion*/
if ( x > x_s) {
/*define motion before T_MAX*/
if ( CURRENT_TIME >= FTT && CURRENT_TIME <= T_max) {
/*morphing flap*/
camber =-(W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq)*pow((x-x_s),3))/(pow((chord-x_s),3));
dy_c= (-3*W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq))*pow((x-x_s),2)/(pow((chord-x_s),3));
theta = atan(((-3*W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq))*pow((x-x_s),2)/(pow((chord-x_s),3))));
xupper = x - thickness*sin(theta);
yupper =camber + thickness*cos(theta);
NODE_Y (node_p) = yupper ;
}
/*morphing stops*/
if ( CURRENT_TIME > T_max) {
camber =-(W_te*sin(2*M_PI*Tmorph*freq)*pow((x-x_s),3))/(pow((chord-x_s),3));
dy_c= (-3*W_te*sin(2*M_PI*Tmorph*freq))*pow((x-x_s),2)/(pow((chord-x_s),3));
theta = atan(((-3*W_te*sin(2*M_PI*Tmorph*freq))*pow((x-x_s),2)/(pow((chord-x_s),3))));
xupper = x - thickness*sin(theta);
yupper =camber + thickness*cos(theta);
NODE_Y (node_p) = yupper ;
}
}
}
end_f_loop (f, tf);
}
}
}
DEFINE_GRID_MOTION(Down, domain, dt, time, dtime)
{
Thread *tf = DT_THREAD (dt);
face_t f;
Node *node_p;
real x, y,z,thickness,camber,theta,yupper,dy_c,x_s,xupper,W_te,T_max,Tmorph,freq;
int n;
freq = 6; /*Morphing frequency*/
Tmorph= 1/(4*freq); /*Time in s needed for the morphing*/
T_max = FTT+Tmorph; /*Flow time in s when the morphing stops*/
W_te= 0.05*chord; /*Maximum flap deflection */
x_s = 0.75*chord; /*location where the morphing starts */
/* Set/activate the deforming flag on adjacent cell zone, which */
/* means that the cells adjacent to the deforming wall will also be */
/* deformed, in order to avoid skewness. */
SET_DEFORMING_THREAD_FLAG (THREAD_T0 (tf));
/* Loop over the deforming boundary zone's faces; */
/* inner loop loops over all nodes of a given face; */
/* Thus, since one node can belong to several faces, one must guard */
/* against operating on a given node more than once: */
begin_f_loop (f, tf)
{
f_node_loop (f, tf, n)
{
node_p = F_NODE (f, tf, n);
/* Update the current node only if it has not been */
/* previously visited:
*/
if (NODE_POS_NEED_UPDATE (node_p))
{
/* Set flag to indicate that the current node's */
/* position has been updated, so that it will not be */
/* updated during a future pass through the loop: */
NODE_POS_UPDATED (node_p);
x = NODE_X (node_p);
z = NODE_Z (node_p);
/*Airfoil thickness distribution */
thickness= (chord*Thick / 0.2) * (0.2969*sqrt(x/chord)-0.1260*x/chord-0.3516*pow((x/chord),2) + 0.2843*pow((x/chord),3)-0.1036*pow((x/chord),4));
if ( x > x_s) {
if ( CURRENT_TIME>=FTT && CURRENT_TIME <= T_max) {
camber =-(W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq)*pow((x-x_s),3))/(pow((chord-x_s),3));
dy_c= (-3*W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq))*pow((x-x_s),2)/(pow((chord-x_s),3));
theta = atan(((-3*W_te*sin(2*M_PI*(CURRENT_TIME-FTT)*freq))*pow((x-x_s),2)/(pow((chord-x_s),3))));
slope = sin(theta);
xlower = x + thickness*slope;
lower= camber - thickness*cos(theta);
NODE_Y (node_p) = lower ;
}
if ( CURRENT_TIME >= T_max) {
camber =-(W_te*sin(2*M_PI*Tmorph*freq)*pow((x-x_s),3))/(pow((chord-x_s),3));
dy_c= (-3*W_te*sin(2*M_PI*Tmorph*freq))*pow((x-x_s),2)/(pow((chord-x_s),3));
theta = atan(((-3*W_te*sin(2*M_PI*Tmorph*freq))*pow((x-x_s),2)/(pow((chord-x_s),3))));
slope = sin(theta);
xlower = x + thickness*slope;
lower= camber - thickness*cos(theta);
NODE_Y (node_p) = lower ;
}
}
}
end_f_loop (f, tf);
}
}
}
/*********************************************************************/
/* */
/* End of the UDF. */
/* */
/*********************************************************************/