mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-28 20:46:58 +00:00
Testing/code coverage (#83)
Change the code coverage to green. * removed duplicate code * Removed unused code * removed unmaintained code * DCTI + DVTI refactored * discrete fields refactored and tested * fields are now tested quite well. * Removed obsolete code not used anywhere * Element descriptions to common dictionary * size in global const dictionary also * Added coverage to sparse tools and removed couple unused functions * get nonzero rows from SparseMatrixCSC * bugfix: extending element basis now working and tested * Removed two unused functions from elements.jl * removed useless function * Useless conversion * remove elasticity assembly using ForwardDiff because it's not used anywhere' * Added basic testing for NURBS. Fixed bug in NSolid interpolation. * removed unused functions * Removed some debug stuff * renamed file * removed field assembly posthook, i think not good idea at all * test for nnz(K) == 0 and automatic determination of dofs * Testing that solver is throwing error if having problems with boundary assembly * Removed some unused options. Refactoring. * Moved solver non-related code to elements.jl * Removed custom exception (no need) * unneeded postprocess code * More tests for NURBS elements. * Removed unfinished .mail parser * proper use of Logging package * also read results * renamed test file * create_surface_elements accepts surface name in String now * bugfix: remove zero rows from constraint matrix after manually removing dofs from some boundary assemblies. * New test, displacement 3d patch test * skip displacement field in surface element splitting if not defined * test element splitting and linear surface elements, fails. * Bugfix: Xdmf, not XDMF * removed nonworking tests, requires bugfix * abaqus_read_results is not working -> bug
This commit is contained in:
committed by
Tero Frondelius
parent
ddabc9d82b
commit
c307c1482c
@@ -124,3 +124,10 @@ end
|
||||
@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
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Testing
|
||||
|
||||
@testset "NSeg interpolate" begin
|
||||
element = Element(NSeg, [1, 2])
|
||||
@test element([0.0], 0.0) == [0.5 0.5]
|
||||
@test size(element) == (1, 2)
|
||||
@test is_nurbs(element)
|
||||
element2 = Element(Seg2, [1, 2])
|
||||
@test !is_nurbs(element2)
|
||||
end
|
||||
|
||||
@testset "NSurf interpolate" begin
|
||||
element = Element(NSurf, [1, 2, 3, 4])
|
||||
@test element([0.0, 0.0], 0.0) == [0.25 0.25 0.25 0.25]
|
||||
@test size(element) == (2, 4)
|
||||
@test is_nurbs(element)
|
||||
end
|
||||
|
||||
@testset "NSolid interpolate" begin
|
||||
element = Element(NSolid, [1, 2, 3, 4, 5, 6, 7, 8])
|
||||
@test element([0.0, 0.0, 0.0], 0.0) == [0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125]
|
||||
@test size(element) == (3, 8)
|
||||
@test is_nurbs(element)
|
||||
end
|
||||
+139
-17
@@ -3,13 +3,83 @@
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Testing
|
||||
using Logging
|
||||
Logging.configure(level=DEBUG)
|
||||
|
||||
@testset "create and manipulate fields" begin
|
||||
@testset "discrete, constant, time invariant field" begin
|
||||
@test isa(DCTI(), DCTI)
|
||||
@test DCTI(0.0).data == 0.0
|
||||
@test isa(Field(0.0), DCTI)
|
||||
@test isa(Field(), DCTI)
|
||||
f = DCTI()
|
||||
update!(f, 1.0)
|
||||
@test f.data == 1.0
|
||||
@test DCTI(1) == 1
|
||||
@test length(DCTI(1)) == 1
|
||||
@test f == DCTI(1.0)
|
||||
@test isapprox(f, DCTI(1.0))
|
||||
@test isapprox(f, 1.0)
|
||||
@test 2*f == 2.0 # multiply by constant
|
||||
@test f(1.0) == 1.0 # time interpolation
|
||||
@test isapprox([2.0]''*f, 2.0) # wanted behavior?
|
||||
end
|
||||
|
||||
@testset "updating time dependent fields" begin
|
||||
@testset "discrete, variable, time invariant field" begin
|
||||
@test isa(DVTI(), DVTI)
|
||||
@test DVTI([1.0, 2.0]).data == [1.0, 2.0]
|
||||
@test isa(Field([1.0, 2.0]), DVTI)
|
||||
|
||||
f = DVTI()
|
||||
update!(f, [2.0, 3.0])
|
||||
@test isapprox(f.data, [2.0, 3.0])
|
||||
@test length(f) == 2
|
||||
|
||||
# slicing
|
||||
@test isapprox(f[1], 2.0)
|
||||
@test isapprox(f[[1, 2]], [2.0, 3.0])
|
||||
|
||||
# boolean comparison and multiplying by a constant
|
||||
@test f == DVTI([2.0, 3.0])
|
||||
@test isapprox(2*f, [4.0, 6.0])
|
||||
|
||||
f3 = 2*f
|
||||
@test isa(f3, DVTI)
|
||||
@test f3+f == 3*f
|
||||
@test f3-f == f
|
||||
|
||||
# spatial interpolation
|
||||
N = [1.0, 2.0]
|
||||
@test isapprox(N*f, 8.0)
|
||||
|
||||
# time interpolation
|
||||
@test isapprox(f(1.0), [2.0, 3.0])
|
||||
|
||||
# spatial interpolation of vector valued variable field
|
||||
f2 = DVTI(Vector[[1.0, 2.0], [3.0, 4.0]])
|
||||
@test isapprox(f2[1], [1.0, 2.0])
|
||||
@test isapprox(f2[2], [3.0, 4.0])
|
||||
@test length(f2) == 2
|
||||
@test isapprox(N*f2, [1.0, 2.0] + [6.0, 8.0])
|
||||
|
||||
# iteration of DVTI field
|
||||
s = zeros(2)
|
||||
for j in f2
|
||||
s += j
|
||||
end
|
||||
@test isapprox(s, [4.0, 6.0])
|
||||
|
||||
@test vec(f2) == [1.0, 2.0, 3.0, 4.0]
|
||||
@test isapprox([1.0 2.0]*f, [8.0]'')
|
||||
|
||||
new_data = [2.0, 3.0, 4.0, 5.0]
|
||||
f4 = similar(f2, new_data)
|
||||
@test isa(f4, DVTI)
|
||||
@test isapprox(f4.data[1], [2.0, 3.0])
|
||||
@test isapprox(f4.data[2], [4.0, 5.0])
|
||||
end
|
||||
|
||||
@testset "discrete, constant, time-variant field" begin
|
||||
@test isa(DCTV(), DCTV)
|
||||
f = Field(0.0 => 1.0)
|
||||
@test isa(f, DCTV)
|
||||
@test last(f).time == 0.0
|
||||
@test last(f).data == 1.0
|
||||
update!(f, 0.0 => 2.0)
|
||||
@@ -20,27 +90,81 @@ Logging.configure(level=DEBUG)
|
||||
@test last(f).time == 1.0
|
||||
@test last(f).data == 3.0
|
||||
@test length(f) == 2
|
||||
|
||||
@testset "interpolation in time direction" begin
|
||||
@test isa(f(0.0), DCTI) # converts to time-invariant after time interpolation
|
||||
@test isapprox(f(-1.0), 2.0)
|
||||
@test isapprox(f(0.0), 2.0)
|
||||
@test isapprox(f(0.5), 2.5)
|
||||
@test isapprox(f(1.0), 3.0)
|
||||
@test isapprox(f(2.0), 3.0)
|
||||
end
|
||||
|
||||
# create several time steps at once
|
||||
f = DCTV(0.0 => 1.0, 1.0 => 2.0)
|
||||
@test isapprox(f(0.5), 1.5)
|
||||
|
||||
end
|
||||
|
||||
@testset "updating time invariant fields" begin
|
||||
f = Field(1.0)
|
||||
@test f.data == 1.0
|
||||
update!(f, 2.0)
|
||||
@test f.data == 2.0
|
||||
@testset "discrete, variable, time-variant field" begin
|
||||
@test isa(DVTV(), DVTV)
|
||||
f = Field(0.0 => [1.0, 2.0])
|
||||
@test isa(f, DVTV)
|
||||
@test last(f).time == 0.0
|
||||
@test last(f).data == [1.0, 2.0]
|
||||
update!(f, 0.0 => [2.0, 3.0])
|
||||
@test last(f).time == 0.0
|
||||
@test last(f).data == [2.0, 3.0]
|
||||
@test length(f) == 1
|
||||
update!(f, 1.0 => [3.0, 4.0])
|
||||
@test last(f).time == 1.0
|
||||
@test last(f).data == [3.0, 4.0]
|
||||
@test length(f) == 2
|
||||
|
||||
@testset "interpolation in time direction" begin
|
||||
@test isa(f(0.0), DVTI) # converts to time-invariant after time interpolation
|
||||
@test isapprox(f(-1.0), [2.0, 3.0])
|
||||
@test isapprox(f(0.0), [2.0, 3.0])
|
||||
@test isapprox(f(0.5), [2.5, 3.5])
|
||||
@test isapprox(f(1.0), [3.0, 4.0])
|
||||
@test isapprox(f(2.0), [3.0, 4.0])
|
||||
end
|
||||
|
||||
# create several time steps at once
|
||||
f = DVTV(0.0 => [1.0, 2.0], 1.0 => [2.0, 3.0])
|
||||
@test isapprox(f(0.5), [1.5, 2.5])
|
||||
end
|
||||
|
||||
@testset "field defined using function" begin
|
||||
g(xi, t) = xi[1]*t
|
||||
f = Field(g)
|
||||
v = f([1.0], 2.0)
|
||||
@test isapprox(v, 2.0)
|
||||
@testset "continuous, constant, time-invariant field" begin
|
||||
f = Field(() -> 2.0)
|
||||
@test isapprox(f([1.0], 2.0), 2.0)
|
||||
|
||||
end
|
||||
|
||||
@testset "continuous, constant, time variant field" begin
|
||||
f = Field((time::Float64) -> 2.0*time)
|
||||
@test isapprox(f([1.0], 2.0), 4.0)
|
||||
|
||||
end
|
||||
|
||||
@testset "continuous, variable, time invariant field" begin
|
||||
f = Field((xi::Vector) -> sum(xi))
|
||||
@test isapprox(f([1.0, 2.0], 2.0), 3.0)
|
||||
end
|
||||
|
||||
@testset "continuous, variable, time variant field" begin
|
||||
f = Field((xi::Vector, t::Float64) -> xi[1]*t)
|
||||
@test isapprox(f([1.0], 2.0), 2.0)
|
||||
end
|
||||
|
||||
@testset "unknown function argument for continuous field" begin
|
||||
@test_throws ErrorException Field((a, b, c) -> a*b*c)
|
||||
end
|
||||
|
||||
@testset "dictionary fields" begin
|
||||
f1 = Dict{Int64, Vector{Float64}}(1 => [0.0, 0.0], 2 => [0.0, 0.0])
|
||||
f2 = Dict{Int64, Vector{Float64}}(1 => [1.0, 1.0], 2 => [1.0, 1.0])
|
||||
f = Field(0.0 => f1, 1.0 => f2)
|
||||
debug("field = $f")
|
||||
@test isa(f, DVTV)
|
||||
@test isapprox(f(0.0)[1], [0.0, 0.0])
|
||||
@test isapprox(f(1.0)[2], [1.0, 1.0])
|
||||
@@ -58,5 +182,3 @@ end
|
||||
f = Field(f1)
|
||||
@test isa(f, DVTI)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+10
-15
@@ -3,7 +3,6 @@
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Testing
|
||||
using JuliaFEM: description
|
||||
|
||||
ALL_ELEMENTS = [
|
||||
Seg2, Seg3,
|
||||
@@ -14,6 +13,16 @@ ALL_ELEMENTS = [
|
||||
Hex8, Hex20, Hex27
|
||||
]
|
||||
|
||||
info("basic data for elements implemented so far:")
|
||||
for element_type in [Poi1; ALL_ELEMENTS]
|
||||
element = Element(element_type, Int[])
|
||||
element_length = length(element)
|
||||
element_size = size(element)
|
||||
element_description = description(element)
|
||||
info("Element $element_type, description = $element_description, length = $element_length, size = $element_size")
|
||||
end
|
||||
|
||||
|
||||
ALL_ELEMENTS_NODES = [
|
||||
[1,2], [1,2,3],
|
||||
[1,2,3], [1,2,3,4,5,6], [1,2,3,4,5,6,7],
|
||||
@@ -78,17 +87,3 @@ end
|
||||
@test length(el) == length(vec)
|
||||
end
|
||||
end
|
||||
|
||||
DESC = ["2 node segment", "3 node segment", "3 node triangle",
|
||||
"6 node triangle", "7 node triangle", "4 node quadrangle",
|
||||
"8 node Serendip quadrangle", "9 node quadrangle",
|
||||
"4 node tetrahedral element", "10 node tetrahedral element",
|
||||
"6 node prismatic element (wedge)",
|
||||
"8 node hexahedral element", "20 node hexahedral element",
|
||||
"27 node hexahedral element"]
|
||||
|
||||
@testset "element description" begin
|
||||
for (T, res) in zip(ALL_ELEMENTS, DESC)
|
||||
@test description(Type(T)) == res
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ using JuliaFEM
|
||||
using JuliaFEM.Preprocess
|
||||
using JuliaFEM.Postprocess
|
||||
using JuliaFEM.Testing
|
||||
using JuliaFEM.Abaqus: create_surface_elements
|
||||
|
||||
@testset "test that interface transfers constant field without error" begin
|
||||
meshfile = Pkg.dir("JuliaFEM") * "/test/testdata/block_3d.med"
|
||||
@@ -47,3 +47,32 @@ using JuliaFEM.Testing
|
||||
info("Temperature at point X = $X is T = $T")
|
||||
@test isapprox(T, 100.0)
|
||||
end
|
||||
|
||||
@testset "problem not found from solver" begin
|
||||
s = Solver(Linear, "demo solver")
|
||||
@test_throws KeyError getindex(s, "not_found")
|
||||
end
|
||||
|
||||
@testset "automatic determination of problem dimension if not spesified" begin
|
||||
s = Solver(Linear, "demo solver")
|
||||
p = Problem(Elasticity, "demo problem", 2)
|
||||
push!(s, p)
|
||||
get_field_assembly(s)
|
||||
@test s.ndofs == 0
|
||||
add!(p.assembly.K, [4], [4], [4.0]'')
|
||||
get_field_assembly(s)
|
||||
@test s.ndofs == 4
|
||||
end
|
||||
|
||||
@testset "test for error when overdetermined system and requesting boundary assembly" begin
|
||||
s = Solver(Linear, "demo solver")
|
||||
@test_throws AssertionError get_boundary_assembly(s) # ndofs = 0
|
||||
p1 = Problem(Dirichlet, "bc1", 2, "displacement")
|
||||
p2 = Problem(Dirichlet, "bc2", 2, "displacement")
|
||||
# third dofs constrained
|
||||
add!(p1.assembly.C2, [3], [3], [1.0]'')
|
||||
add!(p2.assembly.C2, [3], [4], [1.0]'')
|
||||
s.ndofs = 4
|
||||
push!(s, p1, p2)
|
||||
@test_throws ErrorException get_boundary_assembly(s)
|
||||
end
|
||||
@@ -17,3 +17,31 @@ end
|
||||
add!(b, sparse(b2))
|
||||
@test isapprox(full(b), full(b2))
|
||||
end
|
||||
|
||||
@testset "Failure to add data to sparse vector due dimensino mismatch" begin
|
||||
b = SparseVectorCOO()
|
||||
@test_throws ErrorException add!(b, [1, 2], [1.0, 2.0, 3.0])
|
||||
end
|
||||
|
||||
@testset "Test combining of SparseMatrixCOO" begin
|
||||
k = convert(Matrix{Float64}, reshape(collect(1:9), 3, 3))
|
||||
dofs1 = [1, 2, 3]
|
||||
dofs2 = [2, 3, 4]
|
||||
A = SparseMatrixCOO()
|
||||
add!(A, dofs1, dofs1, k)
|
||||
add!(A, dofs2, dofs2, k)
|
||||
A1 = full(A)
|
||||
optimize!(A)
|
||||
A2 = full(A)
|
||||
@test isapprox(A1, A2)
|
||||
end
|
||||
|
||||
@testset "resize of sparse matrix and sparse vector" begin
|
||||
A = sparse(rand(3, 3))
|
||||
B = resize_sparse(A, 4, 4)
|
||||
@test size(B) == (4, 4)
|
||||
a = sparse(rand(3))
|
||||
b = resize_sparsevec(a, 4)
|
||||
@test size(b) == (4, )
|
||||
end
|
||||
|
||||
|
||||
+1354
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user