Skip to content

Commit

Permalink
Adjust CS-step test case to not compare to implicitad_option==true
Browse files Browse the repository at this point in the history
  • Loading branch information
dingraha committed Mar 15, 2024
1 parent 393578f commit e3f712a
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -689,55 +689,65 @@ Vinf = 30.0
RPM = 2100
Omega = RPM * pi/30

function ccbladewrapper(x)

# unpack
nall = length(x)
nvec = nall - 7
n = nvec ÷ 3
import ForwardDiff
import FiniteDiff

rp = x[1:n]
chordp = x[n+1:2*n]
thetap = x[2*n+1:3*n]
Rhubp = x[3*n+1]
Rtipp = x[3*n+2]
pitchp = x[3*n+3]
preconep = x[3*n+4]
Vinfp = x[3*n+5]
Omegap = x[3*n+6]
rhop = x[3*n+7]
J_no_implicitad = nothing
for implicitad_option in (false, true)

rotor = Rotor(Rhubp, Rtipp, B; turbine=turbine, precone=preconep)
sections = Section.(rp, chordp, thetap, airfoils)
ops = simple_op.(Vinfp, Omegap, rp, rhop; pitch=pitchp)
function ccbladewrapper(x)

# unpack
nall = length(x)
nvec = nall - 7
n = nvec ÷ 3

outputs = solve.(Ref(rotor), sections, ops)
rp = x[1:n]
chordp = x[n+1:2*n]
thetap = x[2*n+1:3*n]
Rhubp = x[3*n+1]
Rtipp = x[3*n+2]
pitchp = x[3*n+3]
preconep = x[3*n+4]
Vinfp = x[3*n+5]
Omegap = x[3*n+6]
rhop = x[3*n+7]

T, Q = thrusttorque(rotor, sections, outputs)
rotor = Rotor(Rhubp, Rtipp, B; turbine=turbine, precone=preconep)
sections = Section.(rp, chordp, thetap, airfoils)
ops = simple_op.(Vinfp, Omegap, rp, rhop; pitch=pitchp)

return [T; Q]
end
outputs = solve.(Ref(rotor), sections, ops, implicitad_option=implicitad_option)

import ForwardDiff
T, Q = thrusttorque(rotor, sections, outputs)

x = [r; chord; theta; Rhub; Rtip; pitch; precone; Vinf; Omega; rho]
return [T; Q]
end

J = ForwardDiff.jacobian(ccbladewrapper, x)
x = [r; chord; theta; Rhub; Rtip; pitch; precone; Vinf; Omega; rho]

# using BenchmarkTools
# @btime ForwardDiff.jacobian($ccbladewrapper, $x)
# original: 584.041 μs (9910 allocations: 1.15 MiB)
# with ImplicitAD: 323.208 μs (11862 allocations: 747.50 KiB)
J = ForwardDiff.jacobian(ccbladewrapper, x)
if !implicitad_option
J_no_implicitad = J
# else
# @show maximum(abs.(J .- J_no_implicitad))
# maximum(abs.(J .- J_no_implicitad)) = 1.2650161806959659e-8
end

import FiniteDiff
# using BenchmarkTools
# @btime ForwardDiff.jacobian($ccbladewrapper, $x)
# original: 584.041 μs (9910 allocations: 1.15 MiB)
# with ImplicitAD: 323.208 μs (11862 allocations: 747.50 KiB)

J2 = FiniteDiff.finite_difference_jacobian(ccbladewrapper, x, Val{:central})

J2 = FiniteDiff.finite_difference_jacobian(ccbladewrapper, x, Val{:central})
@test maximum(abs.(J - J2)) < 1e-6

@test maximum(abs.(J - J2)) < 1e-6
J3 = FiniteDiff.finite_difference_jacobian(ccbladewrapper, x, Val{:complex})

J3 = FiniteDiff.finite_difference_jacobian(ccbladewrapper, x, Val{:complex})
@test maximum(abs.(J_no_implicitad - J3)) < 1e-12

@test maximum(abs.(J - J3)) < 1e-12
end

end

Expand Down

0 comments on commit e3f712a

Please sign in to comment.