peterdsharpe / AeroSandbox

Aircraft design optimization made fast through modern automatic differentiation. Composable analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.
https://peterdsharpe.github.io/AeroSandbox/
MIT License
687 stars 111 forks source link

add docker/jupyter #58

Open scivm opened 2 years ago

scivm commented 2 years ago

I am working on creating a docker container with a set of aerospace software so analysis can be driven from a jupyter notebook.

So far I have included xfoil, avl and aerosandbox though others that fit can be added.

Sample jupyter notebook that uses aerosandbox and xfoil to create geometry for a plane, perform 2d analysis using xfoil and graph the polars.

reynolds = [10000,20000,30000,50000,100000,150000,200000,300000,500000]
polars = {}
for re in reynolds:
    xf = XFoil(
        airfoil=rg15,
        Re=re,
        max_iter=40
    )
    polars[re] = xf.alpha(np.arange(-3, 9, .25))
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import seaborn as sns

def graphPolars(polars):
    reynolds = polars.keys()
    # setup colors
    increment = 0
    palette = sns.color_palette(None, len(reynolds)).as_hex()
    for re in reynolds:
        reynolds_color[re] = palette[increment]
        increment = increment + 1

    # Initialize figure with subplots
    fig = make_subplots(
        rows=3, cols=2, vertical_spacing = 0.07, horizontal_spacing = 0.07, 
        subplot_titles=("CD Vs. CL", "alpha Vs CL", "alpha Vs CM", "xtr_upper Vs CL", "alpha Vs CL/CD")
    )

    # Add traces
    for re in reynolds:
        polar = polars[re]
        fig.add_trace(go.Scatter(x=polar['CD'], y=polar['CL'], name="Re"+str(re), legendgroup="Re" + str(re), line=dict(color=reynolds_color[re])), row=1, col=1)
        fig.add_trace(go.Scatter(x=polar['alpha'], y=polar['CL'], name="Re"+str(re), legendgroup="Re" + str(re), line=dict(color=reynolds_color[re]), showlegend=False), row=1, col=2)
        fig.add_trace(go.Scatter(x=polar['alpha'], y=polar['CM'], name="Re"+str(re), legendgroup="Re" + str(re), line=dict(color=reynolds_color[re]), showlegend=False), row=2, col=1)
        fig.add_trace(go.Scatter(x=polar['xtr_upper'], y=polar['CL'], name="Re"+str(re), legendgroup="Re" + str(re), line=dict(color=reynolds_color[re]), showlegend=False), row=2, col=2)
        fig.add_trace(go.Scatter(x=polar['alpha'], y=polar['CL']/polar['CD'], name="Re"+str(re), legendgroup="Re" + str(re), line=dict(color=reynolds_color[re]), showlegend=False), row=3, col=1)

    # Update xaxis properties
    fig.update_xaxes(title_text="CD", row=1, col=1)
    fig.update_xaxes(title_text="alpha", row=1, col=2)
    fig.update_xaxes(title_text="alpha", row=2, col=1)
    fig.update_xaxes(title_text="xtr_upper", row=2, col=2)
    fig.update_xaxes(title_text="alpha", row=3, col=1)

    # Update yaxis properties
    fig.update_yaxes(title_text="CL", row=1, col=1)
    fig.update_yaxes(title_text="CL", row=1, col=2)
    fig.update_yaxes(title_text="CM", row=2, col=1)
    fig.update_yaxes(title_text="CL", row=2, col=2)
    fig.update_yaxes(title_text="CL/CD", row=3, col=1)

    # Update title and height
    fig.update_layout(title_text="Polars", height=1200)
    return fig

polar

peterdsharpe commented 2 years ago

Hi Michael,

This looks great!

I'm off the grid for the next week or so (currently out camping), but will be able to review this when I get back.

In the meantime, I wanted to make you aware of the new aerosandbox.AVL that is available in the just-released AeroSandbox 3.1.0! It's an interface between AeroSandbox objects and AVL.

scivm commented 2 years ago

ok, will take a look and see if I can call avl from jupyter.

I also have openVsp dockerized now in a non gui mode with python api. I can display the openvsp geometry in threejs inside a jupyter notebook by converting it to stl first.

Was thinking to create a geometry importer from openVsp->Aerosandbox if no one else is looking at that. suave has a similar importer and I could modify that code. suave importer