From 5c5faf987cb89a8d4946e0be0c072a816998496f Mon Sep 17 00:00:00 2001 From: hess_ja Date: Thu, 7 Nov 2024 11:33:44 +0100 Subject: [PATCH] Removed the use of mapreduce --- src/IO/mesh_data.jl | 6 +-- .../Pre_calculation/bond_deformation.jl | 8 +++- src/Support/geometry.jl | 24 +++++------ test/unit_tests/Core/Solver/ut_Verlet.jl | 6 +-- test/unit_tests/IO/ut_mesh_data.jl | 6 +-- test/unit_tests/Support/ut_geometry.jl | 42 +++++++++---------- 6 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/IO/mesh_data.jl b/src/IO/mesh_data.jl index f12d6036..d471f534 100644 --- a/src/IO/mesh_data.jl +++ b/src/IO/mesh_data.jl @@ -365,12 +365,12 @@ function get_bond_geometry(datamanager::Module) undeformed_bond = datamanager.create_constant_bond_field("Bond Geometry", Float64, dof) undeformed_bond_length = datamanager.create_constant_bond_field("Bond Length", Float64, 1) - Geometry.bond_geometry( + Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector{Int64}(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) return datamanager end diff --git a/src/Models/Pre_calculation/bond_deformation.jl b/src/Models/Pre_calculation/bond_deformation.jl index 9be2b1a5..eff01cd5 100644 --- a/src/Models/Pre_calculation/bond_deformation.jl +++ b/src/Models/Pre_calculation/bond_deformation.jl @@ -80,7 +80,13 @@ function compute( deformed_coor = datamanager.get_field("Deformed Coordinates", "NP1") deformed_bond = datamanager.get_field("Deformed Bond Geometry", "NP1") deformed_bond_length = datamanager.get_field("Deformed Bond Length", "NP1") - Geometry.bond_geometry(nodes, nlist, deformed_coor, deformed_bond, deformed_bond_length) + Geometry.bond_geometry!( + deformed_bond, + deformed_bond_length, + nodes, + nlist, + deformed_coor, + ) return datamanager end diff --git a/src/Support/geometry.jl b/src/Support/geometry.jl index 78f12a01..68517518 100644 --- a/src/Support/geometry.jl +++ b/src/Support/geometry.jl @@ -10,13 +10,13 @@ using StaticArrays using Rotations include("helpers.jl") using .Helpers: invert, smat, mat_mul_transpose_mat! -export bond_geometry +export bond_geometry! export compute_shape_tensors! export compute_deformation_gradients! """ - bond_geometry(nodes::Union{SubArray,Vector{Int64}}, nlist, coor, undeformed_bond, undeformed_bond_length) + bond_geometry!(nodes::Union{SubArray,Vector{Int64}}, nlist, coor, undeformed_bond, undeformed_bond_length) Calculate bond geometries between nodes based on their coordinates. @@ -46,12 +46,12 @@ Calculate bond geometries between nodes based on their coordinates. undeformed_bond(nodes, dof, nlist, coor, undeformed_bond) """ -function bond_geometry( +function 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}}, - undeformed_bond::Vector{Vector{Vector{Float64}}}, - undeformed_bond_length::Vector{Vector{Float64}}, ) for iID in nodes @@ -141,7 +141,7 @@ function compute_shape_tensors!( volume, omega[iID], bond_damage[iID], - mapreduce(permutedims, vcat, undeformed_bond[iID]), + undeformed_bond[iID], nlist, iID, ) @@ -180,8 +180,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] @@ -271,8 +271,8 @@ function compute_deformation_gradients!( compute_deformation_gradient!( temp, bond_damage[iID], - mapreduce(permutedims, vcat, deformed_bond[iID]), - mapreduce(permutedims, vcat, undeformed_bond[iID]), + deformed_bond[iID], + undeformed_bond[iID], volume, omega[iID], nlist, @@ -300,8 +300,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] diff --git a/test/unit_tests/Core/Solver/ut_Verlet.jl b/test/unit_tests/Core/Solver/ut_Verlet.jl index 6089df85..c374142f 100644 --- a/test/unit_tests/Core/Solver/ut_Verlet.jl +++ b/test/unit_tests/Core/Solver/ut_Verlet.jl @@ -76,12 +76,12 @@ volume = [0.5, 0.5, 0.5, 0.5, 0.5] density = [1e-6, 1e-6, 3e-6, 3e-6, 1e-6] horizon = [3.1, 3.1, 3.1, 3.1, 3.1] -PeriLab.IO.Geometry.bond_geometry( +PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) blocks = [1, 1, 2, 2, 1] diff --git a/test/unit_tests/IO/ut_mesh_data.jl b/test/unit_tests/IO/ut_mesh_data.jl index e64b7926..db2c1ad7 100644 --- a/test/unit_tests/IO/ut_mesh_data.jl +++ b/test/unit_tests/IO/ut_mesh_data.jl @@ -529,12 +529,12 @@ end test_data_manager.create_constant_bond_field("Bond Geometry", Float64, dof) undeformed_bond_length = test_data_manager.create_constant_bond_field("Bond Length", Float64, 1) - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) @test undeformed_bond[1][1][1] == 1 diff --git a/test/unit_tests/Support/ut_geometry.jl b/test/unit_tests/Support/ut_geometry.jl index f2bfa5ca..52fd4de1 100644 --- a/test/unit_tests/Support/ut_geometry.jl +++ b/test/unit_tests/Support/ut_geometry.jl @@ -142,12 +142,12 @@ end @test undeformed_bond[1][2][2] == 0 @test undeformed_bond_length[1][2] == 1 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) @test undeformed_bond[1][1][1] == 0.5 @@ -174,12 +174,12 @@ end @test undeformed_bond[4][1][1] == 0.5 @test undeformed_bond[4][1][2] == -0.5 @test undeformed_bond_length[4][1] / sqrt(1.25) - 1 < 1e-8 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) # test if a sum exists or not @test undeformed_bond[1][1][1] == 0.5 @@ -216,12 +216,12 @@ end end end - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) end @@ -305,12 +305,12 @@ end coor[4, 1] = 1 coor[4, 2] = 0.5 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + undeformed_bond, + undeformed_bond_length, Vector(1:nnodes), nlist, coor, - undeformed_bond, - undeformed_bond_length, ) PeriLab.IO.Geometry.compute_shape_tensors!( shape_tensor, @@ -348,12 +348,12 @@ end deformed_coor[2, 1] = 0.25 deformed_coor[4, 1] = 0.25 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + deformed_bond, + deformed_bond_length, Vector(1:nnodes), nlist, deformed_coor, - deformed_bond, - deformed_bond_length, ) PeriLab.IO.Geometry.compute_deformation_gradients!( deformation_gradient, @@ -382,12 +382,12 @@ end deformed_coor[3, 2] = 1.5 deformed_coor[4, 2] = 1.5 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + deformed_bond, + deformed_bond_length, Vector(1:nnodes), nlist, deformed_coor, - deformed_bond, - deformed_bond_length, ) PeriLab.IO.Geometry.compute_deformation_gradients!( deformation_gradient, @@ -420,12 +420,12 @@ end deformed_coor[4, 1] = 1.5 deformed_coor[4, 2] = 0.5 - PeriLab.IO.Geometry.bond_geometry( + PeriLab.IO.Geometry.bond_geometry!( + deformed_bond, + deformed_bond_length, Vector(1:nnodes), nlist, deformed_coor, - deformed_bond, - deformed_bond_length, ) PeriLab.IO.Geometry.compute_deformation_gradients!( deformation_gradient,