mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-10-02 06:13:59 +00:00
petsc interface
This commit is contained in:
+46
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user