Skip to content

Commit

Permalink
Merge 606a2ea into 267e2af
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojukka5 committed Sep 4, 2018
2 parents 267e2af + 606a2ea commit 9c1879c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 27 deletions.
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
language: julia

os:
- linux

julia:
- 0.6
- 0.7
- 1.0
- nightly

matrix:
allow_failures:
- julia: nightly

addons:
apt:
packages:
- hdf5-tools
before_script:
- julia --color=yes -e 'Pkg.clone("https://github.com/JuliaFEM/PkgTestSuite.jl.git")'
- julia --color=yes -e 'using PkgTestSuite; init()'
script:
- julia --color=yes -e 'using PkgTestSuite; test()'

after_success:
- julia --color=yes -e 'using PkgTestSuite; deploy()'
- julia -e 'cd(Pkg.dir("AsterReader")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.6
julia 0.7
FEMBase
HDF5
2 changes: 1 addition & 1 deletion docs/deploy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Documenter

deploydocs(
repo = "github.com/JuliaFEM/AsterReader.jl.git",
julia = "0.6",
julia = "0.7",
target = "build",
deps = nothing,
make = nothing)
18 changes: 17 additions & 1 deletion src/AsterReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
# License is MIT: see https://github.com/JuliaFEM/AsterReader.jl/blob/master/LICENSE

module AsterReader
using HDF5

using FEMBase, HDF5, LinearAlgebra, SparseArrays

"""
parse_node_id(node_name)
Return id number from node name. Usually the node name contains the id number,
i.e. N123 => 123 and so on.
"""
function parse_node_id(node_name)
m = match(r"\d+", node_name)
m != nothing || error("Unable to parse id from node name $node_name.")
return tryparse(Int, m.match)
end

include("read_aster_mesh.jl")
include("read_aster_results.jl")
export aster_read_mesh

end
12 changes: 5 additions & 7 deletions src/read_aster_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function aster_parse_nodes(section; strip_characters=true)
nodes = Dict{Any, Vector{Float64}}()
has_started = false
for line in split(section, '\n')
m = matchall(r"[\w.-]+", line)
m = collect((string(m.match) for m in eachmatch(r"[\w.-]+", line)))
if (length(m) != 1) && (!has_started)
continue
end
Expand All @@ -18,13 +18,13 @@ function aster_parse_nodes(section; strip_characters=true)
break
end
end
to(T, x) = map(x -> parse(T, x), x)
if length(m) == 4
nid = m[1]
if strip_characters
nid = matchall(r"\d", nid)
nid = parse(Int, nid[1])
nodes[parse_node_id(m[1])] = to(Float64, m[2:end])
else
nodes[nid] = to(Float64, m[2:end])
end
nodes[nid] = float(m[2:end])
end
end
return nodes
Expand Down Expand Up @@ -203,5 +203,3 @@ function aster_read_mesh(fn, mesh_name=nothing)
end
return mesh
end


9 changes: 3 additions & 6 deletions src/read_aster_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ function aster_read_nodes(rmed::RMEDFile)
node_coords = reshape(node_coords, nnodes, dim)'
stripper(node_name) = strip(ascii(unsafe_string(pointer(convert(Vector{UInt8}, node_name)))))
node_names = map(stripper, node_names)
# INFO: quite safe assumption is that id is in node name, i.e. N1 => 1, N123 => 123
node_id(node_name) = parse(matchall(r"\d+", node_name)[1])
node_ids = map(node_id, node_names)
node_ids = map(parse_node_id, node_names)
nodes = Dict(j => node_coords[:,j] for j in node_ids)
return nodes
end
Expand All @@ -34,7 +32,7 @@ end
function aster_read_data(rmed::RMEDFile, field_name; field_type=:NODE,
info_fields=true, node_ids=nothing)

if contains(field_name, "ELGA")
if occursin("ELGA", field_name)
field_type = :GAUSS
end

Expand All @@ -46,7 +44,7 @@ function aster_read_data(rmed::RMEDFile, field_name; field_type=:NODE,
if info_fields
field_names = keys(rmed.data["CHA"])
all_fields = join(field_names, ", ")
info("results: $all_fields")
@info("results: $all_fields")
end

chdata = rmed.data["CHA"]["RESU____$field_name"]
Expand All @@ -60,4 +58,3 @@ function aster_read_data(rmed::RMEDFile, field_name; field_type=:NODE,
end
return results
end

1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Documenter
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AsterReader.jl/blob/master/LICENSE

using AsterReader
using Base.Test
using FEMBase, AsterReader, Test, LinearAlgebra, SparseArrays

include(joinpath("..", "docs", "make.jl"))

@testset "AsterReader.jl" begin
include("test_read_aster_mesh.jl")
include("test_read_aster_results.jl")
end

include(joinpath("..", "docs", "deploy.jl"))
2 changes: 1 addition & 1 deletion test/test_read_aster_mesh.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AsterReader.jl/blob/master/LICENSE

using Base.Test
using FEMBase, Test, AsterReader
using AsterReader: aster_parse_nodes, aster_read_mesh, MEDFile, get_element_sets

datadir = first(splitext(basename(@__FILE__)))
Expand Down
2 changes: 1 addition & 1 deletion test/test_read_aster_results.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of JuliaFEM.
# License is MIT: see https://github.com/JuliaFEM/AsterReader.jl/blob/master/LICENSE

using Base.Test
using FEMBase, AsterReader, Test
using AsterReader: RMEDFile, aster_read_data

datadir = first(splitext(basename(@__FILE__)))
Expand Down

0 comments on commit 9c1879c

Please sign in to comment.