diff --git a/src/element/fem_element_internal.f90 b/src/element/fem_element_internal.f90 index c8e837f..2481996 100644 --- a/src/element/fem_element_internal.f90 +++ b/src/element/fem_element_internal.f90 @@ -49,6 +49,9 @@ contains case ('S4') call shell4_internal_force(elem, ierr) if (ierr .ne. FEM_SUCCESS) return + case ('S6') + call shell6_internal_force(elem, ierr) + if (ierr .ne. FEM_SUCCESS) return case default cycle end select @@ -521,6 +524,147 @@ contains ierr = FEM_SUCCESS end subroutine shell3_internal_force + subroutine shell6_internal_force(elem, ierr) + integer, intent(in) :: elem + integer, intent(out) :: ierr + integer, parameter :: MAX_QP = 16 + real(rk) :: basis(NDIM,NDIM) + real(rk) :: xloc(2,MAX_NEN) + real(rk) :: qloc(5,MAX_NEN) + real(rk) :: floc(5,MAX_NEN) + real(rk) :: gp_nat(NDIM,MAX_QP) + real(rk) :: gp_weight(MAX_QP) + real(rk) :: nshape(MAX_NEN) + real(rk) :: dndx(MAX_NEN) + real(rk) :: dndy(MAX_NEN) + real(rk) :: strain_mem(3) + real(rk) :: strain_ben(3) + real(rk) :: strain_shr(2) + real(rk) :: force_mem(3) + real(rk) :: force_ben(3) + real(rk) :: force_shr(2) + real(rk) :: young + real(rk) :: poisson + real(rk) :: thickness + real(rk) :: shear_mod + real(rk) :: coeff_mem + real(rk) :: coeff_ben + real(rk) :: coeff_shr + real(rk) :: detj + real(rk) :: weight + integer :: q + integer :: npoint + integer :: local_node + integer :: gp + integer :: gp_start + integer :: mat + integer :: sec + + if (elem_nnode(elem) .ne. 6) then + call error_set(FEM_ERR_MESH, 'S6 element must have 6 nodes', ierr) + return + end if + + mat = elem_mat(elem) + sec = elem_sec(elem) + if (mat .lt. 1 .or. mat .gt. n_material) then + call error_set(FEM_ERR_MATERIAL, 'S6 element has invalid material index', ierr) + return + end if + if (sec .lt. 1 .or. sec .gt. n_section) then + call error_set(FEM_ERR_INPUT, 'S6 element has invalid section index', ierr) + return + end if + + young = mat_e(mat) + poisson = mat_nu(mat) + thickness = section_thickness(sec) + if (young .le. ZERO) then + call error_set(FEM_ERR_MATERIAL, 'S6 elastic modulus must be positive', ierr) + return + end if + if (poisson .le. -ONE .or. poisson .ge. HALF) then + call error_set(FEM_ERR_MATERIAL, 'S6 Poisson ratio must be in (-1,0.5)', ierr) + return + end if + if (thickness .le. ZERO) then + call error_set(FEM_ERR_INPUT, 'S6 section thickness must be positive', ierr) + return + end if + + call shell_triangle_basis(elem, 6, basis, xloc, ierr) + if (ierr .ne. FEM_SUCCESS) return + call shell_general_local_dofs(elem, 6, basis, qloc) + + shear_mod = young / (2.0_rk * (ONE + poisson)) + coeff_mem = young * thickness / (ONE - poisson * poisson) + coeff_ben = young * thickness**3 / & + (12.0_rk * (ONE - poisson * poisson)) + coeff_shr = (5.0_rk / 6.0_rk) * shear_mod * thickness + + call quadrature_get_rule('S6', MAX_QP, npoint, gp_nat, gp_weight, ierr) + if (ierr .ne. FEM_SUCCESS) return + gp_start = elem_gp_start(elem) + gp = gp_start + floc = ZERO + + do q = 1, npoint + call shell_general_shape_xy('S6', 6, xloc, gp_nat(:,q), & + nshape, dndx, dndy, detj, ierr) + if (ierr .ne. FEM_SUCCESS) return + weight = gp_weight(q) * detj + + call shell_general_strains(6, nshape, dndx, dndy, qloc, strain_mem, & + strain_ben, strain_shr) + call shell4_resultants(coeff_mem, coeff_ben, coeff_shr, poisson, & + strain_mem, strain_ben, strain_shr, & + force_mem, force_ben, force_shr) + + do local_node = 1, 6 + floc(1,local_node) = floc(1,local_node) + weight * & + (dndx(local_node) * force_mem(1) + & + dndy(local_node) * force_mem(3)) + floc(2,local_node) = floc(2,local_node) + weight * & + (dndy(local_node) * force_mem(2) + & + dndx(local_node) * force_mem(3)) + floc(3,local_node) = floc(3,local_node) + weight * & + (dndx(local_node) * force_shr(1) + & + dndy(local_node) * force_shr(2)) + floc(4,local_node) = floc(4,local_node) + weight * & + (-dndy(local_node) * force_ben(2) - & + dndx(local_node) * force_ben(3) - & + nshape(local_node) * force_shr(2)) + floc(5,local_node) = floc(5,local_node) + weight * & + (dndx(local_node) * force_ben(1) + & + dndy(local_node) * force_ben(3) + & + nshape(local_node) * force_shr(1)) + end do + + if (gp .gt. 0) then + strain(:,gp) = ZERO + stress(:,gp) = ZERO + statev(:,gp) = ZERO + strain(1,gp) = strain_mem(1) + strain(2,gp) = strain_mem(2) + strain(4,gp) = strain_mem(3) + strain(5,gp) = strain_shr(1) + strain(6,gp) = strain_shr(2) + stress(1,gp) = force_mem(1) / thickness + stress(2,gp) = force_mem(2) / thickness + stress(4,gp) = force_mem(3) / thickness + stress(5,gp) = force_shr(1) / thickness + stress(6,gp) = force_shr(2) / thickness + statev(10,gp) = strain_ben(1) + statev(11,gp) = strain_ben(2) + statev(12,gp) = strain_ben(3) + end if + gp = gp + 1 + end do + + call shell_general_add_global(elem, 6, basis, floc) + ierr = FEM_SUCCESS + end subroutine shell6_internal_force + subroutine shell4_internal_force(elem, ierr) integer, intent(in) :: elem integer, intent(out) :: ierr @@ -852,6 +996,203 @@ contains end do end subroutine shell3_add_global + subroutine shell_triangle_basis(elem, nlocal, basis, xloc, ierr) + integer, intent(in) :: elem + integer, intent(in) :: nlocal + real(rk), intent(out) :: basis(NDIM,NDIM) + real(rk), intent(out) :: xloc(2,MAX_NEN) + integer, intent(out) :: ierr + real(rk) :: origin(NDIM) + real(rk) :: x1(NDIM) + real(rk) :: x2(NDIM) + real(rk) :: x3(NDIM) + real(rk) :: v12(NDIM) + real(rk) :: v13(NDIM) + real(rk) :: normal(NDIM) + real(rk) :: tmp(NDIM) + real(rk) :: len1 + real(rk) :: lenn + integer :: local_node + integer :: node + + x1 = coord0(:, elem_conn(1,elem)) + x2 = coord0(:, elem_conn(2,elem)) + x3 = coord0(:, elem_conn(3,elem)) + origin = x1 + v12 = x2 - x1 + v13 = x3 - x1 + + len1 = sqrt(sum(v12 * v12)) + if (len1 .le. ZERO) then + call error_set(FEM_ERR_MESH, 'triangular shell has coincident first edge nodes', ierr) + return + end if + basis(:,1) = v12 / len1 + + call cross3(v12, v13, normal) + lenn = sqrt(sum(normal * normal)) + if (lenn .le. ZERO) then + call error_set(FEM_ERR_MESH, 'triangular shell local basis is singular', ierr) + return + end if + basis(:,3) = normal / lenn + call cross3(basis(:,3), basis(:,1), basis(:,2)) + + xloc = ZERO + do local_node = 1, nlocal + node = elem_conn(local_node, elem) + tmp = coord0(:,node) - origin + xloc(1,local_node) = dot_product(tmp, basis(:,1)) + xloc(2,local_node) = dot_product(tmp, basis(:,2)) + end do + + ierr = FEM_SUCCESS + end subroutine shell_triangle_basis + + subroutine shell_general_local_dofs(elem, nlocal, basis, qloc) + integer, intent(in) :: elem + integer, intent(in) :: nlocal + real(rk), intent(in) :: basis(NDIM,NDIM) + real(rk), intent(out) :: qloc(5,MAX_NEN) + real(rk) :: disp(NDIM) + real(rk) :: rot(NDIM) + integer :: local_node + integer :: node + integer :: idir + integer :: dof + + qloc = ZERO + do local_node = 1, nlocal + node = elem_conn(local_node, elem) + disp = ZERO + rot = ZERO + do idir = 1, NDIM + dof = dof_id(idir,node) + if (dof .gt. 0) disp(idir) = u(dof) + dof = dof_id(idir + 3,node) + if (dof .gt. 0) rot(idir) = u(dof) + end do + qloc(1,local_node) = dot_product(disp, basis(:,1)) + qloc(2,local_node) = dot_product(disp, basis(:,2)) + qloc(3,local_node) = dot_product(disp, basis(:,3)) + qloc(4,local_node) = dot_product(rot, basis(:,1)) + qloc(5,local_node) = dot_product(rot, basis(:,2)) + end do + end subroutine shell_general_local_dofs + + subroutine shell_general_shape_xy(etype, nlocal, xloc, natural, nshape, & + dndx, dndy, detj, ierr) + character(len=*), intent(in) :: etype + integer, intent(in) :: nlocal + real(rk), intent(in) :: xloc(2,MAX_NEN) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndx(MAX_NEN) + real(rk), intent(out) :: dndy(MAX_NEN) + real(rk), intent(out) :: detj + integer, intent(out) :: ierr + real(rk) :: dndr(NDIM,MAX_NEN) + real(rk) :: jac(2,2) + real(rk) :: invj(2,2) + integer :: local_node + + call shape_evaluate(etype, natural, nshape, dndr, ierr) + if (ierr .ne. FEM_SUCCESS) return + + jac = ZERO + do local_node = 1, nlocal + jac(1,1) = jac(1,1) + xloc(1,local_node) * dndr(1,local_node) + jac(1,2) = jac(1,2) + xloc(1,local_node) * dndr(2,local_node) + jac(2,1) = jac(2,1) + xloc(2,local_node) * dndr(1,local_node) + jac(2,2) = jac(2,2) + xloc(2,local_node) * dndr(2,local_node) + end do + + detj = jac(1,1) * jac(2,2) - jac(1,2) * jac(2,1) + if (detj .le. ZERO) then + call error_set(FEM_ERR_MESH, 'shell element has non-positive Jacobian', ierr) + return + end if + + invj(1,1) = jac(2,2) / detj + invj(1,2) = -jac(1,2) / detj + invj(2,1) = -jac(2,1) / detj + invj(2,2) = jac(1,1) / detj + + dndx = ZERO + dndy = ZERO + do local_node = 1, nlocal + dndx(local_node) = dndr(1,local_node) * invj(1,1) + & + dndr(2,local_node) * invj(2,1) + dndy(local_node) = dndr(1,local_node) * invj(1,2) + & + dndr(2,local_node) * invj(2,2) + end do + + ierr = FEM_SUCCESS + end subroutine shell_general_shape_xy + + subroutine shell_general_strains(nlocal, nshape, dndx, dndy, qloc, & + strain_mem, strain_ben, strain_shr) + integer, intent(in) :: nlocal + real(rk), intent(in) :: nshape(MAX_NEN) + real(rk), intent(in) :: dndx(MAX_NEN) + real(rk), intent(in) :: dndy(MAX_NEN) + real(rk), intent(in) :: qloc(5,MAX_NEN) + real(rk), intent(out) :: strain_mem(3) + real(rk), intent(out) :: strain_ben(3) + real(rk), intent(out) :: strain_shr(2) + integer :: local_node + + strain_mem = ZERO + strain_ben = ZERO + strain_shr = ZERO + + do local_node = 1, nlocal + strain_mem(1) = strain_mem(1) + dndx(local_node) * qloc(1,local_node) + strain_mem(2) = strain_mem(2) + dndy(local_node) * qloc(2,local_node) + strain_mem(3) = strain_mem(3) + dndy(local_node) * qloc(1,local_node) + & + dndx(local_node) * qloc(2,local_node) + + strain_ben(1) = strain_ben(1) + dndx(local_node) * qloc(5,local_node) + strain_ben(2) = strain_ben(2) - dndy(local_node) * qloc(4,local_node) + strain_ben(3) = strain_ben(3) - dndx(local_node) * qloc(4,local_node) + & + dndy(local_node) * qloc(5,local_node) + + strain_shr(1) = strain_shr(1) + dndx(local_node) * qloc(3,local_node) + & + nshape(local_node) * qloc(5,local_node) + strain_shr(2) = strain_shr(2) + dndy(local_node) * qloc(3,local_node) - & + nshape(local_node) * qloc(4,local_node) + end do + end subroutine shell_general_strains + + subroutine shell_general_add_global(elem, nlocal, basis, floc) + integer, intent(in) :: elem + integer, intent(in) :: nlocal + real(rk), intent(in) :: basis(NDIM,NDIM) + real(rk), intent(in) :: floc(5,MAX_NEN) + real(rk) :: fglob(NDIM) + real(rk) :: mglob(NDIM) + integer :: local_node + integer :: node + integer :: idir + integer :: dof + + do local_node = 1, nlocal + node = elem_conn(local_node, elem) + fglob = floc(1,local_node) * basis(:,1) + & + floc(2,local_node) * basis(:,2) + & + floc(3,local_node) * basis(:,3) + mglob = floc(4,local_node) * basis(:,1) + & + floc(5,local_node) * basis(:,2) + + do idir = 1, NDIM + dof = dof_id(idir,node) + if (dof .gt. 0) fint(dof) = fint(dof) + fglob(idir) + dof = dof_id(idir + 3,node) + if (dof .gt. 0) fint(dof) = fint(dof) + mglob(idir) + end do + end do + end subroutine shell_general_add_global + subroutine shell4_basis(elem, basis, xloc, ierr) integer, intent(in) :: elem real(rk), intent(out) :: basis(NDIM,NDIM) diff --git a/tests/module/test_shell_internal.f90 b/tests/module/test_shell_internal.f90 index 31fb7c1..d8ab1c7 100644 --- a/tests/module/test_shell_internal.f90 +++ b/tests/module/test_shell_internal.f90 @@ -12,6 +12,7 @@ program test_shell_internal real(rk), parameter :: EXX = 0.01_rk call check_s3_membrane_patch() + call check_s6_membrane_patch() contains @@ -25,8 +26,8 @@ contains call element_compute_internal_force(ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) if (elem_status(1) .ne. 0) call fail(3) - call check_state_shape(4) - call check_membrane_state(10) + call check_state_shape(1, 4) + call check_membrane_state(1, 10) call check_force_balance(20) call check_no_normal_or_rotation(30) @@ -34,6 +35,25 @@ contains if (ierr .ne. FEM_SUCCESS) call fail(40) end subroutine check_s3_membrane_patch + subroutine check_s6_membrane_patch() + integer :: ierr + + call setup_s6(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(51) + call apply_x_extension(EXX) + + call element_compute_internal_force(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(52) + if (elem_status(1) .ne. 0) call fail(53) + call check_state_shape(3, 54) + call check_membrane_state(3, 60) + call check_force_balance(70) + call check_no_normal_or_rotation(80) + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(90) + end subroutine check_s6_membrane_patch + subroutine setup_s3(ierr) integer, intent(out) :: ierr @@ -75,6 +95,53 @@ contains call database_assign_dofs(ierr) end subroutine setup_s3 + subroutine setup_s6(ierr) + integer, intent(out) :: ierr + + call database_allocate_model(6, 1, 0, 1, 0, 1, 1, 0, 1, & + 0, 0, 0, 0, 0, ierr) + if (ierr .ne. FEM_SUCCESS) return + + node_id_ext(1) = 1 + node_id_ext(2) = 2 + node_id_ext(3) = 3 + node_id_ext(4) = 4 + node_id_ext(5) = 5 + node_id_ext(6) = 6 + coord0(:,1) = (/ ZERO, ZERO, ZERO /) + coord0(:,2) = (/ ONE, ZERO, ZERO /) + coord0(:,3) = (/ ZERO, ONE, ZERO /) + coord0(:,4) = HALF * (coord0(:,1) + coord0(:,2)) + coord0(:,5) = HALF * (coord0(:,2) + coord0(:,3)) + coord0(:,6) = HALF * (coord0(:,3) + coord0(:,1)) + coord = coord0 + + elem_id_ext(1) = 1 + elem_type(1) = 'S6' + elem_nnode(1) = 6 + elem_conn(:,1) = 0 + elem_conn(1:6,1) = (/ 1, 2, 3, 4, 5, 6 /) + elem_mat(1) = 1 + elem_sec(1) = 1 + + elset_name(1) = 'EALL' + elset_start(1) = 1 + elset_count(1) = 1 + elset_items(1) = 1 + + mat_name(1) = 'MAT' + mat_density(1) = ONE + mat_e(1) = YOUNG + mat_nu(1) = POISSON + + section_type(1) = 'SHELL' + section_elset_name(1) = 'EALL' + section_material_name(1) = 'MAT' + section_thickness(1) = THICKNESS + + call database_assign_dofs(ierr) + end subroutine setup_s6 + subroutine apply_x_extension(exx) real(rk), intent(in) :: exx integer :: node @@ -85,21 +152,24 @@ contains end do end subroutine apply_x_extension - subroutine check_state_shape(code) + subroutine check_state_shape(expected_ngp, code) + integer, intent(in) :: expected_ngp integer, intent(in) :: code if (elem_gp_start(1) .ne. 1) call fail(code) - if (elem_ngp(1) .ne. 1) call fail(code + 1) - if (ngauss_total .ne. 1) call fail(code + 2) + if (elem_ngp(1) .ne. expected_ngp) call fail(code + 1) + if (ngauss_total .ne. expected_ngp) call fail(code + 2) if (.not. allocated(stress)) call fail(code + 3) if (.not. allocated(strain)) call fail(code + 4) end subroutine check_state_shape - subroutine check_membrane_state(code) + subroutine check_membrane_state(npoint, code) + integer, intent(in) :: npoint integer, intent(in) :: code real(rk) :: coeff real(rk) :: expected_stress(NSTRESS) real(rk) :: expected_strain(NSTRESS) + integer :: gp coeff = YOUNG / (ONE - POISSON * POISSON) expected_strain = ZERO @@ -108,11 +178,13 @@ contains expected_stress(1) = coeff * EXX expected_stress(2) = coeff * POISSON * EXX - call check_vector_close(strain(:,1), expected_strain, code) - call check_vector_close(stress(:,1), expected_stress, code + 1) - if (abs(statev(10,1)) .gt. TOL) call fail(code + 2) - if (abs(statev(11,1)) .gt. TOL) call fail(code + 3) - if (abs(statev(12,1)) .gt. TOL) call fail(code + 4) + do gp = 1, npoint + call check_vector_close(strain(:,gp), expected_strain, code) + call check_vector_close(stress(:,gp), expected_stress, code + 1) + if (abs(statev(10,gp)) .gt. TOL) call fail(code + 2) + if (abs(statev(11,gp)) .gt. TOL) call fail(code + 3) + if (abs(statev(12,gp)) .gt. TOL) call fail(code + 4) + end do end subroutine check_membrane_state subroutine check_force_balance(code)