Add CCLite 0.2.2 interface views and load buffers
This commit is contained in:
@@ -26,7 +26,7 @@ module ccl_controller
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_SOLVER_ID_CCL = 3_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_EXPORT_RECORD_CAPACITY = 4_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_EMPTY_LOAD_CAPACITY = 0_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_LOAD_RECORD_CAPACITY = 4_c_int32_t
|
||||
|
||||
type :: CCL_Worker_Runtime
|
||||
character(len=16) :: solver_name = ""
|
||||
@@ -191,7 +191,7 @@ contains
|
||||
|
||||
command_bytes = int(ccl_command_block_size(), c_size_t)
|
||||
export_bytes = data_block_bytes(worker%export_role, CCL_EXPORT_RECORD_CAPACITY)
|
||||
load_bytes = data_block_bytes(worker%load_role, CCL_EMPTY_LOAD_CAPACITY)
|
||||
load_bytes = data_block_bytes(worker%load_role, CCL_LOAD_RECORD_CAPACITY)
|
||||
|
||||
call ccl_shm_create(worker%command_name, command_bytes, worker%command_shm, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
@@ -208,7 +208,7 @@ contains
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call c_f_pointer(worker%load_shm%payload, worker%load_header)
|
||||
call ccl_data_header_init(worker%load_header, worker%load_role, CCL_SOLVER_ID_CCL, &
|
||||
worker%solver_id, CCL_EMPTY_LOAD_CAPACITY)
|
||||
worker%solver_id, CCL_LOAD_RECORD_CAPACITY)
|
||||
|
||||
call ccl_event_create(worker%command_event_name, .false., worker%command_event, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
@@ -279,6 +279,8 @@ contains
|
||||
call prepare_empty_load(fem_worker, step_id, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
|
||||
call log_step_interface_counts(diag, sph_worker, fem_worker, step_id)
|
||||
|
||||
call send_worker_command(sph_worker, CCL_CMD_IMPORT_LOADS, step_id, dt, diag, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call send_worker_command(fem_worker, CCL_CMD_IMPORT_LOADS, step_id, dt, diag, ierr)
|
||||
@@ -369,6 +371,21 @@ contains
|
||||
call ccl_data_header_set_state(worker%load_header, CCL_BUFFER_READY, ierr)
|
||||
end subroutine prepare_empty_load
|
||||
|
||||
subroutine log_step_interface_counts(diag, sph_worker, fem_worker, step_id)
|
||||
type(CCL_Diagnostics_Type), intent(inout) :: diag
|
||||
type(CCL_Worker_Runtime), intent(in) :: sph_worker
|
||||
type(CCL_Worker_Runtime), intent(in) :: fem_worker
|
||||
integer, intent(in) :: step_id
|
||||
character(len=256) :: msg
|
||||
|
||||
write(msg, '(a,i0,a,i0,a,i0,a,i0,a,i0)') "step=", step_id, &
|
||||
" sph_particles=", sph_worker%export_header%item_count, &
|
||||
" fem_facets=", fem_worker%export_header%item_count, &
|
||||
" sph_forces=", sph_worker%load_header%item_count, &
|
||||
" fem_loads=", fem_worker%load_header%item_count
|
||||
call ccl_diagnostics_write_run(diag, "INFO", "interface_counts", trim(msg))
|
||||
end subroutine log_step_interface_counts
|
||||
|
||||
subroutine stop_worker(worker, diag, ierr)
|
||||
type(CCL_Worker_Runtime), intent(inout) :: worker
|
||||
type(CCL_Diagnostics_Type), intent(inout) :: diag
|
||||
|
||||
@@ -20,7 +20,7 @@ module ccl_mock_worker
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_SOLVER_ID_CCL = 3_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_EXPORT_RECORD_CAPACITY = 4_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_EMPTY_LOAD_CAPACITY = 0_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_LOAD_RECORD_CAPACITY = 4_c_int32_t
|
||||
|
||||
type :: CCL_Mock_Worker_Config
|
||||
logical :: service_mode = .false.
|
||||
@@ -213,7 +213,7 @@ contains
|
||||
|
||||
command_bytes = int(ccl_command_block_size(), c_size_t)
|
||||
export_bytes = data_block_bytes(runtime%export_role, CCL_EXPORT_RECORD_CAPACITY)
|
||||
load_bytes = data_block_bytes(runtime%load_role, CCL_EMPTY_LOAD_CAPACITY)
|
||||
load_bytes = data_block_bytes(runtime%load_role, CCL_LOAD_RECORD_CAPACITY)
|
||||
|
||||
call ccl_shm_open(runtime%command_name, command_bytes, runtime%command_shm, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
@@ -300,7 +300,7 @@ contains
|
||||
case (CCL_CMD_EXPORT_INTERFACE)
|
||||
call export_empty_block(runtime, ierr)
|
||||
case (CCL_CMD_IMPORT_LOADS)
|
||||
call consume_empty_load(runtime, ierr)
|
||||
call consume_load_block(runtime, ierr)
|
||||
case (CCL_CMD_STOP)
|
||||
should_stop = .true.
|
||||
case default
|
||||
@@ -322,7 +322,7 @@ contains
|
||||
call ccl_data_header_set_state(runtime%export_header, CCL_BUFFER_READY, ierr)
|
||||
end subroutine export_empty_block
|
||||
|
||||
subroutine consume_empty_load(runtime, ierr)
|
||||
subroutine consume_load_block(runtime, ierr)
|
||||
type(CCL_Mock_Worker_Runtime), intent(inout) :: runtime
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
@@ -335,7 +335,7 @@ contains
|
||||
call ccl_data_header_set_state(runtime%load_header, CCL_BUFFER_READING, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call ccl_data_header_set_state(runtime%load_header, CCL_BUFFER_CONSUMED, ierr)
|
||||
end subroutine consume_empty_load
|
||||
end subroutine consume_load_block
|
||||
|
||||
subroutine close_runtime(runtime, ierr)
|
||||
type(CCL_Mock_Worker_Runtime), intent(inout) :: runtime
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
module ccl_interface_view
|
||||
use, intrinsic :: ieee_arithmetic, only: ieee_is_finite
|
||||
use iso_c_binding, only: c_double, c_int32_t, c_int64_t
|
||||
use ccl_data_block, only: CCL_BUFFER_READY, CCL_BUFFER_WRITING, CCL_Data_Block_Header_Type, &
|
||||
CCL_FEM_Facet_Record_Type, CCL_FEM_Load_Record_Type, CCL_ROLE_CCL_TO_FEM_LOAD, &
|
||||
CCL_ROLE_CCL_TO_SPH_FORCE, CCL_SPH_Force_Record_Type, CCL_SPH_Particle_Record_Type, &
|
||||
ccl_data_header_set_count, ccl_data_header_set_state, ccl_data_header_validate
|
||||
use ccl_errors, only: CCL_ERROR_INPUT_INVALID_VALUE, CCL_ERROR_IPC_BAD_HEADER, CCL_SUCCESS
|
||||
implicit none
|
||||
|
||||
integer, parameter :: CCL_VIEW_MAX_FEM_NODES = 8
|
||||
|
||||
type :: CCL_SPH_Particle_View_Type
|
||||
integer(c_int64_t) :: external_id = 0_c_int64_t
|
||||
integer(c_int32_t) :: internal_index = 0_c_int32_t
|
||||
integer(c_int32_t) :: status = 0_c_int32_t
|
||||
integer(c_int32_t) :: valid_flags = 0_c_int32_t
|
||||
real(c_double) :: contact_radius = 0.0_c_double
|
||||
real(c_double) :: mass = 0.0_c_double
|
||||
real(c_double) :: x(3) = 0.0_c_double
|
||||
real(c_double) :: v(3) = 0.0_c_double
|
||||
end type CCL_SPH_Particle_View_Type
|
||||
|
||||
type :: CCL_FEM_Facet_View_Type
|
||||
integer(c_int64_t) :: facet_id = 0_c_int64_t
|
||||
integer(c_int32_t) :: node_count = 0_c_int32_t
|
||||
integer(c_int64_t) :: node_ids(CCL_VIEW_MAX_FEM_NODES) = 0_c_int64_t
|
||||
integer(c_int32_t) :: valid_flags = 0_c_int32_t
|
||||
real(c_double) :: area = 0.0_c_double
|
||||
real(c_double) :: thickness = 0.0_c_double
|
||||
real(c_double) :: normal(3) = 0.0_c_double
|
||||
real(c_double) :: x(3, CCL_VIEW_MAX_FEM_NODES) = 0.0_c_double
|
||||
real(c_double) :: v(3, CCL_VIEW_MAX_FEM_NODES) = 0.0_c_double
|
||||
end type CCL_FEM_Facet_View_Type
|
||||
|
||||
type :: CCL_SPH_Force_Accumulator_Type
|
||||
integer :: count = 0
|
||||
integer :: capacity = 0
|
||||
type(CCL_SPH_Force_Record_Type), allocatable :: records(:)
|
||||
end type CCL_SPH_Force_Accumulator_Type
|
||||
|
||||
type :: CCL_FEM_Load_Accumulator_Type
|
||||
integer :: count = 0
|
||||
integer :: capacity = 0
|
||||
type(CCL_FEM_Load_Record_Type), allocatable :: records(:)
|
||||
end type CCL_FEM_Load_Accumulator_Type
|
||||
|
||||
contains
|
||||
|
||||
subroutine ccl_sph_particle_view_from_record(record, view, ierr)
|
||||
type(CCL_SPH_Particle_Record_Type), intent(in) :: record
|
||||
type(CCL_SPH_Particle_View_Type), intent(out) :: view
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
view = CCL_SPH_Particle_View_Type()
|
||||
if (.not. finite_scalar(record%contact_radius) .or. record%contact_radius < 0.0_c_double) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
if (.not. finite_scalar(record%mass) .or. record%mass < 0.0_c_double) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
if (.not. finite_vector3(record%x) .or. .not. finite_vector3(record%v)) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
|
||||
view%external_id = record%external_id
|
||||
view%internal_index = record%internal_index
|
||||
view%status = record%status
|
||||
view%valid_flags = record%valid_flags
|
||||
view%contact_radius = record%contact_radius
|
||||
view%mass = record%mass
|
||||
view%x = record%x
|
||||
view%v = record%v
|
||||
end subroutine ccl_sph_particle_view_from_record
|
||||
|
||||
subroutine ccl_fem_facet_view_from_record(record, view, ierr)
|
||||
type(CCL_FEM_Facet_Record_Type), intent(in) :: record
|
||||
type(CCL_FEM_Facet_View_Type), intent(out) :: view
|
||||
integer, intent(out) :: ierr
|
||||
integer :: i
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
view = CCL_FEM_Facet_View_Type()
|
||||
if (record%node_count < 3_c_int32_t .or. record%node_count > CCL_VIEW_MAX_FEM_NODES) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
if (.not. finite_scalar(record%area) .or. record%area < 0.0_c_double) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
if (.not. finite_scalar(record%thickness)) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
if (.not. finite_vector3(record%normal)) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
do i = 1, int(record%node_count)
|
||||
if (.not. finite_vector3(record%x(:, i)) .or. .not. finite_vector3(record%v(:, i))) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
end do
|
||||
|
||||
view%facet_id = record%facet_id
|
||||
view%node_count = record%node_count
|
||||
view%node_ids = record%node_ids
|
||||
view%valid_flags = record%valid_flags
|
||||
view%area = record%area
|
||||
view%thickness = record%thickness
|
||||
view%normal = record%normal
|
||||
view%x = record%x
|
||||
view%v = record%v
|
||||
end subroutine ccl_fem_facet_view_from_record
|
||||
|
||||
subroutine ccl_sph_force_accumulator_init(accumulator, capacity)
|
||||
type(CCL_SPH_Force_Accumulator_Type), intent(out) :: accumulator
|
||||
integer, intent(in) :: capacity
|
||||
|
||||
accumulator%count = 0
|
||||
accumulator%capacity = max(0, capacity)
|
||||
allocate(accumulator%records(accumulator%capacity))
|
||||
end subroutine ccl_sph_force_accumulator_init
|
||||
|
||||
subroutine ccl_fem_load_accumulator_init(accumulator, capacity)
|
||||
type(CCL_FEM_Load_Accumulator_Type), intent(out) :: accumulator
|
||||
integer, intent(in) :: capacity
|
||||
|
||||
accumulator%count = 0
|
||||
accumulator%capacity = max(0, capacity)
|
||||
allocate(accumulator%records(accumulator%capacity))
|
||||
end subroutine ccl_fem_load_accumulator_init
|
||||
|
||||
subroutine ccl_sph_force_accumulator_add(accumulator, external_id, internal_index, force, ierr)
|
||||
type(CCL_SPH_Force_Accumulator_Type), intent(inout) :: accumulator
|
||||
integer(c_int64_t), intent(in) :: external_id
|
||||
integer(c_int32_t), intent(in) :: internal_index
|
||||
real(c_double), intent(in) :: force(3)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: slot
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
if (.not. finite_vector3(force)) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
|
||||
slot = find_sph_force_slot(accumulator, external_id, internal_index)
|
||||
if (slot == 0) then
|
||||
if (accumulator%count >= accumulator%capacity) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
accumulator%count = accumulator%count + 1
|
||||
slot = accumulator%count
|
||||
call clear_sph_force_record(accumulator%records(slot))
|
||||
accumulator%records(slot)%external_id = external_id
|
||||
accumulator%records(slot)%internal_index = internal_index
|
||||
accumulator%records(slot)%valid_flags = 1_c_int32_t
|
||||
end if
|
||||
accumulator%records(slot)%force = accumulator%records(slot)%force + force
|
||||
end subroutine ccl_sph_force_accumulator_add
|
||||
|
||||
subroutine ccl_fem_load_accumulator_add_node(accumulator, node_id, force, ierr)
|
||||
type(CCL_FEM_Load_Accumulator_Type), intent(inout) :: accumulator
|
||||
integer(c_int64_t), intent(in) :: node_id
|
||||
real(c_double), intent(in) :: force(3)
|
||||
integer, intent(out) :: ierr
|
||||
integer :: slot
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
if (.not. finite_vector3(force)) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
|
||||
slot = find_fem_load_slot(accumulator, node_id)
|
||||
if (slot == 0) then
|
||||
if (accumulator%count >= accumulator%capacity) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
return
|
||||
end if
|
||||
accumulator%count = accumulator%count + 1
|
||||
slot = accumulator%count
|
||||
call clear_fem_load_record(accumulator%records(slot))
|
||||
accumulator%records(slot)%node_count = 1_c_int32_t
|
||||
accumulator%records(slot)%node_ids(1) = node_id
|
||||
accumulator%records(slot)%valid_flags = 1_c_int32_t
|
||||
end if
|
||||
accumulator%records(slot)%node_forces(:, 1) = accumulator%records(slot)%node_forces(:, 1) + force
|
||||
accumulator%records(slot)%resultant = accumulator%records(slot)%resultant + force
|
||||
end subroutine ccl_fem_load_accumulator_add_node
|
||||
|
||||
subroutine ccl_prepare_sph_force_header(header, step_id, item_count, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(inout) :: header
|
||||
integer(c_int32_t), intent(in) :: step_id
|
||||
integer(c_int32_t), intent(in) :: item_count
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
if (header%block_role /= CCL_ROLE_CCL_TO_SPH_FORCE) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
call prepare_load_header(header, step_id, item_count, ierr)
|
||||
end subroutine ccl_prepare_sph_force_header
|
||||
|
||||
subroutine ccl_prepare_fem_load_header(header, step_id, item_count, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(inout) :: header
|
||||
integer(c_int32_t), intent(in) :: step_id
|
||||
integer(c_int32_t), intent(in) :: item_count
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
if (header%block_role /= CCL_ROLE_CCL_TO_FEM_LOAD) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
call prepare_load_header(header, step_id, item_count, ierr)
|
||||
end subroutine ccl_prepare_fem_load_header
|
||||
|
||||
subroutine prepare_load_header(header, step_id, item_count, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(inout) :: header
|
||||
integer(c_int32_t), intent(in) :: step_id
|
||||
integer(c_int32_t), intent(in) :: item_count
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
call ccl_data_header_validate(header, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
header%step_id = step_id
|
||||
call ccl_data_header_set_state(header, CCL_BUFFER_WRITING, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call ccl_data_header_set_count(header, item_count, ierr)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call ccl_data_header_set_state(header, CCL_BUFFER_READY, ierr)
|
||||
end subroutine prepare_load_header
|
||||
|
||||
integer function find_sph_force_slot(accumulator, external_id, internal_index) result(slot)
|
||||
type(CCL_SPH_Force_Accumulator_Type), intent(in) :: accumulator
|
||||
integer(c_int64_t), intent(in) :: external_id
|
||||
integer(c_int32_t), intent(in) :: internal_index
|
||||
integer :: i
|
||||
|
||||
slot = 0
|
||||
do i = 1, accumulator%count
|
||||
if (accumulator%records(i)%external_id == external_id .and. &
|
||||
accumulator%records(i)%internal_index == internal_index) then
|
||||
slot = i
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function find_sph_force_slot
|
||||
|
||||
integer function find_fem_load_slot(accumulator, node_id) result(slot)
|
||||
type(CCL_FEM_Load_Accumulator_Type), intent(in) :: accumulator
|
||||
integer(c_int64_t), intent(in) :: node_id
|
||||
integer :: i
|
||||
|
||||
slot = 0
|
||||
do i = 1, accumulator%count
|
||||
if (accumulator%records(i)%node_count == 1_c_int32_t .and. &
|
||||
accumulator%records(i)%node_ids(1) == node_id) then
|
||||
slot = i
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end function find_fem_load_slot
|
||||
|
||||
subroutine clear_sph_force_record(record)
|
||||
type(CCL_SPH_Force_Record_Type), intent(out) :: record
|
||||
|
||||
record%external_id = 0_c_int64_t
|
||||
record%internal_index = 0_c_int32_t
|
||||
record%load_mode = 0_c_int32_t
|
||||
record%contact_state = 0_c_int32_t
|
||||
record%coupling_step = 0_c_int32_t
|
||||
record%valid_flags = 0_c_int32_t
|
||||
record%reserved_i4 = 0_c_int32_t
|
||||
record%source_pair_id = 0_c_int64_t
|
||||
record%source_facet_id = 0_c_int64_t
|
||||
record%force = 0.0_c_double
|
||||
record%moment = 0.0_c_double
|
||||
record%normal = 0.0_c_double
|
||||
record%gap = 0.0_c_double
|
||||
record%penetration = 0.0_c_double
|
||||
record%pressure = 0.0_c_double
|
||||
record%target_motion = 0.0_c_double
|
||||
end subroutine clear_sph_force_record
|
||||
|
||||
subroutine clear_fem_load_record(record)
|
||||
type(CCL_FEM_Load_Record_Type), intent(out) :: record
|
||||
|
||||
record%facet_id = 0_c_int64_t
|
||||
record%source_pair_id = 0_c_int64_t
|
||||
record%source_particle_id = 0_c_int64_t
|
||||
record%node_count = 0_c_int32_t
|
||||
record%load_type = 0_c_int32_t
|
||||
record%distribution_mode = 0_c_int32_t
|
||||
record%contact_state = 0_c_int32_t
|
||||
record%valid_flags = 0_c_int32_t
|
||||
record%reserved_i4 = 0_c_int32_t
|
||||
record%node_ids = 0_c_int64_t
|
||||
record%node_forces = 0.0_c_double
|
||||
record%pressure = 0.0_c_double
|
||||
record%traction = 0.0_c_double
|
||||
record%resultant = 0.0_c_double
|
||||
record%normal = 0.0_c_double
|
||||
end subroutine clear_fem_load_record
|
||||
|
||||
logical function finite_scalar(value) result(is_finite)
|
||||
real(c_double), intent(in) :: value
|
||||
|
||||
is_finite = ieee_is_finite(value)
|
||||
end function finite_scalar
|
||||
|
||||
logical function finite_vector3(value) result(is_finite)
|
||||
real(c_double), intent(in) :: value(3)
|
||||
|
||||
is_finite = ieee_is_finite(value(1)) .and. ieee_is_finite(value(2)) .and. ieee_is_finite(value(3))
|
||||
end function finite_vector3
|
||||
|
||||
end module ccl_interface_view
|
||||
Reference in New Issue
Block a user