--- trunk/OOPSE/libmdtools/do_Forces.F90 2004/04/15 16:18:26 1113 +++ trunk/OOPSE/libmdtools/do_Forces.F90 2004/05/07 21:35:05 1150 @@ -4,13 +4,14 @@ !! @author Charles F. Vardeman II !! @author Matthew Meineke -!! @version $Id: do_Forces.F90,v 1.49 2004-04-15 16:18:26 tim Exp $, $Date: 2004-04-15 16:18:26 $, $Name: not supported by cvs2svn $, $Revision: 1.49 $ +!! @version $Id: do_Forces.F90,v 1.54 2004-05-07 21:35:04 gezelter Exp $, $Date: 2004-05-07 21:35:04 $, $Name: not supported by cvs2svn $, $Revision: 1.54 $ module do_Forces use force_globals use simulation use definitions use atype_module + use switcheroo use neighborLists use lj use sticky_pair @@ -30,6 +31,7 @@ module do_Forces #define __FORTRAN90 #include "fForceField.h" +#include "fSwitchingFunction.h" logical, save :: haveRlist = .false. logical, save :: haveNeighborList = .false. @@ -55,13 +57,13 @@ module do_Forces logical, save :: SIM_requires_prepair_calc logical, save :: SIM_uses_directional_atoms logical, save :: SIM_uses_PBC + logical, save :: SIM_uses_molecular_cutoffs real(kind=dp), save :: rlist, rlistsq public :: init_FF public :: do_force_loop public :: setRlistDF - #ifdef PROFILE public :: getforcetime @@ -160,6 +162,7 @@ contains SIM_requires_prepair_calc = SimRequiresPrepairCalc() SIM_uses_directional_atoms = SimUsesDirectionalAtoms() SIM_uses_PBC = SimUsesPBC() + !SIM_uses_molecular_cutoffs = SimUsesMolecularCutoffs() haveSIMvariables = .true. @@ -277,6 +280,12 @@ contains !! Assume sanity (for the sake of argument) haveSaneForceField = .true. + !! + if (FF_uses_charges) then + dielect = getDielect() + call initialize_charge(dielect) + endif + !! check to make sure the FF_uses_RF setting makes sense @@ -356,16 +365,20 @@ contains endif haveNeighborList = .true. endif + + end subroutine init_FF !! Does force loop over i,j pairs. Calls do_pair to calculates forces. !-------------------------------------------------------------> - subroutine do_force_loop(q, A, u_l, f, t, tau, pot, do_pot_c, do_stress_c, & - error) + 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 + !! molecular center-of-mass position array + real ( kind = dp ), dimension(3,nGroup) :: q_group !! Rotation Matrix for each long range particle in simulation. real( kind = dp), dimension(9,nLocal) :: A !! Unit vectors for dipoles (lab frame) @@ -381,18 +394,23 @@ contains logical ( kind = 2) :: do_pot_c, do_stress_c logical :: do_pot logical :: do_stress + logical :: in_switching_region #ifdef IS_MPI real( kind = DP ) :: pot_local integer :: nrow integer :: ncol integer :: nprocs + integer :: nrow_group + integer :: ncol_group #endif integer :: natoms logical :: update_nlist integer :: i, j, jbeg, jend, jnab + integer :: ia, jb, atom1, atom2 integer :: nlist - real( kind = DP ) :: rijsq - real(kind=dp),dimension(3) :: d + real( kind = DP ) :: ratmsq, rgrpsq, rgrp, vpair, vab + real( kind = DP ) :: sw, dswdr, swderiv, mf + real(kind=dp),dimension(3) :: d_atm, d_grp real(kind=dp) :: rfpot, mu_i, virial integer :: me_i, me_j logical :: is_dp_i @@ -402,17 +420,19 @@ contains integer :: propPack_i, propPack_j real(kind=dp) :: listSkin = 1.0 - + !! initialize local variables - + #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) #else natoms = nlocal #endif - + call doReadyCheck(localError) if ( localError .ne. 0 ) then call handleError("do_force_loop", "Not Initialized") @@ -420,16 +440,19 @@ contains return end if call zero_work_arrays() - + do_pot = do_pot_c do_stress = do_stress_c - + ! Gather all information needed by all force loops: #ifdef IS_MPI + + call gather(q, q_Row, plan_row3d) + call gather(q, q_Col, plan_col3d) - call gather(q,q_Row,plan_row3d) - call gather(q,q_Col,plan_col3d) + call gather(q_group, q_group_Row, plan_row_Group_3d) + call gather(q_group, q_group_Col, plan_col_Group_3d) if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then call gather(u_l,u_l_Row,plan_row3d) @@ -440,200 +463,241 @@ contains endif #endif - -!! Begin force loop timing: + + !! Begin force loop timing: #ifdef PROFILE call cpu_time(forceTimeInitial) nloops = nloops + 1 #endif - + if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then !! See if we need to update neighbor lists - call checkNeighborList(nlocal, q, listSkin, update_nlist) + + call checkNeighborList(nGroup, q_group, listSkin, update_nlist) + !! 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----------->>>>>>>>>>>>>>>>>>>>>>>>>>> + + !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>> #ifdef IS_MPI - - if (update_nlist) then - !! save current configuration, construct neighbor list, - !! and calculate forces - call saveNeighborList(nlocal, q) - - neighborListSize = size(list) - nlist = 0 - - do i = 1, nrow - point(i) = nlist + 1 + if (update_nlist) then - prepair_inner: do j = 1, ncol - - if (skipThisPair(i,j)) cycle prepair_inner - - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) - - if (rijsq < rlistsq) then - - nlist = nlist + 1 + !! 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 - if (nlist > neighborListSize) then - call expandNeighborList(nlocal, 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 + call get_interatomic_vector(q_group_Row(:,i), & + q_group_Col(:,j), d_grp, rgrpsq) - list(nlist) = j - call do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot_local) - endif - enddo prepair_inner - enddo + 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) - point(nrow + 1) = nlist + 1 - - else !! (of update_check) + 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) - ! use the list to find the neighbors - do i = 1, nrow - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check thiat molecule i has neighbors - if (jbeg .le. jend) then - - do jnab = jbeg, jend - j = list(jnab) - - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) - call do_prepair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot_local) - + enddo prepair_inner + enddo + end if enddo - endif - enddo - endif - -#else - - if (update_nlist) then + 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 + endif - ! save current configuration, contruct neighbor list, - ! and calculate forces - call saveNeighborList(natoms, q) - - neighborListSize = size(list) - - nlist = 0 +#else - do i = 1, natoms-1 - point(i) = nlist + 1 + if (update_nlist) then - prepair_inner: do j = i+1, natoms + !! 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 - if (skipThisPair(i,j)) cycle prepair_inner - - call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) - - - if (rijsq < rlistsq) then - - - nlist = nlist + 1 - - if (nlist > neighborListSize) then - call expandNeighborList(natoms, 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 + do j = i+1, nGroup - list(nlist) = j + call get_interatomic_vector(q_group(:,i), & + q_group(:,j), d_grp, rgrpsq) - call do_prepair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) + 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(:,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 prepair_inner - enddo - - point(natoms) = nlist + 1 + enddo + endif - else !! (update) - - ! use the list to find the neighbors - do i = 1, natoms-1 - JBEG = POINT(i) - JEND = POINT(i+1) - 1 - ! check thiat molecule i has neighbors - if (jbeg .le. jend) then - - do jnab = jbeg, jend - j = list(jnab) - - call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) - call do_prepair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) - - 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. + + !! 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(nlocal, q, listSkin, update_nlist) + call checkNeighborList(nGroup, q_group, listSkin, update_nlist) endif - - - - - -!---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - - + + !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>> + #ifdef IS_MPI if (update_nlist) then + !! save current configuration, construct neighbor list, !! and calculate forces - call saveNeighborList(nlocal, q) + call saveNeighborList(nGroup, q_group) + neighborListSize = size(list) nlist = 0 - do i = 1, nrow - + do i = 1, nrow_group point(i) = nlist + 1 - inner: do j = 1, ncol + do j = 1, ncol_group - if (skipThisPair(i,j)) cycle inner + call get_interatomic_vector(q_group_Row(:,i), & + q_group_Col(:,j), d_grp, rgrpsq) - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) - - if (rijsq < rlistsq) then - + if (rgrpsq < rlistsq) then nlist = nlist + 1 if (nlist > neighborListSize) then - call expandNeighborList(nlocal, listerror) + call expandNeighborList(nGroup, listerror) if (listerror /= 0) then error = -1 write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." @@ -643,65 +707,142 @@ contains endif list(nlist) = j - - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot_local) - endif - enddo inner - enddo + 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 - point(nrow + 1) = nlist + 1 + 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 + + 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 + do i = 1, nrow_group JBEG = POINT(i) JEND = POINT(i+1) - 1 - ! check thiat molecule i has neighbors + ! 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) + + 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_pair(atom1, atom2, ratmsq, d_atm, sw, & + do_pot, do_stress, & + u_l, A, f, t, pot_local, 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_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 - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot_local) - enddo endif enddo endif #else - - if (update_nlist) then - ! save current configuration, contruct neighbor list, - ! and calculate forces - call saveNeighborList(natoms, q) + if (update_nlist) then + !! save current configuration, construct neighbor list, + !! and calculate forces + + call saveNeighborList(nGroup, q_group) + neighborListSize = size(list) - - nlist = 0 + nlist = 0 - do i = 1, natoms-1 + do i = 1, nGroup-1 point(i) = nlist + 1 - inner: do j = i+1, natoms + do j = i+1, nGroup - if (skipThisPair(i,j)) cycle inner - - call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) - - - if (rijsq < rlistsq) then - + 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(natoms, listerror) + call expandNeighborList(nGroup, listerror) if (listerror /= 0) then error = -1 write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." @@ -711,57 +852,135 @@ contains endif list(nlist) = j + + vab = 0.0d0 + call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & + in_switching_region) - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) - - endif - enddo inner + 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(:,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=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 + + end if + enddo enddo + point(nGroup) = nlist + 1 - point(natoms) = nlist + 1 + else !! (of update_check) - else !! (update) - ! use the list to find the neighbors - do i = 1, natoms-1 + do i = 1, nGroup-1 JBEG = POINT(i) JEND = POINT(i+1) - 1 - ! check thiat molecule i has neighbors + ! check that group i has neighbors if (jbeg .le. jend) then do jnab = jbeg, jend j = list(jnab) - call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) + 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 ! phew, done with main loop. - -!! Do timing + + !! Do timing #ifdef PROFILE call cpu_time(forceTimeFinal) forceTime = forceTime + forceTimeFinal - forceTimeInitial -#endif - - +#endif + #ifdef IS_MPI !!distribute forces - + f_temp = 0.0_dp call scatter(f_Row,f_temp,plan_row3d) 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) do i = 1,nlocal @@ -785,7 +1004,7 @@ contains if (do_pot) then ! scatter/gather pot_row into the members of my column call scatter(pot_Row, pot_Temp, plan_row) - + ! scatter/gather pot_local into all other procs ! add resultant to get total pot do i = 1, nlocal @@ -793,19 +1012,19 @@ contains enddo pot_Temp = 0.0_DP - + call scatter(pot_Col, pot_Temp, plan_col) do i = 1, nlocal pot_local = pot_local + pot_Temp(i) enddo - - endif + + endif #endif - + if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then 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) @@ -815,18 +1034,18 @@ contains #endif do i = 1, nLocal - + rfpot = 0.0_DP #ifdef IS_MPI me_i = atid_row(i) #else me_i = atid(i) #endif - + if (PropertyMap(me_i)%is_DP) then - + mu_i = PropertyMap(me_i)%dipole_moment - + !! The reaction field needs to include a self contribution !! to the field: call accumulate_self_rf(i, mu_i, u_l) @@ -843,25 +1062,25 @@ contains enddo endif endif - - + + #ifdef IS_MPI - + if (do_pot) then pot = pot + pot_local !! we assume the c code will do the allreduce to get the total potential !! we could do it right here if we needed to... endif - + if (do_stress) then - call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, & + call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, & mpi_comm_world,mpi_err) call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, & mpi_comm_world,mpi_err) endif - + #else - + if (do_stress) then tau = tau_Temp virial = virial_Temp @@ -870,20 +1089,22 @@ contains #endif - end subroutine do_force_loop - subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) + + subroutine do_pair(i, j, rijsq, d, sw, do_pot, do_stress, & + u_l, A, f, t, pot, vpair) - real( kind = dp ) :: pot + real( kind = dp ) :: pot, vpair, sw + 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 + 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 integer, intent(in) :: i, j - real ( kind = dp ), intent(inout) :: rijsq + real ( kind = dp ), intent(inout) :: rijsq real ( kind = dp ) :: r real ( kind = dp ), intent(inout) :: d(3) integer :: me_i, me_j @@ -904,7 +1125,8 @@ 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, pot, f, do_pot, do_stress) + call do_lj_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, & + do_stress) endif endif @@ -912,7 +1134,8 @@ 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, pot, f, do_pot, do_stress) + call do_charge_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, & + do_stress) endif endif @@ -920,7 +1143,7 @@ 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, pot, u_l, f, t, & + call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, & do_pot, do_stress) if (FF_uses_RF .and. SIM_uses_RF) then call accumulate_rf(i, j, r, u_l) @@ -933,7 +1156,7 @@ 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, A, pot, f, t, & + call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, pot, A, f, t, & do_pot, do_stress) endif @@ -943,7 +1166,7 @@ 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, u_l, pot, f, t, & + call do_gb_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, & do_pot, do_stress) endif @@ -952,16 +1175,16 @@ 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, pot, f, do_pot, do_stress) + call do_eam_pair(i, j, d, r, rijsq, sw, vpair, pot, f, & + do_pot, do_stress) endif endif - + end subroutine do_pair - - - subroutine do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) + subroutine do_prepair(i, j, rijsq, d, rcijsq, dc, & + do_pot, do_stress, u_l, A, f, t, pot) real( kind = dp ) :: pot real( kind = dp ), dimension(3,nLocal) :: u_l real (kind=dp), dimension(9,nLocal) :: A @@ -970,15 +1193,21 @@ contains logical, intent(inout) :: do_pot, do_stress integer, intent(in) :: i, j - real ( kind = dp ), intent(inout) :: rijsq - real ( kind = dp ) :: r - real ( kind = dp ), intent(inout) :: d(3) + real ( kind = dp ), intent(inout) :: rijsq, rcijsq + real ( kind = dp ) :: r, rc + real ( kind = dp ), intent(inout) :: d(3), dc(3) logical :: is_EAM_i, is_EAM_j integer :: me_i, me_j - r = sqrt(rijsq) + + r = sqrt(rijsq) + if (SIM_uses_molecular_cutoffs) then + rc = sqrt(rcijsq) + else + rc = r + endif #ifdef IS_MPI @@ -1008,228 +1237,226 @@ contains - subroutine do_preforce(nlocal,pot) - integer :: nlocal - real( kind = dp ) :: pot - - if (FF_uses_EAM .and. SIM_uses_EAM) then - call calc_EAM_preforce_Frho(nlocal,pot) - endif - - - end subroutine do_preforce - - - subroutine get_interatomic_vector(q_i, q_j, d, r_sq) - - real (kind = dp), dimension(3) :: q_i - real (kind = dp), dimension(3) :: q_j - real ( kind = dp ), intent(out) :: r_sq - real( kind = dp ) :: d(3), scaled(3) - integer i - - d(1:3) = q_j(1:3) - q_i(1:3) - - ! Wrap back into periodic box if necessary - if ( SIM_uses_PBC ) then - - if( .not.boxIsOrthorhombic ) then - ! calc the scaled coordinates. - - scaled = matmul(HmatInv, d) - - ! wrap the scaled coordinates - - scaled = scaled - anint(scaled) - - - ! calc the wrapped real coordinates from the wrapped scaled - ! coordinates - - d = matmul(Hmat,scaled) - - else - ! calc the scaled coordinates. - - do i = 1, 3 - scaled(i) = d(i) * HmatInv(i,i) - - ! wrap the scaled coordinates - - scaled(i) = scaled(i) - anint(scaled(i)) - - ! calc the wrapped real coordinates from the wrapped scaled - ! coordinates - - d(i) = scaled(i)*Hmat(i,i) - enddo - endif - - endif - - r_sq = dot_product(d,d) - - end subroutine get_interatomic_vector - - subroutine zero_work_arrays() - -#ifdef IS_MPI - - q_Row = 0.0_dp - q_Col = 0.0_dp - - u_l_Row = 0.0_dp - u_l_Col = 0.0_dp - - A_Row = 0.0_dp - A_Col = 0.0_dp - - f_Row = 0.0_dp - f_Col = 0.0_dp - f_Temp = 0.0_dp + subroutine do_preforce(nlocal,pot) + integer :: nlocal + real( kind = dp ) :: pot + + if (FF_uses_EAM .and. SIM_uses_EAM) then + call calc_EAM_preforce_Frho(nlocal,pot) + endif + + + end subroutine do_preforce + + + subroutine get_interatomic_vector(q_i, q_j, d, r_sq) + + real (kind = dp), dimension(3) :: q_i + real (kind = dp), dimension(3) :: q_j + real ( kind = dp ), intent(out) :: r_sq + real( kind = dp ) :: d(3), scaled(3) + integer i + + d(1:3) = q_j(1:3) - q_i(1:3) + + ! Wrap back into periodic box if necessary + if ( SIM_uses_PBC ) then - t_Row = 0.0_dp - t_Col = 0.0_dp - t_Temp = 0.0_dp + if( .not.boxIsOrthorhombic ) then + ! calc the scaled coordinates. + + scaled = matmul(HmatInv, d) + + ! wrap the scaled coordinates + + scaled = scaled - anint(scaled) + + + ! calc the wrapped real coordinates from the wrapped scaled + ! coordinates + + d = matmul(Hmat,scaled) + + else + ! calc the scaled coordinates. + + do i = 1, 3 + scaled(i) = d(i) * HmatInv(i,i) + + ! wrap the scaled coordinates + + scaled(i) = scaled(i) - anint(scaled(i)) + + ! calc the wrapped real coordinates from the wrapped scaled + ! coordinates + + d(i) = scaled(i)*Hmat(i,i) + enddo + endif + + endif + + r_sq = dot_product(d,d) + + end subroutine get_interatomic_vector - pot_Row = 0.0_dp - pot_Col = 0.0_dp - pot_Temp = 0.0_dp - - rf_Row = 0.0_dp - rf_Col = 0.0_dp - rf_Temp = 0.0_dp - -#endif + subroutine zero_work_arrays() + +#ifdef IS_MPI + + q_Row = 0.0_dp + q_Col = 0.0_dp + q_group_Row = 0.0_dp + q_group_Col = 0.0_dp + + u_l_Row = 0.0_dp + u_l_Col = 0.0_dp + + A_Row = 0.0_dp + A_Col = 0.0_dp + + f_Row = 0.0_dp + f_Col = 0.0_dp + f_Temp = 0.0_dp + + t_Row = 0.0_dp + t_Col = 0.0_dp + t_Temp = 0.0_dp + + pot_Row = 0.0_dp + pot_Col = 0.0_dp + pot_Temp = 0.0_dp + + rf_Row = 0.0_dp + rf_Col = 0.0_dp + rf_Temp = 0.0_dp + +#endif - if (FF_uses_EAM .and. SIM_uses_EAM) then - call clean_EAM() - endif - - - - - - rf = 0.0_dp - tau_Temp = 0.0_dp - virial_Temp = 0.0_dp - end subroutine zero_work_arrays - - function skipThisPair(atom1, atom2) result(skip_it) - integer, intent(in) :: atom1 - integer, intent(in), optional :: atom2 - logical :: skip_it - integer :: unique_id_1, unique_id_2 - integer :: me_i,me_j - integer :: i - - skip_it = .false. - - !! there are a number of reasons to skip a pair or a particle - !! mostly we do this to exclude atoms who are involved in short - !! range interactions (bonds, bends, torsions), but we also need - !! to exclude some overcounted interactions that result from - !! the parallel decomposition - + if (FF_uses_EAM .and. SIM_uses_EAM) then + call clean_EAM() + endif + + rf = 0.0_dp + tau_Temp = 0.0_dp + virial_Temp = 0.0_dp + end subroutine zero_work_arrays + + function skipThisPair(atom1, atom2) result(skip_it) + integer, intent(in) :: atom1 + integer, intent(in), optional :: atom2 + logical :: skip_it + integer :: unique_id_1, unique_id_2 + integer :: me_i,me_j + integer :: i + + skip_it = .false. + + !! there are a number of reasons to skip a pair or a particle + !! mostly we do this to exclude atoms who are involved in short + !! range interactions (bonds, bends, torsions), but we also need + !! to exclude some overcounted interactions that result from + !! the parallel decomposition + #ifdef IS_MPI - !! in MPI, we have to look up the unique IDs for each atom - unique_id_1 = tagRow(atom1) + !! in MPI, we have to look up the unique IDs for each atom + unique_id_1 = tagRow(atom1) #else - !! in the normal loop, the atom numbers are unique - unique_id_1 = atom1 + !! in the normal loop, the atom numbers are unique + unique_id_1 = atom1 #endif - - !! We were called with only one atom, so just check the global exclude - !! list for this atom - if (.not. present(atom2)) then - do i = 1, nExcludes_global - if (excludesGlobal(i) == unique_id_1) then - skip_it = .true. - return - end if - end do - return - end if - + + !! We were called with only one atom, so just check the global exclude + !! list for this atom + if (.not. present(atom2)) then + do i = 1, nExcludes_global + if (excludesGlobal(i) == unique_id_1) then + skip_it = .true. + return + end if + end do + return + end if + #ifdef IS_MPI - unique_id_2 = tagColumn(atom2) + unique_id_2 = tagColumn(atom2) #else - unique_id_2 = atom2 + unique_id_2 = atom2 #endif - + #ifdef IS_MPI - !! this situation should only arise in MPI simulations - if (unique_id_1 == unique_id_2) then - skip_it = .true. - return - end if - - !! this prevents us from doing the pair on multiple processors - if (unique_id_1 < unique_id_2) then - if (mod(unique_id_1 + unique_id_2,2) == 0) then - skip_it = .true. - return - endif - else - if (mod(unique_id_1 + unique_id_2,2) == 1) then - skip_it = .true. - return - endif - endif + !! this situation should only arise in MPI simulations + if (unique_id_1 == unique_id_2) then + skip_it = .true. + return + end if + + !! this prevents us from doing the pair on multiple processors + if (unique_id_1 < unique_id_2) then + if (mod(unique_id_1 + unique_id_2,2) == 0) then + skip_it = .true. + return + endif + else + if (mod(unique_id_1 + unique_id_2,2) == 1) then + skip_it = .true. + return + endif + endif #endif + + !! the rest of these situations can happen in all simulations: + do i = 1, nExcludes_global + if ((excludesGlobal(i) == unique_id_1) .or. & + (excludesGlobal(i) == unique_id_2)) then + skip_it = .true. + return + 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 + endif + end do + + return + end function skipThisPair - !! the rest of these situations can happen in all simulations: - do i = 1, nExcludes_global - if ((excludesGlobal(i) == unique_id_1) .or. & - (excludesGlobal(i) == unique_id_2)) then - skip_it = .true. - return - 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 - endif - end do - - return - end function skipThisPair - - function FF_UsesDirectionalAtoms() result(doesit) - logical :: doesit - doesit = FF_uses_dipoles .or. FF_uses_sticky .or. & - FF_uses_GB .or. FF_uses_RF - end function FF_UsesDirectionalAtoms - - function FF_RequiresPrepairCalc() result(doesit) - logical :: doesit - doesit = FF_uses_EAM - end function FF_RequiresPrepairCalc - - function FF_RequiresPostpairCalc() result(doesit) - logical :: doesit - doesit = FF_uses_RF - end function FF_RequiresPostpairCalc - + function FF_UsesDirectionalAtoms() result(doesit) + logical :: doesit + doesit = FF_uses_dipoles .or. FF_uses_sticky .or. & + FF_uses_GB .or. FF_uses_RF + end function FF_UsesDirectionalAtoms + + function FF_RequiresPrepairCalc() result(doesit) + logical :: doesit + doesit = FF_uses_EAM + end function FF_RequiresPrepairCalc + + function FF_RequiresPostpairCalc() result(doesit) + logical :: doesit + doesit = FF_uses_RF + end function FF_RequiresPostpairCalc + #ifdef PROFILE - function getforcetime() result(totalforcetime) - real(kind=dp) :: totalforcetime - totalforcetime = forcetime - end function getforcetime + function getforcetime() result(totalforcetime) + real(kind=dp) :: totalforcetime + totalforcetime = forcetime + end function getforcetime #endif - -!! This cleans componets of force arrays belonging only to fortran - + + !! This cleans componets of force arrays belonging only to fortran + end module do_Forces