Skip to content

Commit

Permalink
Improve the AD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dingraha committed Mar 16, 2024
1 parent e3f712a commit 0da6f9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/CCBlade.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Solve the BEM equations for given rotor geometry and operating point.
**Returns**
- `outputs::Outputs`: BEM output data including loads, induction factors, etc.
"""
function solve(rotor, section, op; npts=10, forcebackwardsearch=false, epsilon_everywhere=false, implicitad_option=true)
function solve(rotor, section, op; npts=10, forcebackwardsearch=false, epsilon_everywhere=false, implicitad_option=true, atol=2e-12, rtol=4*eps())

# error handling
if typeof(section) <: AbstractVector
Expand Down Expand Up @@ -505,7 +505,7 @@ function solve(rotor, section, op; npts=10, forcebackwardsearch=false, epsilon_e
success, phiL, phiU = firstbracket(phi -> residual(phi, xv, pv), phimin, phimax, npts, backwardsearch)

function solve(x, p)
phistar, _ = FLOWMath.brent(phi -> residual(phi, x, p), phiL, phiU)
phistar, _ = FLOWMath.brent(phi -> residual(phi, x, p), phiL, phiU; atol, rtol)
return phistar
end

Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ for implicitad_option in (false, true)
sections = Section.(rp, chordp, thetap, airfoils)
ops = simple_op.(Vinfp, Omegap, rp, rhop; pitch=pitchp)

outputs = solve.(Ref(rotor), sections, ops, implicitad_option=implicitad_option)
outputs = solve.(Ref(rotor), sections, ops; implicitad_option=implicitad_option, atol=1e-14)

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

Expand All @@ -730,8 +730,8 @@ for implicitad_option in (false, true)
if !implicitad_option
J_no_implicitad = J
# else
# @show maximum(abs.(J .- J_no_implicitad))
# maximum(abs.(J .- J_no_implicitad)) = 1.2650161806959659e-8
# @show maximum(abs.(J .- J_no_implicitad))
# maximum(abs.(J .- J_no_implicitad)) = 2.5494273359072395e-11
end

# using BenchmarkTools
Expand All @@ -745,9 +745,9 @@ for implicitad_option in (false, true)

J3 = FiniteDiff.finite_difference_jacobian(ccbladewrapper, x, Val{:complex})

@test maximum(abs.(J_no_implicitad - J3)) < 1e-12
@test maximum(abs.(J - J3)) < 3e-11

end
end

end

Expand Down

0 comments on commit 0da6f9a

Please sign in to comment.