310 lines
11 KiB
Fortran
310 lines
11 KiB
Fortran
program test_particle_acceptance
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_particle_state
|
|
use fem_particle_contact
|
|
use fem_particle_step
|
|
use fem_particle_facet_coupling
|
|
use fem_particle_facet_step
|
|
implicit none
|
|
|
|
real(rk), parameter :: TOL = 1.0e-9_rk
|
|
|
|
call check_free_fall()
|
|
call check_wall_collision()
|
|
call check_particle_pile()
|
|
call check_particle_facet()
|
|
|
|
contains
|
|
|
|
subroutine check_free_fall()
|
|
type(particle_contact_params) :: params
|
|
type(particle_step_ctrl) :: ctrl
|
|
type(particle_step_diag) :: diag
|
|
type(particle_wall_def) :: wall(1)
|
|
integer :: slot
|
|
integer :: ierr
|
|
real(rk) :: mass0
|
|
real(rk) :: mass1
|
|
real(rk) :: mom0(3)
|
|
real(rk) :: mom1(3)
|
|
real(rk) :: ke0
|
|
real(rk) :: ke1
|
|
real(rk) :: dissipated
|
|
real(rk) :: max_overlap
|
|
|
|
call particle_reset()
|
|
call particle_add(1, (/ ZERO, ZERO, ONE /), (/ ZERO, ZERO, ZERO /), &
|
|
0.10_rk, 2.0_rk, slot, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(10)
|
|
call init_params(100.0_rk, ZERO, ZERO, ZERO, 100.0_rk, ZERO, params, 11)
|
|
call pstep_ctrl_init(0.20_rk, ZERO, (/ ZERO, ZERO, -10.0_rk /), ZERO, &
|
|
ctrl, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(12)
|
|
wall(1)%active = .false.
|
|
|
|
call pstep_advance(ctrl, params, wall, 1, diag, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(13)
|
|
call pstep_diag_values(diag, ctrl%dt, mass0, mass1, mom0, mom1, ke0, ke1, &
|
|
dissipated, max_overlap, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(14)
|
|
call check_close(mass0, 2.0_rk, 15)
|
|
call check_close(mass1, 2.0_rk, 16)
|
|
call check_vec(mom0, (/ ZERO, ZERO, ZERO /), 17)
|
|
call check_vec(mom1, (/ ZERO, ZERO, -4.0_rk /), 18)
|
|
call check_close(ke0, ZERO, 19)
|
|
call check_close(ke1, 4.0_rk, 20)
|
|
call check_close(max_overlap, ZERO, 21)
|
|
call require_nonnegative_value(dissipated, 22)
|
|
if (diag%pair_count .ne. 0 .or. diag%wall_count .ne. 0) call fail(23)
|
|
end subroutine check_free_fall
|
|
|
|
subroutine check_wall_collision()
|
|
type(particle_contact_params) :: params
|
|
type(particle_step_ctrl) :: ctrl
|
|
type(particle_step_diag) :: diag
|
|
type(particle_wall_def) :: wall(1)
|
|
integer :: slot
|
|
integer :: ierr
|
|
real(rk) :: mass0
|
|
real(rk) :: mass1
|
|
real(rk) :: mom0(3)
|
|
real(rk) :: mom1(3)
|
|
real(rk) :: ke0
|
|
real(rk) :: ke1
|
|
real(rk) :: dissipated
|
|
real(rk) :: max_overlap
|
|
|
|
call particle_reset()
|
|
call particle_add(2, (/ ZERO, ZERO, 0.45_rk /), &
|
|
(/ ZERO, ZERO, -ONE /), 0.50_rk, ONE, slot, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(40)
|
|
call init_params(500.0_rk, ZERO, ZERO, ZERO, 2000.0_rk, 20.0_rk, &
|
|
params, 41)
|
|
call pstep_wall_init((/ ZERO, ZERO, ZERO /), (/ ZERO, ZERO, ONE /), &
|
|
wall(1), ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(42)
|
|
call pstep_ctrl_init(0.01_rk, ZERO, (/ ZERO, ZERO, ZERO /), ZERO, &
|
|
ctrl, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(43)
|
|
|
|
call pstep_advance(ctrl, params, wall, 1, diag, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(44)
|
|
call pstep_diag_values(diag, ctrl%dt, mass0, mass1, mom0, mom1, ke0, ke1, &
|
|
dissipated, max_overlap, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(45)
|
|
call check_close(mass0, mass1, 46)
|
|
call check_close(max_overlap, 0.05_rk, 47)
|
|
if (max_overlap .gt. 0.15_rk) call fail(48)
|
|
call require_nonnegative_value(dissipated, 49)
|
|
if (diag%wall_count .ne. 1 .or. diag%pair_count .ne. 0) call fail(50)
|
|
if (mom1(3) .le. ZERO) call fail(51)
|
|
if (ke1 .ge. ke0) call fail(52)
|
|
end subroutine check_wall_collision
|
|
|
|
subroutine check_particle_pile()
|
|
type(particle_contact_params) :: params
|
|
type(particle_step_ctrl) :: ctrl
|
|
type(particle_step_diag) :: diag
|
|
type(particle_wall_def) :: wall(1)
|
|
integer :: slot
|
|
integer :: ierr
|
|
real(rk) :: mass0
|
|
real(rk) :: mass1
|
|
real(rk) :: mom0(3)
|
|
real(rk) :: mom1(3)
|
|
real(rk) :: ke0
|
|
real(rk) :: ke1
|
|
real(rk) :: dissipated
|
|
real(rk) :: max_overlap
|
|
real(rk) :: ratio
|
|
|
|
call particle_reset()
|
|
call add_particle(10, (/ -0.45_rk, ZERO, 0.48_rk /), slot, 70)
|
|
call add_particle(11, (/ 0.45_rk, ZERO, 0.48_rk /), slot, 71)
|
|
call add_particle(12, (/ ZERO, ZERO, 1.30_rk /), slot, 72)
|
|
call init_params(800.0_rk, 2.0_rk, ZERO, ZERO, 2000.0_rk, 5.0_rk, &
|
|
params, 73)
|
|
call pstep_wall_init((/ ZERO, ZERO, ZERO /), (/ ZERO, ZERO, ONE /), &
|
|
wall(1), ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(74)
|
|
call pstep_ctrl_init(0.002_rk, ZERO, (/ ZERO, ZERO, ZERO /), ZERO, &
|
|
ctrl, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(75)
|
|
|
|
call pstep_advance(ctrl, params, wall, 1, diag, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(76)
|
|
call pstep_diag_values(diag, ctrl%dt, mass0, mass1, mom0, mom1, ke0, ke1, &
|
|
dissipated, max_overlap, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(77)
|
|
call check_close(mass0, 3.0_rk, 78)
|
|
call check_close(mass1, 3.0_rk, 79)
|
|
if (diag%pair_count .lt. 3 .or. diag%wall_count .lt. 2) call fail(80)
|
|
call pstep_contact_ratio(diag, 0.50_rk, ratio, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(81)
|
|
if (ratio .gt. 0.25_rk) call fail(82)
|
|
if (ke1 .le. ke0) call fail(83)
|
|
call require_nonnegative_value(dissipated, 84)
|
|
end subroutine check_particle_pile
|
|
|
|
subroutine check_particle_facet()
|
|
type(particle_contact_params) :: params
|
|
type(pfacet_step_stats) :: stats
|
|
integer, parameter :: NF = 1
|
|
integer, parameter :: MAXN = 3
|
|
integer :: slot
|
|
integer :: slots(1)
|
|
integer :: facet_nnode(NF)
|
|
integer :: particle_count_out
|
|
integer :: contact_count
|
|
integer :: ierr
|
|
real(rk) :: coords(3,MAXN,NF)
|
|
real(rk) :: velocities(3,MAXN,NF)
|
|
real(rk) :: node_loads(3,MAXN,NF)
|
|
real(rk) :: max_overlap
|
|
real(rk) :: total_energy
|
|
real(rk) :: total_power
|
|
real(rk) :: force_norm
|
|
real(rk) :: node_force_norm
|
|
real(rk) :: particle_force(3)
|
|
real(rk) :: residual
|
|
real(rk) :: momentum(3)
|
|
real(rk) :: total_mass
|
|
real(rk) :: kinetic
|
|
|
|
call setup_triangle(coords(:,:,1), velocities(:,:,1), facet_nnode(1))
|
|
node_loads = ZERO
|
|
call particle_reset()
|
|
call particle_add(20, (/ 0.25_rk, 0.25_rk, 0.20_rk /), &
|
|
(/ 0.50_rk, ZERO, -ONE /), 0.30_rk, 1.50_rk, &
|
|
slot, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(110)
|
|
call init_params(1000.0_rk, ZERO, 40.0_rk, 0.40_rk, 1000.0_rk, &
|
|
5.0_rk, params, 111)
|
|
|
|
slots(1) = slot
|
|
call pfacet_step_reset(stats)
|
|
call pfacet_step_cloud(1, slots, NF, MAXN, facet_nnode, coords, &
|
|
velocities, params, node_loads, stats, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(112)
|
|
call pfacet_step_summary(stats, particle_count_out, contact_count, &
|
|
max_overlap, total_energy, total_power, &
|
|
force_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(113)
|
|
if (particle_count_out .ne. 1 .or. contact_count .ne. 1) call fail(114)
|
|
call check_close(max_overlap, 0.10_rk, 115)
|
|
call require_nonnegative_value(total_power * 0.01_rk, 116)
|
|
call pfacet_step_force_norms(stats, force_norm, node_force_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(117)
|
|
if (force_norm .le. ZERO .or. node_force_norm .le. ZERO) call fail(118)
|
|
call particle_force_at(slot, particle_force, 119)
|
|
call pfacet_force_balance(3, node_loads(:,1:3,1), particle_force, &
|
|
residual, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(120)
|
|
call check_close(residual, ZERO, 121)
|
|
call particle_momentum(momentum, total_mass, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(122)
|
|
call particle_kinetic_energy(kinetic, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(123)
|
|
call check_close(total_mass, 1.50_rk, 124)
|
|
call check_vec(momentum, (/ 0.75_rk, ZERO, -1.50_rk /), 125)
|
|
call check_close(kinetic, 0.9375_rk, 126)
|
|
end subroutine check_particle_facet
|
|
|
|
subroutine init_params(kn, cn, kt, mu, kwall, cwall, params, code)
|
|
real(rk), intent(in) :: kn
|
|
real(rk), intent(in) :: cn
|
|
real(rk), intent(in) :: kt
|
|
real(rk), intent(in) :: mu
|
|
real(rk), intent(in) :: kwall
|
|
real(rk), intent(in) :: cwall
|
|
type(particle_contact_params), intent(out) :: params
|
|
integer, intent(in) :: code
|
|
|
|
integer :: ierr
|
|
|
|
call particle_contact_init(kn, cn, kt, mu, kwall, cwall, params, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(code)
|
|
end subroutine init_params
|
|
|
|
subroutine add_particle(ext_id, position, slot, code)
|
|
integer, intent(in) :: ext_id
|
|
real(rk), intent(in) :: position(3)
|
|
integer, intent(out) :: slot
|
|
integer, intent(in) :: code
|
|
|
|
integer :: ierr
|
|
|
|
call particle_add(ext_id, position, (/ ZERO, ZERO, ZERO /), 0.50_rk, &
|
|
ONE, slot, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(code)
|
|
end subroutine add_particle
|
|
|
|
subroutine setup_triangle(coords, velocities, nnode)
|
|
real(rk), intent(out) :: coords(3,3)
|
|
real(rk), intent(out) :: velocities(3,3)
|
|
integer, intent(out) :: nnode
|
|
|
|
nnode = 3
|
|
coords(:,1) = (/ ZERO, ZERO, ZERO /)
|
|
coords(:,2) = (/ ONE, ZERO, ZERO /)
|
|
coords(:,3) = (/ ZERO, ONE, ZERO /)
|
|
velocities = ZERO
|
|
end subroutine setup_triangle
|
|
|
|
subroutine particle_force_at(slot, force, code)
|
|
integer, intent(in) :: slot
|
|
real(rk), intent(out) :: force(3)
|
|
integer, intent(in) :: code
|
|
|
|
integer :: ierr
|
|
integer :: ext_id
|
|
logical :: active
|
|
real(rk) :: position(3)
|
|
real(rk) :: velocity(3)
|
|
real(rk) :: radius
|
|
real(rk) :: mass
|
|
|
|
call particle_get(slot, ext_id, active, position, velocity, radius, mass, &
|
|
force, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) call fail(code)
|
|
if (.not. active) call fail(code + 1)
|
|
end subroutine particle_force_at
|
|
|
|
subroutine require_nonnegative_value(value, code)
|
|
real(rk), intent(in) :: value
|
|
integer, intent(in) :: code
|
|
|
|
if (value .lt. -TOL) call fail(code)
|
|
end subroutine require_nonnegative_value
|
|
|
|
subroutine check_close(actual, expected, code)
|
|
real(rk), intent(in) :: actual
|
|
real(rk), intent(in) :: expected
|
|
integer, intent(in) :: code
|
|
|
|
if (abs(actual - expected) .gt. TOL * max(ONE, abs(expected))) then
|
|
call fail(code)
|
|
end if
|
|
end subroutine check_close
|
|
|
|
subroutine check_vec(actual, expected, code)
|
|
real(rk), intent(in) :: actual(3)
|
|
real(rk), intent(in) :: expected(3)
|
|
integer, intent(in) :: code
|
|
|
|
if (maxval(abs(actual - expected)) .gt. &
|
|
TOL * max(ONE, maxval(abs(expected)))) then
|
|
call fail(code)
|
|
end if
|
|
end subroutine check_vec
|
|
|
|
subroutine fail(code)
|
|
integer, intent(in) :: code
|
|
|
|
write(*,*) 'test_particle_acceptance failed:', code
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_particle_acceptance
|