--- trunk/OOPSE/libmdtools/do_Forces.F90 2004/05/11 21:31:15 1160 +++ trunk/OOPSE/libmdtools/do_Forces.F90 2004/06/01 21:45:22 1217 @@ -4,7 +4,7 @@ !! @author Charles F. Vardeman II !! @author Matthew Meineke -!! @version $Id: do_Forces.F90,v 1.55 2004-05-11 21:31:14 gezelter Exp $, $Date: 2004-05-11 21:31:14 $, $Name: not supported by cvs2svn $, $Revision: 1.55 $ +!! @version $Id: do_Forces.F90,v 1.68 2004-06-01 21:45:22 gezelter Exp $, $Date: 2004-06-01 21:45:22 $, $Name: not supported by cvs2svn $, $Revision: 1.68 $ module do_Forces use force_globals @@ -33,6 +33,9 @@ module do_Forces #include "fForceField.h" #include "fSwitchingFunction.h" + INTEGER, PARAMETER:: PREPAIR_LOOP = 1 + INTEGER, PARAMETER:: PAIR_LOOP = 2 + logical, save :: haveRlist = .false. logical, save :: haveNeighborList = .false. logical, save :: havePolicies = .false. @@ -370,11 +373,11 @@ contains subroutine do_force_loop(q, q_group, A, u_l, f, t, tau, pot, & do_pot_c, do_stress_c, error) !! Position array provided by C, dimensioned by getNlocal - real ( kind = dp ), dimension(3,nLocal) :: q + real ( kind = dp ), dimension(3, nLocal) :: q !! molecular center-of-mass position array - real ( kind = dp ), dimension(3,nGroup) :: q_group + real ( kind = dp ), dimension(3, nGroups) :: q_group !! Rotation Matrix for each long range particle in simulation. - real( kind = dp), dimension(9,nLocal) :: A + real( kind = dp), dimension(9, nLocal) :: A !! Unit vectors for dipoles (lab frame) real( kind = dp ), dimension(3,nLocal) :: u_l !! Force array provided by C, dimensioned by getNlocal @@ -391,27 +394,29 @@ contains logical :: in_switching_region #ifdef IS_MPI real( kind = DP ) :: pot_local - integer :: nrow - integer :: ncol + integer :: nAtomsInRow + integer :: nAtomsInCol integer :: nprocs - integer :: nrow_group - integer :: ncol_group + integer :: nGroupsInRow + integer :: nGroupsInCol #endif integer :: natoms logical :: update_nlist - integer :: i, j, jbeg, jend, jnab + integer :: i, j, jstart, jend, jnab + integer :: istart, iend integer :: ia, jb, atom1, atom2 integer :: nlist - real( kind = DP ) :: ratmsq, rgrpsq, rgrp, vpair, vab + real( kind = DP ) :: ratmsq, rgrpsq, rgrp, vpair, vij real( kind = DP ) :: sw, dswdr, swderiv, mf - real(kind=dp),dimension(3) :: d_atm, d_grp + real(kind=dp),dimension(3) :: d_atm, d_grp, fpair, fij real(kind=dp) :: rfpot, mu_i, virial - integer :: me_i, me_j + integer :: me_i, me_j, n_in_i, n_in_j logical :: is_dp_i integer :: neighborListSize integer :: listerror, error integer :: localError integer :: propPack_i, propPack_j + integer :: loopStart, loopEnd, loop real(kind=dp) :: listSkin = 1.0 @@ -419,10 +424,10 @@ contains #ifdef IS_MPI pot_local = 0.0_dp - nrow = getNrow(plan_row) - ncol = getNcol(plan_col) - nrow_group = getNrowGroup(plan_row) - ncol_group = getNcolGroup(plan_col) + nAtomsInRow = getNatomsInRow(plan_atom_row) + nAtomsInCol = getNatomsInCol(plan_atom_col) + nGroupsInRow = getNgroupsInRow(plan_group_row) + nGroupsInCol = getNgroupsInCol(plan_group_col) #else natoms = nlocal #endif @@ -442,18 +447,18 @@ contains #ifdef IS_MPI - call gather(q, q_Row, plan_row3d) - call gather(q, q_Col, plan_col3d) + call gather(q, q_Row, plan_atom_row_3d) + call gather(q, q_Col, plan_atom_col_3d) - call gather(q_group, q_group_Row, plan_row_Group_3d) - call gather(q_group, q_group_Col, plan_col_Group_3d) + call gather(q_group, q_group_Row, plan_group_row_3d) + call gather(q_group, q_group_Col, plan_group_col_3d) if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then - call gather(u_l,u_l_Row,plan_row3d) - call gather(u_l,u_l_Col,plan_col3d) + call gather(u_l, u_l_Row, plan_atom_row_3d) + call gather(u_l, u_l_Col, plan_atom_col_3d) - call gather(A,A_Row,plan_row_rotation) - call gather(A,A_Col,plan_col_rotation) + call gather(A, A_Row, plan_atom_row_rotation) + call gather(A, A_Col, plan_atom_col_rotation) endif #endif @@ -464,131 +469,90 @@ contains nloops = nloops + 1 #endif + loopEnd = PAIR_LOOP if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then - !! See if we need to update neighbor lists - - call checkNeighborList(nGroup, q_group, listSkin, update_nlist) + loopStart = PREPAIR_LOOP + else + loopStart = PAIR_LOOP + endif - !! if_mpi_gather_stuff_for_prepair - !! do_prepair_loop_if_needed - !! if_mpi_scatter_stuff_from_prepair - !! if_mpi_gather_stuff_from_prepair_to_main_loop - - !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>> + do loop = loopStart, loopEnd + + ! See if we need to update neighbor lists + ! (but only on the first time through): + if (loop .eq. loopStart) then #ifdef IS_MPI + call checkNeighborList(nGroupsInRow, q_group_row, listSkin, & + update_nlist) +#else + call checkNeighborList(nGroups, q_group, listSkin, & + update_nlist) +#endif + endif if (update_nlist) then - - !! save current configuration, construct neighbor list, - !! and calculate forces - - call saveNeighborList(nGroup, q_group) - + !! save current configuration and construct neighbor list +#ifdef IS_MPI + call saveNeighborList(nGroupsInRow, q_group_row) +#else + call saveNeighborList(nGroups, q_group) +#endif neighborListSize = size(list) - nlist = 0 - - do i = 1, nrow_group - point(i) = nlist + 1 - - do j = 1, ncol_group - - call get_interatomic_vector(q_group_Row(:,i), & - q_group_Col(:,j), d_grp, rgrpsq) - - if (rgrpsq < rlistsq) then - nlist = nlist + 1 - - if (nlist > neighborListSize) then - call expandNeighborList(nGroup, listerror) - if (listerror /= 0) then - error = -1 - write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." - return - end if - neighborListSize = size(list) - endif - - list(nlist) = j - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - prepair_inner: do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - if (skipThisPair(atom1, atom2)) cycle prepair_inner - - call get_interatomic_vector(q_Row(:,atom1), & - q_Col(:,atom2), d_atm, ratmsq) - - call do_prepair(atom1, atom2, ratmsq, d_atm, & - rgrpsq, d_grp, do_pot, do_stress, & - u_l, A, f, t, pot_local) - - enddo prepair_inner - enddo - end if - enddo - enddo - point(nrow_group + 1) = nlist + 1 - - else !! (of update_check) - - ! use the list to find the neighbors - do i = 1, nrow_group - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check that group i has neighbors - if (jbeg .le. jend) then - - do jnab = jbeg, jend - j = list(jnab) - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - call get_interatomic_vector(q_Row(:,atom1), & - q_Col(:,atom2), d_atm, ratmsq) - - call do_prepair(atom1, atom2, ratmsq, d_atm, & - rgrpsq, d_grp, do_pot, do_stress, & - u_l, A, f, t, pot_local) - - enddo - enddo - enddo - endif - enddo + nlist = 0 endif + istart = 1 +#ifdef IS_MPI + iend = nGroupsInRow #else + iend = nGroups - 1 +#endif + outer: do i = istart, iend - if (update_nlist) then + if (update_nlist) point(i) = nlist + 1 - !! save current configuration, construct neighbor list, - !! and calculate forces + n_in_i = groupStartRow(i+1) - groupStartRow(i) - call saveNeighborList(nGroup, q_group) + if (update_nlist) then +#ifdef IS_MPI + jstart = 1 + jend = nGroupsInCol +#else + jstart = i+1 + jend = nGroups +#endif + else + jstart = point(i) + jend = point(i+1) - 1 + ! make sure group i has neighbors + if (jstart .gt. jend) cycle outer + endif - neighborListSize = size(list) - nlist = 0 - - do i = 1, nGroup-1 - point(i) = nlist + 1 - - do j = i+1, nGroup - - call get_interatomic_vector(q_group(:,i), & - q_group(:,j), d_grp, rgrpsq) - - if (rgrpsq < rlistsq) then + do jnab = jstart, jend + if (update_nlist) then + j = jnab + else + j = list(jnab) + endif + +#ifdef IS_MPI + call get_interatomic_vector(q_group_Row(:,i), & + q_group_Col(:,j), d_grp, rgrpsq) +#else + call get_interatomic_vector(q_group(:,i), & + q_group(:,j), d_grp, rgrpsq) +#endif + + if (rgrpsq < rlistsq) then + if (update_nlist) then nlist = nlist + 1 if (nlist > neighborListSize) then - call expandNeighborList(nGroup, listerror) +#ifdef IS_MPI + call expandNeighborList(nGroupsInRow, listerror) +#else + call expandNeighborList(nGroups, listerror) +#endif if (listerror /= 0) then error = -1 write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." @@ -598,368 +562,130 @@ contains endif list(nlist) = j - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - prepair_inner: do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - if (skipThisPair(atom1, atom2)) cycle prepair_inner - - call get_interatomic_vector(q(:,atom1), & - q(:,atom2), d_atm, ratmsq) - - call do_prepair(atom1, atom2, ratmsq, d_atm, & - rgrpsq, d_grp, do_pot, do_stress, & - u_l, A, f, t, pot) - - enddo prepair_inner - enddo - end if - enddo - enddo - point(nGroup) = nlist + 1 - - else !! (of update_check) - - ! use the list to find the neighbors - do i = 1, nGroup-1 - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check that group i has neighbors - if (jbeg .le. jend) then - - do jnab = jbeg, jend - j = list(jnab) - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - call get_interatomic_vector(q(:,atom1), & - q(:,atom2), d_atm, ratmsq) - - call do_prepair(atom1, atom2, ratmsq, d_atm, & - rgrpsq, d_grp, do_pot, do_stress, & - u_l, A, f, t, pot) - - enddo - enddo - enddo - endif - enddo - endif - -#endif - - !! Do rest of preforce calculations - !! do necessary preforce calculations - call do_preforce(nlocal,pot) - ! we have already updated the neighbor list set it to false... - update_nlist = .false. - else - !! See if we need to update neighbor lists for non pre-pair - call checkNeighborList(nGroup, q_group, listSkin, update_nlist) - endif - - !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>> - -#ifdef IS_MPI - - if (update_nlist) then - - !! save current configuration, construct neighbor list, - !! and calculate forces - - call saveNeighborList(nGroup, q_group) - - neighborListSize = size(list) - nlist = 0 - - do i = 1, nrow_group - point(i) = nlist + 1 - - do j = 1, ncol_group - - call get_interatomic_vector(q_group_Row(:,i), & - q_group_Col(:,j), d_grp, rgrpsq) - - if (rgrpsq < rlistsq) then - nlist = nlist + 1 - - if (nlist > neighborListSize) then - call expandNeighborList(nGroup, listerror) - if (listerror /= 0) then - error = -1 - write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." - return - end if - neighborListSize = size(list) endif - list(nlist) = j - - vab = 0.0d0 - call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & - in_switching_region) - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - inner: do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - if (skipThisPair(atom1, atom2)) cycle inner - - call get_interatomic_vector(q_Row(:,atom1), & - q_Col(:,atom2), d_atm, ratmsq) - - call do_pair(atom1, atom2, ratmsq, d_atm, sw, & - do_pot, do_stress, & - u_l, A, f, t, pot_local, vpair) - - vab = vab + vpair - enddo inner - enddo - - if (in_switching_region) then - swderiv = vab*dswdr/rgrp - - do ia=groupStart(i), groupStart(i+1)-1 - atom1=groupList(ia) - mf = mfact(atom1) - f_Row(1,atom1) = f_Row(1,atom1) - swderiv*d_grp(1)*mf - f_Row(2,atom1) = f_Row(2,atom1) - swderiv*d_grp(2)*mf - f_Row(3,atom1) = f_Row(3,atom1) - swderiv*d_grp(3)*mf - enddo - - do jb=groupStart(j), groupStart(j+1)-1 - atom2=groupList(jb) - mf = mfact(atom2) - f_Col(1,atom2) = f_Col(1,atom2) + swderiv*d_grp(1)*mf - f_Col(2,atom2) = f_Col(2,atom2) + swderiv*d_grp(2)*mf - f_Col(3,atom2) = f_Col(3,atom2) + swderiv*d_grp(3)*mf - enddo + if (loop .eq. PAIR_LOOP) then + vij = 0.0d0 + fij(1:3) = 0.0d0 endif - - end if - enddo - enddo - point(nrow_group + 1) = nlist + 1 - - else !! (of update_check) - - ! use the list to find the neighbors - do i = 1, nrow_group - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check that group i has neighbors - if (jbeg .le. jend) then - - do jnab = jbeg, jend - j = list(jnab) - - call get_interatomic_vector(q_group_Row(:,i), & - q_group_Col(:,j), d_grp, rgrpsq) - vab = 0.0d0 call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & in_switching_region) - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) + n_in_j = groupStartCol(j+1) - groupStartCol(j) + + do ia = groupStartRow(i), groupStartRow(i+1)-1 - do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) + atom1 = groupListRow(ia) + + inner: do jb = groupStartCol(j), groupStartCol(j+1)-1 - call get_interatomic_vector(q_Row(:,atom1), & - q_Col(:,atom2), d_atm, ratmsq) - - call do_pair(atom1, atom2, ratmsq, d_atm, sw, & - do_pot, do_stress, & - u_l, A, f, t, pot_local, vpair) + atom2 = groupListCol(jb) - vab = vab + vpair - - enddo - enddo - - if (in_switching_region) then - swderiv = vab*dswdr/rgrp - - do ia=groupStart(i), groupStart(i+1)-1 - atom1=groupList(ia) - mf = mfact(atom1) - f_Row(1,atom1) = f_Row(1,atom1) - swderiv*d_grp(1)*mf - f_Row(2,atom1) = f_Row(2,atom1) - swderiv*d_grp(2)*mf - f_Row(3,atom1) = f_Row(3,atom1) - swderiv*d_grp(3)*mf - enddo - - do jb=groupStart(j), groupStart(j+1)-1 - atom2=groupList(jb) - mf = mfact(atom2) - f_Col(1,atom2) = f_Col(1,atom2) + swderiv*d_grp(1)*mf - f_Col(2,atom2) = f_Col(2,atom2) + swderiv*d_grp(2)*mf - f_Col(3,atom2) = f_Col(3,atom2) + swderiv*d_grp(3)*mf - enddo - endif + if (skipThisPair(atom1, atom2)) cycle inner - enddo - endif - enddo - endif - + if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then + d_atm(1:3) = d_grp(1:3) + ratmsq = rgrpsq + else +#ifdef IS_MPI + call get_interatomic_vector(q_Row(:,atom1), & + q_Col(:,atom2), d_atm, ratmsq) #else + call get_interatomic_vector(q(:,atom1), & + q(:,atom2), d_atm, ratmsq) +#endif + endif - if (update_nlist) then - - !! save current configuration, construct neighbor list, - !! and calculate forces - - call saveNeighborList(nGroup, q_group) - - neighborListSize = size(list) - nlist = 0 - - do i = 1, nGroup-1 - point(i) = nlist + 1 - - do j = i+1, nGroup - - call get_interatomic_vector(q_group(:,i), & - q_group(:,j), d_grp, rgrpsq) - - if (rgrpsq < rlistsq) then - nlist = nlist + 1 - - if (nlist > neighborListSize) then - call expandNeighborList(nGroup, listerror) - if (listerror /= 0) then - error = -1 - write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." - return - end if - neighborListSize = size(list) - endif - - list(nlist) = j + if (loop .eq. PREPAIR_LOOP) then +#ifdef IS_MPI + call do_prepair(atom1, atom2, ratmsq, d_atm, sw, & + rgrpsq, d_grp, do_pot, do_stress, & + u_l, A, f, t, pot_local) +#else + call do_prepair(atom1, atom2, ratmsq, d_atm, sw, & + rgrpsq, d_grp, do_pot, do_stress, & + u_l, A, f, t, pot) +#endif + else +#ifdef IS_MPI + call do_pair(atom1, atom2, ratmsq, d_atm, sw, & + do_pot, & + u_l, A, f, t, pot_local, vpair, fpair) +#else + call do_pair(atom1, atom2, ratmsq, d_atm, sw, & + do_pot, & + u_l, A, f, t, pot, vpair, fpair) +#endif - vab = 0.0d0 - call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & - in_switching_region) + vij = vij + vpair + fij(1:3) = fij(1:3) + fpair(1:3) + endif + enddo inner + enddo - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - inner: do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) + if (loop .eq. PAIR_LOOP) then + if (in_switching_region) then + swderiv = vij*dswdr/rgrp + fij(1) = fij(1) + swderiv*d_grp(1) + fij(2) = fij(2) + swderiv*d_grp(2) + fij(3) = fij(3) + swderiv*d_grp(3) - if (skipThisPair(atom1, atom2)) cycle inner + do ia=groupStartRow(i), groupStartRow(i+1)-1 + atom1=groupListRow(ia) + mf = mfactRow(atom1) +#ifdef IS_MPI + f_Row(1,atom1) = f_Row(1,atom1) + swderiv*d_grp(1)*mf + f_Row(2,atom1) = f_Row(2,atom1) + swderiv*d_grp(2)*mf + f_Row(3,atom1) = f_Row(3,atom1) + swderiv*d_grp(3)*mf +#else + f(1,atom1) = f(1,atom1) + swderiv*d_grp(1)*mf + f(2,atom1) = f(2,atom1) + swderiv*d_grp(2)*mf + f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf +#endif + enddo - call get_interatomic_vector(q(:,atom1), & - q(:,atom2), d_atm, ratmsq) - - call do_pair(atom1, atom2, ratmsq, d_atm, sw, & - do_pot, do_stress, & - u_l, A, f, t, pot, vpair) - - vab = vab + vpair - - enddo inner - enddo - - if (in_switching_region) then - swderiv = vab*dswdr/rgrp - do ia=groupStart(i), groupStart(i+1)-1 - atom1=groupList(ia) - mf = mfact(atom1) - f(1,atom1) = f(1,atom1) - swderiv*d_grp(1)*mf - f(2,atom1) = f(2,atom1) - swderiv*d_grp(2)*mf - f(3,atom1) = f(3,atom1) - swderiv*d_grp(3)*mf - enddo + do jb=groupStartCol(j), groupStartCol(j+1)-1 + atom2=groupListCol(jb) + mf = mfactCol(atom2) +#ifdef IS_MPI + f_Col(1,atom2) = f_Col(1,atom2) - swderiv*d_grp(1)*mf + f_Col(2,atom2) = f_Col(2,atom2) - swderiv*d_grp(2)*mf + f_Col(3,atom2) = f_Col(3,atom2) - swderiv*d_grp(3)*mf +#else + f(1,atom2) = f(1,atom2) - swderiv*d_grp(1)*mf + f(2,atom2) = f(2,atom2) - swderiv*d_grp(2)*mf + f(3,atom2) = f(3,atom2) - swderiv*d_grp(3)*mf +#endif + enddo + endif - do jb=groupStart(j), groupStart(j+1)-1 - atom2=groupList(jb) - mf = mfact(atom2) - f(1,atom2) = f(1,atom2) + swderiv*d_grp(1)*mf - f(2,atom2) = f(2,atom2) + swderiv*d_grp(2)*mf - f(3,atom2) = f(3,atom2) + swderiv*d_grp(3)*mf - enddo + if (do_stress) call add_stress_tensor(d_grp, fij) endif - end if enddo - enddo - point(nGroup) = nlist + 1 + enddo outer - else !! (of update_check) - - ! use the list to find the neighbors - do i = 1, nGroup-1 - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check that group i has neighbors - if (jbeg .le. jend) then + if (update_nlist) then +#ifdef IS_MPI + point(nGroupsInRow + 1) = nlist + 1 +#else + point(nGroups) = nlist + 1 +#endif + if (loop .eq. PREPAIR_LOOP) then + ! we just did the neighbor list update on the first + ! pass, so we don't need to do it + ! again on the second pass + update_nlist = .false. + endif + endif - do jnab = jbeg, jend - j = list(jnab) - - call get_interatomic_vector(q_group(:,i), & - q_group(:,j), d_grp, rgrpsq) - - vab = 0.0d0 - call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & - in_switching_region) - - do ia = groupStart(i), groupStart(i+1)-1 - atom1 = groupList(ia) - - do jb = groupStart(j), groupStart(j+1)-1 - atom2 = groupList(jb) - - call get_interatomic_vector(q(:,atom1), & - q(:,atom2), d_atm, ratmsq) - - call do_pair(atom1, atom2, ratmsq, d_atm, sw, & - do_pot, do_stress, & - u_l, A, f, t, pot, vpair) - - vab = vab + vpair - - enddo - enddo - - if (in_switching_region) then - swderiv = vab*dswdr/rgrp - - do ia=groupStart(i), groupStart(i+1)-1 - atom1=groupList(ia) - mf = mfact(atom1) - f(1,atom1) = f(1,atom1) - swderiv*d_grp(1)*mf - f(2,atom1) = f(2,atom1) - swderiv*d_grp(2)*mf - f(3,atom1) = f(3,atom1) - swderiv*d_grp(3)*mf - enddo - - do jb=groupStart(j), groupStart(j+1)-1 - atom2=groupList(jb) - mf = mfact(atom2) - f(1,atom2) = f(1,atom2) + swderiv*d_grp(1)*mf - f(2,atom2) = f(2,atom2) + swderiv*d_grp(2)*mf - f(3,atom2) = f(3,atom2) + swderiv*d_grp(3)*mf - enddo - endif - enddo - endif - enddo - endif - -#endif + if (loop .eq. PREPAIR_LOOP) then + call do_preforce(nlocal, pot) + endif + + enddo - ! phew, done with main loop. - !! Do timing #ifdef PROFILE call cpu_time(forceTimeFinal) @@ -970,25 +696,25 @@ contains !!distribute forces f_temp = 0.0_dp - call scatter(f_Row,f_temp,plan_row3d) + call scatter(f_Row,f_temp,plan_atom_row_3d) do i = 1,nlocal f(1:3,i) = f(1:3,i) + f_temp(1:3,i) end do f_temp = 0.0_dp - call scatter(f_Col,f_temp,plan_col3d) + call scatter(f_Col,f_temp,plan_atom_col_3d) do i = 1,nlocal f(1:3,i) = f(1:3,i) + f_temp(1:3,i) end do if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then t_temp = 0.0_dp - call scatter(t_Row,t_temp,plan_row3d) + call scatter(t_Row,t_temp,plan_atom_row_3d) do i = 1,nlocal t(1:3,i) = t(1:3,i) + t_temp(1:3,i) end do t_temp = 0.0_dp - call scatter(t_Col,t_temp,plan_col3d) + call scatter(t_Col,t_temp,plan_atom_col_3d) do i = 1,nlocal t(1:3,i) = t(1:3,i) + t_temp(1:3,i) @@ -997,7 +723,7 @@ contains if (do_pot) then ! scatter/gather pot_row into the members of my column - call scatter(pot_Row, pot_Temp, plan_row) + call scatter(pot_Row, pot_Temp, plan_atom_row) ! scatter/gather pot_local into all other procs ! add resultant to get total pot @@ -1007,7 +733,7 @@ contains pot_Temp = 0.0_DP - call scatter(pot_Col, pot_Temp, plan_col) + call scatter(pot_Col, pot_Temp, plan_atom_col) do i = 1, nlocal pot_local = pot_local + pot_Temp(i) enddo @@ -1020,8 +746,8 @@ contains if (FF_uses_RF .and. SIM_uses_RF) then #ifdef IS_MPI - call scatter(rf_Row,rf,plan_row3d) - call scatter(rf_Col,rf_Temp,plan_col3d) + call scatter(rf_Row,rf,plan_atom_row_3d) + call scatter(rf_Col,rf_Temp,plan_atom_col_3d) do i = 1,nlocal rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i) end do @@ -1081,22 +807,21 @@ contains endif #endif - - + end subroutine do_force_loop - - subroutine do_pair(i, j, rijsq, d, sw, do_pot, do_stress, & - u_l, A, f, t, pot, vpair) + subroutine do_pair(i, j, rijsq, d, sw, do_pot, & + u_l, A, f, t, pot, vpair, fpair) real( kind = dp ) :: pot, vpair, sw + real( kind = dp ), dimension(3) :: fpair real( kind = dp ), dimension(nLocal) :: mfact real( kind = dp ), dimension(3,nLocal) :: u_l real( kind = dp ), dimension(9,nLocal) :: A real( kind = dp ), dimension(3,nLocal) :: f real( kind = dp ), dimension(3,nLocal) :: t - logical, intent(inout) :: do_pot, do_stress + logical, intent(inout) :: do_pot integer, intent(in) :: i, j real ( kind = dp ), intent(inout) :: rijsq real ( kind = dp ) :: r @@ -1104,11 +829,10 @@ contains integer :: me_i, me_j r = sqrt(rijsq) + vpair = 0.0d0 + fpair(1:3) = 0.0d0 #ifdef IS_MPI - if (tagRow(i) .eq. tagColumn(j)) then - write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j) - endif me_i = atid_row(i) me_j = atid_col(j) #else @@ -1119,8 +843,7 @@ contains if (FF_uses_LJ .and. SIM_uses_LJ) then if ( PropertyMap(me_i)%is_LJ .and. PropertyMap(me_j)%is_LJ ) then - call do_lj_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, & - do_stress) + call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot) endif endif @@ -1128,8 +851,7 @@ contains if (FF_uses_charges .and. SIM_uses_charges) then if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then - call do_charge_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, & - do_stress) + call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot) endif endif @@ -1137,11 +859,11 @@ contains if (FF_uses_dipoles .and. SIM_uses_dipoles) then if ( PropertyMap(me_i)%is_DP .and. PropertyMap(me_j)%is_DP) then - call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, & - do_pot, do_stress) + call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, & + do_pot) if (FF_uses_RF .and. SIM_uses_RF) then call accumulate_rf(i, j, r, u_l, sw) - call rf_correct_forces(i, j, d, r, u_l, sw, f, do_stress) + call rf_correct_forces(i, j, d, r, u_l, sw, f, fpair) endif endif @@ -1150,8 +872,8 @@ contains if (FF_uses_Sticky .and. SIM_uses_sticky) then if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then - call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, pot, A, f, t, & - do_pot, do_stress) + call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, A, f, t, & + do_pot) endif endif @@ -1160,8 +882,8 @@ contains if (FF_uses_GB .and. SIM_uses_GB) then if ( PropertyMap(me_i)%is_GB .and. PropertyMap(me_j)%is_GB) then - call do_gb_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, & - do_pot, do_stress) + call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, & + do_pot) endif endif @@ -1169,17 +891,18 @@ contains if (FF_uses_EAM .and. SIM_uses_EAM) then if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then - call do_eam_pair(i, j, d, r, rijsq, sw, vpair, pot, f, & - do_pot, do_stress) + call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, & + do_pot) endif endif end subroutine do_pair - subroutine do_prepair(i, j, rijsq, d, rcijsq, dc, & + subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, & do_pot, do_stress, u_l, A, f, t, pot) - real( kind = dp ) :: pot + + real( kind = dp ) :: pot, sw real( kind = dp ), dimension(3,nLocal) :: u_l real (kind=dp), dimension(9,nLocal) :: A real (kind=dp), dimension(3,nLocal) :: f @@ -1204,33 +927,24 @@ contains endif -#ifdef IS_MPI - if (tagRow(i) .eq. tagColumn(j)) then - write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j) - endif - +#ifdef IS_MPI me_i = atid_row(i) - me_j = atid_col(j) - -#else - + me_j = atid_col(j) +#else me_i = atid(i) - me_j = atid(j) - + me_j = atid(j) #endif - + if (FF_uses_EAM .and. SIM_uses_EAM) then - + if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) & call calc_EAM_prepair_rho(i, j, d, r, rijsq ) - + endif end subroutine do_prepair - - - - + + subroutine do_preforce(nlocal,pot) integer :: nlocal real( kind = dp ) :: pot @@ -1355,7 +1069,7 @@ contains #ifdef IS_MPI !! in MPI, we have to look up the unique IDs for each atom - unique_id_1 = tagRow(atom1) + unique_id_1 = AtomRowToGlobal(atom1) #else !! in the normal loop, the atom numbers are unique unique_id_1 = atom1 @@ -1374,7 +1088,7 @@ contains end if #ifdef IS_MPI - unique_id_2 = tagColumn(atom2) + unique_id_2 = AtomColToGlobal(atom2) #else unique_id_2 = atom2 #endif @@ -1409,19 +1123,10 @@ contains endif enddo - do i = 1, nExcludes_local - if (excludesLocal(1,i) == unique_id_1) then - if (excludesLocal(2,i) == unique_id_2) then - skip_it = .true. - return - endif - else - if (excludesLocal(1,i) == unique_id_2) then - if (excludesLocal(2,i) == unique_id_1) then - skip_it = .true. - return - endif - endif + do i = 1, nSkipsForAtom(atom1) + if (skipsForAtom(atom1, i) .eq. unique_id_2) then + skip_it = .true. + return endif end do @@ -1452,5 +1157,29 @@ contains #endif !! This cleans componets of force arrays belonging only to fortran + + subroutine add_stress_tensor(dpair, fpair) + + real( kind = dp ), dimension(3), intent(in) :: dpair, fpair + + ! because the d vector is the rj - ri vector, and + ! because fx, fy, fz are the force on atom i, we need a + ! negative sign here: + + tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1) + tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2) + tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3) + tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1) + tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2) + tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3) + tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1) + tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2) + tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3) + + virial_Temp = virial_Temp + & + (tau_Temp(1) + tau_Temp(5) + tau_Temp(9)) + + end subroutine add_stress_tensor end module do_Forces +