diff --git a/CMakeLists.txt b/CMakeLists.txt index cdcc90c..0788e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,6 +172,13 @@ add_executable(test_shell_pressure target_link_libraries(test_shell_pressure PRIVATE femlite_core) femlite_apply_fortran_options(test_shell_pressure) +add_executable(test_shell_internal + tests/module/test_shell_internal.f90 +) + +target_link_libraries(test_shell_internal PRIVATE femlite_core) +femlite_apply_fortran_options(test_shell_internal) + add_executable(test_solver_implicit tests/module/test_solver_implicit.f90 ) @@ -263,6 +270,11 @@ set_tests_properties(shell_pressure PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) +add_test(NAME shell_internal COMMAND test_shell_internal) +set_tests_properties(shell_internal PROPERTIES + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +) + add_test(NAME solver_implicit COMMAND test_solver_implicit) set_tests_properties(solver_implicit PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" diff --git a/src/element/fem_element_internal.f90 b/src/element/fem_element_internal.f90 index 6967b6e..c8e837f 100644 --- a/src/element/fem_element_internal.f90 +++ b/src/element/fem_element_internal.f90 @@ -43,6 +43,9 @@ contains case ('C3D10', 'C3D20') call solid_quadratic_internal_force(elem, dt_local, ierr) if (ierr .ne. FEM_SUCCESS) return + case ('S3') + call shell3_internal_force(elem, ierr) + if (ierr .ne. FEM_SUCCESS) return case ('S4') call shell4_internal_force(elem, ierr) if (ierr .ne. FEM_SUCCESS) return @@ -391,6 +394,133 @@ contains ierr = FEM_SUCCESS end subroutine solid_quadratic_internal_force + subroutine shell3_internal_force(elem, ierr) + integer, intent(in) :: elem + integer, intent(out) :: ierr + real(rk) :: basis(NDIM,NDIM) + real(rk) :: xloc(2,3) + real(rk) :: qloc(5,3) + real(rk) :: floc(5,3) + real(rk) :: nshape(3) + real(rk) :: dndx(3) + real(rk) :: dndy(3) + 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 :: local_node + integer :: gp + integer :: mat + integer :: sec + + if (elem_nnode(elem) .ne. 3) then + call error_set(FEM_ERR_MESH, 'S3 element must have 3 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, 'S3 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, 'S3 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, 'S3 elastic modulus must be positive', ierr) + return + end if + if (poisson .le. -ONE .or. poisson .ge. HALF) then + call error_set(FEM_ERR_MATERIAL, 'S3 Poisson ratio must be in (-1,0.5)', ierr) + return + end if + if (thickness .le. ZERO) then + call error_set(FEM_ERR_INPUT, 'S3 section thickness must be positive', ierr) + return + end if + + call shell3_basis(elem, basis, xloc, ierr) + if (ierr .ne. FEM_SUCCESS) return + call shell3_local_dofs(elem, 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 shell3_shape_xy(xloc, nshape, dndx, dndy, detj, ierr) + if (ierr .ne. FEM_SUCCESS) return + weight = HALF * detj + + call shell3_strains(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) + + floc = ZERO + do local_node = 1, 3 + 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 + + gp = elem_gp_start(elem) + 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 + + call shell3_add_global(elem, basis, floc) + ierr = FEM_SUCCESS + end subroutine shell3_internal_force + subroutine shell4_internal_force(elem, ierr) integer, intent(in) :: elem integer, intent(out) :: ierr @@ -534,6 +664,194 @@ contains ierr = FEM_SUCCESS end subroutine shell4_internal_force + subroutine shell3_basis(elem, basis, xloc, ierr) + integer, intent(in) :: elem + real(rk), intent(out) :: basis(NDIM,NDIM) + real(rk), intent(out) :: xloc(2,3) + 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, 'S3 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, 'S3 local basis is singular', ierr) + return + end if + basis(:,3) = normal / lenn + call cross3(basis(:,3), basis(:,1), basis(:,2)) + + do local_node = 1, 3 + 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 shell3_basis + + subroutine shell3_local_dofs(elem, basis, qloc) + integer, intent(in) :: elem + real(rk), intent(in) :: basis(NDIM,NDIM) + real(rk), intent(out) :: qloc(5,3) + real(rk) :: disp(NDIM) + real(rk) :: rot(NDIM) + integer :: local_node + integer :: node + integer :: idir + integer :: dof + + qloc = ZERO + do local_node = 1, 3 + 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 shell3_local_dofs + + subroutine shell3_shape_xy(xloc, nshape, dndx, dndy, detj, ierr) + real(rk), intent(in) :: xloc(2,3) + real(rk), intent(out) :: nshape(3) + real(rk), intent(out) :: dndx(3) + real(rk), intent(out) :: dndy(3) + real(rk), intent(out) :: detj + integer, intent(out) :: ierr + real(rk) :: dndr(3) + real(rk) :: dnds(3) + real(rk) :: jac(2,2) + real(rk) :: invj(2,2) + integer :: local_node + + nshape = (/ ONE / 3.0_rk, ONE / 3.0_rk, ONE / 3.0_rk /) + dndr = (/ -ONE, ONE, ZERO /) + dnds = (/ -ONE, ZERO, ONE /) + + jac = ZERO + do local_node = 1, 3 + jac(1,1) = jac(1,1) + xloc(1,local_node) * dndr(local_node) + jac(1,2) = jac(1,2) + xloc(1,local_node) * dnds(local_node) + jac(2,1) = jac(2,1) + xloc(2,local_node) * dndr(local_node) + jac(2,2) = jac(2,2) + xloc(2,local_node) * dnds(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, 'S3 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 + + do local_node = 1, 3 + dndx(local_node) = dndr(local_node) * invj(1,1) + & + dnds(local_node) * invj(2,1) + dndy(local_node) = dndr(local_node) * invj(1,2) + & + dnds(local_node) * invj(2,2) + end do + + ierr = FEM_SUCCESS + end subroutine shell3_shape_xy + + subroutine shell3_strains(nshape, dndx, dndy, qloc, strain_mem, & + strain_ben, strain_shr) + real(rk), intent(in) :: nshape(3) + real(rk), intent(in) :: dndx(3) + real(rk), intent(in) :: dndy(3) + real(rk), intent(in) :: qloc(5,3) + 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, 3 + 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 shell3_strains + + subroutine shell3_add_global(elem, basis, floc) + integer, intent(in) :: elem + real(rk), intent(in) :: basis(NDIM,NDIM) + real(rk), intent(in) :: floc(5,3) + real(rk) :: fglob(NDIM) + real(rk) :: mglob(NDIM) + integer :: local_node + integer :: node + integer :: idir + integer :: dof + + do local_node = 1, 3 + 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 shell3_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 new file mode 100644 index 0000000..31fb7c1 --- /dev/null +++ b/tests/module/test_shell_internal.f90 @@ -0,0 +1,171 @@ +program test_shell_internal + use fem_precision + use fem_error + use fem_database + use fem_element_internal + implicit none + + real(rk), parameter :: TOL = 1.0e-10_rk + real(rk), parameter :: YOUNG = 30.0_rk + real(rk), parameter :: POISSON = 0.25_rk + real(rk), parameter :: THICKNESS = 0.2_rk + real(rk), parameter :: EXX = 0.01_rk + + call check_s3_membrane_patch() + +contains + + subroutine check_s3_membrane_patch() + integer :: ierr + + call setup_s3(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(1) + call apply_x_extension(EXX) + + 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_force_balance(20) + call check_no_normal_or_rotation(30) + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(40) + end subroutine check_s3_membrane_patch + + subroutine setup_s3(ierr) + integer, intent(out) :: ierr + + call database_allocate_model(3, 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 + coord0(:,1) = (/ ZERO, ZERO, ZERO /) + coord0(:,2) = (/ ONE, ZERO, ZERO /) + coord0(:,3) = (/ ZERO, ONE, ZERO /) + coord = coord0 + + elem_id_ext(1) = 1 + elem_type(1) = 'S3' + elem_nnode(1) = 3 + elem_conn(:,1) = 0 + elem_conn(1:3,1) = (/ 1, 2, 3 /) + 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_s3 + + subroutine apply_x_extension(exx) + real(rk), intent(in) :: exx + integer :: node + + u = ZERO + do node = 1, nnode + u(dof_id(1,node)) = exx * coord0(1,node) + end do + end subroutine apply_x_extension + + subroutine check_state_shape(code) + 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 (.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) + integer, intent(in) :: code + real(rk) :: coeff + real(rk) :: expected_stress(NSTRESS) + real(rk) :: expected_strain(NSTRESS) + + coeff = YOUNG / (ONE - POISSON * POISSON) + expected_strain = ZERO + expected_strain(1) = EXX + expected_stress = ZERO + 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) + end subroutine check_membrane_state + + subroutine check_force_balance(code) + integer, intent(in) :: code + real(rk) :: balance(NDOF_NODE) + real(rk) :: max_force + integer :: node + integer :: idir + + balance = ZERO + max_force = ZERO + do node = 1, nnode + do idir = 1, NDOF_NODE + balance(idir) = balance(idir) + fint(dof_id(idir,node)) + max_force = max(max_force, abs(fint(dof_id(idir,node)))) + end do + end do + + if (maxval(abs(balance)) .gt. TOL) call fail(code) + if (max_force .le. TOL) call fail(code + 1) + end subroutine check_force_balance + + subroutine check_no_normal_or_rotation(code) + integer, intent(in) :: code + integer :: node + integer :: idir + + do node = 1, nnode + if (abs(fint(dof_id(3,node))) .gt. TOL) call fail(code) + do idir = 4, NDOF_NODE + if (abs(fint(dof_id(idir,node))) .gt. TOL) call fail(code + 1) + end do + end do + end subroutine check_no_normal_or_rotation + + subroutine check_vector_close(actual, expected, code) + real(rk), intent(in) :: actual(NSTRESS) + real(rk), intent(in) :: expected(NSTRESS) + integer, intent(in) :: code + integer :: i + + do i = 1, NSTRESS + if (abs(actual(i) - expected(i)) .gt. TOL * max(ONE, abs(expected(i)))) then + call fail(code) + end if + end do + end subroutine check_vector_close + + subroutine fail(code) + integer, intent(in) :: code + + write(*,*) 'test_shell_internal failed:', code + stop 1 + end subroutine fail + +end program test_shell_internal