Skip to content

Commit

Permalink
Merge ae2e59e into ce7fffb
Browse files Browse the repository at this point in the history
  • Loading branch information
jtveiten committed Feb 1, 2018
2 parents ce7fffb + ae2e59e commit 9f4f5ab
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 44 deletions.
59 changes: 15 additions & 44 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/FEMTruss.jl/blob/master/LICENSE

using FEMBase
using FEMTruss

using Base.Test
using TimerOutputs
const to = TimerOutput()

@testset "FEMTruss.jl" begin

elem1 = Element(Seg2, [1, 2]) # connects to nodes 1, 2
elem1.id = 1
X = Dict{Int64, Vector{Float64}}(
1 => [0.0],
2 => [10.0])

update!(elem1, "geometry", X)
update!(elem1, "youngs modulus", 288.0)
update!(elem1, "cross section area", 0.1)
p1 = Problem(Truss, "my truss problem", 1) # 1 dofs/node for now;
empty!(p1.assembly)
assemble!(p1.assembly, p1, elem1, 0.0)
K_truss = full(p1.assembly.K)
@test isapprox(K_truss, [2.88 -2.88;-2.88 2.88])

# now for the 2d case
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [10.0, 0.0])

update!(elem1, "geometry", X)
p1 = Problem(Truss, "my truss problem", 2) # 1 dofs/node for now;
empty!(p1.assembly)
assemble!(p1.assembly, p1, elem1, 0.0)
K_truss = full(p1.assembly.K)
@test isapprox(K_truss, [2.88 0.0 -2.88 0.0; 0.0 0.0 0.0 0.0; -2.88 0.0 2.88 0.0; 0.0 0.0 0.0 0.0])
test_files = String[]
push!(test_files, "test_elements.jl")
#push!(test_files, "test_problems.jl")

# now for the 3d case
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0, 0.0],
2 => [10.0, 0.0, 0.0])

update!(elem1, "geometry", X)
p1 = Problem(Truss, "my truss problem", 3) # 1 dofs/node for now;
empty!(p1.assembly)
assemble!(p1.assembly, p1, elem1, 0.0)
K_truss = full(p1.assembly.K)
@test isapprox(K_truss, [2.88 0.0 0.0 -2.88 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; -2.88 0.0 0.0 2.88 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0])
@testset "FEMTruss.jl" begin
for fn in test_files
timeit(to, fn) do
include(fn)
end
end
end
println()
println("Test statistics:")
println(to)

# Need some boundary conditions and forces
# simple truss along x axis
Expand All @@ -56,5 +29,3 @@ K_truss = full(p1.assembly.K)
#solver = Solver(Linear, p1, f1, b1)
#solver()
# u = 10*10/(288*0.1)

end
95 changes: 95 additions & 0 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/FEMTruss.jl/blob/master/LICENSE

using FEMBase
using FEMTruss

using Base.Test
# thsi is the same for all tests testing K and orientation
function make_test_problem(coords::Vector{Tuple{Int64, Vector{Float64}}}, dim::Int64, t::Float64=0.0)
elem_id = map(x->x[1], coords)
coord_dict=Dict(coords)
elem1 = Element(Seg2, elem_id) # connects to nodes 1, 2
elem1.id = 1
update!(elem1, "geometry", coord_dict)
update!(elem1, "youngs modulus", 288.0)
update!(elem1, "cross section area", 0.1)
p1 = Problem(Truss, "my truss problem", dim) # 1 dofs/node for now;
empty!(p1.assembly)
assemble!(p1.assembly, p1, elem1, t)
return p1
end

@testset "FEMTrussElements.jl" begin

zeros_2d = zeros(1,2)
zeros_3d = zeros(1,3)
K_oracle_base = [2.88 -2.88;-2.88 2.88]
#truss test
X = [(1 , [0.0]),(2, [10.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)

@test get_unknown_field_name(p1)=="displacement"

#This one fails
#Test threw an exception of type UndefVarError
# Expression: get_formulation_type(p1)
# UndefVarError: get_formulation_type not defined
#@test get_formulation_type(p1)

K_truss = full(p1.assembly.K)
K_oracle = K_oracle_base
@test isapprox(K_truss, K_oracle)

# now for the 2d x case
X = [(1 , [0.0,0.0]),(2, [10.0,0.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)
K_truss = full(p1.assembly.K)
trans_2d = [1 0]
trans = [trans_2d zeros_2d;zeros_2d trans_2d]
K_oracle = trans'*K_oracle_base*trans
@test isapprox(K_truss, K_oracle)

# lets do y as well
X = [(1 , [0.0,0.0]),(2, [0.0,10.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)
K_truss = full(p1.assembly.K)
trans_2d = [0 1]
trans = [trans_2d zeros_2d;zeros_2d trans_2d]
K_oracle = trans'*K_oracle_base*trans
@test isapprox(K_truss, K_oracle)

# now for the 2d x case reverted
X = [(2 , [0.0,0.0]),(1, [10.0,0.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)
K_truss = full(p1.assembly.K)
trans_2d = [-1 0]
trans = [trans_2d zeros_2d;zeros_2d trans_2d]
K_oracle = trans'*K_oracle_base*trans
@test isapprox(K_truss, K_oracle)

# lets do y as well reverted
X = [(2 , [0.0,0.0]),(1, [0.0,10.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)
K_truss = full(p1.assembly.K)
trans_2d = [0 -1]
trans = [trans_2d zeros_2d;zeros_2d trans_2d]
K_oracle = trans'*K_oracle_base*trans
@test isapprox(K_truss, K_oracle)

# now for the 3d case
X = [(1 , [0.0,0.0,0.0]),(2, [10.0,0.0,0.0])]
ndofs = length(X[1][2])
p1 = make_test_problem(X, ndofs)
K_truss = full(p1.assembly.K)
trans_3d = [1 0 0]
trans = [trans_3d zeros_3d;zeros_3d trans_3d]
K_oracle = trans'*K_oracle_base*trans
@test isapprox(K_truss, K_oracle)

end

0 comments on commit 9f4f5ab

Please sign in to comment.