Add blast diagnostics output boundary
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
program test_blast_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_advance_explicit, sph_set_output_directory, &
|
||||
sph_write_output
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
|
||||
call delete_output_pair(70)
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for Blast output')
|
||||
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for Blast output')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for Blast output')
|
||||
call sph_advance_explicit(1.0e-7_rk, ierr)
|
||||
call assert_ok(ierr, 'advance failed for Blast output')
|
||||
call sph_set_output_directory('build-codex-unix', ierr)
|
||||
call assert_ok(ierr, 'set output directory failed for Blast output')
|
||||
call sph_write_output(70, 1.0e-7_rk, ierr)
|
||||
call assert_ok(ierr, 'write failed for Blast output')
|
||||
call check_particle_csv('build-codex-unix/sphlite_00000070.csv')
|
||||
call check_summary_csv('build-codex-unix/sphlite_00000070_summary.csv')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize failed for Blast output')
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_particle_csv(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=512) :: header
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
|
||||
unit = 94
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Blast particle CSV open failed')
|
||||
read(unit, '(A)', iostat=ios) header
|
||||
if (ios /= 0) call fail('Blast particle CSV header missing')
|
||||
if (index(header, 'blast_solid_fx,blast_solid_fy,blast_solid_fz') <= 0) then
|
||||
call fail('Blast particle CSV Solid force columns missing')
|
||||
end if
|
||||
call check_particle_rows(unit)
|
||||
close(unit=unit)
|
||||
end subroutine check_particle_csv
|
||||
|
||||
subroutine check_particle_rows(unit)
|
||||
integer, intent(in) :: unit
|
||||
integer :: ios
|
||||
integer :: id
|
||||
real(rk) :: blast_values(9)
|
||||
|
||||
do
|
||||
call read_particle_row(unit, id, blast_values, ios)
|
||||
if (ios /= 0) exit
|
||||
if (id == 5) then
|
||||
if (blast_values(1) <= 0.0_rk) call fail('Blast Solid force not output')
|
||||
if (maxval(abs(blast_values(4:9))) > 0.0_rk) then
|
||||
call fail('Blast Solid row polluted Shell load columns')
|
||||
end if
|
||||
return
|
||||
end if
|
||||
end do
|
||||
call fail('Blast output target row missing')
|
||||
end subroutine check_particle_rows
|
||||
|
||||
subroutine read_particle_row(unit, id, blast_values, ios)
|
||||
integer, intent(in) :: unit
|
||||
integer, intent(out) :: id
|
||||
real(rk), intent(out) :: blast_values(9)
|
||||
integer, intent(out) :: ios
|
||||
integer :: phase
|
||||
integer :: status
|
||||
integer :: mat
|
||||
integer :: sec
|
||||
integer :: failure
|
||||
integer :: reference_neighbors
|
||||
integer :: correction_status
|
||||
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) :: solid_values(5)
|
||||
|
||||
read(unit, *, iostat=ios) id, phase, status, mat, sec, pos, vel, &
|
||||
scalar_values, explosive_values, stress_values, solid_values, &
|
||||
blast_values, failure, reference_neighbors, correction_status
|
||||
end subroutine read_particle_row
|
||||
|
||||
subroutine check_summary_csv(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
|
||||
call assert_summary_int(filename, 'blast_regions', 1)
|
||||
call assert_summary_int(filename, 'blast_source_count_1', 1)
|
||||
call assert_summary_int(filename, 'blast_load_targets_1', 2)
|
||||
call assert_summary_positive(filename, 'blast_solid_force_x_1')
|
||||
call assert_summary_positive(filename, 'blast_total_force_x_1')
|
||||
call assert_summary_positive(filename, 'blast_energy_input_1')
|
||||
call assert_summary_positive(filename, 'blast_max_acceleration_1')
|
||||
end subroutine check_summary_csv
|
||||
|
||||
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('Blast 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('Blast 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 = 95
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Blast 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('Blast summary integer parse failed')
|
||||
return
|
||||
end if
|
||||
end do
|
||||
close(unit=unit)
|
||||
call fail('Blast 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 = 96
|
||||
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Blast 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('Blast summary real parse failed')
|
||||
return
|
||||
end if
|
||||
end do
|
||||
close(unit=unit)
|
||||
call fail('Blast 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=97, file=trim(filename), status='old', iostat=ios)
|
||||
if (ios == 0) close(unit=97, 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_blast_output
|
||||
@@ -0,0 +1,78 @@
|
||||
program test_blast_restart_boundary
|
||||
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_advance_explicit, sph_write_restart, &
|
||||
sph_read_restart, sph_get_blast_summary
|
||||
use sph_blast_load, only: SPH_BLAST_SUMMARY_COUNT_SIZE, &
|
||||
SPH_BLAST_SUMMARY_VALUE_SIZE
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
integer :: counts(SPH_BLAST_SUMMARY_COUNT_SIZE)
|
||||
real(rk) :: values(SPH_BLAST_SUMMARY_VALUE_SIZE)
|
||||
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for Blast restart boundary')
|
||||
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_070.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for Blast restart boundary')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for Blast restart boundary')
|
||||
call sph_advance_explicit(1.0e-7_rk, ierr)
|
||||
call assert_ok(ierr, 'advance failed for Blast restart boundary')
|
||||
call sph_get_blast_summary(1, counts, values, ierr)
|
||||
call assert_ok(ierr, 'pre-restart Blast summary failed')
|
||||
if (counts(6) <= 0) call fail('pre-restart Blast load summary missing')
|
||||
call sph_write_restart('build-codex-unix/restart_blast_boundary.tmp', ierr)
|
||||
call assert_ok(ierr, 'write failed for Blast restart boundary')
|
||||
call assert_restart_header('build-codex-unix/restart_blast_boundary.tmp')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize write session failed for Blast restart boundary')
|
||||
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize read session failed for Blast restart boundary')
|
||||
call sph_read_restart('build-codex-unix/restart_blast_boundary.tmp', ierr)
|
||||
call assert_ok(ierr, 'read failed for Blast restart boundary')
|
||||
call sph_get_blast_summary(1, counts, values, ierr)
|
||||
call assert_ok(ierr, 'post-restart Blast summary failed')
|
||||
if (maxval(abs(counts)) /= 0) call fail('Blast restart restored non-state counts')
|
||||
if (maxval(abs(values)) > 0.0_rk) call fail('Blast restart restored diagnostics')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize read session failed for Blast restart boundary')
|
||||
|
||||
contains
|
||||
|
||||
subroutine assert_restart_header(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=32) :: tag
|
||||
character(len=32) :: state
|
||||
integer :: major
|
||||
integer :: minor
|
||||
integer :: patch
|
||||
integer :: ios
|
||||
|
||||
open(unit=98, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
if (ios /= 0) call fail('Blast restart header open failed')
|
||||
read(98, *, iostat=ios) tag, major, minor, patch, state
|
||||
close(unit=98)
|
||||
if (ios /= 0) call fail('Blast restart header read failed')
|
||||
if (trim(tag) /= 'SPHLITE_RESTART') call fail('Blast restart tag mismatch')
|
||||
if (trim(state) == 'STATE_0_7') call fail('Blast restart state was frozen too early')
|
||||
if (trim(state) /= 'STATE_0_5_1') call fail('Blast restart boundary state mismatch')
|
||||
end subroutine assert_restart_header
|
||||
|
||||
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_blast_restart_boundary
|
||||
@@ -0,0 +1,85 @@
|
||||
program test_blast_summary
|
||||
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_advance_explicit, sph_get_blast_summary
|
||||
use sph_blast_load, only: SPH_BLAST_SUMMARY_COUNT_SIZE, &
|
||||
SPH_BLAST_SUMMARY_VALUE_SIZE
|
||||
implicit none
|
||||
|
||||
integer :: ierr
|
||||
integer :: counts(SPH_BLAST_SUMMARY_COUNT_SIZE)
|
||||
real(rk) :: values(SPH_BLAST_SUMMARY_VALUE_SIZE)
|
||||
|
||||
call check_initial_summary()
|
||||
call check_advanced_summary()
|
||||
call check_invalid_region()
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_initial_summary()
|
||||
call setup_blast_model()
|
||||
call sph_get_blast_summary(1, counts, values, ierr)
|
||||
call assert_ok(ierr, 'initial Blast summary query failed')
|
||||
if (counts(1) /= 1) call fail('Blast source count mismatch')
|
||||
if (counts(2) /= 4) call fail('Blast target count mismatch')
|
||||
if (counts(3) /= 4) call fail('Blast candidate pair count mismatch')
|
||||
if (counts(6) /= 4) call fail('Blast load target count mismatch')
|
||||
if (counts(10) /= 2) call fail('Blast Water count mismatch')
|
||||
if (counts(11) /= 1) call fail('Blast Gas count mismatch')
|
||||
if (counts(12) /= 1) call fail('Blast Explosive count mismatch')
|
||||
if (values(1) <= 0.0_rk) call fail('Blast source mass missing')
|
||||
if (values(3) <= 0.0_rk) call fail('Blast source pressure missing')
|
||||
if (values(8) <= 0.0_rk) call fail('Blast Solid force missing')
|
||||
if (values(11) <= 0.0_rk) call fail('Blast Shell force missing')
|
||||
if (values(25) <= 0.0_rk) call fail('Blast max force missing')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize initial Blast summary failed')
|
||||
end subroutine check_initial_summary
|
||||
|
||||
subroutine check_advanced_summary()
|
||||
call setup_blast_model()
|
||||
call sph_advance_explicit(1.0e-7_rk, ierr)
|
||||
call assert_ok(ierr, 'Blast summary advance failed')
|
||||
call sph_get_blast_summary(1, counts, values, ierr)
|
||||
call assert_ok(ierr, 'advanced Blast summary query failed')
|
||||
if (values(5) < 0.99_rk) call fail('Blast progress summary missing')
|
||||
if (values(24) <= 0.0_rk) call fail('Blast energy input summary missing')
|
||||
if (values(26) <= 0.0_rk) call fail('Blast acceleration summary missing')
|
||||
if (counts(9) /= 0) call fail('Blast nonfinite count mismatch')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize advanced Blast summary failed')
|
||||
end subroutine check_advanced_summary
|
||||
|
||||
subroutine check_invalid_region()
|
||||
call setup_blast_model()
|
||||
call sph_get_blast_summary(0, counts, values, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('invalid Blast region summary succeeded')
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize invalid Blast summary failed')
|
||||
end subroutine check_invalid_region
|
||||
|
||||
subroutine setup_blast_model()
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize failed for Blast summary')
|
||||
call sph_read_inp('tests/data/blast_water_gas_explosive_solid_shell_070.inp', ierr)
|
||||
call assert_ok(ierr, 'read failed for Blast summary')
|
||||
call sph_build_model(ierr)
|
||||
call assert_ok(ierr, 'build failed for Blast summary')
|
||||
end subroutine setup_blast_model
|
||||
|
||||
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_blast_summary
|
||||
@@ -106,7 +106,7 @@ contains
|
||||
|
||||
subroutine check_particle_header(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=512) :: header
|
||||
character(len=1024) :: header
|
||||
integer :: ios
|
||||
|
||||
open(unit=71, file=trim(filename), status='old', action='read', iostat=ios)
|
||||
@@ -121,6 +121,9 @@ contains
|
||||
'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_strain_rate_eq,solid_acceleration_norm,' // &
|
||||
'blast_solid_fx,blast_solid_fy,blast_solid_fz,' // &
|
||||
'blast_shell_fx,blast_shell_fy,blast_shell_fz,' // &
|
||||
'blast_shell_mx,blast_shell_my,blast_shell_mz,' // &
|
||||
'solid_failure_status,solid_reference_neighbor_count,' // &
|
||||
'solid_correction_status') then
|
||||
call fail('particle CSV header mismatch')
|
||||
@@ -178,6 +181,7 @@ contains
|
||||
call assert_summary_metric(filename, 'solid_correction_det_min')
|
||||
call assert_summary_metric(filename, 'solid_correction_status')
|
||||
call assert_summary_metric(filename, 'solid_dtcrit')
|
||||
call assert_summary_metric(filename, 'blast_regions')
|
||||
end subroutine check_summary_metrics
|
||||
|
||||
subroutine assert_summary_metric(filename, metric)
|
||||
|
||||
@@ -62,7 +62,7 @@ contains
|
||||
|
||||
subroutine check_particle_csv(filename)
|
||||
character(len=*), intent(in) :: filename
|
||||
character(len=512) :: header
|
||||
character(len=1024) :: header
|
||||
integer :: unit
|
||||
integer :: ios
|
||||
integer :: id
|
||||
@@ -81,6 +81,7 @@ contains
|
||||
real(rk) :: softening
|
||||
real(rk) :: strain_rate_eq
|
||||
real(rk) :: acceleration_norm
|
||||
real(rk) :: blast_force_values(9)
|
||||
integer :: reference_neighbors
|
||||
integer :: correction_status
|
||||
|
||||
@@ -96,13 +97,16 @@ contains
|
||||
'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_strain_rate_eq,solid_acceleration_norm,' // &
|
||||
'blast_solid_fx,blast_solid_fy,blast_solid_fz,' // &
|
||||
'blast_shell_fx,blast_shell_fy,blast_shell_fz,' // &
|
||||
'blast_shell_mx,blast_shell_my,blast_shell_mz,' // &
|
||||
'solid_failure_status,solid_reference_neighbor_count,' // &
|
||||
'solid_correction_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, strain_rate_eq, acceleration_norm, failure, &
|
||||
softening, strain_rate_eq, acceleration_norm, blast_force_values, failure, &
|
||||
reference_neighbors, correction_status
|
||||
close(unit=unit)
|
||||
if (ios /= 0) call fail('Solid particle CSV row read failed')
|
||||
@@ -128,6 +132,9 @@ contains
|
||||
if (abs(acceleration_norm - sqrt(sum(a(:,1) * a(:,1)))) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV acceleration mismatch')
|
||||
end if
|
||||
if (maxval(abs(blast_force_values)) > 1.0e-12_rk) then
|
||||
call fail('Solid particle CSV Blast load pollution')
|
||||
end if
|
||||
if (failure /= solid_failure_status(1)) call fail('Solid particle CSV failure mismatch')
|
||||
if (reference_neighbors /= solid_reference_neighbor_count(1)) then
|
||||
call fail('Solid particle CSV reference neighbor mismatch')
|
||||
|
||||
Reference in New Issue
Block a user