Skip to content

Commit

Permalink
Merge 14dca54 into 110acde
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojukka5 committed Nov 16, 2017
2 parents 110acde + 14dca54 commit d542756
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/FEMBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export Poi1, Seg2, Seg3, Tri3, Tri6, Tri7, Quad4, Quad8, Quad9,
export update!, add_elements!, add!, get_gdofs, group_by_element_type,
get_unknown_field_name, get_unknown_field_dimension,
get_integration_points, initialize!, assemble!
export DCTI, DVTI, DCTV, DVTV, CCTI, CVTI, CCTV, CVTV

end
5 changes: 5 additions & 0 deletions src/assembly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function assemble!(problem::Problem, time=0.0; auto_initialize=true)
return true
end

function assemble!{P}(assembly::Assembly, problem::Problem{P}, element::Element, time)
warn("One must define assemble! function for problem of type $P. Not doing anything.")
return nothing
end

function assemble!(assembly::Assembly, problem::Problem, elements::Vector{Element}, time)
warn("assemble!() this is default assemble operation, decreased performance can be expected without preallocation of memory!")
for element in elements
Expand Down
5 changes: 5 additions & 0 deletions src/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ function get_unknown_field_dimension(problem::Problem)
return problem.dimension
end

function get_unknown_field_name{P<:AbstractProblem}(::Type{P})
warn("The name of unknown field (e.g. displacement, temperature, ...) of the problem type must be given by defining function `get_unknown_field_name`")
return "N/A"
end

""" Return the name of the unknown field of this problem. """
function get_unknown_field_name{P}(problem::Problem{P})
return get_unknown_field_name(P)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using TimerOutputs
const to = TimerOutput()

test_files = String[]
push!(test_files, "test_add_elements.jl")
push!(test_files, "test_common_failures.jl")
push!(test_files, "test_elements.jl")

@testset "FEMBase.jl" begin
for fn in test_files
Expand Down
16 changes: 16 additions & 0 deletions test/test_add_elements.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/FEMBase.jl/blob/master/LICENSE

using FEMBase
using Base.Test

type Dummy <: FEMBase.FieldProblem
end

@testset "add elements to problem" begin
problem = Problem(Dummy, "test", 2)
element = Element(Quad4, [1, 2, 3, 4])
elements = [element]
add_elements!(problem, elements)
@test problem.elements[1] == element
end
15 changes: 15 additions & 0 deletions test/test_common_failures.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/FEMBase.jl/blob/master/LICENSE

using FEMBase
using Base.Test

type Dummy <: FieldProblem end

@testset "no unknown field name or assemble!-function defined" begin
el = Element(Quad4, [1, 2, 3, 4])
pr = Problem(Dummy, "problem", 2)
add_elements!(pr, [el])
assemble!(pr)
@test true
end
75 changes: 75 additions & 0 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/FEMBase.jl/blob/master/LICENSE

using FEMBase
using Base.Test

using FEMBase: group_by_element_type

@testset "add time dependent field to element" begin
el = Element(Seg2, [1, 2])
u1 = Vector{Float64}[[0.0, 0.0], [0.0, 0.0]]
u2 = Vector{Float64}[[1.0, 1.0], [1.0, 1.0]]
update!(el, "displacement", 0.0 => u1)
update!(el, "displacement", 1.0 => u2)
@test length(el["displacement"]) == 2
@test isapprox(el("displacement", [0.0], 0.0), [0.0, 0.0])
@test isapprox(el("displacement", [0.0], 0.5), [0.5, 0.5])
@test isapprox(el("displacement", [0.0], 1.0), [1.0, 1.0])
el2 = Element(Poi1, [1])
update!(el2, "force 1", 0.0 => 1.0)
end

@testset "add CVTV field to element" begin
el = Element(Seg2, [1, 2])
f(xi, time) = xi[1]*time
update!(el, "my field", f)
v = el("my field", [1.0], 2.0)
@test isapprox(v, 2.0)
end

@testset "add DCTI to element" begin
el = Element(Quad4, [1, 2, 3, 4])
update!(el, "displacement load", DCTI([4.0, 8.0]))
@test isa(el["displacement load"], DCTI)
@test !isa(el["displacement load"].data, DCTI)
update!(el, "displacement load 2", [4.0, 8.0])
@test isa(el["displacement load 2"], DCTI)
update!(el, "temperature", [1.0, 2.0, 3.0, 4.0])
@test isa(el["temperature"], DVTI)
@test isapprox(el("displacement load", [0.0, 0.0], 0.0), [4.0, 8.0])
end

@testset "interpolate DCTI from element" begin
el = Element(Seg2, [1, 2])
update!(el, "foobar", 1.0)
fb = el("foobar", [0.0], 0.0)
@test isa(fb, Float64)
@test isapprox(fb, 1.0)
end

@testset "add elements to elements" begin
el1 = Element(Seg2, [1, 2])
el2 = Element(Seg2, [3, 4])
update!(el1, "master elements", [el2])
lst = el1("master elements", 0.0)
@test isa(lst, Vector)
end

@testset "extend basis" begin
el = Element(Quad4, [1, 2, 3, 4])
expected = [
0.25 0.00 0.25 0.00 0.25 0.00 0.25 0.00
0.00 0.25 0.00 0.25 0.00 0.25 0.00 0.25]
@test isapprox(el([0.0, 0.0], 0.0, 2), expected)
end

@testset "group elements" begin
e1 = Element(Seg2, [1, 2])
e2 = Element(Quad4, [1, 2, 3, 4])
elements = [e1, e2]
r = group_by_element_type(elements)
@test length(r) == 2
@test first(r[Element{Seg2}]) == e1
@test first(r[Element{Quad4}]) == e2
end

0 comments on commit d542756

Please sign in to comment.