From a234e33248773533ddccc4886824f2ed096922e5 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 5 Jul 2026 23:45:25 +0800 Subject: [PATCH] Add CCLite 0.2.1 contact input parsing --- CMakeLists.txt | 24 ++ src/case/ccl_case_types.f90 | 35 ++ src/case/ccl_inp_parser.f90 | 318 +++++++++++++++++- tests/data/v020_contact_friction_nonzero.inp | 39 +++ tests/data/v020_contact_invalid_normal.inp | 38 +++ tests/data/v020_contact_missing_kn.inp | 38 +++ .../data/v020_contact_unknown_interaction.inp | 38 +++ tests/data/v020_contact_valid.inp | 39 +++ todo.md | 24 +- 9 files changed, 567 insertions(+), 26 deletions(-) create mode 100644 tests/data/v020_contact_friction_nonzero.inp create mode 100644 tests/data/v020_contact_invalid_normal.inp create mode 100644 tests/data/v020_contact_missing_kn.inp create mode 100644 tests/data/v020_contact_unknown_interaction.inp create mode 100644 tests/data/v020_contact_valid.inp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f2f61c..2772b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,30 @@ add_test(NAME check_invalid_ipc_type ) set_tests_properties(check_invalid_ipc_type PROPERTIES WILL_FAIL TRUE) +add_test(NAME V020_check_valid_contact_case + COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v020_contact_valid.inp +) + +add_test(NAME V020_check_invalid_contact_missing_kn + COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v020_contact_missing_kn.inp +) +set_tests_properties(V020_check_invalid_contact_missing_kn PROPERTIES WILL_FAIL TRUE) + +add_test(NAME V020_check_invalid_contact_normal + COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v020_contact_invalid_normal.inp +) +set_tests_properties(V020_check_invalid_contact_normal PROPERTIES WILL_FAIL TRUE) + +add_test(NAME V020_check_invalid_contact_unknown_interaction + COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v020_contact_unknown_interaction.inp +) +set_tests_properties(V020_check_invalid_contact_unknown_interaction PROPERTIES WILL_FAIL TRUE) + +add_test(NAME V020_check_invalid_contact_friction + COMMAND cclite check ${CMAKE_SOURCE_DIR}/tests/data/v020_contact_friction_nonzero.inp +) +set_tests_properties(V020_check_invalid_contact_friction PROPERTIES WILL_FAIL TRUE) + add_test(NAME ipc_lifecycle COMMAND test_ipc_lifecycle) add_test(NAME command_block_semantics COMMAND test_command_block) add_test(NAME data_block_semantics COMMAND test_data_block) diff --git a/src/case/ccl_case_types.f90 b/src/case/ccl_case_types.f90 index 5da5538..acbb5aa 100644 --- a/src/case/ccl_case_types.f90 +++ b/src/case/ccl_case_types.f90 @@ -5,6 +5,8 @@ module ccl_case_types integer, parameter :: CCL_TEXT_LEN = 256 integer, parameter :: CCL_SOLVER_SPH = 1 integer, parameter :: CCL_SOLVER_FEM = 2 + integer, parameter :: CCL_MAX_SURFACE_INTERACTIONS = 16 + integer, parameter :: CCL_MAX_CONTACT_PAIRS = 16 type :: CCL_Solver_Config logical :: is_set = .false. @@ -43,6 +45,28 @@ module ccl_case_types logical :: log = .true. end type CCL_Output_Config + type :: CCL_Surface_Interaction_Config + logical :: is_set = .false. + integer :: line_no = 0 + character(len=CCL_TEXT_LEN) :: name = "" + character(len=32) :: normal_model = "" + real(8) :: kn = 0.0d0 + real(8) :: cn = 0.0d0 + real(8) :: friction = 0.0d0 + logical :: has_kn = .false. + logical :: has_cn = .false. + logical :: has_friction = .false. + end type CCL_Surface_Interaction_Config + + type :: CCL_Contact_Pair_Config + logical :: is_set = .false. + integer :: line_no = 0 + character(len=CCL_TEXT_LEN) :: name = "" + character(len=CCL_TEXT_LEN) :: interface_name = "" + character(len=CCL_TEXT_LEN) :: interaction_name = "" + character(len=64) :: contact_type = "" + end type CCL_Contact_Pair_Config + type :: CCL_Case_Type logical :: has_control = .false. character(len=CCL_TEXT_LEN) :: name = "" @@ -53,6 +77,10 @@ module ccl_case_types type(CCL_Time_Config) :: time type(CCL_Interface_Config) :: interface type(CCL_Output_Config) :: output + integer :: num_surface_interactions = 0 + integer :: num_contact_pairs = 0 + type(CCL_Surface_Interaction_Config) :: surface_interaction(CCL_MAX_SURFACE_INTERACTIONS) + type(CCL_Contact_Pair_Config) :: contact_pair(CCL_MAX_CONTACT_PAIRS) end type CCL_Case_Type contains @@ -91,6 +119,13 @@ contains call ccl_log_info("case", trim(msg)) call ccl_log_info("case", "interface=" // trim(ccl_case%interface%name)) call ccl_log_info("case", "output=" // trim(ccl_case%output%directory)) + write(msg, '(a,i0)') "surface interactions=", ccl_case%num_surface_interactions + call ccl_log_info("case", trim(msg)) + write(msg, '(a,i0)') "contact pairs=", ccl_case%num_contact_pairs + call ccl_log_info("case", trim(msg)) + if (ccl_case%num_contact_pairs > 0) then + call ccl_log_info("case", "0.2.x contact model=NORMAL:PENALTY, friction disabled") + end if end subroutine ccl_case_print_summary end module ccl_case_types diff --git a/src/case/ccl_inp_parser.f90 b/src/case/ccl_inp_parser.f90 index 50dd1b2..642bb1a 100644 --- a/src/case/ccl_inp_parser.f90 +++ b/src/case/ccl_inp_parser.f90 @@ -1,5 +1,7 @@ module ccl_inp_parser - use ccl_case_types, only: CCL_Case_Type, CCL_SOLVER_FEM, CCL_SOLVER_SPH, ccl_case_init, ccl_solver_slot + use, intrinsic :: ieee_arithmetic, only: ieee_is_finite + use ccl_case_types, only: CCL_Case_Type, CCL_MAX_CONTACT_PAIRS, CCL_MAX_SURFACE_INTERACTIONS, & + CCL_SOLVER_FEM, CCL_SOLVER_SPH, ccl_case_init, ccl_solver_slot use ccl_errors, only: CCL_SUCCESS, CCL_ERROR_INPUT_INVALID_VALUE, & CCL_ERROR_INPUT_MISSING_ARGUMENT, CCL_ERROR_INPUT_PARSE_FAILED use ccl_string_utils, only: ccl_parse_bool, ccl_strip_quotes, ccl_to_upper @@ -17,6 +19,8 @@ contains integer :: ios integer :: line_no integer :: current_solver + integer :: current_interaction + integer :: current_pair character(len=1024) :: line character(len=64) :: section @@ -25,6 +29,8 @@ contains errmsg = "" section = "" current_solver = 0 + current_interaction = 0 + current_pair = 0 line_no = 0 open(newunit=unit_id, file=trim(filename), status="old", action="read", iostat=ios) @@ -38,7 +44,8 @@ contains read(unit_id, '(a)', iostat=ios) line if (ios /= 0) exit line_no = line_no + 1 - call ccl_parse_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg) + call ccl_parse_line(line, line_no, ccl_case, section, current_solver, current_interaction, & + current_pair, ierr, errmsg) if (ierr /= CCL_SUCCESS) exit end do @@ -48,12 +55,15 @@ contains call ccl_validate_case(ccl_case, ierr, errmsg) end subroutine ccl_case_read - subroutine ccl_parse_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg) + subroutine ccl_parse_line(line, line_no, ccl_case, section, current_solver, current_interaction, & + current_pair, ierr, errmsg) character(len=*), intent(in) :: line integer, intent(in) :: line_no type(CCL_Case_Type), intent(inout) :: ccl_case character(len=*), intent(inout) :: section integer, intent(inout) :: current_solver + integer, intent(inout) :: current_interaction + integer, intent(inout) :: current_pair integer, intent(out) :: ierr character(len=*), intent(out) :: errmsg @@ -71,18 +81,23 @@ contains first_nonblank = 1 if (clean_line(first_nonblank:first_nonblank) == "*") then - call parse_keyword_line(clean_line, line_no, ccl_case, section, current_solver, ierr, errmsg) + call parse_keyword_line(clean_line, line_no, ccl_case, section, current_solver, current_interaction, & + current_pair, ierr, errmsg) else - call parse_param_list(clean_line, line_no, section, ccl_case, current_solver, ierr, errmsg) + call parse_param_list(clean_line, line_no, section, ccl_case, current_solver, current_interaction, & + current_pair, ierr, errmsg) end if end subroutine ccl_parse_line - subroutine parse_keyword_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg) + subroutine parse_keyword_line(line, line_no, ccl_case, section, current_solver, current_interaction, & + current_pair, ierr, errmsg) character(len=*), intent(in) :: line integer, intent(in) :: line_no type(CCL_Case_Type), intent(inout) :: ccl_case character(len=*), intent(inout) :: section integer, intent(inout) :: current_solver + integer, intent(inout) :: current_interaction + integer, intent(inout) :: current_pair integer, intent(out) :: ierr character(len=*), intent(out) :: errmsg @@ -103,6 +118,8 @@ contains section = trim(keyword) current_solver = 0 + current_interaction = 0 + current_pair = 0 select case (trim(section)) case ("CCLITE CONTROL") @@ -117,8 +134,12 @@ contains ccl_case%interface%is_set = .true. case ("CCLITE OUTPUT") ccl_case%output%is_set = .true. - case ("CCLITE SURFACE INTERACTION", "CCLITE CONTACT PAIR") - continue + case ("CCLITE SURFACE INTERACTION") + call begin_surface_interaction(ccl_case, line_no, current_interaction, ierr, errmsg) + if (ierr /= CCL_SUCCESS) return + case ("CCLITE CONTACT PAIR") + call begin_contact_pair(ccl_case, line_no, current_pair, ierr, errmsg) + if (ierr /= CCL_SUCCESS) return case default ierr = CCL_ERROR_INPUT_PARSE_FAILED write(errmsg, '(a,i0,a,a)') "line ", line_no, ": unsupported keyword *", trim(section) @@ -126,16 +147,20 @@ contains end select if (len_trim(params) > 0) then - call parse_param_list(params, line_no, section, ccl_case, current_solver, ierr, errmsg) + call parse_param_list(params, line_no, section, ccl_case, current_solver, current_interaction, & + current_pair, ierr, errmsg) end if end subroutine parse_keyword_line - subroutine parse_param_list(text, line_no, section, ccl_case, current_solver, ierr, errmsg) + subroutine parse_param_list(text, line_no, section, ccl_case, current_solver, current_interaction, & + current_pair, ierr, errmsg) character(len=*), intent(in) :: text integer, intent(in) :: line_no character(len=*), intent(in) :: section type(CCL_Case_Type), intent(inout) :: ccl_case integer, intent(inout) :: current_solver + integer, intent(inout) :: current_interaction + integer, intent(inout) :: current_pair integer, intent(out) :: ierr character(len=*), intent(out) :: errmsg @@ -172,18 +197,22 @@ contains key = ccl_to_upper(token(:eq_pos-1)) value = ccl_strip_quotes(adjustl(token(eq_pos+1:))) - call apply_param(section, trim(key), trim(value), line_no, ccl_case, current_solver, ierr, errmsg) + call apply_param(section, trim(key), trim(value), line_no, ccl_case, current_solver, & + current_interaction, current_pair, ierr, errmsg) if (ierr /= CCL_SUCCESS) return end do end subroutine parse_param_list - subroutine apply_param(section, key, value, line_no, ccl_case, current_solver, ierr, errmsg) + subroutine apply_param(section, key, value, line_no, ccl_case, current_solver, current_interaction, & + current_pair, ierr, errmsg) character(len=*), intent(in) :: section character(len=*), intent(in) :: key character(len=*), intent(in) :: value integer, intent(in) :: line_no type(CCL_Case_Type), intent(inout) :: ccl_case integer, intent(inout) :: current_solver + integer, intent(inout) :: current_interaction + integer, intent(inout) :: current_pair integer, intent(out) :: ierr character(len=*), intent(out) :: errmsg @@ -222,8 +251,20 @@ contains call apply_interface_param(key, value, ccl_case, ierr, errmsg) case ("CCLITE OUTPUT") call apply_output_param(key, value, ccl_case, ierr, errmsg) - case ("CCLITE SURFACE INTERACTION", "CCLITE CONTACT PAIR") - continue + case ("CCLITE SURFACE INTERACTION") + if (current_interaction <= 0) then + ierr = CCL_ERROR_INPUT_PARSE_FAILED + errmsg = "SURFACE INTERACTION data must follow *CCLITE SURFACE INTERACTION" + else + call apply_surface_interaction_param(key, value, ccl_case, current_interaction, ierr, errmsg) + end if + case ("CCLITE CONTACT PAIR") + if (current_pair <= 0) then + ierr = CCL_ERROR_INPUT_PARSE_FAILED + errmsg = "CONTACT PAIR data must follow *CCLITE CONTACT PAIR" + else + call apply_contact_pair_param(key, value, ccl_case, current_pair, ierr, errmsg) + end if case default ierr = CCL_ERROR_INPUT_PARSE_FAILED errmsg = "parameters found before a supported CCLite keyword" @@ -234,6 +275,50 @@ contains end if end subroutine apply_param + subroutine begin_surface_interaction(ccl_case, line_no, current_interaction, ierr, errmsg) + type(CCL_Case_Type), intent(inout) :: ccl_case + integer, intent(in) :: line_no + integer, intent(out) :: current_interaction + integer, intent(out) :: ierr + character(len=*), intent(out) :: errmsg + + ierr = CCL_SUCCESS + errmsg = "" + current_interaction = 0 + if (ccl_case%num_surface_interactions >= CCL_MAX_SURFACE_INTERACTIONS) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,i0)') "line ", line_no, ": too many surface interactions, max=", & + CCL_MAX_SURFACE_INTERACTIONS + return + end if + ccl_case%num_surface_interactions = ccl_case%num_surface_interactions + 1 + current_interaction = ccl_case%num_surface_interactions + ccl_case%surface_interaction(current_interaction)%is_set = .true. + ccl_case%surface_interaction(current_interaction)%line_no = line_no + end subroutine begin_surface_interaction + + subroutine begin_contact_pair(ccl_case, line_no, current_pair, ierr, errmsg) + type(CCL_Case_Type), intent(inout) :: ccl_case + integer, intent(in) :: line_no + integer, intent(out) :: current_pair + integer, intent(out) :: ierr + character(len=*), intent(out) :: errmsg + + ierr = CCL_SUCCESS + errmsg = "" + current_pair = 0 + if (ccl_case%num_contact_pairs >= CCL_MAX_CONTACT_PAIRS) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,i0)') "line ", line_no, ": too many contact pairs, max=", & + CCL_MAX_CONTACT_PAIRS + return + end if + ccl_case%num_contact_pairs = ccl_case%num_contact_pairs + 1 + current_pair = ccl_case%num_contact_pairs + ccl_case%contact_pair(current_pair)%is_set = .true. + ccl_case%contact_pair(current_pair)%line_no = line_no + end subroutine begin_contact_pair + subroutine apply_control_param(key, value, ccl_case, ierr, errmsg) character(len=*), intent(in) :: key character(len=*), intent(in) :: value @@ -378,6 +463,73 @@ contains if (ierr /= CCL_SUCCESS) errmsg = "OUTPUT boolean must be YES or NO" end subroutine apply_output_param + subroutine apply_surface_interaction_param(key, value, ccl_case, interaction_id, ierr, errmsg) + character(len=*), intent(in) :: key + character(len=*), intent(in) :: value + type(CCL_Case_Type), intent(inout) :: ccl_case + integer, intent(in) :: interaction_id + integer, intent(out) :: ierr + character(len=*), intent(out) :: errmsg + + ierr = CCL_SUCCESS + errmsg = "" + select case (key) + case ("NAME") + ccl_case%surface_interaction(interaction_id)%name = value + case ("NORMAL") + ccl_case%surface_interaction(interaction_id)%normal_model = ccl_to_upper(value) + case ("KN") + read(value, *, iostat=ierr) ccl_case%surface_interaction(interaction_id)%kn + if (ierr == 0) then + ccl_case%surface_interaction(interaction_id)%has_kn = .true. + else + errmsg = "KN must be numeric" + end if + case ("CN") + read(value, *, iostat=ierr) ccl_case%surface_interaction(interaction_id)%cn + if (ierr == 0) then + ccl_case%surface_interaction(interaction_id)%has_cn = .true. + else + errmsg = "CN must be numeric" + end if + case ("FRICTION") + read(value, *, iostat=ierr) ccl_case%surface_interaction(interaction_id)%friction + if (ierr == 0) then + ccl_case%surface_interaction(interaction_id)%has_friction = .true. + else + errmsg = "FRICTION must be numeric" + end if + case default + ierr = CCL_ERROR_INPUT_INVALID_VALUE + errmsg = "unsupported SURFACE INTERACTION parameter: " // trim(key) + end select + end subroutine apply_surface_interaction_param + + subroutine apply_contact_pair_param(key, value, ccl_case, pair_id, ierr, errmsg) + character(len=*), intent(in) :: key + character(len=*), intent(in) :: value + type(CCL_Case_Type), intent(inout) :: ccl_case + integer, intent(in) :: pair_id + integer, intent(out) :: ierr + character(len=*), intent(out) :: errmsg + + ierr = CCL_SUCCESS + errmsg = "" + select case (key) + case ("NAME") + ccl_case%contact_pair(pair_id)%name = value + case ("INTERFACE") + ccl_case%contact_pair(pair_id)%interface_name = value + case ("INTERACTION") + ccl_case%contact_pair(pair_id)%interaction_name = value + case ("TYPE") + ccl_case%contact_pair(pair_id)%contact_type = ccl_to_upper(value) + case default + ierr = CCL_ERROR_INPUT_INVALID_VALUE + errmsg = "unsupported CONTACT PAIR parameter: " // trim(key) + end select + end subroutine apply_contact_pair_param + subroutine ccl_validate_case(ccl_case, ierr, errmsg) type(CCL_Case_Type), intent(in) :: ccl_case integer, intent(out) :: ierr @@ -453,9 +605,127 @@ contains if (len_trim(ccl_case%output%directory) == 0) then ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT errmsg = "OUTPUT DIRECTORY is required" + return end if + call validate_contact_definitions(ccl_case, ierr, errmsg) end subroutine ccl_validate_case + subroutine validate_contact_definitions(ccl_case, ierr, errmsg) + type(CCL_Case_Type), intent(in) :: ccl_case + integer, intent(out) :: ierr + character(len=*), intent(out) :: errmsg + + integer :: i + integer :: j + integer :: interaction_id + + ierr = CCL_SUCCESS + errmsg = "" + + do i = 1, ccl_case%num_surface_interactions + if (len_trim(ccl_case%surface_interaction(i)%name) == 0) then + ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": SURFACE INTERACTION NAME is required" + return + end if + do j = i + 1, ccl_case%num_surface_interactions + if (same_name(ccl_case%surface_interaction(i)%name, ccl_case%surface_interaction(j)%name)) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,a)') "line ", ccl_case%surface_interaction(j)%line_no, & + ": duplicate SURFACE INTERACTION name: ", trim(ccl_case%surface_interaction(j)%name) + return + end if + end do + if (trim(ccl_case%surface_interaction(i)%normal_model) /= "PENALTY") then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": SURFACE INTERACTION requires NORMAL=PENALTY in 0.2.x" + return + end if + if (.not. ccl_case%surface_interaction(i)%has_kn) then + ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": SURFACE INTERACTION requires KN" + return + end if + if (.not. ieee_is_finite(ccl_case%surface_interaction(i)%kn) .or. & + ccl_case%surface_interaction(i)%kn <= 0.0d0) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": KN must be finite and positive" + return + end if + if (.not. ieee_is_finite(ccl_case%surface_interaction(i)%cn) .or. & + ccl_case%surface_interaction(i)%cn < 0.0d0) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": CN must be finite and non-negative" + return + end if + if (.not. ieee_is_finite(ccl_case%surface_interaction(i)%friction)) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": FRICTION must be finite" + return + end if + if (abs(ccl_case%surface_interaction(i)%friction) > 0.0d0) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%surface_interaction(i)%line_no, & + ": FRICTION is reserved in 0.2.x and must be 0.0" + return + end if + end do + + do i = 1, ccl_case%num_contact_pairs + if (len_trim(ccl_case%contact_pair(i)%name) == 0) then + ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT + write(errmsg, '(a,i0,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": CONTACT PAIR NAME is required" + return + end if + do j = i + 1, ccl_case%num_contact_pairs + if (same_name(ccl_case%contact_pair(i)%name, ccl_case%contact_pair(j)%name)) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,a)') "line ", ccl_case%contact_pair(j)%line_no, & + ": duplicate CONTACT PAIR name: ", trim(ccl_case%contact_pair(j)%name) + return + end if + end do + if (len_trim(ccl_case%contact_pair(i)%interface_name) == 0) then + ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT + write(errmsg, '(a,i0,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": CONTACT PAIR requires INTERFACE" + return + end if + if (.not. same_name(ccl_case%contact_pair(i)%interface_name, ccl_case%interface%name)) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": unknown CONTACT PAIR INTERFACE: ", trim(ccl_case%contact_pair(i)%interface_name) + return + end if + if (len_trim(ccl_case%contact_pair(i)%interaction_name) == 0) then + ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT + write(errmsg, '(a,i0,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": CONTACT PAIR requires INTERACTION" + return + end if + interaction_id = find_surface_interaction(ccl_case, ccl_case%contact_pair(i)%interaction_name) + if (interaction_id == 0) then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": unknown CONTACT PAIR INTERACTION: ", trim(ccl_case%contact_pair(i)%interaction_name) + return + end if + if (trim(ccl_case%contact_pair(i)%contact_type) /= "SPH_PARTICLE_TO_FEM_FACE") then + ierr = CCL_ERROR_INPUT_INVALID_VALUE + write(errmsg, '(a,i0,a)') "line ", ccl_case%contact_pair(i)%line_no, & + ": CONTACT PAIR requires TYPE=SPH_PARTICLE_TO_FEM_FACE in 0.2.x" + return + end if + end do + end subroutine validate_contact_definitions + subroutine validate_solver(ccl_case, slot, label, ierr, errmsg) type(CCL_Case_Type), intent(in) :: ccl_case integer, intent(in) :: slot @@ -486,4 +756,24 @@ contains write(text, '(i0)') value end function int_to_text + integer function find_surface_interaction(ccl_case, name) result(index_value) + type(CCL_Case_Type), intent(in) :: ccl_case + character(len=*), intent(in) :: name + integer :: i + + index_value = 0 + do i = 1, ccl_case%num_surface_interactions + if (same_name(ccl_case%surface_interaction(i)%name, name)) then + index_value = i + return + end if + end do + end function find_surface_interaction + + logical function same_name(left, right) result(is_same) + character(len=*), intent(in) :: left + character(len=*), intent(in) :: right + is_same = trim(ccl_to_upper(left)) == trim(ccl_to_upper(right)) + end function same_name + end module ccl_inp_parser diff --git a/tests/data/v020_contact_friction_nonzero.inp b/tests/data/v020_contact_friction_nonzero.inp new file mode 100644 index 0000000..be6a0d6 --- /dev/null +++ b/tests/data/v020_contact_friction_nonzero.inp @@ -0,0 +1,39 @@ +** Invalid CCLite 0.2.x contact case: friction is reserved. +*CCLITE CONTROL, NAME=V020_CONTACT_FRICTION_NONZERO, MODE=CHECK +VERSION=0.2 + +*CCLITE SOLVER, ID=SPH, KIND=SPHLITE +EXECUTABLE=mock_sph_worker.exe +INPUT=mock_sph_contact.inp + +*CCLITE SOLVER, ID=FEM, KIND=FEMLITE +EXECUTABLE=mock_fem_worker.exe +INPUT=mock_fem_wall.inp + +*CCLITE IPC, TYPE=WINDOWS_SHMEM +NAME_PREFIX=CCLITE_V020 +BUFFER=DOUBLE +TIMEOUT_MS=5000 + +*CCLITE TIME +START=0.0 +END=1.0e-6 +DT=1.0e-6 + +*CCLITE INTERFACE, NAME=WALL_CONTACT +SPH_REGION=SPH_CONTACT_REGION +FEM_SURFACE=FEM_WALL + +*CCLITE SURFACE INTERACTION, NAME=PENALTY_1 +NORMAL=PENALTY, KN=1.0e6, CN=0.0 +FRICTION=0.1 + +*CCLITE CONTACT PAIR, NAME=PAIR_1 +INTERFACE=WALL_CONTACT +INTERACTION=PENALTY_1 +TYPE=SPH_PARTICLE_TO_FEM_FACE + +*CCLITE OUTPUT +DIRECTORY=output/v020_contact_friction_nonzero +CSV=YES +LOG=YES diff --git a/tests/data/v020_contact_invalid_normal.inp b/tests/data/v020_contact_invalid_normal.inp new file mode 100644 index 0000000..bf384ad --- /dev/null +++ b/tests/data/v020_contact_invalid_normal.inp @@ -0,0 +1,38 @@ +** Invalid CCLite 0.2.x contact case: unsupported normal model. +*CCLITE CONTROL, NAME=V020_CONTACT_INVALID_NORMAL, MODE=CHECK +VERSION=0.2 + +*CCLITE SOLVER, ID=SPH, KIND=SPHLITE +EXECUTABLE=mock_sph_worker.exe +INPUT=mock_sph_contact.inp + +*CCLITE SOLVER, ID=FEM, KIND=FEMLITE +EXECUTABLE=mock_fem_worker.exe +INPUT=mock_fem_wall.inp + +*CCLITE IPC, TYPE=WINDOWS_SHMEM +NAME_PREFIX=CCLITE_V020 +BUFFER=DOUBLE +TIMEOUT_MS=5000 + +*CCLITE TIME +START=0.0 +END=1.0e-6 +DT=1.0e-6 + +*CCLITE INTERFACE, NAME=WALL_CONTACT +SPH_REGION=SPH_CONTACT_REGION +FEM_SURFACE=FEM_WALL + +*CCLITE SURFACE INTERACTION, NAME=PENALTY_1 +NORMAL=LINEAR, KN=1.0e6, CN=0.0 + +*CCLITE CONTACT PAIR, NAME=PAIR_1 +INTERFACE=WALL_CONTACT +INTERACTION=PENALTY_1 +TYPE=SPH_PARTICLE_TO_FEM_FACE + +*CCLITE OUTPUT +DIRECTORY=output/v020_contact_invalid_normal +CSV=YES +LOG=YES diff --git a/tests/data/v020_contact_missing_kn.inp b/tests/data/v020_contact_missing_kn.inp new file mode 100644 index 0000000..143c378 --- /dev/null +++ b/tests/data/v020_contact_missing_kn.inp @@ -0,0 +1,38 @@ +** Invalid CCLite 0.2.x contact case: missing KN. +*CCLITE CONTROL, NAME=V020_CONTACT_MISSING_KN, MODE=CHECK +VERSION=0.2 + +*CCLITE SOLVER, ID=SPH, KIND=SPHLITE +EXECUTABLE=mock_sph_worker.exe +INPUT=mock_sph_contact.inp + +*CCLITE SOLVER, ID=FEM, KIND=FEMLITE +EXECUTABLE=mock_fem_worker.exe +INPUT=mock_fem_wall.inp + +*CCLITE IPC, TYPE=WINDOWS_SHMEM +NAME_PREFIX=CCLITE_V020 +BUFFER=DOUBLE +TIMEOUT_MS=5000 + +*CCLITE TIME +START=0.0 +END=1.0e-6 +DT=1.0e-6 + +*CCLITE INTERFACE, NAME=WALL_CONTACT +SPH_REGION=SPH_CONTACT_REGION +FEM_SURFACE=FEM_WALL + +*CCLITE SURFACE INTERACTION, NAME=PENALTY_1 +NORMAL=PENALTY, CN=0.0 + +*CCLITE CONTACT PAIR, NAME=PAIR_1 +INTERFACE=WALL_CONTACT +INTERACTION=PENALTY_1 +TYPE=SPH_PARTICLE_TO_FEM_FACE + +*CCLITE OUTPUT +DIRECTORY=output/v020_contact_missing_kn +CSV=YES +LOG=YES diff --git a/tests/data/v020_contact_unknown_interaction.inp b/tests/data/v020_contact_unknown_interaction.inp new file mode 100644 index 0000000..589c62b --- /dev/null +++ b/tests/data/v020_contact_unknown_interaction.inp @@ -0,0 +1,38 @@ +** Invalid CCLite 0.2.x contact case: unknown interaction reference. +*CCLITE CONTROL, NAME=V020_CONTACT_UNKNOWN_INTERACTION, MODE=CHECK +VERSION=0.2 + +*CCLITE SOLVER, ID=SPH, KIND=SPHLITE +EXECUTABLE=mock_sph_worker.exe +INPUT=mock_sph_contact.inp + +*CCLITE SOLVER, ID=FEM, KIND=FEMLITE +EXECUTABLE=mock_fem_worker.exe +INPUT=mock_fem_wall.inp + +*CCLITE IPC, TYPE=WINDOWS_SHMEM +NAME_PREFIX=CCLITE_V020 +BUFFER=DOUBLE +TIMEOUT_MS=5000 + +*CCLITE TIME +START=0.0 +END=1.0e-6 +DT=1.0e-6 + +*CCLITE INTERFACE, NAME=WALL_CONTACT +SPH_REGION=SPH_CONTACT_REGION +FEM_SURFACE=FEM_WALL + +*CCLITE SURFACE INTERACTION, NAME=PENALTY_1 +NORMAL=PENALTY, KN=1.0e6, CN=0.0 + +*CCLITE CONTACT PAIR, NAME=PAIR_1 +INTERFACE=WALL_CONTACT +INTERACTION=UNKNOWN_PENALTY +TYPE=SPH_PARTICLE_TO_FEM_FACE + +*CCLITE OUTPUT +DIRECTORY=output/v020_contact_unknown_interaction +CSV=YES +LOG=YES diff --git a/tests/data/v020_contact_valid.inp b/tests/data/v020_contact_valid.inp new file mode 100644 index 0000000..963c1f5 --- /dev/null +++ b/tests/data/v020_contact_valid.inp @@ -0,0 +1,39 @@ +** Valid CCLite 0.2.x contact check case. +*CCLITE CONTROL, NAME=V020_CONTACT_VALID, MODE=CHECK +VERSION=0.2 + +*CCLITE SOLVER, ID=SPH, KIND=SPHLITE +EXECUTABLE=mock_sph_worker.exe +INPUT=mock_sph_contact.inp + +*CCLITE SOLVER, ID=FEM, KIND=FEMLITE +EXECUTABLE=mock_fem_worker.exe +INPUT=mock_fem_wall.inp + +*CCLITE IPC, TYPE=WINDOWS_SHMEM +NAME_PREFIX=CCLITE_V020 +BUFFER=DOUBLE +TIMEOUT_MS=5000 + +*CCLITE TIME +START=0.0 +END=1.0e-6 +DT=1.0e-6 + +*CCLITE INTERFACE, NAME=WALL_CONTACT +SPH_REGION=SPH_CONTACT_REGION +FEM_SURFACE=FEM_WALL + +*CCLITE SURFACE INTERACTION, NAME=PENALTY_1 +NORMAL=PENALTY, KN=1.0e6, CN=0.0 +FRICTION=0.0 + +*CCLITE CONTACT PAIR, NAME=PAIR_1 +INTERFACE=WALL_CONTACT +INTERACTION=PENALTY_1 +TYPE=SPH_PARTICLE_TO_FEM_FACE + +*CCLITE OUTPUT +DIRECTORY=output/v020_contact_valid +CSV=YES +LOG=YES diff --git a/todo.md b/todo.md index f083c0c..19663fd 100644 --- a/todo.md +++ b/todo.md @@ -73,40 +73,40 @@ 目标:支持 0.2.x 基础接触输入关键词,并把 interaction 与 contact pair 保存到内部模型。 -- [ ] T0201-01 扩展 case model 保存 surface interaction。 +- [x] T0201-01 扩展 case model 保存 surface interaction。 完成判据:内部结构可保存 `name`、`normal_model`、`kn`、`cn` 和 `friction`。 -- [ ] T0201-02 扩展 case model 保存 contact pair。 +- [x] T0201-02 扩展 case model 保存 contact pair。 完成判据:内部结构可保存 `name`、`interface`、`interaction` 和 `type`。 -- [ ] T0201-03 解析 `*CCLITE SURFACE INTERACTION` 关键词行。 +- [x] T0201-03 解析 `*CCLITE SURFACE INTERACTION` 关键词行。 完成判据:可读取 `NAME=...`,缺少名称时给出带行号错误。 -- [ ] T0201-04 解析 surface interaction 数据行。 +- [x] T0201-04 解析 surface interaction 数据行。 完成判据:可读取 `NORMAL=PENALTY`、`KN=...`、`CN=...` 和 `FRICTION=...`。 -- [ ] T0201-05 解析 `*CCLITE CONTACT PAIR` 关键词行。 +- [x] T0201-05 解析 `*CCLITE CONTACT PAIR` 关键词行。 完成判据:可读取 `NAME=...`,重复名称能报错。 -- [ ] T0201-06 解析 contact pair 数据行。 +- [x] T0201-06 解析 contact pair 数据行。 完成判据:可读取 `INTERFACE=...`、`INTERACTION=...` 和 `TYPE=SPH_PARTICLE_TO_FEM_FACE`。 -- [ ] T0201-07 校验 interaction 参数合法性。 +- [x] T0201-07 校验 interaction 参数合法性。 完成判据:缺少 `KN`、非法 `NORMAL`、负刚度或非有限数值均返回输入错误。 -- [ ] T0201-08 校验 contact pair 引用合法性。 +- [x] T0201-08 校验 contact pair 引用合法性。 完成判据:未知 interface、未知 interaction 和非法 type 均返回输入错误。 -- [ ] T0201-09 处理 0.2.x 未启用摩擦字段。 +- [x] T0201-09 处理 0.2.x 未启用摩擦字段。 完成判据:`FRICTION` 非 0 时给出错误或 warning,并且不启用摩擦计算。 -- [ ] T0201-10 增加 contact 输入检查摘要。 +- [x] T0201-10 增加 contact 输入检查摘要。 完成判据:`cclite check` 输出 interaction 数量、pair 数量和未启用能力提示。 -- [ ] T0201-11 增加合法 contact `.inp` 样例。 +- [x] T0201-11 增加合法 contact `.inp` 样例。 完成判据:样例可通过 `cclite check`,并包含 surface interaction 与 contact pair。 -- [ ] T0201-12 增加 contact parser 单元测试。 +- [x] T0201-12 增加 contact parser 单元测试。 完成判据:覆盖合法输入、缺少 `KN`、非法 `NORMAL`、未知引用和摩擦未启用路径。 # 4. 0.2.2 接口 View 与 Load Buffer