Files
JuliaFEM.jl/test/test_solvers.jl
T

79 lines
2.4 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
2016-07-03 21:16:03 +03:00
using JuliaFEM
using JuliaFEM.Testing
2015-10-28 04:29:14 +02:00
2017-01-21 09:57:52 +02:00
@testset "test linearsolver + xdmf writing" begin
el1 = Element(Quad4, [1, 2, 3, 4])
el2 = Element(Seg2, [1, 2])
el3 = Element(Seg2, [3, 4])
X = Dict(
1 => [0.0, 0.0],
2 => [1.0, 0.0],
3 => [1.0, 1.0],
4 => [0.0, 1.0])
update!([el1, el2, el3], "geometry", X)
update!(el1, "thermal conductivity", 6.0)
update!(el1, "density", 36.0)
2015-10-28 04:29:14 +02:00
2017-01-21 09:57:52 +02:00
update!(el2, "heat flux", 0.0 => 0.0)
update!(el2, "heat flux", 1.0 => 600.0)
2015-10-28 04:29:14 +02:00
2017-01-21 09:57:52 +02:00
problem = Problem(Heat, "test problem", 1)
problem.properties.formulation = "2D"
push!(problem.elements, el1, el2)
2015-10-28 04:29:14 +02:00
2017-01-21 09:57:52 +02:00
update!(el3, "temperature 1", 0.0)
2015-10-28 04:29:14 +02:00
2017-01-21 09:57:52 +02:00
bc = Problem(Dirichlet, "fixed", 1, "temperature")
2015-11-27 10:10:00 +02:00
2017-01-21 09:57:52 +02:00
push!(bc.elements, el3)
2015-11-27 10:10:00 +02:00
2015-10-28 04:29:14 +02:00
# Create a solver for a set of problems
2017-01-21 09:57:52 +02:00
solver = Solver(Linear, "solve heat problem")
push!(solver, problem, bc)
2015-11-27 10:10:00 +02:00
2015-10-28 04:29:14 +02:00
# Solve problem at time t=1.0 and update fields
2017-01-21 09:57:52 +02:00
solver.time = 1.0
solver.xdmf = Xdmf()
solver()
2015-11-27 10:10:00 +02:00
2015-10-28 04:29:14 +02:00
# Postprocess.
# Interpolate temperature field along boundary of Γ₁ at time t=1.0
2017-08-05 11:33:43 +03:00
xi = (0.0, )
2015-11-27 10:10:00 +02:00
X = el2("geometry", xi, 1.0)
T = el2("temperature", xi, 1.0)
2015-11-18 01:19:04 +02:00
info("Temperature at point X = $X is T = $T")
@test isapprox(T, 100.0)
2015-11-18 01:19:04 +02:00
end
2017-01-30 12:28:33 +02:00
@testset "problem not found from solver" begin
s = Solver(Linear, "demo solver")
@test_throws KeyError getindex(s, "not_found")
end
@testset "automatic determination of problem dimension if not spesified" begin
s = Solver(Linear, "demo solver")
p = Problem(Elasticity, "demo problem", 2)
push!(s, p)
get_field_assembly(s)
@test s.ndofs == 0
2017-07-20 20:46:57 +03:00
add!(p.assembly.K, [4], [4], reshape([4.0],1,1))
2017-01-30 12:28:33 +02:00
get_field_assembly(s)
@test s.ndofs == 4
end
@testset "test for error when overdetermined system and requesting boundary assembly" begin
s = Solver(Linear, "demo solver")
@test_throws AssertionError get_boundary_assembly(s) # ndofs = 0
p1 = Problem(Dirichlet, "bc1", 2, "displacement")
p2 = Problem(Dirichlet, "bc2", 2, "displacement")
# third dofs constrained
2017-07-20 20:46:57 +03:00
add!(p1.assembly.C2, [3], [3], reshape([1.0],1,1))
add!(p2.assembly.C2, [3], [4], reshape([1.0],1,1))
2017-01-30 12:28:33 +02:00
s.ndofs = 4
push!(s, p1, p2)
@test_throws ErrorException get_boundary_assembly(s)
end