Skip to content

Commit

Permalink
optimized distribute_forces
Browse files Browse the repository at this point in the history
  • Loading branch information
JTHesse committed Nov 20, 2024
1 parent 98e874f commit 3f5f360
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/Models/Material/Material_Factory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include("../../Core/Module_inclusion/set_Modules.jl")
include("material_basis.jl")
using LinearAlgebra
using .Material_Basis:
get_all_elastic_moduli, distribute_forces, check_symmetry, get_all_elastic_moduli
get_all_elastic_moduli, distribute_forces!, check_symmetry, get_all_elastic_moduli
using .Set_modules
using TimerOutputs
using StaticArrays
Expand Down Expand Up @@ -246,7 +246,8 @@ function distribute_force_densities(
if !isnothing(nlist_filtered_ids)
bond_norm = datamanager.get_field("Bond Norm")
displacements = datamanager.get_field("Displacements", "NP1")
force_densities = distribute_forces(
force_densities = distribute_forces!(
force_densities,
nodes,
nlist,
nlist_filtered_ids,
Expand All @@ -255,10 +256,9 @@ function distribute_force_densities(
bond_damage,
displacements,
bond_norm,
force_densities,
)
else
distribute_forces(nodes, nlist, bond_force, volume, bond_damage, force_densities)
distribute_forces!(force_densities, nodes, nlist, bond_force, volume, bond_damage)
end

end
Expand Down
15 changes: 7 additions & 8 deletions src/Models/Material/material_basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using .Helpers: get_MMatrix, determinant, invert, smat
export get_value
export get_all_elastic_moduli
export get_Hooke_matrix
export distribute_forces
export distribute_forces!
export flaw_function
export matrix_to_voigt
export voigt_to_matrix
Expand Down Expand Up @@ -275,7 +275,7 @@ function get_Hooke_matrix(parameter::Dict, symmetry::String, dof::Int64, ID::Int
end

"""
distribute_forces(nodes::Union{SubArray,Vector{Int64}}, nlist::Vector{Vector{Int64}}, nlist_filtered_ids::Vector{Vector{Int64}}, bond_force::Vector{Matrix{Float64}}, volume::Vector{Float64}, bond_damage::Vector{Vector{Float64}}, displacements::Matrix{Float64}, bond_norm::Vector{Matrix{Float64}}, force_densities::Matrix{Float64})
distribute_forces!(nodes::Union{SubArray,Vector{Int64}}, nlist::Vector{Vector{Int64}}, nlist_filtered_ids::Vector{Vector{Int64}}, bond_force::Vector{Matrix{Float64}}, volume::Vector{Float64}, bond_damage::Vector{Vector{Float64}}, displacements::Matrix{Float64}, bond_norm::Vector{Matrix{Float64}}, force_densities::Matrix{Float64})
Distribute the forces on the nodes
Expand All @@ -292,7 +292,8 @@ Distribute the forces on the nodes
# Returns
- `force_densities::Matrix{Float64}`: The force densities.
"""
function distribute_forces(
function distribute_forces!(
force_densities::Matrix{Float64},
nodes::Union{SubArray,Vector{Int64}},
nlist::Vector{Vector{Int64}},
nlist_filtered_ids::Vector{Vector{Int64}},
Expand All @@ -301,7 +302,6 @@ function distribute_forces(
bond_damage::Vector{Vector{Float64}},
displacements::Matrix{Float64},
bond_norm::Vector{Vector{Vector{Float64}}},
force_densities::Matrix{Float64},
)

@inbounds @fastmath for iID in nodes
Expand Down Expand Up @@ -339,7 +339,7 @@ function distribute_forces(
end

"""
distribute_forces(nodes::Union{SubArray,Vector{Int64}}, nlist::Vector{Vector{Int64}}, bond_force::Vector{Matrix{Float64}}, volume::Vector{Float64}, bond_damage::Vector{Vector{Float64}}, force_densities::Matrix{Float64})
distribute_forces!(nodes::Union{SubArray,Vector{Int64}}, nlist::Vector{Vector{Int64}}, bond_force::Vector{Matrix{Float64}}, volume::Vector{Float64}, bond_damage::Vector{Vector{Float64}}, force_densities::Matrix{Float64})
Distribute the forces on the nodes
Expand All @@ -353,13 +353,13 @@ Distribute the forces on the nodes
# Returns
- `force_densities::Matrix{Float64}`: The force densities.
"""
function distribute_forces(
function distribute_forces!(
force_densities::Matrix{Float64},
nodes::Union{SubArray,Vector{Int64}},
nlist::Vector{Vector{Int64}},
bond_force::Vector{Vector{Vector{Float64}}},
volume::Vector{Float64},
bond_damage::Vector{Vector{Float64}},
force_densities::Matrix{Float64},
)
@inbounds @fastmath for iID in nodes
@views @inbounds @fastmath for jID axes(nlist[iID], 1)
Expand All @@ -375,7 +375,6 @@ function distribute_forces(
end
end
end
return force_densities
end


Expand Down
8 changes: 4 additions & 4 deletions src/Support/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ Checks if the sum of the array is finite. If not, an error is raised.
- `Bool`: `true` if the sum of the array is finite, `false` otherwise.
"""
function check_inf_or_nan(array, msg)
if !isfinite(sum(array))
@error "Field ''$msg'' is infinite."
return true
end
if isnan(sum(array))
@error "Field ''$msg'' has NaN elements."
return true
end
if !isfinite(sum(array))
@error "Field ''$msg'' is infinite."
return true
end
return false
end

Expand Down
Binary file modified test/fullscale_tests/test_DCB/Reference/DCBmodel_PD_solid.e
Binary file not shown.
15 changes: 11 additions & 4 deletions test/unit_tests/Models/Material/ut_material_basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using .Material_Basis:
get_value,
get_all_elastic_moduli,
get_Hooke_matrix,
distribute_forces,
distribute_forces!,
flaw_function,
matrix_to_voigt,
voigt_to_matrix,
Expand Down Expand Up @@ -72,9 +72,16 @@ end
bond_damage[iID] .* mapreduce(permutedims, vcat, bond_force[iID]) .* volume[iID]
end

result =
distribute_forces(nodes, nlist, bond_force, volume, bond_damage, force_densities)
@test result expected_force_densities
distribute_forces!(
force_densities,
nodes,
nlist,
bond_force,
volume,
bond_damage,
force_densities,
)
@test force_densities expected_force_densities
end
@testset "ut_flaw_function" begin

Expand Down

0 comments on commit 3f5f360

Please sign in to comment.