Files
JuliaFEM.jl/test/test_dirichlet.jl
T

159 lines
4.9 KiB
Julia
Raw Normal View History

2015-11-11 00:52:16 +02:00
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
2018-09-06 12:08:16 +03:00
using JuliaFEM, SparseArrays, Test
2015-12-23 17:39:53 +02:00
2016-02-24 01:20:39 +02:00
#=
2016-05-25 22:33:47 +03:00
In [36]: C = Matrix([[0], [30], [15]]) # node coordinates
In [37]: A = Matrix([P.subs({x: C[i,0]}).T for i in range(len(P))])
In [38]: N = P.T*A.inv()
In [39]: Me = integrate(N.T*N, (x, 0, 30))
In [40]: De = diag(*integrate(N, (x, 0, 30)))
In [41]: Me
2018-09-06 12:08:16 +03:00
Out[41]:
2016-05-25 22:33:47 +03:00
Matrix([
[ 4, -1, 2],
[-1, 4, 2],
[ 2, 2, 16]])
In [42]: De
2018-09-06 12:08:16 +03:00
Out[42]:
2016-05-25 22:33:47 +03:00
Matrix([
[5, 0, 0],
[0, 5, 0],
[0, 0, 20]])
=#
2015-12-23 17:39:53 +02:00
@testset "dirichlet problem in 1 dimension" begin
2018-09-06 12:08:16 +03:00
time = 0.0
element = Element(Seg2, (1, 2))
X = Dict(1 => [0.0, 0.0], 2 => [6.0, 0.0])
update!(element, "geometry", X)
update!(element, "temperature 1", 0.0)
problem1 = Problem(Dirichlet, "test problem 1", 1, "temperature")
problem1.properties.variational = true
problem1.properties.dual_basis = false
add_element!(problem1, element)
assemble!(problem1, time)
C1 = problem1.assembly.C1
C2 = problem1.assembly.C2
2016-05-25 22:33:47 +03:00
@test isapprox(C1, C2)
@test isapprox(C1, [2.0 1.0; 1.0 2.0])
2018-09-06 12:08:16 +03:00
problem2 = Problem(Dirichlet, "test problem 2", 1, "temperature")
problem2.properties.variational = true
problem2.properties.dual_basis = true
add_element!(problem2, element)
assemble!(problem2, time)
C1 = problem2.assembly.C1
C2 = problem2.assembly.C2
2016-05-25 22:33:47 +03:00
@test isapprox(C1, C2)
@test isapprox(C1, [3.0 0.0; 0.0 3.0])
2018-09-06 12:08:16 +03:00
element = Element(Seg3, (1, 2, 3))
X = Dict(1 => [0.0, 0.0], 2 => [30.0, 0.0], 3 => [15.0, 0.0])
update!(element, "geometry", X)
update!(element, "temperature 1", 0.0)
problem3 = Problem(Dirichlet, "quadratic 1", 1, "temperature")
problem3.properties.variational = true
problem3.properties.dual_basis = false
add_element!(problem3, element)
assemble!(problem3, time)
C1 = problem3.assembly.C1
C2 = problem3.assembly.C2
2015-12-23 17:39:53 +02:00
@test isapprox(C1, C2)
2016-05-25 22:33:47 +03:00
@test isapprox(C1, [4.0 -1.0 2.0; -1.0 4.0 2.0; 2.0 2.0 16.0])
2018-09-06 12:08:16 +03:00
problem4 = Problem(Dirichlet, "quadratic 2", 1, "temperature")
problem4.properties.variational = true
problem4.properties.dual_basis = true
add_element!(problem4, element)
assemble!(problem4, time)
C1 = problem4.assembly.C1
C2 = problem4.assembly.C2
2016-05-25 22:33:47 +03:00
@test isapprox(C1, C2)
@test isapprox(C1, [5.0 0.0 0.0; 0.0 5.0 0.0; 0.0 0.0 20.0])
end
2016-05-25 22:33:47 +03:00
#=
2016-02-24 01:20:39 +02:00
@testset "dirichlet problem using tri3 surface element" begin
element = Tri3([1, 2, 3])
element["geometry"] = Node[[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
element["temperature"] = 0.0
problem = Problem(Dirichlet, "test problem", 1, "temperature")
push!(problem, element)
assemble!(problem, 0.0)
C1 = full(problem.assembly.C1)
C2 = full(problem.assembly.C2)
@test isapprox(C1, C2)
@test isapprox(C1, 1/24*[2 1 1; 1 2 1; 1 1 2])
end
2015-12-23 17:39:53 +02:00
@testset "dirichlet problem in 2 dimensions" begin
element = Seg2([1, 2])
2015-12-23 17:39:53 +02:00
element["geometry"] = Node[[1.0, 1.0], [0.0, 1.0]]
2016-02-24 01:20:39 +02:00
element["displacement 1"] = 0.0
element["displacement 2"] = 0.0
problem = Problem(Dirichlet, "test problem", 2, "displacement")
push!(problem, element)
2016-02-24 01:20:39 +02:00
assemble!(problem, 0.0)
C1 = full(problem.assembly.C1)
C2 = full(problem.assembly.C2)
g = full(problem.assembly.g)
2015-12-23 17:39:53 +02:00
@test isapprox(C1, C2)
C1_expected = 1/6*[2 0 1 0; 0 2 0 1; 1 0 2 0; 0 1 0 2]
@test isapprox(C1, C1_expected)
@test isapprox(g, [0.0, 0.0, 0.0, 0.0])
end
2015-11-11 00:52:16 +02:00
2015-12-23 17:39:53 +02:00
@testset "dirichlet problem in 2 dimensions, with 1 dof fixed" begin
element = Seg2([1, 2])
2015-12-23 17:39:53 +02:00
element["geometry"] = Node[[1.0, 1.0], [0.0, 1.0]]
element["displacement 2"] = 0.0
2016-02-24 01:20:39 +02:00
problem = Problem(Dirichlet, "test problem", 2, "displacement")
2015-11-11 00:52:16 +02:00
push!(problem, element)
2016-02-24 01:20:39 +02:00
assemble!(problem, 0.0)
C1 = full(problem.assembly.C1)
C2 = full(problem.assembly.C2)
g = full(problem.assembly.g)
2015-12-23 17:39:53 +02:00
@test isapprox(C1, C2)
C1_expected = 1/6*[
0 0 0 0
0 2 0 1
0 0 0 0
0 1 0 2]
2015-12-23 17:39:53 +02:00
@test isapprox(C1, C1_expected)
@test isapprox(g, [0.0, 0.0, 0.0, 0.0])
2015-11-11 00:52:16 +02:00
end
2016-05-25 22:33:47 +03:00
=#
2015-11-11 00:52:16 +02:00
2016-06-27 16:11:33 +03:00
@testset "test analytical boundary condition" begin
2018-09-06 12:08:16 +03:00
X = Dict(1 => [0.0, 0.0],
2 => [1.0, 0.0])
element = Element(Seg2, (1, 2))
2016-06-27 16:11:33 +03:00
update!(element, "geometry", X)
2018-09-06 12:08:16 +03:00
function f(element, ip, time)
x, y = element("geometry", ip, time)
val = x*time
@debug("analytical function called", ip, time, x, y, val)
2016-06-27 16:11:33 +03:00
return val
end
2018-09-06 12:08:16 +03:00
update!(element, "displacement 1", 0.0)
2016-06-27 16:11:33 +03:00
update!(element, "displacement 2", f)
2018-09-06 12:08:16 +03:00
problem = Problem(Dirichlet, "test boundary", 2, "displacement")
add_element!(problem, element)
time = 0.0
assemble!(problem, time)
@test isapprox(problem.assembly.g, [0.0, 0.0, 0.0, 0.0])
empty!(problem.assembly)
time = 1.0
assemble!(problem, time)
g2 = Vector(problem.assembly.g, 4)
C2 = Matrix(problem.assembly.C2, 4, 4)
2016-06-27 16:11:33 +03:00
u = C2 \ g2
2018-09-06 12:08:16 +03:00
@debug("displacement vector", u)
2016-06-27 16:11:33 +03:00
@test isapprox(u, [0.0, 0.0, 0.0, 1.0])
end