program test_material_mc_driver use fem_precision use fem_error use fem_database use fem_material_mohr_coulomb use fem_material_mc_driver 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_options() call check_elastic_driver() call check_shear_driver() call check_tension_driver() call check_path_merge() call check_triaxial_path() call check_tension_path() call check_point_eval() call check_limited_status() 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_options() type(mc_driver_options) :: options integer :: ierr_local call mc_driver_options_init(options) call mc_driver_options_valid(options, ierr_local) call require_success(ierr_local, 10) if (options%max_substeps .lt. options%min_substeps) call fail(11) if (options%target_strain .le. ZERO) call fail(12) if (trim(mc_driver_branch_name(MC_BRANCH_ELASTIC)) .ne. 'ELASTIC') & call fail(13) if (trim(mc_driver_branch_name(MC_BRANCH_SHEAR)) .ne. 'SHEAR') & call fail(14) if (trim(mc_driver_branch_name(MC_BRANCH_TENSION)) .ne. 'TENSION') & call fail(15) if (trim(mc_driver_branch_name(MC_BRANCH_MIXED)) .ne. 'MIXED') & call fail(16) if (trim(mc_driver_status_name(MC_DRV_OK)) .ne. 'OK') call fail(17) if (trim(mc_driver_status_name(MC_DRV_LIMITED)) .ne. 'LIMITED') & call fail(18) end subroutine check_options subroutine check_elastic_driver() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: deps(NSTRESS) real(rk) :: stress_old(NSTRESS) real(rk) :: stress_new(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: state_new(NSTATEV_MAX) integer :: ierr_local integer :: substeps integer :: branch integer :: status real(rk) :: max_yield real(rk) :: plastic_total real(rk) :: work_total call mc_driver_options_init(options) options%target_strain = 1.0e-3_rk deps = ZERO deps(1) = -1.0e-4_rk deps(2) = -1.0e-4_rk deps(3) = -1.0e-4_rk stress_old = ZERO state_old = ZERO call mc_driver_update(1, deps, 0.1_rk, state_old, stress_old, options, & stress_new, state_new, diag, ierr_local) call require_success(ierr_local, 30) if (diag%substeps .ne. 1) call fail(31) if (diag%final_branch .ne. MC_BRANCH_ELASTIC) call fail(32) if (diag%branch_count(MC_BRANCH_ELASTIC) .ne. 1) call fail(33) if (state_new(1) .gt. TOL) call fail(34) if (stress_new(1) .ge. ZERO .or. stress_new(2) .ge. ZERO) call fail(35) if (diag%tangent_trace .le. ZERO) call fail(36) call mc_driver_summary(diag, substeps, branch, max_yield, plastic_total, & work_total, status, ierr_local) call require_success(ierr_local, 37) if (substeps .ne. 1 .or. branch .ne. MC_BRANCH_ELASTIC) call fail(38) if (status .ne. MC_DRV_OK) call fail(39) if (plastic_total .gt. TOL) call fail(40) if (work_total .le. ZERO) call fail(41) if (max_yield .gt. TOL) call fail(42) end subroutine check_elastic_driver subroutine check_shear_driver() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: deps(NSTRESS) real(rk) :: stress_old(NSTRESS) real(rk) :: stress_new(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: state_new(NSTATEV_MAX) real(rk) :: yield_norm integer :: branch integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 2.0e-3_rk options%min_substeps = 12 options%max_substeps = 80 deps = ZERO stress_old = ZERO stress_old(1) = -10.0_rk stress_old(2) = -10.0_rk stress_old(3) = -80.0_rk state_old = ZERO call mc_driver_update(1, deps, 1.0_rk, state_old, stress_old, options, & stress_new, state_new, diag, ierr_local) call require_success(ierr_local, 60) if (diag%substeps .lt. 10) call fail(61) if (diag%branch_count(MC_BRANCH_SHEAR) + & diag%branch_count(MC_BRANCH_MIXED) .lt. 1) call fail(62) if (diag%plastic_total .le. ZERO) call fail(63) if (diag%max_plastic_step .le. ZERO) call fail(64) if (stress_new(3) .le. stress_old(3)) call fail(65) call mc_driver_yield_norm(1, stress_new, yield_norm, branch, ierr_local) call require_success(ierr_local, 66) if (yield_norm .gt. max(1.0e-5_rk, 100.0_rk * options%yield_tolerance)) & call fail(67) if (branch .ne. MC_BRANCH_ELASTIC .and. branch .ne. MC_BRANCH_SHEAR) & call fail(68) end subroutine check_shear_driver subroutine check_tension_driver() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: deps(NSTRESS) real(rk) :: stress_old(NSTRESS) real(rk) :: stress_new(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: state_new(NSTATEV_MAX) real(rk) :: principal(3) real(rk) :: vectors(3,3) integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 1.0e-3_rk options%max_substeps = 80 deps = ZERO deps(1) = 0.03_rk stress_old = ZERO state_old = ZERO call mc_driver_update(1, deps, 1.0_rk, state_old, stress_old, options, & stress_new, state_new, diag, ierr_local) call require_success(ierr_local, 80) if (diag%branch_count(MC_BRANCH_TENSION) .lt. 1 .and. & diag%branch_count(MC_BRANCH_MIXED) .lt. 1) call fail(81) if (diag%plastic_total .le. ZERO) call fail(82) call material_mc_principal(stress_new, principal, vectors, ierr_local) call require_success(ierr_local, 83) if (principal(1) - T_TEST .gt. 1.0e-7_rk) call fail(84) if (state_new(1) .le. ZERO) call fail(85) end subroutine check_tension_driver subroutine check_path_merge() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: deps_hist(NSTRESS,4) real(rk) :: dt_hist(4) real(rk) :: stress_old(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: stress_hist(NSTRESS,4) integer :: branch_hist(4) integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 2.0e-3_rk options%max_substeps = 80 deps_hist = ZERO deps_hist(3,1) = -0.01_rk deps_hist(3,2) = -0.01_rk deps_hist(1,3) = 0.015_rk deps_hist(4,4) = 0.02_rk dt_hist = 0.25_rk stress_old = ZERO stress_old(1) = -8.0_rk stress_old(2) = -8.0_rk stress_old(3) = -8.0_rk state_old = ZERO call mc_driver_path(1, 4, deps_hist, dt_hist, state_old, stress_old, & options, stress_hist, branch_hist, diag, ierr_local) call require_success(ierr_local, 100) if (diag%substeps .lt. 10) call fail(101) if (diag%plastic_total .le. ZERO) call fail(102) if (branch_hist(4) .lt. MC_BRANCH_ELASTIC .or. & branch_hist(4) .gt. MC_BRANCH_MIXED) call fail(103) if (maxval(abs(stress_hist(:,4))) .le. ZERO) call fail(104) if (abs(diag%work_total) .le. TOL) call fail(105) end subroutine check_path_merge subroutine check_triaxial_path() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: stress_hist(NSTRESS,6) integer :: branch_hist(6) integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 1.5e-3_rk options%max_substeps = 200 call mc_driver_triaxial(1, -0.20_rk, 5.0_rk, 6, options, stress_hist, & branch_hist, diag, ierr_local) call require_success(ierr_local, 120) if (diag%substeps .lt. 30) call fail(121) if (stress_hist(3,6) .ge. stress_hist(1,6)) call fail(122) if (diag%branch_count(MC_BRANCH_ELASTIC) .lt. 1) call fail(123) if (diag%plastic_total .lt. ZERO) call fail(124) if (branch_hist(6) .lt. MC_BRANCH_ELASTIC .or. & branch_hist(6) .gt. MC_BRANCH_MIXED) call fail(125) end subroutine check_triaxial_path subroutine check_tension_path() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: stress_hist(NSTRESS,5) integer :: branch_hist(5) real(rk) :: principal(3) real(rk) :: vectors(3,3) integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 1.0e-3_rk options%max_substeps = 80 call mc_driver_tension(1, 0.04_rk, 5, options, stress_hist, branch_hist, & diag, ierr_local) call require_success(ierr_local, 140) if (diag%branch_count(MC_BRANCH_TENSION) .lt. 1 .and. & diag%branch_count(MC_BRANCH_MIXED) .lt. 1) call fail(141) call material_mc_principal(stress_hist(:,5), principal, vectors, & ierr_local) call require_success(ierr_local, 142) if (principal(1) - T_TEST .gt. 1.0e-7_rk) call fail(143) if (diag%plastic_total .le. ZERO) call fail(144) if (branch_hist(5) .ne. MC_BRANCH_TENSION .and. & branch_hist(5) .ne. MC_BRANCH_MIXED .and. & branch_hist(5) .ne. MC_BRANCH_ELASTIC) call fail(145) end subroutine check_tension_path subroutine check_point_eval() type(mc_driver_point) :: point real(rk) :: stress(NSTRESS) real(rk) :: state(NSTATEV_MAX) real(rk) :: yield_norm integer :: branch integer :: ierr_local stress = ZERO stress(1) = -5.0_rk stress(2) = -20.0_rk stress(3) = -50.0_rk state = ZERO call mc_driver_point_eval(1, stress, state, point, ierr_local) call require_success(ierr_local, 160) if (point%branch .ne. MC_BRANCH_SHEAR) call fail(161) if (point%shear_f .le. ZERO) call fail(162) if (point%principal(1) .lt. point%principal(2)) call fail(163) call mc_driver_yield_norm(1, stress, yield_norm, branch, ierr_local) call require_success(ierr_local, 164) if (branch .ne. MC_BRANCH_SHEAR) call fail(165) if (yield_norm .le. ZERO) call fail(166) end subroutine check_point_eval subroutine check_limited_status() type(mc_driver_options) :: options type(mc_driver_diag) :: diag real(rk) :: deps(NSTRESS) real(rk) :: stress_old(NSTRESS) real(rk) :: stress_new(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: state_new(NSTATEV_MAX) integer :: ierr_local call mc_driver_options_init(options) options%target_strain = 1.0e-5_rk options%max_substeps = 3 deps = ZERO deps(3) = -0.02_rk stress_old = ZERO state_old = ZERO call mc_driver_update(1, deps, 1.0_rk, state_old, stress_old, options, & stress_new, state_new, diag, ierr_local) call require_success(ierr_local, 180) if (diag%status .ne. MC_DRV_LIMITED) call fail(181) if (diag%requested_steps .le. options%max_substeps) call fail(182) if (diag%limited_steps .ne. 1) call fail(183) if (trim(mc_driver_status_name(diag%status)) .ne. 'LIMITED') call fail(184) end subroutine check_limited_status subroutine check_error_paths() type(mc_driver_options) :: options type(mc_driver_diag) :: diag type(mc_driver_diag) :: left type(mc_driver_diag) :: right type(mc_driver_diag) :: merged real(rk) :: deps(NSTRESS) real(rk) :: stress_old(NSTRESS) real(rk) :: stress_new(NSTRESS) real(rk) :: state_old(NSTATEV_MAX) real(rk) :: state_new(NSTATEV_MAX) real(rk) :: stress_hist(NSTRESS,1) integer :: branch_hist(1) integer :: ierr_local call mc_driver_options_init(options) options%max_substeps = 0 call mc_driver_options_valid(options, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(200) call mc_driver_options_init(options) options%target_strain = -ONE call mc_driver_options_valid(options, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(201) call mc_driver_options_init(options) options%cutback_factor = ONE call mc_driver_options_valid(options, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(202) call mc_driver_options_init(options) deps = ZERO stress_old = ZERO state_old = ZERO call mc_driver_update(2, deps, ZERO, state_old, stress_old, options, & stress_new, state_new, diag, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(203) call mc_driver_triaxial(1, -0.01_rk, -ONE, 1, options, stress_hist, & branch_hist, diag, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(204) call mc_driver_diag_reset(left) call mc_driver_diag_reset(right) left%status = MC_DRV_INVALID call mc_driver_merge_diag(left, right, merged, ierr_local) if (ierr_local .eq. FEM_SUCCESS) call fail(205) end subroutine check_error_paths 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_driver failed:', code stop 1 end subroutine fail end program test_material_mc_driver