Files
JuliaFEM.jl/test/test_elasticity_2d_plane_stress_stiffness_matrix.jl
T
Jukka Aho bec6642693 Assemble several elements at a time
Now assemble! takes a vector of elements as input. This makes it
possible to preallocate memory for common matrices making code super
fast.
2017-08-17 17:49:39 +03:00

48 lines
1.5 KiB
Julia

# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# http://ahojukka5.github.io/posts/finite-element-solution-for-one-element-problem/
using JuliaFEM
using JuliaFEM.Testing
@testset "test 2d linear elasticity local matrices" begin
element = Element(Quad4, [1, 2, 3, 4])
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [1.0, 0.0],
3 => [1.0, 1.0],
4 => [0.0, 1.0])
u = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [0.0, 0.0],
3 => [0.0, 0.0],
4 => [0.0, 0.0])
update!(element, "geometry", X)
update!(element, "displacement", u)
update!(element, "youngs modulus" => 288.0, "poissons ratio" => 1/3)
update!(element, "displacement load", DCTI([4.0, 8.0]))
problem = Problem(Elasticity, "[0x1] x [0x1] block", 2)
update!(problem.properties, "formulation" => "plane_stress")
add_elements!(problem, [element])
assemble!(problem)
K = full(problem.assembly.K)
f = vec(full(problem.assembly.f))
K_expected = [
144 54 -90 0 -72 -54 18 0
54 144 0 18 -54 -72 0 -90
-90 0 144 -54 18 0 -72 54
0 18 -54 144 0 -90 54 -72
-72 -54 18 0 144 54 -90 0
-54 -72 0 -90 54 144 0 18
18 0 -72 54 -90 0 144 -54
0 -90 54 -72 0 18 -54 144]
f_expected = [1, 2, 1, 2, 1, 2, 1, 2]
@test isapprox(K, K_expected)
@test isapprox(f, f_expected)
end