Skip to content

Commit

Permalink
correction nested loop and typo
Browse files Browse the repository at this point in the history
  • Loading branch information
mclarke2 committed Jan 23, 2021
1 parent 329105a commit f4f58b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion trunk/SUAVE/Methods/Propulsion/electric_motor_sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def optimize_kv(io, v , omeg, etam , Q, kv_lower_bound = 0.01, Res_lower_boun

bnds = ((kv_lower_bound, kv_upper_bound), (Res_lower_bound , Res_upper_bound))

# try hard constraints to fine optimum motor parameters
# try hard constraints to find optimum motor parameters
sol = minimize(objective, [0.5, 0.1], args=(v , omeg, etam , Q , io) , method='SLSQP', bounds=bnds, tol=1e-6, constraints=hard_cons)

if sol.success == False:
Expand Down
37 changes: 25 additions & 12 deletions trunk/SUAVE/Methods/Propulsion/propeller_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,22 @@ def propeller_design(prop,number_of_stations=20):
# compute airfoil polars for airfoils
airfoil_polars = compute_airfoil_polars(a_geo, a_pol)
airfoil_cl_surs = airfoil_polars.lift_coefficient_surrogates
airfoil_cd_surs = airfoil_polars.drag_coefficient_surrogates
airfoil_cd_surs = airfoil_polars.drag_coefficient_surrogates

alpha = np.zeros_like(RE)
Cdval = np.zeros_like(RE)
# assign initial values
alpha0 = np.ones(N)*0.05

for i in range(N):
sol = root(objective, 0.05, args=(airfoil_cl_surs, RE , a_geo , a_loc, i, Cl))
AoA_soln = sol.x[0]
alpha[i] = AoA_soln
Cdval[i] = airfoil_cd_surs[a_geo[a_loc[i]]](RE[i],alpha[i],grid=False)
# solve for optimal alpha to meet design Cl target
sol = root(objective, x0 = alpha0 , args=(airfoil_cl_surs, RE , a_geo ,a_loc, Cl ,N))
alpha = sol.x

# query surrogate for sectional Cls at stations
Cdval = np.zeros_like(RE)
for j in range(len(airfoil_cd_surs)):
Cdval_af = airfoil_cd_surs[a_geo[j]](RE,alpha,grid=False)
locs = np.where(np.array(a_loc) == j )
Cdval[locs] = Cdval_af[locs]

else:
Cdval = (0.108*(Cl**4)-0.2612*(Cl**3)+0.181*(Cl**2)-0.0139*Cl+0.0278)*((50000./RE)**0.2)
alpha = Cl/(2.*np.pi)
Expand Down Expand Up @@ -288,7 +294,14 @@ def propeller_design(prop,number_of_stations=20):
return prop


def objective(x, airfoil_cl_surs, RE , a_geo ,a_loc, i, Cl ):
AoA = x[0]
Cl_residual = airfoil_cl_surs[a_geo[a_loc[i]]](RE[i],AoA,grid=False) - Cl
return Cl_residual
def objective(x, airfoil_cl_surs, RE , a_geo ,a_loc, Cl ,N):
# query surrogate for sectional Cls at stations
Cl_vals = np.zeros(N)
for j in range(len(airfoil_cl_surs)):
Cl_af = airfoil_cl_surs[a_geo[j]](RE,x,grid=False)
locs = np.where(np.array(a_loc) == j )
Cl_vals[locs] = Cl_af[locs]

# compute Cl residual
Cl_residuals = Cl_vals - Cl
return Cl_residuals

0 comments on commit f4f58b2

Please sign in to comment.