Files
FemLite/tests/module/test_facet_topology.f90

180 lines
5.5 KiB
Fortran

program test_facet_topology
use fem_precision
use fem_error
use fem_database
use fem_coupling
implicit none
real(rk), parameter :: TOL = 1.0e-10_rk
integer, parameter :: MAX_TEST_FACETS = 8
call check_c3d10()
call check_c3d20()
call check_s6()
call check_s8()
contains
subroutine check_c3d10()
integer :: ierr
call database_allocate_mesh(10, 1, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(1)
call fill_tet10()
call check_facets(4, 6, 1.5_rk + sqrt(3.0_rk) * HALF, 10)
end subroutine check_c3d10
subroutine check_c3d20()
integer :: ierr
call database_allocate_mesh(20, 1, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(20)
call fill_hex20()
call check_facets(6, 8, 6.0_rk, 30)
end subroutine check_c3d20
subroutine check_s6()
integer :: ierr
call database_allocate_mesh(6, 1, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(40)
call fill_tri6()
call check_facets(1, 6, HALF, 50)
end subroutine check_s6
subroutine check_s8()
integer :: ierr
call database_allocate_mesh(8, 1, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(60)
call fill_quad8()
call check_facets(1, 8, ONE, 70)
end subroutine check_s8
subroutine check_facets(expected_count, expected_max_nodes, expected_area, code)
integer, intent(in) :: expected_count
integer, intent(in) :: expected_max_nodes
real(rk), intent(in) :: expected_area
integer, intent(in) :: code
integer :: ierr
integer :: nfacet
integer :: max_nodes
integer :: facet_id(MAX_TEST_FACETS)
integer :: elem_id(MAX_TEST_FACETS)
integer :: face_id(MAX_TEST_FACETS)
integer :: facet_nnode(MAX_TEST_FACETS)
integer :: facet_conn(MAX_FACE_NODES,MAX_TEST_FACETS)
real(rk) :: x(NDIM,MAX_FACE_NODES,MAX_TEST_FACETS)
real(rk) :: vnod(NDIM,MAX_FACE_NODES,MAX_TEST_FACETS)
real(rk) :: normal(NDIM,MAX_TEST_FACETS)
real(rk) :: area(MAX_TEST_FACETS)
call database_assign_dofs(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code)
call cpl_build_facets(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 1)
call cpl_get_facet_count(nfacet, max_nodes, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 2)
if (nfacet .ne. expected_count) call fail(code + 3)
if (max_nodes .ne. expected_max_nodes) call fail(code + 4)
call cpl_get_facets(MAX_TEST_FACETS, MAX_FACE_NODES, facet_id, elem_id, &
face_id, facet_nnode, facet_conn, x, vnod, normal, &
area, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 5)
if (abs(sum(area(1:nfacet)) - expected_area) .gt. TOL) call fail(code + 6)
call cpl_finalize_facets()
call database_finalize(ierr)
if (ierr .ne. FEM_SUCCESS) call fail(code + 7)
end subroutine check_facets
subroutine fill_tet10()
call set_common_element('C3D10', 10)
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ZERO, ONE, ZERO /)
coord0(:,4) = (/ ZERO, ZERO, ONE /)
coord0(:,5) = (/ HALF, ZERO, ZERO /)
coord0(:,6) = (/ HALF, HALF, ZERO /)
coord0(:,7) = (/ ZERO, HALF, ZERO /)
coord0(:,8) = (/ ZERO, ZERO, HALF /)
coord0(:,9) = (/ HALF, ZERO, HALF /)
coord0(:,10) = (/ ZERO, HALF, HALF /)
end subroutine fill_tet10
subroutine fill_hex20()
call set_common_element('C3D20', 20)
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ONE, ONE, ZERO /)
coord0(:,4) = (/ ZERO, ONE, ZERO /)
coord0(:,5) = (/ ZERO, ZERO, ONE /)
coord0(:,6) = (/ ONE, ZERO, ONE /)
coord0(:,7) = (/ ONE, ONE, ONE /)
coord0(:,8) = (/ ZERO, ONE, ONE /)
coord0(:,9) = (/ HALF, ZERO, ZERO /)
coord0(:,10) = (/ ONE, HALF, ZERO /)
coord0(:,11) = (/ HALF, ONE, ZERO /)
coord0(:,12) = (/ ZERO, HALF, ZERO /)
coord0(:,13) = (/ HALF, ZERO, ONE /)
coord0(:,14) = (/ ONE, HALF, ONE /)
coord0(:,15) = (/ HALF, ONE, ONE /)
coord0(:,16) = (/ ZERO, HALF, ONE /)
coord0(:,17) = (/ ZERO, ZERO, HALF /)
coord0(:,18) = (/ ONE, ZERO, HALF /)
coord0(:,19) = (/ ONE, ONE, HALF /)
coord0(:,20) = (/ ZERO, ONE, HALF /)
end subroutine fill_hex20
subroutine fill_tri6()
call set_common_element('S6', 6)
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ZERO, ONE, ZERO /)
coord0(:,4) = (/ HALF, ZERO, ZERO /)
coord0(:,5) = (/ HALF, HALF, ZERO /)
coord0(:,6) = (/ ZERO, HALF, ZERO /)
end subroutine fill_tri6
subroutine fill_quad8()
call set_common_element('S8', 8)
coord0(:,1) = (/ ZERO, ZERO, ZERO /)
coord0(:,2) = (/ ONE, ZERO, ZERO /)
coord0(:,3) = (/ ONE, ONE, ZERO /)
coord0(:,4) = (/ ZERO, ONE, ZERO /)
coord0(:,5) = (/ HALF, ZERO, ZERO /)
coord0(:,6) = (/ ONE, HALF, ZERO /)
coord0(:,7) = (/ HALF, ONE, ZERO /)
coord0(:,8) = (/ ZERO, HALF, ZERO /)
end subroutine fill_quad8
subroutine set_common_element(type_name, nlocal)
character(len=*), intent(in) :: type_name
integer, intent(in) :: nlocal
integer :: i
coord = ZERO
node_id_ext = 0
do i = 1, nnode
node_id_ext(i) = i
end do
elem_id_ext(1) = 1
elem_type(1) = type_name
elem_nnode(1) = nlocal
elem_conn(:,1) = 0
do i = 1, nlocal
elem_conn(i,1) = i
end do
elem_status(1) = 0
end subroutine set_common_element
subroutine fail(code)
integer, intent(in) :: code
write(*,*) 'test_facet_topology failed:', code
stop 1
end subroutine fail
end program test_facet_topology