Skip to content

Commit

Permalink
test fix and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CWillberg committed Oct 31, 2024
1 parent a0d7c9f commit 3ce7b59
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/Models/Pre_calculation/deformation_gradient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Deformation_Gradient
using DataStructures: OrderedDict
include("../../Support/geometry.jl")
using .Geometry: compute_deformation_gradient
using .Geometry: compute_deformation_gradients
export pre_calculation_name
export init_model
export compute
Expand Down Expand Up @@ -80,9 +80,10 @@ function compute(
deformed_bond = datamanager.get_field("Deformed Bond Geometry", "NP1")
deformation_gradient = datamanager.get_field("Deformation Gradient")
inverse_shape_tensor = datamanager.get_field("Inverse Shape Tensor")

deformation_gradient = compute_deformation_gradient(
dof = datamanager.get_dof()
compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down
58 changes: 42 additions & 16 deletions src/Support/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function bond_associated_deformation_gradient(
end

"""
compute_deformation_gradient(nodes::Union{SubArray, Vector{Int64}}, nlist, volume, omega, bond_damage, undeformed_bond, deformed_bond, inverse_shape_tensor, deformation_gradient)
compute_deformation_gradients(nodes::Union{SubArray, Vector{Int64}}, nlist, volume, omega, bond_damage, undeformed_bond, deformed_bond, inverse_shape_tensor, deformation_gradient)
Calculate the deformation gradient tensor for a set of nodes in a computational mechanics context.
Expand Down Expand Up @@ -252,8 +252,9 @@ inverse_shape_tensor = rand(Float64, length(nodes), dof, dof)
deformation_gradient = zeros(Float64, length(nodes), dof, dof)
"""
function compute_deformation_gradient(
function compute_deformation_gradients(
nodes::Union{SubArray,Vector{Int64}},
dof::Int64,
nlist::Vector{Vector{Int64}},
volume::Vector{Float64},
omega::Vector{Vector{Float64}},
Expand All @@ -263,18 +264,53 @@ function compute_deformation_gradient(
inverse_shape_tensor::Array{Float64,3},
deformation_gradient::Array{Float64,3},
)
if dof == 2
temp = @MMatrix zeros(2, 2)
else
temp = @MMatrix zeros(3, 3)
end
for iID in nodes
deformation_gradient[iID, :, :] = calculate_deformation_gradient(
compute_deformation_gradient(
temp,
bond_damage[iID],
deformed_bond[iID],
undeformed_bond[iID],
volume[nlist[iID]],
volume,
omega[iID],
nlist,
iID,
)
dg = @view deformation_gradient[iID, :, :]
mul!(dg, temp, inverse_shape_tensor[iID, :, :])
end

end

@views deformation_gradient[iID, :, :] *= inverse_shape_tensor[iID, :, :]
function compute_deformation_gradient(
deformation_gradient,
bond_damage,
deformed_bond,
undeformed_bond,
volume::Union{Vector{Int64},Vector{Float64}},
omega,
nlist,
iID,
)
#return (bond_damage .* volume .* omega .* deformed_bond)' * undeformed_bond
@inbounds @fastmath for m axes(deformation_gradient, 1),
n axes(deformation_gradient, 2)

Cmn = zero(eltype(deformation_gradient))
@inbounds @fastmath for k axes(undeformed_bond, 1)
Cmn +=
deformed_bond[k, m] *
undeformed_bond[k, n] *
volume[nlist[iID][k]] *
omega[k] *
bond_damage[k]
end
deformation_gradient[m, n] = Cmn
end
return deformation_gradient
end


Expand Down Expand Up @@ -305,16 +341,6 @@ function compute_left_stretch_tensor(deformation_gradient::Matrix{Float64})
return sqrt(deformation_gradient * deformation_gradient')
end

function calculate_deformation_gradient(
bond_damage,
deformed_bond,
undeformed_bond,
volume::Union{Vector{Int64},Vector{Float64}},
omega,
)
return (bond_damage .* volume .* omega .* deformed_bond)' * undeformed_bond

end


function compute_weighted_deformation_gradient(
Expand Down
Binary file not shown.
15 changes: 10 additions & 5 deletions test/unit_tests/Support/ut_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ end

deformed_coor = copy(coor)

deformation_gradient = PeriLab.IO.Geometry.compute_deformation_gradient(
PeriLab.IO.Geometry.compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down Expand Up @@ -361,8 +362,9 @@ end
deformed_bond,
deformed_bond_length,
)
deformation_gradient = PeriLab.IO.Geometry.compute_deformation_gradient(
PeriLab.IO.Geometry.compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down Expand Up @@ -395,8 +397,9 @@ end
deformed_bond,
deformed_bond_length,
)
deformation_gradient = PeriLab.IO.Geometry.compute_deformation_gradient(
PeriLab.IO.Geometry.compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down Expand Up @@ -433,8 +436,9 @@ end
deformed_bond,
deformed_bond_length,
)
deformation_gradient = PeriLab.IO.Geometry.compute_deformation_gradient(
PeriLab.IO.Geometry.compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down Expand Up @@ -485,8 +489,9 @@ end
dof,
)

deformation_gradient = PeriLab.IO.Geometry.compute_deformation_gradient(
PeriLab.IO.Geometry.compute_deformation_gradients(
nodes,
dof,
nlist,
volume,
omega,
Expand Down

0 comments on commit 3ce7b59

Please sign in to comment.