742 lines
24 KiB
Fortran
742 lines
24 KiB
Fortran
module fem_coupling
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_database
|
|
implicit none
|
|
|
|
private
|
|
|
|
integer :: nfacet = 0
|
|
integer, allocatable :: facet_elem(:)
|
|
integer, allocatable :: facet_face(:)
|
|
integer, allocatable :: facet_nnode(:)
|
|
integer, allocatable :: facet_conn(:,:)
|
|
|
|
public :: cpl_build_facets
|
|
public :: cpl_finalize_facets
|
|
public :: cpl_get_facet_count
|
|
public :: cpl_get_facets
|
|
public :: cpl_apply_facet_pressure
|
|
public :: cpl_apply_facet_tractions
|
|
|
|
contains
|
|
|
|
subroutine cpl_build_facets(ierr)
|
|
integer, intent(out) :: ierr
|
|
integer :: max_faces
|
|
integer :: table_size
|
|
integer :: stat
|
|
integer :: elem
|
|
integer :: face_count
|
|
integer :: out_count
|
|
integer :: local_nodes(MAX_FACE_NODES)
|
|
integer, allocatable :: hash(:)
|
|
integer, allocatable :: cand_elem(:)
|
|
integer, allocatable :: cand_face(:)
|
|
integer, allocatable :: cand_nnode(:)
|
|
integer, allocatable :: cand_count(:)
|
|
integer, allocatable :: cand_conn(:,:)
|
|
integer, allocatable :: cand_key(:,:)
|
|
|
|
call cpl_finalize_facets()
|
|
|
|
call count_candidate_faces(max_faces, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
if (max_faces .le. 0) then
|
|
nfacet = 0
|
|
ierr = FEM_SUCCESS
|
|
return
|
|
end if
|
|
|
|
table_size = max(17, 3 * max_faces + 1)
|
|
allocate(hash(table_size), cand_elem(max_faces), cand_face(max_faces), &
|
|
cand_nnode(max_faces), cand_count(max_faces), &
|
|
cand_conn(MAX_FACE_NODES,max_faces), &
|
|
cand_key(MAX_FACE_NODES,max_faces), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_INTERNAL, 'failed to allocate facet candidates', ierr)
|
|
return
|
|
end if
|
|
|
|
hash = 0
|
|
cand_elem = 0
|
|
cand_face = 0
|
|
cand_nnode = 0
|
|
cand_count = 0
|
|
cand_conn = 0
|
|
cand_key = 0
|
|
face_count = 0
|
|
|
|
do elem = 1, nelem
|
|
if (elem_status(elem) .ne. 0) cycle
|
|
|
|
select case (trim(adjustl(elem_type(elem))))
|
|
case ('C3D4')
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 2
|
|
local_nodes(3) = 3
|
|
call add_solid_face(elem, 1, 3, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 2
|
|
local_nodes(3) = 4
|
|
call add_solid_face(elem, 2, 3, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 3
|
|
local_nodes(3) = 4
|
|
call add_solid_face(elem, 3, 3, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 2
|
|
local_nodes(2) = 3
|
|
local_nodes(3) = 4
|
|
call add_solid_face(elem, 4, 3, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
case ('C3D8')
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 2
|
|
local_nodes(3) = 3
|
|
local_nodes(4) = 4
|
|
call add_solid_face(elem, 1, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 5
|
|
local_nodes(2) = 6
|
|
local_nodes(3) = 7
|
|
local_nodes(4) = 8
|
|
call add_solid_face(elem, 2, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 2
|
|
local_nodes(3) = 6
|
|
local_nodes(4) = 5
|
|
call add_solid_face(elem, 3, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 2
|
|
local_nodes(2) = 3
|
|
local_nodes(3) = 7
|
|
local_nodes(4) = 6
|
|
call add_solid_face(elem, 4, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 3
|
|
local_nodes(2) = 4
|
|
local_nodes(3) = 8
|
|
local_nodes(4) = 7
|
|
call add_solid_face(elem, 5, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
local_nodes = 0
|
|
local_nodes(1) = 4
|
|
local_nodes(2) = 1
|
|
local_nodes(3) = 5
|
|
local_nodes(4) = 8
|
|
call add_solid_face(elem, 6, 4, local_nodes, face_count, hash, &
|
|
table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
case ('S4')
|
|
local_nodes = 0
|
|
local_nodes(1) = 1
|
|
local_nodes(2) = 2
|
|
local_nodes(3) = 3
|
|
local_nodes(4) = 4
|
|
call add_shell_face(elem, 1, 4, local_nodes, face_count, cand_elem, &
|
|
cand_face, cand_nnode, cand_count, cand_conn, &
|
|
cand_key, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
case default
|
|
call error_set(FEM_ERR_MESH, 'unsupported element type for boundary facets', ierr)
|
|
return
|
|
end select
|
|
end do
|
|
|
|
out_count = 0
|
|
do elem = 1, face_count
|
|
if (cand_count(elem) .eq. 1) out_count = out_count + 1
|
|
end do
|
|
|
|
nfacet = out_count
|
|
if (nfacet .gt. 0) then
|
|
allocate(facet_elem(nfacet), facet_face(nfacet), facet_nnode(nfacet), &
|
|
facet_conn(MAX_FACE_NODES,nfacet), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_INTERNAL, 'failed to allocate boundary facets', ierr)
|
|
return
|
|
end if
|
|
|
|
out_count = 0
|
|
do elem = 1, face_count
|
|
if (cand_count(elem) .eq. 1) then
|
|
out_count = out_count + 1
|
|
facet_elem(out_count) = cand_elem(elem)
|
|
facet_face(out_count) = cand_face(elem)
|
|
facet_nnode(out_count) = cand_nnode(elem)
|
|
facet_conn(:,out_count) = cand_conn(:,elem)
|
|
end if
|
|
end do
|
|
end if
|
|
|
|
deallocate(hash, cand_elem, cand_face, cand_nnode, cand_count, &
|
|
cand_conn, cand_key)
|
|
ierr = FEM_SUCCESS
|
|
end subroutine cpl_build_facets
|
|
|
|
subroutine cpl_finalize_facets()
|
|
if (allocated(facet_elem)) deallocate(facet_elem)
|
|
if (allocated(facet_face)) deallocate(facet_face)
|
|
if (allocated(facet_nnode)) deallocate(facet_nnode)
|
|
if (allocated(facet_conn)) deallocate(facet_conn)
|
|
nfacet = 0
|
|
end subroutine cpl_finalize_facets
|
|
|
|
subroutine cpl_get_facet_count(facet_count, max_face_nodes, ierr)
|
|
integer, intent(out) :: facet_count
|
|
integer, intent(out) :: max_face_nodes
|
|
integer, intent(out) :: ierr
|
|
integer :: idx
|
|
|
|
facet_count = 0
|
|
max_face_nodes = 0
|
|
do idx = 1, nfacet
|
|
if (elem_status(facet_elem(idx)) .eq. 0) then
|
|
facet_count = facet_count + 1
|
|
if (facet_nnode(idx) .gt. max_face_nodes) max_face_nodes = facet_nnode(idx)
|
|
end if
|
|
end do
|
|
ierr = FEM_SUCCESS
|
|
end subroutine cpl_get_facet_count
|
|
|
|
subroutine cpl_get_facets(nfacet_in, max_face_nodes_in, &
|
|
facet_id, elem_id, face_id, &
|
|
facet_nnode_out, facet_conn_out, &
|
|
x, vnod, normal, area, ierr)
|
|
integer, intent(in) :: nfacet_in
|
|
integer, intent(in) :: max_face_nodes_in
|
|
integer, intent(out) :: facet_id(nfacet_in)
|
|
integer, intent(out) :: elem_id(nfacet_in)
|
|
integer, intent(out) :: face_id(nfacet_in)
|
|
integer, intent(out) :: facet_nnode_out(nfacet_in)
|
|
integer, intent(out) :: facet_conn_out(max_face_nodes_in,nfacet_in)
|
|
real(rk), intent(out) :: x(NDIM,max_face_nodes_in,nfacet_in)
|
|
real(rk), intent(out) :: vnod(NDIM,max_face_nodes_in,nfacet_in)
|
|
real(rk), intent(out) :: normal(NDIM,nfacet_in)
|
|
real(rk), intent(out) :: area(nfacet_in)
|
|
integer, intent(out) :: ierr
|
|
integer :: idx
|
|
integer :: active_count
|
|
integer :: out_idx
|
|
integer :: local_node
|
|
integer :: node
|
|
integer :: max_nodes
|
|
real(rk) :: coords(NDIM,MAX_FACE_NODES)
|
|
real(rk) :: velocities(NDIM,MAX_FACE_NODES)
|
|
real(rk) :: nrm(NDIM)
|
|
real(rk) :: ar
|
|
|
|
call cpl_get_facet_count(active_count, max_nodes, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
if (nfacet_in .lt. active_count) then
|
|
call error_set(FEM_ERR_COUPLING, 'facet output array is too small', ierr)
|
|
return
|
|
end if
|
|
if (max_face_nodes_in .lt. max_nodes) then
|
|
call error_set(FEM_ERR_COUPLING, 'facet node dimension is too small', ierr)
|
|
return
|
|
end if
|
|
|
|
facet_id = 0
|
|
elem_id = 0
|
|
face_id = 0
|
|
facet_nnode_out = 0
|
|
facet_conn_out = 0
|
|
x = ZERO
|
|
vnod = ZERO
|
|
normal = ZERO
|
|
area = ZERO
|
|
|
|
out_idx = 0
|
|
do idx = 1, nfacet
|
|
if (elem_status(facet_elem(idx)) .ne. 0) cycle
|
|
out_idx = out_idx + 1
|
|
call facet_current_geometry(idx, coords, velocities, nrm, ar, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
facet_id(out_idx) = idx
|
|
elem_id(out_idx) = elem_id_ext(facet_elem(idx))
|
|
face_id(out_idx) = facet_face(idx)
|
|
facet_nnode_out(out_idx) = facet_nnode(idx)
|
|
normal(:,out_idx) = nrm
|
|
area(out_idx) = ar
|
|
|
|
do local_node = 1, facet_nnode(idx)
|
|
node = facet_conn(local_node,idx)
|
|
facet_conn_out(local_node,out_idx) = node_id_ext(node)
|
|
x(:,local_node,out_idx) = coords(:,local_node)
|
|
vnod(:,local_node,out_idx) = velocities(:,local_node)
|
|
end do
|
|
end do
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine cpl_get_facets
|
|
|
|
subroutine cpl_apply_facet_pressure(nfacet_in, facet_id, pressure, ierr)
|
|
integer, intent(in) :: nfacet_in
|
|
integer, intent(in) :: facet_id(nfacet_in)
|
|
real(rk), intent(in) :: pressure(nfacet_in)
|
|
integer, intent(out) :: ierr
|
|
real(rk), allocatable :: shear(:,:)
|
|
integer :: stat
|
|
|
|
allocate(shear(NDIM,nfacet_in), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_INTERNAL, 'failed to allocate zero shear array', ierr)
|
|
return
|
|
end if
|
|
shear = ZERO
|
|
call cpl_apply_facet_tractions(nfacet_in, facet_id, pressure, shear, ierr)
|
|
deallocate(shear)
|
|
end subroutine cpl_apply_facet_pressure
|
|
|
|
subroutine cpl_apply_facet_tractions(nfacet_in, facet_id, pressure, shear, ierr)
|
|
integer, intent(in) :: nfacet_in
|
|
integer, intent(in) :: facet_id(nfacet_in)
|
|
real(rk), intent(in) :: pressure(nfacet_in)
|
|
real(rk), intent(in) :: shear(NDIM,nfacet_in)
|
|
integer, intent(out) :: ierr
|
|
integer :: item
|
|
integer :: idx
|
|
integer :: local_node
|
|
integer :: node
|
|
integer :: idir
|
|
integer :: dof
|
|
real(rk) :: coords(NDIM,MAX_FACE_NODES)
|
|
real(rk) :: velocities(NDIM,MAX_FACE_NODES)
|
|
real(rk) :: nrm(NDIM)
|
|
real(rk) :: ar
|
|
real(rk) :: traction(NDIM)
|
|
real(rk) :: nodal_force(NDIM)
|
|
|
|
if (.not. allocated(fsph)) then
|
|
call error_set(FEM_ERR_INTERNAL, 'SPH force vector is not allocated', ierr)
|
|
return
|
|
end if
|
|
if (nfacet_in .lt. 0) then
|
|
call error_set(FEM_ERR_COUPLING, 'number of SPH facets is negative', ierr)
|
|
return
|
|
end if
|
|
|
|
do item = 1, nfacet_in
|
|
idx = find_facet(facet_id(item))
|
|
if (idx .eq. 0) then
|
|
call error_set(FEM_ERR_COUPLING, 'SPH facet load references unknown facet', ierr)
|
|
return
|
|
end if
|
|
end do
|
|
|
|
do item = 1, nfacet_in
|
|
idx = find_facet(facet_id(item))
|
|
if (elem_status(facet_elem(idx)) .ne. 0) cycle
|
|
|
|
call facet_current_geometry(idx, coords, velocities, nrm, ar, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
traction = -pressure(item) * nrm + shear(:,item)
|
|
nodal_force = traction * ar / real(facet_nnode(idx), rk)
|
|
|
|
do local_node = 1, facet_nnode(idx)
|
|
node = facet_conn(local_node,idx)
|
|
do idir = 1, NDIM
|
|
dof = dof_id(idir,node)
|
|
if (dof .gt. 0) fsph(dof) = fsph(dof) + nodal_force(idir)
|
|
end do
|
|
end do
|
|
end do
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine cpl_apply_facet_tractions
|
|
|
|
subroutine count_candidate_faces(max_faces, ierr)
|
|
integer, intent(out) :: max_faces
|
|
integer, intent(out) :: ierr
|
|
integer :: elem
|
|
|
|
max_faces = 0
|
|
do elem = 1, nelem
|
|
if (elem_status(elem) .ne. 0) cycle
|
|
select case (trim(adjustl(elem_type(elem))))
|
|
case ('C3D4')
|
|
max_faces = max_faces + 4
|
|
case ('C3D8')
|
|
max_faces = max_faces + 6
|
|
case ('S4')
|
|
max_faces = max_faces + 1
|
|
case default
|
|
call error_set(FEM_ERR_MESH, 'unsupported element type for boundary facets', ierr)
|
|
return
|
|
end select
|
|
end do
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine count_candidate_faces
|
|
|
|
subroutine add_solid_face(elem, face, num_face_nodes, local_nodes, face_count, &
|
|
hash, table_size, cand_elem, cand_face, cand_nnode, &
|
|
cand_count, cand_conn, cand_key, ierr)
|
|
integer, intent(in) :: elem
|
|
integer, intent(in) :: face
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(in) :: local_nodes(MAX_FACE_NODES)
|
|
integer, intent(inout) :: face_count
|
|
integer, intent(in) :: table_size
|
|
integer, intent(inout) :: hash(:)
|
|
integer, intent(inout) :: cand_elem(:)
|
|
integer, intent(inout) :: cand_face(:)
|
|
integer, intent(inout) :: cand_nnode(:)
|
|
integer, intent(inout) :: cand_count(:)
|
|
integer, intent(inout) :: cand_conn(:,:)
|
|
integer, intent(inout) :: cand_key(:,:)
|
|
integer, intent(out) :: ierr
|
|
integer :: nodes(MAX_FACE_NODES)
|
|
integer :: key(MAX_FACE_NODES)
|
|
integer :: h
|
|
integer :: probe
|
|
integer :: slot
|
|
integer :: cand
|
|
integer :: local_node
|
|
|
|
nodes = 0
|
|
key = 0
|
|
do local_node = 1, num_face_nodes
|
|
nodes(local_node) = elem_conn(local_nodes(local_node), elem)
|
|
key(local_node) = nodes(local_node)
|
|
end do
|
|
|
|
call orient_solid_face(elem, num_face_nodes, nodes, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call sort_face_key(key, num_face_nodes)
|
|
|
|
h = face_hash(key, num_face_nodes, table_size)
|
|
do probe = 1, table_size
|
|
slot = 1 + mod(h + probe - 2, table_size)
|
|
cand = hash(slot)
|
|
if (cand .eq. 0) then
|
|
face_count = face_count + 1
|
|
cand_elem(face_count) = elem
|
|
cand_face(face_count) = face
|
|
cand_nnode(face_count) = num_face_nodes
|
|
cand_count(face_count) = 1
|
|
cand_conn(:,face_count) = nodes
|
|
cand_key(:,face_count) = key
|
|
hash(slot) = face_count
|
|
ierr = FEM_SUCCESS
|
|
return
|
|
end if
|
|
|
|
if (same_face_key(cand_key(:,cand), key, num_face_nodes, cand_nnode(cand))) then
|
|
cand_count(cand) = cand_count(cand) + 1
|
|
ierr = FEM_SUCCESS
|
|
return
|
|
end if
|
|
end do
|
|
|
|
call error_set(FEM_ERR_INTERNAL, 'facet hash table is full', ierr)
|
|
end subroutine add_solid_face
|
|
|
|
subroutine add_shell_face(elem, face, num_face_nodes, local_nodes, face_count, &
|
|
cand_elem, cand_face, cand_nnode, cand_count, &
|
|
cand_conn, cand_key, ierr)
|
|
integer, intent(in) :: elem
|
|
integer, intent(in) :: face
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(in) :: local_nodes(MAX_FACE_NODES)
|
|
integer, intent(inout) :: face_count
|
|
integer, intent(inout) :: cand_elem(:)
|
|
integer, intent(inout) :: cand_face(:)
|
|
integer, intent(inout) :: cand_nnode(:)
|
|
integer, intent(inout) :: cand_count(:)
|
|
integer, intent(inout) :: cand_conn(:,:)
|
|
integer, intent(inout) :: cand_key(:,:)
|
|
integer, intent(out) :: ierr
|
|
integer :: local_node
|
|
|
|
face_count = face_count + 1
|
|
cand_elem(face_count) = elem
|
|
cand_face(face_count) = face
|
|
cand_nnode(face_count) = num_face_nodes
|
|
cand_count(face_count) = 1
|
|
cand_conn(:,face_count) = 0
|
|
cand_key(:,face_count) = 0
|
|
do local_node = 1, num_face_nodes
|
|
cand_conn(local_node,face_count) = elem_conn(local_nodes(local_node),elem)
|
|
cand_key(local_node,face_count) = cand_conn(local_node,face_count)
|
|
end do
|
|
call sort_face_key(cand_key(:,face_count), num_face_nodes)
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine add_shell_face
|
|
|
|
subroutine orient_solid_face(elem, num_face_nodes, nodes, ierr)
|
|
integer, intent(in) :: elem
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(inout) :: nodes(MAX_FACE_NODES)
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: face_center(NDIM)
|
|
real(rk) :: elem_center(NDIM)
|
|
real(rk) :: nrm(NDIM)
|
|
real(rk) :: ar
|
|
integer :: local_node
|
|
integer :: node
|
|
|
|
elem_center = ZERO
|
|
do local_node = 1, elem_nnode(elem)
|
|
node = elem_conn(local_node,elem)
|
|
elem_center = elem_center + coord0(:,node)
|
|
end do
|
|
elem_center = elem_center / real(elem_nnode(elem), rk)
|
|
|
|
face_center = ZERO
|
|
do local_node = 1, num_face_nodes
|
|
face_center = face_center + coord0(:,nodes(local_node))
|
|
end do
|
|
face_center = face_center / real(num_face_nodes, rk)
|
|
|
|
call face_geometry_from_nodes(num_face_nodes, nodes, coord0, nrm, ar, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
if (dot_product(nrm, face_center - elem_center) .lt. ZERO) then
|
|
call reverse_face_nodes(num_face_nodes, nodes)
|
|
end if
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine orient_solid_face
|
|
|
|
subroutine facet_current_geometry(idx, coords, velocities, normal, area, ierr)
|
|
integer, intent(in) :: idx
|
|
real(rk), intent(out) :: coords(NDIM,MAX_FACE_NODES)
|
|
real(rk), intent(out) :: velocities(NDIM,MAX_FACE_NODES)
|
|
real(rk), intent(out) :: normal(NDIM)
|
|
real(rk), intent(out) :: area
|
|
integer, intent(out) :: ierr
|
|
integer :: local_node
|
|
integer :: node
|
|
integer :: idir
|
|
integer :: dof
|
|
|
|
coords = ZERO
|
|
velocities = ZERO
|
|
do local_node = 1, facet_nnode(idx)
|
|
node = facet_conn(local_node,idx)
|
|
coords(:,local_node) = coord0(:,node)
|
|
do idir = 1, NDIM
|
|
dof = dof_id(idir,node)
|
|
if (dof .gt. 0) then
|
|
coords(idir,local_node) = coords(idir,local_node) + u(dof)
|
|
velocities(idir,local_node) = v(dof)
|
|
end if
|
|
end do
|
|
end do
|
|
|
|
call face_geometry(facet_nnode(idx), coords, normal, area, ierr)
|
|
end subroutine facet_current_geometry
|
|
|
|
subroutine face_geometry_from_nodes(num_face_nodes, nodes, coordinates, normal, area, ierr)
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(in) :: nodes(MAX_FACE_NODES)
|
|
real(rk), intent(in) :: coordinates(:,:)
|
|
real(rk), intent(out) :: normal(NDIM)
|
|
real(rk), intent(out) :: area
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: coords(NDIM,MAX_FACE_NODES)
|
|
integer :: local_node
|
|
|
|
coords = ZERO
|
|
do local_node = 1, num_face_nodes
|
|
coords(:,local_node) = coordinates(:,nodes(local_node))
|
|
end do
|
|
|
|
call face_geometry(num_face_nodes, coords, normal, area, ierr)
|
|
end subroutine face_geometry_from_nodes
|
|
|
|
subroutine face_geometry(num_face_nodes, coords, normal, area, ierr)
|
|
integer, intent(in) :: num_face_nodes
|
|
real(rk), intent(in) :: coords(NDIM,MAX_FACE_NODES)
|
|
real(rk), intent(out) :: normal(NDIM)
|
|
real(rk), intent(out) :: area
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: tri_normal(NDIM)
|
|
real(rk) :: total_normal(NDIM)
|
|
real(rk) :: tri_area
|
|
|
|
if (num_face_nodes .eq. 3) then
|
|
call triangle_normal_area(coords(:,1), coords(:,2), coords(:,3), &
|
|
normal, area, ierr)
|
|
return
|
|
else if (num_face_nodes .eq. 4) then
|
|
call triangle_normal_area(coords(:,1), coords(:,2), coords(:,3), &
|
|
total_normal, area, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call triangle_normal_area(coords(:,1), coords(:,3), coords(:,4), &
|
|
tri_normal, tri_area, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
total_normal = total_normal * area + tri_normal * tri_area
|
|
area = area + tri_area
|
|
if (area .le. ZERO) then
|
|
call error_set(FEM_ERR_MESH, 'facet has non-positive area', ierr)
|
|
return
|
|
end if
|
|
normal = total_normal / sqrt(sum(total_normal * total_normal))
|
|
else
|
|
call error_set(FEM_ERR_MESH, 'unsupported number of facet nodes', ierr)
|
|
return
|
|
end if
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine face_geometry
|
|
|
|
subroutine triangle_normal_area(a, b, c, normal, area, ierr)
|
|
real(rk), intent(in) :: a(NDIM)
|
|
real(rk), intent(in) :: b(NDIM)
|
|
real(rk), intent(in) :: c(NDIM)
|
|
real(rk), intent(out) :: normal(NDIM)
|
|
real(rk), intent(out) :: area
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: ab(NDIM)
|
|
real(rk) :: ac(NDIM)
|
|
real(rk) :: cr(NDIM)
|
|
real(rk) :: norm_cr
|
|
|
|
ab = b - a
|
|
ac = c - a
|
|
call cross3(ab, ac, cr)
|
|
norm_cr = sqrt(sum(cr * cr))
|
|
if (norm_cr .le. ZERO) then
|
|
call error_set(FEM_ERR_MESH, 'facet has zero area triangle', ierr)
|
|
return
|
|
end if
|
|
|
|
area = HALF * norm_cr
|
|
normal = cr / norm_cr
|
|
ierr = FEM_SUCCESS
|
|
end subroutine triangle_normal_area
|
|
|
|
subroutine cross3(a, b, c)
|
|
real(rk), intent(in) :: a(NDIM)
|
|
real(rk), intent(in) :: b(NDIM)
|
|
real(rk), intent(out) :: c(NDIM)
|
|
|
|
c(1) = a(2) * b(3) - a(3) * b(2)
|
|
c(2) = a(3) * b(1) - a(1) * b(3)
|
|
c(3) = a(1) * b(2) - a(2) * b(1)
|
|
end subroutine cross3
|
|
|
|
subroutine reverse_face_nodes(num_face_nodes, nodes)
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(inout) :: nodes(MAX_FACE_NODES)
|
|
integer :: tmp(MAX_FACE_NODES)
|
|
integer :: local_node
|
|
|
|
tmp = nodes
|
|
do local_node = 1, num_face_nodes
|
|
nodes(local_node) = tmp(num_face_nodes - local_node + 1)
|
|
end do
|
|
end subroutine reverse_face_nodes
|
|
|
|
subroutine sort_face_key(key, num_face_nodes)
|
|
integer, intent(inout) :: key(MAX_FACE_NODES)
|
|
integer, intent(in) :: num_face_nodes
|
|
integer :: i
|
|
integer :: j
|
|
integer :: value
|
|
|
|
do i = 2, num_face_nodes
|
|
value = key(i)
|
|
j = i - 1
|
|
do while (j .ge. 1)
|
|
if (key(j) .le. value) exit
|
|
key(j + 1) = key(j)
|
|
j = j - 1
|
|
end do
|
|
key(j + 1) = value
|
|
end do
|
|
do i = num_face_nodes + 1, MAX_FACE_NODES
|
|
key(i) = 0
|
|
end do
|
|
end subroutine sort_face_key
|
|
|
|
integer function face_hash(key, num_face_nodes, table_size)
|
|
integer, intent(in) :: key(MAX_FACE_NODES)
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(in) :: table_size
|
|
integer :: i
|
|
integer :: h
|
|
|
|
h = 0
|
|
do i = 1, num_face_nodes
|
|
h = mod(131 * h + 17 * key(i) + i, table_size)
|
|
end do
|
|
face_hash = h + 1
|
|
end function face_hash
|
|
|
|
logical function same_face_key(candidate_key, key, num_face_nodes, candidate_nnode)
|
|
integer, intent(in) :: candidate_key(MAX_FACE_NODES)
|
|
integer, intent(in) :: key(MAX_FACE_NODES)
|
|
integer, intent(in) :: num_face_nodes
|
|
integer, intent(in) :: candidate_nnode
|
|
integer :: i
|
|
|
|
same_face_key = .false.
|
|
if (candidate_nnode .ne. num_face_nodes) return
|
|
do i = 1, MAX_FACE_NODES
|
|
if (candidate_key(i) .ne. key(i)) return
|
|
end do
|
|
same_face_key = .true.
|
|
end function same_face_key
|
|
|
|
integer function find_facet(facet_id)
|
|
integer, intent(in) :: facet_id
|
|
|
|
if (facet_id .ge. 1 .and. facet_id .le. nfacet) then
|
|
find_facet = facet_id
|
|
else
|
|
find_facet = 0
|
|
end if
|
|
end function find_facet
|
|
|
|
end module fem_coupling
|