@ -8,7 +8,7 @@ module opt_group
use box
use box
implicit none
implicit none
integer :: group_ele_num , group_atom_num , remesh_size , normal , dim1 , dim2
integer :: group_ele_num , group_atom_num , remesh_size , normal , dim1 , dim2 , random_num
character ( len = 15 ) :: type , shape ! Type indicates what element type is selected and shape is the group shape
character ( len = 15 ) :: type , shape ! Type indicates what element type is selected and shape is the group shape
real ( kind = dp ) :: block_bd ( 6 ) , centroid ( 3 ) , vertices ( 3 , 3 ) , disp_vec ( 3 ) , tip_radius , bwidth
real ( kind = dp ) :: block_bd ( 6 ) , centroid ( 3 ) , vertices ( 3 , 3 ) , disp_vec ( 3 ) , tip_radius , bwidth
logical :: displace , delete , max_remesh , refine , group_nodes
logical :: displace , delete , max_remesh , refine , group_nodes
@ -27,6 +27,7 @@ module opt_group
group_ele_num = 0
group_ele_num = 0
group_atom_num = 0
group_atom_num = 0
remesh_size = 0
remesh_size = 0
random_num = 0
displace = . false .
displace = . false .
delete = . false .
delete = . false .
max_remesh = . false .
max_remesh = . false .
@ -347,6 +348,11 @@ module opt_group
delete = . true .
delete = . true .
case ( 'nodes' )
case ( 'nodes' )
group_nodes = . true .
group_nodes = . true .
case ( 'random' )
arg_pos = arg_pos + 1
call get_command_argument ( arg_pos , textholder , arglen )
if ( arglen == 0 ) stop "Missing number of random atoms in group command"
read ( textholder , * ) random_num
case default
case default
! If it isn ' t an available option to opt_disl then we just exit
! If it isn ' t an available option to opt_disl then we just exit
exit
exit
@ -357,15 +363,18 @@ module opt_group
subroutine get_group
subroutine get_group
! This subroutine finds all elements and / or atoms within the group boundaries
! This subroutine finds all elements and / or atoms within the group boundaries
! specified by the user .
! specified by the user .
integer :: i , j , inod , ibasis
integer :: i , j , inod , ibasis , temp
integer , allocatable :: resize_array ( : )
integer , allocatable :: resize_array ( : )
real ( kind = dp ) :: r_center ( 3 )
real ( kind = dp ) :: r_center ( 3 ) , rand
select case ( trim ( adjustl ( shape ) ) )
select case ( trim ( adjustl ( shape ) ) )
case ( 'block' )
case ( 'block' )
print * , "Group has block shape with boundaries: " , block_bd
print * , "Group has block shape with boundaries: " , block_bd
case ( 'wedge' )
case ( 'wedge' )
print * , "Group has wedge shape with dim1" , dim1 , "and dim2" , dim2 , "and vertices " , vertices
print * , "Group has wedge shape with dim1" , dim1 , "and dim2" , dim2 , "and vertices " , vertices
case ( 'notch' )
print * , "Group has notch shape with dim1" , dim1 , "and dim2" , dim2 , " tip radius " , tip_radius , "and vertices " , &
vertices
case ( 'id' )
case ( 'id' )
print * , 'Group contains ' , group_ele_num , " elements and " , group_atom_num , " atoms."
print * , 'Group contains ' , group_ele_num , " elements and " , group_atom_num , " atoms."
return
return
@ -401,6 +410,7 @@ module opt_group
element_index ( group_ele_num ) = i
element_index ( group_ele_num ) = i
end if
end if
end do
end do
else if ( group_nodes ) then
else if ( group_nodes ) then
eleloop : do i = 1 , ele_num
eleloop : do i = 1 , ele_num
r_center ( : ) = 0.0_dp
r_center ( : ) = 0.0_dp
@ -421,6 +431,21 @@ module opt_group
end do
end do
end do eleloop
end do eleloop
end if
end if
if ( random_num > 0 ) then
! If we have the random option enabled then we select random_num number of elements from the group and overwrite
! the group with those elements
do i = 1 , random_num
call random_number ( rand )
j = i + floor ( ( group_ele_num + 1 - i ) * rand )
temp = element_index ( j )
element_index ( j ) = element_index ( i )
element_index ( i ) = temp
end do
group_ele_num = random_num
end if
end select
end select
! Check the type to see if we need to find the atoms within the group
! Check the type to see if we need to find the atoms within the group
select case ( trim ( adjustl ( type ) ) )
select case ( trim ( adjustl ( type ) ) )
@ -438,6 +463,19 @@ module opt_group
atom_index ( group_atom_num ) = i
atom_index ( group_atom_num ) = i
end if
end if
end do
end do
if ( random_num > 0 ) then
! If we have the random option enabled then we select random_num number of atom from the group and overwrite
! the group with those atom
do i = 1 , random_num
call random_number ( rand )
j = i + floor ( ( group_atom_num + 1 - i ) * rand )
temp = atom_index ( j )
atom_index ( j ) = atom_index ( i )
atom_index ( i ) = temp
end do
group_atom_num = random_num
end if
end select
end select
j = 0
j = 0