From a20977fd7fa80a92cb67c51b271d8a2349f93419 Mon Sep 17 00:00:00 2001 From: shenw Date: Mon, 22 Jun 2026 20:29:58 +0800 Subject: [PATCH] Add element infrastructure for v0.2 --- CMakeLists.txt | 15 + src/element/fem_element_internal.f90 | 12 +- src/element/fem_element_topology.f90 | 312 ++++++++++++++ src/element/fem_quadrature.f90 | 245 +++++++++++ src/element/fem_shape_functions.f90 | 419 +++++++++++++++++++ tests/module/test_element_infrastructure.f90 | 249 +++++++++++ 6 files changed, 1242 insertions(+), 10 deletions(-) create mode 100644 src/element/fem_element_topology.f90 create mode 100644 src/element/fem_quadrature.f90 create mode 100644 src/element/fem_shape_functions.f90 create mode 100644 tests/module/test_element_infrastructure.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index cdbabac..daeff50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,9 @@ add_library(femlite_core STATIC src/mesh/fem_database.f90 src/input/fem_inp_reader.f90 src/material/fem_material_j2.f90 + src/element/fem_element_topology.f90 + src/element/fem_quadrature.f90 + src/element/fem_shape_functions.f90 src/element/fem_element_mass.f90 src/element/fem_element_internal.f90 src/coupling/fem_coupling.f90 @@ -79,6 +82,13 @@ add_executable(test_material_j2 target_link_libraries(test_material_j2 PRIVATE femlite_core) femlite_apply_fortran_options(test_material_j2) +add_executable(test_element_infrastructure + tests/module/test_element_infrastructure.f90 +) + +target_link_libraries(test_element_infrastructure PRIVATE femlite_core) +femlite_apply_fortran_options(test_element_infrastructure) + add_executable(perf_p1 tests/performance/perf_p1.f90 ) @@ -95,3 +105,8 @@ add_test(NAME material_j2 COMMAND test_material_j2) set_tests_properties(material_j2 PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) + +add_test(NAME element_infrastructure COMMAND test_element_infrastructure) +set_tests_properties(element_infrastructure PROPERTIES + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +) diff --git a/src/element/fem_element_internal.f90 b/src/element/fem_element_internal.f90 index f27e44d..d42c98e 100644 --- a/src/element/fem_element_internal.f90 +++ b/src/element/fem_element_internal.f90 @@ -2,6 +2,7 @@ module fem_element_internal use fem_precision use fem_error use fem_database + use fem_element_topology use fem_material_j2 implicit none @@ -69,16 +70,7 @@ contains ngauss_total = 0 do elem = 1, nelem - select case (trim(adjustl(elem_type(elem)))) - case ('C3D4') - elem_ngp(elem) = 1 - case ('C3D8') - elem_ngp(elem) = 8 - case ('S4') - elem_ngp(elem) = 4 - case default - elem_ngp(elem) = 0 - end select + elem_ngp(elem) = element_num_integration_points(elem_type(elem)) if (elem_ngp(elem) .gt. 0) then elem_gp_start(elem) = ngauss_total + 1 diff --git a/src/element/fem_element_topology.f90 b/src/element/fem_element_topology.f90 new file mode 100644 index 0000000..9121b35 --- /dev/null +++ b/src/element/fem_element_topology.f90 @@ -0,0 +1,312 @@ +module fem_element_topology + use fem_precision + use fem_error + implicit none + + private + + integer, parameter :: ELEM_KIND_UNKNOWN = 0 + integer, parameter :: ELEM_KIND_SOLID = 1 + integer, parameter :: ELEM_KIND_SHELL = 2 + + public :: ELEM_KIND_UNKNOWN + public :: ELEM_KIND_SOLID + public :: ELEM_KIND_SHELL + public :: element_kind + public :: element_is_supported + public :: element_is_solid + public :: element_is_shell + public :: element_num_nodes + public :: element_num_faces + public :: element_num_integration_points + public :: element_validate_node_count + public :: element_face_nodes + +contains + + integer function element_kind(type_name) + character(len=*), intent(in) :: type_name + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + select case (trim(etype)) + case ('C3D4', 'C3D8', 'C3D10', 'C3D20') + element_kind = ELEM_KIND_SOLID + case ('S3', 'S4', 'S6', 'S8') + element_kind = ELEM_KIND_SHELL + case default + element_kind = ELEM_KIND_UNKNOWN + end select + end function element_kind + + logical function element_is_supported(type_name) + character(len=*), intent(in) :: type_name + + element_is_supported = element_kind(type_name) .ne. ELEM_KIND_UNKNOWN + end function element_is_supported + + logical function element_is_solid(type_name) + character(len=*), intent(in) :: type_name + + element_is_solid = element_kind(type_name) .eq. ELEM_KIND_SOLID + end function element_is_solid + + logical function element_is_shell(type_name) + character(len=*), intent(in) :: type_name + + element_is_shell = element_kind(type_name) .eq. ELEM_KIND_SHELL + end function element_is_shell + + integer function element_num_nodes(type_name) + character(len=*), intent(in) :: type_name + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + select case (trim(etype)) + case ('C3D4') + element_num_nodes = 4 + case ('C3D8') + element_num_nodes = 8 + case ('C3D10') + element_num_nodes = 10 + case ('C3D20') + element_num_nodes = 20 + case ('S3') + element_num_nodes = 3 + case ('S4') + element_num_nodes = 4 + case ('S6') + element_num_nodes = 6 + case ('S8') + element_num_nodes = 8 + case default + element_num_nodes = 0 + end select + end function element_num_nodes + + integer function element_num_faces(type_name) + character(len=*), intent(in) :: type_name + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + select case (trim(etype)) + case ('C3D4', 'C3D10') + element_num_faces = 4 + case ('C3D8', 'C3D20') + element_num_faces = 6 + case ('S3', 'S4', 'S6', 'S8') + element_num_faces = 1 + case default + element_num_faces = 0 + end select + end function element_num_faces + + integer function element_num_integration_points(type_name) + character(len=*), intent(in) :: type_name + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + select case (trim(etype)) + case ('C3D4') + element_num_integration_points = 1 + case ('C3D8') + element_num_integration_points = 8 + case ('C3D10') + element_num_integration_points = 4 + case ('C3D20') + element_num_integration_points = 27 + case ('S3') + element_num_integration_points = 1 + case ('S4') + element_num_integration_points = 4 + case ('S6') + element_num_integration_points = 3 + case ('S8') + element_num_integration_points = 9 + case default + element_num_integration_points = 0 + end select + end function element_num_integration_points + + subroutine element_validate_node_count(type_name, actual_nnode, ierr) + character(len=*), intent(in) :: type_name + integer, intent(in) :: actual_nnode + integer, intent(out) :: ierr + integer :: expected + + expected = element_num_nodes(type_name) + if (expected .le. 0) then + call error_set(FEM_ERR_MESH, 'unsupported element type', ierr) + return + end if + if (actual_nnode .ne. expected) then + call error_set(FEM_ERR_MESH, 'element node count does not match element type', ierr) + return + end if + + ierr = FEM_SUCCESS + end subroutine element_validate_node_count + + subroutine element_face_nodes(type_name, face_id, num_face_nodes, local_nodes, ierr) + character(len=*), intent(in) :: type_name + integer, intent(in) :: face_id + integer, intent(out) :: num_face_nodes + integer, intent(out) :: local_nodes(MAX_FACE_NODES) + integer, intent(out) :: ierr + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + local_nodes = 0 + num_face_nodes = 0 + + select case (trim(etype)) + case ('C3D4') + call c3d4_face(face_id, num_face_nodes, local_nodes, ierr) + case ('C3D8') + call c3d8_face(face_id, num_face_nodes, local_nodes, ierr) + case ('C3D10') + call c3d10_face(face_id, num_face_nodes, local_nodes, ierr) + case ('C3D20') + call c3d20_face(face_id, num_face_nodes, local_nodes, ierr) + case ('S3') + if (face_id .eq. 1) then + num_face_nodes = 3 + local_nodes(1:3) = (/ 1, 2, 3 /) + ierr = FEM_SUCCESS + else + call error_set(FEM_ERR_MESH, 'invalid S3 face id', ierr) + end if + case ('S4') + if (face_id .eq. 1) then + num_face_nodes = 4 + local_nodes(1:4) = (/ 1, 2, 3, 4 /) + ierr = FEM_SUCCESS + else + call error_set(FEM_ERR_MESH, 'invalid S4 face id', ierr) + end if + case ('S6') + if (face_id .eq. 1) then + num_face_nodes = 6 + local_nodes(1:6) = (/ 1, 2, 3, 4, 5, 6 /) + ierr = FEM_SUCCESS + else + call error_set(FEM_ERR_MESH, 'invalid S6 face id', ierr) + end if + case ('S8') + if (face_id .eq. 1) then + num_face_nodes = 8 + local_nodes(1:8) = (/ 1, 2, 3, 4, 5, 6, 7, 8 /) + ierr = FEM_SUCCESS + else + call error_set(FEM_ERR_MESH, 'invalid S8 face id', ierr) + end if + case default + call error_set(FEM_ERR_MESH, 'unsupported element type for face topology', ierr) + end select + end subroutine element_face_nodes + + subroutine c3d4_face(face_id, num_face_nodes, local_nodes, ierr) + integer, intent(in) :: face_id + integer, intent(out) :: num_face_nodes + integer, intent(out) :: local_nodes(MAX_FACE_NODES) + integer, intent(out) :: ierr + + num_face_nodes = 3 + select case (face_id) + case (1) + local_nodes(1:3) = (/ 1, 2, 3 /) + case (2) + local_nodes(1:3) = (/ 1, 2, 4 /) + case (3) + local_nodes(1:3) = (/ 1, 3, 4 /) + case (4) + local_nodes(1:3) = (/ 2, 3, 4 /) + case default + num_face_nodes = 0 + call error_set(FEM_ERR_MESH, 'invalid C3D4 face id', ierr) + return + end select + ierr = FEM_SUCCESS + end subroutine c3d4_face + + subroutine c3d8_face(face_id, num_face_nodes, local_nodes, ierr) + integer, intent(in) :: face_id + integer, intent(out) :: num_face_nodes + integer, intent(out) :: local_nodes(MAX_FACE_NODES) + integer, intent(out) :: ierr + + num_face_nodes = 4 + select case (face_id) + case (1) + local_nodes(1:4) = (/ 1, 2, 3, 4 /) + case (2) + local_nodes(1:4) = (/ 5, 6, 7, 8 /) + case (3) + local_nodes(1:4) = (/ 1, 2, 6, 5 /) + case (4) + local_nodes(1:4) = (/ 2, 3, 7, 6 /) + case (5) + local_nodes(1:4) = (/ 3, 4, 8, 7 /) + case (6) + local_nodes(1:4) = (/ 4, 1, 5, 8 /) + case default + num_face_nodes = 0 + call error_set(FEM_ERR_MESH, 'invalid C3D8 face id', ierr) + return + end select + ierr = FEM_SUCCESS + end subroutine c3d8_face + + subroutine c3d10_face(face_id, num_face_nodes, local_nodes, ierr) + integer, intent(in) :: face_id + integer, intent(out) :: num_face_nodes + integer, intent(out) :: local_nodes(MAX_FACE_NODES) + integer, intent(out) :: ierr + + num_face_nodes = 6 + select case (face_id) + case (1) + local_nodes(1:6) = (/ 1, 2, 3, 5, 6, 7 /) + case (2) + local_nodes(1:6) = (/ 1, 2, 4, 5, 9, 8 /) + case (3) + local_nodes(1:6) = (/ 2, 3, 4, 6, 10, 9 /) + case (4) + local_nodes(1:6) = (/ 3, 1, 4, 7, 8, 10 /) + case default + num_face_nodes = 0 + call error_set(FEM_ERR_MESH, 'invalid C3D10 face id', ierr) + return + end select + ierr = FEM_SUCCESS + end subroutine c3d10_face + + subroutine c3d20_face(face_id, num_face_nodes, local_nodes, ierr) + integer, intent(in) :: face_id + integer, intent(out) :: num_face_nodes + integer, intent(out) :: local_nodes(MAX_FACE_NODES) + integer, intent(out) :: ierr + + num_face_nodes = 8 + select case (face_id) + case (1) + local_nodes(1:8) = (/ 1, 2, 3, 4, 9, 10, 11, 12 /) + case (2) + local_nodes(1:8) = (/ 5, 6, 7, 8, 13, 14, 15, 16 /) + case (3) + local_nodes(1:8) = (/ 1, 2, 6, 5, 9, 18, 13, 17 /) + case (4) + local_nodes(1:8) = (/ 2, 3, 7, 6, 10, 19, 14, 18 /) + case (5) + local_nodes(1:8) = (/ 3, 4, 8, 7, 11, 20, 15, 19 /) + case (6) + local_nodes(1:8) = (/ 4, 1, 5, 8, 12, 17, 16, 20 /) + case default + num_face_nodes = 0 + call error_set(FEM_ERR_MESH, 'invalid C3D20 face id', ierr) + return + end select + ierr = FEM_SUCCESS + end subroutine c3d20_face + +end module fem_element_topology diff --git a/src/element/fem_quadrature.f90 b/src/element/fem_quadrature.f90 new file mode 100644 index 0000000..aee7951 --- /dev/null +++ b/src/element/fem_quadrature.f90 @@ -0,0 +1,245 @@ +module fem_quadrature + use fem_precision + use fem_error + use fem_element_topology + implicit none + + private + + public :: quadrature_get_count + public :: quadrature_get_rule + public :: gauss_legendre_1d + +contains + + subroutine quadrature_get_count(type_name, npoint, ierr) + character(len=*), intent(in) :: type_name + integer, intent(out) :: npoint + integer, intent(out) :: ierr + + npoint = element_num_integration_points(type_name) + if (npoint .le. 0) then + call error_set(FEM_ERR_MESH, 'unsupported element type for quadrature', ierr) + return + end if + + ierr = FEM_SUCCESS + end subroutine quadrature_get_count + + subroutine quadrature_get_rule(type_name, max_points, npoint, xi, weight, ierr) + character(len=*), intent(in) :: type_name + integer, intent(in) :: max_points + integer, intent(out) :: npoint + real(rk), intent(out) :: xi(NDIM,max_points) + real(rk), intent(out) :: weight(max_points) + integer, intent(out) :: ierr + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + npoint = element_num_integration_points(etype) + if (npoint .le. 0) then + call error_set(FEM_ERR_MESH, 'unsupported element type for quadrature', ierr) + return + end if + if (max_points .lt. npoint) then + call error_set(FEM_ERR_INTERNAL, 'quadrature output arrays are too small', ierr) + return + end if + + xi = ZERO + weight = ZERO + + select case (trim(etype)) + case ('C3D4') + call tetra1_rule(npoint, xi, weight) + case ('C3D8') + call hex2_rule(npoint, xi, weight) + case ('C3D10') + call tetra4_rule(npoint, xi, weight) + case ('C3D20') + call hex3_rule(npoint, xi, weight) + case ('S3') + call tri1_rule(npoint, xi, weight) + case ('S4') + call quad2_rule(npoint, xi, weight) + case ('S6') + call tri3_rule(npoint, xi, weight) + case ('S8') + call quad3_rule(npoint, xi, weight) + case default + call error_set(FEM_ERR_MESH, 'unsupported element type for quadrature', ierr) + return + end select + + ierr = FEM_SUCCESS + end subroutine quadrature_get_rule + + subroutine gauss_legendre_1d(order, points, weights, ierr) + integer, intent(in) :: order + real(rk), intent(out) :: points(order) + real(rk), intent(out) :: weights(order) + integer, intent(out) :: ierr + + select case (order) + case (1) + points(1) = ZERO + weights(1) = 2.0_rk + case (2) + points(1) = -ONE / sqrt(3.0_rk) + points(2) = ONE / sqrt(3.0_rk) + weights(1) = ONE + weights(2) = ONE + case (3) + points(1) = -sqrt(3.0_rk / 5.0_rk) + points(2) = ZERO + points(3) = sqrt(3.0_rk / 5.0_rk) + weights(1) = 5.0_rk / 9.0_rk + weights(2) = 8.0_rk / 9.0_rk + weights(3) = 5.0_rk / 9.0_rk + case default + call error_set(FEM_ERR_INTERNAL, 'unsupported 1D Gauss order', ierr) + return + end select + + ierr = FEM_SUCCESS + end subroutine gauss_legendre_1d + + subroutine tetra1_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + + xi(:,1) = (/ 0.25_rk, 0.25_rk, 0.25_rk /) + weight(1) = ONE / 6.0_rk + end subroutine tetra1_rule + + subroutine tetra4_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + real(rk) :: a + real(rk) :: b + + a = 0.5854101966249685_rk + b = 0.1381966011250105_rk + xi(:,1) = (/ a, b, b /) + xi(:,2) = (/ b, a, b /) + xi(:,3) = (/ b, b, a /) + xi(:,4) = (/ b, b, b /) + weight(1:4) = ONE / 24.0_rk + end subroutine tetra4_rule + + subroutine tri1_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + + xi(:,1) = (/ ONE / 3.0_rk, ONE / 3.0_rk, ZERO /) + weight(1) = HALF + end subroutine tri1_rule + + subroutine tri3_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + + xi(:,1) = (/ ONE / 6.0_rk, ONE / 6.0_rk, ZERO /) + xi(:,2) = (/ 2.0_rk / 3.0_rk, ONE / 6.0_rk, ZERO /) + xi(:,3) = (/ ONE / 6.0_rk, 2.0_rk / 3.0_rk, ZERO /) + weight(1:3) = ONE / 6.0_rk + end subroutine tri3_rule + + subroutine quad2_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + real(rk) :: gp(2) + real(rk) :: gw(2) + integer :: ierr + + call gauss_legendre_1d(2, gp, gw, ierr) + call tensor2_rule(2, gp, gw, npoint, xi, weight) + end subroutine quad2_rule + + subroutine quad3_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + real(rk) :: gp(3) + real(rk) :: gw(3) + integer :: ierr + + call gauss_legendre_1d(3, gp, gw, ierr) + call tensor2_rule(3, gp, gw, npoint, xi, weight) + end subroutine quad3_rule + + subroutine hex2_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + real(rk) :: gp(2) + real(rk) :: gw(2) + integer :: ierr + + call gauss_legendre_1d(2, gp, gw, ierr) + call tensor3_rule(2, gp, gw, npoint, xi, weight) + end subroutine hex2_rule + + subroutine hex3_rule(npoint, xi, weight) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + real(rk) :: gp(3) + real(rk) :: gw(3) + integer :: ierr + + call gauss_legendre_1d(3, gp, gw, ierr) + call tensor3_rule(3, gp, gw, npoint, xi, weight) + end subroutine hex3_rule + + subroutine tensor2_rule(order, gp, gw, npoint, xi, weight) + integer, intent(in) :: order + real(rk), intent(in) :: gp(order) + real(rk), intent(in) :: gw(order) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + integer :: i + integer :: j + integer :: point + + point = 0 + do i = 1, order + do j = 1, order + point = point + 1 + xi(:,point) = (/ gp(i), gp(j), ZERO /) + weight(point) = gw(i) * gw(j) + end do + end do + end subroutine tensor2_rule + + subroutine tensor3_rule(order, gp, gw, npoint, xi, weight) + integer, intent(in) :: order + real(rk), intent(in) :: gp(order) + real(rk), intent(in) :: gw(order) + integer, intent(in) :: npoint + real(rk), intent(out) :: xi(NDIM,npoint) + real(rk), intent(out) :: weight(npoint) + integer :: i + integer :: j + integer :: k + integer :: point + + point = 0 + do i = 1, order + do j = 1, order + do k = 1, order + point = point + 1 + xi(:,point) = (/ gp(i), gp(j), gp(k) /) + weight(point) = gw(i) * gw(j) * gw(k) + end do + end do + end do + end subroutine tensor3_rule + +end module fem_quadrature diff --git a/src/element/fem_shape_functions.f90 b/src/element/fem_shape_functions.f90 new file mode 100644 index 0000000..5aee21b --- /dev/null +++ b/src/element/fem_shape_functions.f90 @@ -0,0 +1,419 @@ +module fem_shape_functions + use fem_precision + use fem_error + implicit none + + private + + public :: shape_evaluate + +contains + + subroutine shape_evaluate(type_name, natural, nshape, dndr, ierr) + character(len=*), intent(in) :: type_name + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + integer, intent(out) :: ierr + character(len=ELEM_TYPE_LEN) :: etype + + etype = adjustl(type_name) + nshape = ZERO + dndr = ZERO + + select case (trim(etype)) + case ('C3D4') + call shape_c3d4(natural, nshape, dndr) + case ('C3D8') + call shape_c3d8(natural, nshape, dndr) + case ('C3D10') + call shape_c3d10(natural, nshape, dndr) + case ('C3D20') + call shape_c3d20(natural, nshape, dndr) + case ('S3') + call shape_s3(natural, nshape, dndr) + case ('S4') + call shape_s4(natural, nshape, dndr) + case ('S6') + call shape_s6(natural, nshape, dndr) + case ('S8') + call shape_s8(natural, nshape, dndr) + case default + call error_set(FEM_ERR_MESH, 'unsupported element type for shape function', ierr) + return + end select + + ierr = FEM_SUCCESS + end subroutine shape_evaluate + + subroutine shape_c3d4(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: r + real(rk) :: s + real(rk) :: t + + r = natural(1) + s = natural(2) + t = natural(3) + + nshape(1) = ONE - r - s - t + nshape(2) = r + nshape(3) = s + nshape(4) = t + + dndr(:,1) = (/ -ONE, -ONE, -ONE /) + dndr(:,2) = (/ ONE, ZERO, ZERO /) + dndr(:,3) = (/ ZERO, ONE, ZERO /) + dndr(:,4) = (/ ZERO, ZERO, ONE /) + end subroutine shape_c3d4 + + subroutine shape_c3d8(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: xi_node(8) + real(rk) :: eta_node(8) + real(rk) :: zeta_node(8) + real(rk) :: r + real(rk) :: s + real(rk) :: t + integer :: i + + r = natural(1) + s = natural(2) + t = natural(3) + call hex8_natural_coords(xi_node, eta_node, zeta_node) + + do i = 1, 8 + nshape(i) = 0.125_rk * (ONE + r * xi_node(i)) * & + (ONE + s * eta_node(i)) * (ONE + t * zeta_node(i)) + dndr(1,i) = 0.125_rk * xi_node(i) * & + (ONE + s * eta_node(i)) * (ONE + t * zeta_node(i)) + dndr(2,i) = 0.125_rk * eta_node(i) * & + (ONE + r * xi_node(i)) * (ONE + t * zeta_node(i)) + dndr(3,i) = 0.125_rk * zeta_node(i) * & + (ONE + r * xi_node(i)) * (ONE + s * eta_node(i)) + end do + end subroutine shape_c3d8 + + subroutine shape_c3d10(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: lval(4) + real(rk) :: dl(NDIM,4) + + call tet_barycentric(natural, lval, dl) + call tet10_from_barycentric(lval, dl, nshape, dndr) + end subroutine shape_c3d10 + + subroutine shape_c3d20(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: r + real(rk) :: s + real(rk) :: t + + r = natural(1) + s = natural(2) + t = natural(3) + + call hex20_corner(1, -ONE, -ONE, -ONE, r, s, t, nshape, dndr) + call hex20_corner(2, ONE, -ONE, -ONE, r, s, t, nshape, dndr) + call hex20_corner(3, ONE, ONE, -ONE, r, s, t, nshape, dndr) + call hex20_corner(4, -ONE, ONE, -ONE, r, s, t, nshape, dndr) + call hex20_corner(5, -ONE, -ONE, ONE, r, s, t, nshape, dndr) + call hex20_corner(6, ONE, -ONE, ONE, r, s, t, nshape, dndr) + call hex20_corner(7, ONE, ONE, ONE, r, s, t, nshape, dndr) + call hex20_corner(8, -ONE, ONE, ONE, r, s, t, nshape, dndr) + + call hex20_edge_xi(9, -ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_eta(10, ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_xi(11, ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_eta(12, -ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_xi(13, -ONE, ONE, r, s, t, nshape, dndr) + call hex20_edge_eta(14, ONE, ONE, r, s, t, nshape, dndr) + call hex20_edge_xi(15, ONE, ONE, r, s, t, nshape, dndr) + call hex20_edge_eta(16, -ONE, ONE, r, s, t, nshape, dndr) + call hex20_edge_zeta(17, -ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_zeta(18, ONE, -ONE, r, s, t, nshape, dndr) + call hex20_edge_zeta(19, ONE, ONE, r, s, t, nshape, dndr) + call hex20_edge_zeta(20, -ONE, ONE, r, s, t, nshape, dndr) + end subroutine shape_c3d20 + + subroutine shape_s3(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: r + real(rk) :: s + + r = natural(1) + s = natural(2) + nshape(1) = ONE - r - s + nshape(2) = r + nshape(3) = s + dndr(:,1) = (/ -ONE, -ONE, ZERO /) + dndr(:,2) = (/ ONE, ZERO, ZERO /) + dndr(:,3) = (/ ZERO, ONE, ZERO /) + end subroutine shape_s3 + + subroutine shape_s4(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: r + real(rk) :: s + + r = natural(1) + s = natural(2) + + nshape(1) = 0.25_rk * (ONE - r) * (ONE - s) + nshape(2) = 0.25_rk * (ONE + r) * (ONE - s) + nshape(3) = 0.25_rk * (ONE + r) * (ONE + s) + nshape(4) = 0.25_rk * (ONE - r) * (ONE + s) + + dndr(1,1) = -0.25_rk * (ONE - s) + dndr(1,2) = 0.25_rk * (ONE - s) + dndr(1,3) = 0.25_rk * (ONE + s) + dndr(1,4) = -0.25_rk * (ONE + s) + dndr(2,1) = -0.25_rk * (ONE - r) + dndr(2,2) = -0.25_rk * (ONE + r) + dndr(2,3) = 0.25_rk * (ONE + r) + dndr(2,4) = 0.25_rk * (ONE - r) + end subroutine shape_s4 + + subroutine shape_s6(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: lval(3) + real(rk) :: dl(NDIM,3) + + call tri_barycentric(natural, lval, dl) + call tri6_from_barycentric(lval, dl, nshape, dndr) + end subroutine shape_s6 + + subroutine shape_s8(natural, nshape, dndr) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + real(rk) :: r + real(rk) :: s + + r = natural(1) + s = natural(2) + + nshape(1) = 0.25_rk * (ONE - r) * (ONE - s) * (-r - s - ONE) + nshape(2) = 0.25_rk * (ONE + r) * (ONE - s) * ( r - s - ONE) + nshape(3) = 0.25_rk * (ONE + r) * (ONE + s) * ( r + s - ONE) + nshape(4) = 0.25_rk * (ONE - r) * (ONE + s) * (-r + s - ONE) + nshape(5) = HALF * (ONE - r * r) * (ONE - s) + nshape(6) = HALF * (ONE + r) * (ONE - s * s) + nshape(7) = HALF * (ONE - r * r) * (ONE + s) + nshape(8) = HALF * (ONE - r) * (ONE - s * s) + + dndr(1,1) = 0.25_rk * (ONE - s) * (2.0_rk * r + s) + dndr(2,1) = 0.25_rk * (ONE - r) * (r + 2.0_rk * s) + dndr(1,2) = 0.25_rk * (ONE - s) * (2.0_rk * r - s) + dndr(2,2) = 0.25_rk * (ONE + r) * (-r + 2.0_rk * s) + dndr(1,3) = 0.25_rk * (ONE + s) * (2.0_rk * r + s) + dndr(2,3) = 0.25_rk * (ONE + r) * (r + 2.0_rk * s) + dndr(1,4) = 0.25_rk * (ONE + s) * (2.0_rk * r - s) + dndr(2,4) = 0.25_rk * (ONE - r) * (-r + 2.0_rk * s) + dndr(1,5) = -r * (ONE - s) + dndr(2,5) = -HALF * (ONE - r * r) + dndr(1,6) = HALF * (ONE - s * s) + dndr(2,6) = -(ONE + r) * s + dndr(1,7) = -r * (ONE + s) + dndr(2,7) = HALF * (ONE - r * r) + dndr(1,8) = -HALF * (ONE - s * s) + dndr(2,8) = -(ONE - r) * s + end subroutine shape_s8 + + subroutine tet_barycentric(natural, lval, dl) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: lval(4) + real(rk), intent(out) :: dl(NDIM,4) + + lval(1) = ONE - natural(1) - natural(2) - natural(3) + lval(2) = natural(1) + lval(3) = natural(2) + lval(4) = natural(3) + dl(:,1) = (/ -ONE, -ONE, -ONE /) + dl(:,2) = (/ ONE, ZERO, ZERO /) + dl(:,3) = (/ ZERO, ONE, ZERO /) + dl(:,4) = (/ ZERO, ZERO, ONE /) + end subroutine tet_barycentric + + subroutine tri_barycentric(natural, lval, dl) + real(rk), intent(in) :: natural(NDIM) + real(rk), intent(out) :: lval(3) + real(rk), intent(out) :: dl(NDIM,3) + + lval(1) = ONE - natural(1) - natural(2) + lval(2) = natural(1) + lval(3) = natural(2) + dl(:,1) = (/ -ONE, -ONE, ZERO /) + dl(:,2) = (/ ONE, ZERO, ZERO /) + dl(:,3) = (/ ZERO, ONE, ZERO /) + end subroutine tri_barycentric + + subroutine tet10_from_barycentric(lval, dl, nshape, dndr) + real(rk), intent(in) :: lval(4) + real(rk), intent(in) :: dl(NDIM,4) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + + call quadratic_corner(1, 1, lval, dl, nshape, dndr) + call quadratic_corner(2, 2, lval, dl, nshape, dndr) + call quadratic_corner(3, 3, lval, dl, nshape, dndr) + call quadratic_corner(4, 4, lval, dl, nshape, dndr) + call quadratic_edge(5, 1, 2, lval, dl, nshape, dndr) + call quadratic_edge(6, 2, 3, lval, dl, nshape, dndr) + call quadratic_edge(7, 3, 1, lval, dl, nshape, dndr) + call quadratic_edge(8, 1, 4, lval, dl, nshape, dndr) + call quadratic_edge(9, 2, 4, lval, dl, nshape, dndr) + call quadratic_edge(10, 3, 4, lval, dl, nshape, dndr) + end subroutine tet10_from_barycentric + + subroutine tri6_from_barycentric(lval, dl, nshape, dndr) + real(rk), intent(in) :: lval(3) + real(rk), intent(in) :: dl(NDIM,3) + real(rk), intent(out) :: nshape(MAX_NEN) + real(rk), intent(out) :: dndr(NDIM,MAX_NEN) + + call quadratic_corner(1, 1, lval, dl, nshape, dndr) + call quadratic_corner(2, 2, lval, dl, nshape, dndr) + call quadratic_corner(3, 3, lval, dl, nshape, dndr) + call quadratic_edge(4, 1, 2, lval, dl, nshape, dndr) + call quadratic_edge(5, 2, 3, lval, dl, nshape, dndr) + call quadratic_edge(6, 3, 1, lval, dl, nshape, dndr) + end subroutine tri6_from_barycentric + + subroutine quadratic_corner(node, lidx, lval, dl, nshape, dndr) + integer, intent(in) :: node + integer, intent(in) :: lidx + real(rk), intent(in) :: lval(:) + real(rk), intent(in) :: dl(:,:) + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + + nshape(node) = lval(lidx) * (2.0_rk * lval(lidx) - ONE) + dndr(:,node) = (4.0_rk * lval(lidx) - ONE) * dl(:,lidx) + end subroutine quadratic_corner + + subroutine quadratic_edge(node, lidx, jidx, lval, dl, nshape, dndr) + integer, intent(in) :: node + integer, intent(in) :: lidx + integer, intent(in) :: jidx + real(rk), intent(in) :: lval(:) + real(rk), intent(in) :: dl(:,:) + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + + nshape(node) = 4.0_rk * lval(lidx) * lval(jidx) + dndr(:,node) = 4.0_rk * (lval(lidx) * dl(:,jidx) + & + lval(jidx) * dl(:,lidx)) + end subroutine quadratic_edge + + subroutine hex20_corner(node, xi, eta, zeta, r, s, t, nshape, dndr) + integer, intent(in) :: node + real(rk), intent(in) :: xi + real(rk), intent(in) :: eta + real(rk), intent(in) :: zeta + real(rk), intent(in) :: r + real(rk), intent(in) :: s + real(rk), intent(in) :: t + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + real(rk) :: ar + real(rk) :: bs + real(rk) :: ct + real(rk) :: q + + ar = ONE + xi * r + bs = ONE + eta * s + ct = ONE + zeta * t + q = xi * r + eta * s + zeta * t - 2.0_rk + + nshape(node) = 0.125_rk * ar * bs * ct * q + dndr(1,node) = 0.125_rk * xi * bs * ct * (q + ar) + dndr(2,node) = 0.125_rk * eta * ar * ct * (q + bs) + dndr(3,node) = 0.125_rk * zeta * ar * bs * (q + ct) + end subroutine hex20_corner + + subroutine hex20_edge_xi(node, eta, zeta, r, s, t, nshape, dndr) + integer, intent(in) :: node + real(rk), intent(in) :: eta + real(rk), intent(in) :: zeta + real(rk), intent(in) :: r + real(rk), intent(in) :: s + real(rk), intent(in) :: t + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + real(rk) :: bs + real(rk) :: ct + + bs = ONE + eta * s + ct = ONE + zeta * t + nshape(node) = 0.25_rk * (ONE - r * r) * bs * ct + dndr(1,node) = -HALF * r * bs * ct + dndr(2,node) = 0.25_rk * (ONE - r * r) * eta * ct + dndr(3,node) = 0.25_rk * (ONE - r * r) * bs * zeta + end subroutine hex20_edge_xi + + subroutine hex20_edge_eta(node, xi, zeta, r, s, t, nshape, dndr) + integer, intent(in) :: node + real(rk), intent(in) :: xi + real(rk), intent(in) :: zeta + real(rk), intent(in) :: r + real(rk), intent(in) :: s + real(rk), intent(in) :: t + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + real(rk) :: ar + real(rk) :: ct + + ar = ONE + xi * r + ct = ONE + zeta * t + nshape(node) = 0.25_rk * ar * (ONE - s * s) * ct + dndr(1,node) = 0.25_rk * xi * (ONE - s * s) * ct + dndr(2,node) = -HALF * ar * s * ct + dndr(3,node) = 0.25_rk * ar * (ONE - s * s) * zeta + end subroutine hex20_edge_eta + + subroutine hex20_edge_zeta(node, xi, eta, r, s, t, nshape, dndr) + integer, intent(in) :: node + real(rk), intent(in) :: xi + real(rk), intent(in) :: eta + real(rk), intent(in) :: r + real(rk), intent(in) :: s + real(rk), intent(in) :: t + real(rk), intent(inout) :: nshape(MAX_NEN) + real(rk), intent(inout) :: dndr(NDIM,MAX_NEN) + real(rk) :: ar + real(rk) :: bs + + ar = ONE + xi * r + bs = ONE + eta * s + nshape(node) = 0.25_rk * ar * bs * (ONE - t * t) + dndr(1,node) = 0.25_rk * xi * bs * (ONE - t * t) + dndr(2,node) = 0.25_rk * ar * eta * (ONE - t * t) + dndr(3,node) = -HALF * ar * bs * t + end subroutine hex20_edge_zeta + + subroutine hex8_natural_coords(xi, eta, zeta) + real(rk), intent(out) :: xi(8) + real(rk), intent(out) :: eta(8) + real(rk), intent(out) :: zeta(8) + + xi = (/ -ONE, ONE, ONE, -ONE, -ONE, ONE, ONE, -ONE /) + eta = (/ -ONE, -ONE, ONE, ONE, -ONE, -ONE, ONE, ONE /) + zeta = (/ -ONE, -ONE, -ONE, -ONE, ONE, ONE, ONE, ONE /) + end subroutine hex8_natural_coords + +end module fem_shape_functions diff --git a/tests/module/test_element_infrastructure.f90 b/tests/module/test_element_infrastructure.f90 new file mode 100644 index 0000000..b27a640 --- /dev/null +++ b/tests/module/test_element_infrastructure.f90 @@ -0,0 +1,249 @@ +program test_element_infrastructure + use fem_precision + use fem_error + use fem_element_topology + use fem_quadrature + use fem_shape_functions + implicit none + + real(rk), parameter :: TOL = 1.0e-10_rk + + call test_topology() + call test_quadrature() + call test_shapes() + +contains + + subroutine test_topology() + integer :: ierr + integer :: nface + integer :: nfn + integer :: face_nodes(MAX_FACE_NODES) + + if (element_num_nodes('C3D4') .ne. 4) stop 1 + if (element_num_nodes('C3D8') .ne. 8) stop 2 + if (element_num_nodes('C3D10') .ne. 10) stop 3 + if (element_num_nodes('C3D20') .ne. 20) stop 4 + if (element_num_nodes('S3') .ne. 3) stop 5 + if (element_num_nodes('S4') .ne. 4) stop 6 + if (element_num_nodes('S6') .ne. 6) stop 7 + if (element_num_nodes('S8') .ne. 8) stop 8 + if (element_num_nodes('UNKNOWN') .ne. 0) stop 9 + + if (.not. element_is_solid('C3D20')) stop 10 + if (.not. element_is_shell('S8')) stop 11 + if (element_is_supported('B31')) stop 12 + + if (element_num_faces('C3D4') .ne. 4) stop 13 + if (element_num_faces('C3D8') .ne. 6) stop 14 + if (element_num_faces('C3D10') .ne. 4) stop 15 + if (element_num_faces('C3D20') .ne. 6) stop 16 + if (element_num_faces('S4') .ne. 1) stop 17 + + if (element_num_integration_points('C3D4') .ne. 1) stop 18 + if (element_num_integration_points('C3D8') .ne. 8) stop 19 + if (element_num_integration_points('C3D10') .ne. 4) stop 20 + if (element_num_integration_points('C3D20') .ne. 27) stop 21 + if (element_num_integration_points('S3') .ne. 1) stop 22 + if (element_num_integration_points('S4') .ne. 4) stop 23 + if (element_num_integration_points('S6') .ne. 3) stop 24 + if (element_num_integration_points('S8') .ne. 9) stop 25 + + call element_validate_node_count('C3D8', 8, ierr) + if (ierr .ne. FEM_SUCCESS) stop 26 + call element_validate_node_count('C3D8', 4, ierr) + if (ierr .eq. FEM_SUCCESS) stop 27 + + call element_face_nodes('C3D20', 6, nfn, face_nodes, ierr) + if (ierr .ne. FEM_SUCCESS) stop 28 + if (nfn .ne. 8) stop 29 + if (face_nodes(1) .ne. 4) stop 30 + if (face_nodes(8) .ne. 20) stop 31 + + call element_face_nodes('S6', 1, nfn, face_nodes, ierr) + if (ierr .ne. FEM_SUCCESS) stop 32 + if (nfn .ne. 6) stop 33 + if (face_nodes(6) .ne. 6) stop 34 + + nface = element_num_faces('S8') + if (nface .ne. 1) stop 35 + end subroutine test_topology + + subroutine test_quadrature() + call check_rule('C3D4', 1, ONE / 6.0_rk, 101) + call check_rule('C3D8', 8, 8.0_rk, 110) + call check_rule('C3D10', 4, ONE / 6.0_rk, 120) + call check_rule('C3D20', 27, 8.0_rk, 130) + call check_rule('S3', 1, HALF, 140) + call check_rule('S4', 4, 4.0_rk, 150) + call check_rule('S6', 3, HALF, 160) + call check_rule('S8', 9, 4.0_rk, 170) + end subroutine test_quadrature + + subroutine check_rule(etype, expected_points, expected_weight, stop_base) + character(len=*), intent(in) :: etype + integer, intent(in) :: expected_points + real(rk), intent(in) :: expected_weight + integer, intent(in) :: stop_base + integer :: ierr + integer :: npoint + real(rk) :: xi(NDIM,32) + real(rk) :: weight(32) + + call quadrature_get_count(etype, npoint, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(stop_base) + if (npoint .ne. expected_points) call fail(stop_base + 1) + + call quadrature_get_rule(etype, 32, npoint, xi, weight, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(stop_base + 2) + if (npoint .ne. expected_points) call fail(stop_base + 3) + if (abs(sum(weight(1:npoint)) - expected_weight) .gt. TOL) call fail(stop_base + 4) + end subroutine check_rule + + subroutine test_shapes() + call check_shape('C3D4', 4, 201) + call check_shape('C3D8', 8, 220) + call check_shape('C3D10', 10, 240) + call check_shape('C3D20', 20, 260) + call check_shape('S3', 3, 300) + call check_shape('S4', 4, 320) + call check_shape('S6', 6, 340) + call check_shape('S8', 8, 360) + end subroutine test_shapes + + subroutine check_shape(etype, nnode, stop_base) + character(len=*), intent(in) :: etype + integer, intent(in) :: nnode + integer, intent(in) :: stop_base + integer :: ierr + integer :: node + real(rk) :: node_nat(NDIM,MAX_NEN) + real(rk) :: natural(NDIM) + real(rk) :: nshape(MAX_NEN) + real(rk) :: dndr(NDIM,MAX_NEN) + + call fill_node_natural(etype, node_nat) + call sample_natural(etype, natural) + call shape_evaluate(etype, natural, nshape, dndr, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(stop_base) + if (abs(sum(nshape(1:nnode)) - ONE) .gt. TOL) call fail(stop_base + 1) + if (maxval(abs(sum(dndr(:,1:nnode), dim=2))) .gt. TOL) call fail(stop_base + 2) + + do node = 1, nnode + call shape_evaluate(etype, node_nat(:,node), nshape, dndr, ierr) + if (ierr .ne. FEM_SUCCESS) call fail(stop_base + 3) + if (abs(nshape(node) - ONE) .gt. TOL) call fail(stop_base + 4) + nshape(node) = nshape(node) - ONE + if (maxval(abs(nshape(1:nnode))) .gt. TOL) call fail(stop_base + 5) + end do + end subroutine check_shape + + subroutine sample_natural(etype, natural) + character(len=*), intent(in) :: etype + real(rk), intent(out) :: natural(NDIM) + + natural = ZERO + select case (trim(etype)) + case ('C3D4', 'C3D10') + natural = (/ 0.20_rk, 0.30_rk, 0.10_rk /) + case ('S3', 'S6') + natural = (/ 0.20_rk, 0.30_rk, ZERO /) + case default + natural = (/ 0.20_rk, -0.30_rk, 0.40_rk /) + if (trim(etype) .eq. 'S4' .or. trim(etype) .eq. 'S8') natural(3) = ZERO + end select + end subroutine sample_natural + + subroutine fill_node_natural(etype, node_nat) + character(len=*), intent(in) :: etype + real(rk), intent(out) :: node_nat(NDIM,MAX_NEN) + + node_nat = ZERO + select case (trim(etype)) + case ('C3D4') + node_nat(:,1) = (/ ZERO, ZERO, ZERO /) + node_nat(:,2) = (/ ONE, ZERO, ZERO /) + node_nat(:,3) = (/ ZERO, ONE, ZERO /) + node_nat(:,4) = (/ ZERO, ZERO, ONE /) + case ('C3D8') + call fill_hex8_nodes(node_nat) + case ('C3D10') + node_nat(:,1) = (/ ZERO, ZERO, ZERO /) + node_nat(:,2) = (/ ONE, ZERO, ZERO /) + node_nat(:,3) = (/ ZERO, ONE, ZERO /) + node_nat(:,4) = (/ ZERO, ZERO, ONE /) + node_nat(:,5) = (/ HALF, ZERO, ZERO /) + node_nat(:,6) = (/ HALF, HALF, ZERO /) + node_nat(:,7) = (/ ZERO, HALF, ZERO /) + node_nat(:,8) = (/ ZERO, ZERO, HALF /) + node_nat(:,9) = (/ HALF, ZERO, HALF /) + node_nat(:,10) = (/ ZERO, HALF, HALF /) + case ('C3D20') + call fill_hex20_nodes(node_nat) + case ('S3') + node_nat(:,1) = (/ ZERO, ZERO, ZERO /) + node_nat(:,2) = (/ ONE, ZERO, ZERO /) + node_nat(:,3) = (/ ZERO, ONE, ZERO /) + case ('S4') + node_nat(:,1) = (/ -ONE, -ONE, ZERO /) + node_nat(:,2) = (/ ONE, -ONE, ZERO /) + node_nat(:,3) = (/ ONE, ONE, ZERO /) + node_nat(:,4) = (/ -ONE, ONE, ZERO /) + case ('S6') + node_nat(:,1) = (/ ZERO, ZERO, ZERO /) + node_nat(:,2) = (/ ONE, ZERO, ZERO /) + node_nat(:,3) = (/ ZERO, ONE, ZERO /) + node_nat(:,4) = (/ HALF, ZERO, ZERO /) + node_nat(:,5) = (/ HALF, HALF, ZERO /) + node_nat(:,6) = (/ ZERO, HALF, ZERO /) + case ('S8') + node_nat(:,1) = (/ -ONE, -ONE, ZERO /) + node_nat(:,2) = (/ ONE, -ONE, ZERO /) + node_nat(:,3) = (/ ONE, ONE, ZERO /) + node_nat(:,4) = (/ -ONE, ONE, ZERO /) + node_nat(:,5) = (/ ZERO, -ONE, ZERO /) + node_nat(:,6) = (/ ONE, ZERO, ZERO /) + node_nat(:,7) = (/ ZERO, ONE, ZERO /) + node_nat(:,8) = (/ -ONE, ZERO, ZERO /) + end select + end subroutine fill_node_natural + + subroutine fill_hex8_nodes(node_nat) + real(rk), intent(inout) :: node_nat(NDIM,MAX_NEN) + + node_nat(:,1) = (/ -ONE, -ONE, -ONE /) + node_nat(:,2) = (/ ONE, -ONE, -ONE /) + node_nat(:,3) = (/ ONE, ONE, -ONE /) + node_nat(:,4) = (/ -ONE, ONE, -ONE /) + node_nat(:,5) = (/ -ONE, -ONE, ONE /) + node_nat(:,6) = (/ ONE, -ONE, ONE /) + node_nat(:,7) = (/ ONE, ONE, ONE /) + node_nat(:,8) = (/ -ONE, ONE, ONE /) + end subroutine fill_hex8_nodes + + subroutine fill_hex20_nodes(node_nat) + real(rk), intent(inout) :: node_nat(NDIM,MAX_NEN) + + call fill_hex8_nodes(node_nat) + node_nat(:,9) = (/ ZERO, -ONE, -ONE /) + node_nat(:,10) = (/ ONE, ZERO, -ONE /) + node_nat(:,11) = (/ ZERO, ONE, -ONE /) + node_nat(:,12) = (/ -ONE, ZERO, -ONE /) + node_nat(:,13) = (/ ZERO, -ONE, ONE /) + node_nat(:,14) = (/ ONE, ZERO, ONE /) + node_nat(:,15) = (/ ZERO, ONE, ONE /) + node_nat(:,16) = (/ -ONE, ZERO, ONE /) + node_nat(:,17) = (/ -ONE, -ONE, ZERO /) + node_nat(:,18) = (/ ONE, -ONE, ZERO /) + node_nat(:,19) = (/ ONE, ONE, ZERO /) + node_nat(:,20) = (/ -ONE, ONE, ZERO /) + end subroutine fill_hex20_nodes + + subroutine fail(code) + integer, intent(in) :: code + + write(*,*) 'test_element_infrastructure failed:', code + stop 1 + end subroutine fail + +end program test_element_infrastructure