From d8b1926e1f76780fde56d4f40abf8ef45a605e2d Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Wed, 24 Jun 2015 22:37:04 +0300 Subject: [PATCH] lightxml test --- test/test_xdmf.jl | 115 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/test/test_xdmf.jl b/test/test_xdmf.jl index cc3a559..22c51fb 100644 --- a/test/test_xdmf.jl +++ b/test/test_xdmf.jl @@ -1,33 +1,94 @@ -using JuliaFEM -using Base.Test +using FactCheck +using Logging +@Logging.configure(level=INFO) +using LightXML -function test_write_to_xdmf() - m = new_model() - nodes = Dict(1 => [0.0, 0.0, 0.0], - 2 => [1.0, 0.0, 0.0], - 3 => [0.0, 1.0, 0.0], - 4 => [0.0, 0.0, 1.0]) - add_nodes(m, nodes) - el1 = Dict("element_type" => 0x6, "node_ids" => [1, 2, 3, 4]) - elements = [el1] - add_elements(elements) +testdata = """\ + + + + + + + + + + + +""" - # create new field "temperature" for nodal points - f = new_field(m.nodes, "temperature") - f[1] = 0.1 - f[2] = 0.2 - f[3] = 0.3 - # do NOT write to fourth node. +facts("test test data") do + xdoc = XMLDocument() + xroot = create_root(xdoc, "Xdmf") + set_attribute(xroot, "xmlns:xi", "http://www.w3.org/2001/XInclude") + set_attribute(xroot, "Version", "2.1") + domain = new_child(xroot, "Domain") + temporal_collection = new_child(domain, "Grid") + set_attribute(temporal_collection, "CollectionType", "Temporal") + set_attribute(temporal_collection, "GridType", "Collection") + set_attribute(temporal_collection, "Name", "Collection") + geometry = new_child(temporal_collection, "Geometry") + set_attribute(geometry, "Type", "None") + topology = new_child(temporal_collection, "Topology") + set_attribute(topology, "Dimensions", "0") + set_attribute(topology, "Type", "NoTopology") - # export model to xdmf - fn = tempname() - println("temp file: ", fn) - time = 123 - write_xdmf(m, fn, time; fields = ["temperature"]) - - d = h5open(fn) - @test d[123]["temperature"][:] = [0.1, 0.2, 0.3] + grid = new_child(temporal_collection, "Grid") + set_attribute(grid, "Name", "Grid") + time = new_child(grid, "Time") + set_attribute(time, "Value", "123") + geometry = new_child(grid, "Geometry") + set_attribute(geometry, "Type", "XYZ") + dataitem = new_child(geometry, "DataItem") + set_attribute(dataitem, "DataType", "Float") + set_attribute(dataitem, "Dimensions", "12") + set_attribute(dataitem, "Format", "XML") + set_attribute(dataitem, "Precision", "4") + add_text(dataitem, "0 0 0 1 0 0 0 1 0 0 0 1") + topology = new_child(grid, "Topology") + set_attribute(topology, "Dimensions", "1") + set_attribute(topology, "Type", "Mixed") + dataitem = new_child(topology, "DataItem") + set_attribute(dataitem, "DataType", "Int") + set_attribute(dataitem, "Dimensions", "5") + set_attribute(dataitem, "Format", "XML") + set_attribute(dataitem, "Precision", 4) + add_text(dataitem, "6 0 1 2 3") + attribute = new_child(grid, "Attribute") + set_attribute(attribute, "Center", "Cell") + set_attribute(attribute, "Name", "Temperature field") + set_attribute(attribute, "Type", "Scalar") + dataitem = new_child(attribute, "DataItem") + set_attribute(dataitem, "DataType", "Int") + set_attribute(dataitem, "Dimensions", 1) + set_attribute(dataitem, "Format", "XML") + set_attribute(dataitem, "Precision", 4) + add_text(dataitem, "56") + attribute = new_child(grid, "Attribute") + set_attribute(attribute, "Center", "Node") + set_attribute(attribute, "Name", "Density") + set_attribute(attribute, "Type", "Vector") + dataitem = new_child(attribute, "DataItem") + set_attribute(dataitem, "DataType", "Float") + set_attribute(dataitem, "Dimensions", 4) + set_attribute(dataitem, "Format", "XML") + set_attribute(dataitem, "Precision", 4) + add_text(dataitem, "1 2 4 7") + #save_file(xdoc, "/tmp/model.xmf") + @fact string(xdoc) => testdata end -test_write_to_xdmf()