From c1b5d2f7ed0e05166d867b19fe98b46752489594 Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sat, 21 Jan 2017 09:57:52 +0200 Subject: [PATCH] Inceased coverage (#77) - added Xdmf() to solver for two tests to test also creating Xdmf after solution. --- test/test_modal_analysis_elasticity.jl | 1 + test/test_solver.jl | 90 +++++++------------------- 2 files changed, 26 insertions(+), 65 deletions(-) diff --git a/test/test_modal_analysis_elasticity.jl b/test/test_modal_analysis_elasticity.jl index 1fd21b8..c9837c7 100644 --- a/test/test_modal_analysis_elasticity.jl +++ b/test/test_modal_analysis_elasticity.jl @@ -142,6 +142,7 @@ numéro fréquence (HZ) norme d'erreur solver = Solver(Modal, body, fixed1, fixed2) solver.properties.nev = 5 + solver.xdmf = Xdmf() solver() freqs_jf = sqrt(solver.properties.eigvals)/(2.0*pi) # with Tet4 elements diff --git a/test/test_solver.jl b/test/test_solver.jl index 728b20f..29e3fc1 100644 --- a/test/test_solver.jl +++ b/test/test_solver.jl @@ -4,38 +4,40 @@ using JuliaFEM using JuliaFEM.Testing -function test_linearsolver() - el1 = Quad4([1, 2, 3, 4]) - el1["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]] - el1["temperature thermal conductivity"] = 6.0 - el1["density"] = 36.0 +@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) - el2 = Seg2([1, 2]) - el2["geometry"] = Vector[[0.0, 0.0], [1.0, 0.0]] - el2["temperature flux"] = ( - (0.0 => 0.0), - (1.0 => 600.0) - ) + update!(el2, "heat flux", 0.0 => 0.0) + update!(el2, "heat flux", 1.0 => 600.0) - field_problem = HeatProblem() - push!(field_problem, el1) - push!(field_problem, el2) + problem = Problem(Heat, "test problem", 1) + problem.properties.formulation = "2D" + push!(problem.elements, el1, el2) - el3 = Seg2([3, 4]) - el3["geometry"] = Vector[[1.0, 1.0], [0.0, 1.0]] - el3["temperature"] = 0.0 + update!(el3, "temperature 1", 0.0) - boundary_problem = DirichletProblem("temperature", 1) + bc = Problem(Dirichlet, "fixed", 1, "temperature") - push!(boundary_problem, el3) + push!(bc.elements, el3) # Create a solver for a set of problems - solver = LinearSolver() - push!(solver, field_problem) - push!(solver, boundary_problem) + solver = Solver(Linear, "solve heat problem") + push!(solver, problem, bc) # Solve problem at time t=1.0 and update fields - solver(1.0) + solver.time = 1.0 + solver.xdmf = Xdmf() + solver() # Postprocess. # Interpolate temperature field along boundary of Γ₁ at time t=1.0 @@ -45,45 +47,3 @@ function test_linearsolver() info("Temperature at point X = $X is T = $T") @test isapprox(T, 100.0) end - -function test_solvers() - K = [ - 440.0 150.0 -260.0 -30.0 40.0 30.0 -220.0 -150.0 - 150.0 440.0 30.0 40.0 -30.0 -260.0 -150.0 -220.0 - -260.0 30.0 440.0 -150.0 -220.0 150.0 40.0 -30.0 - -30.0 40.0 -150.0 440.0 150.0 -220.0 30.0 -260.0 - 40.0 -30.0 -220.0 150.0 440.0 -150.0 -260.0 30.0 - 30.0 -260.0 150.0 -220.0 -150.0 440.0 -30.0 40.0 - -220.0 -150.0 40.0 30.0 -260.0 -30.0 440.0 150.0 - -150.0 -220.0 -30.0 -260.0 30.0 40.0 150.0 440.0] - - C = 1/3*[ - 1.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 - 0.0 1.0 0.0 0.0 0.0 0.5 0.0 0.0 - 0.0 0.0 1.0 0.0 0.0 0.0 0.5 0.0 - 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.5 - 0.5 0.0 0.0 0.0 1.0 0.0 0.0 0.0 - 0.0 0.5 0.0 0.0 0.0 1.0 0.0 0.0 - 0.0 0.0 0.5 0.0 0.0 0.0 1.0 0.0 - 0.0 0.0 0.0 0.5 0.0 0.0 0.0 1.0] - - f = zeros(8) - - g = 1/100 * [-5.0, 5.0, 10.0, -10.0, -5.0, 5.0, 10.0, -10.0] - - K = sparse(K) - C = sparse(C) - f = sparse(f) - g = sparse(g) - - expected = [-0.1, 0.1, 0.2, -0.2, -0.1, 0.1, 0.2, -0.2] - u1, la1 = solve(K, f, C, g, Val{:UMFPACK}) - @test isapprox(u1, expected) - u2, la2 = solve(K, f, C, g, Val{:CHOLMOD}) - @test isapprox(u2, expected) - # FIXME: how to dynamically include packages only if they are installed? - #include(Pkg.dir("JuliaFEM"*"/src/petsc.jl")) - u3, la3 = solve(K, f, C, g, Val{:PETSc_GMRES}) - @test isapprox(u3, expected) -end -