Improvements to preprocess scripts

* convert several elements to node sets in one command

* possibility to find particular node from mesh filtered by node set
This commit is contained in:
Jukka Aho
2017-02-27 07:33:06 +02:00
parent 4a471b5cb7
commit 6248887189
3 changed files with 30 additions and 7 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ module Preprocess
include("preprocess.jl") include("preprocess.jl")
export create_elements, Mesh, add_node!, add_nodes!, add_element!, export create_elements, Mesh, add_node!, add_nodes!, add_element!,
add_elements!, add_element_to_element_set!, add_node_to_node_set!, add_elements!, add_element_to_element_set!, add_node_to_node_set!,
find_nearest_nodes, reorder_element_connectivity! find_nearest_nodes, reorder_element_connectivity!, create_node_set_from_element_set!
include("preprocess_abaqus_reader.jl") include("preprocess_abaqus_reader.jl")
export parse_abaqus, parse_section, parse_element_section, export parse_abaqus, parse_section, parse_element_section,
abaqus_read_mesh, abaqus_read_model abaqus_read_mesh, abaqus_read_model
+16 -6
View File
@@ -50,12 +50,16 @@ function add_node_to_node_set!(mesh::Mesh, set_name, nids...)
end end
""" Create a new node set from nodes in element set. """ """ Create a new node set from nodes in element set. """
function create_node_set_from_element_set!(mesh::Mesh, set_name) function create_node_set_from_element_set!(mesh::Mesh, set_names::String...)
node_ids = Set{Int}() for set_name in set_names
for elid in mesh.element_sets[set_name] set_name = Symbol(set_name)
push!(node_ids, mesh.elements[elid]...) info("Creating node set $set_name from element set")
node_ids = Set{Int}()
for elid in mesh.element_sets[set_name]
push!(node_ids, mesh.elements[elid]...)
end
mesh.node_sets[set_name] = node_ids
end end
mesh.node_sets[set_name] = node_ids
return return
end end
@@ -145,14 +149,20 @@ end
""" find npts nearest nodes from mesh and return id numbers as list. """ """ find npts nearest nodes from mesh and return id numbers as list. """
function find_nearest_nodes(mesh::Mesh, coords::Vector, npts=1) function find_nearest_nodes(mesh::Mesh, coords::Vector{Float64}, npts::Int=1; node_set=nothing)
dist = Dict{Int, Float64}() dist = Dict{Int, Float64}()
for (nid, c) in mesh.nodes for (nid, c) in mesh.nodes
if node_set != nothing && !(nid in mesh.node_sets[Symbol(node_set)])
continue
end
dist[nid] = norm(coords-c) dist[nid] = norm(coords-c)
end end
s = sort(collect(dist), by=x->x[2]) s = sort(collect(dist), by=x->x[2])
nd = s[1:npts] # [(id1, dist1), (id2, dist2), ..., (id_npts, dist_npts)] nd = s[1:npts] # [(id1, dist1), (id2, dist2), ..., (id_npts, dist_npts)]
node_ids = [n[1] for n in nd] node_ids = [n[1] for n in nd]
if length(node_ids) == 1
return first(node_ids)
end
return node_ids return node_ids
end end
+13
View File
@@ -6,6 +6,8 @@ using JuliaFEM.Preprocess
using JuliaFEM.Postprocess using JuliaFEM.Postprocess
using JuliaFEM.Testing using JuliaFEM.Testing
datadir = first(splitext(basename(@__FILE__)))
@testset "renumber element nodes" begin @testset "renumber element nodes" begin
mesh = Mesh() mesh = Mesh()
add_element!(mesh, 1, :Tet10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) add_element!(mesh, 1, :Tet10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
@@ -31,3 +33,14 @@ end
@test mesh.elements[1] == vec @test mesh.elements[1] == vec
@test mesh.elements[11] == vec @test mesh.elements[11] == vec
end end
@testset "find nearest nodes from mesh" begin
meshfile = joinpath(datadir, "block_2d.med")
mesh = aster_read_mesh(meshfile)
create_node_set_from_element_set!(mesh, "LOWER_LEFT", "UPPER_BOTTOM")
# nid 1 coords = (0.0, 0.5), nid 13 coords = (0.0, 0.5)
nid = find_nearest_nodes(mesh, [0.0, 0.5]; node_set="LOWER_LEFT")
@test first(nid) == 1
nid = find_nearest_nodes(mesh, [0.0, 0.5]; node_set="UPPER_BOTTOM")
@test first(nid) == 13
end