diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dfb46a..cdcc90c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,13 @@ add_executable(test_shell_mass target_link_libraries(test_shell_mass PRIVATE femlite_core) femlite_apply_fortran_options(test_shell_mass) +add_executable(test_shell_pressure + tests/module/test_shell_pressure.f90 +) + +target_link_libraries(test_shell_pressure PRIVATE femlite_core) +femlite_apply_fortran_options(test_shell_pressure) + add_executable(test_solver_implicit tests/module/test_solver_implicit.f90 ) @@ -251,6 +258,11 @@ set_tests_properties(shell_mass PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) +add_test(NAME shell_pressure COMMAND test_shell_pressure) +set_tests_properties(shell_pressure 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/boundary/fem_boundary.f90 b/src/boundary/fem_boundary.f90 index d0d7222..96f1dbb 100644 --- a/src/boundary/fem_boundary.f90 +++ b/src/boundary/fem_boundary.f90 @@ -2,6 +2,9 @@ module fem_boundary use fem_precision use fem_error use fem_database + use fem_element_topology + use fem_quadrature + use fem_shape_functions implicit none real(rk) :: boundary_last_load_time = ZERO @@ -246,38 +249,89 @@ contains integer, intent(in) :: elem real(rk), intent(in) :: pressure integer, intent(out) :: ierr - real(rk) :: normal(NDIM) - real(rk) :: area - real(rk) :: nodal_force(NDIM) - integer :: local_node - integer :: node - integer :: idir - integer :: dof if (elem_status(elem) .ne. 0) then ierr = FEM_SUCCESS return end if - if (trim(adjustl(elem_type(elem))) .ne. 'S4') then - call error_set(FEM_ERR_INPUT, 'DLOAD P is implemented for S4 only', ierr) + if (.not. element_is_shell(elem_type(elem))) then + call error_set(FEM_ERR_INPUT, 'DLOAD P is implemented for shell elements only', ierr) return end if - call shell4_normal_area(elem, normal, area, ierr) + call element_validate_node_count(elem_type(elem), elem_nnode(elem), ierr) + if (ierr .ne. FEM_SUCCESS) return + call apply_shell_pressure(elem, pressure, ierr) + end subroutine apply_pressure_to_element + + subroutine apply_shell_pressure(elem, pressure, ierr) + integer, intent(in) :: elem + real(rk), intent(in) :: pressure + integer, intent(out) :: ierr + integer, parameter :: MAX_QP = 16 + real(rk) :: xi(NDIM,MAX_QP) + real(rk) :: weight(MAX_QP) + real(rk) :: nshape(MAX_NEN) + real(rk) :: dndr(NDIM,MAX_NEN) + real(rk) :: coords(NDIM,MAX_NEN) + real(rk) :: tangent1(NDIM) + real(rk) :: tangent2(NDIM) + real(rk) :: normal(NDIM) + real(rk) :: traction(NDIM) + real(rk) :: jac_area + real(rk) :: factor + integer :: gp + integer :: npoint + integer :: local_node + integer :: node + integer :: idir + integer :: dof + + call quadrature_get_rule(elem_type(elem), MAX_QP, npoint, xi, weight, ierr) if (ierr .ne. FEM_SUCCESS) return - nodal_force = -pressure * normal * area / real(elem_nnode(elem), rk) + coords = ZERO do local_node = 1, elem_nnode(elem) - node = elem_conn(local_node,elem) + node = elem_conn(local_node, elem) + coords(:,local_node) = coord0(:,node) do idir = 1, NDIM dof = dof_id(idir,node) - if (dof .gt. 0) fext(dof) = fext(dof) + nodal_force(idir) + if (dof .gt. 0) coords(idir,local_node) = coords(idir,local_node) + u(dof) + end do + end do + + do gp = 1, npoint + call shape_evaluate(elem_type(elem), xi(:,gp), nshape, dndr, ierr) + if (ierr .ne. FEM_SUCCESS) return + + tangent1 = ZERO + tangent2 = ZERO + do local_node = 1, elem_nnode(elem) + tangent1 = tangent1 + coords(:,local_node) * dndr(1,local_node) + tangent2 = tangent2 + coords(:,local_node) * dndr(2,local_node) + end do + + call cross3(tangent1, tangent2, normal) + jac_area = sqrt(sum(normal * normal)) + if (jac_area .le. ZERO) then + call error_set(FEM_ERR_MESH, 'shell pressure surface has non-positive Jacobian', ierr) + return + end if + traction = -pressure * normal / jac_area + + do local_node = 1, elem_nnode(elem) + node = elem_conn(local_node,elem) + factor = nshape(local_node) * jac_area * weight(gp) + do idir = 1, NDIM + dof = dof_id(idir,node) + if (dof .gt. 0) fext(dof) = fext(dof) + factor * traction(idir) + end do end do end do ierr = FEM_SUCCESS - end subroutine apply_pressure_to_element + end subroutine apply_shell_pressure subroutine shell4_normal_area(elem, normal, area, ierr) integer, intent(in) :: elem diff --git a/tests/module/test_shell_pressure.f90 b/tests/module/test_shell_pressure.f90 new file mode 100644 index 0000000..e3a0e0e --- /dev/null +++ b/tests/module/test_shell_pressure.f90 @@ -0,0 +1,210 @@ +program test_shell_pressure + use fem_precision + use fem_error + use fem_database + use fem_boundary + implicit none + + real(rk), parameter :: TOL = 1.0e-10_rk + real(rk), parameter :: PRESSURE = 2.0_rk + + call check_shell_pressure('S3', 3, HALF, 10) + call check_shell_pressure('S4', 4, ONE, 40) + call check_shell_pressure('S6', 6, HALF, 70) + call check_shell_pressure('S8', 8, ONE, 100) + +contains + + subroutine check_shell_pressure(etype, nlocal, area, code) + character(len=*), intent(in) :: etype + integer, intent(in) :: nlocal + real(rk), intent(in) :: area + integer, intent(in) :: code + integer :: ierr + real(rk) :: total_force(NDIM) + character(len=ELEM_TYPE_LEN) :: local_type + + call setup_shell(etype, nlocal, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code) + + call boundary_apply_prescribed_loads(ZERO, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code + 1) + + call collect_total_force(total_force) + call check_close(total_force(1), ZERO, code + 2) + call check_close(total_force(2), ZERO, code + 3) + call check_close(total_force(3), -PRESSURE * area, code + 4) + call check_rotational_force_is_zero(code + 5) + + local_type = adjustl(etype) + select case (trim(local_type)) + case ('S3') + call check_node_force_z(1, -PRESSURE * area / 3.0_rk, code + 6) + call check_node_force_z(3, -PRESSURE * area / 3.0_rk, code + 7) + case ('S4') + call check_node_force_z(1, -PRESSURE * area / 4.0_rk, code + 6) + call check_node_force_z(4, -PRESSURE * area / 4.0_rk, code + 7) + case ('S6') + call check_node_force_z(1, ZERO, code + 6) + call check_node_force_z(4, -PRESSURE * area / 3.0_rk, code + 7) + call check_node_force_z(6, -PRESSURE * area / 3.0_rk, code + 8) + case ('S8') + call check_node_force_z(1, PRESSURE / 12.0_rk, code + 6) + call check_node_force_z(5, -PRESSURE / 3.0_rk, code + 7) + call check_node_force_z(8, -PRESSURE / 3.0_rk, code + 8) + end select + + call database_finalize(ierr) + if (ierr .ne. FEM_SUCCESS) call fail(code + 20) + end subroutine check_shell_pressure + + subroutine setup_shell(etype, nlocal, ierr) + character(len=*), intent(in) :: etype + integer, intent(in) :: nlocal + integer, intent(out) :: ierr + + call database_allocate_model(nlocal, 1, 0, 1, 0, 1, 1, 0, 1, & + 0, 0, 0, 0, 1, ierr) + if (ierr .ne. FEM_SUCCESS) return + call fill_common_model(etype, nlocal) + call fill_shell_coordinates(etype) + coord = coord0 + + dload_target(1) = '1' + dload_label(1) = 'P' + dload_value(1) = PRESSURE + dload_amp(1) = 0 + + call database_assign_dofs(ierr) + end subroutine setup_shell + + subroutine fill_common_model(etype, nlocal) + character(len=*), intent(in) :: etype + integer, intent(in) :: nlocal + integer :: i + + do i = 1, nlocal + node_id_ext(i) = i + coord0(:,i) = ZERO + coord(:,i) = ZERO + elem_conn(i,1) = i + end do + + elem_id_ext(1) = 1 + elem_type(1) = etype + elem_nnode(1) = nlocal + 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) = ONE + mat_nu(1) = 0.25_rk + + section_type(1) = 'SHELL' + section_elset_name(1) = 'EALL' + section_material_name(1) = 'MAT' + section_thickness(1) = ONE + end subroutine fill_common_model + + subroutine fill_shell_coordinates(etype) + character(len=*), intent(in) :: etype + character(len=ELEM_TYPE_LEN) :: local_type + + local_type = adjustl(etype) + select case (trim(local_type)) + case ('S3') + call fill_triangle3() + case ('S4') + call fill_quad4() + case ('S6') + call fill_triangle6() + case ('S8') + call fill_quad8() + case default + call fail(900) + end select + end subroutine fill_shell_coordinates + + subroutine fill_triangle3() + coord0(:,1) = (/ ZERO, ZERO, ZERO /) + coord0(:,2) = (/ ONE, ZERO, ZERO /) + coord0(:,3) = (/ ZERO, ONE, ZERO /) + end subroutine fill_triangle3 + + subroutine fill_triangle6() + call fill_triangle3() + coord0(:,4) = HALF * (coord0(:,1) + coord0(:,2)) + coord0(:,5) = HALF * (coord0(:,2) + coord0(:,3)) + coord0(:,6) = HALF * (coord0(:,3) + coord0(:,1)) + end subroutine fill_triangle6 + + subroutine fill_quad4() + coord0(:,1) = (/ ZERO, ZERO, ZERO /) + coord0(:,2) = (/ ONE, ZERO, ZERO /) + coord0(:,3) = (/ ONE, ONE, ZERO /) + coord0(:,4) = (/ ZERO, ONE, ZERO /) + end subroutine fill_quad4 + + subroutine fill_quad8() + call fill_quad4() + coord0(:,5) = HALF * (coord0(:,1) + coord0(:,2)) + coord0(:,6) = HALF * (coord0(:,2) + coord0(:,3)) + coord0(:,7) = HALF * (coord0(:,3) + coord0(:,4)) + coord0(:,8) = HALF * (coord0(:,4) + coord0(:,1)) + end subroutine fill_quad8 + + subroutine collect_total_force(total_force) + real(rk), intent(out) :: total_force(NDIM) + integer :: node + integer :: idir + + total_force = ZERO + do node = 1, nnode + do idir = 1, NDIM + total_force(idir) = total_force(idir) + fext(dof_id(idir,node)) + end do + end do + end subroutine collect_total_force + + subroutine check_rotational_force_is_zero(code) + integer, intent(in) :: code + integer :: node + integer :: idir + + do node = 1, nnode + do idir = 4, NDOF_NODE + if (abs(fext(dof_id(idir,node))) .gt. TOL) call fail(code) + end do + end do + end subroutine check_rotational_force_is_zero + + subroutine check_node_force_z(node, expected, code) + integer, intent(in) :: node + real(rk), intent(in) :: expected + integer, intent(in) :: code + + call check_close(fext(dof_id(3,node)), expected, code) + end subroutine check_node_force_z + + 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 fail(code) + integer, intent(in) :: code + + write(*,*) 'test_shell_pressure failed:', code + stop 1 + end subroutine fail + +end program test_shell_pressure