diff --git a/CMakeLists.txt b/CMakeLists.txt index e274ebb..92cfea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,24 @@ set_target_properties(test_coupling_region_build_080 PROPERTIES Fortran_MODULE_D add_test(NAME coupling_region_build_080 COMMAND test_coupling_region_build_080) set_tests_properties(coupling_region_build_080 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_input_coupling_load_mode_081 tests/module/test_input_coupling_load_mode_081.f90) +target_link_libraries(test_input_coupling_load_mode_081 PRIVATE sphlite_core) +set_target_properties(test_input_coupling_load_mode_081 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_coupling_load_mode_081 COMMAND test_input_coupling_load_mode_081) +set_tests_properties(input_coupling_load_mode_081 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_input_coupling_load_errors_081 tests/module/test_input_coupling_load_errors_081.f90) +target_link_libraries(test_input_coupling_load_errors_081 PRIVATE sphlite_core) +set_target_properties(test_input_coupling_load_errors_081 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME input_coupling_load_errors_081 COMMAND test_input_coupling_load_errors_081) +set_tests_properties(input_coupling_load_errors_081 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_coupling_contact_state_081 tests/module/test_coupling_contact_state_081.f90) +target_link_libraries(test_coupling_contact_state_081 PRIVATE sphlite_core) +set_target_properties(test_coupling_contact_state_081 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME coupling_contact_state_081 COMMAND test_coupling_contact_state_081) +set_tests_properties(coupling_contact_state_081 PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_coupling_particle_export_080 tests/module/test_coupling_particle_export_080.f90) target_link_libraries(test_coupling_particle_export_080 PRIVATE sphlite_core) set_target_properties(test_coupling_particle_export_080 PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") diff --git a/src/coupling_interface/sph_coupling_interface.f90 b/src/coupling_interface/sph_coupling_interface.f90 index 00bbb4e..b196e27 100644 --- a/src/coupling_interface/sph_coupling_interface.f90 +++ b/src/coupling_interface/sph_coupling_interface.f90 @@ -56,6 +56,11 @@ module sph_coupling_interface real(rk), allocatable :: coupling_motion_position(:,:) integer, allocatable :: coupling_motion_flag(:) integer, allocatable :: coupling_motion_mode(:) + integer, allocatable :: coupling_contact_flag(:) + real(rk), allocatable :: coupling_contact_normal(:,:) + real(rk), allocatable :: coupling_contact_gap(:) + real(rk), allocatable :: coupling_contact_penetration(:) + real(rk), allocatable :: coupling_contact_pressure(:) integer :: coupling_epoch = 0 integer :: coupling_stale_load_count = 0 integer :: coupling_skipped_particle_count = 0 @@ -103,6 +108,11 @@ contains if (allocated(coupling_motion_position)) deallocate(coupling_motion_position) if (allocated(coupling_motion_flag)) deallocate(coupling_motion_flag) if (allocated(coupling_motion_mode)) deallocate(coupling_motion_mode) + if (allocated(coupling_contact_flag)) deallocate(coupling_contact_flag) + if (allocated(coupling_contact_normal)) deallocate(coupling_contact_normal) + if (allocated(coupling_contact_gap)) deallocate(coupling_contact_gap) + if (allocated(coupling_contact_penetration)) deallocate(coupling_contact_penetration) + if (allocated(coupling_contact_pressure)) deallocate(coupling_contact_pressure) coupling_epoch = 0 coupling_stale_load_count = 0 coupling_skipped_particle_count = 0 @@ -141,13 +151,22 @@ contains allocated(coupling_motion_velocity) .and. & allocated(coupling_motion_position) .and. & allocated(coupling_motion_flag) .and. & - allocated(coupling_motion_mode)) return + allocated(coupling_motion_mode) .and. & + allocated(coupling_contact_flag) .and. & + allocated(coupling_contact_normal) .and. & + allocated(coupling_contact_gap) .and. & + allocated(coupling_contact_penetration) .and. & + allocated(coupling_contact_pressure)) return call sph_coupling_release_imports() end if allocate(coupling_external_force(SPH_NDIM,npart), & coupling_motion_velocity(SPH_NDIM,npart), & coupling_motion_position(SPH_NDIM,npart), & - coupling_motion_flag(npart), coupling_motion_mode(npart), stat=stat) + coupling_motion_flag(npart), coupling_motion_mode(npart), & + coupling_contact_flag(npart), & + coupling_contact_normal(SPH_NDIM,npart), & + coupling_contact_gap(npart), coupling_contact_penetration(npart), & + coupling_contact_pressure(npart), stat=stat) if (stat /= 0) then call sph_coupling_release_imports() call sph_error_set(SPH_ERROR_ARGUMENT, 'failed to allocate coupling imports') @@ -179,6 +198,11 @@ contains if (allocated(coupling_motion_position)) coupling_motion_position = 0.0_rk if (allocated(coupling_motion_flag)) coupling_motion_flag = SPH_COUPLING_MOTION_NONE if (allocated(coupling_motion_mode)) coupling_motion_mode = 0 + if (allocated(coupling_contact_flag)) coupling_contact_flag = 0 + if (allocated(coupling_contact_normal)) coupling_contact_normal = 0.0_rk + if (allocated(coupling_contact_gap)) coupling_contact_gap = 0.0_rk + if (allocated(coupling_contact_penetration)) coupling_contact_penetration = 0.0_rk + if (allocated(coupling_contact_pressure)) coupling_contact_pressure = 0.0_rk coupling_imported_force_count = 0 end subroutine sph_coupling_zero_import_buffers diff --git a/src/database/sph_database.f90 b/src/database/sph_database.f90 index 04cac04..4b0a875 100644 --- a/src/database/sph_database.f90 +++ b/src/database/sph_database.f90 @@ -38,6 +38,18 @@ module sph_database integer, parameter :: SPH_COUPLING_IMPORT_FACET_LOAD = 2 integer, parameter :: SPH_COUPLING_IMPORT_MOTION = 3 + integer, parameter :: SPH_COUPLING_LOAD_PARTICLE_FORCE = 1 + integer, parameter :: SPH_COUPLING_LOAD_FACET_FORCE = 2 + integer, parameter :: SPH_COUPLING_LOAD_PRESSURE = 3 + integer, parameter :: SPH_COUPLING_LOAD_TRACTION = 4 + + integer, parameter :: SPH_COUPLING_DISTRIBUTION_UNIFORM = 1 + integer, parameter :: SPH_COUPLING_DISTRIBUTION_AREA = 2 + integer, parameter :: SPH_COUPLING_DISTRIBUTION_MASS = 3 + + integer, parameter :: SPH_COUPLING_CONTACT_STATE_NONE = 0 + integer, parameter :: SPH_COUPLING_CONTACT_STATE_IMPORT = 1 + integer :: npart = 0 integer, allocatable :: particle_id_ext(:) integer, allocatable :: particle_phase(:) @@ -162,6 +174,9 @@ module sph_database integer :: coupling_region_type(SPH_MAX_REGIONS) integer :: coupling_region_export_mode(SPH_MAX_REGIONS) integer :: coupling_region_import_mode(SPH_MAX_REGIONS) + integer :: coupling_region_load_mode(SPH_MAX_REGIONS) + integer :: coupling_region_distribution_mode(SPH_MAX_REGIONS) + integer :: coupling_region_contact_state_mode(SPH_MAX_REGIONS) integer :: coupling_region_enabled(SPH_MAX_REGIONS) integer :: coupling_region_phase_filter(SPH_MAX_REGIONS) integer :: coupling_region_material_filter(SPH_MAX_REGIONS) @@ -318,6 +333,9 @@ contains coupling_region_type = 0 coupling_region_export_mode = 0 coupling_region_import_mode = 0 + coupling_region_load_mode = 0 + coupling_region_distribution_mode = 0 + coupling_region_contact_state_mode = 0 coupling_region_enabled = 0 coupling_region_phase_filter = 0 coupling_region_material_filter = 0 @@ -709,13 +727,17 @@ contains end subroutine sph_db_add_element subroutine sph_db_add_coupling_region(name, set_name, region_type, & - export_mode, import_mode, enabled, surface_name, phase_filter, & + export_mode, import_mode, load_mode, distribution_mode, & + contact_state_mode, enabled, surface_name, phase_filter, & material_filter_name, section_filter_name, ierr) character(len=*), intent(in) :: name character(len=*), intent(in) :: set_name integer, intent(in) :: region_type integer, intent(in) :: export_mode integer, intent(in) :: import_mode + integer, intent(in) :: load_mode + integer, intent(in) :: distribution_mode + integer, intent(in) :: contact_state_mode logical, intent(in) :: enabled character(len=*), intent(in) :: surface_name integer, intent(in) :: phase_filter @@ -772,6 +794,36 @@ contains ierr = SPH_ERROR_DATABASE return end if + if (load_mode /= SPH_COUPLING_LOAD_PARTICLE_FORCE .and. & + load_mode /= SPH_COUPLING_LOAD_FACET_FORCE .and. & + load_mode /= SPH_COUPLING_LOAD_PRESSURE .and. & + load_mode /= SPH_COUPLING_LOAD_TRACTION) then + call sph_error_set(SPH_ERROR_DATABASE, 'invalid coupling load mode') + ierr = SPH_ERROR_DATABASE + return + end if + if (distribution_mode /= SPH_COUPLING_DISTRIBUTION_UNIFORM .and. & + distribution_mode /= SPH_COUPLING_DISTRIBUTION_AREA .and. & + distribution_mode /= SPH_COUPLING_DISTRIBUTION_MASS) then + call sph_error_set(SPH_ERROR_DATABASE, 'invalid coupling distribution mode') + ierr = SPH_ERROR_DATABASE + return + end if + if (contact_state_mode /= SPH_COUPLING_CONTACT_STATE_NONE .and. & + contact_state_mode /= SPH_COUPLING_CONTACT_STATE_IMPORT) then + call sph_error_set(SPH_ERROR_DATABASE, 'invalid coupling contact state mode') + ierr = SPH_ERROR_DATABASE + return + end if + if ((load_mode == SPH_COUPLING_LOAD_PRESSURE .or. & + load_mode == SPH_COUPLING_LOAD_TRACTION .or. & + load_mode == SPH_COUPLING_LOAD_FACET_FORCE) .and. & + export_mode == SPH_COUPLING_EXPORT_PARTICLE .and. enabled) then + call sph_error_set(SPH_ERROR_DATABASE, & + 'facet coupling load requires facet export') + ierr = SPH_ERROR_DATABASE + return + end if if (phase_filter < 0 .or. phase_filter > SPH_PHASE_SHELL_FAILED) then call sph_error_set(SPH_ERROR_DATABASE, 'invalid coupling phase filter') ierr = SPH_ERROR_DATABASE @@ -811,6 +863,9 @@ contains coupling_region_type(coupling_region_count) = region_type coupling_region_export_mode(coupling_region_count) = export_mode coupling_region_import_mode(coupling_region_count) = import_mode + coupling_region_load_mode(coupling_region_count) = load_mode + coupling_region_distribution_mode(coupling_region_count) = distribution_mode + coupling_region_contact_state_mode(coupling_region_count) = contact_state_mode coupling_region_enabled(coupling_region_count) = 0 if (enabled) coupling_region_enabled(coupling_region_count) = 1 coupling_region_phase_filter(coupling_region_count) = phase_filter diff --git a/src/input/sph_input_reader.f90 b/src/input/sph_input_reader.f90 index 5782804..3e99b53 100644 --- a/src/input/sph_input_reader.f90 +++ b/src/input/sph_input_reader.f90 @@ -9,6 +9,11 @@ module sph_input_reader SPH_COUPLING_EXPORT_PARTICLE, SPH_COUPLING_EXPORT_FACET, & SPH_COUPLING_EXPORT_BOTH, SPH_COUPLING_IMPORT_FORCE, & SPH_COUPLING_IMPORT_FACET_LOAD, SPH_COUPLING_IMPORT_MOTION, & + SPH_COUPLING_LOAD_PARTICLE_FORCE, SPH_COUPLING_LOAD_FACET_FORCE, & + SPH_COUPLING_LOAD_PRESSURE, SPH_COUPLING_LOAD_TRACTION, & + SPH_COUPLING_DISTRIBUTION_UNIFORM, SPH_COUPLING_DISTRIBUTION_AREA, & + SPH_COUPLING_DISTRIBUTION_MASS, SPH_COUPLING_CONTACT_STATE_NONE, & + SPH_COUPLING_CONTACT_STATE_IMPORT, & SPH_PHASE_WATER, SPH_PHASE_GAS, SPH_PHASE_EXPLOSIVE, & SPH_PHASE_SOLID, SPH_PHASE_SHELL, SPH_PHASE_BOUNDARY, & SPH_PHASE_COUPLING, SPH_PHASE_SOLID_FAILED, SPH_PHASE_SHELL_FAILED, & @@ -1122,10 +1127,16 @@ contains character(len=SPH_INPUT_FIELD_LEN) :: section_name character(len=SPH_INPUT_FIELD_LEN) :: export_name character(len=SPH_INPUT_FIELD_LEN) :: import_name + character(len=SPH_INPUT_FIELD_LEN) :: load_mode_name + character(len=SPH_INPUT_FIELD_LEN) :: distribution_name + character(len=SPH_INPUT_FIELD_LEN) :: contact_state_name character(len=SPH_INPUT_FIELD_LEN) :: enabled_name integer :: region_type integer :: export_mode integer :: import_mode + integer :: load_mode + integer :: distribution_mode + integer :: contact_state_mode integer :: phase_filter logical :: enabled logical :: has_modern_continuum_option @@ -1177,6 +1188,33 @@ contains if (ierr /= SPH_SUCCESS) return end if + if (import_mode == SPH_COUPLING_IMPORT_FACET_LOAD) then + load_mode = SPH_COUPLING_LOAD_FACET_FORCE + else + load_mode = SPH_COUPLING_LOAD_PARTICLE_FORCE + end if + call sph_input_get_option(line, 'LOAD_MODE', load_mode_name) + if (len_trim(load_mode_name) > 0) then + call sph_input_parse_coupling_load_mode(load_mode_name, load_mode, ierr) + if (ierr /= SPH_SUCCESS) return + end if + + distribution_mode = SPH_COUPLING_DISTRIBUTION_UNIFORM + call sph_input_get_option(line, 'DISTRIBUTION', distribution_name) + if (len_trim(distribution_name) > 0) then + call sph_input_parse_coupling_distribution(distribution_name, & + distribution_mode, ierr) + if (ierr /= SPH_SUCCESS) return + end if + + contact_state_mode = SPH_COUPLING_CONTACT_STATE_NONE + call sph_input_get_option(line, 'CONTACT_STATE', contact_state_name) + if (len_trim(contact_state_name) > 0) then + call sph_input_parse_coupling_contact_state(contact_state_name, & + contact_state_mode, ierr) + if (ierr /= SPH_SUCCESS) return + end if + enabled = .true. call sph_input_get_option(line, 'ENABLED', enabled_name) if (len_trim(enabled_name) > 0) then @@ -1197,6 +1235,9 @@ contains sph_input_option_present(line, 'SECTION') .or. & sph_input_option_present(line, 'EXPORT') .or. & sph_input_option_present(line, 'IMPORT') .or. & + sph_input_option_present(line, 'LOAD_MODE') .or. & + sph_input_option_present(line, 'DISTRIBUTION') .or. & + sph_input_option_present(line, 'CONTACT_STATE') .or. & sph_input_option_present(line, 'ENABLED') if (region_type == SPH_REGION_COUPLING_CONTINUUM) then if (has_modern_continuum_option) then @@ -1207,8 +1248,18 @@ contains enabled = .false. end if + if (enabled .and. (load_mode == SPH_COUPLING_LOAD_PRESSURE .or. & + load_mode == SPH_COUPLING_LOAD_TRACTION .or. & + load_mode == SPH_COUPLING_LOAD_FACET_FORCE) .and. & + export_mode == SPH_COUPLING_EXPORT_PARTICLE) then + call sph_input_set_error('facet coupling load requires facet export') + ierr = SPH_ERROR_INPUT + return + end if + call sph_db_add_coupling_region(name, set_name, region_type, & - export_mode, import_mode, enabled, surface_name, phase_filter, & + export_mode, import_mode, load_mode, distribution_mode, & + contact_state_mode, enabled, surface_name, phase_filter, & material_name, section_name, ierr) end subroutine sph_input_parse_coupling_region @@ -1252,6 +1303,68 @@ contains end if end subroutine sph_input_parse_coupling_import + subroutine sph_input_parse_coupling_load_mode(text, mode, ierr) + character(len=*), intent(in) :: text + integer, intent(out) :: mode + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: upper_text + + ierr = SPH_SUCCESS + upper_text = sph_inp_upper(adjustl(text)) + if (trim(upper_text) == 'PARTICLE_FORCE') then + mode = SPH_COUPLING_LOAD_PARTICLE_FORCE + else if (trim(upper_text) == 'FACET_FORCE') then + mode = SPH_COUPLING_LOAD_FACET_FORCE + else if (trim(upper_text) == 'PRESSURE') then + mode = SPH_COUPLING_LOAD_PRESSURE + else if (trim(upper_text) == 'TRACTION') then + mode = SPH_COUPLING_LOAD_TRACTION + else + call sph_input_set_error('invalid coupling region LOAD_MODE option') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_input_parse_coupling_load_mode + + subroutine sph_input_parse_coupling_distribution(text, mode, ierr) + character(len=*), intent(in) :: text + integer, intent(out) :: mode + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: upper_text + + ierr = SPH_SUCCESS + upper_text = sph_inp_upper(adjustl(text)) + if (trim(upper_text) == 'UNIFORM') then + mode = SPH_COUPLING_DISTRIBUTION_UNIFORM + else if (trim(upper_text) == 'AREA') then + mode = SPH_COUPLING_DISTRIBUTION_AREA + else if (trim(upper_text) == 'MASS') then + mode = SPH_COUPLING_DISTRIBUTION_MASS + else + call sph_input_set_error('invalid coupling region DISTRIBUTION option') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_input_parse_coupling_distribution + + subroutine sph_input_parse_coupling_contact_state(text, mode, ierr) + character(len=*), intent(in) :: text + integer, intent(out) :: mode + integer, intent(out) :: ierr + character(len=SPH_INPUT_FIELD_LEN) :: upper_text + + ierr = SPH_SUCCESS + upper_text = sph_inp_upper(adjustl(text)) + if (trim(upper_text) == 'NONE' .or. trim(upper_text) == 'NO' .or. & + trim(upper_text) == 'OFF') then + mode = SPH_COUPLING_CONTACT_STATE_NONE + else if (trim(upper_text) == 'IMPORT' .or. trim(upper_text) == 'YES' .or. & + trim(upper_text) == 'ON') then + mode = SPH_COUPLING_CONTACT_STATE_IMPORT + else + call sph_input_set_error('invalid coupling region CONTACT_STATE option') + ierr = SPH_ERROR_INPUT + end if + end subroutine sph_input_parse_coupling_contact_state + subroutine sph_input_parse_coupling_phase(text, phase_id, ierr) character(len=*), intent(in) :: text integer, intent(out) :: phase_id diff --git a/tests/data/coupling_load_bad_contact_state_081.inp b/tests/data/coupling_load_bad_contact_state_081.inp new file mode 100644 index 0000000..f18a975 --- /dev/null +++ b/tests/data/coupling_load_bad_contact_state_081.inp @@ -0,0 +1,11 @@ +*NODE +1, 0.0, 0.0, 0.0 +*NSET, NSET=SHELL_SET +1 +*MATERIAL, NAME=SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, NSET=SHELL_SET, MATERIAL=SHELL_STEEL, THICKNESS=0.010 +*SPHLITE COUPLING REGION, NAME=BAD_CONTACT_STATE, SET=SHELL_SET, TYPE=CONTACT, EXPORT=FACET, IMPORT=FACET_LOAD, LOAD_MODE=PRESSURE, CONTACT_STATE=MAYBE diff --git a/tests/data/coupling_load_bad_distribution_081.inp b/tests/data/coupling_load_bad_distribution_081.inp new file mode 100644 index 0000000..72caa4d --- /dev/null +++ b/tests/data/coupling_load_bad_distribution_081.inp @@ -0,0 +1,11 @@ +*NODE +1, 0.0, 0.0, 0.0 +*NSET, NSET=SHELL_SET +1 +*MATERIAL, NAME=SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, NSET=SHELL_SET, MATERIAL=SHELL_STEEL, THICKNESS=0.010 +*SPHLITE COUPLING REGION, NAME=BAD_DISTRIBUTION, SET=SHELL_SET, TYPE=CONTACT, EXPORT=FACET, IMPORT=FACET_LOAD, LOAD_MODE=PRESSURE, DISTRIBUTION=RANDOM diff --git a/tests/data/coupling_load_bad_mode_081.inp b/tests/data/coupling_load_bad_mode_081.inp new file mode 100644 index 0000000..899fb0d --- /dev/null +++ b/tests/data/coupling_load_bad_mode_081.inp @@ -0,0 +1,11 @@ +*NODE +1, 0.0, 0.0, 0.0 +*NSET, NSET=SHELL_SET +1 +*MATERIAL, NAME=SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SHELL SECTION, NSET=SHELL_SET, MATERIAL=SHELL_STEEL, THICKNESS=0.010 +*SPHLITE COUPLING REGION, NAME=BAD_LOAD, SET=SHELL_SET, TYPE=CONTACT, EXPORT=FACET, IMPORT=FACET_LOAD, LOAD_MODE=FLUX diff --git a/tests/data/coupling_load_missing_facet_081.inp b/tests/data/coupling_load_missing_facet_081.inp new file mode 100644 index 0000000..2b357b6 --- /dev/null +++ b/tests/data/coupling_load_missing_facet_081.inp @@ -0,0 +1,11 @@ +*NODE +1, 0.0, 0.0, 0.0 +*NSET, NSET=SOLID_SET +1 +*MATERIAL, NAME=STEEL, TYPE=SOLID +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*SOLID SECTION, NSET=SOLID_SET, MATERIAL=STEEL +*SPHLITE COUPLING REGION, NAME=MISSING_FACET, SET=SOLID_SET, TYPE=CONTACT, EXPORT=PARTICLE, IMPORT=FACET_LOAD, LOAD_MODE=PRESSURE, DISTRIBUTION=UNIFORM, ENABLED=YES diff --git a/tests/data/coupling_load_mode_081.inp b/tests/data/coupling_load_mode_081.inp new file mode 100644 index 0000000..42f24c8 --- /dev/null +++ b/tests/data/coupling_load_mode_081.inp @@ -0,0 +1,32 @@ +*NODE +1, 0.0, 0.0, 0.0 +2, 0.1, 0.0, 0.0 +3, 0.0, 0.1, 0.0 +4, 0.2, 0.0, 0.0 +*ELEMENT, TYPE=SPH3D +1, 1 +2, 2 +3, 3 +4, 4 +*ELSET, ELSET=SHELL_PARTICLES +1, 2, 3 +*ELSET, ELSET=DISABLED_PARTICLE +4 +*MATERIAL, NAME=SHELL_STEEL, TYPE=SHELL +*DENSITY +7850.0 +*ELASTIC +210.0E9, 0.30 +*MATERIAL, NAME=SOLID_STEEL, TYPE=SOLID +*DENSITY +7800.0 +*ELASTIC +200.0E9, 0.30 +*SHELL SECTION, ELSET=SHELL_PARTICLES, MATERIAL=SHELL_STEEL, THICKNESS=0.010, POINTS=3, SHEAR_CORRECTION=0.8333333333 +*SOLID SECTION, ELSET=DISABLED_PARTICLE, MATERIAL=SOLID_STEEL +*SPHLITE SHELL DIRECTOR, SET=SHELL_PARTICLES, NX=0.0, NY=0.0, NZ=1.0 +*SPHLITE PARTICLE CONTROL, H=0.12, MASS=7.85, VOLUME=0.001 +*SPHLITE TIME CONTROL, DT=1.0E-7, TIME=1.0E-7, STEPS=1, SAFETY=0.5 +*SPHLITE COUPLING REGION, NAME=PRESSURE_CONTACT, SET=SHELL_PARTICLES, TYPE=CONTACT, EXPORT=FACET, IMPORT=FACET_LOAD, LOAD_MODE=PRESSURE, DISTRIBUTION=AREA, CONTACT_STATE=IMPORT, ENABLED=YES, PHASE=SHELL, MATERIAL=SHELL_STEEL, SECTION=SHELL_PARTICLES, SURFACE=SHELL_PRESSURE_SURFACE +*SPHLITE COUPLING REGION, NAME=TRACTION_CONTACT, SET=SHELL_PARTICLES, TYPE=CONTACT, EXPORT=BOTH, IMPORT=FACET_LOAD, LOAD_MODE=TRACTION, DISTRIBUTION=MASS, CONTACT_STATE=ON, ENABLED=YES, PHASE=SHELL, MATERIAL=SHELL_STEEL, SECTION=SHELL_PARTICLES, SURFACE=SHELL_TRACTION_SURFACE +*SPHLITE COUPLING REGION, NAME=DISABLED_PRESSURE, SET=DISABLED_PARTICLE, TYPE=CONTACT, EXPORT=PARTICLE, IMPORT=FACET_LOAD, LOAD_MODE=PRESSURE, DISTRIBUTION=UNIFORM, CONTACT_STATE=IMPORT, ENABLED=NO, PHASE=SOLID, MATERIAL=SOLID_STEEL, SECTION=DISABLED_PARTICLE diff --git a/tests/module/test_coupling_contact_state_081.f90 b/tests/module/test_coupling_contact_state_081.f90 new file mode 100644 index 0000000..c0c8b5f --- /dev/null +++ b/tests/module/test_coupling_contact_state_081.f90 @@ -0,0 +1,71 @@ +program test_coupling_contact_state_081 + use sph_precision, only: rk, SPH_NDIM + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + use sph_database, only: npart + use sph_coupling_interface, only: sph_coupling_clear_imports, & + coupling_contact_flag, coupling_contact_normal, coupling_contact_gap, & + coupling_contact_penetration, coupling_contact_pressure + implicit none + + integer :: ierr + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for contact state cache') + call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr) + call assert_ok(ierr, 'read failed for contact state cache') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for contact state cache') + + if (npart /= 4) call fail('contact cache particle count mismatch') + call assert_contact_cache_zero('build initialized contact cache') + + coupling_contact_flag(1) = 1 + coupling_contact_normal(:,1) = (/ 0.0_rk, 0.0_rk, 1.0_rk /) + coupling_contact_gap(1) = 1.0e-4_rk + coupling_contact_penetration(1) = 2.0e-4_rk + coupling_contact_pressure(1) = 3.0_rk + call sph_coupling_clear_imports(ierr) + call assert_ok(ierr, 'clear imports failed for contact cache') + call assert_contact_cache_zero('clear imports did not reset contact cache') + + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for contact state cache') + +contains + + subroutine assert_contact_cache_zero(message) + character(len=*), intent(in) :: message + + if (.not. allocated(coupling_contact_flag)) call fail('contact flag cache not allocated') + if (.not. allocated(coupling_contact_normal)) call fail('contact normal cache not allocated') + if (.not. allocated(coupling_contact_gap)) call fail('contact gap cache not allocated') + if (.not. allocated(coupling_contact_penetration)) call fail('contact penetration cache not allocated') + if (.not. allocated(coupling_contact_pressure)) call fail('contact pressure cache not allocated') + if (size(coupling_contact_flag) /= npart) call fail('contact flag cache size mismatch') + if (size(coupling_contact_normal,1) /= SPH_NDIM .or. & + size(coupling_contact_normal,2) /= npart) then + call fail('contact normal cache size mismatch') + end if + if (maxval(abs(coupling_contact_flag)) /= 0) call fail(message) + if (maxval(abs(coupling_contact_normal)) > 0.0_rk) call fail(message) + if (maxval(abs(coupling_contact_gap)) > 0.0_rk) call fail(message) + if (maxval(abs(coupling_contact_penetration)) > 0.0_rk) call fail(message) + if (maxval(abs(coupling_contact_pressure)) > 0.0_rk) call fail(message) + end subroutine assert_contact_cache_zero + + subroutine assert_ok(ierr_value, message) + integer, intent(in) :: ierr_value + character(len=*), intent(in) :: message + + if (ierr_value /= SPH_SUCCESS) call fail(message) + end subroutine assert_ok + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_coupling_contact_state_081 diff --git a/tests/module/test_input_coupling_load_errors_081.f90 b/tests/module/test_input_coupling_load_errors_081.f90 new file mode 100644 index 0000000..4530b8e --- /dev/null +++ b/tests/module/test_input_coupling_load_errors_081.f90 @@ -0,0 +1,43 @@ +program test_input_coupling_load_errors_081 + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + implicit none + + integer :: ierr + + call expect_fails('tests/data/coupling_load_bad_mode_081.inp') + call expect_fails('tests/data/coupling_load_bad_distribution_081.inp') + call expect_fails('tests/data/coupling_load_bad_contact_state_081.inp') + call expect_fails('tests/data/coupling_load_missing_facet_081.inp') + +contains + + subroutine expect_fails(filename) + character(len=*), intent(in) :: filename + + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for failing 0.8.1 coupling input') + call sph_read_inp(filename, ierr) + if (ierr == SPH_SUCCESS) then + call sph_build_model(ierr) + if (ierr == SPH_SUCCESS) call fail('0.8.1 coupling input unexpectedly built') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after failing 0.8.1 coupling input') + end subroutine expect_fails + + subroutine assert_ok(ierr_value, message) + integer, intent(in) :: ierr_value + character(len=*), intent(in) :: message + + if (ierr_value /= SPH_SUCCESS) call fail(message) + end subroutine assert_ok + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_input_coupling_load_errors_081 diff --git a/tests/module/test_input_coupling_load_mode_081.f90 b/tests/module/test_input_coupling_load_mode_081.f90 new file mode 100644 index 0000000..4b03687 --- /dev/null +++ b/tests/module/test_input_coupling_load_mode_081.f90 @@ -0,0 +1,140 @@ +program test_input_coupling_load_mode_081 + use sph_error, only: SPH_SUCCESS + use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model + use sph_database, only: coupling_region_count, coupling_region_name, & + coupling_region_export_mode, coupling_region_import_mode, & + coupling_region_load_mode, coupling_region_distribution_mode, & + coupling_region_contact_state_mode, coupling_region_enabled, & + coupling_region_particle_count, coupling_region_disabled_count, & + SPH_COUPLING_EXPORT_PARTICLE, SPH_COUPLING_EXPORT_FACET, & + SPH_COUPLING_EXPORT_BOTH, SPH_COUPLING_IMPORT_FORCE, & + SPH_COUPLING_IMPORT_FACET_LOAD, SPH_COUPLING_IMPORT_MOTION, & + SPH_COUPLING_LOAD_PARTICLE_FORCE, SPH_COUPLING_LOAD_FACET_FORCE, & + SPH_COUPLING_LOAD_PRESSURE, SPH_COUPLING_LOAD_TRACTION, & + SPH_COUPLING_DISTRIBUTION_UNIFORM, SPH_COUPLING_DISTRIBUTION_AREA, & + SPH_COUPLING_DISTRIBUTION_MASS, SPH_COUPLING_CONTACT_STATE_NONE, & + SPH_COUPLING_CONTACT_STATE_IMPORT + implicit none + + integer :: ierr + + call check_081_load_modes() + call check_080_defaults() + +contains + + subroutine check_081_load_modes() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for 0.8.1 load modes') + call sph_read_inp('tests/data/coupling_load_mode_081.inp', ierr) + call assert_ok(ierr, 'read failed for 0.8.1 load modes') + + if (coupling_region_count /= 3) call fail('0.8.1 coupling region count mismatch') + call assert_name(1, 'PRESSURE_CONTACT') + call assert_name(2, 'TRACTION_CONTACT') + call assert_name(3, 'DISABLED_PRESSURE') + if (coupling_region_export_mode(1) /= SPH_COUPLING_EXPORT_FACET) then + call fail('pressure export mode mismatch') + end if + if (coupling_region_export_mode(2) /= SPH_COUPLING_EXPORT_BOTH) then + call fail('traction export mode mismatch') + end if + if (coupling_region_export_mode(3) /= SPH_COUPLING_EXPORT_PARTICLE) then + call fail('disabled export mode mismatch') + end if + if (coupling_region_import_mode(1) /= SPH_COUPLING_IMPORT_FACET_LOAD) then + call fail('pressure import mode mismatch') + end if + if (coupling_region_load_mode(1) /= SPH_COUPLING_LOAD_PRESSURE) then + call fail('pressure load mode mismatch') + end if + if (coupling_region_load_mode(2) /= SPH_COUPLING_LOAD_TRACTION) then + call fail('traction load mode mismatch') + end if + if (coupling_region_load_mode(3) /= SPH_COUPLING_LOAD_PRESSURE) then + call fail('disabled load mode was not preserved') + end if + if (coupling_region_distribution_mode(1) /= SPH_COUPLING_DISTRIBUTION_AREA) then + call fail('pressure distribution mismatch') + end if + if (coupling_region_distribution_mode(2) /= SPH_COUPLING_DISTRIBUTION_MASS) then + call fail('traction distribution mismatch') + end if + if (coupling_region_distribution_mode(3) /= SPH_COUPLING_DISTRIBUTION_UNIFORM) then + call fail('disabled distribution mismatch') + end if + if (coupling_region_contact_state_mode(1) /= SPH_COUPLING_CONTACT_STATE_IMPORT) then + call fail('pressure contact state mismatch') + end if + if (coupling_region_contact_state_mode(2) /= SPH_COUPLING_CONTACT_STATE_IMPORT) then + call fail('traction contact state mismatch') + end if + if (coupling_region_enabled(3) /= 0) call fail('disabled flag mismatch') + + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for 0.8.1 load modes') + if (coupling_region_particle_count(1) /= 3) call fail('pressure runtime count mismatch') + if (coupling_region_particle_count(2) /= 3) call fail('traction runtime count mismatch') + if (coupling_region_particle_count(3) /= 0) call fail('disabled region exported particles') + if (coupling_region_disabled_count /= 1) call fail('disabled count mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for 0.8.1 load modes') + end subroutine check_081_load_modes + + subroutine check_080_defaults() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for 0.8.0 defaults') + call sph_read_inp('tests/data/coupling_region_080.inp', ierr) + call assert_ok(ierr, 'read failed for 0.8.0 defaults') + if (coupling_region_import_mode(1) /= SPH_COUPLING_IMPORT_FORCE) then + call fail('0.8.0 force import mode mismatch') + end if + if (coupling_region_load_mode(1) /= SPH_COUPLING_LOAD_PARTICLE_FORCE) then + call fail('0.8.0 force load default mismatch') + end if + if (coupling_region_import_mode(2) /= SPH_COUPLING_IMPORT_FACET_LOAD) then + call fail('0.8.0 facet import mode mismatch') + end if + if (coupling_region_load_mode(2) /= SPH_COUPLING_LOAD_FACET_FORCE) then + call fail('0.8.0 facet load default mismatch') + end if + if (coupling_region_import_mode(3) /= SPH_COUPLING_IMPORT_MOTION) then + call fail('0.8.0 motion import mode mismatch') + end if + if (coupling_region_load_mode(3) /= SPH_COUPLING_LOAD_PARTICLE_FORCE) then + call fail('0.8.0 motion load default mismatch') + end if + if (maxval(coupling_region_distribution_mode(1:3)) /= & + SPH_COUPLING_DISTRIBUTION_UNIFORM) then + call fail('0.8.0 distribution default mismatch') + end if + if (maxval(coupling_region_contact_state_mode(1:3)) /= & + SPH_COUPLING_CONTACT_STATE_NONE) then + call fail('0.8.0 contact state default mismatch') + end if + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed for 0.8.0 defaults') + end subroutine check_080_defaults + + subroutine assert_name(index, expected) + integer, intent(in) :: index + character(len=*), intent(in) :: expected + + if (trim(coupling_region_name(index)) /= trim(expected)) call fail('region name mismatch') + end subroutine assert_name + + subroutine assert_ok(ierr_value, message) + integer, intent(in) :: ierr_value + character(len=*), intent(in) :: message + + if (ierr_value /= SPH_SUCCESS) call fail(message) + end subroutine assert_ok + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_input_coupling_load_mode_081 diff --git a/todo.md b/todo.md index 505ffdd..fedcedf 100644 --- a/todo.md +++ b/todo.md @@ -38,42 +38,42 @@ ## 阶段 B:输入控制、载荷模式和接触状态契约 -- [ ] 定义 `LOAD_MODE=PARTICLE_FORCE` 输入语义。 -- [ ] 定义 `LOAD_MODE=FACET_FORCE` 输入语义。 -- [ ] 定义 `LOAD_MODE=PRESSURE` 输入语义。 -- [ ] 定义 `LOAD_MODE=TRACTION` 输入语义。 -- [ ] 定义 `DISTRIBUTION=UNIFORM` 输入语义。 -- [ ] 定义 `DISTRIBUTION=AREA` 输入语义。 -- [ ] 定义 `DISTRIBUTION=MASS` 输入语义。 -- [ ] 定义 `CONTACT_STATE=IMPORT` 输入语义。 -- [ ] 支持读取 coupling region 的 `LOAD_MODE` 字段。 -- [ ] 支持读取 coupling region 的 `DISTRIBUTION` 字段。 -- [ ] 支持读取 coupling region 的 `CONTACT_STATE` 字段。 -- [ ] 为未显式给出的 `LOAD_MODE` 设置 0.8.0 兼容默认值。 -- [ ] 为未显式给出的 `DISTRIBUTION` 设置兼容默认值。 -- [ ] 对非法 `LOAD_MODE` 报 error。 -- [ ] 对非法 `DISTRIBUTION` 报 error。 -- [ ] 对非法 `CONTACT_STATE` 报 error。 -- [ ] 对 pressure/traction 载荷但无 facet proxy 的 active region 报 error。 -- [ ] 对 disabled region 保留新增输入记录但不参与导入。 -- [ ] 在数据库中保存 load mode。 -- [ ] 在数据库中保存 distribution mode。 -- [ ] 在数据库中保存 contact state mode。 -- [ ] 建立 contact flag 运行时缓存。 -- [ ] 建立 contact normal 运行时缓存。 -- [ ] 建立 gap 运行时缓存。 -- [ ] 建立 penetration 运行时缓存。 -- [ ] 建立 contact pressure 运行时缓存。 -- [ ] 在初始化阶段分配 contact state 缓存。 -- [ ] 在 finalize 阶段释放 contact state 缓存。 -- [ ] 在模型重建阶段清空 contact state 缓存。 -- [ ] 新增 `input_coupling_load_mode_081` 测试。 -- [ ] 新增 `input_coupling_load_errors_081` 测试。 -- [ ] 新增 `coupling_contact_state_081` 基础测试。 -- [ ] 将阶段 B 新测试接入 CTest。 -- [ ] 运行阶段 B 输入和接触状态专项测试。 -- [ ] 运行 `git diff --check`。 -- [ ] 准备阶段 B 本地提交说明。 +- [x] 定义 `LOAD_MODE=PARTICLE_FORCE` 输入语义。 +- [x] 定义 `LOAD_MODE=FACET_FORCE` 输入语义。 +- [x] 定义 `LOAD_MODE=PRESSURE` 输入语义。 +- [x] 定义 `LOAD_MODE=TRACTION` 输入语义。 +- [x] 定义 `DISTRIBUTION=UNIFORM` 输入语义。 +- [x] 定义 `DISTRIBUTION=AREA` 输入语义。 +- [x] 定义 `DISTRIBUTION=MASS` 输入语义。 +- [x] 定义 `CONTACT_STATE=IMPORT` 输入语义。 +- [x] 支持读取 coupling region 的 `LOAD_MODE` 字段。 +- [x] 支持读取 coupling region 的 `DISTRIBUTION` 字段。 +- [x] 支持读取 coupling region 的 `CONTACT_STATE` 字段。 +- [x] 为未显式给出的 `LOAD_MODE` 设置 0.8.0 兼容默认值。 +- [x] 为未显式给出的 `DISTRIBUTION` 设置兼容默认值。 +- [x] 对非法 `LOAD_MODE` 报 error。 +- [x] 对非法 `DISTRIBUTION` 报 error。 +- [x] 对非法 `CONTACT_STATE` 报 error。 +- [x] 对 pressure/traction 载荷但无 facet proxy 的 active region 报 error。 +- [x] 对 disabled region 保留新增输入记录但不参与导入。 +- [x] 在数据库中保存 load mode。 +- [x] 在数据库中保存 distribution mode。 +- [x] 在数据库中保存 contact state mode。 +- [x] 建立 contact flag 运行时缓存。 +- [x] 建立 contact normal 运行时缓存。 +- [x] 建立 gap 运行时缓存。 +- [x] 建立 penetration 运行时缓存。 +- [x] 建立 contact pressure 运行时缓存。 +- [x] 在初始化阶段分配 contact state 缓存。 +- [x] 在 finalize 阶段释放 contact state 缓存。 +- [x] 在模型重建阶段清空 contact state 缓存。 +- [x] 新增 `input_coupling_load_mode_081` 测试。 +- [x] 新增 `input_coupling_load_errors_081` 测试。 +- [x] 新增 `coupling_contact_state_081` 基础测试。 +- [x] 将阶段 B 新测试接入 CTest。 +- [x] 运行阶段 B 输入和接触状态专项测试。 +- [x] 运行 `git diff --check`。 +- [x] 准备阶段 B 本地提交说明。 ## 阶段 C:Facet Pressure、Traction、Resultant 和分配策略