Add Solid reference correction diagnostics

This commit is contained in:
Codex
2026-07-03 17:19:47 +08:00
parent f1ad27c5d7
commit db3c01c978
11 changed files with 533 additions and 39 deletions
+11
View File
@@ -377,7 +377,10 @@ contains
solid_reference_volume(npart), &
solid_deformation_gradient(SPH_NDIM,SPH_NDIM,npart), &
solid_correction_matrix(SPH_NDIM,SPH_NDIM,npart), &
solid_correction_determinant(npart), &
solid_acc_internal(SPH_NDIM,npart), &
solid_reference_neighbor_count(npart), &
solid_reference_degenerate(npart), solid_correction_status(npart), &
solid_failure_status(npart), stat=stat)
if (stat /= 0) then
call sph_solid_deallocate_state()
@@ -400,7 +403,11 @@ contains
if (allocated(solid_reference_volume)) deallocate(solid_reference_volume)
if (allocated(solid_deformation_gradient)) deallocate(solid_deformation_gradient)
if (allocated(solid_correction_matrix)) deallocate(solid_correction_matrix)
if (allocated(solid_correction_determinant)) deallocate(solid_correction_determinant)
if (allocated(solid_acc_internal)) deallocate(solid_acc_internal)
if (allocated(solid_reference_neighbor_count)) deallocate(solid_reference_neighbor_count)
if (allocated(solid_reference_degenerate)) deallocate(solid_reference_degenerate)
if (allocated(solid_correction_status)) deallocate(solid_correction_status)
if (allocated(solid_failure_status)) deallocate(solid_failure_status)
end subroutine sph_solid_deallocate_state
@@ -416,7 +423,11 @@ contains
if (allocated(solid_reference_volume)) solid_reference_volume = 0.0_rk
if (allocated(solid_deformation_gradient)) solid_deformation_gradient = 0.0_rk
if (allocated(solid_correction_matrix)) solid_correction_matrix = 0.0_rk
if (allocated(solid_correction_determinant)) solid_correction_determinant = 0.0_rk
if (allocated(solid_acc_internal)) solid_acc_internal = 0.0_rk
if (allocated(solid_reference_neighbor_count)) solid_reference_neighbor_count = 0
if (allocated(solid_reference_degenerate)) solid_reference_degenerate = 0
if (allocated(solid_correction_status)) solid_correction_status = 0
if (allocated(solid_failure_status)) solid_failure_status = SPH_STATUS_ACTIVE
end subroutine sph_solid_clear_particle_state
+197 -9
View File
@@ -2,12 +2,15 @@ module sph_solid_dynamics
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, sph_error_set
use sph_database, only: npart, particle_phase, particle_status, material_id, &
x, v, a, mass, rho, volume, h, solid_particle_count, solid_failed_count, &
x0, x, v, a, mass, rho, volume, h, solid_particle_count, &
solid_failed_count, &
solid_mass, solid_momentum, solid_kinetic_energy, &
solid_internal_energy_total, solid_max_von_mises, &
solid_min_plastic_strain, solid_max_plastic_strain, solid_min_damage, &
solid_max_damage, solid_min_softening, solid_max_softening, &
solid_dt_cfl, solid_dt_accel, solid_dtcrit, SPH_PHASE_SOLID, &
solid_dt_cfl, solid_dt_accel, solid_dtcrit, &
solid_reference_neighbor_min, solid_correction_det_min, &
solid_correction_status_max, SPH_PHASE_SOLID, &
SPH_PHASE_SOLID_FAILED, SPH_STATUS_ACTIVE, SPH_STATUS_FAILED, &
sph_db_clear_solid_diagnostics
use sph_solid_state
@@ -84,10 +87,10 @@ contains
subroutine sph_solid_build_reference_state(ierr)
integer, intent(out) :: ierr
integer :: i
integer :: j
ierr = SPH_SUCCESS
if (.not. allocated(solid_correction_matrix)) return
call sph_solid_clear_reference_state()
do i = 1, npart
if (.not. sph_solid_is_active(i)) cycle
if (h(i) <= 0.0_rk) then
@@ -99,15 +102,164 @@ contains
if (solid_reference_volume(i) <= 0.0_rk .and. rho(i) > 0.0_rk) then
solid_reference_volume(i) = mass(i) / rho(i)
end if
solid_correction_matrix(:,:,i) = 0.0_rk
solid_deformation_gradient(:,:,i) = 0.0_rk
do j = 1, SPH_NDIM
solid_correction_matrix(j,j,i) = 1.0_rk
solid_deformation_gradient(j,j,i) = 1.0_rk
end do
if (solid_reference_volume(i) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, &
'Solid reference state requires positive volume')
ierr = SPH_ERROR_ARGUMENT
return
end if
call sph_solid_set_identity(solid_deformation_gradient(:,:,i))
end do
do i = 1, npart
if (.not. sph_solid_is_active(i)) cycle
call sph_solid_build_particle_reference(i, ierr)
if (ierr /= SPH_SUCCESS) return
end do
end subroutine sph_solid_build_reference_state
subroutine sph_solid_clear_reference_state()
if (allocated(solid_reference_volume)) solid_reference_volume = 0.0_rk
if (allocated(solid_deformation_gradient)) solid_deformation_gradient = 0.0_rk
if (allocated(solid_correction_matrix)) solid_correction_matrix = 0.0_rk
if (allocated(solid_correction_determinant)) then
solid_correction_determinant = 0.0_rk
end if
if (allocated(solid_reference_neighbor_count)) then
solid_reference_neighbor_count = 0
end if
if (allocated(solid_reference_degenerate)) solid_reference_degenerate = 0
if (allocated(solid_correction_status)) solid_correction_status = 0
end subroutine sph_solid_clear_reference_state
subroutine sph_solid_build_particle_reference(index, ierr)
integer, intent(in) :: index
integer, intent(out) :: ierr
integer :: j
integer :: row
integer :: col
real(rk) :: rij(SPH_NDIM)
real(rk) :: distance
real(rk) :: radius
real(rk) :: weight
real(rk) :: moment(SPH_NDIM,SPH_NDIM)
real(rk) :: inverse(SPH_NDIM,SPH_NDIM)
real(rk) :: det_value
logical :: invertible
ierr = SPH_SUCCESS
moment = 0.0_rk
do j = 1, npart
if (j == index) cycle
if (.not. sph_solid_is_active(j)) cycle
radius = 2.0_rk * max(h(index), h(j))
rij = x0(:,j) - x0(:,index)
distance = sqrt(sum(rij * rij))
if (distance <= 0.0_rk .or. distance > radius) cycle
solid_reference_neighbor_count(index) = &
solid_reference_neighbor_count(index) + 1
weight = solid_reference_volume(j)
do row = 1, SPH_NDIM
do col = 1, SPH_NDIM
moment(row,col) = moment(row,col) + weight * rij(row) * rij(col)
end do
end do
end do
if (solid_reference_neighbor_count(index) < SPH_NDIM) then
call sph_solid_reference_fallback(index, &
SPH_SOLID_CORRECTION_UNDERCONSTRAINED, 0.0_rk)
return
end if
call sph_solid_invert_3x3(moment, inverse, det_value, invertible)
solid_correction_determinant(index) = det_value
if (.not. invertible) then
call sph_solid_reference_fallback(index, &
SPH_SOLID_CORRECTION_SINGULAR, det_value)
return
end if
solid_correction_matrix(:,:,index) = inverse
solid_correction_status(index) = SPH_SOLID_CORRECTION_OK
solid_reference_degenerate(index) = SPH_SOLID_REFERENCE_OK
end subroutine sph_solid_build_particle_reference
subroutine sph_solid_reference_fallback(index, status, det_value)
integer, intent(in) :: index
integer, intent(in) :: status
real(rk), intent(in) :: det_value
call sph_solid_set_identity(solid_correction_matrix(:,:,index))
solid_correction_determinant(index) = det_value
solid_correction_status(index) = status
solid_reference_degenerate(index) = SPH_SOLID_REFERENCE_DEGENERATE
end subroutine sph_solid_reference_fallback
subroutine sph_solid_invert_3x3(matrix, inverse, det_value, invertible)
real(rk), intent(in) :: matrix(SPH_NDIM,SPH_NDIM)
real(rk), intent(out) :: inverse(SPH_NDIM,SPH_NDIM)
real(rk), intent(out) :: det_value
logical, intent(out) :: invertible
real(rk) :: scale
real(rk) :: tolerance
inverse = 0.0_rk
det_value = sph_solid_det3(matrix)
invertible = .false.
if (.not. sph_solid_matrix_is_finite(matrix)) return
if (det_value /= det_value) return
scale = maxval(abs(matrix))
if (scale <= 0.0_rk) return
tolerance = 1000.0_rk * epsilon(1.0_rk) * max(scale**3, tiny(1.0_rk))
if (abs(det_value) <= tolerance) return
inverse(1,1) = (matrix(2,2) * matrix(3,3) - matrix(2,3) * matrix(3,2))
inverse(1,2) = (matrix(1,3) * matrix(3,2) - matrix(1,2) * matrix(3,3))
inverse(1,3) = (matrix(1,2) * matrix(2,3) - matrix(1,3) * matrix(2,2))
inverse(2,1) = (matrix(2,3) * matrix(3,1) - matrix(2,1) * matrix(3,3))
inverse(2,2) = (matrix(1,1) * matrix(3,3) - matrix(1,3) * matrix(3,1))
inverse(2,3) = (matrix(1,3) * matrix(2,1) - matrix(1,1) * matrix(2,3))
inverse(3,1) = (matrix(2,1) * matrix(3,2) - matrix(2,2) * matrix(3,1))
inverse(3,2) = (matrix(1,2) * matrix(3,1) - matrix(1,1) * matrix(3,2))
inverse(3,3) = (matrix(1,1) * matrix(2,2) - matrix(1,2) * matrix(2,1))
inverse = inverse / det_value
if (.not. sph_solid_matrix_is_finite(inverse)) return
invertible = .true.
end subroutine sph_solid_invert_3x3
real(rk) function sph_solid_det3(matrix)
real(rk), intent(in) :: matrix(SPH_NDIM,SPH_NDIM)
sph_solid_det3 = matrix(1,1) * (matrix(2,2) * matrix(3,3) - &
matrix(2,3) * matrix(3,2)) - &
matrix(1,2) * (matrix(2,1) * matrix(3,3) - &
matrix(2,3) * matrix(3,1)) + &
matrix(1,3) * (matrix(2,1) * matrix(3,2) - &
matrix(2,2) * matrix(3,1))
end function sph_solid_det3
logical function sph_solid_matrix_is_finite(matrix)
real(rk), intent(in) :: matrix(SPH_NDIM,SPH_NDIM)
integer :: row
integer :: col
sph_solid_matrix_is_finite = .true.
do row = 1, SPH_NDIM
do col = 1, SPH_NDIM
if (matrix(row,col) /= matrix(row,col)) sph_solid_matrix_is_finite = .false.
if (abs(matrix(row,col)) > huge(matrix(row,col)) * 0.5_rk) then
sph_solid_matrix_is_finite = .false.
end if
end do
end do
end function sph_solid_matrix_is_finite
subroutine sph_solid_set_identity(matrix)
real(rk), intent(out) :: matrix(SPH_NDIM,SPH_NDIM)
integer :: i
matrix = 0.0_rk
do i = 1, SPH_NDIM
matrix(i,i) = 1.0_rk
end do
end subroutine sph_solid_set_identity
subroutine sph_solid_compute_particle_strain_increment(index, dt, strain_inc, ierr)
integer, intent(in) :: index
real(rk), intent(in) :: dt
@@ -204,6 +356,7 @@ contains
solid_max_damage = solid_damage(i)
solid_min_softening = solid_softening(i)
solid_max_softening = solid_softening(i)
call sph_solid_set_reference_diagnostics(i)
first_active = .false.
else
if (vm_value > solid_max_von_mises) solid_max_von_mises = vm_value
@@ -212,10 +365,45 @@ contains
call sph_solid_update_range(solid_damage(i), solid_min_damage, solid_max_damage)
call sph_solid_update_range(solid_softening(i), solid_min_softening, &
solid_max_softening)
call sph_solid_update_reference_diagnostics(i)
end if
end do
end subroutine sph_solid_update_diagnostics
subroutine sph_solid_set_reference_diagnostics(index)
integer, intent(in) :: index
if (allocated(solid_reference_neighbor_count)) then
solid_reference_neighbor_min = solid_reference_neighbor_count(index)
end if
if (allocated(solid_correction_determinant)) then
solid_correction_det_min = solid_correction_determinant(index)
end if
if (allocated(solid_correction_status)) then
solid_correction_status_max = solid_correction_status(index)
end if
end subroutine sph_solid_set_reference_diagnostics
subroutine sph_solid_update_reference_diagnostics(index)
integer, intent(in) :: index
if (allocated(solid_reference_neighbor_count)) then
if (solid_reference_neighbor_count(index) < solid_reference_neighbor_min) then
solid_reference_neighbor_min = solid_reference_neighbor_count(index)
end if
end if
if (allocated(solid_correction_determinant)) then
if (solid_correction_determinant(index) < solid_correction_det_min) then
solid_correction_det_min = solid_correction_determinant(index)
end if
end if
if (allocated(solid_correction_status)) then
if (solid_correction_status(index) > solid_correction_status_max) then
solid_correction_status_max = solid_correction_status(index)
end if
end if
end subroutine sph_solid_update_reference_diagnostics
subroutine sph_solid_estimate_dt_limits(dt_cfl, dt_accel, dt_limit, ierr)
real(rk), intent(out) :: dt_cfl
real(rk), intent(out) :: dt_accel
+11
View File
@@ -21,7 +21,18 @@ module sph_solid_state
real(rk), allocatable :: solid_reference_volume(:)
real(rk), allocatable :: solid_deformation_gradient(:,:,:)
real(rk), allocatable :: solid_correction_matrix(:,:,:)
real(rk), allocatable :: solid_correction_determinant(:)
real(rk), allocatable :: solid_acc_internal(:,:)
integer, allocatable :: solid_reference_neighbor_count(:)
integer, allocatable :: solid_reference_degenerate(:)
integer, allocatable :: solid_correction_status(:)
integer, allocatable :: solid_failure_status(:)
integer, parameter :: SPH_SOLID_REFERENCE_OK = 0
integer, parameter :: SPH_SOLID_REFERENCE_DEGENERATE = 1
integer, parameter :: SPH_SOLID_CORRECTION_OK = 0
integer, parameter :: SPH_SOLID_CORRECTION_UNDERCONSTRAINED = 1
integer, parameter :: SPH_SOLID_CORRECTION_SINGULAR = 2
integer, parameter :: SPH_SOLID_CORRECTION_FALLBACK = 3
end module sph_solid_state