Merge pull request #94 from JuliaFEM/feature/preprocess

Improvements to preprocess scripts
This commit is contained in:
Jukka Aho
2017-02-27 09:24:49 +02:00
committed by GitHub
4 changed files with 36 additions and 7 deletions
+2 -1
View File
@@ -128,7 +128,8 @@ module Preprocess
include("preprocess.jl")
export create_elements, Mesh, add_node!, add_nodes!, add_element!,
add_elements!, add_element_to_element_set!, add_node_to_node_set!,
find_nearest_nodes, reorder_element_connectivity!
find_nearest_nodes, find_nearest_node, reorder_element_connectivity!,
create_node_set_from_element_set!
include("preprocess_abaqus_reader.jl")
export parse_abaqus, parse_section, parse_element_section,
abaqus_read_mesh, abaqus_read_model
+21 -6
View File
@@ -50,15 +50,23 @@ function add_node_to_node_set!(mesh::Mesh, set_name, nids...)
end
""" Create a new node set from nodes in element set. """
function create_node_set_from_element_set!(mesh::Mesh, set_name)
node_ids = Set{Int}()
for elid in mesh.element_sets[set_name]
push!(node_ids, mesh.elements[elid]...)
function create_node_set_from_element_set!(mesh::Mesh, set_names::String...)
for set_name in set_names
set_name = Symbol(set_name)
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
mesh.node_sets[set_name] = node_ids
return
end
function create_node_set_from_element_set!(mesh::Mesh, set_name::Symbol)
create_node_set_from_element_set!(mesh, string(set_name))
end
function add_element!(mesh::Mesh, elid::Int, eltype::Symbol, connectivity::Vector{Int})
mesh.elements[elid] = connectivity
mesh.element_types[elid] = eltype
@@ -145,9 +153,12 @@ end
""" 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}()
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)
end
s = sort(collect(dist), by=x->x[2])
@@ -156,6 +167,10 @@ function find_nearest_nodes(mesh::Mesh, coords::Vector, npts=1)
return node_ids
end
function find_nearest_node(mesh::Mesh, coords::Vector{Float64}; node_set=nothing)
return first(find_nearest_nodes(mesh, coords, 1; node_set=node_set))
end
"""
Apply new node ordering to elements. In JuliaFEM same node ordering is used
than in ABAQUS and if mesh is parsed from FEM format with other node ordering
+13
View File
@@ -6,6 +6,8 @@ using JuliaFEM.Preprocess
using JuliaFEM.Postprocess
using JuliaFEM.Testing
datadir = first(splitext(basename(@__FILE__)))
@testset "renumber element nodes" begin
mesh = Mesh()
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[11] == vec
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_node(mesh, [0.0, 0.5]; node_set="LOWER_LEFT")
@test first(nid) == 1
nid = find_nearest_node(mesh, [0.0, 0.5]; node_set="UPPER_BOTTOM")
@test first(nid) == 13
end
Binary file not shown.