Files
JuliaFEM.jl/test/test_preprocess.jl
T
Jukka Aho 741bb8d057 Fix test
Now both JuliaFEM and JuliaFEM.Preprocess export add_elements! and
it must be spesifically pointed out which one is used in test.
2017-08-16 17:20:55 +03:00

90 lines
3.5 KiB
Julia

# 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.Preprocess
using JuliaFEM.Postprocess
using JuliaFEM.Testing
datadir = first(splitext(basename(@__FILE__)))
@testset "renumber element nodes" begin
mesh = Mesh()
add_element!(mesh, 1, :Tet10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
mapping = Dict{Symbol, Vector{Int}}(
:Tet10 => [1, 2, 4, 3, 5, 6, 7, 8, 9, 10])
reorder_element_connectivity!(mesh, mapping)
@test mesh.elements[1] == [1, 2, 4, 3, 5, 6, 7, 8, 9, 10]
invmapping = Dict{Symbol, Vector{Int}}()
invmapping[:Tet10] = invperm(mapping[:Tet10])
reorder_element_connectivity!(mesh, invmapping)
@test mesh.elements[1] == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
end
@testset "add_nodes! and add_elements!" begin
mesh = Mesh()
dic = Dict(1 => [1.,1.,1.], 2 => [2.,2.,2])
add_nodes!(mesh, dic)
@test mesh.nodes == dic
vec = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
JuliaFEM.Preprocess.add_elements!(mesh,Dict(1=>(:Tet10,vec),
11=>(:Tet10,vec)))
@test mesh.elements[1] == vec
@test mesh.elements[11] == vec
end
@testset "find nearest nodes from mesh" begin
meshfile = joinpath(datadir, "block_2d.med")
mesh = aster_read_mesh(meshfile)
create_node_set_from_element_set!(mesh, "LOWER_LEFT", "UPPER_BOTTOM")
# nid 1 coords = (0.0, 0.5), nid 13 coords = (0.0, 0.5)
nid = find_nearest_node(mesh, [0.0, 0.5]; node_set="LOWER_LEFT")
@test first(nid) == 1
nid = find_nearest_node(mesh, [0.0, 0.5]; node_set="UPPER_BOTTOM")
@test first(nid) == 13
end
@testset "test filter by element set" begin
mesh = aster_read_mesh(joinpath(datadir, "block_2d_1elem_quad4.med"))
mesh2 = filter_by_element_set(mesh, :BLOCK)
@test haskey(mesh2.element_sets, :BLOCK)
@test length(mesh2.elements) == 1
end
function calculate_volume(mesh_name, eltype)
mesh_file = joinpath(datadir, "primitives.med")
mesh = aster_read_mesh(mesh_file, mesh_name)
elements = create_elements(mesh; element_type=eltype)
V = 0.0
time = 0.0
for element in elements
for ip in get_integration_points(element)
detJ = element(ip, time, Val{:detJ})
detJ > 0 || warn("negative determinant for element $eltype !")
V += ip.weight*detJ
end
end
info("volume of $eltype is $V")
return V
end
@testset "calculate volume for 1 element models" begin
@test isapprox(calculate_volume("TRIANGLE_TRI3_1", :Tri3), 1/2)
@test isapprox(calculate_volume("TRIANGLE_TRI6_1", :Tri6), 1/2)
@test isapprox(calculate_volume("TRIANGLE_TRI7_1", :Tri7), 1/2)
@test isapprox(calculate_volume("SQUARE_QUAD4_1", :Quad4), 2^2)
@test isapprox(calculate_volume("SQUARE_QUAD8_1", :Quad8), 2^2)
@test isapprox(calculate_volume("SQUARE_QUAD9_1", :Quad9), 2^2)
@test isapprox(calculate_volume("TETRA_TET4_1", :Tet4), 1/6)
@test isapprox(calculate_volume("TETRA_TET10_1", :Tet10), 1/6)
# @test isapprox(calculate_volume("TETRA_TET14_1", :Tet14), 1/6)
@test isapprox(calculate_volume("CUBE_HEX8_1", :Hex8), 2^3)
@test isapprox(calculate_volume("CUBE_HEX20_1", :Hex20), 2^3)
@test isapprox(calculate_volume("CUBE_HEX27_1", :Hex27), 2^3)
@test isapprox(calculate_volume("WEDGE_WEDGE6_1", :Wedge6), 1)
# @test isapprox(calculate_volume("WEDGE_WEDGE15_1", :Wedge15, 1/2))
# @test isapprox(calculate_volume("PYRAMID_PYRAMID5_1", :Pyramid5, ?))
# @test isapprox(calculate_volume("PYRAMID_PYRAMID13_1", :Pyramid13, ?))
end