Skip to content

Commit

Permalink
Implement create global stiffness and mass matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapo authored and ahojukka5 committed Aug 4, 2017
1 parent 4aa6105 commit 80b4f79
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ModelReduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

module ModelReduction

include("global_stiffness.jl")
include("global_mass.jl")

end
10 changes: 10 additions & 0 deletions src/global_mass.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/ModelReduction.jl/blob/master/LICENSE

function global_mass(m, N)
M = zeros(N,N)
for i=1:N-1
M[i:i+1,i:i+1] += m
end
return M
end
10 changes: 10 additions & 0 deletions src/global_stiffness.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/ModelReduction.jl/blob/master/LICENSE

function global_stiffness(k, N)
K = zeros(N,N)
for i=1:N-1
K[i:i+1,i:i+1] += k
end
return K
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ using ModelReduction
using Base.Test

@testset "ModelReduction.jl" begin
include("test_global_stiffness.jl")
include("test_global_mass.jl")
end
19 changes: 19 additions & 0 deletions test/test_global_mass.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/ModelReduction.jl/blob/master/LICENSE

using ModelReduction

m = [1 0; 0 1]

N = 5

@testset "Build the global mass matrix" begin
expected =
[1.0 0.0 0.0 0.0 0.0;
0.0 2.0 0.0 0.0 0.0;
0.0 0.0 2.0 0.0 0.0;
0.0 0.0 0.0 2.0 0.0;
0.0 0.0 0.0 0.0 1.0]
result = ModelReduction.global_mass(m, N)
@test result expected
end
19 changes: 19 additions & 0 deletions test/test_global_stiffness.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/ModelReduction.jl/blob/master/LICENSE

using ModelReduction

k = [1 -1; -1 1]

N = 5

@testset "Build the global stiffness matrix" begin
expected =
[1.0 -1.0 0.0 0.0 0.0;
-1.0 2.0 -1.0 0.0 0.0;
0.0 -1.0 2.0 -1.0 0.0;
0.0 0.0 -1.0 2.0 -1.0;
0.0 0.0 0.0 -1.0 1.0]
result = ModelReduction.global_stiffness(k, N)
@test result expected
end

0 comments on commit 80b4f79

Please sign in to comment.