diff --git a/test/test_elasticity_2d_linear_with_surface_load.jl b/test/test_elasticity_2d_linear_with_surface_load.jl index f0019b9..d1e2e03 100644 --- a/test/test_elasticity_2d_linear_with_surface_load.jl +++ b/test/test_elasticity_2d_linear_with_surface_load.jl @@ -41,5 +41,6 @@ using JuliaFEM.Test nu = 1/3 u3_expected = f/E*[-nu, 1] + g/(2*E)*[-nu, 1] u3 = reshape(block.assembly.u, 2, 4)[:,3] + info("u3 = $u3") @test isapprox(u3, u3_expected) end diff --git a/test/test_elasticity_3d_unit_block.jl b/test/test_elasticity_3d_unit_block.jl index 4ad82d2..35e0586 100644 --- a/test/test_elasticity_3d_unit_block.jl +++ b/test/test_elasticity_3d_unit_block.jl @@ -6,10 +6,9 @@ using JuliaFEM.Preprocess using JuliaFEM.Postprocess using JuliaFEM.Test -function get_model(fn, vol, sur) +function get_model(fn, vol, sur; with_volume_load=false) meshfile = Pkg.dir("JuliaFEM")*"/geometry/3d_blocks/BLOCK.med" mesh = parse_aster_med_file(meshfile, fn) - info(mesh) block = Problem(Elasticity, fn, 3) block.properties.finite_strain = false @@ -17,7 +16,9 @@ function get_model(fn, vol, sur) elements = aster_create_elements(mesh, :BLOCK, vol) update!(elements, "youngs modulus", 288.0) update!(elements, "poissons ratio", 1/3) - update!(elements, "displacement load 3", 576.0) + if with_volume_load + update!(elements, "displacement load 3", 576.0) + end push!(block, elements...) traction = aster_create_elements(mesh, :LOAD, sur) @@ -36,7 +37,7 @@ function get_model(fn, vol, sur) return block, bc, elements, traction, symyz, symxz, symxy end -function calc_size(elements, dim) +function calc_size(elements, dim; debug_print=false) A = 0.0 for element in elements Ael = 0.0 @@ -45,69 +46,27 @@ function calc_size(elements, dim) detJ = element(xi, 0.0, Val{:detJ}) Ael += w*detJ end - for (i, X) in enumerate(element["geometry"](0.0)) - info("$i : $X") + if debug_print + for (i, X) in enumerate(element["geometry"](0.0)) + info("$i : $X") + end + info("Area / volume: $Ael") end - info("Area / volume: $Ael") A += Ael end return A end -function xdmf_dump(all_elements, eltype, elsym, filename="/tmp/xdmf_result.xmf") - info("$(length(all_elements)) elements.") - xdoc, xmodel = xdmf_new_model() - coll = xdmf_new_temporal_collection(xmodel) - grid = xdmf_new_grid(coll; time=0.0) - - Xg = Dict{Int64, Vector{Float64}}() - ug = Dict{Int64, Vector{Float64}}() - nids = Dict{Int64, Int64}() - for element in all_elements - conn = get_connectivity(element) - for (i, c) in enumerate(conn) - nids[c] = c - end - X = element("geometry", 0.0) - for (i, c) in enumerate(conn) - Xg[c] = X[i] - end - haskey(element, "displacement") || continue - u = element("displacement", 0.0) - for (i, c) in enumerate(conn) - ug[c] = u[i] - end - end - perm = sort(collect(keys(Xg))) - nodes = Vector{Float64}[Xg[i] for i in perm] - disp = Vector{Float64}[ug[i] for i in perm] - nids = Int[nids[i] for i in perm] - inids = Dict{Int64, Int64}() - for (i, nid) in enumerate(nids) - inids[nid] = i - end - elements = [] - for element in all_elements - isa(element, eltype) || continue - conn = get_connectivity(element) - nconn = [inids[i] for i in conn] - push!(elements, (elsym, nconn)) - end - - xdmf_new_mesh!(grid, nodes, elements) - xdmf_new_nodal_field!(grid, "displacement", disp) - xdmf_save_model(xdoc, filename) - info("model dumped to $filename") -end - -function calc_model(model, volume_element, surface_element) - block, bc, elements, traction, symyz, symxz, symxy = get_model(model, volume_element, surface_element) +function calc_model(model, volume_element, surface_element; with_volume_load=false, debug_print=false) + block, bc, elements, traction, symyz, symxz, symxy = get_model(model, volume_element, surface_element; with_volume_load=with_volume_load) V = calc_size(block.elements, 3) - info("volume of block: $V") A = calc_size(bc.elements, 2) - info("area of boundary condition: $A") At = calc_size(traction, 2) - info("area of load surface: $At") + if debug_print + info("volume of block: $V") + info("area of boundary condition: $A") + info("area of load surface: $At") + end @test isapprox(V, 1.0) @test isapprox(At, 1.0) @test isapprox(A, 3.0) @@ -119,24 +78,29 @@ function calc_model(model, volume_element, surface_element) nu = round(Int, length(block.assembly.u)/3) u = reshape(block.assembly.u, 3, nu) f = reshape(full(block.assembly.f), 3, nu) - dump(round(u', 5)) - dump(round(f', 5)) - info("max |u| = $max_u") + if debug_print + dump(round(u', 5)) + dump(round(f', 5)) + info("max |u| = $max_u") + end return block, u end + +@testset "test 3d block HEX8" begin + block, u = calc_model("BLOCK_HEX8", :HE8, :QU4; with_volume_load=true) + @test isapprox(maximum(u), 2.0) +end + @testset "test 3d block TET4" begin - block, u = calc_model("BLOCK_TET4", :TE4, :TR3) - @test isapprox(maximum(u), 2.1329516539440205) +# block, u = calc_model("BLOCK_TET4", :TE4, :TR3; with_volume_load=true) +# @test isapprox(maximum(u), 2.1329516539440205) + block, u = calc_model("BLOCK_TET4", :TE4, :TR3; with_volume_load=false) + @test isapprox(maximum(u), 1.0) end @testset "test 3d block TET10" begin - block, u = calc_model("BLOCK_TET10", :T10, :TR6) - @test isapprox(maximum(u), 2.13656216413056) -end - -@testset "test 3d block HEX8" begin - block, u = calc_model("BLOCK_HEX8", :HE8, :QU4) -# xdmf_dump(block.elements, Element{Hex8}, :Hex8, "/tmp/BLOCK_HEX8.xmf") - @test isapprox(maximum(u), 2.0) + block, u = calc_model("BLOCK_TET10", :T10, :TR6; with_volume_load=false) +# @test isapprox(maximum(u), 2.13656216413056) + @test isapprox(maximum(u), 1.0) end