Skip to content

Commit

Permalink
performance
Browse files Browse the repository at this point in the history
  • Loading branch information
CWillberg committed Aug 15, 2024
1 parent 4904d6c commit b1c50cc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/Core/Solver/Verlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function run_solver(
#if solver_options["Material Models"]
#needed because of optional deformation_gradient, Deformed bonds, etc.
# all points to guarantee that the neighbors have coor as coordinates if they are not active
deformed_coorNP1[:, :] = coor[:, :] + uNP1[:, :]
deformed_coorNP1[:, :] .= coor .+ uNP1

@timeit to "upload_to_cores" datamanager.synch_manager(
synchronise_field,
Expand Down Expand Up @@ -532,24 +532,24 @@ function run_solver(
# edit external force densities won't work so easy, because the corresponded volume is in detJ
# force density is for FEM part force
force_densities[find_active(fe_nodes[nodes]), :] +=
external_forces[find_active(fe_nodes[nodes]), :]
@view external_forces[find_active(fe_nodes[nodes]), :]
a[find_active(fe_nodes[nodes]), :] =
force_densities[find_active(fe_nodes[nodes]), :] ./
lumped_mass[find_active(fe_nodes[nodes])] # element wise
forces[find_active(fe_nodes[nodes]), :] =
force_densities[find_active(fe_nodes[nodes]), :]
@view force_densities[find_active(fe_nodes[nodes]), :]

# only for cases in coupling where both the FEM and PD nodes are equal
# TODO discuss design decission
force_densities[find_active(fe_nodes[nodes]), :] ./
volume[find_active(fe_nodes[nodes])]
force_densities[find_active(fe_nodes[nodes]), :] ./=
volume[find_active(fe_nodes[nodes])]

# toggles the value and switch the non FEM nodes to true
nodes = find_active(Vector{Bool}(.~fe_nodes[nodes]))
end
force_densities[nodes, :] +=
external_force_densities[nodes, :] .+
external_forces[nodes, :] ./ volume[nodes]
(@view external_force_densities[nodes, :]) .+
(@view external_forces[nodes, :]) ./ volume[nodes]
a[nodes, :] = force_densities[nodes, :] ./ density[nodes] # element wise
forces[nodes, :] = force_densities[nodes, :] .* volume[nodes]

Expand Down
6 changes: 3 additions & 3 deletions src/MPI_communication/MPI_communication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ function synch_controller_bonds_to_responder(comm::MPI.Comm, overlapnodes, array
if !isempty(overlapnodes[rank+1][jcore]["Controller"])
for iID in overlapnodes[rank+1][jcore]["Controller"]
if dof == 1
send_msg = array[iID]
send_msg = @view array[iID]
else
#TODO: Check if we can remove the [:,:]
send_msg = array[iID][:, :]
send_msg = @view array[iID][:, :]
end
MPI.Isend(send_msg, comm; dest = jcore - 1, tag = 0)
# @debug "Sending $rank -> $(jcore-1)"
Expand All @@ -243,7 +243,7 @@ function synch_controller_bonds_to_responder(comm::MPI.Comm, overlapnodes, array
if dof == 1
recv_msg = similar(array[iID])
else
recv_msg = similar(array[iID][:, :])
recv_msg = similar(@view array[iID][:, :])
end
MPI.Recv!(recv_msg, comm; source = jcore - 1, tag = 0)
# @debug "Receiving $(jcore-1) -> $rank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ function compute_forces(

for (jID, nID) in enumerate(nlist[iID])
# TODO how to make the separation if the datamager is included?
stress_NP1[iID][:, :, :], datamanager = mod.compute_stresses(
stress_NP1[iID], datamanager = mod.compute_stresses(
datamanager,
jID,
dof,
material_parameter,
time,
dt,
strain_increment[iID][:, :, :],
stress_N[iID][:, :, :],
stress_NP1[iID][:, :, :],
strain_increment[iID],
stress_N[iID],
stress_NP1[iID],
(iID, jID, nID),
)
end
Expand Down Expand Up @@ -292,8 +292,8 @@ function compute_bond_strain(nodes, nlist, deformation_gradient, strain)
for iID in nodes
strain[iID][:, :, :] = compute_strain(
eachindex(nlist[iID]),
deformation_gradient[iID][:, :, :],
strain[iID][:, :, :],
(@view deformation_gradient[iID][:, :, :]),
(@view strain[iID][:, :, :]),
)
end
return strain
Expand Down
2 changes: 1 addition & 1 deletion src/Physics/Material/Material_Models/Correspondence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function calculate_bond_force(
stress_NP1[iID, :, :],
deformation_gradient[iID, :, :],
) *
inverse_shape_tensor[iID, :, :]
(@view inverse_shape_tensor[iID, :, :])

end
return bond_force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ function compute_stresses(
get_Hooke_matrix(material_parameter, material_parameter["Symmetry"], dof, iID)

stress_NP1[iID, :, :] =
voigt_to_matrix(hookeMatrix * matrix_to_voigt(strain_increment[iID, :, :])) +
stress_N[iID, :, :]
voigt_to_matrix(hookeMatrix * matrix_to_voigt(@view strain_increment[iID, :, :])) +
@view stress_N[iID, :, :]
return stress_NP1, datamanager
end

Expand Down
11 changes: 8 additions & 3 deletions src/Physics/Material/material_basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function get_all_elastic_moduli(
end
end




"""
get_Hooke_matrix(parameter::Dict, symmetry::String, dof::Int64, ID::Int64=1)
Expand Down Expand Up @@ -285,21 +288,23 @@ function distribute_forces(
) > 0
bond_mod[neighborID, :] .= 0
else
bond_mod[neighborID, :] = abs.(bond_norm[iID][neighborID, :])
bond_mod[neighborID, :] = abs.(@view bond_norm[iID][neighborID, :])
end
end
end

force_densities[iID, :] .+= transpose(
sum(
bond_damage[iID] .* bond_force[iID][:, :] .* bond_mod .* volume[nlist[iID]],
bond_damage[iID] .* (@view bond_force[iID][:, :]) .* bond_mod .*
volume[nlist[iID]],
dims = 1,
),
)

# force_densities[nlist[iID], :] .-= bond_damage[iID] .* bond_force[iID] .* bond_mod .* volume[iID]
force_densities[nlist[iID], :] .-=
bond_damage[iID] .* bond_force[iID][:, :] .* bond_mod[:, :] .* volume[iID]
bond_damage[iID] .* (@view bond_force[iID][:, :]) .* (@view bond_mod[:, :]) .*
volume[iID]
end
return force_densities
end
Expand Down
2 changes: 1 addition & 1 deletion src/Support/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function calculate_bond_length(
nlist::Vector{Int64},
)

bond_vectors = coor[nlist, :] .- coor[iID, :]'
bond_vectors = (@view coor[nlist, :]) .- (@view coor[iID, :])'
# distances = sqrt.(sum(bond_vectors .^ 2, dims=2))[:]

# Check for identical point coordinates
Expand Down

0 comments on commit b1c50cc

Please sign in to comment.