-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from RohitRathore1/module
moved the code and added the tests
- Loading branch information
Showing
41 changed files
with
3,957 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
comment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.vscode | ||
.DS_Store | ||
/Manifest.toml | ||
/test/Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.