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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
| import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D
def naca4_airfoil(m, p, t, num_points=100): """ Generate coordinates for a NACA 4-digit airfoil. Parameters: - m: maximum camber as fraction of chord - p: location of maximum camber as fraction of chord - t: maximum thickness as fraction of chord - num_points: number of points to generate Returns: - x_upper, y_upper: coordinates of the upper surface - x_lower, y_lower: coordinates of the lower surface """ beta = np.linspace(0, np.pi, num_points) x = 0.5 * (1 - np.cos(beta)) y_t = 5 * t * (0.2969 * np.sqrt(x) - 0.1260 * x - 0.3516 * x**2 + 0.2843 * x**3 - 0.1015 * x**4) if m == 0: x_upper = x y_upper = y_t x_lower = x y_lower = -y_t else: y_c = np.zeros_like(x) dyc_dx = np.zeros_like(x) mask = x <= p y_c[mask] = m * (x[mask] / p**2) * (2 * p - x[mask]) dyc_dx[mask] = 2 * m / p**2 * (p - x[mask]) mask = x > p y_c[mask] = m * ((1 - x[mask]) / (1 - p)**2) * (1 + x[mask] - 2 * p) dyc_dx[mask] = 2 * m / (1 - p)**2 * (p - x[mask]) theta = np.arctan(dyc_dx) x_upper = x - y_t * np.sin(theta) y_upper = y_c + y_t * np.cos(theta) x_lower = x + y_t * np.sin(theta) y_lower = y_c - y_t * np.cos(theta) return x_upper, y_upper, x_lower, y_lower
def plot_airfoil(x_upper, y_upper, x_lower, y_lower, title): """Plot an airfoil profile.""" plt.figure(figsize=(10, 6)) plt.plot(x_upper, y_upper, 'b-', label='Upper Surface') plt.plot(x_lower, y_lower, 'r-', label='Lower Surface') plt.grid(True) plt.axis('equal') plt.xlabel('x/c') plt.ylabel('y/c') plt.title(title) plt.legend() plt.show()
def calculate_lift_coefficient(alpha, camber, max_camber_pos): """ Calculate approximate lift coefficient based on thin airfoil theory. Parameters: - alpha: angle of attack in degrees - camber: maximum camber - max_camber_pos: position of maximum camber Returns: - CL: lift coefficient """ alpha_rad = np.deg2rad(alpha) CL = 2 * np.pi * alpha_rad if camber > 0: CL += np.pi * camber * (2 - 4 * max_camber_pos) return CL
def plot_lift_curve(airfoil_name, m, p, t, alpha_range): """ Plot lift curve for a given airfoil. Parameters: - airfoil_name: name for plot title - m, p, t: airfoil parameters - alpha_range: range of angles of attack to plot """ lift_coefficients = [calculate_lift_coefficient(alpha, m, p) for alpha in alpha_range] plt.figure(figsize=(10, 6)) plt.plot(alpha_range, lift_coefficients, 'b-o') plt.grid(True) plt.xlabel('Angle of Attack (degrees)') plt.ylabel('Lift Coefficient (CL)') plt.title(f'Lift Curve for {airfoil_name}') plt.axhline(y=0, color='k', linestyle='-', alpha=0.3) plt.axvline(x=0, color='k', linestyle='-', alpha=0.3) plt.show() return lift_coefficients
def study_camber_effect(): """Study the effect of camber on airfoil performance.""" camber_values = np.linspace(0, 0.06, 4) alpha = 5 max_camber_pos = 0.4 thickness = 0.12 plt.figure(figsize=(12, 8)) for m in camber_values: x_upper, y_upper, x_lower, y_lower = naca4_airfoil(m, max_camber_pos, thickness) label = f'Camber = {m:.2f}' plt.plot(x_upper, y_upper, '-', label=label) plt.plot(x_lower, y_lower, '-') plt.grid(True) plt.axis('equal') plt.xlabel('x/c') plt.ylabel('y/c') plt.title('Effect of Camber on Airfoil Shape') plt.legend() plt.show() camber_range = np.linspace(0, 0.1, 50) lift_coefficients = [calculate_lift_coefficient(alpha, m, max_camber_pos) for m in camber_range] plt.figure(figsize=(10, 6)) plt.plot(camber_range, lift_coefficients, 'b-') plt.grid(True) plt.xlabel('Maximum Camber (m)') plt.ylabel('Lift Coefficient (CL) at α = 5°') plt.title('Effect of Camber on Lift Coefficient') plt.show()
def study_thickness_effect(): """Study the effect of thickness on airfoil shape.""" thickness_values = np.linspace(0.06, 0.18, 4) camber = 0.04 max_camber_pos = 0.4 plt.figure(figsize=(12, 8)) for t in thickness_values: x_upper, y_upper, x_lower, y_lower = naca4_airfoil(camber, max_camber_pos, t) label = f'Thickness = {t:.2f}' plt.plot(x_upper, y_upper, '-', label=label) plt.plot(x_lower, y_lower, '-') plt.grid(True) plt.axis('equal') plt.xlabel('x/c') plt.ylabel('y/c') plt.title('Effect of Thickness on Airfoil Shape') plt.legend() plt.show()
def pressure_distribution(x_upper, y_upper, x_lower, y_lower, alpha=5): """ Calculate approximate pressure coefficient distribution around an airfoil. Parameters: - x_upper, y_upper, x_lower, y_lower: airfoil coordinates - alpha: angle of attack in degrees Returns: - Cp_upper, Cp_lower: pressure coefficients for upper and lower surfaces """ alpha_rad = np.deg2rad(alpha) Cp_upper = 1 - (2 * np.sin(alpha_rad + np.arctan2(np.gradient(y_upper, x_upper), 1)))**2 Cp_lower = 1 - (2 * np.sin(alpha_rad + np.arctan2(np.gradient(y_lower, x_lower), 1)))**2 return Cp_upper, Cp_lower
def plot_pressure_distribution(x_upper, y_upper, x_lower, y_lower, alpha, title): """Plot pressure coefficient distribution around an airfoil.""" Cp_upper, Cp_lower = pressure_distribution(x_upper, y_upper, x_lower, y_lower, alpha) plt.figure(figsize=(12, 6)) plt.plot(x_upper, -Cp_upper, 'b-', label='Upper Surface') plt.plot(x_lower, -Cp_lower, 'r-', label='Lower Surface') plt.grid(True) plt.xlabel('x/c') plt.ylabel('-Cp') plt.title(f'Pressure Distribution around {title} at α = {alpha}°') plt.legend() plt.gca().invert_yaxis() plt.show()
def plot_3d_pressure_flow(airfoil_name, m, p, t, alpha_range): """Create a 3D visualization of pressure distribution at different angles of attack.""" x_upper, y_upper, x_lower, y_lower = naca4_airfoil(m, p, t, num_points=50) X, Y = np.meshgrid(x_upper, alpha_range) Z = np.zeros_like(X) for i, alpha in enumerate(alpha_range): Cp_upper, _ = pressure_distribution(x_upper, y_upper, x_lower, y_lower, alpha) Z[i, :] = -Cp_upper fig = plt.figure(figsize=(12, 10)) ax = fig.add_subplot(111, projection='3d') surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=True) ax.set_xlabel('x/c') ax.set_ylabel('Angle of Attack (degrees)') ax.set_zlabel('-Cp (Pressure Coefficient)') ax.set_title(f'3D Pressure Distribution for {airfoil_name}') fig.colorbar(surf, shrink=0.5, aspect=5) plt.show()
if __name__ == "__main__": print("NACA Airfoil Analysis Example\n") m = 0.04 p = 0.4 t = 0.12 airfoil_name = f"NACA 4412" print(f"Analyzing {airfoil_name} airfoil:") print(f"- Maximum camber: {m*100}%") print(f"- Position of maximum camber: {p*100}%") print(f"- Maximum thickness: {t*100}%\n") x_upper, y_upper, x_lower, y_lower = naca4_airfoil(m, p, t) plot_airfoil(x_upper, y_upper, x_lower, y_lower, airfoil_name) alpha_range = np.linspace(-5, 15, 21) lift_coefficients = plot_lift_curve(airfoil_name, m, p, t, alpha_range) plot_pressure_distribution(x_upper, y_upper, x_lower, y_lower, 5, airfoil_name) study_camber_effect() study_thickness_effect() plot_3d_pressure_flow(airfoil_name, m, p, t, np.linspace(0, 10, 11)) print("Analysis complete!")
|