132 lines
5.3 KiB
Fortran
132 lines
5.3 KiB
Fortran
program test_contact_force
|
|
use iso_c_binding, only: c_double, c_int32_t, c_int64_t
|
|
use ccl_case_types, only: CCL_Surface_Interaction_Config
|
|
use ccl_contact_force, only: CCL_Contact_Force_Stats_Type, ccl_contact_force_compute, &
|
|
ccl_contact_force_stats_reset, ccl_contact_normal_velocity
|
|
use ccl_contact_narrow, only: CCL_Contact_Record_Type
|
|
use ccl_errors, only: CCL_SUCCESS
|
|
use ccl_interface_view, only: CCL_FEM_Facet_View_Type, CCL_FEM_Load_Accumulator_Type, &
|
|
CCL_SPH_Force_Accumulator_Type, CCL_SPH_Particle_View_Type, ccl_fem_load_accumulator_init, &
|
|
ccl_sph_force_accumulator_init
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
type(CCL_Surface_Interaction_Config) :: interaction
|
|
type(CCL_SPH_Particle_View_Type) :: particles(1)
|
|
type(CCL_FEM_Facet_View_Type) :: facets(1)
|
|
type(CCL_Contact_Record_Type) :: contacts(1)
|
|
type(CCL_SPH_Force_Accumulator_Type) :: sph_forces
|
|
type(CCL_FEM_Load_Accumulator_Type) :: fem_loads
|
|
type(CCL_Contact_Force_Stats_Type) :: stats
|
|
|
|
call make_interaction(interaction)
|
|
call make_particle(particles(1))
|
|
call make_facet(facets(1))
|
|
call make_contact(contacts(1))
|
|
call ccl_sph_force_accumulator_init(sph_forces, 2)
|
|
call ccl_fem_load_accumulator_init(fem_loads, 8)
|
|
call ccl_contact_force_stats_reset(stats)
|
|
|
|
call require_real_close(ccl_contact_normal_velocity(particles(1), facets(1), contacts(1)), &
|
|
-1.0_c_double, "normal velocity")
|
|
call ccl_contact_force_compute(interaction, particles, 1, facets, 1, contacts, 1, sph_forces, &
|
|
fem_loads, stats, ierr)
|
|
call require_equal(ierr, CCL_SUCCESS, "penalty force compute")
|
|
call require_equal(sph_forces%count, 1, "SPH force count")
|
|
call require_equal(fem_loads%count, 4, "FEM nodal load count")
|
|
call require_real_close(sph_forces%records(1)%force(3), 20.0_c_double, "SPH penalty damping force")
|
|
call require_real_close(stats%total_sph_force(3), 20.0_c_double, "total SPH force")
|
|
call require_real_close(stats%total_fem_force(3), -20.0_c_double, "total FEM force")
|
|
call require_real_close(stats%force_balance_error, 0.0_c_double, "force balance")
|
|
call require_real_close(stats%moment_balance_error, 0.0_c_double, "moment balance")
|
|
call require_equal(stats%nonfinite_force_count, 0, "nonfinite force count")
|
|
|
|
contains
|
|
|
|
subroutine make_interaction(value)
|
|
type(CCL_Surface_Interaction_Config), intent(out) :: value
|
|
|
|
value = CCL_Surface_Interaction_Config()
|
|
value%name = "PENALTY_1"
|
|
value%normal_model = "PENALTY"
|
|
value%kn = 100.0_c_double
|
|
value%cn = 10.0_c_double
|
|
value%has_kn = .true.
|
|
value%has_cn = .true.
|
|
end subroutine make_interaction
|
|
|
|
subroutine make_particle(particle)
|
|
type(CCL_SPH_Particle_View_Type), intent(out) :: particle
|
|
|
|
particle = CCL_SPH_Particle_View_Type()
|
|
particle%external_id = 101_c_int64_t
|
|
particle%internal_index = 1_c_int32_t
|
|
particle%status = 1_c_int32_t
|
|
particle%valid_flags = 1_c_int32_t
|
|
particle%contact_radius = 0.2_c_double
|
|
particle%mass = 1.0_c_double
|
|
particle%x = [0.25_c_double, 0.25_c_double, 0.10_c_double]
|
|
particle%v = [0.0_c_double, 0.0_c_double, -1.0_c_double]
|
|
end subroutine make_particle
|
|
|
|
subroutine make_facet(facet)
|
|
type(CCL_FEM_Facet_View_Type), intent(out) :: facet
|
|
|
|
facet = CCL_FEM_Facet_View_Type()
|
|
facet%facet_id = 201_c_int64_t
|
|
facet%node_count = 4_c_int32_t
|
|
facet%node_ids(1:4) = [201_c_int64_t, 202_c_int64_t, 203_c_int64_t, 204_c_int64_t]
|
|
facet%area = 1.0_c_double
|
|
facet%thickness = 0.0_c_double
|
|
facet%normal = [0.0_c_double, 0.0_c_double, 1.0_c_double]
|
|
facet%x(:, 1) = [0.0_c_double, 0.0_c_double, 0.0_c_double]
|
|
facet%x(:, 2) = [1.0_c_double, 0.0_c_double, 0.0_c_double]
|
|
facet%x(:, 3) = [1.0_c_double, 1.0_c_double, 0.0_c_double]
|
|
facet%x(:, 4) = [0.0_c_double, 1.0_c_double, 0.0_c_double]
|
|
facet%v = 0.0_c_double
|
|
facet%valid_flags = 1_c_int32_t
|
|
end subroutine make_facet
|
|
|
|
subroutine make_contact(contact)
|
|
type(CCL_Contact_Record_Type), intent(out) :: contact
|
|
|
|
contact = CCL_Contact_Record_Type()
|
|
contact%step_id = 1_c_int32_t
|
|
contact%pair_id = 1_c_int32_t
|
|
contact%particle_index = 1
|
|
contact%facet_index = 1
|
|
contact%sph_external_id = 101_c_int64_t
|
|
contact%facet_id = 201_c_int64_t
|
|
contact%node_count = 4_c_int32_t
|
|
contact%normal = [0.0_c_double, 0.0_c_double, 1.0_c_double]
|
|
contact%gap = 0.1_c_double
|
|
contact%contact_distance = 0.2_c_double
|
|
contact%penetration = 0.1_c_double
|
|
contact%closest_point = [0.25_c_double, 0.25_c_double, 0.0_c_double]
|
|
contact%shape_weights(1:4) = [0.5625_c_double, 0.1875_c_double, 0.0625_c_double, 0.1875_c_double]
|
|
end subroutine make_contact
|
|
|
|
subroutine require_equal(actual, expected, message)
|
|
integer, intent(in) :: actual
|
|
integer, intent(in) :: expected
|
|
character(len=*), intent(in) :: message
|
|
|
|
if (actual /= expected) then
|
|
print '(a,": expected ",i0," got ",i0)', trim(message), expected, actual
|
|
stop 1
|
|
end if
|
|
end subroutine require_equal
|
|
|
|
subroutine require_real_close(actual, expected, message)
|
|
real(c_double), intent(in) :: actual
|
|
real(c_double), intent(in) :: expected
|
|
character(len=*), intent(in) :: message
|
|
|
|
if (abs(actual - expected) > 1.0e-10_c_double) then
|
|
print '(a,": expected ",es12.4," got ",es12.4)', trim(message), expected, actual
|
|
stop 1
|
|
end if
|
|
end subroutine require_real_close
|
|
|
|
end program test_contact_force
|