Replies: 14 comments
-
I found ""np.argmin()" doesn't support casadi. |
Beta Was this translation helpful? Give feedback.
-
Hey @Zcaic ! This is an area of active work-in-progress that I am extremely excited for! :) Previously, with XFoil-driven aerodynamics, optimizing on airfoils through the Now, with NeuralFoil, optimizing CST parameters of airfoils (i.e., airfoil shape optimization as part of a larger aircraft design optimization problem) should in theory be possible! However, the nuts and bolts of the code haven't yet been fully implemented - I imagine this will happen in the next few weeks. In the time between, you may have luck with the following steps:
Critically, Step 3 bypasses the conversion to/from a coordinate array, eliminating the This approach may need some massaging to work correctly, but in theory it should work. If you give this a shot, please let me know how it goes! I'm extremely excited to see how NeuralFoil does when stress-tested against airfoil aerodynamic shape optimization. When I have time to take a stab at this and get it working, I will post a Jupyter notebook in |
Beta Was this translation helpful? Give feedback.
-
it is my testimport aerosandbox as asb
import aerosandbox.numpy as np
from aerosandbox.geometry.airfoil.airfoil_families import get_kulfan_coordinates,get_kulfan_parameters
from neuralfoil import get_aero_from_kulfan_parameters
import logging
logging.basicConfig(level=logging.INFO,format='%(levelname)s - %(asctime)s - %(message)s...')
def track_opt(iter):
logging.info(f"optimizer state at iteration {iter}")
track_lp.append(opti.debug.value(lp))
track_up.append(opti.debug.value(up))
oriairfoil=asb.Airfoil(name='rae2822')
initcst=get_kulfan_parameters(coordinates=oriairfoil.coordinates)
opti = asb.Opti()
lp = opti.variable(init_guess=initcst['lower_weights'], upper_bound=-0.03, lower_bound=-0.5)
up = opti.variable(init_guess=initcst['upper_weights'], upper_bound=0.5, lower_bound=0.05)
mycst = dict(lower_weights=lp, upper_weights=up, TE_thickness=0, leading_edge_weight=0)
rsaero = get_aero_from_kulfan_parameters(kulfan_parameters=mycst, alpha=2, Re=6.98886e+06)
ck = -rsaero["CL"] / rsaero["CD"]
opti.minimize(ck)
track_lp=[]
track_up=[]
sol = opti.solve(callback=track_opt,verbose=False)
print(track_lp[-1])
print(track_up[-1])
print(sol.stats()['iterations']['obj'])
it seems to work sucessfully lp = np.array([-0.05640185, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03, -0.03]) # the optimal lp
up = np.array([0.13740123, 0.29148949, 0.29450211, 0.27986522, 0.5, 0.5, 0.17367956, 0.3624671]) # the optimal up
myairfoil=asb.Airfoil(coordinates=get_kulfan_coordinates(lower_weights=lp,upper_weights=up))
rsaero=myairfoil.get_aero_from_neuralfoil(alpha=2,Re=6.98886e+06)
ck=rsaero['CL']/rsaero['CD']
print(f"neuralfoil: {ck}")
xf=asb.XFoil(airfoil=myairfoil,Re=6.98886e+06)
rsaero=xf.alpha(2)
ck=rsaero['CL']/rsaero['CD']
print(f"xfoil: {ck}")
it works well although the CL/CD has a little difference between neuralfoil and xfoil |
Beta Was this translation helpful? Give feedback.
-
This is so awesome! 😄 <3% difference in L/D between NeuralFoil and XFoil after optimization is excellent to hear, and better than I was expecting. You may try supplying Great work here! |
Beta Was this translation helpful? Give feedback.
-
@peterdsharpe hello, Is it possible to use an external optimizer? |
Beta Was this translation helpful? Give feedback.
-
I use code below to get objective and gradient: import casadi as ca
import aerosandbox as asb
opti=asb.Opti()
twi=opti.variable()
...
ap=asb.AeroBuildup(
airplane=myairplane,
op_point=asb.OperatingPoint(
velocity=100,
alpha=twi
)
).run()
ck=ap['CL']/ap['CD']
f=ca.Function('ck',[twi],[ck])
dfdt=ca.Function('dfdt',[tw0],[ca.gradient(ck,twi)])
print(f(0))
print(dfdt(0)) it can work as I expect. |
Beta Was this translation helpful? Give feedback.
-
Nice work! This is exactly the right way to access the gradient. This actually reminds me that I should put together an AeroSandbox tutorial on how to connect AeroSandbox to NLOPT, for users who want to try other optimizers (e.g., gradient-free or global). Perhaps even making this a method of |
Beta Was this translation helpful? Give feedback.
-
By the way @Zcaic , Check out these two brand-new tutorials which show AeroSandbox airfoil optimization through a few examples: |
Beta Was this translation helpful? Give feedback.
-
Oh, it's a so amazing work! @peterdsharpe |
Beta Was this translation helpful? Give feedback.
-
But I am curious about what happens about optimization at high Mach. I also tried to optimize at Ma=0.8, Re=1.8e7, the optimizer ran 1000 steps and warn that optimization failed. The optimized airfoil also looks a little strange. |
Beta Was this translation helpful? Give feedback.
-
I'm glad to hear that the new tutorials are helpful! I have also noticed some weird behavior in terms of transonic airfoil optimization - it seems to behave worse than subsonic airfoil optimization. I think that this is because of a few reasons:
I won't have time for the next few weeks to work on these improvements (busy with other projects), but I hope to get around to it within the next few months. This is definitely an area where contributions would be welcome! |
Beta Was this translation helpful? Give feedback.
-
(Converting this issue to a discussion, as the initial question has been resolved and now we're exploring other fun topics) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@peterdsharpe , hello! |
Beta Was this translation helpful? Give feedback.
-
Hello, is Aerosandbox.Opti() not supported for optimization of CST parameters of airfoils?
I user opti.varibale to define get_kulfan_coordinates()'s upper_weights and lower_weights,
then use get_aero_from_neuralfoil() to get CD, then opti.minimize(CD),
but it doesn't seem to work.
Beta Was this translation helpful? Give feedback.
All reactions