diff --git a/README.md b/README.md index 257393e..93955f4 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,15 @@ delete This command deletes all selected atoms and elements within the group. + +**Random** +``` +random n +``` + +This command selects `n` random atoms and `n` random elements within your group bounds. If using group type `atoms` or `elements` then only `n` random atoms or elements are selected. This random atoms/elements then form the new group. + + ### Option overwrite ``` diff --git a/src/opt_group.f90 b/src/opt_group.f90 index c3edc8a..f0bb067 100644 --- a/src/opt_group.f90 +++ b/src/opt_group.f90 @@ -8,7 +8,7 @@ module opt_group use box 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 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 @@ -27,6 +27,7 @@ module opt_group group_ele_num = 0 group_atom_num = 0 remesh_size=0 + random_num=0 displace=.false. delete=.false. max_remesh=.false. @@ -347,6 +348,11 @@ module opt_group delete=.true. case('nodes') 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 !If it isn't an available option to opt_disl then we just exit exit @@ -357,15 +363,18 @@ module opt_group subroutine get_group !This subroutine finds all elements and/or atoms within the group boundaries !specified by the user. - integer :: i, j, inod, ibasis + integer :: i, j, inod, ibasis, temp integer, allocatable :: resize_array(:) - real(kind=dp) :: r_center(3) + real(kind=dp) :: r_center(3), rand select case(trim(adjustl(shape))) case('block') print *, "Group has block shape with boundaries: ", block_bd case ('wedge') 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') print *, 'Group contains ', group_ele_num, " elements and ", group_atom_num, " atoms." return @@ -401,6 +410,7 @@ module opt_group element_index(group_ele_num) = i end if end do + else if(group_nodes) then eleloop:do i = 1, ele_num r_center(:) = 0.0_dp @@ -421,6 +431,21 @@ module opt_group end do end do eleloop 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 !Check the type to see if we need to find the atoms within the group select case(trim(adjustl(type))) @@ -438,6 +463,19 @@ module opt_group atom_index(group_atom_num) = i end if 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 j = 0