Add Solid output and restart
This commit is contained in:
@@ -0,0 +1,271 @@
|
||||
program test_solid_output
|
||||
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, &
|
||||
sph_estimate_stable_dt, sph_set_output_directory, sph_write_output
|
||||
use sph_database, only: v, solid_particle_count, solid_failed_count, &
|
||||
solid_dtcrit, SPH_STATUS_FAILED
|
||||
use sph_solid, only: sph_solid_mark_particle_failed
|
||||
use sph_solid_state, only: solid_stress, solid_plastic_strain, solid_damage, &
|
||||
solid_softening, solid_internal_energy, solid_failure_status
|
||||
use sph_solid_dynamics, only: sph_solid_update_diagnostics
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
|
||||
call check_solid_output_fields()
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_solid_output_fields()
|
||||
real(rk) :: dtcrit
|
||||
|
||||
call delete_output_pair(50)
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for Solid output')
|
||||
call sph_read_inp('tests/data/solid_body_force_050.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for Solid output')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for Solid output')
|
||||
call seed_solid_state()
|
||||
call sph_solid_mark_particle_failed(2, ierr)
|
||||
call assert_ok(ierr, 'mark Solid failed particle failed')
|
||||
call sph_estimate_stable_dt(dtcrit, ierr)
|
||||
call assert_ok(ierr, 'Solid output dt estimate failed')
|
||||
call sph_solid_update_diagnostics(ierr)
|
||||
call assert_ok(ierr, 'Solid output diagnostics failed')
|
||||
call sph_set_output_directory('build-codex-unix', ierr)
|
||||
call assert_ok(ierr, 'Solid output directory failed')
|
||||
call sph_write_output(50, 0.0_rk, ierr)
|
||||
call assert_ok(ierr, 'Solid output write failed')
|
||||
call check_particle_csv('build-codex-unix/sphlite_00000050.csv')
|
||||
call check_summary_csv('build-codex-unix/sphlite_00000050_summary.csv')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed for Solid output')
|
||||
end subroutine check_solid_output_fields
|
||||
|
||||
subroutine seed_solid_state()
|
||||
v(:,1) = (/2.0_rk, 3.0_rk, 4.0_rk/)
|
||||
solid_stress(:,1) = (/1.0_rk, 2.0_rk, 3.0_rk, &
|
||||
4.0_rk, 5.0_rk, 6.0_rk/)
|
||||
solid_plastic_strain(1) = 0.25_rk
|
||||
solid_damage(1) = 0.40_rk
|
||||
solid_softening(1) = 0.60_rk
|
||||
solid_internal_energy(1) = 2.0_rk
|
||||
solid_failure_status(1) = 0
|
||||
end subroutine seed_solid_state
|
||||
|
||||
subroutine check_particle_csv(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=512) :: header
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
integer :: id
|
||||
integer :: phase
|
||||
integer :: status
|
||||
integer :: mat
|
||||
integer :: sec
|
||||
integer :: failure
|
||||
real(rk) :: pos(3)
|
||||
real(rk) :: vel(3)
|
||||
real(rk) :: scalar_values(4)
|
||||
real(rk) :: explosive_values(6)
|
||||
real(rk) :: stress_values(6)
|
||||
real(rk) :: plastic
|
||||
real(rk) :: damage
|
||||
real(rk) :: softening
|
||||
|
||||
unit = 84
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Solid particle CSV open failed')
|
||||
read(unit, '(A)', iostat=ios) header
|
||||
if (ios /= 0) call fail('Solid particle CSV header read failed')
|
||||
if (trim(header) /= 'id,phase,status,material,section,x,y,z,' // &
|
||||
'vx,vy,vz,rho,pressure,temperature,h,explosive_detonation_time,' // &
|
||||
'explosive_lambda,explosive_initial_mass,explosive_remaining_mass,' // &
|
||||
'explosive_released_mass,explosive_released_energy,' // &
|
||||
'solid_stress_xx,solid_stress_yy,solid_stress_zz,solid_stress_xy,' // &
|
||||
'solid_stress_yz,solid_stress_zx,solid_plastic_strain,solid_damage,' // &
|
||||
'solid_softening,solid_failure_status') then
|
||||
call fail('Solid particle CSV header mismatch')
|
||||
end if
|
||||
read(unit, *, iostat=ios) id, phase, status, mat, sec, pos, vel, &
|
||||
scalar_values, explosive_values, stress_values, plastic, damage, &
|
||||
softening, failure
|
||||
close(unit=unit)
|
||||
if (ios /= 0) call fail('Solid particle CSV row read failed')
|
||||
if (id /= 1) call fail('Solid particle CSV id mismatch')
|
||||
if (maxval(abs(vel - (/2.0_rk, 3.0_rk, 4.0_rk/))) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV velocity mismatch')
|
||||
end if
|
||||
if (maxval(abs(stress_values - solid_stress(:,1))) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV stress mismatch')
|
||||
end if
|
||||
if (abs(plastic - solid_plastic_strain(1)) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV plastic strain mismatch')
|
||||
end if
|
||||
if (abs(damage - solid_damage(1)) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV damage mismatch')
|
||||
end if
|
||||
if (abs(softening - solid_softening(1)) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV softening mismatch')
|
||||
end if
|
||||
if (failure /= solid_failure_status(1)) call fail('Solid particle CSV failure mismatch')
|
||||
end subroutine check_particle_csv
|
||||
|
||||
subroutine check_summary_csv(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
|
||||
call assert_summary_int(filename, 'solid_particles', solid_particle_count)
|
||||
call assert_summary_int(filename, 'solid_failed_particles', solid_failed_count)
|
||||
if (solid_particle_count /= 1) call fail('Solid summary active count mismatch')
|
||||
if (solid_failed_count /= 1) call fail('Solid summary failed count mismatch')
|
||||
call assert_summary_present(filename, 'solid_mass')
|
||||
call assert_summary_present(filename, 'solid_momentum_x')
|
||||
call assert_summary_present(filename, 'solid_momentum_y')
|
||||
call assert_summary_present(filename, 'solid_momentum_z')
|
||||
call assert_summary_positive(filename, 'solid_kinetic_energy')
|
||||
call assert_summary_positive(filename, 'solid_internal_energy')
|
||||
call assert_summary_positive(filename, 'solid_max_von_mises')
|
||||
call assert_summary_present(filename, 'solid_plastic_strain_min')
|
||||
call assert_summary_present(filename, 'solid_plastic_strain_max')
|
||||
call assert_summary_present(filename, 'solid_damage_min')
|
||||
call assert_summary_present(filename, 'solid_damage_max')
|
||||
call assert_summary_present(filename, 'solid_softening_min')
|
||||
call assert_summary_present(filename, 'solid_softening_max')
|
||||
call assert_summary_positive(filename, 'solid_dt_cfl')
|
||||
call assert_summary_positive(filename, 'solid_dt_accel')
|
||||
call assert_summary_positive(filename, 'solid_dtcrit')
|
||||
if (solid_dtcrit <= 0.0_rk) call fail('Solid dtcrit diagnostic missing')
|
||||
end subroutine check_summary_csv
|
||||
|
||||
subroutine assert_summary_present(filename, metric)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=*), intent(in) :: metric
|
||||
character(len=256) :: line
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
logical :: found
|
||||
|
||||
found = .false.
|
||||
unit = 85
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Solid summary CSV open failed')
|
||||
do
|
||||
read(unit, '(A)', iostat=ios) line
|
||||
if (ios /= 0) exit
|
||||
if (index(line, trim(metric) // ',') == 1) found = .true.
|
||||
end do
|
||||
close(unit=unit)
|
||||
if (.not. found) call fail('Solid summary metric missing')
|
||||
end subroutine assert_summary_present
|
||||
|
||||
subroutine assert_summary_int(filename, metric, expected)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=*), intent(in) :: metric
|
||||
integer, intent(in) :: expected
|
||||
integer :: actual
|
||||
|
||||
call read_summary_int(filename, metric, actual)
|
||||
if (actual /= expected) call fail('Solid summary integer mismatch')
|
||||
end subroutine assert_summary_int
|
||||
|
||||
subroutine assert_summary_positive(filename, metric)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=*), intent(in) :: metric
|
||||
real(rk) :: value
|
||||
|
||||
call read_summary_real(filename, metric, value)
|
||||
if (value <= 0.0_rk) call fail('Solid summary positive metric missing')
|
||||
end subroutine assert_summary_positive
|
||||
|
||||
subroutine read_summary_int(filename, metric, value)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=*), intent(in) :: metric
|
||||
integer, intent(out) :: value
|
||||
character(len=256) :: line
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
integer :: start
|
||||
|
||||
unit = 86
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Solid summary integer open failed')
|
||||
do
|
||||
read(unit, '(A)', iostat=ios) line
|
||||
if (ios /= 0) exit
|
||||
if (index(line, trim(metric) // ',') == 1) then
|
||||
start = len_trim(metric) + 2
|
||||
read(line(start:), *, iostat=ios) value
|
||||
close(unit=unit)
|
||||
if (ios /= 0) call fail('Solid summary integer parse failed')
|
||||
return
|
||||
end if
|
||||
end do
|
||||
close(unit=unit)
|
||||
call fail('Solid summary integer missing')
|
||||
end subroutine read_summary_int
|
||||
|
||||
subroutine read_summary_real(filename, metric, value)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=*), intent(in) :: metric
|
||||
real(rk), intent(out) :: value
|
||||
character(len=256) :: line
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
integer :: start
|
||||
|
||||
unit = 87
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Solid summary real open failed')
|
||||
do
|
||||
read(unit, '(A)', iostat=ios) line
|
||||
if (ios /= 0) exit
|
||||
if (index(line, trim(metric) // ',') == 1) then
|
||||
start = len_trim(metric) + 2
|
||||
read(line(start:), *, iostat=ios) value
|
||||
close(unit=unit)
|
||||
if (ios /= 0) call fail('Solid summary real parse failed')
|
||||
return
|
||||
end if
|
||||
end do
|
||||
close(unit=unit)
|
||||
call fail('Solid summary real missing')
|
||||
end subroutine read_summary_real
|
||||
|
||||
subroutine delete_output_pair(step_value)
|
||||
integer, intent(in) :: step_value
|
||||
character(len=256) :: filename
|
||||
|
||||
write(filename, '("build-codex-unix/sphlite_",I8.8,".csv")') step_value
|
||||
call delete_file_if_exists(filename)
|
||||
write(filename, '("build-codex-unix/sphlite_",I8.8,"_summary.csv")') step_value
|
||||
call delete_file_if_exists(filename)
|
||||
end subroutine delete_output_pair
|
||||
|
||||
subroutine delete_file_if_exists(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
logical :: exists
|
||||
integer :: ios
|
||||
|
||||
inquire(file=trim(filename), exist=exists)
|
||||
if (.not. exists) return
|
||||
open(unit=88, file=trim(filename), status='old', iostat=ios)
|
||||
if (ios == 0) close(unit=88, status='delete')
|
||||
end subroutine delete_file_if_exists
|
||||
|
||||
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_output
|
||||
Reference in New Issue
Block a user