petsc interface

This commit is contained in:
Jukka Aho
2015-12-05 10:58:01 +02:00
parent f078330971
commit d4e21af8de
9 changed files with 194 additions and 45 deletions
+4 -3
View File
@@ -98,10 +98,10 @@ function test_direct_cholesky_with_non_homogeneous_dirichlet_conditions()
push!(solver, boundary)
# launch solver
# solver.method = :LU
# solver.dump_matrices = true
solver.method = :UMFPACK
solver.dump_matrices = true
solver.max_iterations = 1
solver(0.0)
iters, status = solver(0.0)
# FIXME: solver gives no convergence warning when all dofs are fixed.
n1disp = e1("displacement", [-1.0, -1.0], 0.0)
n2disp = e1("displacement", [ 1.0, -1.0], 0.0)
@@ -113,6 +113,7 @@ function test_direct_cholesky_with_non_homogeneous_dirichlet_conditions()
@test isapprox(n3disp, [-0.1, 0.1])
@test isapprox(n2disp, [ 0.2, -0.2])
@test isapprox(n4disp, [ 0.2, -0.2])
@test status == true
end
#test_direct_cholesky_with_non_homogeneous_dirichlet_conditions()
+10 -2
View File
@@ -23,6 +23,13 @@ function get_test_2d_model()
master2 = Seg2([8, 9])
master2["geometry"] = Vector[N[8], N[9]]
#=
master1 = Seg2([9, 8])
master1["geometry"] = Vector[N[9], N[8]]
master2 = Seg2([8, 7])
master2["geometry"] = Vector[N[8], N[7]]
=#
slave1 = Seg2([10, 11])
slave1["geometry"] = Vector[N[10], N[11]]
# should be n = [0 -1]' and t = [1 0]'
@@ -202,8 +209,9 @@ function test_2d_mortar_multiple_bodies_multiple_dirichlet_bc()
push!(solver, boundary2)
push!(solver, boundary3)
solver.name = "test_2d_mortar_multiple_bodies_multiple_dirichlet_bcs"
solver.dump_matrices = true
solver.method = :LU
solver.method = :UMFPACK
# launch solver
solver(0.0)
@@ -324,7 +332,7 @@ function test_2d_mortar_three_bodies_shared_nodes()
push!(solver, bc5)
# launch solver
solver.method = :LU
solver.method = :UMFPACK
call(solver, 0.0)
disp = e2("displacement", [1.0, 1.0], 0.0)
+46 -2
View File
@@ -8,6 +8,7 @@ using JuliaFEM.Test
using JuliaFEM.Core: Seg2, Quad4
using JuliaFEM.Core: DirichletProblem, HeatProblem
using JuliaFEM.Core: LinearSolver
using JuliaFEM.Core: solve
function test_linearsolver()
el1 = Quad4([1, 2, 3, 4])
@@ -35,7 +36,9 @@ function test_linearsolver()
push!(boundary_problem, el3)
# Create a solver for a set of problems
solver = LinearSolver(field_problem, boundary_problem)
solver = LinearSolver()
push!(solver, field_problem)
push!(solver, boundary_problem)
# Solve problem at time t=1.0 and update fields
solver(1.0)
@@ -48,7 +51,48 @@ function test_linearsolver()
info("Temperature at point X = $X is T = $T")
@test isapprox(T, 100.0)
end
#test_basic()
test_basic()
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)
include(Pkg.dir("JuliaFEM"*"/src/petsc.jl"))
u3, la3 = solve(K, f, C, g, Val{:PETSc_GMRES})
@test isapprox(u3, expected)
end
# test_solvers()
end