-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hypersonic shape design case study
- Loading branch information
Showing
23 changed files
with
450 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import CvxLean | ||
|
||
noncomputable section | ||
|
||
namespace HypersonicShapeDesign | ||
|
||
open CvxLean Minimization Real | ||
|
||
-- Height of rectangle. | ||
variable (a : ℝ) | ||
|
||
-- Width of rectangle. | ||
variable (b : ℝ) | ||
|
||
def hypersonicShapeDesign := | ||
optimization (Δx : ℝ) | ||
minimize sqrt ((1 / Δx ^ 2) - 1) | ||
subject to | ||
h1 : 10e-6 ≤ Δx | ||
h2 : Δx ≤ 1 | ||
h3 : a * (1 / Δx) - (1 - b) * sqrt (1 - Δx ^ 2) ≤ 0 | ||
|
||
set_option trace.Meta.debug true | ||
|
||
#check Lean.Expr | ||
|
||
equivalence eqv/hypersonicShapeDesignConvex (a b : ℝ) (ha : 0 ≤ a) (hb : b < 1) : | ||
hypersonicShapeDesign a b := by | ||
pre_dcp | ||
|
||
@[optimization_param] | ||
def aₚ : ℝ := 0.05 | ||
|
||
lemma aₚ_nonneg : 0 ≤ aₚ := by | ||
unfold aₚ; norm_num | ||
|
||
@[optimization_param] | ||
def bₚ : ℝ := 0.65 | ||
|
||
lemma bₚ_lt_one : bₚ < 1 := by | ||
unfold bₚ; norm_num | ||
|
||
@[simp high] | ||
lemma one_sub_bₚ_nonpos : 0 ≤ 1 - bₚ := by | ||
unfold bₚ; norm_num | ||
|
||
solve hypersonicShapeDesignConvex aₚ bₚ aₚ_nonneg bₚ_lt_one | ||
|
||
-- Final width of wedge. | ||
def width := hypersonicShapeDesignConvex.solution | ||
|
||
#eval width | ||
|
||
-- Final height of wedge. | ||
def height := Float.sqrt (1 - width ^ 2) | ||
|
||
#eval height | ||
|
||
-- Final L/D ratio. | ||
def ldRatio := 1 / (Float.sqrt ((1 / width ^ 2) - 1)) | ||
|
||
#eval ldRatio | ||
|
||
end HypersonicShapeDesign | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import cvxpy as cp | ||
import numpy as np | ||
|
||
a = .05 # height of rectangle | ||
|
||
b = .65 # width of rectangle | ||
|
||
x = cp.Variable(pos=True) | ||
|
||
obj = cp.sqrt(cp.inv_pos(cp.square(x)) - 1) | ||
|
||
p = cp.Problem( | ||
cp.Minimize(obj), [ | ||
a * cp.inv_pos(x) - (1 - b) * cp.sqrt(1 - cp.square(x)) <= 0 | ||
]) | ||
|
||
p.solve(qcp=True, verbose=True) | ||
|
||
print('QCP Final L/D Ratio = ', 1 / obj.value) | ||
print('QCP Final width of wedge = ', x.value) | ||
print('QCP Final height of wedge = ', np.sqrt(1 - x.value ** 2)) | ||
|
||
x = cp.Variable(pos=True) | ||
|
||
obj = cp.power(x, -2) - 1 | ||
|
||
p = cp.Problem( | ||
cp.Minimize(obj), [ | ||
a * cp.inv_pos(x) - (1 - b) * cp.sqrt(1 - cp.square(x)) <= 0 | ||
]) | ||
|
||
p.solve(verbose=True) | ||
|
||
print('DCP Final L/D Ratio = ', 1 / np.sqrt(obj.value)) | ||
print('DCP Final width of wedge = ', x.value) | ||
print('DCP Final height of wedge = ', np.sqrt(1 - x.value ** 2)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.