program test_quadratic_mass use fem_precision use fem_error use fem_database use fem_element_mass implicit none real(rk), parameter :: TOL = 1.0e-10_rk call check_c3d10_mass() call check_c3d20_mass() contains subroutine check_c3d10_mass() integer :: ierr real(rk) :: total_mass real(rk) :: rot_mass real(rk) :: nodal_mass call setup_c3d10(ierr) if (ierr .ne. FEM_SUCCESS) call fail(1) call element_compute_lumped_mass(ierr) if (ierr .ne. FEM_SUCCESS) call fail(2) call collect_mass(total_mass, rot_mass) call check_close(total_mass, 10.0_rk, 3) call check_close(rot_mass, ZERO, 4) nodal_mass = 10.0_rk / 10.0_rk call check_close(mass_diag(dof_id(1,1)), nodal_mass, 5) call check_close(mass_diag(dof_id(2,5)), nodal_mass, 6) call check_close(mass_diag(dof_id(3,10)), nodal_mass, 7) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(8) end subroutine check_c3d10_mass subroutine check_c3d20_mass() integer :: ierr real(rk) :: total_mass real(rk) :: rot_mass real(rk) :: nodal_mass call setup_c3d20(ierr) if (ierr .ne. FEM_SUCCESS) call fail(20) call element_compute_lumped_mass(ierr) if (ierr .ne. FEM_SUCCESS) call fail(21) call collect_mass(total_mass, rot_mass) call check_close(total_mass, 40.0_rk, 22) call check_close(rot_mass, ZERO, 23) nodal_mass = 40.0_rk / 20.0_rk call check_close(mass_diag(dof_id(1,1)), nodal_mass, 24) call check_close(mass_diag(dof_id(2,9)), nodal_mass, 25) call check_close(mass_diag(dof_id(3,20)), nodal_mass, 26) call database_finalize(ierr) if (ierr .ne. FEM_SUCCESS) call fail(27) end subroutine check_c3d20_mass subroutine setup_c3d10(ierr) integer, intent(out) :: ierr call database_allocate_model(10, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_common_model('C3D10', 10, 60.0_rk) coord0(:,1) = (/ ZERO, ZERO, ZERO /) coord0(:,2) = (/ ONE, ZERO, ZERO /) coord0(:,3) = (/ ZERO, ONE, ZERO /) coord0(:,4) = (/ ZERO, ZERO, ONE /) coord0(:,5) = HALF * (coord0(:,1) + coord0(:,2)) coord0(:,6) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,7) = HALF * (coord0(:,3) + coord0(:,1)) coord0(:,8) = HALF * (coord0(:,1) + coord0(:,4)) coord0(:,9) = HALF * (coord0(:,2) + coord0(:,4)) coord0(:,10) = HALF * (coord0(:,3) + coord0(:,4)) coord = coord0 call database_assign_dofs(ierr) end subroutine setup_c3d10 subroutine setup_c3d20(ierr) integer, intent(out) :: ierr call database_allocate_model(20, 1, 0, 1, 0, 1, 1, 0, 1, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return call fill_common_model('C3D20', 20, 40.0_rk) 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 * (coord0(:,1) + coord0(:,2)) coord0(:,10) = HALF * (coord0(:,2) + coord0(:,3)) coord0(:,11) = HALF * (coord0(:,3) + coord0(:,4)) coord0(:,12) = HALF * (coord0(:,4) + coord0(:,1)) coord0(:,13) = HALF * (coord0(:,5) + coord0(:,6)) coord0(:,14) = HALF * (coord0(:,6) + coord0(:,7)) coord0(:,15) = HALF * (coord0(:,7) + coord0(:,8)) coord0(:,16) = HALF * (coord0(:,8) + coord0(:,5)) coord0(:,17) = HALF * (coord0(:,1) + coord0(:,5)) coord0(:,18) = HALF * (coord0(:,2) + coord0(:,6)) coord0(:,19) = HALF * (coord0(:,3) + coord0(:,7)) coord0(:,20) = HALF * (coord0(:,4) + coord0(:,8)) coord = coord0 call database_assign_dofs(ierr) end subroutine setup_c3d20 subroutine fill_common_model(etype, nlocal, density) character(len=*), intent(in) :: etype integer, intent(in) :: nlocal real(rk), intent(in) :: density 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) = density mat_e(1) = ONE mat_nu(1) = 0.25_rk section_type(1) = 'SOLID' section_elset_name(1) = 'EALL' section_material_name(1) = 'MAT' end subroutine fill_common_model subroutine collect_mass(total_mass, rot_mass) real(rk), intent(out) :: total_mass real(rk), intent(out) :: rot_mass integer :: node integer :: idir integer :: dof total_mass = ZERO rot_mass = ZERO do node = 1, nnode dof = dof_id(1,node) if (dof .gt. 0) total_mass = total_mass + mass_diag(dof) do idir = 4, NDOF_NODE dof = dof_id(idir,node) if (dof .gt. 0) rot_mass = rot_mass + mass_diag(dof) end do end do end subroutine collect_mass 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_quadratic_mass failed:', code stop 1 end subroutine fail end program test_quadratic_mass