Skip to content

Commit

Permalink
rearrange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taylormcd committed Aug 23, 2022
1 parent dc699ff commit d1d3818
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions test/section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ function sectionwrapper(x)

webs = [web, web]


nodes, elements = afmesh(xaf, yaf, chord, twist, paxis, xbreak, webloc, segments, webs)

S, sc, tc = compliance_matrix(nodes, elements)
Expand All @@ -722,36 +721,6 @@ function sectionwrapper(x)
return vcat([S; M]...)
end


@testset "type stability" begin

function checkstability()
xvec = [0.5014995, 0.07571157, 10.30e9, 1.9, 0.0*pi/180, 17*0.00053, 20.0, 38*0.00053, 0.0]
try
@inferred Vector{Float64} sectionwrapper(xvec)
return true
catch err
println(err)
return false
end
end

@test checkstability()

end

@testset "Jacobian" begin

# should use graph coloring b.c. plenty of sparsity, but dense is fine for purpose of this test.
xvec = [0.5014995, 0.07571157, 10.30e9, 1.9, 0.0*pi/180, 17*0.00053, 20.0, 38*0.00053, 0.0]

J1 = ForwardDiff.jacobian(sectionwrapper, xvec)
J2 = FiniteDiff.finite_difference_jacobian(sectionwrapper, xvec, Val{:central})

@test maximum(abs.(J1 .- J2)) < 1e-6

end

function sectionwrapper_nowebs(x)

TF = eltype(x)
Expand Down Expand Up @@ -804,13 +773,42 @@ function sectionwrapper_nowebs(x)
return vcat([S; M]...)
end

@testset "No webs" begin
@testset "type stability" begin

function checkstability()
xvec = [0.5014995, 0.07571157, 10.30e9, 1.9, 0.0*pi/180, 17*0.00053, 20.0, 38*0.00053, 0.0]
try
@inferred Vector{Float64} sectionwrapper(xvec)
return true
catch err
println(err)
return false
end
end

@test checkstability()

end

@testset "Jacobian with Webs" begin

# should use graph coloring b.c. plenty of sparsity, but dense is fine for purpose of this test.
xvec = [0.5014995, 0.07571157, 10.30e9, 1.9, 0.0*pi/180, 17*0.00053, 20.0, 38*0.00053, 0.0]

J1 = ForwardDiff.jacobian(sectionwrapper, xvec)
J2 = FiniteDiff.finite_difference_jacobian(sectionwrapper, xvec, Val{:central})

@test maximum(abs.(J1 .- J2)) < 1e-6

end

@testset "Jacobian without Webs" begin

xvec = [0.5014995, 0.07571157, 10.30e9, 1.9, 0.0*pi/180, 17*0.00053, 20.0, 38*0.00053, 0.0]

J1 = ForwardDiff.jacobian(sectionwrapper_nowebs, xvec)
J2 = FiniteDiff.finite_difference_jacobian(sectionwrapper_nowebs, xvec, Val{:central})

@test maximum(abs.(J1 .- J2)) < 1e-6 #ensures it runs without error and derivatives can still pass through
@test maximum(abs.(J1 .- J2)) < 1e-6

end

0 comments on commit d1d3818

Please sign in to comment.