Skip to content

Commit

Permalink
lint ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojukka5 committed Jul 19, 2017
1 parent d4a783b commit 5befc21
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
12 changes: 5 additions & 7 deletions src/keyword_register.jl
@@ -1,16 +1,16 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md

let register=Set{String}()
global __register__ = Set{String}()

"""
register_abaqus_keyword(keyword::String)
Add ABAQUS keyword `s` to register. That is, after registration every time
keyword show up in `.inp` file a new section is started
"""
global function register_abaqus_keyword(keyword::String)
push!(register, keyword)
function register_abaqus_keyword(keyword::String)
push!(__register__, keyword)
return Type{Val{Symbol(keyword)}}
end

Expand All @@ -19,8 +19,6 @@ end
Return true/false is ABAQUS keyword registered.
"""
global function is_abaqus_keyword_registered(keyword::String)
return keyword in register
end

function is_abaqus_keyword_registered(keyword::String)
return keyword in __register__
end
14 changes: 7 additions & 7 deletions src/parse_mesh.jl
Expand Up @@ -46,8 +46,8 @@ function parse_definition(definition)
set_definition = matchset(definition)
set_definition == nothing && return nothing
for x in set_definition
name, values = map(strip, split(x, "="))
set_defs[lowercase(name)] = values
name, vals = map(strip, split(x, "="))
set_defs[lowercase(name)] = vals
end
set_defs
end
Expand All @@ -73,7 +73,7 @@ end
"""Parse nodes from the lines
"""
function parse_section(model, lines, key::Symbol, idx_start, idx_end, ::Type{Val{:NODE}})
info("Parsing *NODE block between lines $idx_start .. $idx_end")
debug("Parsing $key block between lines $idx_start .. $idx_end")
nnodes = 0
ids = Integer[]
definition = lines[idx_start]
Expand Down Expand Up @@ -123,6 +123,7 @@ Reads element ids and their connectivity nodes from input lines.
If elset definition exists, also adds the set to model.
"""
function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:ELEMENT}})
debug("parse section $key")
ids = Integer[]
definition = lines[idx_start]
element_type = regex_match(r"TYPE=([\w\-\_]+)", definition, 1)
Expand Down Expand Up @@ -167,8 +168,8 @@ function parse_section(model, lines, key, idx_start, idx_end, ::Union{Type{Val{:

if endswith(strip(definition), "GENERATE")
line = lines[idx_start + 1]
first_id, last_id, step = parse_numbers(line, Int)
set_ids = collect(first_id:step:last_id)
first_id, last_id, step_ = parse_numbers(line, Int)
set_ids = collect(first_id:step_:last_id)
push!(data, set_ids...)
else
for line in lines[idx_start + 1: idx_end]
Expand All @@ -184,7 +185,7 @@ end
"""Parse SURFACE keyword
"""
function parse_section(model, lines, key, idx_start, idx_end, ::Type{Val{:SURFACE}})
debug("Parsing surface section")
debug("Parsing surface section $key")
data = Vector{Tuple{Int64, Symbol}}()
definition = lines[idx_start]

Expand Down Expand Up @@ -224,7 +225,6 @@ Function parses Abaqus input file and generates a dictionary of
all the available keywords.
"""
function parse_abaqus(fid::IOStream)
parser::Function = x->()
model = Dict{String, Dict}()
model["nodes"] = Dict{Int64, Vector{Float64}}()
model["node_sets"] = Dict{String, Vector{Int64}}()
Expand Down
38 changes: 21 additions & 17 deletions src/parse_model.jl
Expand Up @@ -149,47 +149,51 @@ function is_new_section(line)
return true
end

function maybe_close_section!(model, state; verbose=true)
# open_section! is called right after keyword is found
function open_section!()
end

# close_section! is called at the end or section or before new keyword
function close_section!()
end

function maybe_close_section!(model, state)
debug("$(model.name): maybe_close_section!")
isnull(state.section) && return
section_name = get(state.section).name
verbose && info("Close section: $section_name")
info("Close section: $section_name")
args = Tuple{Model, AbaqusReaderState, Type{Val{Symbol(section_name)}}}
if method_exists(close_section!, args)
close_section!(model, state, Val{Symbol(section_name)})
else
verbose && warn("no close_section! found for $section_name")
debug("no close_section! found for $section_name")
end
state.section = nothing
end

function maybe_open_section!(model, state; verbose=true)
function maybe_open_section!(model, state)
debug("$(model.name): maybe_open_section!")
section_name = get(state.section).name
section_options = get(state.section).options
verbose && info("New section: $section_name with options $section_options")
info("New section: $section_name with options $section_options")
args = Tuple{Model, AbaqusReaderState, Type{Val{Symbol(section_name)}}}
if method_exists(open_section!, args)
open_section!(model, state, Val{Symbol(section_name)})
else
verbose && warn("no open_section! found for $section_name")
debug("no open_section! found for $section_name")
end
end

function new_section!(model, state, line::AbstractString; verbose=true)
maybe_close_section!(model, state; verbose=verbose)
function new_section!(model, state, line::String)
maybe_close_section!(model, state)
state.data = []
state.section = parse_keyword(line)
maybe_open_section!(model, state; verbose=verbose)
maybe_open_section!(model, state)
end

# open_section! is called right after keyword is found
function open_section! end

# close_section! is called at the end or section or before new keyword
function close_section! end

function process_line!(model, state, line; verbose=false)
function process_line!(model, state, line::String)
if isnull(state.section)
verbose && info("section = nothing! line = $line")
info("section = nothing! line = $line")
return
end
if is_keyword(line)
Expand Down

0 comments on commit 5befc21

Please sign in to comment.