290 lines
11 KiB
Fortran
290 lines
11 KiB
Fortran
program test_blast_output_071
|
|
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 check_default_output_disabled()
|
|
call check_multiregion_output()
|
|
|
|
contains
|
|
|
|
subroutine check_default_output_disabled()
|
|
call delete_output_pair(71)
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for default output check')
|
|
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for default output check')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for default output check')
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'advance failed for default output check')
|
|
call assert_file_missing('build-codex-unix/sphlite_00000071.csv')
|
|
call assert_file_missing('build-codex-unix/sphlite_00000071_summary.csv')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for default output check')
|
|
end subroutine check_default_output_disabled
|
|
|
|
subroutine check_multiregion_output()
|
|
call delete_output_pair(71)
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for 0.7.1 Blast output')
|
|
call sph_read_inp('tests/data/blast_multiregion_071.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for 0.7.1 Blast output')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for 0.7.1 Blast output')
|
|
call sph_advance_explicit(1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'advance failed for 0.7.1 Blast output')
|
|
call sph_set_output_directory('build-codex-unix', ierr)
|
|
call assert_ok(ierr, 'set output directory failed for 0.7.1 Blast output')
|
|
call sph_write_output(71, 1.0e-7_rk, ierr)
|
|
call assert_ok(ierr, 'write failed for 0.7.1 Blast output')
|
|
call check_particle_csv('build-codex-unix/sphlite_00000071.csv')
|
|
call check_summary_csv('build-codex-unix/sphlite_00000071_summary.csv')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for 0.7.1 Blast output')
|
|
end subroutine check_multiregion_output
|
|
|
|
subroutine check_particle_csv(filename)
|
|
character(len=*), intent(in) :: filename
|
|
character(len=512) :: header
|
|
integer :: unit
|
|
integer :: ios
|
|
|
|
unit = 84
|
|
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('0.7.1 Blast particle CSV open failed')
|
|
read(unit, '(A)', iostat=ios) header
|
|
if (ios /= 0) call fail('0.7.1 Blast particle CSV header missing')
|
|
if (index(header, 'blast_solid_fx,blast_solid_fy,blast_solid_fz') <= 0) then
|
|
call fail('0.7.1 Blast Solid force columns missing')
|
|
end if
|
|
if (index(header, 'blast_shell_fx,blast_shell_fy,blast_shell_fz') <= 0) then
|
|
call fail('0.7.1 Blast Shell 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
|
|
logical :: saw_solid
|
|
logical :: saw_shell
|
|
real(rk) :: blast_values(9)
|
|
|
|
saw_solid = .false.
|
|
saw_shell = .false.
|
|
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('Solid row Blast force missing')
|
|
if (maxval(abs(blast_values(4:9))) > 0.0_rk) then
|
|
call fail('Solid row polluted Shell Blast columns')
|
|
end if
|
|
saw_solid = .true.
|
|
else if (id == 7) then
|
|
if (blast_values(4) <= 0.0_rk) call fail('Shell row Blast x force missing')
|
|
if (blast_values(5) <= 0.0_rk) call fail('Shell row Blast y force missing')
|
|
if (maxval(abs(blast_values(1:3))) > 0.0_rk) then
|
|
call fail('Shell row polluted Solid Blast columns')
|
|
end if
|
|
if (maxval(abs(blast_values(7:9))) > 0.0_rk) then
|
|
call fail('Shell row moment placeholder changed')
|
|
end if
|
|
saw_shell = .true.
|
|
end if
|
|
end do
|
|
if (.not. saw_solid) call fail('0.7.1 Blast output Solid row missing')
|
|
if (.not. saw_shell) call fail('0.7.1 Blast output Shell 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
|
|
integer :: coupling_contact_flag
|
|
integer :: coupling_motion_flag
|
|
integer :: coupling_region_id
|
|
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)
|
|
real(rk) :: coupling_force(3)
|
|
real(rk) :: coupling_contact_values(2)
|
|
|
|
read(unit, *, iostat=ios) id, phase, status, mat, sec, pos, vel, &
|
|
scalar_values, explosive_values, stress_values, solid_values, &
|
|
blast_values, coupling_force, coupling_contact_values, &
|
|
coupling_contact_flag, failure, reference_neighbors, &
|
|
correction_status, coupling_motion_flag, coupling_region_id
|
|
end subroutine read_particle_row
|
|
|
|
subroutine check_summary_csv(filename)
|
|
character(len=*), intent(in) :: filename
|
|
|
|
call assert_summary_int(filename, 'blast_regions', 3)
|
|
call assert_summary_int(filename, 'blast_source_count_1', 1)
|
|
call assert_summary_int(filename, 'blast_source_count_2', 1)
|
|
call assert_summary_int(filename, 'blast_source_count_3', 0)
|
|
call assert_summary_int(filename, 'blast_load_targets_1', 2)
|
|
call assert_summary_int(filename, 'blast_load_targets_2', 2)
|
|
call assert_summary_int(filename, 'blast_load_targets_3', 0)
|
|
call assert_summary_positive(filename, 'blast_solid_force_x_1')
|
|
call assert_summary_zero(filename, 'blast_shell_force_x_1')
|
|
call assert_summary_positive(filename, 'blast_shell_force_x_2')
|
|
call assert_summary_positive(filename, 'blast_shell_force_y_2')
|
|
call assert_summary_zero(filename, 'blast_solid_force_x_2')
|
|
call assert_summary_positive(filename, 'blast_total_force_x_1')
|
|
call assert_summary_positive(filename, 'blast_total_force_x_2')
|
|
call assert_summary_zero(filename, 'blast_total_force_x_3')
|
|
call assert_summary_positive(filename, 'blast_energy_input_1')
|
|
call assert_summary_positive(filename, 'blast_energy_input_2')
|
|
call assert_summary_zero(filename, 'blast_energy_input_3')
|
|
call assert_summary_positive(filename, 'blast_max_acceleration_1')
|
|
call assert_summary_positive(filename, 'blast_max_acceleration_2')
|
|
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('0.7.1 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('0.7.1 Blast summary positive metric missing')
|
|
end subroutine assert_summary_positive
|
|
|
|
subroutine assert_summary_zero(filename, metric)
|
|
character(len=*), intent(in) :: filename
|
|
character(len=*), intent(in) :: metric
|
|
real(rk) :: value
|
|
|
|
call read_summary_real(filename, metric, value)
|
|
if (abs(value) > 1.0e-18_rk) call fail('0.7.1 Blast summary zero mismatch')
|
|
end subroutine assert_summary_zero
|
|
|
|
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 = 85
|
|
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('0.7.1 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('0.7.1 Blast summary integer parse failed')
|
|
return
|
|
end if
|
|
end do
|
|
close(unit=unit)
|
|
call fail('0.7.1 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 = 86
|
|
open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('0.7.1 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('0.7.1 Blast summary real parse failed')
|
|
return
|
|
end if
|
|
end do
|
|
close(unit=unit)
|
|
call fail('0.7.1 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=87, file=trim(filename), status='old', iostat=ios)
|
|
if (ios == 0) close(unit=87, status='delete')
|
|
end subroutine delete_file_if_exists
|
|
|
|
subroutine assert_file_missing(filename)
|
|
character(len=*), intent(in) :: filename
|
|
logical :: exists
|
|
|
|
inquire(file=trim(filename), exist=exists)
|
|
if (exists) call fail('default output wrote file unexpectedly')
|
|
end subroutine assert_file_missing
|
|
|
|
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_071
|