codex/airfoil-edge-geometry.py

airfoil-edge-geometry.py
"""Original four-digit thickness calculation; writes opaque PNG to cwd."""
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt


def half_thickness(x, eta=.12, rear=.1015):
    return 5 * eta * (.2969*np.sqrt(x) - .1260*x - .3516*x*x + .2843*x**3 - rear*x**4)


def main():
    np.testing.assert_allclose(2*half_thickness(1.), .00252, atol=1e-14)
    np.testing.assert_allclose(half_thickness(1., rear=.1036), 0, atol=1e-14)
    assert np.isclose(1.1019 * .12**2 * .2 * 1000, 3.173472)
    assert np.isclose(2 * half_thickness(1.) * .2 * 1000, .504)
    x = (1-np.cos(np.linspace(0, np.pi, 1001)))/2
    fig, axes = plt.subplots(1, 2, figsize=(10, 3.6), dpi=100, facecolor='white', gridspec_kw={'width_ratios':[1.35, 1]})
    for ax in axes:
        y = half_thickness(x)
        ax.fill_between(x, -y, y, color='#deedf7')
        for sign in (-1, 1):
            ax.plot(x, sign*y, color='#2475ad', label='Finite trailing edge' if sign==1 else None)
            ax.plot(x, sign*half_thickness(x, rear=.1036), color='#da812a', ls='--', label='Closed-edge variant' if sign==1 else None)
        ax.axhline(0, color='#777777', lw=.7)
        ax.set(xlabel='Chordwise coordinate x/c', ylabel='Surface height y/c')
        ax.grid(alpha=.2)
    axes[0].set(xlim=(-.03, 1.03), ylim=(-.1,.12), title='Full symmetric profile (thickness ratio 0.12)')
    axes[0].annotate('Leading edge', xy=(0,0), xytext=(.1,.09), arrowprops=dict(arrowstyle='->'), fontsize=10)
    axes[0].annotate('Trailing edge', xy=(1,0), xytext=(.66,.09), arrowprops=dict(arrowstyle='->'), fontsize=10)
    axes[0].set_aspect('equal', adjustable='box')
    handles, labels = axes[0].get_legend_handles_labels()
    fig.legend(handles, labels, loc='lower center', ncol=2, fontsize=9)
    axes[1].set(xlim=(.96,1.006), ylim=(-.007,.007), title='Rear detail: terminal gap = 0.00252 c')
    axes[1].annotate('', xy=(1,.00126), xytext=(1,-.00126), arrowprops=dict(arrowstyle='<->', color='#a33232'))
    fig.tight_layout(rect=(0, .10, 1, 1))
    fig.savefig(Path.cwd()/(Path(__file__).stem+'.png'),facecolor='white')
    plt.close(fig)


if __name__=='__main__':
    main()