program test_material_mc_envelope use fem_precision use fem_error use fem_database use fem_material_mohr_coulomb use fem_material_mc_envelope implicit none real(rk), parameter :: E_TEST = 1000.0_rk real(rk), parameter :: NU_TEST = 0.25_rk real(rk), parameter :: C_TEST = 10.0_rk real(rk), parameter :: T_TEST = 2.0_rk real(rk), parameter :: TOL = 1.0e-8_rk real(rk) :: phi real(rk) :: psi integer :: ierr phi = 30.0_rk * acos(-ONE) / 180.0_rk psi = 5.0_rk * acos(-ONE) / 180.0_rk call setup_mc(phi, psi, ONE, ierr) call require_success(ierr, 1) call check_strength_formula() call check_table_diag() call check_stress_margins() call check_safety_ratio() call check_point_eval() call check_reduced_material() call check_error_paths() call database_finalize(ierr) call require_success(ierr, 2) contains subroutine setup_mc(phi_in, psi_in, factor, ierr) real(rk), intent(in) :: phi_in real(rk), intent(in) :: psi_in real(rk), intent(in) :: factor integer, intent(out) :: ierr call database_allocate_model(1, 1, 0, 0, 0, 0, 1, 0, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return mat_name(1) = 'SOIL' mat_plastic_model(1) = 'MOHR_COULOMB' mat_density(1) = 1800.0_rk mat_e(1) = E_TEST mat_nu(1) = NU_TEST mat_mc_phi(1) = phi_in mat_mc_cohesion(1) = C_TEST mat_mc_dilation(1) = psi_in mat_mc_tension(1) = T_TEST mat_mc_res_phi(1) = ZERO mat_mc_res_cohesion(1) = ZERO mat_mc_res_dilation(1) = ZERO mat_mc_reduction(1) = factor ierr = FEM_SUCCESS end subroutine setup_mc subroutine check_strength_formula() real(rk) :: compression real(rk) :: extension real(rk) :: tension real(rk) :: nphi real(rk) :: kphi integer :: ierr_local nphi = (ONE + sin(phi)) / (ONE - sin(phi)) kphi = 2.0_rk * C_TEST * sqrt(nphi) call mc_env_strengths(1, 5.0_rk, compression, extension, tension, & ierr_local) call require_success(ierr_local, 10) call check_close(compression, nphi * 5.0_rk + kphi, 11) call check_close(extension, ZERO, 12) call check_close(tension, T_TEST, 13) call mc_env_strengths(1, 60.0_rk, compression, extension, tension, & ierr_local) call require_success(ierr_local, 14) call check_close(compression, nphi * 60.0_rk + kphi, 15) call check_close(extension, (60.0_rk - kphi) / nphi, 16) call check_close(tension, T_TEST, 17) end subroutine check_strength_formula subroutine check_table_diag() type(mc_envelope_diag) :: diag real(rk) :: confining(5) real(rk) :: compression(5) real(rk) :: extension(5) real(rk) :: tension(5) integer :: sample_count integer :: errors real(rk) :: compression_max real(rk) :: extension_max real(rk) :: tension_cap integer :: ierr_local call mc_env_table(1, 5, ZERO, 60.0_rk, confining, compression, extension, & tension, diag, ierr_local) call require_success(ierr_local, 30) call check_close(confining(1), ZERO, 31) call check_close(confining(5), 60.0_rk, 32) if (compression(5) .le. compression(1)) call fail(33) if (extension(5) .lt. extension(1)) call fail(34) call check_close(tension(1), T_TEST, 35) call check_close(tension(5), T_TEST, 36) if (diag%monotonic_errors .ne. 0) call fail(37) call mc_env_diag_values(diag, sample_count, compression_max, & extension_max, tension_cap, errors, ierr_local) call require_success(ierr_local, 38) if (sample_count .ne. 5) call fail(39) call check_close(compression_max, compression(5), 40) call check_close(extension_max, extension(5), 41) call check_close(tension_cap, T_TEST, 42) if (errors .ne. 0) call fail(43) end subroutine check_table_diag subroutine check_stress_margins() real(rk) :: stress(NSTRESS) real(rk) :: shear_margin real(rk) :: tension_margin real(rk) :: nphi real(rk) :: kphi integer :: branch integer :: ierr_local nphi = (ONE + sin(phi)) / (ONE - sin(phi)) kphi = 2.0_rk * C_TEST * sqrt(nphi) stress = ZERO stress(1) = -5.0_rk stress(2) = -20.0_rk stress(3) = -(nphi * 5.0_rk + kphi) call mc_env_stress_margin(1, stress, shear_margin, tension_margin, branch, & ierr_local) call require_success(ierr_local, 60) call check_close(shear_margin, ZERO, 61) if (tension_margin .le. ZERO) call fail(62) if (branch .ne. MC_BRANCH_ELASTIC) call fail(63) stress(3) = stress(3) - 5.0_rk call mc_env_stress_margin(1, stress, shear_margin, tension_margin, branch, & ierr_local) call require_success(ierr_local, 64) if (shear_margin .ge. ZERO) call fail(65) if (branch .ne. MC_BRANCH_SHEAR) call fail(66) stress = ZERO stress(1) = 3.0_rk call mc_env_stress_margin(1, stress, shear_margin, tension_margin, branch, & ierr_local) call require_success(ierr_local, 67) if (tension_margin .ge. ZERO) call fail(68) if (branch .ne. MC_BRANCH_TENSION) call fail(69) end subroutine check_stress_margins subroutine check_safety_ratio() real(rk) :: stress(NSTRESS) real(rk) :: ratio integer :: branch integer :: ierr_local stress = ZERO stress(1) = -5.0_rk stress(2) = -5.0_rk stress(3) = -5.0_rk call mc_env_safety_ratio(1, stress, ratio, branch, ierr_local) call require_success(ierr_local, 80) if (ratio .ge. ONE) call fail(81) if (branch .ne. MC_BRANCH_ELASTIC) call fail(82) stress = ZERO stress(1) = 3.0_rk call mc_env_safety_ratio(1, stress, ratio, branch, ierr_local) call require_success(ierr_local, 83) if (ratio .le. ONE) call fail(84) if (branch .ne. MC_BRANCH_TENSION) call fail(85) stress = ZERO stress(1) = -5.0_rk stress(2) = -20.0_rk stress(3) = -80.0_rk call mc_env_safety_ratio(1, stress, ratio, branch, ierr_local) call require_success(ierr_local, 86) if (ratio .le. ONE) call fail(87) if (branch .ne. MC_BRANCH_SHEAR) call fail(88) end subroutine check_safety_ratio subroutine check_point_eval() type(mc_envelope_point) :: point real(rk) :: stress(NSTRESS) integer :: ierr_local stress = ZERO stress(1) = -5.0_rk stress(2) = -20.0_rk stress(3) = -80.0_rk call mc_env_point_eval(1, stress, point, ierr_local) call require_success(ierr_local, 100) if (point%branch .ne. MC_BRANCH_SHEAR) call fail(101) if (point%compression .le. ZERO) call fail(102) if (point%shear_margin .ge. ZERO) call fail(103) if (point%tension_margin .le. ZERO) call fail(104) end subroutine check_point_eval subroutine check_reduced_material() real(rk) :: compression_full real(rk) :: extension_full real(rk) :: tension_full real(rk) :: compression_red real(rk) :: extension_red real(rk) :: tension_red integer :: ierr_local call mc_env_strengths(1, 20.0_rk, compression_full, extension_full, & tension_full, ierr_local) call require_success(ierr_local, 120) mat_mc_reduction(1) = 2.0_rk call mc_env_strengths(1, 20.0_rk, compression_red, extension_red, & tension_red, ierr_local) call require_success(ierr_local, 121) if (compression_red .ge. compression_full) call fail(122) if (tension_red .ge. tension_full) call fail(123) if (extension_red .lt. ZERO .or. extension_full .lt. ZERO) call fail(124) mat_mc_reduction(1) = ONE end subroutine check_reduced_material subroutine check_error_paths() type(mc_envelope_diag) :: diag real(rk) :: confining(1) real(rk) :: compression(1) real(rk) :: extension(1) real(rk) :: tension(1) integer :: sample_count integer :: errors real(rk) :: compression_max real(rk) :: extension_max real(rk) :: tension_cap integer :: ierr_local call mc_env_strengths(1, -ONE, compression(1), extension(1), tension(1), & ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(140) call mc_env_table(1, 0, ZERO, ONE, confining, compression, extension, & tension, diag, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(141) call mc_env_table(1, 2, ZERO, ONE, confining, compression, extension, & tension, diag, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(142) call mc_env_diag_reset(diag) call mc_env_diag_values(diag, sample_count, compression_max, & extension_max, tension_cap, errors, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(143) end subroutine check_error_paths subroutine check_close(actual, expected, code) real(rk), intent(in) :: actual real(rk), intent(in) :: expected integer, intent(in) :: code if (abs(actual - expected) .gt. TOL * max(ONE, abs(expected))) & call fail(code) end subroutine check_close subroutine require_success(ierr, code) integer, intent(in) :: ierr integer, intent(in) :: code if (ierr .ne. FEM_SUCCESS) call fail(code) end subroutine require_success subroutine fail(code) integer, intent(in) :: code write(*,*) 'test_material_mc_envelope failed:', code stop 1 end subroutine fail end program test_material_mc_envelope