Skip to content

Commit

Permalink
improved speed
Browse files Browse the repository at this point in the history
  • Loading branch information
CWillberg committed Nov 12, 2024
1 parent dd365a3 commit dfa86cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function compute_model(

# optimizing, because if no damage it has not to be updated
# TBD update_list should be used here as in shape_tensor.jl
@timeit to "Weighted Volume" weighted_volume = compute_weighted_volume(
@timeit to "Weighted Volume" compute_weighted_volume(
weighted_volume,
nodes,
nlist,
Expand All @@ -151,7 +151,7 @@ function compute_model(
omega,
volume,
)
@timeit to "Dilatation" theta = compute_dilatation(
@timeit to "Dilatation" compute_dilatation(
nodes,
nneighbors,
nlist,
Expand All @@ -161,6 +161,7 @@ function compute_model(
volume,
weighted_volume,
omega,
theta,
)
@timeit to "elastic" bond_force_deviatoric_part, bond_force_isotropic_part = elastic(
nodes,
Expand Down
25 changes: 15 additions & 10 deletions src/Support/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ export compute_deformation_gradients!


"""
bond_geometry!(nodes::Union{SubArray,Vector{Int64}}, nlist, coor, undeformed_bond, undeformed_bond_length)
bond_geometry(undeformed_bond::Vector{Vector{Vector{Float64}}},
undeformed_bond_length::Vector{Vector{Float64}},
nodes::Union{SubArray,Vector{Int64}},
nlist::Vector{Vector{Int64}},
coor::Union{SubArray,Matrix{Float64},Matrix{Int64}},
Calculate bond geometries between nodes based on their coordinates.
# Arguments
- `undeformed_bond`: A preallocated array or data structure to store bond geometries.
- `undeformed_bond_length`: A preallocated array or data structure to store bond distances.
- `nodes::Union{SubArray,Vector{Int64}}`: A vector of integers representing node IDs.
- `nlist`: A data structure (e.g., a list or array) representing neighboring node IDs for each node.
- `coor`: A matrix representing the coordinates of each node.
- `undeformed_bond`: A preallocated array or data structure to store bond geometries.
- `undeformed_bond_length`: A preallocated array or data structure to store bond distances.
# Output
- `undeformed_bond`: An updated `undeformed_bond` array with calculated bond geometries.
Expand Down Expand Up @@ -141,7 +146,7 @@ function compute_shape_tensors!(
volume,
omega[iID],
bond_damage[iID],
undeformed_bond[iID],
mapreduce(permutedims, vcat, undeformed_bond[iID]),
nlist,
iID,
)
Expand Down Expand Up @@ -180,8 +185,8 @@ function compute_shape_tensor!(
Cmn = zero(eltype(shape_tensor))
@inbounds @fastmath for k axes(undeformed_bond, 1)
Cmn +=
undeformed_bond[k][m] *
undeformed_bond[k][n] *
undeformed_bond[k, m] *
undeformed_bond[k, n] *
volume[nlist[iID][k]] *
omega[k] *
bond_damage[k]
Expand Down Expand Up @@ -271,8 +276,8 @@ function compute_deformation_gradients!(
compute_deformation_gradient!(
temp,
bond_damage[iID],
deformed_bond[iID],
undeformed_bond[iID],
mapreduce(permutedims, vcat, deformed_bond[iID]),
mapreduce(permutedims, vcat, undeformed_bond[iID]),
volume,
omega[iID],
nlist,
Expand Down Expand Up @@ -300,8 +305,8 @@ function compute_deformation_gradient!(
Cmn = zero(eltype(deformation_gradient))
@inbounds @fastmath for k axes(undeformed_bond, 1)
Cmn +=
deformed_bond[k][m] *
undeformed_bond[k][n] *
deformed_bond[k, m] *
undeformed_bond[k, n] *
volume[nlist[iID][k]] *
omega[k] *
bond_damage[k]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ using .Ordinary
0.8615883,
]
vec = Vector{Int64}(1:nnodes)
weighted_volume = Ordinary.compute_weighted_volume(
Ordinary.compute_weighted_volume(
weighted_volume,
vec,
nlist,
Expand All @@ -97,16 +97,7 @@ using .Ordinary
for iID = 1:nnodes
@test weighted_volume[iID] / weightedTest[iID] - 1 < 1e-6
end
weighted_volume = Ordinary.compute_weighted_volume(
weighted_volume,
Int64[],
nlist,
undeformed_bond_length,
bond_damage,
omega,
volume,
)
@test weighted_volume == []

end

nnodes = 2
Expand All @@ -125,6 +116,7 @@ bond_damage[2][1] = 1

volume = ones(Float64, 2)
weighted_volume = ones(Float64, 2)
theta = zeros(Float64, 2)
omega = [ones(Float64, 2), ones(Float64, 2)]

nlist = [Vector{Int64}(undef, 1), Vector{Int64}(undef, 1)]
Expand All @@ -133,7 +125,7 @@ nlist[2][1] = 2
@testset "compute_dilatation" begin
vec = Vector{Int64}(1:nnodes)
theta = zeros(Float64, 2)
theta = Ordinary.compute_dilatation(
Ordinary.compute_dilatation(
vec,
nneighbors,
nlist,
Expand All @@ -143,11 +135,12 @@ nlist[2][1] = 2
volume,
weighted_volume,
omega,
theta,
)
@test theta[1] == 3.0
@test theta[2] == 3.0
weighted_volume[1] = 0
theta = Ordinary.compute_dilatation(
Ordinary.compute_dilatation(
vec,
nneighbors,
nlist,
Expand All @@ -157,21 +150,11 @@ nlist[2][1] = 2
volume,
weighted_volume,
omega,
theta,
)
@test theta[1] == 0.0
@test theta[2] == 3.0
theta = Ordinary.compute_dilatation(
Int64[],
nneighbors,
nlist,
undeformed_bond_length,
deformed_bond_length,
bond_damage,
volume,
weighted_volume,
omega,
)
@test theta == []

end

@testset "calculate_symmetry_params" begin
Expand Down

0 comments on commit dfa86cf

Please sign in to comment.