# 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.Postprocess using JuliaFEM.Test testdata = """\ """ function test_write_to_xml() nodes = Vector{Float64}[ [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5], [1.0, 1.0, 1.0], [2.0, 1.0, 1.0], [1.0, 2.0, 1.0], [1.0, 1.0, 2.0], [1.5, 1.0, 1.0], [1.5, 1.5, 1.0], [1.0, 1.5, 1.0], [1.0, 1.0, 1.5], [1.5, 1.0, 1.5], [1.0, 1.5, 1.5]] elements = [ (:Tet10, [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) (:Tet10, [11, 12, 13, 14, 15, 16, 17, 18, 19, 20])] displacement_field = nodes # same structure xdoc, model = JuliaFEM.Postprocess.xdmf_new_model() temporal_collection = JuliaFEM.Postprocess.xdmf_new_temporal_collection(model) grid = JuliaFEM.Postprocess.xdmf_new_grid(temporal_collection; time=1) JuliaFEM.Postprocess.xdmf_new_mesh!(grid, nodes, elements) JuliaFEM.Postprocess.xdmf_new_nodal_field!(grid, "Displacement", displacement_field) JuliaFEM.Postprocess.xdmf_save_model(xdoc, "/tmp/foo.xmf") #info("exported data model: \n$(string(xdoc))") #@test string(xdoc) == testdata d1 = split(string(xdoc), "\n") # d2 = split(testdata, "\n") d2 = open(readlines, Pkg.dir("JuliaFEM")*"/test/testdata/quad_two_tet10.xmf") println("comparing string") for i in 1:length(d1) println("d1: $(d1[i])") println("d2: $(d2[i])") #status = d1 == d2 ? "MATCHES" : "NO MATCH" #info("line: $(d1[i]) $status") #if d1 != d2 # info("should be:\n$(d2[i])") #end d1 == d2 || error("No match") end end @testset "write simple xmf file" 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]) u = Dict{Int64, Vector{Float64}}( 1 => [0.0, 0.0], 2 => [0.0, 0.0], 3 => [0.5, 1.0], 4 => [0.0, 0.0]) n = Dict{Int64, Vector{Float64}}( 2 => [1.0, 0.0], 3 => [1.0, 0.0]) el1 = Element(Quad4, [1, 2, 3, 4]) el2 = Element(Seg2, [2, 3]) update!([el1, el2], "geometry", X) update!([el1, el2], "displacement", u) update!(el2, "normal", n) xdmf = XDMF() xdmf.dimension = 2 xdmf_new_result!(xdmf, [el1, el2], 0.0) xdmf_save_field!(xdmf, [el1, el2], 0.0, "displacement"; field_type="Vector") xdmf_save_field!(xdmf, [el1, el2], 0.0, "normal"; field_type="Vector") xdmf_save!(xdmf, "/tmp/test.xmf") # TODO: how to test? end