Implement CCLite 0.1.4 data block
This commit is contained in:
@@ -3,8 +3,8 @@ module ccl_version
|
||||
|
||||
integer, parameter :: CCL_VERSION_MAJOR = 0
|
||||
integer, parameter :: CCL_VERSION_MINOR = 1
|
||||
integer, parameter :: CCL_VERSION_PATCH = 3
|
||||
character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.3"
|
||||
integer, parameter :: CCL_VERSION_PATCH = 4
|
||||
character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.4"
|
||||
|
||||
contains
|
||||
|
||||
|
||||
@@ -0,0 +1,407 @@
|
||||
module ccl_data_block
|
||||
use iso_c_binding, only: c_char, c_double, c_int32_t, c_int64_t, c_sizeof
|
||||
use ccl_errors, only: CCL_ERROR_IPC_BAD_HEADER, CCL_SUCCESS
|
||||
implicit none
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_DATA_MAGIC = 1128488004_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_DATA_VERSION_MAJOR = 0_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_DATA_VERSION_MINOR = 1_c_int32_t
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_LAYOUT_AOR_V1 = 1_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_LAYOUT_SOA_V2 = 2_c_int32_t
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_SPH_TO_CCL_PARTICLE = 101_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_SPH_TO_CCL_FACET = 102_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_FEM_TO_CCL_FACET = 201_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_CCL_TO_SPH_FORCE = 301_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_CCL_TO_FEM_LOAD = 302_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_CCL_DIAGNOSTIC = 401_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_CCL_COMMAND_SPH = 901_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_ROLE_CCL_COMMAND_FEM = 902_c_int32_t
|
||||
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_EMPTY = 0_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_WRITING = 1_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_READY = 2_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_READING = 3_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_CONSUMED = 4_c_int32_t
|
||||
integer(c_int32_t), parameter :: CCL_BUFFER_ERROR = 5_c_int32_t
|
||||
|
||||
type, bind(C) :: CCL_Data_Block_Header_Type
|
||||
integer(c_int32_t) :: magic
|
||||
integer(c_int32_t) :: version_major
|
||||
integer(c_int32_t) :: version_minor
|
||||
integer(c_int32_t) :: layout_id
|
||||
integer(c_int32_t) :: block_role
|
||||
integer(c_int32_t) :: producer_id
|
||||
integer(c_int32_t) :: consumer_id
|
||||
integer(c_int32_t) :: step_id
|
||||
integer(c_int32_t) :: buffer_id
|
||||
integer(c_int32_t) :: state
|
||||
integer(c_int32_t) :: item_count
|
||||
integer(c_int32_t) :: item_stride
|
||||
integer(c_int64_t) :: payload_bytes
|
||||
integer(c_int32_t) :: header_bytes
|
||||
integer(c_int32_t) :: max_item_count
|
||||
integer(c_int32_t) :: error_code
|
||||
integer(c_int32_t) :: reserved_i4(16)
|
||||
end type CCL_Data_Block_Header_Type
|
||||
|
||||
type, bind(C) :: CCL_SPH_Particle_Record_Type
|
||||
integer(c_int64_t) :: external_id
|
||||
integer(c_int32_t) :: internal_index
|
||||
integer(c_int32_t) :: phase
|
||||
integer(c_int32_t) :: status
|
||||
integer(c_int32_t) :: material_id
|
||||
integer(c_int32_t) :: section_id
|
||||
integer(c_int32_t) :: valid_flags
|
||||
integer(c_int32_t) :: reserved_i4(2)
|
||||
real(c_double) :: mass
|
||||
real(c_double) :: volume
|
||||
real(c_double) :: density
|
||||
real(c_double) :: pressure
|
||||
real(c_double) :: internal_energy
|
||||
real(c_double) :: temperature
|
||||
real(c_double) :: h
|
||||
real(c_double) :: smoothing_length
|
||||
real(c_double) :: contact_radius
|
||||
real(c_double) :: sound_speed
|
||||
real(c_double) :: x(3)
|
||||
real(c_double) :: v(3)
|
||||
real(c_double) :: a(3)
|
||||
end type CCL_SPH_Particle_Record_Type
|
||||
|
||||
type, bind(C) :: CCL_SPH_Facet_Record_Type
|
||||
integer(c_int64_t) :: facet_id
|
||||
integer(c_int32_t) :: particle_count
|
||||
integer(c_int32_t) :: section_id
|
||||
integer(c_int32_t) :: material_id
|
||||
integer(c_int32_t) :: reserved_i4
|
||||
integer(c_int64_t) :: particle_ids(8)
|
||||
real(c_double) :: area
|
||||
real(c_double) :: normal(3)
|
||||
real(c_double) :: x(3, 8)
|
||||
real(c_double) :: v(3, 8)
|
||||
end type CCL_SPH_Facet_Record_Type
|
||||
|
||||
type, bind(C) :: CCL_FEM_Facet_Record_Type
|
||||
integer(c_int64_t) :: facet_id
|
||||
integer(c_int64_t) :: elem_id
|
||||
integer(c_int32_t) :: face_id
|
||||
integer(c_int32_t) :: node_count
|
||||
integer(c_int32_t) :: element_type
|
||||
integer(c_int32_t) :: surface_type
|
||||
integer(c_int64_t) :: surface_id
|
||||
integer(c_int32_t) :: valid_flags
|
||||
integer(c_int32_t) :: reserved_i4(3)
|
||||
integer(c_int64_t) :: node_ids(8)
|
||||
real(c_double) :: area
|
||||
real(c_double) :: thickness
|
||||
real(c_double) :: shell_thickness
|
||||
real(c_double) :: mass_per_area
|
||||
real(c_double) :: normal(3)
|
||||
real(c_double) :: x(3, 8)
|
||||
real(c_double) :: v(3, 8)
|
||||
end type CCL_FEM_Facet_Record_Type
|
||||
|
||||
type, bind(C) :: CCL_SPH_Force_Record_Type
|
||||
integer(c_int64_t) :: external_id
|
||||
integer(c_int32_t) :: internal_index
|
||||
integer(c_int32_t) :: load_mode
|
||||
integer(c_int32_t) :: contact_state
|
||||
integer(c_int32_t) :: coupling_step
|
||||
integer(c_int32_t) :: valid_flags
|
||||
integer(c_int32_t) :: reserved_i4
|
||||
integer(c_int64_t) :: source_pair_id
|
||||
integer(c_int64_t) :: source_facet_id
|
||||
real(c_double) :: force(3)
|
||||
real(c_double) :: moment(3)
|
||||
real(c_double) :: normal(3)
|
||||
real(c_double) :: gap
|
||||
real(c_double) :: penetration
|
||||
real(c_double) :: pressure
|
||||
real(c_double) :: target_motion(3)
|
||||
end type CCL_SPH_Force_Record_Type
|
||||
|
||||
type, bind(C) :: CCL_FEM_Load_Record_Type
|
||||
integer(c_int64_t) :: facet_id
|
||||
integer(c_int64_t) :: source_pair_id
|
||||
integer(c_int64_t) :: source_particle_id
|
||||
integer(c_int32_t) :: node_count
|
||||
integer(c_int32_t) :: load_type
|
||||
integer(c_int32_t) :: distribution_mode
|
||||
integer(c_int32_t) :: contact_state
|
||||
integer(c_int32_t) :: valid_flags
|
||||
integer(c_int32_t) :: reserved_i4
|
||||
integer(c_int64_t) :: node_ids(8)
|
||||
real(c_double) :: node_forces(3, 8)
|
||||
real(c_double) :: pressure
|
||||
real(c_double) :: traction(3)
|
||||
real(c_double) :: resultant(3)
|
||||
real(c_double) :: normal(3)
|
||||
end type CCL_FEM_Load_Record_Type
|
||||
|
||||
type, bind(C) :: CCL_Diagnostic_Record_Type
|
||||
integer(c_int32_t) :: step_id
|
||||
integer(c_int32_t) :: source_id
|
||||
integer(c_int32_t) :: metric_id
|
||||
integer(c_int32_t) :: reserved_i4
|
||||
integer(c_int64_t) :: count_value
|
||||
real(c_double) :: real_value
|
||||
character(kind=c_char) :: message(128)
|
||||
end type CCL_Diagnostic_Record_Type
|
||||
|
||||
contains
|
||||
|
||||
subroutine ccl_data_header_init(header, block_role, producer_id, consumer_id, max_item_count)
|
||||
type(CCL_Data_Block_Header_Type), intent(out) :: header
|
||||
integer(c_int32_t), intent(in) :: block_role
|
||||
integer(c_int32_t), intent(in) :: producer_id
|
||||
integer(c_int32_t), intent(in) :: consumer_id
|
||||
integer(c_int32_t), intent(in) :: max_item_count
|
||||
|
||||
header%magic = CCL_DATA_MAGIC
|
||||
header%version_major = CCL_DATA_VERSION_MAJOR
|
||||
header%version_minor = CCL_DATA_VERSION_MINOR
|
||||
header%layout_id = CCL_LAYOUT_AOR_V1
|
||||
header%block_role = block_role
|
||||
header%producer_id = producer_id
|
||||
header%consumer_id = consumer_id
|
||||
header%step_id = 0_c_int32_t
|
||||
header%buffer_id = 0_c_int32_t
|
||||
header%state = CCL_BUFFER_EMPTY
|
||||
header%item_count = 0_c_int32_t
|
||||
header%item_stride = ccl_data_record_size_for_role(block_role)
|
||||
header%payload_bytes = 0_c_int64_t
|
||||
header%header_bytes = ccl_data_header_size()
|
||||
header%max_item_count = max(0_c_int32_t, max_item_count)
|
||||
header%error_code = CCL_SUCCESS
|
||||
header%reserved_i4 = 0_c_int32_t
|
||||
end subroutine ccl_data_header_init
|
||||
|
||||
subroutine ccl_data_header_validate(header, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(in) :: header
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
integer(c_int32_t) :: expected_stride
|
||||
integer(c_int64_t) :: expected_payload
|
||||
integer(c_int64_t) :: max_payload
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
if (header%magic /= CCL_DATA_MAGIC) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%version_major /= CCL_DATA_VERSION_MAJOR) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%layout_id /= CCL_LAYOUT_AOR_V1) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (.not. ccl_data_role_is_valid(header%block_role)) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (.not. ccl_data_state_is_valid(header%state)) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%header_bytes /= ccl_data_header_size()) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%item_count < 0_c_int32_t .or. header%max_item_count < 0_c_int32_t) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%item_count > header%max_item_count) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
|
||||
expected_stride = ccl_data_record_size_for_role(header%block_role)
|
||||
if (header%item_stride /= expected_stride) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
|
||||
expected_payload = int(header%item_count, c_int64_t) * int(header%item_stride, c_int64_t)
|
||||
max_payload = int(header%max_item_count, c_int64_t) * int(header%item_stride, c_int64_t)
|
||||
if (header%payload_bytes /= expected_payload) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
if (header%payload_bytes < 0_c_int64_t .or. header%payload_bytes > max_payload) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
end if
|
||||
end subroutine ccl_data_header_validate
|
||||
|
||||
subroutine ccl_data_header_set_count(header, item_count, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(inout) :: header
|
||||
integer(c_int32_t), intent(in) :: item_count
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
if (item_count < 0_c_int32_t .or. item_count > header%max_item_count) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
|
||||
header%item_count = item_count
|
||||
header%payload_bytes = int(item_count, c_int64_t) * int(header%item_stride, c_int64_t)
|
||||
call ccl_data_header_validate(header, ierr)
|
||||
end subroutine ccl_data_header_set_count
|
||||
|
||||
subroutine ccl_data_header_set_state(header, state, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(inout) :: header
|
||||
integer(c_int32_t), intent(in) :: state
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
if (.not. ccl_data_state_is_valid(state)) then
|
||||
ierr = CCL_ERROR_IPC_BAD_HEADER
|
||||
return
|
||||
end if
|
||||
|
||||
header%state = state
|
||||
call ccl_data_header_validate(header, ierr)
|
||||
end subroutine ccl_data_header_set_state
|
||||
|
||||
subroutine ccl_data_header_pack(src, dst, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(in) :: src
|
||||
type(CCL_Data_Block_Header_Type), intent(out) :: dst
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
call ccl_data_header_validate(src, ierr)
|
||||
if (ierr == CCL_SUCCESS) dst = src
|
||||
end subroutine ccl_data_header_pack
|
||||
|
||||
subroutine ccl_data_header_unpack(src, dst, ierr)
|
||||
type(CCL_Data_Block_Header_Type), intent(in) :: src
|
||||
type(CCL_Data_Block_Header_Type), intent(out) :: dst
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
dst = src
|
||||
call ccl_data_header_validate(dst, ierr)
|
||||
end subroutine ccl_data_header_unpack
|
||||
|
||||
logical function ccl_data_role_is_valid(block_role) result(valid)
|
||||
integer(c_int32_t), intent(in) :: block_role
|
||||
|
||||
select case (block_role)
|
||||
case (CCL_ROLE_SPH_TO_CCL_PARTICLE, CCL_ROLE_SPH_TO_CCL_FACET, &
|
||||
CCL_ROLE_FEM_TO_CCL_FACET, CCL_ROLE_CCL_TO_SPH_FORCE, &
|
||||
CCL_ROLE_CCL_TO_FEM_LOAD, CCL_ROLE_CCL_DIAGNOSTIC, &
|
||||
CCL_ROLE_CCL_COMMAND_SPH, CCL_ROLE_CCL_COMMAND_FEM)
|
||||
valid = .true.
|
||||
case default
|
||||
valid = .false.
|
||||
end select
|
||||
end function ccl_data_role_is_valid
|
||||
|
||||
logical function ccl_data_state_is_valid(state) result(valid)
|
||||
integer(c_int32_t), intent(in) :: state
|
||||
|
||||
select case (state)
|
||||
case (CCL_BUFFER_EMPTY, CCL_BUFFER_WRITING, CCL_BUFFER_READY, CCL_BUFFER_READING, &
|
||||
CCL_BUFFER_CONSUMED, CCL_BUFFER_ERROR)
|
||||
valid = .true.
|
||||
case default
|
||||
valid = .false.
|
||||
end select
|
||||
end function ccl_data_state_is_valid
|
||||
|
||||
logical function ccl_data_state_transition_is_valid(from_state, to_state) result(valid)
|
||||
integer(c_int32_t), intent(in) :: from_state
|
||||
integer(c_int32_t), intent(in) :: to_state
|
||||
|
||||
valid = .false.
|
||||
select case (from_state)
|
||||
case (CCL_BUFFER_EMPTY)
|
||||
valid = (to_state == CCL_BUFFER_WRITING .or. to_state == CCL_BUFFER_ERROR)
|
||||
case (CCL_BUFFER_WRITING)
|
||||
valid = (to_state == CCL_BUFFER_READY .or. to_state == CCL_BUFFER_ERROR)
|
||||
case (CCL_BUFFER_READY)
|
||||
valid = (to_state == CCL_BUFFER_READING .or. to_state == CCL_BUFFER_ERROR)
|
||||
case (CCL_BUFFER_READING)
|
||||
valid = (to_state == CCL_BUFFER_CONSUMED .or. to_state == CCL_BUFFER_ERROR)
|
||||
case (CCL_BUFFER_CONSUMED, CCL_BUFFER_ERROR)
|
||||
valid = (to_state == CCL_BUFFER_EMPTY)
|
||||
case default
|
||||
valid = .false.
|
||||
end select
|
||||
end function ccl_data_state_transition_is_valid
|
||||
|
||||
integer(c_int32_t) function ccl_data_record_size_for_role(block_role) result(byte_size)
|
||||
integer(c_int32_t), intent(in) :: block_role
|
||||
|
||||
select case (block_role)
|
||||
case (CCL_ROLE_SPH_TO_CCL_PARTICLE)
|
||||
byte_size = ccl_sph_particle_record_size()
|
||||
case (CCL_ROLE_SPH_TO_CCL_FACET)
|
||||
byte_size = ccl_sph_facet_record_size()
|
||||
case (CCL_ROLE_FEM_TO_CCL_FACET)
|
||||
byte_size = ccl_fem_facet_record_size()
|
||||
case (CCL_ROLE_CCL_TO_SPH_FORCE)
|
||||
byte_size = ccl_sph_force_record_size()
|
||||
case (CCL_ROLE_CCL_TO_FEM_LOAD)
|
||||
byte_size = ccl_fem_load_record_size()
|
||||
case (CCL_ROLE_CCL_DIAGNOSTIC)
|
||||
byte_size = ccl_diagnostic_record_size()
|
||||
case (CCL_ROLE_CCL_COMMAND_SPH, CCL_ROLE_CCL_COMMAND_FEM)
|
||||
byte_size = 0_c_int32_t
|
||||
case default
|
||||
byte_size = -1_c_int32_t
|
||||
end select
|
||||
end function ccl_data_record_size_for_role
|
||||
|
||||
integer(c_int64_t) function ccl_data_payload_capacity_bytes(header) result(byte_size)
|
||||
type(CCL_Data_Block_Header_Type), intent(in) :: header
|
||||
|
||||
byte_size = int(header%max_item_count, c_int64_t) * int(header%item_stride, c_int64_t)
|
||||
end function ccl_data_payload_capacity_bytes
|
||||
|
||||
integer(c_int32_t) function ccl_data_header_size() result(byte_size)
|
||||
type(CCL_Data_Block_Header_Type) :: header
|
||||
|
||||
byte_size = int(c_sizeof(header), c_int32_t)
|
||||
end function ccl_data_header_size
|
||||
|
||||
integer(c_int32_t) function ccl_sph_particle_record_size() result(byte_size)
|
||||
type(CCL_SPH_Particle_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_sph_particle_record_size
|
||||
|
||||
integer(c_int32_t) function ccl_sph_facet_record_size() result(byte_size)
|
||||
type(CCL_SPH_Facet_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_sph_facet_record_size
|
||||
|
||||
integer(c_int32_t) function ccl_fem_facet_record_size() result(byte_size)
|
||||
type(CCL_FEM_Facet_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_fem_facet_record_size
|
||||
|
||||
integer(c_int32_t) function ccl_sph_force_record_size() result(byte_size)
|
||||
type(CCL_SPH_Force_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_sph_force_record_size
|
||||
|
||||
integer(c_int32_t) function ccl_fem_load_record_size() result(byte_size)
|
||||
type(CCL_FEM_Load_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_fem_load_record_size
|
||||
|
||||
integer(c_int32_t) function ccl_diagnostic_record_size() result(byte_size)
|
||||
type(CCL_Diagnostic_Record_Type) :: record
|
||||
|
||||
byte_size = int(c_sizeof(record), c_int32_t)
|
||||
end function ccl_diagnostic_record_size
|
||||
|
||||
end module ccl_data_block
|
||||
Reference in New Issue
Block a user