From c7a82ad1423ae135b799a6e1660f130a1b37de6f Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Tue, 3 Jul 2018 14:03:03 +0300 Subject: [PATCH] Refactoring code (#12) - Hopefully someday coming 2d implementation is in separate file beam2d.jl. - Instead of import FEMBase: , use directly FEMBase. --- src/FEMBeam.jl | 23 +---------------------- src/beam2d.jl | 19 +++++++++++++++++++ src/beam3d.jl | 20 ++++++++------------ test/runtests.jl | 12 ++++++++---- test/test_beam2d.jl | 11 +++++++++++ 5 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 src/beam2d.jl create mode 100644 test/test_beam2d.jl diff --git a/src/FEMBeam.jl b/src/FEMBeam.jl index 92972ed..c3897ed 100644 --- a/src/FEMBeam.jl +++ b/src/FEMBeam.jl @@ -10,31 +10,10 @@ using Reexport include("get_beam_stiffness_matrix_2d.jl") include("get_beam_forces_vector_2d.jl") include("get_beam_mass_matrix_2d.jl") - -import FEMBase: get_unknown_field_name, - get_formulation_type, - assemble_elements! - -type Beam2D <: FieldProblem -end - -function get_unknown_field_name(::Problem{Beam2D}) - return "displacement" -end - -function assemble_elements!{B}(::Problem{Beam2D}, ::Assembly, - elements::Vector{Element{B}}, ::Float64) - - for element in elements - info("Not doing anything useful right now.") - end - -end - +include("beam2d.jl") export Beam2D include("beam3d.jl") - export Beam end diff --git a/src/beam2d.jl b/src/beam2d.jl new file mode 100644 index 0000000..41cb740 --- /dev/null +++ b/src/beam2d.jl @@ -0,0 +1,19 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/FEMBeam.jl/blob/master/LICENSE + +type Beam2D <: FieldProblem +end + +function FEMBase.get_unknown_field_name(::Problem{Beam2D}) + return "displacement" +end + +function FEMBase.assemble_elements!{B}(::Problem{Beam2D}, ::Assembly, + elements::Vector{Element{B}}, ::Float64) + + for element in elements + info("Not doing anything useful right now.") + end + + return nothing +end diff --git a/src/beam3d.jl b/src/beam3d.jl index 824d3d5..843bdd4 100644 --- a/src/beam3d.jl +++ b/src/beam3d.jl @@ -13,17 +13,13 @@ Euler-Bernoulli beam, 3d formulation. type Beam <: FieldProblem end -import FEMBase: get_unknown_field_name, - get_formulation_type, - assemble_elements!, - get_integration_points using FEMQuad: get_quadrature_points -function get_unknown_field_name(::Problem{Beam}) +function FEMBase.get_unknown_field_name(::Problem{Beam}) return "displacement" end -function get_integration_points(::Problem{Beam}, ::Element{Seg2}) +function FEMBase.get_integration_points(::Problem{Beam}, ::Element{Seg2}) return get_quadrature_points(Val{:GLSEG3}) end @@ -68,8 +64,8 @@ function get_rotation_matrix(X1, X2, n1) return T end -function assemble_elements!(problem::Problem{Beam}, assembly::Assembly, - elements::Vector{Element{Seg2}}, time::Float64) +function FEMBase.assemble_elements!(problem::Problem{Beam}, assembly::Assembly, + elements::Vector{Element{Seg2}}, time::Float64) B = zeros(4, 12) N = zeros(6, 12) @@ -230,12 +226,12 @@ function assemble_elements!(problem::Problem{Beam}, assembly::Assembly, add!(assembly.f, gdofs, fe) end - nothing + return nothing end -function assemble_elements!(problem::Problem{Beam}, assembly::Assembly, - elements::Vector{Element{Poi1}}, time::Float64) +function FEMBase.assemble_elements!(problem::Problem{Beam}, assembly::Assembly, + elements::Vector{Element{Poi1}}, time::Float64) for element in elements gdofs = get_gdofs(problem, element) @@ -263,6 +259,6 @@ function assemble_elements!(problem::Problem{Beam}, assembly::Assembly, end end - nothing + return nothing end diff --git a/test/runtests.jl b/test/runtests.jl index 7a9f0bf..71a7a4f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,8 @@ # This file is a part of JuliaFEM. # License is MIT: see https://github.com/JuliaFEM/FEMBeam.jl/blob/master/LICENSE -using FEMBase using FEMBeam - -using Base.Test +using FEMBase.Test @testset "Beam 1 Stiffness matrix" begin X1=[0.0,0.0]; X2=[0.0,6.5] @@ -129,6 +127,10 @@ m_expected= @test isapprox(m, m_expected, rtol=0.0001) end +@testset "test beam 2d" begin + include("test_beam2d.jl") +end + @testset "test beam 3D stiffness" begin include("test_beam3d_ex1.jl") end @@ -141,4 +143,6 @@ end include("test_supports.jl") end -@testset "test_rotation_matrix.jl" begin include("test_rotation_matrix.jl") end +@testset "test_rotation_matrix.jl" begin + include("test_rotation_matrix.jl") +end diff --git a/test/test_beam2d.jl b/test/test_beam2d.jl new file mode 100644 index 0000000..691993b --- /dev/null +++ b/test/test_beam2d.jl @@ -0,0 +1,11 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/FEMBeam.jl/blob/master/LICENSE + +using FEMBeam +using FEMBase.Test +beam_element = Element(Seg2, [1, 2]) +problem = Problem(Beam2D, "test problem", 3) +add_elements!(problem, [beam_element]) + +@test get_unknown_field_name(problem) == "displacement" +@test assemble!(problem, 0.0) == nothing