Skip to content

Commit

Permalink
Merge pull request #17 from askprash/main
Browse files Browse the repository at this point in the history
clean up `wsize` part 1 of many?
  • Loading branch information
askprash authored Feb 8, 2024
2 parents 87185b6 + 214c697 commit af22732
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 57 deletions.
4 changes: 1 addition & 3 deletions docs/src/sizing/sizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ The aircraft is sized via a fixed point iteration for the design mission (`wsize
`wsize` is typically the driving script in an analysis, as is the case in the `size_aircraft!` call (as demonstrated in the [first example] (@ref firstexample)). The sizing analysis calls the various performance routines (e.g., `fusebl`, `surfw`, `cdsum`, `mission`, etc.) as shown in the [TASOPT flowchart](@ref flowchart).

```@docs
TASOPT.wsize(pari, parg, parm, para, pare,
itermax, wrlx1, wrlx2, wrlx3,
initwgt, initeng, iairf, Ldebug, printiter, saveODperf)
TASOPT.wsize(ac)
TASOPT.woper(pari, parg, parm, para, pare,
parad, pared, itermax, initeng, NPSS_PT, NPSS)
Expand Down
6 changes: 3 additions & 3 deletions src/TASOPT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function size_aircraft!(ac::aircraft; iter=35, initwgt=false, Ldebug=false,
printiter=true, saveOD=false)

Ldebug && println("Max weight iterations = $iter")
wsize(ac.pari, ac.parg, view(ac.parm, :, 1),
view(ac.para, :, :, 1), view(ac.pare, :, :, 1),
iter, 0.5, 0.9, 0.5, initwgt, 0, 1, Ldebug, printiter, saveOD)
wsize(ac, itermax = iter, initwgt = initwgt,
Ldebug = Ldebug, printiter = printiter,
saveODperf = saveOD)
end
end
12 changes: 12 additions & 0 deletions src/misc/aircraft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ struct aircraft
pare::AbstractArray{Float64}
end

function Base.getproperty(ac::aircraft, sym::Symbol)
if sym === :parad #Design para
return view(getfield(ac, :para), :, : , 1)
elseif sym === :pared #Design pare
return view(getfield(ac, :pare), :, : , 1)
elseif sym === :parmd #Design parm
return view(getfield(ac, :parm), :, 1)
else
return getfield(ac, sym)
end
end # function getproperty

function Base.summary(ac::aircraft)
println("\n----- TASOPT model summary -----")
println(ac.name)
Expand Down
90 changes: 42 additions & 48 deletions src/sizing/wsize.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Printf
"""
wsize(pari, parg, parm, para, pare,
itermax, wrlx1, wrlx2, wrlx3,
initwgt, initeng, iairf, Ldebug, printiter, saveODperf)
wsize(ac; itermax=35,
wrlx1=0.5, wrlx2=0.9, wrlx3=0.5, initwgt=false, initeng=0,
iairf=1, Ldebug=false, printiter=true, saveODperf=false)
Main weight sizing function. Calls on various sub-functions to calculate weight of fuselage, wings, tails, etc.,
and iterates until the MTOW converges to within a specified tolerance.
Expand All @@ -18,10 +18,18 @@ and iterates until the MTOW converges to within a specified tolerance.
**Outputs:**
- No explicit outputs. Computed quantities are saved to `par` arrays of `aircraft` model.
"""
function wsize(pari, parg, parm, para, pare,
itermax, wrlx1, wrlx2, wrlx3,
initwgt, initeng, iairf, Ldebug, printiter, saveODperf)

function wsize(ac; itermax=35,
wrlx1=0.5, wrlx2=0.9, wrlx3=0.5,
initwgt=false, initeng=0,
iairf=1, Ldebug=false,
printiter=true, saveODperf=false)

pari = ac.pari
parg = view(ac.parg, :)
parm = view(ac.parm, :, 1)
para = view(ac.para, :, :, 1)
pare = view(ac.pare, :, :, 1)

time_propsys = 0.0

inite1 = 0
Expand Down Expand Up @@ -64,9 +72,6 @@ function wsize(pari, parg, parm, para, pare,
ngen = parpt[ipt_ngen]
nTshaft = parpt[ipt_nTshaft]

# Atmospheric conditions at sea-level
TSL, pSL, ρSL, aSL, μSL = atmos(0.0)

# Calculate fuselage B.L. development at start of cruise: ipcruise1
time_fusebl = @elapsed fusebl!(pari, parg, para, ipcruise1)
# println("Fuse bl time = $time_fusebl")
Expand Down Expand Up @@ -269,47 +274,13 @@ function wsize(pari, parg, parm, para, pare,
rSnace = parg[igrSnace]

# set cruise-altitude atmospheric conditions
ip = ipcruise1
altkm = para[iaalt, ip] / 1000.0
T0, p0, ρ0, a0, μ0 = atmos(altkm)
Mach = para[iaMach, ip]
pare[iep0, ip] = p0
pare[ieT0, ip] = T0
pare[iea0, ip] = a0
pare[ierho0, ip] = ρ0
pare[iemu0, ip] = μ0
pare[ieM0, ip] = Mach
pare[ieu0, ip] = Mach * a0
para[iaReunit, ip] = Mach * a0 * ρ0 / μ0
set_ambient_conditions!(ac, ipcruise1)

# set takeoff-altitude atmospheric conditions
ip = iprotate
altkm = para[iaalt, ip] / 1000.0
T0, p0, ρ0, a0, μ0 = atmos(altkm)
Mach = 0.25
pare[iep0, ip] = p0
pare[ieT0, ip] = T0
pare[iea0, ip] = a0
pare[ierho0, ip] = ρ0
pare[iemu0, ip] = μ0
pare[ieM0, ip] = Mach
pare[ieu0, ip] = Mach * a0
para[iaReunit, ip] = Mach * a0 * ρ0 / μ0
set_ambient_conditions!(ac, iprotate, 0.25)

# Set atmos conditions for top of climb
ip = ipclimbn
altkm = para[iaalt, ipcruise1] / 1000.0
T0, p0, ρ0, a0, μ0 = atmos(altkm)
Mach = para[iaMach, ip]
pare[iep0, ip] = p0
pare[ieT0, ip] = T0
pare[iea0, ip] = a0
pare[ierho0, ip] = ρ0
pare[iemu0, ip] = μ0
pare[ieM0, ip] = Mach
pare[ieu0, ip] = Mach * a0
para[iaReunit, ip] = Mach * a0 * ρ0 / μ0

set_ambient_conditions!(ac, ipclimbn)

# -------------------------------------------------------
## Initial guess section [Section 3.2 of TASOPT docs]
Expand Down Expand Up @@ -1442,4 +1413,27 @@ function Wupdate!(parg, rlx, fsum)
parg[igWtesys] = WMTO * ftesys


end
end

"""
set_ambient_conditions!(ac, mis_point, Mach=NaN)
Sets ambient condition at the given mission point `mis_point`.
"""
function set_ambient_conditions!(ac, mis_point, Mach=NaN)
mis_point = mis_point
altkm = ac.parad[iaalt, mis_point]/1000.0
T0, p0, ρ0, a0, μ0 = atmos(altkm)
if Mach === NaN
Mach = ac.parad[iaMach, mis_point]
end
ac.pared[iep0, mis_point] = p0
ac.pared[ieT0, mis_point] = T0
ac.pared[iea0, mis_point] = a0
ac.pared[ierho0, mis_point] = ρ0
ac.pared[iemu0, mis_point] = μ0
ac.pared[ieM0, mis_point] = Mach
ac.pared[ieu0, mis_point] = Mach * a0
ac.parad[iaReunit, mis_point] = Mach * a0 * ρ0 / μ0

end # function set_ambient_conditions
2 changes: 1 addition & 1 deletion test/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function benchmark_drag()
wc = zeros(Float64, idim)
vnc = zeros(Float64, idim)

airfoil_section = aerodynamics.airtable(joinpath(TASOPT.__TASOPTroot__,"air/C.air"));
airfoil_section = aerodynamics.airtable(joinpath(TASOPT.__TASOPTroot__,"airfoil_data/C.air"));

clp = 0.45
toc = 0.126
Expand Down
2 changes: 0 additions & 2 deletions test/unit_test_PEMFC.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using TASOPT
using Test

@testset "PEM fuel cell" begin

Expand Down

0 comments on commit af22732

Please sign in to comment.