Add quadratic solid internal force path
This commit is contained in:
@@ -151,6 +151,13 @@ add_executable(test_quadratic_mass
|
||||
target_link_libraries(test_quadratic_mass PRIVATE femlite_core)
|
||||
femlite_apply_fortran_options(test_quadratic_mass)
|
||||
|
||||
add_executable(test_quadratic_internal
|
||||
tests/module/test_quadratic_internal.f90
|
||||
)
|
||||
|
||||
target_link_libraries(test_quadratic_internal PRIVATE femlite_core)
|
||||
femlite_apply_fortran_options(test_quadratic_internal)
|
||||
|
||||
add_executable(test_solver_implicit
|
||||
tests/module/test_solver_implicit.f90
|
||||
)
|
||||
@@ -227,6 +234,11 @@ set_tests_properties(quadratic_mass PROPERTIES
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
add_test(NAME quadratic_internal COMMAND test_quadratic_internal)
|
||||
set_tests_properties(quadratic_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}"
|
||||
|
||||
@@ -40,6 +40,9 @@ contains
|
||||
case ('C3D8')
|
||||
call c3d8_internal_force(elem, dt_local, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
case ('C3D10', 'C3D20')
|
||||
call solid_quadratic_internal_force(elem, dt_local, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
case ('S4')
|
||||
call shell4_internal_force(elem, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
@@ -279,6 +282,115 @@ contains
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine c3d8_internal_force
|
||||
|
||||
subroutine solid_quadratic_internal_force(elem, dt, ierr)
|
||||
integer, intent(in) :: elem
|
||||
real(rk), intent(in) :: dt
|
||||
integer, intent(out) :: ierr
|
||||
integer, parameter :: MAX_QP = 32
|
||||
real(rk) :: gp_nat(NDIM,MAX_QP)
|
||||
real(rk) :: gp_weight(MAX_QP)
|
||||
real(rk) :: nshape(MAX_NEN)
|
||||
real(rk) :: dndr(NDIM,MAX_NEN)
|
||||
real(rk) :: dndx(NDIM,MAX_NEN)
|
||||
real(rk) :: detj
|
||||
real(rk) :: eps(NSTRESS)
|
||||
real(rk) :: deps(NSTRESS)
|
||||
real(rk) :: sig(NSTRESS)
|
||||
real(rk) :: state_old(NSTATEV_MAX)
|
||||
real(rk) :: state_new(NSTATEV_MAX)
|
||||
real(rk) :: stress_old(NSTRESS)
|
||||
real(rk) :: spin_current(3)
|
||||
real(rk) :: spin_inc(3)
|
||||
real(rk) :: local_force(NDIM,MAX_NEN)
|
||||
real(rk) :: factor
|
||||
integer :: q
|
||||
integer :: npoint
|
||||
integer :: nlocal
|
||||
integer :: local_node
|
||||
integer :: node
|
||||
integer :: gp
|
||||
integer :: gp_start
|
||||
integer :: failed_count
|
||||
integer :: dof
|
||||
|
||||
nlocal = elem_nnode(elem)
|
||||
call element_validate_node_count(elem_type(elem), nlocal, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
|
||||
call quadrature_get_rule(elem_type(elem), MAX_QP, npoint, gp_nat, gp_weight, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
|
||||
gp_start = elem_gp_start(elem)
|
||||
gp = gp_start
|
||||
failed_count = 0
|
||||
local_force = ZERO
|
||||
|
||||
do q = 1, npoint
|
||||
call shape_evaluate(elem_type(elem), gp_nat(:,q), nshape, dndr, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
call solid_shape_gradients(elem, nlocal, dndr, dndx, detj, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
|
||||
call solid_strain_from_dndx(elem, nlocal, dndx, eps)
|
||||
|
||||
deps = eps
|
||||
stress_old = ZERO
|
||||
state_old = ZERO
|
||||
if (gp .gt. 0) then
|
||||
deps = eps - strain(:,gp)
|
||||
stress_old = stress(:,gp)
|
||||
state_old = statev(:,gp)
|
||||
end if
|
||||
call solid_current_spin(elem, nlocal, dndx, spin_current)
|
||||
spin_inc = spin_current - state_old(14:16)
|
||||
|
||||
call material_update_small_strain_dt(elem_mat(elem), dt, deps, &
|
||||
state_old, stress_old, sig, &
|
||||
state_new, ierr, spin_inc)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
state_new(14:16) = spin_current
|
||||
|
||||
if (gp .gt. 0) then
|
||||
strain(:,gp) = eps
|
||||
stress(:,gp) = sig
|
||||
statev(:,gp) = state_new
|
||||
if (state_new(4) .ge. HALF) failed_count = failed_count + 1
|
||||
end if
|
||||
|
||||
factor = gp_weight(q) * detj
|
||||
do local_node = 1, nlocal
|
||||
local_force(1,local_node) = local_force(1,local_node) + factor * &
|
||||
(dndx(1,local_node) * sig(1) + dndx(2,local_node) * sig(4) + &
|
||||
dndx(3,local_node) * sig(5))
|
||||
local_force(2,local_node) = local_force(2,local_node) + factor * &
|
||||
(dndx(1,local_node) * sig(4) + dndx(2,local_node) * sig(2) + &
|
||||
dndx(3,local_node) * sig(6))
|
||||
local_force(3,local_node) = local_force(3,local_node) + factor * &
|
||||
(dndx(1,local_node) * sig(5) + dndx(2,local_node) * sig(6) + &
|
||||
dndx(3,local_node) * sig(3))
|
||||
end do
|
||||
|
||||
gp = gp + 1
|
||||
end do
|
||||
|
||||
if (should_delete_solid(elem_type(elem), failed_count, npoint)) then
|
||||
elem_status(elem) = 1
|
||||
if (gp_start .gt. 0) stress(:,gp_start:gp_start+npoint-1) = ZERO
|
||||
else
|
||||
do local_node = 1, nlocal
|
||||
node = elem_conn(local_node, elem)
|
||||
dof = dof_id(1,node)
|
||||
if (dof .gt. 0) fint(dof) = fint(dof) + local_force(1,local_node)
|
||||
dof = dof_id(2,node)
|
||||
if (dof .gt. 0) fint(dof) = fint(dof) + local_force(2,local_node)
|
||||
dof = dof_id(3,node)
|
||||
if (dof .gt. 0) fint(dof) = fint(dof) + local_force(3,local_node)
|
||||
end do
|
||||
end if
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine solid_quadratic_internal_force
|
||||
|
||||
subroutine shell4_internal_force(elem, ierr)
|
||||
integer, intent(in) :: elem
|
||||
integer, intent(out) :: ierr
|
||||
@@ -656,6 +768,91 @@ contains
|
||||
end do
|
||||
end subroutine shell4_add_global
|
||||
|
||||
subroutine solid_shape_gradients(elem, nlocal, dndr, dndx, detj, ierr)
|
||||
integer, intent(in) :: elem
|
||||
integer, intent(in) :: nlocal
|
||||
real(rk), intent(in) :: dndr(NDIM,MAX_NEN)
|
||||
real(rk), intent(out) :: dndx(NDIM,MAX_NEN)
|
||||
real(rk), intent(out) :: detj
|
||||
integer, intent(out) :: ierr
|
||||
real(rk) :: jac(NDIM,NDIM)
|
||||
real(rk) :: invj(NDIM,NDIM)
|
||||
integer :: local_node
|
||||
integer :: node
|
||||
integer :: i
|
||||
integer :: j
|
||||
integer :: k
|
||||
|
||||
jac = ZERO
|
||||
dndx = ZERO
|
||||
|
||||
do local_node = 1, nlocal
|
||||
node = elem_conn(local_node, elem)
|
||||
do i = 1, NDIM
|
||||
do j = 1, NDIM
|
||||
jac(i,j) = jac(i,j) + coord0(i,node) * dndr(j,local_node)
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
|
||||
call inverse3(jac, invj, detj, ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) return
|
||||
if (detj .le. ZERO) then
|
||||
call error_set(FEM_ERR_MESH, 'solid element has non-positive Jacobian', ierr)
|
||||
return
|
||||
end if
|
||||
|
||||
do local_node = 1, nlocal
|
||||
do i = 1, NDIM
|
||||
dndx(i,local_node) = ZERO
|
||||
do k = 1, NDIM
|
||||
dndx(i,local_node) = dndx(i,local_node) + invj(k,i) * dndr(k,local_node)
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
|
||||
ierr = FEM_SUCCESS
|
||||
end subroutine solid_shape_gradients
|
||||
|
||||
subroutine solid_strain_from_dndx(elem, nlocal, dndx, eps)
|
||||
integer, intent(in) :: elem
|
||||
integer, intent(in) :: nlocal
|
||||
real(rk), intent(in) :: dndx(NDIM,MAX_NEN)
|
||||
real(rk), intent(out) :: eps(NSTRESS)
|
||||
integer :: local_node
|
||||
integer :: node
|
||||
|
||||
eps = ZERO
|
||||
do local_node = 1, nlocal
|
||||
node = elem_conn(local_node, elem)
|
||||
eps(1) = eps(1) + dndx(1,local_node) * get_dof_value(u, 1, node)
|
||||
eps(2) = eps(2) + dndx(2,local_node) * get_dof_value(u, 2, node)
|
||||
eps(3) = eps(3) + dndx(3,local_node) * get_dof_value(u, 3, node)
|
||||
eps(4) = eps(4) + dndx(2,local_node) * get_dof_value(u, 1, node) + &
|
||||
dndx(1,local_node) * get_dof_value(u, 2, node)
|
||||
eps(5) = eps(5) + dndx(3,local_node) * get_dof_value(u, 1, node) + &
|
||||
dndx(1,local_node) * get_dof_value(u, 3, node)
|
||||
eps(6) = eps(6) + dndx(3,local_node) * get_dof_value(u, 2, node) + &
|
||||
dndx(2,local_node) * get_dof_value(u, 3, node)
|
||||
end do
|
||||
end subroutine solid_strain_from_dndx
|
||||
|
||||
logical function should_delete_solid(etype, failed_count, npoint)
|
||||
character(len=*), intent(in) :: etype
|
||||
integer, intent(in) :: failed_count
|
||||
integer, intent(in) :: npoint
|
||||
character(len=ELEM_TYPE_LEN) :: local_type
|
||||
|
||||
local_type = adjustl(etype)
|
||||
if (failed_count .le. 0) then
|
||||
should_delete_solid = .false.
|
||||
else if (trim(local_type) .eq. 'C3D4' .or. trim(local_type) .eq. 'C3D10') then
|
||||
should_delete_solid = .true.
|
||||
else
|
||||
should_delete_solid = failed_count * 2 .ge. npoint
|
||||
end if
|
||||
end function should_delete_solid
|
||||
|
||||
subroutine solid_current_spin(elem, nlocal, dndx, spin_current)
|
||||
integer, intent(in) :: elem
|
||||
integer, intent(in) :: nlocal
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
program test_quadratic_internal
|
||||
use fem_precision
|
||||
use fem_error
|
||||
use fem_database
|
||||
use fem_element_internal
|
||||
implicit none
|
||||
|
||||
real(rk), parameter :: TOL = 1.0e-8_rk
|
||||
real(rk), parameter :: EXX = 0.01_rk
|
||||
|
||||
call check_c3d10_internal()
|
||||
call check_c3d20_internal()
|
||||
|
||||
contains
|
||||
|
||||
subroutine check_c3d10_internal()
|
||||
integer :: ierr
|
||||
|
||||
call setup_c3d10(ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(1)
|
||||
call apply_x_extension(EXX)
|
||||
|
||||
call element_compute_internal_force(ierr, 1.0e-4_rk)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(2)
|
||||
if (elem_status(1) .ne. 0) call fail(3)
|
||||
call check_state_shape(4, 4)
|
||||
call check_gp_values(4, 10)
|
||||
call check_force_balance(20)
|
||||
|
||||
call database_finalize(ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(29)
|
||||
end subroutine check_c3d10_internal
|
||||
|
||||
subroutine check_c3d20_internal()
|
||||
integer :: ierr
|
||||
|
||||
call setup_c3d20(ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(30)
|
||||
call apply_x_extension(EXX)
|
||||
|
||||
call element_compute_internal_force(ierr, 1.0e-4_rk)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(31)
|
||||
if (elem_status(1) .ne. 0) call fail(32)
|
||||
call check_state_shape(27, 33)
|
||||
call check_gp_values(27, 40)
|
||||
call check_force_balance(50)
|
||||
|
||||
call database_finalize(ierr)
|
||||
if (ierr .ne. FEM_SUCCESS) call fail(59)
|
||||
end subroutine check_c3d20_internal
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
character(len=*), intent(in) :: etype
|
||||
integer, intent(in) :: nlocal
|
||||
integer :: i
|
||||
|
||||
do i = 1, nlocal
|
||||
node_id_ext(i) = i
|
||||
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) = 30.0_rk
|
||||
mat_nu(1) = 0.25_rk
|
||||
mat_plastic_model(1) = 'ELASTIC'
|
||||
|
||||
section_type(1) = 'SOLID'
|
||||
section_elset_name(1) = 'EALL'
|
||||
section_material_name(1) = 'MAT'
|
||||
end subroutine fill_common_model
|
||||
|
||||
subroutine apply_x_extension(exx)
|
||||
real(rk), intent(in) :: exx
|
||||
integer :: node
|
||||
integer :: dof
|
||||
|
||||
u = ZERO
|
||||
do node = 1, nnode
|
||||
dof = dof_id(1,node)
|
||||
if (dof .gt. 0) u(dof) = exx * coord0(1,node)
|
||||
end do
|
||||
end subroutine apply_x_extension
|
||||
|
||||
subroutine check_state_shape(expected_ngp, code)
|
||||
integer, intent(in) :: expected_ngp
|
||||
integer, intent(in) :: code
|
||||
|
||||
if (elem_gp_start(1) .ne. 1) call fail(code)
|
||||
if (elem_ngp(1) .ne. expected_ngp) call fail(code + 1)
|
||||
if (ngauss_total .ne. expected_ngp) 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_gp_values(npoint, code)
|
||||
integer, intent(in) :: npoint
|
||||
integer, intent(in) :: code
|
||||
real(rk) :: lambda
|
||||
real(rk) :: mu
|
||||
real(rk) :: expected_stress(NSTRESS)
|
||||
real(rk) :: expected_strain(NSTRESS)
|
||||
integer :: gp
|
||||
|
||||
lambda = mat_e(1) * mat_nu(1) / &
|
||||
((ONE + mat_nu(1)) * (ONE - 2.0_rk * mat_nu(1)))
|
||||
mu = mat_e(1) / (2.0_rk * (ONE + mat_nu(1)))
|
||||
|
||||
expected_strain = ZERO
|
||||
expected_strain(1) = EXX
|
||||
|
||||
expected_stress = ZERO
|
||||
expected_stress(1) = (lambda + 2.0_rk * mu) * EXX
|
||||
expected_stress(2) = lambda * EXX
|
||||
expected_stress(3) = lambda * EXX
|
||||
|
||||
do gp = 1, npoint
|
||||
call check_vector_close(strain(:,gp), expected_strain, code)
|
||||
call check_vector_close(stress(:,gp), expected_stress, code + 1)
|
||||
if (abs(statev(4,gp)) .gt. TOL) call fail(code + 2)
|
||||
end do
|
||||
end subroutine check_gp_values
|
||||
|
||||
subroutine check_force_balance(code)
|
||||
integer, intent(in) :: code
|
||||
real(rk) :: balance(NDIM)
|
||||
real(rk) :: max_force
|
||||
integer :: node
|
||||
integer :: idir
|
||||
integer :: dof
|
||||
|
||||
balance = ZERO
|
||||
max_force = ZERO
|
||||
do node = 1, nnode
|
||||
do idir = 1, NDIM
|
||||
dof = dof_id(idir,node)
|
||||
if (dof .gt. 0) then
|
||||
balance(idir) = balance(idir) + fint(dof)
|
||||
max_force = max(max_force, abs(fint(dof)))
|
||||
end if
|
||||
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_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_quadratic_internal failed:', code
|
||||
stop 1
|
||||
end subroutine fail
|
||||
|
||||
end program test_quadratic_internal
|
||||
Reference in New Issue
Block a user