@@ -15,8 +15,7 @@ for mod in module_list
1515end
1616
1717using LinearAlgebra
18- using StaticArrays
19- using LoopVectorization
18+ a = using LoopVectorization
2019using Rotations
2120include (" ./Bond_Associated_Correspondence.jl" )
2221using . Bond_Associated_Correspondence
@@ -262,7 +261,6 @@ function calculate_bond_force!(nodes::AbstractVector{Int64},
262261 inverse_shape_tensor,
263262 stress_NP1)
264263 end
265- # return bond_force
266264end
267265
268266function calculate_bond_force_2d! (bond_force:: BondVectorState{Float64} ,
@@ -272,32 +270,71 @@ function calculate_bond_force_2d!(bond_force::BondVectorState{Float64},
272270 bond_damage:: BondScalarState{Float64} ,
273271 inverse_shape_tensor:: NodeTensorField{Float64,3} ,
274272 stress_NP1:: NodeTensorField{Float64,3} )
275- pk_stress = MMatrix {2,2} ( zeros ( 2 , 2 ))
276- temp = MMatrix {2,2} ( zeros (Float64, 2 , 2 ))
277- @inbounds @fastmath for iID in nodes
278- if ! all (deformation_gradient[ iID, :, :] .== 0.0 )
279- @views compute_Piola_Kirchhoff_stress! (pk_stress,
280- SMatrix {2,2} ( @views stress_NP1[iID, :,
281- :]),
282- SMatrix {2,2} ( @views deformation_gradient[iID,
283- :,
284- :]))
273+ pk11, pk12, pk21, pk22 = 0.0 , 0.0 , 0.0 , 0.0
274+ t11, t12, t21, t22 = 0.0 , 0.0 , 0.0 , 0.0
275+
276+ @inbounds for iID in nodes
277+ has_deformation = false
278+ for i in 1 : 2 , j in 1 : 2
279+ if deformation_gradient[iID, i, j] != 0.0
280+ has_deformation = true
281+ break
282+ end
285283 end
286- mat_mul! (temp, SMatrix {2,2} (pk_stress),
287- SMatrix {2,2} (@views inverse_shape_tensor[iID, :, :]))
288-
289- @views @inbounds @fastmath for jID in axes (bond_damage[iID], 1 )
290- @inbounds @fastmath for idof in 1 : 2
291- b_fi = Float64 (0.0 )
292- @inbounds @fastmath for jdof in 1 : 2
293- b_fi += temp[idof, jdof] *
294- bond_damage[iID][jID] *
295- undeformed_bond[iID][jID][jdof]
296- end
297- bond_force[iID][jID][idof] = b_fi
284+
285+ if has_deformation
286+ F11 = deformation_gradient[iID, 1 , 1 ]
287+ F12 = deformation_gradient[iID, 1 , 2 ]
288+ F21 = deformation_gradient[iID, 2 , 1 ]
289+ F22 = deformation_gradient[iID, 2 , 2 ]
290+
291+ sigma11 = stress_NP1[iID, 1 , 1 ]
292+ sigma12 = stress_NP1[iID, 1 , 2 ]
293+ sigma21 = stress_NP1[iID, 2 , 1 ]
294+ sigma22 = stress_NP1[iID, 2 , 2 ]
295+
296+ detF = F11 * F22 - F12 * F21
297+ if abs (detF) > 1e-15
298+ inv_detF = 1.0 / detF
299+ Finv11 = F22 * inv_detF
300+ Finv12 = - F12 * inv_detF
301+ Finv21 = - F21 * inv_detF
302+ Finv22 = F11 * inv_detF
303+
304+ pk11 = sigma11 * Finv11 + sigma12 * Finv21
305+ pk12 = sigma11 * Finv12 + sigma12 * Finv22
306+ pk21 = sigma21 * Finv11 + sigma22 * Finv21
307+ pk22 = sigma21 * Finv12 + sigma22 * Finv22
308+ else
309+ pk11 = pk12 = pk21 = pk22 = 0.0
298310 end
311+ else
312+ pk11 = pk12 = pk21 = pk22 = 0.0
313+ end
314+
315+ # temp = pk_stress * K^(-1) (inline)
316+ K11 = inverse_shape_tensor[iID, 1 , 1 ]
317+ K12 = inverse_shape_tensor[iID, 1 , 2 ]
318+ K21 = inverse_shape_tensor[iID, 2 , 1 ]
319+ K22 = inverse_shape_tensor[iID, 2 , 2 ]
320+
321+ t11 = pk11 * K11 + pk12 * K21
322+ t12 = pk11 * K12 + pk12 * K22
323+ t21 = pk21 * K11 + pk22 * K21
324+ t22 = pk21 * K12 + pk22 * K22
325+
326+ # Bond forces (inline)
327+ @fastmath for jID in eachindex (bond_damage[iID])
328+ bd = bond_damage[iID][jID]
329+ xi1 = undeformed_bond[iID][jID][1 ]
330+ xi2 = undeformed_bond[iID][jID][2 ]
331+
332+ bond_force[iID][jID][1 ] = bd * (t11 * xi1 + t12 * xi2)
333+ bond_force[iID][jID][2 ] = bd * (t21 * xi1 + t22 * xi2)
299334 end
300335 end
336+
337+ return nothing
301338end
302339
303340function calculate_bond_force_3d! (bond_force:: BondVectorState{Float64} ,
@@ -307,31 +344,128 @@ function calculate_bond_force_3d!(bond_force::BondVectorState{Float64},
307344 bond_damage:: BondScalarState{Float64} ,
308345 inverse_shape_tensor:: NodeTensorField{Float64,3} ,
309346 stress_NP1:: NodeTensorField{Float64,3} )
310- pk_stress = MMatrix {3,3} (zeros (3 , 3 ))
311- temp = MMatrix {3,3} (zeros (Float64, 3 , 3 ))
312- @inbounds @fastmath for iID in nodes
313- if ! all (deformation_gradient[iID, :, :] .== 0.0 )
314- @views compute_Piola_Kirchhoff_stress! (pk_stress,
315- SMatrix {3,3} (stress_NP1[iID, :,
316- :]),
317- SMatrix {3,3} (deformation_gradient[iID,
318- :,
319- :]))
347+
348+ # Pre-allokierte lokale Variablen außerhalb der Schleife
349+ pk11, pk12, pk13 = 0.0 , 0.0 , 0.0
350+ pk21, pk22, pk23 = 0.0 , 0.0 , 0.0
351+ pk31, pk32, pk33 = 0.0 , 0.0 , 0.0
352+
353+ t11, t12, t13 = 0.0 , 0.0 , 0.0
354+ t21, t22, t23 = 0.0 , 0.0 , 0.0
355+ t31, t32, t33 = 0.0 , 0.0 , 0.0
356+
357+ @inbounds for iID in nodes
358+ # Prüfe auf Deformation (ohne all())
359+ has_deformation = false
360+ for i in 1 : 3 , j in 1 : 3
361+ if deformation_gradient[iID, i, j] != 0.0
362+ has_deformation = true
363+ break
364+ end
320365 end
321- mat_mul! (temp, SMatrix {3,3} (pk_stress),
322- SMatrix {3,3} (inverse_shape_tensor[iID, :, :]))
323- @views @inbounds @fastmath for jID in axes (bond_damage[iID], 1 )
324- @inbounds @fastmath for idof in 1 : 3
325- b_fi = Float64 (0.0 )
326- @inbounds @fastmath for jdof in 1 : 3
327- @views b_fi += temp[idof, jdof] *
328- bond_damage[iID][jID] *
329- undeformed_bond[iID][jID][jdof]
330- end
331- bond_force[iID][jID][idof] = b_fi
366+
367+ if has_deformation
368+ # Deformationsgradient laden
369+ F11 = deformation_gradient[iID, 1 , 1 ]
370+ F12 = deformation_gradient[iID, 1 , 2 ]
371+ F13 = deformation_gradient[iID, 1 , 3 ]
372+ F21 = deformation_gradient[iID, 2 , 1 ]
373+ F22 = deformation_gradient[iID, 2 , 2 ]
374+ F23 = deformation_gradient[iID, 2 , 3 ]
375+ F31 = deformation_gradient[iID, 3 , 1 ]
376+ F32 = deformation_gradient[iID, 3 , 2 ]
377+ F33 = deformation_gradient[iID, 3 , 3 ]
378+
379+ # Cauchy Stress laden
380+ sigma11 = stress_NP1[iID, 1 , 1 ]
381+ sigma12 = stress_NP1[iID, 1 , 2 ]
382+ sigma13 = stress_NP1[iID, 1 , 3 ]
383+ sigma21 = stress_NP1[iID, 2 , 1 ]
384+ sigma22 = stress_NP1[iID, 2 , 2 ]
385+ sigma23 = stress_NP1[iID, 2 , 3 ]
386+ sigma31 = stress_NP1[iID, 3 , 1 ]
387+ sigma32 = stress_NP1[iID, 3 , 2 ]
388+ sigma33 = stress_NP1[iID, 3 , 3 ]
389+
390+ # Determinante von F
391+ detF = F11 * (F22 * F33 - F23 * F32) -
392+ F12 * (F21 * F33 - F23 * F31) +
393+ F13 * (F21 * F32 - F22 * F31)
394+
395+ if abs (detF) > 1e-15
396+ inv_detF = 1.0 / detF
397+
398+ # Inverse von F (Adjugate / det)
399+ Finv11 = (F22 * F33 - F23 * F32) * inv_detF
400+ Finv12 = (F13 * F32 - F12 * F33) * inv_detF
401+ Finv13 = (F12 * F23 - F13 * F22) * inv_detF
402+ Finv21 = (F23 * F31 - F21 * F33) * inv_detF
403+ Finv22 = (F11 * F33 - F13 * F31) * inv_detF
404+ Finv23 = (F13 * F21 - F11 * F23) * inv_detF
405+ Finv31 = (F21 * F32 - F22 * F31) * inv_detF
406+ Finv32 = (F12 * F31 - F11 * F32) * inv_detF
407+ Finv33 = (F11 * F22 - F12 * F21) * inv_detF
408+
409+ # PK-Stress: P = sigma * F^(-T)
410+ pk11 = sigma11 * Finv11 + sigma12 * Finv21 + sigma13 * Finv31
411+ pk12 = sigma11 * Finv12 + sigma12 * Finv22 + sigma13 * Finv32
412+ pk13 = sigma11 * Finv13 + sigma12 * Finv23 + sigma13 * Finv33
413+
414+ pk21 = sigma21 * Finv11 + sigma22 * Finv21 + sigma23 * Finv31
415+ pk22 = sigma21 * Finv12 + sigma22 * Finv22 + sigma23 * Finv32
416+ pk23 = sigma21 * Finv13 + sigma22 * Finv23 + sigma23 * Finv33
417+
418+ pk31 = sigma31 * Finv11 + sigma32 * Finv21 + sigma33 * Finv31
419+ pk32 = sigma31 * Finv12 + sigma32 * Finv22 + sigma33 * Finv32
420+ pk33 = sigma31 * Finv13 + sigma32 * Finv23 + sigma33 * Finv33
421+ else
422+ pk11 = pk12 = pk13 = 0.0
423+ pk21 = pk22 = pk23 = 0.0
424+ pk31 = pk32 = pk33 = 0.0
332425 end
426+ else
427+ pk11 = pk12 = pk13 = 0.0
428+ pk21 = pk22 = pk23 = 0.0
429+ pk31 = pk32 = pk33 = 0.0
430+ end
431+
432+ # temp = pk_stress * K^(-1) (inline)
433+ K11 = inverse_shape_tensor[iID, 1 , 1 ]
434+ K12 = inverse_shape_tensor[iID, 1 , 2 ]
435+ K13 = inverse_shape_tensor[iID, 1 , 3 ]
436+ K21 = inverse_shape_tensor[iID, 2 , 1 ]
437+ K22 = inverse_shape_tensor[iID, 2 , 2 ]
438+ K23 = inverse_shape_tensor[iID, 2 , 3 ]
439+ K31 = inverse_shape_tensor[iID, 3 , 1 ]
440+ K32 = inverse_shape_tensor[iID, 3 , 2 ]
441+ K33 = inverse_shape_tensor[iID, 3 , 3 ]
442+
443+ t11 = pk11 * K11 + pk12 * K21 + pk13 * K31
444+ t12 = pk11 * K12 + pk12 * K22 + pk13 * K32
445+ t13 = pk11 * K13 + pk12 * K23 + pk13 * K33
446+
447+ t21 = pk21 * K11 + pk22 * K21 + pk23 * K31
448+ t22 = pk21 * K12 + pk22 * K22 + pk23 * K32
449+ t23 = pk21 * K13 + pk22 * K23 + pk23 * K33
450+
451+ t31 = pk31 * K11 + pk32 * K21 + pk33 * K31
452+ t32 = pk31 * K12 + pk32 * K22 + pk33 * K32
453+ t33 = pk31 * K13 + pk32 * K23 + pk33 * K33
454+
455+ # Bond forces (inline)
456+ @fastmath for jID in eachindex (bond_damage[iID])
457+ bd = bond_damage[iID][jID]
458+ xi1 = undeformed_bond[iID][jID][1 ]
459+ xi2 = undeformed_bond[iID][jID][2 ]
460+ xi3 = undeformed_bond[iID][jID][3 ]
461+
462+ bond_force[iID][jID][1 ] = bd * (t11 * xi1 + t12 * xi2 + t13 * xi3)
463+ bond_force[iID][jID][2 ] = bd * (t21 * xi1 + t22 * xi2 + t23 * xi3)
464+ bond_force[iID][jID][3 ] = bd * (t31 * xi1 + t32 * xi2 + t33 * xi3)
333465 end
334466 end
467+
468+ return nothing
335469end
336470
337471end
0 commit comments