Skip to content

Commit

Permalink
Merge pull request #3 from RohitRathore1/module
Browse files Browse the repository at this point in the history
moved the code and added the tests
  • Loading branch information
mohamed82008 authored Jul 24, 2021
2 parents fdaaaa6 + b95bc9b commit 8540156
Show file tree
Hide file tree
Showing 41 changed files with 3,957 additions and 8 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
32 changes: 32 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
tags: '*'
jobs:
test:
name: Test julia ${{ matrix.julia-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ['1.6',]
os: ['ubuntu-latest',]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
if: ${{ matrix.julia-version == '1.6' && matrix.os == 'ubuntu-latest' }}
- uses: codecov/codecov-action@v1
if: ${{ matrix.julia-version == '1.6' && matrix.os == 'ubuntu-latest' }}
with:
file: lcov.info
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
run: julia -e 'using CompatHelper; CompatHelper.main()'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.vscode
.DS_Store
/Manifest.toml
/test/Manifest.toml
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ uuid = "27704a7e-a4df-40bc-951d-d074625df1c8"
authors = ["JuliaTopOpt contributors"]
version = "0.1.0"

[deps]
AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Einsum = "b7d42ee7-0b51-5a75-98ca-779d3107e4c0"
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
VTKDataTypes = "10d27dd1-1d0f-5a4c-b178-bd2d0045a217"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
julia = "1"

Expand Down
15 changes: 15 additions & 0 deletions src/IO/INP/INP.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module INP

export InpStiffness

using ...TopOptProblems: Metadata, StiffnessTopOptProblem
using Ferrite
using ...Utilities: find_black_and_white, find_varind
import ...TopOptProblems: nnodespercell, getE, getν, getgeomorder, getdensity, getpressuredict, getcloaddict, getfacesets

include(joinpath("Parser", "Parser.jl"))
using .Parser

include("inpstiffness.jl")

end
47 changes: 47 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_cells.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function extract_cells(file, ::Type{TI}=Int) where TI
line = readline(file)

cell_idx_pattern = r"^(\d+)\s*,"
m = match(cell_idx_pattern, line)
first_cell_idx = parse(TI, m[1])

node_idx_pattern = r",\s*(\d+)"
local cells
nodes = TI[]
for m in eachmatch(node_idx_pattern, line)
push!(nodes, parse(TI, m[1]))
end
cells = [Tuple(nodes)]

nextline = _extract_cells!(cells, file, first_cell_idx)
return cells, first_cell_idx-TI(1), nextline
end

function _extract_cells!(cells::AbstractVector{NTuple{nnodes, TI}}, file, prev_cell_idx::TI) where {nnodes, TI}
cell_idx_pattern = r"^(\d+)\s*,"
node_idx_pattern = r",\s*(\d+)"
nodes = zeros(TI, nnodes)

line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(cell_idx_pattern, line)
if m != nothing
cell_idx = parse(TI, m[1])
cell_idx == prev_cell_idx + TI(1) || throw("Cell indices are not consecutive.")

nodes .= zero(TI)
for (i, m) in enumerate(eachmatch(node_idx_pattern, line))
nodes[i] = parse(TI, m[1])
end
all(nodes .!= zero(TI)) || throw("Cell $cell_idx has fewer nodes than it should.")
push!(cells, Tuple(nodes))

prev_cell_idx = cell_idx
end
line = readline(file)
m = match(stopping_pattern, line)
end

return line
end
22 changes: 22 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_cload.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function extract_cload!(cloads::Dict{TI, Vector{TF}}, file, ::Type{Val{dim}}) where {TI, TF, dim}
pattern = r"(\d+)\s*,\s*(\d)\s*,\s*(\-?\d+\.\d*E[\+\-]\d{2})"
line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(pattern, line)
if m != nothing
nodeidx = parse(TI, m[1])
dof = parse(Int, m[2])
load = parse(TF, m[3])
if haskey(cloads, nodeidx)
cloads[nodeidx][dof] += load
else
cloads[nodeidx] = zeros(TF, dim)
cloads[nodeidx][dof] = load
end
end
line = readline(file)
m = match(stopping_pattern, line)
end
return line
end
64 changes: 64 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_dbcs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function extract_nodedbcs!(node_dbcs::Dict{String, Vector{Tuple{TI,TF}}}, file) where {TI, TF}
pattern_zero = r"([^,]+)\s*,\s*(\d)"
pattern_range = r"([^,]+)\s*,\s*(\d)\s*,\s*(\d)"
pattern_other = r"([^,]+)\s*,\s*(\d)\s*,\s*(\d)\s*,\s*(\-?\d+\.\d*)"
line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(pattern_other, line)
if m != nothing
nodesetname = m[1]
dof1 = parse(TI, m[2])
dof2 = parse(TI, m[3])
val = parse(TF, m[4])
if haskey(node_dbcs, nodesetname)
for dof in dof1:dof2
push!(node_dbcs[nodesetname], (dof, val))
end
else
node_dbcs[nodesetname] = [(dof1, val)]
for dof in dof1+1:dof2
push!(node_dbcs[nodesetname], (dof, val))
end
end
line = readline(file)
m = match(stopping_pattern, line)
continue
end
m = match(pattern_range, line)
if m != nothing
nodesetname = m[1]
dof1 = parse(TI, m[2])
dof2 = parse(TI, m[3])
if haskey(node_dbcs, nodesetname)
for dof in dof1:dof2
push!(node_dbcs[nodesetname], (dof, zero(TF)))
end
else
node_dbcs[nodesetname] = [(dof1, zero(TF))]
for dof in dof1+1:dof2
push!(node_dbcs[nodesetname], (dof, zero(TF)))
end
end
line = readline(file)
m = match(stopping_pattern, line)
continue
end
m = match(pattern_zero, line)
if m != nothing
nodesetname = m[1]
dof = parse(TI, m[2])
if haskey(node_dbcs, nodesetname)
push!(node_dbcs[nodesetname], (dof, zero(TF)))
else
node_dbcs[nodesetname] = [(dof, zero(TF))]
end
line = readline(file)
m = match(stopping_pattern, line)
continue
end
line = readline(file)
m = match(stopping_pattern, line)
end
return line
end
42 changes: 42 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_dload.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function extract_dload!(dloads::Dict{String, TF}, facesets::Dict{String, Vector{Tuple{TI,TI}}}, file, ::Type{Val{dim}}, offset::TI) where {TI, TF, dim}
pattern = r"(\d+)\s*,\s*P(\d+)\s*,\s*(\-?\d+\.\d*)"
dload_heading_pattern = r"\*DLOAD"

faceset_name = "DLOAD_SET_$(length(dloads)+1)"
facesets[faceset_name] = Tuple{TI,TI}[]

first = true
prevload = zero(TF)
load = zero(TF)

line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(dload_heading_pattern, line)
if m != nothing
dloads[faceset_name] = load
first = true
faceset_name = "DLOAD_SET_$(length(dloads)+1)"
facesets[faceset_name] = Tuple{TI,TI}[]
end
m = match(pattern, line)
if m != nothing
cellidx = parse(TI, m[1]) - offset
faceidx = parse(TI, m[2])
load = parse(TF, m[3])
if !first && prevload != load
throw("Loads in the same DLOAD set are not equal.")
end
prevload = load
if first
first = false
end
push!(facesets[faceset_name], (cellidx, faceidx))
end
line = readline(file)
m = match(stopping_pattern, line)
end
dloads[faceset_name] = load

return line
end
18 changes: 18 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_material.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function extract_material(file, ::Type{TF}=Float64) where TF
elastic_heading_pattern = r"\*ELASTIC"
Emu_pattern = r"(-?\d+\.?\d*)\s*,\s*(-?\d+\.?\d*)"
line = readline(file)
m = match(elastic_heading_pattern, line)
if m != nothing
line = readline(file)
m = match(Emu_pattern, line)
if m != nothing
E = parse(TF, m[1])
mu = parse(TF, m[2])
end
else
throw("Material not supported.")
end
line = readline(file)
return E, mu, line
end
47 changes: 47 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_nodes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function extract_nodes(file, ::Type{TF}=Float64, ::Type{TI}=Int) where {TF, TI}
line = readline(file)

pattern = r"(\d+)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)\s*(,\s*(-?\d+\.?\d*(e[-\+]?\d*)?))?"
m = match(pattern, line)

first_node_idx = parse(TI, m[1])
first_node_idx == TI(1) || throw("First node index is not 1.")

if m[6] isa Nothing
node_coords = [(parse(TF, m[2]), parse(TF, m[4]))]
nextline = _extract_nodes!(node_coords, file, TI(1))
else
node_coords = [(parse(TF, m[2]), parse(TF, m[4]), parse(TF, m[7]))]
nextline = _extract_nodes!(node_coords, file, TI(1))
end
return node_coords, nextline
end

function _extract_nodes!(node_coords::AbstractVector{NTuple{dim, TF}}, file, prev_node_idx::TI) where {dim, TF, TI}
if dim === 2
pattern = r"(\d+)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)"
elseif dim === 3
pattern = r"(\d+)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)\s*,\s*(-?\d+\.?\d*(e[-\+]?\d*)?)"
else
error("Dimension is not supported.")
end

line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(pattern, line)
if m != nothing
node_idx = parse(Int, m[1])
node_idx == prev_node_idx + TI(1) || throw("Node indices are not consecutive.")
if dim === 2
push!(node_coords, (parse(TF, m[2]), parse(TF, m[4])))
else
push!(node_coords, (parse(TF, m[2]), parse(TF, m[4]), parse(TF, m[6])))
end
prev_node_idx = node_idx
end
line = readline(file)
m = match(stopping_pattern, line)
end
return line
end
26 changes: 26 additions & 0 deletions src/IO/INP/Parser/FeatureExtractors/extract_set.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function extract_set!(sets::Dict{String, TV}, setname::AbstractString, file, offset=0) where {TI, TV<:AbstractVector{TI}}
sets[setname] = Int[]
vector = sets[setname]

pattern_single = r"^(\d+)"
pattern_subset = r"^([^,]+)"
line = readline(file)
m = match(stopping_pattern, line)
while m isa Nothing
m = match(pattern_single, line)
if m != nothing
push!(vector, parse(TI, m[1])-offset)
else
m = match(pattern_subset, line)
if m != nothing
subsetname = String(m[1])
if haskey(sets, subsetname)
append!(vector, sets[subsetname])
end
end
end
line = readline(file)
m = match(stopping_pattern, line)
end
return line
end
Loading

0 comments on commit 8540156

Please sign in to comment.