added basic abaqus inp parser

This commit is contained in:
Jukka Aho
2015-06-25 19:58:26 +03:00
parent 8c182e45bb
commit 11dad1097c
4 changed files with 155 additions and 4 deletions
+2 -3
View File
@@ -1,13 +1,12 @@
# This file is a part of JuliaFEM.
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
module JuliaFEM
VERSION < v"0.4-" && using Docile
# import solvers
include("elasticity_solver.jl")
include("xdmf.jl")
#using elasticity_solver
include("abaqus_reader.jl")
export Model, new_model, new_field, get_field, add_nodes, get_nodes, add_elements, get_elements
+132
View File
@@ -0,0 +1,132 @@
# This file is a part of JuliaFEM. License is MIT: https://github.com/ovainola/JuliaFEM/blob/master/README.md
module abaqus_reader
using Logging
@Logging.configure(level=DEBUG)
VERSION < v"0.4-" && using Docile
eldims = Dict("C3D10" => 10)
global handlers = Dict()
"""
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()
for k in args[2:end]
args2 = split(k, "=")
options[args2[1]] = args2[2]
end
d["options"] = options
return d
end
function parse_node_section(model, header, data)
nodes = create_or_get(model, "nodes")
for line in split(data, "\n")
m = matchall(r"[-0-9.]+", line)
id = parse(Int, m[1])
coords = float(m[2:end])
nodes[id] = coords
end
end
function parse_element_section(model, header, data)
eltype = header["options"]["TYPE"]
if !(eltype in keys(eldims))
throw("Element $eltype dimension information missing")
end
eldim = eldims[eltype]
m = matchall(r"[0-9]+", data)
m = map(integer, m)
elements = create_or_get(model, "elements")
m = reshape(m, eldim+1, round(Int, length(m)/(eldim+1)))
nel = size(m)[2]
Logging.debug("$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"]
Logging.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_section(model, header, data)
nset_name = header["options"]["NSET"]
Logging.debug("Creating node set $nset_name")
m = matchall(r"[0-9]+", data)
node_ids = map(integer, m)
nsets = create_or_get(model, "nsets")
nsets[nset_name] = Int64[]
for j in node_ids
push!(nsets[nset_name], j)
end
end
function parse_abaqus(fid)
model = Dict()
section = None
header = None
data = ""
Logging.info("Registered handlers: $(keys(handlers))")
function process_section(section)
if section == None
return
end
if !(section in keys(handlers))
Logging.info("Don't know what to do with data in section $section")
Logging.info("Skipping $(length(data)) bytes of unknown data")
return
end
handlers[section](model, header, strip(data))
data = ""
end
for line in eachline(fid)
if beginswith(line, "**")
continue
end
if beginswith(line, "*")
process_section(section)
header = parse_header(line)
Logging.debug("Found ", header["section"], " section")
section = header["section"]
continue
end
data *= line
end
process_section(section)
return model
end
# add handlers
add_handler("NODE", parse_node_section)
add_handler("ELEMENT", parse_element_section)
add_handler("NSET", parse_nodeset_section)
end
+4 -1
View File
@@ -102,5 +102,8 @@ function xdmf_new_field(grid, name, source, data)
add_text(dataitem, join(data, " "))
end
function xdmf_save_model(xdoc, filename)
save_file(xdoc, filename)
end
end
end
+17
View File
@@ -0,0 +1,17 @@
using FactCheck
using Logging
@Logging.configure(level=INFO)
using JuliaFEM.abaqus_reader: parse_abaqus
facts("test import abaqus model") do
fid = open("../geometry/3d_beam/palkki.inp")
model = parse_abaqus(fid)
close(fid)
@fact length(model["nodes"]) => 298
@fact length(model["elements"]) => 120
@fact length(model["elsets"]["Body1"]) => 120
@fact length(model["nsets"]["SUPPORT"]) => 9
@fact length(model["nsets"]["LOAD"]) => 9
@fact length(model["nsets"]["TOP"]) => 83
end