added functions to add and remove nodes from model

This commit is contained in:
Jukka Aho
2015-06-20 16:00:32 +03:00
parent 6e4b127a36
commit 0f64cabfff
2 changed files with 62 additions and 0 deletions
+45
View File
@@ -71,5 +71,50 @@ function get_field(field_type, field_name; create_if_doesnt_exist=false)
end
function add_nodes(model, nodes)
"""Add new nodes to model.
Parameters
----------
nodes : Dict()
id => coords
Returns
-------
model
Notes
-----
Create new field "coords" to model if not found
"""
println("Adding ", length(nodes), " nodes to model")
field = get_field(model.nodes, "coords"; create_if_doesnt_exist=true)
for (node_id, coords) in nodes
field[node_id] = coords
end
end
function get_nodes(model, node_ids)
"""Return subset of nodes from model.
Parameters
----------
node_ids : array
list of node ids to return
Returns
-------
Dict()
id => coords
"""
subset = Dict()
for node_id in node_ids
subset[node_id] = model.nodes["coords"][node_id]
end
return subset
end
end # module
+17
View File
@@ -1,6 +1,7 @@
using JuliaFEM
using Base.Test
function test_create_model()
m = new_model()
fn = fieldnames(m)
@@ -11,12 +12,14 @@ function test_create_model()
@assert :element_gauss_points in fn
end
function test_add_field()
m = new_model()
field = new_field(m.elements, "color")
@assert "color" in keys(m.elements)
end
function test_get_field()
m = new_model()
field = new_field(m.elements, "color")
@@ -25,6 +28,7 @@ function test_get_field()
@assert field2[1] == "red"
end
function test_get_field_if_it_doesnt_exist()
m = new_model()
# FIXME: how to test exception?
@@ -36,6 +40,19 @@ function test_get_field_if_it_doesnt_exist()
end
function test_add_and_get_nodes()
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)
subset = get_nodes(m, [2, 3])
@assert length(subset) == 2
@assert subset[2] == [1.0, 0.0, 0.0]
@assert subset[3] == [0.0, 1.0, 0.0]
end
# write your own tests here
# @test 1 == JuliaFEM.test()
# @test_approx_eq 1.0 1.0