mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-19 09:54:55 +00:00
fixing bugs + adding functionality to api.jl
This commit is contained in:
+31
-6
@@ -10,16 +10,19 @@ element_has_nodes(::Type{Val{:S3}}) = 3
|
||||
element_has_type( ::Type{Val{:S3}}) = Seg3
|
||||
|
||||
"""
|
||||
Checks for if line is a comment line or just empty
|
||||
"""
|
||||
function empty_or_comment_line(line)
|
||||
function empty_or_comment_line{T<:AbstractString}(line::T)
|
||||
startswith(line, "**") || (length(line) == 0)
|
||||
end
|
||||
|
||||
"""
|
||||
Function for parsing nodes from the file
|
||||
"""
|
||||
function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:NODE}})
|
||||
function parse_section(model::Model,
|
||||
lines, key::Symbol, idx_start, idx_end, ::Type{Val{:NODE}})
|
||||
info("Parsing nodes")
|
||||
ids = Integer[]
|
||||
definition = lines[idx_start]
|
||||
for line in lines[idx_start + 1: idx_end]
|
||||
if !(empty_or_comment_line(line))
|
||||
@@ -28,18 +31,28 @@ function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:NODE}}
|
||||
coords = float(m[2:end])
|
||||
node = Node(node_id, coords)
|
||||
add_node!(model, node)
|
||||
push!(ids, node_id)
|
||||
end
|
||||
end
|
||||
has_set_def = match(r"NSET=([\w\_\-]+)", definition)
|
||||
if has_set_def != nothing
|
||||
set_name = has_set_def[1]
|
||||
add_set!(model, Val{:NSET}, set_name, ids)
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
Custon regex to find match from string
|
||||
Custon regex to find match from string. Index used if there are multiple matches
|
||||
"""
|
||||
function regex_match(regex_str, line, idx)
|
||||
return match(regex_str, line).captures[idx]
|
||||
end
|
||||
|
||||
"""
|
||||
Simple iterator for comsuming element list. Depending
|
||||
on the used element, connectivity nodes might be listed
|
||||
in multiple lines, which is why iterator is used to handle
|
||||
this problem.
|
||||
"""
|
||||
function consumeList(arr, start, stop)
|
||||
function _it()
|
||||
@@ -51,8 +64,10 @@ function consumeList(arr, start, stop)
|
||||
end
|
||||
|
||||
"""
|
||||
Parse elements from input.
|
||||
"""
|
||||
function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:ELEMENT}})
|
||||
function parse_section(model::Model, lines, key, idx_start, idx_end, ::Type{Val{:ELEMENT}})
|
||||
# LISÄÄ TOIMINTO, ETTÄ VOI LUKEA SUORAAN ELSETIT
|
||||
definition = uppercase(lines[idx_start])
|
||||
element_type = regex_match(r"TYPE=([\w\-\_]+)", definition, 1)
|
||||
eltype_sym = symbol(element_type)
|
||||
@@ -60,6 +75,7 @@ function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:ELEMEN
|
||||
element_type = element_has_type(Val{eltype_sym})
|
||||
info("Parsing elements. Type: $(element_type)")
|
||||
list_iterator = consumeList(lines, idx_start+1, idx_end)
|
||||
ids = Integer[]
|
||||
line = consume(list_iterator)
|
||||
while line != nothing
|
||||
arr_num_as_str = matchall(r"[0-9]+", line)
|
||||
@@ -76,11 +92,20 @@ function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:ELEMEN
|
||||
end
|
||||
element = Element{element_type}(connectivity)
|
||||
add_element!(model, element)
|
||||
push!(ids, id)
|
||||
end
|
||||
line = consume(list_iterator)
|
||||
end
|
||||
has_set_def = match(r"ELSET=([\w\_\-]+)", definition)
|
||||
if has_set_def != nothing
|
||||
set_name = has_set_def[1]
|
||||
add_set!(model, Val{:ELSET}, set_name, ids)
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
Parsing Node- and ElementSets.
|
||||
"""
|
||||
function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:NSET}}, Type{Val{:ELSET}}})
|
||||
set_regex_string = Dict(:NSET => r"NSET=([\w\-\_]+)",
|
||||
:ELSET => r"ELSET=([\w\-\_]+)" )
|
||||
@@ -106,7 +131,7 @@ function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:
|
||||
end
|
||||
selected_set = key == :NSET ? NodeSet : ElementSet
|
||||
set_alloc = selected_set(set_name, data)
|
||||
add_set(model, set_alloc)
|
||||
add_set!(model, set_alloc)
|
||||
end
|
||||
|
||||
|
||||
@@ -125,11 +150,11 @@ function find_keywords(lines)
|
||||
end
|
||||
|
||||
"""
|
||||
Main function for parsing Abaqus input file.
|
||||
"""
|
||||
function parse_abaqus(fid::IOStream)
|
||||
model = Model()
|
||||
lines = readlines(fid)
|
||||
# info("Registered handlers: $(keys(parse_section))")
|
||||
keyword_indexes = find_keywords(lines)
|
||||
idx_start = keyword_indexes[1]
|
||||
keyword_sym::Symbol = :none
|
||||
|
||||
+54
-12
@@ -19,15 +19,19 @@ typealias HeatFluxBC NeumannBC
|
||||
|
||||
"""
|
||||
"""
|
||||
type Material
|
||||
type Material{S <: AbstractString, T<:Real}
|
||||
name :: AbstractString
|
||||
scalar_data :: Dict{AbstractString, Float64}
|
||||
owners :: Vector
|
||||
scalar_data :: Dict{S, T}
|
||||
end
|
||||
|
||||
Material(name, data) = Material(name, Dict(data))
|
||||
Material(name) = Material(name, Dict{AbstractString, Real}())
|
||||
Material() = Material("", Dict{AbstractString, Real}())
|
||||
|
||||
function Base.setindex!{T <: AbstractString }(material::Material, val::Real, name::T)
|
||||
material.scalar_data[name] = val
|
||||
end
|
||||
|
||||
# Base.set_index(...) = ...
|
||||
# m = Material(jotian)
|
||||
# m["youngs modulus"] = 200e3
|
||||
"""
|
||||
"""
|
||||
type Node{T<:Real}
|
||||
@@ -44,19 +48,31 @@ end
|
||||
#end
|
||||
|
||||
"""
|
||||
Set of nodes. Holds name and the ids
|
||||
"""
|
||||
type NodeSet
|
||||
name :: AbstractString
|
||||
node_ids :: Array{Integer, 1}
|
||||
end
|
||||
|
||||
#julia> type myn
|
||||
# arr :: Array{Integer, 1}
|
||||
# finder :: Dict{Integer, Integer}
|
||||
# end
|
||||
#
|
||||
#julia> myn(arr::Array{Int64, 1}) = myn(arr, Dict(zip(arr, collect(1:length(arr)))))
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
type ElementSet
|
||||
name :: AbstractString
|
||||
element_ids :: Array{Integer, 1}
|
||||
material :: Material
|
||||
end
|
||||
|
||||
ElementSet(name, el_ids) = ElementSet(name, el_ids, Material())
|
||||
|
||||
type LoadCase{ T <: AbstractProblem }
|
||||
problem :: T
|
||||
boundary_conditions :: Vector{BoundaryProblem}
|
||||
@@ -69,7 +85,6 @@ type Model
|
||||
nodes :: Vector{Node}
|
||||
elements :: Vector{Element}
|
||||
sets :: Dict{AbstractString, Union{NodeSet, ElementSet}}
|
||||
material :: Dict{AbstractString, Material}
|
||||
load_cases :: Vector{LoadCase}
|
||||
# settings :: Dict{AbstractString, Real}
|
||||
end
|
||||
@@ -77,9 +92,13 @@ end
|
||||
Model() = Model(Node[],
|
||||
Element[],
|
||||
Dict{AbstractString, Union{NodeSet, ElementSet}}(),
|
||||
Dict{AbstractString, Material}(),
|
||||
LoadCase[],
|
||||
)
|
||||
)
|
||||
|
||||
function set_material!{S <: AbstractString}(model::Model, material::Material, set_name::S)
|
||||
model.sets[set_name].material = material
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
@@ -107,19 +126,42 @@ function add_problems!()
|
||||
end
|
||||
|
||||
"""
|
||||
Get set from model
|
||||
"""
|
||||
function add_element!(model, element)
|
||||
function get_set{S <: AbstractString}(model::Model, name::S)
|
||||
try
|
||||
return model.set[name]
|
||||
catch
|
||||
err("Given set: $(name) does not exist in Model")
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
"""
|
||||
function add_element!(model::Model, element::Element)
|
||||
push!(model.elements, element)
|
||||
end
|
||||
|
||||
"""
|
||||
"""
|
||||
function add_node!(model, node)
|
||||
function add_node!(model::Model, node::Node)
|
||||
push!(model.nodes, node)
|
||||
end
|
||||
|
||||
"""
|
||||
"""
|
||||
function add_set(model, set)
|
||||
function add_set!(model::Model, set::Union{NodeSet, ElementSet})
|
||||
model.sets[set.name] = set
|
||||
end
|
||||
|
||||
function add_set!{S <: AbstractString}(model::Model, ::Type{Val{:NSET}},
|
||||
name::S, ids::Vector{Integer})
|
||||
new_set = NodeSet(name, ids)
|
||||
add_set!(model, new_set)
|
||||
end
|
||||
|
||||
function add_set!{S <: AbstractString}(model::Model, ::Type{Val{:ELSET}},
|
||||
name::S, ids::Vector{Integer})
|
||||
new_set = ElementSet(name, ids)
|
||||
add_set!(model, new_set)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user