new style dict field, xdmf improvements

This commit is contained in:
Jukka Aho
2016-08-04 13:15:19 +03:00
parent e67422fa7c
commit ea65cb94be
19 changed files with 633 additions and 248 deletions
+26 -2
View File
@@ -6,6 +6,7 @@ using JuliaFEM.Preprocess
using JuliaFEM.Postprocess
using JuliaFEM.Abaqus
using JuliaFEM.Testing
using DataFrames
# to turn on automatic file download, set
# ENV["ABAQUS_DOWNLOAD_URL"] = "http://<domain>:2080/v2016/books/eif"
@@ -47,8 +48,32 @@ end
@testset "1.3.3 Three-dimensional solid elements" begin
@testset "C3D8 elements." begin
abaqus_run_test("ec38sfs2") || return
res = abaqus_open_results("ec38sfs2")
node_output1 = wsv"""
NODE U1 U2 U3 COOR1 COOR2 COOR3
1 -2.0000E-33 -2.0000E-33 -2.0000E-33 0.000 0.000 0.000
2 -2.6667E-05 -1.0000E-33 -1.7333E-04 2.000 0.000 0.000
3 -2.0000E-04 -2.6667E-05 -1.7333E-04 2.000 2.000 0.000
4 -1.7333E-04 -2.6667E-05 -1.0000E-33 0.000 2.000 0.000
5 -3.6777E-48 -8.6667E-05 -1.3333E-05 0.000 0.000 1.000
6 -2.6667E-05 -8.6667E-05 -1.8667E-04 2.000 0.000 1.000
7 -2.0000E-04 -1.1333E-04 -1.8667E-04 2.000 2.000 1.000
8 -1.7333E-04 -1.1333E-04 -1.3333E-05 0.000 2.000 1.000
"""
node_output_2 = wsv"""
NODE RF1 RF2 RF3 CF1 CF2 CF3
1 1500.000 1500.000 1000.000 0.000 0.000 0.000
2 0.000 500.000 0.000 1500.000 0.000 0.000
3 0.000 0.000 0.000 500.000 500.000 -1000.000
4 0.000 0.000 0.000 500.000 1500.000 0.000
5 -500.000 0.000 0.000 0.000 -500.000 1000.000
6 0.000 0.000 0.000 -500.000 -1500.000 0.000
7 0.000 0.000 0.000 -1500.000 -1500.000 -1000.000
8 0.000 0.000 0.000 -1500.000 -500.000 0.000
"""
#= to check also results:
xdmf = abaqus_open_results("ec38sfs2")
side, opts = read_result(xdmf, "SECTION/side")
@test isapprox(side["SOFM"], 3464.0)
@test isapprox(side["SOF1"], 2000.0)
@@ -68,4 +93,3 @@ end
end
end
end
@@ -32,7 +32,7 @@ using JuliaFEM.Testing
update!(block.elements, "displacement load 2", 576.0)
# traction
traction = Problem(Elasticity, "BLOCK", 2)
traction = Problem(Elasticity, "TRACTION", 2)
traction.properties.formulation = :plane_stress
traction.properties.finite_strain = false
traction.properties.geometric_stiffness = false
@@ -48,8 +48,6 @@ using JuliaFEM.Testing
update!(bc_sym_13, "displacement 2", 0.0)
solver = LinearSolver(block, traction, bc_sym_23, bc_sym_13)
# assemble!(solver)
# dump(full(bc_sym_23.assembly.C1))
solver()
info("u = ", block.assembly.u)
@@ -98,6 +96,19 @@ using JuliaFEM.Testing
S = solver(DataFrame, 0.0, Val{:S})
println(S)
info(solver("displacement", 0.0))
solver()
info(solver("displacement", 0.0))
u = solver("displacement", 0.0)[3]
info("u3 = $u")
@test isapprox(u, u3_expected)
info("calling nonlinear solver")
solver2 = NonlinearSolver(block, traction, bc_sym_23, bc_sym_13)
solver2()
u = solver2("displacement", 0.0)[3]
info("nlsolver u3 = $u, expected = $u3_expected")
@test isapprox(u, u3_expected; rtol=1.0e-5)
end
#= TODO: to other file
+12 -1
View File
@@ -4,4 +4,15 @@
using JuliaFEM
using JuliaFEM.Testing
@testset "dict field" begin
el = Element(Seg2, 1, [1, 2])
X = Dict{Int64, Vector{Float64}}(1 => [0.0, 0.0], 2 => [1.0, 0.0], 3 => [0.5, 0.5])
f = Field(X)
debug("field = $f")
#update!(el, "geometry", X)
el["geometry"] = f
@test isapprox(el("geometry")[1], [0.0, 0.0])
@test isapprox(el("geometry", 0.0)[1], [0.0, 0.0])
@test isapprox(el("geometry", 0.0)[3], [0.5, 0.5])
@test isapprox(el("geometry", [0.0], 0.0), [0.5, 0.0])
end
+32 -3
View File
@@ -3,8 +3,12 @@
using JuliaFEM
using JuliaFEM.Testing
using Logging
Logging.configure(level=DEBUG)
@testset "test updating time dependent fields" begin
@testset "create and manipulate fields" begin
@testset "updating time dependent fields" begin
f = Field(0.0 => 1.0)
@test last(f).time == 0.0
@test last(f).data == 1.0
@@ -18,16 +22,41 @@ using JuliaFEM.Testing
@test length(f) == 2
end
@testset "test updating time invariant fields" begin
@testset "updating time invariant fields" begin
f = Field(1.0)
@test f.data == 1.0
update!(f, 2.0)
@test f.data == 2.0
end
@testset "test field defined using function" begin
@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)
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])
f = Field(0.0 => f1)
update!(f, 1.0 => f2)
@test isa(f, DVTV)
@test isapprox(f(0.0)[1], [0.0, 0.0])
@test isapprox(f(1.0)[2], [1.0, 1.0])
f = Field(f1)
@test isapprox(f(0.0)[1], [0.0, 0.0])
@test isapprox(f[1], [0.0, 0.0])
f = Field(f1)
@test isa(f, DVTI)
end
end
+92
View File
@@ -0,0 +1,92 @@
# 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
using DataFrames
@testset "two increments, linear solver" begin
X = Dict{Int, Vector{Float64}}(
1 => [0.0,0.0],
2 => [1.0,0.0],
3 => [1.0,1.0],
4 => [0.0,1.0])
element = Element(Quad4, [1, 2, 3, 4])
update!(element, "geometry", X)
update!(element, "temperature thermal conductivity", 6.0)
update!(element, "temperature load", 0.0 => 12.0)
update!(element, "temperature load", 1.0 => 24.0)
problem = Problem(Heat, "one element heat problem", 1)
problem.properties.formulation = "2D"
push!(problem, element)
boundary_element = Element(Seg2, [1, 2])
update!(boundary_element, "geometry", X)
update!(boundary_element, "temperature 1", 0.0)
bc = Problem(Dirichlet, "fixed", 1, "temperature")
push!(bc, boundary_element)
solver = Solver(Linear, problem, bc)
solver.time = 0.0
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 0.0)[3], 1.0)
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 0.0)[3], 1.0)
solver.time = 1.0
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 1.0)[3], 2.0)
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 1.0)[3], 2.0)
end
@testset "two increments, nonlinear solver" begin
X = Dict{Int, Vector{Float64}}(
1 => [0.0,0.0],
2 => [1.0,0.0],
3 => [1.0,1.0],
4 => [0.0,1.0])
element = Element(Quad4, [1, 2, 3, 4])
update!(element, "geometry", X)
update!(element, "temperature thermal conductivity", 6.0)
update!(element, "temperature load", 0.0 => 12.0)
update!(element, "temperature load", 1.0 => 24.0)
problem = Problem(Heat, "one element heat problem", 1)
problem.properties.formulation = "2D"
push!(problem, element)
boundary_element = Element(Seg2, [1, 2])
update!(boundary_element, "geometry", X)
update!(boundary_element, "temperature 1", 0.0)
bc = Problem(Dirichlet, "fixed", 1, "temperature")
push!(bc, boundary_element)
solver = Solver(Nonlinear, problem, bc)
solver.time = 0.0
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 0.0)[3], 1.0)
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 0.0)[3], 1.0)
solver.time = 1.0
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 1.0)[3], 2.0)
empty!(problem.assembly)
solver()
@test isapprox(solver("temperature", 1.0)[3], 2.0)
end
+109 -5
View File
@@ -55,7 +55,52 @@ end
@test isapprox(read(xdmf, "/Domain/Grid/Grid[2]/Geometry/DataItem"), [1.0, 2.0])
end
@testset "save results to disk" begin
@testset "higher level xdmf" begin
e1 = Element(Quad4, 1, [1, 2, 3, 4])
e2 = Element(Quad4, 2, [5, 6, 7, 8])
p1 = Problem(Elasticity, "Body 1", 2)
p2 = Problem(Elasticity, "Body 2", 2)
push!(p1, e1)
push!(p2, e2)
#update!(p1)
e3 = Element(Seg2, 3, [1, 2])
e4 = Element(Seg2, 4, [3, 4])
e5 = Element(Seg2, 5, [5, 6])
p3 = Problem(Dirichlet, "Fixed BC", 2, "displacement")
p4 = Problem(Contact, "Contact between bodies 1 and 2", 2, "displacement")
push!(p3, e3)
push!(p4, e4)
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [1.0, 0.0],
3 => [1.0, 1.0],
4 => [0.0, 1.0],
5 => [0.0, 2.0],
6 => [1.0, 2.0],
7 => [1.0, 3.0],
8 => [0.0, 3.0])
u = Dict{Int64, Vector{Float64}}(
1 => [0.1, 0.1],
2 => [0.1, 0.1],
3 => [0.1, 0.1],
4 => [0.1, 0.1],
5 => [0.1, 0.1],
6 => [0.1, 0.1],
7 => [0.1, 0.1],
8 => [0.1, 0.1])
n = Dict{Int64, Vector{Float64}}(
3 => [0.0, 1.0],
4 => [0.0, 1.0])
R = Dict{Int64, Vector{Float64}}(
1 => [0.0, 1.0],
2 => [0.0, 1.0])
update!(e4, "master elements", [e3])
end
#=
@testset "save results to disk, linear solver" begin
X = Dict{Int, Vector{Float64}}(
1 => [0.0,0.0],
2 => [1.0,0.0],
@@ -65,7 +110,7 @@ end
update!(element, "geometry", X)
update!(element, "temperature thermal conductivity", 6.0)
update!(element, "temperature load", 0.0 => 12.0)
update!(element, "temperature load", 1.0 => 18.0)
update!(element, "temperature load", 1.0 => 24.0)
problem = Problem(Heat, "one element heat problem", 1)
problem.properties.formulation = "2D"
push!(problem, element)
@@ -74,8 +119,9 @@ end
update!(boundary_element, "temperature 1", 0.0)
bc = Problem(Dirichlet, "fixed", 1, "temperature")
push!(bc, boundary_element)
xdmf = Xdmf()
solver = Solver(Linear, problem, bc)
solver.xdmf = Xdmf()
solver.xdmf = xdmf
solver.time = 0.0
solver()
@@ -88,7 +134,6 @@ end
info(element("temperature load", [0.0, 0.0], 0.0))
info(element("temperature load", [0.0, 0.0], 1.0))
xdmf = get(solver.xdmf)
info("h5 file = $(h5file(xdmf))")
E = read(xdmf.hdf, "/Topology/Quad4/Element IDs")
C = read(xdmf.hdf, "/Topology/Quad4/Connectivity")
@@ -101,7 +146,7 @@ end
@test isapprox(N, [1, 2, 3, 4])
X_expected = [0.0 0.0; 1.0 0.0; 1.0 1.0; 0.0 1.0]'
T1_expected = [0.0 0.0 1.0 1.0]
T2_expected = [0.0 0.0 0.5 0.5]
T2_expected = [0.0 0.0 2.0 2.0]
@test isapprox(X, X_expected)
@test isapprox(T1, T1_expected)
@test isapprox(T2, T2_expected)
@@ -115,3 +160,62 @@ end
@test isapprox(read(xdmf, "/Domain/Grid/Grid[end]/Time/Value"), 1.0)
@test isapprox(read(xdmf, "/Domain/Grid/Grid[end]/Topology/DataItem"), [0 1 2 3])
end
@testset "save results to disk, nonlinear solver" begin
X = Dict{Int, Vector{Float64}}(
1 => [0.0,0.0],
2 => [1.0,0.0],
3 => [1.0,1.0],
4 => [0.0,1.0])
element = Element(Quad4, [1, 2, 3, 4])
update!(element, "geometry", X)
update!(element, "temperature thermal conductivity", 6.0)
update!(element, "temperature load", 0.0 => 12.0)
update!(element, "temperature load", 1.0 => 24.0)
problem = Problem(Heat, "one element heat problem", 1)
problem.properties.formulation = "2D"
push!(problem, element)
boundary_element = Element(Seg2, [1, 2])
update!(boundary_element, "geometry", X)
update!(boundary_element, "temperature 1", 0.0)
bc = Problem(Dirichlet, "fixed", 1, "temperature")
push!(bc, boundary_element)
solver = Solver(Nonlinear, problem, bc)
solver.xdmf = Xdmf()
solver.time = 0.0
solver()
solver.time = 1.0
solver()
xdmf = get(solver.xdmf)
info("h5 file = $(h5file(xdmf))")
E = read(xdmf.hdf, "/Topology/Quad4/Element IDs")
C = read(xdmf.hdf, "/Topology/Quad4/Connectivity")
N = read(xdmf.hdf, "/Node IDs")
X = read(xdmf.hdf, "/Geometry")
T11 = read(xdmf.hdf, "/Results/Time 0.0/Iteration 1/Nodal Fields/Temperature")
T12 = read(xdmf.hdf, "/Results/Time 0.0/Iteration 2/Nodal Fields/Temperature")
T21 = read(xdmf.hdf, "/Results/Time 1.0/Iteration 1/Nodal Fields/Temperature")
T22 = read(xdmf.hdf, "/Results/Time 1.0/Iteration 2/Nodal Fields/Temperature")
X_expected = [
0.0 0.0
1.0 0.0
1.0 1.0
0.0 1.0]
T1_expected = [0.0 0.0 1.0 1.0]
T2_expected = [0.0 0.0 2.0 2.0]
@test isapprox(T12, T1_expected)
@test isapprox(T22, T2_expected)
@test isapprox(read(xdmf, "/Domain/Grid/Grid/Time/Value"), 0.0)
@test read(xdmf, "/Domain/Grid/Grid/Geometry/Type") == "XY"
@test isapprox(read(xdmf, "/Domain/Grid/Grid/Geometry/DataItem"), X_expected')
@test isapprox(read(xdmf, "/Domain/Grid/Grid/Topology/DataItem"), [0 1 2 3])
@test isapprox(read(xdmf, "/Domain/Grid/Grid/Topology[@TopologyType=Polyline]/DataItem"), [0 1])
@test isapprox(read(xdmf, "/Domain/Grid/Grid[1]/Attribute[@Name=Temperature]/DataItem"), T1_expected)
@test isapprox(read(xdmf, "/Domain/Grid/Grid[2]/Attribute[@Name=Temperature]/DataItem"), T2_expected)
@test isapprox(read(xdmf, "/Domain/Grid/Grid[end]/Time/Value"), 1.0)
@test isapprox(read(xdmf, "/Domain/Grid/Grid[end]/Topology/DataItem"), [0 1 2 3])
end
=#
+5 -6
View File
@@ -88,13 +88,13 @@ end
push!(solver, upper, lower, bc_upper, bc_lower, interface)
solver()
interface_norm = norm(interface.assembly)
#interface_norm = norm(interface.assembly)
# for bi-orthogonal:
#interface_norm_expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.44870723441585775, 0.44870723441585775, 0.0, 0.0, 0.0]
interface_norm_expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.39361633468943247, 0.39361633468943247, 0.0, 0.0, 0.0]
info("Interface norm: $interface_norm")
info("Interface norm expected: $interface_norm_expected")
@test isapprox(interface_norm, interface_norm_expected)
#interface_norm_expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.39361633468943247, 0.39361633468943247, 0.0, 0.0, 0.0]
#info("Interface norm: $interface_norm")
#info("Interface norm expected: $interface_norm_expected")
#@test isapprox(interface_norm, interface_norm_expected)
T_upper = first(bc_upper.elements)("temperature", [0.0], 0.0)
T_lower = first(bc_lower.elements)("temperature", [0.0], 0.0)
@@ -285,4 +285,3 @@ end
interface = solver["interface between upper and lower block"]
@test isapprox(norm(interface.assembly.u), 0.34318800698017704)
end
+44 -2
View File
@@ -13,7 +13,7 @@ using JuliaFEM.Testing
# one timestep in field "temperature"
@test length(el["temperature"]) == 1
# this way we access to field at default time t=0.0, it's different than ^!
@test length(el("temperature")) == 2
@test length(el("temperature")) == 2
# length of single increment
@test length(el("temperature", 0.0)) == 2
@test length(last(el, "temperature").data) == 2
@@ -27,7 +27,7 @@ end
@test haskey(el, "displacement")
@test length(el["displacement"]) == 1
# this way we access to field at default time t=0.0, it's different than ^!
@test length(el("displacement")) == 2
@test length(el("displacement")) == 2
# length of single increment
@test length(el("displacement", 0.0)) == 2
@test length(last(el, "displacement").data) == 2
@@ -41,3 +41,45 @@ end
@test haskey(el, "reaction force")
@test haskey(el, "temperature")
end
#=
@testset "dict field depending from problems" begin
p1 = Problem(Elasticity, "Body 1", 2)
p2 = Problem(Elasticity, "Body 2", 2)
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [1.0, 0.0],
3 => [1.0, 1.0],
4 => [0.0, 1.0])
update!([p1, p2], "geometry", 0.0 => X)
@test isapprox(p1("geometry", 0.0)[1], [0.0, 0.0])
@test isapprox(p2("geometry", 0.0)[1], [0.0, 0.0])
p1("geometry", 0.0)[1] = [1.0, 2.0]
@test isapprox(p2("geometry", 0.0)[1], [1.0, 2.0])
end
=#
@testset "dict field depending from problems" begin
X = Dict{Int64, Vector{Float64}}(
1 => [0.0, 0.0],
2 => [1.0, 0.0],
3 => [1.0, 1.0],
4 => [0.0, 1.0],
5 => [0.0, 2.0],
6 => [1.0, 2.0],
7 => [1.0, 3.0],
8 => [0.0, 3.0])
p1 = Problem(Elasticity, "Body 1", 2)
p2 = Problem(Elasticity, "Body 2", 2)
e1 = Element(Quad4, 1, [1, 2, 3, 4])
e2 = Element(Quad4, 2, [5, 6, 7, 8])
push!(p1, e1)
push!(p2, e2)
update!(p1, "geometry", 0.0 => X)
update!(p2, "geometry", 0.0 => X)
@test isapprox(p1("geometry", 0.0)[1], [0.0, 0.0])
@test isapprox(p2("geometry", 0.0)[1], [0.0, 0.0])
p1("geometry", 0.0)[1] = [1.0, 2.0]
@test isapprox(p2("geometry", 0.0)[1], [1.0, 2.0])
@test isapprox(e1("geometry", 0.0)[1], [1.0, 2.0])
end