Files
JuliaFEM.jl/test/test_heat.jl
T

64 lines
1.9 KiB
Julia
Raw Normal View History

2015-10-28 04:29:14 +02:00
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
# unit tests for heat equations
2015-11-01 18:44:50 +02:00
module HeatTests # always wrap tests to module ending with "Tests"
2015-10-28 04:29:14 +02:00
2015-11-01 18:44:50 +02:00
using JuliaFEM.Test # always use JuliaFEM.Test, not Base.Test
2015-11-18 01:19:04 +02:00
2015-11-30 23:00:21 +02:00
using JuliaFEM.Core: Seg2, Quad4, HeatProblem, assemble
2015-11-01 18:44:50 +02:00
function test_one_element() # always start test function with name test_
2015-10-28 04:29:14 +02:00
# volume element
element = Quad4([1, 2, 3, 4])
2015-11-21 18:23:41 +02:00
2015-10-30 12:40:56 +02:00
element["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
element["temperature thermal conductivity"] = 6.0
element["temperature load"] = [12.0, 12.0, 12.0, 12.0]
element["density"] = 36.0
2015-10-28 04:29:14 +02:00
# boundary element
boundary_element = Seg2([1, 2])
2015-10-30 12:40:56 +02:00
boundary_element["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0]]
2015-11-21 18:23:41 +02:00
# linear ramp from 0 to 6 in time 0 to 1
boundary_element["temperature flux"] = (0.0 => 0.0, 1.0 => 6.0)
2015-10-28 04:29:14 +02:00
2015-11-27 10:10:00 +02:00
problem = HeatProblem()
push!(problem, element)
push!(problem, boundary_element)
2015-10-28 04:29:14 +02:00
# Set constant source f=12 with k=6. Accurate solution is
# T=1 on free boundary, u(x,y) = -1/6*(1/2*f*x^2 - f*x)
2015-11-27 10:10:00 +02:00
assembly = assemble(problem, 0.0)
2015-10-28 04:29:14 +02:00
fdofs = [1, 2]
A = full(assembly.stiffness_matrix)
b = full(assembly.force_vector)
info("stiffness matrix = \n$(round(A, 3))")
@test isapprox(A, [
4.0 -1.0 -2.0 -1.0
-1.0 4.0 -1.0 -2.0
-2.0 -1.0 4.0 -1.0
-1.0 -2.0 -1.0 4.0
])
2015-11-01 18:44:50 +02:00
@test isapprox(A[fdofs, fdofs] \ b[fdofs], [1.0, 1.0])
2015-10-28 04:29:14 +02:00
# Set constant flux g=6 on boundary. Accurate solution is
# u(x,y) = x which equals T=1 on boundary.
2015-11-27 10:10:00 +02:00
# at time t=1.0 all loads should be on.
assembly = assemble(problem, 1.0)
A = full(assembly.stiffness_matrix)
b = full(assembly.force_vector)
T = A[fdofs, fdofs] \ b[fdofs]
info("T = $T")
2015-11-27 10:10:00 +02:00
@test isapprox(T, [2.0, 2.0])
2015-10-28 04:29:14 +02:00
end
2015-11-01 18:44:50 +02:00
end
2015-11-27 10:10:00 +02:00