Skip to content

Commit 9218839

Browse files
committed
test fix
1 parent 1adc781 commit 9218839

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

src/Compute/compute_field_values.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ function calculate_stresses(block_nodes::Dict{Int64,Vector{Int64}},
125125
material_parameter["Symmetry"],
126126
Data_Manager.get_dof())
127127
calculate_strain(active_nodes,
128-
invert(hookeMatrix,
129-
"Hooke matrix not invertable"))
128+
inv(hookeMatrix))
130129
end
131130
end
132131
end

src/Models/Material/Material_Basis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function get_2D_Hooke_matrix(aniso_matrix::MMatrix{T}, symmetry::String,
403403
matrix[3, 3] = aniso_matrix[6, 6]
404404
return matrix
405405
elseif occursin("plane stress", symmetry)
406-
inv_aniso = invert(aniso_matrix, "Hooke matrix not invertable")
406+
invert(inv_aniso, aniso_matrix, "Hooke matrix not invertable")
407407
matrix = get_MMatrix(36)
408408
matrix[1:2, 1:2] = inv_aniso[1:2, 1:2]
409409
matrix[3, 1:2] = inv_aniso[6, 1:2]

src/Support/Geometry.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Therefore,
296296
297297
"""
298298

299-
function compute_left_stretch_tensor(deformation_gradient::Matrix{Float64})
299+
function compute_left_stretch_tensor(deformation_gradient::AbstractMatrix{Float64})
300300
return sqrt(deformation_gradient * deformation_gradient')
301301
end
302302

@@ -328,12 +328,13 @@ function deformation_gradient_decomposition(nodes::Union{Base.OneTo{Int64},Vecto
328328
rot_tensor)
329329
for iID in nodes
330330
# EQ (15) in https://doi.org/10.1016/j.ijsolstr.2008.10.029
331-
rot_tensor[iID, :,
332-
:] = invert(compute_left_stretch_tensor(deformation_gradient[iID,
333-
:,
334-
:]),
335-
"Inversion of left stretch tensor fails in function deformation_gradient_decomposition.") *
336-
deformation_gradient[iID, :, :]
331+
@views rot_tensor[iID, :, :] = invert(rot_tensor[iID, :,
332+
:],
333+
compute_left_stretch_tensor(deformation_gradient[iID,
334+
:,
335+
:]),
336+
"Inversion of left stretch tensor fails in function deformation_gradient_decomposition.") *
337+
deformation_gradient[iID, :, :]
337338
end
338339
return rot_tensor
339340
end

src/Support/Helpers.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,15 @@ function interpol_data(x::Union{Vector{Float64},Vector{Int64},Float64,Int64},
943943
return evaluate(values["spl"], x)
944944
end
945945

946+
function invert(A::AbstractMatrix{Float64},
947+
error_message::String = "Matrix is singular")
948+
if abs(det(smat(A))) < 1e-15
949+
@error "$error_message "
950+
return
951+
end
952+
return inv(smat(A))
953+
end
954+
946955
"""
947956
invert(A::Union{Matrix{Float64},Matrix{Int64}}, error_message::String="Matrix is singular")
948957

test/unit_tests/Support/ut_helpers.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ end
5050
end
5151

5252
@testset "ut_invert" begin
53+
test_inv = zeros(2, 2)
5354
PeriLab.Solver_Manager.Helpers.invert(zeros(Float64, 4, 4),
5455
"test Float is singular.")
5556

56-
@test PeriLab.Solver_Manager.Helpers.invert([1.0 0; 0 1]) == inv([1 0; 0 1])
57-
@test PeriLab.Solver_Manager.Helpers.invert([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0],
58-
"test Int is singular.") ==
59-
inv([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0])
57+
PeriLab.Solver_Manager.Helpers.invert(test_inv, [1.0 0; 0 1])
58+
@test test_inv == inv([1 0; 0 1])
59+
test_inv = zeros(3, 3)
60+
PeriLab.Solver_Manager.Helpers.invert(test_inv, [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0],
61+
"test Int is singular.")
62+
@test test_inv == inv([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0])
6063
end
6164

6265
@testset "ut_find_local_neighbors" begin
@@ -295,7 +298,7 @@ end
295298
@test PeriLab.Solver_Manager.Helpers.check_inf_or_nan(a, "a") == false
296299
a = NaN
297300
@test PeriLab.Solver_Manager.Helpers.check_inf_or_nan(a, "a")
298-
a = 1/0
301+
a = 1 / 0
299302
@test PeriLab.Solver_Manager.Helpers.check_inf_or_nan(a, "a") == true
300303
end
301304
@testset "get_matrix_style" begin

0 commit comments

Comments
 (0)