Add Solid material point model

This commit is contained in:
Codex
2026-07-03 15:05:43 +08:00
parent 61cc75b901
commit 80555bcdf8
8 changed files with 854 additions and 33 deletions
@@ -0,0 +1,80 @@
program test_solid_elastic_material
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_solid, only: sph_solid_update_particle_material
use sph_solid_state, only: solid_stress, solid_plastic_strain, solid_internal_energy
use sph_solid_material, only: sph_solid_elastic_constants, &
sph_solid_elastic_trial, sph_solid_von_mises, &
sph_solid_internal_energy_increment
implicit none
integer :: ierr
call check_elastic_helpers()
call check_elastic_particle_update()
contains
subroutine check_elastic_helpers()
real(rk) :: shear
real(rk) :: bulk
real(rk) :: wave_speed
real(rk) :: stress_old(6)
real(rk) :: stress_new(6)
real(rk) :: strain_inc(6)
real(rk) :: energy_inc
call sph_solid_elastic_constants(210.0e9_rk, 0.30_rk, 7850.0_rk, &
shear, bulk, wave_speed, ierr)
call assert_ok(ierr, 'elastic constants failed')
if (shear <= 0.0_rk .or. bulk <= 0.0_rk) call fail('elastic constants missing')
if (wave_speed <= 0.0_rk) call fail('elastic wave speed missing')
stress_old = 0.0_rk
strain_inc = 0.0_rk
strain_inc(1) = 1.0e-5_rk
call sph_solid_elastic_trial(stress_old, strain_inc, shear, bulk, stress_new, ierr)
call assert_ok(ierr, 'elastic trial failed')
if (stress_new(1) <= 0.0_rk) call fail('elastic stress update missing')
if (sph_solid_von_mises(stress_new) <= 0.0_rk) call fail('von Mises stress missing')
call sph_solid_internal_energy_increment(stress_old, stress_new, strain_inc, &
7850.0_rk, energy_inc, ierr)
call assert_ok(ierr, 'elastic energy increment failed')
if (energy_inc <= 0.0_rk) call fail('elastic internal energy increment missing')
end subroutine check_elastic_helpers
subroutine check_elastic_particle_update()
real(rk) :: strain_inc(6)
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for elastic particle update')
call sph_read_inp('tests/data/solid_elastic_minimal_050.inp', ierr)
call assert_ok(ierr, 'read failed for elastic particle update')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for elastic particle update')
strain_inc = 0.0_rk
strain_inc(1) = 1.0e-5_rk
call sph_solid_update_particle_material(1, strain_inc, 1.0e-7_rk, ierr)
call assert_ok(ierr, 'elastic particle update failed')
if (solid_stress(1,1) <= 0.0_rk) call fail('particle elastic stress missing')
if (abs(solid_plastic_strain(1)) > 0.0_rk) call fail('elastic particle became plastic')
if (solid_internal_energy(1) <= 0.0_rk) call fail('particle elastic energy missing')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for elastic particle update')
end subroutine check_elastic_particle_update
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_solid_elastic_material
@@ -0,0 +1,79 @@
program test_solid_johnson_cook_failure
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_database, only: particle_phase, particle_status, mass, &
SPH_PHASE_SOLID_FAILED, SPH_STATUS_FAILED
use sph_solid, only: sph_solid_mark_particle_failed
use sph_solid_state, only: solid_damage, solid_softening, solid_failure_status
use sph_solid_material, only: sph_solid_jc_failure_strain, sph_solid_damage_update
implicit none
integer :: ierr
call check_failure_helpers()
call check_failure_status_keeps_particle_mass()
contains
subroutine check_failure_helpers()
real(rk) :: d_values(5)
real(rk) :: failure_strain
real(rk) :: damage_new
integer :: failure_status
d_values = (/ 0.05_rk, 3.44_rk, -2.12_rk, 0.002_rk, 0.61_rk /)
call sph_solid_jc_failure_strain(d_values, 0.0_rk, 1.0_rk, 1.0_rk, &
293.0_rk, 293.0_rk, 1793.0_rk, failure_strain, ierr)
call assert_ok(ierr, 'Johnson-Cook failure strain failed')
if (failure_strain <= 0.0_rk) call fail('failure strain missing')
call sph_solid_damage_update(0.25_rk, 0.25_rk * failure_strain, &
failure_strain, damage_new, failure_status, ierr)
call assert_ok(ierr, 'damage update failed')
if (damage_new <= 0.25_rk) call fail('damage did not accumulate')
call sph_solid_damage_update(0.95_rk, 0.20_rk * failure_strain, &
failure_strain, damage_new, failure_status, ierr)
call assert_ok(ierr, 'failure damage update failed')
if (failure_status /= SPH_STATUS_FAILED) call fail('failure status was not set')
call sph_solid_damage_update(0.0_rk, 1.0_rk, 0.0_rk, damage_new, &
failure_status, ierr)
if (ierr == SPH_SUCCESS) call fail('invalid failure strain was accepted')
end subroutine check_failure_helpers
subroutine check_failure_status_keeps_particle_mass()
real(rk) :: mass_before
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for failure status check')
call sph_read_inp('tests/data/solid_johnson_cook_failure_050.inp', ierr)
call assert_ok(ierr, 'read failed for failure status check')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for failure status check')
mass_before = mass(1)
call sph_solid_mark_particle_failed(1, ierr)
call assert_ok(ierr, 'mark failed particle failed')
if (solid_failure_status(1) /= SPH_STATUS_FAILED) call fail('Solid failure status mismatch')
if (particle_status(1) /= SPH_STATUS_FAILED) call fail('particle status mismatch after failure')
if (particle_phase(1) /= SPH_PHASE_SOLID_FAILED) call fail('particle phase mismatch after failure')
if (abs(mass(1) - mass_before) > 0.0_rk) call fail('failure changed particle mass')
if (solid_damage(1) < 1.0_rk) call fail('failure did not clamp damage')
if (abs(solid_softening(1)) > 0.0_rk) call fail('failure did not remove softening')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for failure status check')
end subroutine check_failure_status_keeps_particle_mass
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_solid_johnson_cook_failure
@@ -0,0 +1,80 @@
program test_solid_johnson_cook_flow
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model
use sph_solid, only: sph_solid_update_particle_material
use sph_solid_state, only: solid_stress, solid_plastic_strain, &
solid_plastic_strain_rate, solid_temperature, solid_temperature_rise_factor
use sph_solid_material, only: sph_solid_jc_flow_stress, sph_solid_von_mises
implicit none
integer :: ierr
call check_johnson_cook_flow_helpers()
call check_johnson_cook_particle_update()
contains
subroutine check_johnson_cook_flow_helpers()
real(rk) :: flow_static
real(rk) :: flow_hardened
call sph_solid_jc_flow_stress(792.0e6_rk, 510.0e6_rk, 0.26_rk, &
0.014_rk, 1.03_rk, 1.0_rk, 293.0_rk, 1793.0_rk, &
0.0_rk, 0.0_rk, 293.0_rk, flow_static, ierr)
call assert_ok(ierr, 'Johnson-Cook static flow failed')
call sph_solid_jc_flow_stress(792.0e6_rk, 510.0e6_rk, 0.26_rk, &
0.014_rk, 1.03_rk, 1.0_rk, 293.0_rk, 1793.0_rk, &
0.10_rk, 100.0_rk, 293.0_rk, flow_hardened, ierr)
call assert_ok(ierr, 'Johnson-Cook hardened flow failed')
if (flow_static <= 0.0_rk) call fail('Johnson-Cook static flow missing')
if (flow_hardened <= flow_static) call fail('Johnson-Cook hardening/rate term missing')
call sph_solid_jc_flow_stress(792.0e6_rk, 510.0e6_rk, 0.26_rk, &
0.014_rk, 1.03_rk, 0.0_rk, 293.0_rk, 1793.0_rk, &
0.0_rk, 1.0_rk, 293.0_rk, flow_static, ierr)
if (ierr == SPH_SUCCESS) call fail('invalid Johnson-Cook epsdot0 was accepted')
call sph_solid_jc_flow_stress(792.0e6_rk, 510.0e6_rk, 0.26_rk, &
0.014_rk, 1.03_rk, 1.0_rk, 293.0_rk, 293.0_rk, &
0.0_rk, 1.0_rk, 293.0_rk, flow_static, ierr)
if (ierr == SPH_SUCCESS) call fail('invalid Johnson-Cook temperature range was accepted')
end subroutine check_johnson_cook_flow_helpers
subroutine check_johnson_cook_particle_update()
real(rk) :: strain_inc(6)
real(rk) :: temp_before
call sph_initialize(ierr)
call assert_ok(ierr, 'initialize failed for Johnson-Cook update')
call sph_read_inp('tests/data/solid_johnson_cook_failure_050.inp', ierr)
call assert_ok(ierr, 'read failed for Johnson-Cook update')
call sph_build_model(ierr)
call assert_ok(ierr, 'build failed for Johnson-Cook update')
solid_temperature_rise_factor(1) = 1.0e-6_rk
temp_before = solid_temperature(1)
strain_inc = 0.0_rk
strain_inc(4) = 2.0e-2_rk
call sph_solid_update_particle_material(1, strain_inc, 1.0e-6_rk, ierr)
call assert_ok(ierr, 'Johnson-Cook particle update failed')
if (solid_plastic_strain(1) <= 0.0_rk) call fail('plastic strain was not updated')
if (solid_plastic_strain_rate(1) <= 0.0_rk) call fail('plastic strain rate was not updated')
if (sph_solid_von_mises(solid_stress(:,1)) <= 0.0_rk) call fail('plastic stress missing')
if (solid_temperature(1) <= temp_before) call fail('plastic temperature did not increase')
call sph_finalize(ierr)
call assert_ok(ierr, 'finalize failed for Johnson-Cook update')
end subroutine check_johnson_cook_particle_update
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_solid_johnson_cook_flow
@@ -0,0 +1,46 @@
program test_solid_progressive_softening
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_solid_material, only: sph_solid_linear_softening
implicit none
integer :: ierr
call check_linear_softening()
contains
subroutine check_linear_softening()
real(rk) :: softening
call sph_solid_linear_softening(0.0_rk, 1.0_rk, softening, ierr)
call assert_ok(ierr, 'zero damage softening failed')
if (abs(softening - 1.0_rk) > 1.0e-12_rk) call fail('zero damage softening mismatch')
call sph_solid_linear_softening(0.40_rk, 1.0_rk, softening, ierr)
call assert_ok(ierr, 'partial damage softening failed')
if (abs(softening - 0.60_rk) > 1.0e-12_rk) call fail('partial damage softening mismatch')
call sph_solid_linear_softening(2.0_rk, 1.0_rk, softening, ierr)
call assert_ok(ierr, 'clamped damage softening failed')
if (abs(softening) > 0.0_rk) call fail('over-damage softening was not clamped')
call sph_solid_linear_softening(-1.0_rk, 1.0_rk, softening, ierr)
call assert_ok(ierr, 'negative damage softening failed')
if (abs(softening - 1.0_rk) > 1.0e-12_rk) call fail('negative damage softening mismatch')
call sph_solid_linear_softening(0.5_rk, 0.0_rk, softening, ierr)
if (ierr == SPH_SUCCESS) call fail('invalid softening width was accepted')
end subroutine check_linear_softening
subroutine assert_ok(ierr_value, message)
integer, intent(in) :: ierr_value
character(len=*), intent(in) :: message
if (ierr_value /= SPH_SUCCESS) call fail(message)
end subroutine assert_ok
subroutine fail(message)
character(len=*), intent(in) :: message
write(*, '(A)') trim(message)
stop 1
end subroutine fail
end program test_solid_progressive_softening