Files
SPHLite/tests/module/test_water_force.f90
T

86 lines
2.8 KiB
Fortran

program test_water_force
use sph_precision, only: rk
use sph_error, only: SPH_SUCCESS
use sph_database, only: sph_db_allocate, sph_db_free, x, v, h, mass, rho, pressure, &
acc_pressure, a, particle_phase, particle_status, SPH_PHASE_WATER, SPH_STATUS_ACTIVE
use sph_neighbor, only: sph_neighbor_rebuild
use sph_water, only: sph_water_initialize, sph_water_reset, sph_water_set_body_force, &
sph_water_compute_pressure_acceleration, sph_water_compute_acceleration
implicit none
integer :: ierr
call sph_water_initialize()
call check_pressure_pair()
call check_uniform_pressure()
call check_body_force()
call sph_water_reset()
contains
subroutine setup_pair()
call sph_db_allocate(2, ierr)
call assert_ok(ierr, 'force allocation failed')
particle_phase = SPH_PHASE_WATER
particle_status = SPH_STATUS_ACTIVE
h = 1.0_rk
mass = 1.0_rk
rho = 1000.0_rk
v = 0.0_rk
x(:,1) = (/0.0_rk, 0.0_rk, 0.0_rk/)
x(:,2) = (/0.5_rk, 0.0_rk, 0.0_rk/)
call sph_neighbor_rebuild(ierr)
call assert_ok(ierr, 'force neighbor failed')
end subroutine setup_pair
subroutine check_pressure_pair()
call setup_pair()
pressure = (/1000.0_rk, 0.0_rk/)
call sph_water_compute_pressure_acceleration(ierr)
call assert_ok(ierr, 'pressure acceleration failed')
if (maxval(abs(acc_pressure)) <= 0.0_rk) call fail('pressure acceleration is zero')
if (maxval(abs(acc_pressure(:,1) + acc_pressure(:,2))) > 1.0e-12_rk) then
call fail('pressure acceleration is not symmetric')
end if
call sph_db_free()
end subroutine check_pressure_pair
subroutine check_uniform_pressure()
call setup_pair()
pressure = 0.0_rk
acc_pressure = 3.0_rk
call sph_water_compute_pressure_acceleration(ierr)
call assert_ok(ierr, 'uniform pressure failed')
if (maxval(abs(acc_pressure)) > 1.0e-12_rk) call fail('zero pressure force is not zero')
call sph_db_free()
end subroutine check_uniform_pressure
subroutine check_body_force()
real(rk) :: force(3)
call setup_pair()
pressure = 0.0_rk
force = (/0.0_rk, 0.0_rk, -9.81_rk/)
call sph_water_set_body_force(force, ierr)
call assert_ok(ierr, 'set body force failed')
call sph_water_compute_acceleration(ierr)
call assert_ok(ierr, 'total acceleration failed')
if (abs(a(3,1) + 9.81_rk) > 1.0e-12_rk) call fail('body force acceleration mismatch')
call sph_db_free()
end subroutine check_body_force
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_water_force