Added api.jl and broke abaqus_reader.jl

This commit is contained in:
Olli Väinölä
2015-11-28 13:02:56 +02:00
parent 96e2229f91
commit 1fc701f714
3 changed files with 110 additions and 104 deletions
+3
View File
@@ -83,6 +83,9 @@ include("assembly.jl")
include("solvers.jl")
include("directsolver.jl") # parallel sparse direct solver for non-linear problems
### API ###
include("api.jl")
### MORTAR STUFF ###
include("mortar.jl") # mortar projection
+83 -104
View File
@@ -1,35 +1,13 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
global handlers = Dict()
global ABQ_ELTYPE_HAS_NODES = Dict(
:C3D10 => 10,
:C3D4 => 4,
)
"""
Register new handler for parser
"""
function add_handler(section, function_name)
handlers[section] = function_name
end
function create_or_get(model, key)
if !(key in keys(model))
model[key] = Dict()
end
return model[key]
end
function parse_header(header_line)
args = map(s -> strip(s), split(header_line, ","))
args[1] = strip(args[1], '*')
d = Dict("section" => args[1], "options" => Dict())
options = d["options"]
for k in args[2:end]
args2 = split(k, "=")
options[args2[1]] = args2[2]
end
return d
end
function parse_node_section(model, header, data)
function parse_nodes(model, header, data)
nodes = create_or_get(model, "nodes")
for line in split(data, "\n")
m = matchall(r"[-0-9.]+", line)
@@ -39,89 +17,90 @@ function parse_node_section(model, header, data)
end
end
function parse_element_section(model, header, data)
info("Parsing elements")
eldims = Dict(
"C3D10" => 10,
"C3D4" => 4)
eltype = header["options"]["TYPE"]
if !(eltype in keys(eldims))
throw("Element $eltype dimension information missing")
end
eldim = eldims[eltype]
test_match = matchall(r"[0-9]+", "234, 242")
m = matchall(r"[0-9]+", data)
m = map((s) -> parse(Int, s), m)
elements = create_or_get(model, "elements")
m = reshape(m, eldim+1, round(Int, length(m)/(eldim+1)))
nel = size(m)[2]
info("$nel elements found")
for i=1:nel
elements[m[1,i]] = m[2:end,i]
end
if "ELSET" in keys(header["options"])
elsets = create_or_get(model, "elsets")
elset_name = header["options"]["ELSET"]
info("Creating ELSET $elset_name")
elsets[elset_name] = Int64[]
for i=1:nel
push!(elsets[elset_name], m[1,i])
#function parse_elements(model, header, data)
# info("Parsing elements")
# eldims = Dict(
# "C3D10" => 10,
# "C3D4" => 4)
# eltype = header["options"]["TYPE"]
# if !(eltype in keys(eldims))
# throw("Element $eltype dimension information missing")
# end
# eldim = eldims[eltype]
# test_match = matchall(r"[0-9]+", "234, 242")
# m = matchall(r"[0-9]+", data)
# m = map((s) -> parse(Int, s), m)
# elements = create_or_get(model, "elements")
# m = reshape(m, eldim+1, round(Int, length(m)/(eldim+1)))
# nel = size(m)[2]
# info("$nel elements found")
# for i=1:nel
# elements[m[1,i]] = m[2:end,i]
# end
# if "ELSET" in keys(header["options"])
# elsets = create_or_get(model, "elsets")
# elset_name = header["options"]["ELSET"]
# info("Creating ELSET $elset_name")
# elsets[elset_name] = Int64[]
# for i=1:nel
# push!(elsets[elset_name], m[1,i])
# end
# end
#end
#
#function parse_nodeset(model, header, data)
# nset_name = header["options"]["NSET"]
# info("Creating node set $nset_name")
# data = ASCIIString[]
# m = matchall(r"[0-9]+", data)
# node_ids = map((s) -> parse(Int, s), m)
# nsets = create_or_get(model, "nsets")
# nsets[nset_name] = Int64[]
# for j in node_ids
# push!(nsets[nset_name], j)
# end
#end
parse_section = Dict(:NODE => parse_nodes) # ,
#:ELEMENT => parse_elements,
#:NSET => parse_nodeset,
#:ELSET => parse_elementset)
"""
Find lines, which contain keywords, for example "*NODE"
"""
function find_keywords(lines)
indexes = Integer[]
for (idx, line) in enumerate(lines)
if startswith(line, "*") && !startswith(line, "**")
push!(indexes, idx)
end
end
end
function parse_nodeset_section(model, header, data)
nset_name = header["options"]["NSET"]
info("Creating node set $nset_name")
m = matchall(r"[0-9]+", data)
node_ids = map((s) -> parse(Int, s), m)
nsets = create_or_get(model, "nsets")
nsets[nset_name] = Int64[]
for j in node_ids
push!(nsets[nset_name], j)
end
push!(indexes, length(lines))
indexes
end
function parse_abaqus(fid::IOStream)
model = Dict()
section = nothing
header = nothing
data = ASCIIString[]
info("Registered handlers: $(keys(handlers))")
function process_section(section)
if section == nothing
return
# model = Dict()
lines = readlines(fid)
info("Registered handlers: $(keys(parse_section))")
keyword_indexes = find_keywords(lines)
idx_start = keyword_indexes[1]
keyword_sym::Symbol = :none
for idx_end in keyword_indexes[2:end]
keyword_line = lines[idx_start]
keyword = match(r"\s*(\w+)", keyword_line).match
keyword_sym = :($(uppercase(keyword)))
try
parser = parse_section(keyword_sym)
catch
warn("Keyword not implemented: ", keyword_sym)
idx_start = idx_end
continue
end
if !(section in keys(handlers))
info("Don't know what to do with data in section $section")
info("Skipping $(length(data)) bytes of unknown data")
return
end
joined = join(data, "")
handlers[section](model, header, strip(joined))
empty!(data)
idx_start = idx_end
# parser(model, lines, idx_start, idx_end)
end
line_idx = 0
for line in eachline(fid)
if startswith(line, "**")
continue
end
if startswith(line, "*")
process_section(section)
header = parse_header(line)
section = header["section"]
continue
end
push!(data, line)
end
process_section(section)
return model
# return model
end
# add handlers
add_handler("NODE", parse_node_section)
add_handler("ELEMENT", parse_element_section)
add_handler("NSET", parse_nodeset_section)
+24
View File
@@ -0,0 +1,24 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
type INode{T<:Real}
id::Integer
coords::Array{T, 1}
end
type IElement{T<:Real}
id::Integer
connectivity::Array{T, 1}
element_type::AbstractString
end
type INodeset
node_ids
end
type IElementset
jotain
end