--- trunk/OOPSE/libmdtools/do_Forces.F90 2003/12/19 20:36:35 891 +++ trunk/OOPSE/libmdtools/do_Forces.F90 2004/04/28 21:39:22 1138 @@ -4,7 +4,7 @@ !! @author Charles F. Vardeman II !! @author Matthew Meineke -!! @version $Id: do_Forces.F90,v 1.40 2003-12-19 20:36:35 mmeineke Exp $, $Date: 2003-12-19 20:36:35 $, $Name: not supported by cvs2svn $, $Revision: 1.40 $ +!! @version $Id: do_Forces.F90,v 1.52 2004-04-28 21:39:22 gezelter Exp $, $Date: 2004-04-28 21:39:22 $, $Name: not supported by cvs2svn $, $Revision: 1.52 $ module do_Forces use force_globals @@ -15,6 +15,7 @@ module do_Forces use lj use sticky_pair use dipole_dipole + use charge_charge use reaction_field use gb_pair use vector_class @@ -30,14 +31,31 @@ module do_Forces #define __FORTRAN90 #include "fForceField.h" - logical, save :: do_forces_initialized = .false., haveRlist = .false. + logical, save :: haveRlist = .false. + logical, save :: haveNeighborList = .false. logical, save :: havePolicies = .false. + logical, save :: haveSIMvariables = .false. + logical, save :: havePropertyMap = .false. + logical, save :: haveSaneForceField = .false. logical, save :: FF_uses_LJ logical, save :: FF_uses_sticky + logical, save :: FF_uses_charges logical, save :: FF_uses_dipoles logical, save :: FF_uses_RF logical, save :: FF_uses_GB logical, save :: FF_uses_EAM + logical, save :: SIM_uses_LJ + logical, save :: SIM_uses_sticky + logical, save :: SIM_uses_charges + logical, save :: SIM_uses_dipoles + logical, save :: SIM_uses_RF + logical, save :: SIM_uses_GB + logical, save :: SIM_uses_EAM + logical, save :: SIM_requires_postpair_calc + 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 @@ -45,6 +63,7 @@ module do_Forces public :: do_force_loop public :: setRlistDF + #ifdef PROFILE public :: getforcetime real, save :: forceTime = 0 @@ -52,6 +71,19 @@ contains integer :: nLoops #endif + type :: Properties + logical :: is_lj = .false. + logical :: is_sticky = .false. + logical :: is_dp = .false. + logical :: is_gb = .false. + logical :: is_eam = .false. + logical :: is_charge = .false. + real(kind=DP) :: charge = 0.0_DP + real(kind=DP) :: dipole_moment = 0.0_DP + end type Properties + + type(Properties), dimension(:),allocatable :: PropertyMap + contains subroutine setRlistDF( this_rlist ) @@ -62,10 +94,141 @@ contains rlistsq = rlist * rlist haveRlist = .true. - if( havePolicies ) do_forces_initialized = .true. end subroutine setRlistDF + subroutine createPropertyMap(status) + integer :: nAtypes + integer :: status + integer :: i + logical :: thisProperty + real (kind=DP) :: thisDPproperty + + status = 0 + + nAtypes = getSize(atypes) + + if (nAtypes == 0) then + status = -1 + return + end if + + if (.not. allocated(PropertyMap)) then + allocate(PropertyMap(nAtypes)) + endif + + do i = 1, nAtypes + call getElementProperty(atypes, i, "is_LJ", thisProperty) + PropertyMap(i)%is_LJ = thisProperty + + call getElementProperty(atypes, i, "is_Charge", thisProperty) + PropertyMap(i)%is_Charge = thisProperty + + if (thisProperty) then + call getElementProperty(atypes, i, "charge", thisDPproperty) + PropertyMap(i)%charge = thisDPproperty + endif + + call getElementProperty(atypes, i, "is_DP", thisProperty) + PropertyMap(i)%is_DP = thisProperty + + if (thisProperty) then + call getElementProperty(atypes, i, "dipole_moment", thisDPproperty) + PropertyMap(i)%dipole_moment = thisDPproperty + endif + + call getElementProperty(atypes, i, "is_Sticky", thisProperty) + PropertyMap(i)%is_Sticky = thisProperty + call getElementProperty(atypes, i, "is_GB", thisProperty) + PropertyMap(i)%is_GB = thisProperty + call getElementProperty(atypes, i, "is_EAM", thisProperty) + PropertyMap(i)%is_EAM = thisProperty + end do + + havePropertyMap = .true. + + end subroutine createPropertyMap + + subroutine setSimVariables() + SIM_uses_LJ = SimUsesLJ() + SIM_uses_sticky = SimUsesSticky() + SIM_uses_charges = SimUsesCharges() + SIM_uses_dipoles = SimUsesDipoles() + SIM_uses_RF = SimUsesRF() + SIM_uses_GB = SimUsesGB() + SIM_uses_EAM = SimUsesEAM() + SIM_requires_postpair_calc = SimRequiresPostpairCalc() + SIM_requires_prepair_calc = SimRequiresPrepairCalc() + SIM_uses_directional_atoms = SimUsesDirectionalAtoms() + SIM_uses_PBC = SimUsesPBC() + SIM_uses_molecular_cutoffs = SimUsesMolecularCutoffs() + + haveSIMvariables = .true. + + return + end subroutine setSimVariables + + subroutine doReadyCheck(error) + integer, intent(out) :: error + + integer :: myStatus + + error = 0 + + if (.not. havePropertyMap) then + + myStatus = 0 + + call createPropertyMap(myStatus) + + if (myStatus .ne. 0) then + write(default_error, *) 'createPropertyMap failed in do_Forces!' + error = -1 + return + endif + endif + + if (.not. haveSIMvariables) then + call setSimVariables() + endif + + if (.not. haveRlist) then + write(default_error, *) 'rList has not been set in do_Forces!' + error = -1 + return + endif + + if (SIM_uses_LJ .and. FF_uses_LJ) then + if (.not. havePolicies) then + write(default_error, *) 'LJ mixing Policies have not been set in do_Forces!' + error = -1 + return + endif + endif + + if (.not. haveNeighborList) then + write(default_error, *) 'neighbor list has not been initialized in do_Forces!' + error = -1 + return + end if + + if (.not. haveSaneForceField) then + write(default_error, *) 'Force Field is not sane in do_Forces!' + error = -1 + return + end if + +#ifdef IS_MPI + if (.not. isMPISimSet()) then + write(default_error,*) "ERROR: mpiSimulation has not been initialized!" + error = -1 + return + endif +#endif + return + end subroutine doReadyCheck + + subroutine init_FF(LJMIXPOLICY, use_RF_c, thisStat) integer, intent(in) :: LJMIXPOLICY @@ -90,13 +253,17 @@ contains FF_uses_LJ = .false. FF_uses_sticky = .false. + FF_uses_charges = .false. FF_uses_dipoles = .false. FF_uses_GB = .false. FF_uses_EAM = .false. call getMatchingElementList(atypes, "is_LJ", .true., nMatches, MatchList) if (nMatches .gt. 0) FF_uses_LJ = .true. - + + call getMatchingElementList(atypes, "is_Charge", .true., nMatches, MatchList) + if (nMatches .gt. 0) FF_uses_charges = .true. + call getMatchingElementList(atypes, "is_DP", .true., nMatches, MatchList) if (nMatches .gt. 0) FF_uses_dipoles = .true. @@ -110,6 +277,15 @@ contains call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList) if (nMatches .gt. 0) FF_uses_EAM = .true. + !! 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 if (FF_uses_dipoles) then @@ -121,6 +297,7 @@ contains if (FF_uses_RF) then write(default_error,*) 'Using Reaction Field with no dipoles? Huh?' thisStat = -1 + haveSaneForceField = .false. return endif endif @@ -135,18 +312,22 @@ contains case default write(default_error,*) 'unknown LJ Mixing Policy!' thisStat = -1 + haveSaneForceField = .false. return end select if (my_status /= 0) then thisStat = -1 + haveSaneForceField = .false. return end if + havePolicies = .true. endif if (FF_uses_sticky) then call check_sticky_FF(my_status) if (my_status /= 0) then thisStat = -1 + haveSaneForceField = .false. return end if endif @@ -155,55 +336,57 @@ contains if (FF_uses_EAM) then call init_EAM_FF(my_status) if (my_status /= 0) then - write(*,*) "init_EAM_FF returned a bad status" + write(default_error, *) "init_EAM_FF returned a bad status" thisStat = -1 + haveSaneForceField = .false. return end if endif - - if (FF_uses_GB) then call check_gb_pair_FF(my_status) if (my_status .ne. 0) then thisStat = -1 + haveSaneForceField = .false. return endif endif if (FF_uses_GB .and. FF_uses_LJ) then endif - if (.not. do_forces_initialized) then + if (.not. haveNeighborList) then !! Create neighbor lists - call expandNeighborList(getNlocal(), my_status) + call expandNeighborList(nLocal, my_status) if (my_Status /= 0) then write(default_error,*) "SimSetup: ExpandNeighborList returned error." thisStat = -1 return endif + haveNeighborList = .true. endif - - havePolicies = .true. - if( haveRlist ) do_forces_initialized = .true. - 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, qcom, mfact, 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,getNlocal()) :: q + real ( kind = dp ), dimension(3,nLocal) :: q + !! molecular center-of-mass position array + real ( kind = dp ), dimension(3,nLocal) :: qcom + !! mass factors used for molecular cutoffs + real ( kind = dp ), dimension(3,nLocal) :: mfact !! Rotation Matrix for each long range particle in simulation. - real( kind = dp), dimension(9,getNlocal()) :: A + real( kind = dp), dimension(9,nLocal) :: A !! Unit vectors for dipoles (lab frame) - real( kind = dp ), dimension(3,getNlocal()) :: u_l + real( kind = dp ), dimension(3,nLocal) :: u_l !! Force array provided by C, dimensioned by getNlocal - real ( kind = dp ), dimension(3,getNlocal()) :: f + real ( kind = dp ), dimension(3,nLocal) :: f !! Torsion array provided by C, dimensioned by getNlocal - real( kind = dp ), dimension(3,getNlocal()) :: t + real( kind = dp ), dimension(3,nLocal) :: t + !! Stress Tensor real( kind = dp), dimension(9) :: tau real ( kind = dp ) :: pot @@ -216,54 +399,56 @@ contains integer :: ncol integer :: nprocs #endif - integer :: nlocal integer :: natoms logical :: update_nlist integer :: i, j, jbeg, jend, jnab integer :: nlist - real( kind = DP ) :: rijsq - real(kind=dp),dimension(3) :: d + real( kind = DP ) :: rijsq, rcijsq + real(kind=dp),dimension(3) :: d, dc real(kind=dp) :: rfpot, mu_i, virial - integer :: me_i + integer :: me_i, me_j logical :: is_dp_i integer :: neighborListSize integer :: listerror, error integer :: localError + integer :: propPack_i, propPack_j real(kind=dp) :: listSkin = 1.0 - + !! initialize local variables - + #ifdef IS_MPI pot_local = 0.0_dp - nlocal = getNlocal() nrow = getNrow(plan_row) ncol = getNcol(plan_col) #else - nlocal = getNlocal() natoms = nlocal #endif - - call check_initialization(localError) + + call doReadyCheck(localError) if ( localError .ne. 0 ) then - call handleError("do_force_loop","Not Initialized") + call handleError("do_force_loop", "Not Initialized") error = -1 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) - - if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then + + if (SIM_uses_molecular_cutoffs) then + call gather(qcom,qcom_Row,plan_row3d) + call gather(qcom,qcom_Col,plan_col3d) + endif + + 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) @@ -272,174 +457,221 @@ 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. SimRequiresPrepairCalc()) then + + if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then !! See if we need to update neighbor lists - call checkNeighborList(nlocal, q, listSkin, update_nlist) + if (SIM_uses_molecular_cutoffs) then + call checkNeighborList(nlocal, qcom, listSkin, update_nlist) + else + call checkNeighborList(nlocal, q, listSkin, update_nlist) + 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----------->>>>>>>>>>>>>>>>>>>>>>>>>>> + + !--------------------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 + !! save current configuration, construct neighbor list, + !! and calculate forces + if (SIM_uses_molecular_cutoffs) then + call saveNeighborList(nlocal, qcom) + else + call saveNeighborList(nlocal, q) + endif + + neighborListSize = size(list) + nlist = 0 + + do i = 1, nrow + point(i) = nlist + 1 - if (skipThisPair(i,j)) cycle prepair_inner - - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) - - if (rijsq < rlistsq) then + prepair_inner: do j = 1, ncol - nlist = nlist + 1 + if (skipThisPair(i,j)) cycle prepair_inner - 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) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), & + dc, rcijsq) + else + call get_interatomic_vector(q_Row(:,i), q_Col(:,j), & + dc, rcijsq) endif - 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 - - point(nrow + 1) = nlist + 1 - - else !! (of update_check) - - ! 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 - endif - enddo - endif - + if (rcijsq < rlistsq) then + + nlist = nlist + 1 + + 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 + + list(nlist) = j + + if (SIM_uses_molecular_cutoffs) then + ! since the simulation distances were in molecular COMs: + call get_interatomic_vector(q_Row(:,i), q_Col(:,j), & + d, rijsq) + else + d(1:3) = dc(1:3) + rijsq = rcijsq + endif + + call do_prepair(i, j, rijsq, d, rcijsq, dc, & + do_pot, do_stress, u_l, A, f, t, pot_local) + endif + enddo prepair_inner + enddo + + point(nrow + 1) = nlist + 1 + + else !! (of update_check) + + ! 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) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom_Row(:,i),qcom_Col(:,j),& + dc, rcijsq) + else + dc(1:3) = d(1:3) + rcijsq = rijsq + endif + + call do_prepair(i, j, rijsq, d, rcijsq, dc, & + 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) - - neighborListSize = size(list) - - nlist = 0 - - do i = 1, natoms-1 - point(i) = nlist + 1 + if (update_nlist) then - prepair_inner: do j = i+1, natoms + ! save current configuration, contruct neighbor list, + ! and calculate forces + call saveNeighborList(natoms, q) + + neighborListSize = size(list) + + nlist = 0 + + do i = 1, natoms-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 + prepair_inner: do j = i+1, natoms - list(nlist) = j + if (skipThisPair(i,j)) cycle prepair_inner - call do_prepair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom(:,i), qcom(:,j), & + dc, rcijsq) + else + call get_interatomic_vector(q(:,i), q(:,j), dc, rcijsq) + endif - endif - enddo prepair_inner - enddo - - point(natoms) = nlist + 1 - - 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 + if (rcijsq < 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 + + list(nlist) = j + + + if (SIM_uses_molecular_cutoffs) then + ! since the simulation distances were in molecular COMs: + call get_interatomic_vector(q(:,i), q(:,j), & + d, rijsq) + else + dc(1:3) = d(1:3) + rcijsq = rijsq + endif + + call do_prepair(i, j, rijsq, d, rcijsq, dc, & + do_pot, do_stress, u_l, A, f, t, pot) + + endif + enddo prepair_inner + enddo + + point(natoms) = nlist + 1 + + 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) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom(:,i), qcom(:,j), & + dc, rcijsq) + else + dc(1:3) = d(1:3) + rcijsq = rijsq + endif + + call do_prepair(i, j, rijsq, d, rcijsq, dc, & + 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) endif - - - - - -!---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - - + + !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>> + #ifdef IS_MPI if (update_nlist) then @@ -451,15 +683,22 @@ contains nlist = 0 do i = 1, nrow + point(i) = nlist + 1 inner: do j = 1, ncol if (skipThisPair(i,j)) cycle inner - call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), & + dc, rcijsq) + else + call get_interatomic_vector(q_Row(:,i), q_Col(:,j), & + dc, rcijsq) + endif - if (rijsq < rlistsq) then + if (rcijsq < rlistsq) then nlist = nlist + 1 @@ -474,18 +713,26 @@ contains endif list(nlist) = j - - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot_local) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(q_Row(:,i), q_Col(:,j), & + d, rijsq) + else + d(1:3) = dc(1:3) + rijsq = rcijsq + endif + + call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, & + do_pot, do_stress, u_l, A, f, t, pot_local) + endif enddo inner enddo - + point(nrow + 1) = nlist + 1 else !! (of update_check) - + ! use the list to find the neighbors do i = 1, nrow JBEG = POINT(i) @@ -495,11 +742,19 @@ contains do jnab = jbeg, jend j = list(jnab) - + 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) - + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), & + dc, rcijsq) + else + dc(1:3) = d(1:3) + rcijsq = rijsq + endif + + call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, & + do_pot, do_stress, u_l, A, f, t, pot_local) + enddo endif enddo @@ -508,13 +763,13 @@ contains #else if (update_nlist) then - + ! save current configuration, contruct neighbor list, ! and calculate forces call saveNeighborList(natoms, q) neighborListSize = size(list) - + nlist = 0 do i = 1, natoms-1 @@ -523,14 +778,19 @@ contains inner: do j = i+1, natoms if (skipThisPair(i,j)) cycle inner - - call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) - - - if (rijsq < rlistsq) then + + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom(:,i), qcom(:,j), & + dc, rcijsq) + else + call get_interatomic_vector(q(:,i), q(:,j), & + dc, rcijsq) + endif + + if (rcijsq < rlistsq) then nlist = nlist + 1 - + if (nlist > neighborListSize) then call expandNeighborList(natoms, listerror) if (listerror /= 0) then @@ -543,9 +803,17 @@ contains list(nlist) = j - call do_pair(i, j, rijsq, d, do_pot, do_stress, & - u_l, A, f, t, pot) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(q(:,i), q(:,j), & + d, rijsq) + else + d(1:3) = dc(1:3) + rijsq = rcijsq + endif + call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, & + do_pot, do_stress, u_l, A, f, t, pot) + endif enddo inner enddo @@ -564,10 +832,19 @@ contains 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(:,i), q(:,j), d, rijsq) + if (SIM_uses_molecular_cutoffs) then + call get_interatomic_vector(qcom(:,i), qcom(:,j), & + dc, rcijsq) + else + dc(1:3) = d(1:3) + rcijsq = rijsq + endif + + call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, & + do_pot, do_stress, u_l, A, f, t, pot) + enddo endif enddo @@ -576,30 +853,30 @@ contains #endif ! phew, done with main loop. - -!! Do timing + + !! Do timing #ifdef PROFILE call cpu_time(forceTimeFinal) forceTime = forceTime + forceTimeFinal - forceTimeInitial #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 f(1:3,i) = f(1:3,i) + f_temp(1:3,i) end do - if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then + if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then t_temp = 0.0_dp call scatter(t_Row,t_temp,plan_row3d) do i = 1,nlocal @@ -616,7 +893,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 @@ -624,18 +901,18 @@ 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. SimRequiresPostpairCalc()) then + + if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then - if (FF_uses_RF .and. SimUsesRF()) then + if (FF_uses_RF .and. SIM_uses_RF) then #ifdef IS_MPI call scatter(rf_Row,rf,plan_row3d) @@ -645,20 +922,22 @@ contains end do #endif - do i = 1, getNlocal() - + do i = 1, nLocal + rfpot = 0.0_DP #ifdef IS_MPI me_i = atid_row(i) #else me_i = atid(i) #endif - call getElementProperty(atypes, me_i, "is_DP", is_DP_i) - if ( is_DP_i ) then - call getElementProperty(atypes, me_i, "dipole_moment", mu_i) + + 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) + call accumulate_self_rf(i, mu_i, u_l) !! Get the reaction field contribution to the !! potential and torques: call reaction_field_final(i, mu_i, u_l, rfpot, t, do_pot) @@ -672,25 +951,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 @@ -699,128 +978,130 @@ contains #endif - end subroutine do_force_loop + + subroutine do_pair(i, j, rijsq, d, rcijsq, dc, mfact, do_pot, do_stress, & + u_l, A, f, t, pot) - subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) - real( kind = dp ) :: pot - real( kind = dp ), dimension(3,getNlocal()) :: u_l - real (kind=dp), dimension(9,getNlocal()) :: A - real (kind=dp), dimension(3,getNlocal()) :: f - real (kind=dp), dimension(3,getNlocal()) :: t + 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 integer, intent(in) :: i, j - real ( kind = dp ), intent(inout) :: rijsq - real ( kind = dp ) :: r - real ( kind = dp ), intent(inout) :: d(3) - logical :: is_LJ_i, is_LJ_j - logical :: is_DP_i, is_DP_j - logical :: is_GB_i, is_GB_j - logical :: is_EAM_i,is_EAM_j - logical :: is_Sticky_i, is_Sticky_j + real ( kind = dp ), intent(inout) :: rijsq, rcijsq + real ( kind = dp ) :: r, rc + real ( kind = dp ), intent(inout) :: d(3), dc(3) integer :: me_i, me_j r = sqrt(rijsq) + if (SIM_uses_molecular_cutoffs) then + rc = sqrt(rcijsq) + else + rc = r + endif + #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 - me_i = atid(i) me_j = atid(j) - #endif - - if (FF_uses_LJ .and. SimUsesLJ()) then - call getElementProperty(atypes, me_i, "is_LJ", is_LJ_i) - call getElementProperty(atypes, me_j, "is_LJ", is_LJ_j) - - if ( is_LJ_i .and. is_LJ_j ) & - call do_lj_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress) + + 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) + endif + endif - - if (FF_uses_dipoles .and. SimUsesDipoles()) then - call getElementProperty(atypes, me_i, "is_DP", is_DP_i) - call getElementProperty(atypes, me_j, "is_DP", is_DP_j) + + if (FF_uses_charges .and. SIM_uses_charges) then - if ( is_DP_i .and. is_DP_j ) then + if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then + call do_charge_pair(i, j, d, r, rijsq, dc, rc, rcijsq, mfact, & + pot, f, do_pot, do_stress, SIM_uses_molecular_cutoffs) + endif + + endif + + 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, & do_pot, do_stress) - if (FF_uses_RF .and. SimUsesRF()) then + if (FF_uses_RF .and. SIM_uses_RF) then call accumulate_rf(i, j, r, u_l) call rf_correct_forces(i, j, d, r, u_l, f, do_stress) - endif - + endif endif + endif - if (FF_uses_Sticky .and. SimUsesSticky()) then + if (FF_uses_Sticky .and. SIM_uses_sticky) then - call getElementProperty(atypes, me_i, "is_Sticky", is_Sticky_i) - call getElementProperty(atypes, me_j, "is_Sticky", is_Sticky_j) - - if ( is_Sticky_i .and. is_Sticky_j ) 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, & do_pot, do_stress) endif + endif - if (FF_uses_GB .and. SimUsesGB()) then - - - call getElementProperty(atypes, me_i, "is_GB", is_GB_i) - call getElementProperty(atypes, me_j, "is_GB", is_GB_j) + if (FF_uses_GB .and. SIM_uses_GB) then - if ( is_GB_i .and. is_GB_j ) 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, & do_pot, do_stress) endif + endif - + + 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) + endif + + endif - - if (FF_uses_EAM .and. SimUsesEAM()) then - call getElementProperty(atypes, me_i, "is_EAM", is_EAM_i) - call getElementProperty(atypes, me_j, "is_EAM", is_EAM_j) - - if ( is_EAM_i .and. is_EAM_j ) & - call do_eam_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress) - 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,getNlocal()) :: u_l - real (kind=dp), dimension(9,getNlocal()) :: A - real (kind=dp), dimension(3,getNlocal()) :: f - real (kind=dp), dimension(3,getNlocal()) :: t + 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 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 @@ -838,264 +1119,238 @@ contains #endif - if (FF_uses_EAM .and. SimUsesEAM()) then - call getElementProperty(atypes, me_i, "is_EAM", is_EAM_i) - call getElementProperty(atypes, me_j, "is_EAM", is_EAM_j) - - if ( is_EAM_i .and. is_EAM_j ) & + 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 + endif + end subroutine do_prepair - subroutine do_preforce(nlocal,pot) - integer :: nlocal - real( kind = dp ) :: pot - - if (FF_uses_EAM .and. SimUsesEAM()) 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 ( SimUsesPBC() ) 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 check_initialization(error) - integer, intent(out) :: error - - error = 0 - ! Make sure we are properly initialized. - if (.not. do_forces_initialized) then - write(*,*) "Forces not initialized" - error = -1 - return - endif - -#ifdef IS_MPI - if (.not. isMPISimSet()) then - write(default_error,*) "ERROR: mpiSimulation has not been initialized!" - error = -1 - return - endif -#endif - - return - end subroutine check_initialization - - - 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 + subroutine zero_work_arrays() + +#ifdef IS_MPI + + q_Row = 0.0_dp + q_Col = 0.0_dp - rf_Row = 0.0_dp - rf_Col = 0.0_dp - rf_Temp = 0.0_dp - + qcom_Row = 0.0_dp + qcom_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. SimUsesEAM()) 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