peterdsharpe / AeroSandbox

Aircraft design optimization made fast through computational graph transformations (e.g., automatic differentiation). Composable analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.
https://peterdsharpe.github.io/AeroSandbox/
MIT License
761 stars 126 forks source link

Example usage of "linear C_L model" #117

Closed pareal closed 10 months ago

pareal commented 10 months ago

Description of Proposed Feature

An example of how to call the linear C_L model in the neuralfoil.getaero functions

Alternatives I Have Considered

Searched for it in the readme and aerosandbox neuralfoil examples but could not find it

Additional Context

In addition to its neural network models, NeuralFoil also has a bonus "Linear model" that predicts lift coefficient as a purely-affine function of angle of attack. This model is well-suited for linear lifting-line or blade-element-method analyses, where the linearity can be used to solve the resulting system of equations "in one shot" as a linear solve, rather than a less-numerically-robust iterative nonlinear solve.

peterdsharpe commented 10 months ago

Hi @pareal !

This module is not directly accessible through the usual entry points (e.g., asb.Airfoil.get_aero_from_neuralfoil(), nf.get_aero_from_airfoil(), etc.).

However it is directly accessible here in the NeuralFoil source (entire model is only 94 lines, I promise it's not too scary!): Link to repo

Currently, this goes unimported in the main NeuralFoil __init__.py, but you could import it as:

import aerosandbox as asb
from neuralfoil import CL_linear_regression as model

print(
    model.get_CL(
        airfoil=asb.Airfoil("naca0012"),
        alpha=3,
        Re=1e6,
    )
)
pareal commented 10 months ago

Thank you. I'll just put a simple comparison between neuralfoil and cl model, might be useful to someone (works from jupyter notebook cell):

import aerosandbox as asb
import aerosandbox.numpy as np
import matplotlib.pyplot as plt
import aerosandbox.tools.pretty_plots as p
from neuralfoil import CL_linear_regression as model

airfoil = asb.Airfoil("n0012") #symmetrical airfoil
# airfoil = asb.Airfoil("s1210") #cambered airfoil

alpha = np.linspace(-10, 10, 181)
Re=2e6
Ma=0.3

aero=airfoil.get_aero_from_neuralfoil(
    alpha=alpha,
    Re=Re,
    mach=Ma,
    model_size="xxxlarge",
)

cl_model= model.get_CL(
        airfoil=airfoil,
        alpha=alpha,
        Re=Re,
    )

fig, ax = plt.subplots()
ax.plot(alpha,aero["CL"])
ax.plot(alpha,cl_model)