ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/do_Forces.F90
(Generate patch)

Comparing trunk/OOPSE_old/src/mdtools/libmdCode/do_Forces.F90 (file contents):
Revision 309 by gezelter, Mon Mar 10 23:19:23 2003 UTC vs.
Revision 330 by gezelter, Wed Mar 12 23:15:46 2003 UTC

# Line 4 | Line 4
4  
5   !! @author Charles F. Vardeman II
6   !! @author Matthew Meineke
7 < !! @version $Id: do_Forces.F90,v 1.9 2003-03-10 23:19:23 gezelter Exp $, $Date: 2003-03-10 23:19:23 $, $Name: not supported by cvs2svn $, $Revision: 1.9 $
7 > !! @version $Id: do_Forces.F90,v 1.16 2003-03-12 23:15:46 gezelter Exp $, $Date: 2003-03-12 23:15:46 $, $Name: not supported by cvs2svn $, $Revision: 1.16 $
8  
9  
10  
11   module do_Forces
12    use simulation
13    use definitions
14 <  use forceGlobals
15 <  use atype_typedefs
16 <  use neighborLists
17 <
18 <  
14 >  use atype_module
15 >  use neighborLists  
16    use lj
17 <  use sticky_FF
17 >  use sticky_pair
18    use dipole_dipole
22  use gb_FF
19  
20   #ifdef IS_MPI
21    use mpiSimulation
# Line 27 | Line 23 | public :: do_force_loop
23    implicit none
24    PRIVATE
25  
26 < public :: do_force_loop
26 >  logical, save :: do_forces_initialized = .false.
27 >  logical, save :: FF_uses_LJ
28 >  logical, save :: FF_uses_sticky
29 >  logical, save :: FF_uses_dipoles
30 >  logical, save :: FF_uses_RF
31 >  logical, save :: FF_uses_GB
32 >  logical, save :: FF_uses_EAM
33  
32 contains
34  
35 < !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
36 < !------------------------------------------------------------->
36 <  subroutine do_force_loop(q,A,mu,u_l,f,t,tau,potE,do_pot,FFerror)
37 < !! Position array provided by C, dimensioned by getNlocal
38 <    real ( kind = dp ), dimension(3,getNlocal()) :: q
39 <  !! Rotation Matrix for each long range particle in simulation.
40 <    real( kind = dp), dimension(9,getNlocal()) :: A
35 >  public :: init_FF
36 >  public :: do_force_loop
37  
38 <  !! Magnitude dipole moment
43 <    real( kind = dp ), dimension(3,getNlocal()) :: mu
44 <  !! Unit vectors for dipoles (lab frame)
45 <    real( kind = dp ), dimension(3,getNlocal()) :: u_l
46 < !! Force array provided by C, dimensioned by getNlocal
47 <    real ( kind = dp ), dimension(3,getNlocal()) :: f
48 < !! Torsion array provided by C, dimensioned by getNlocal
49 <    real( kind = dp ), dimension(3,getNlocal()) :: t
38 > contains
39  
40 < !! Stress Tensor
41 <    real( kind = dp), dimension(9) :: tau
40 >  subroutine init_FF(thisStat)
41 >  
42 >    integer, intent(out) :: my_status
43 >    integer :: thisStat = 0
44  
45 <    real ( kind = dp ) :: potE
55 <    logical ( kind = 2) :: do_pot
56 <    integer :: FFerror
45 >    ! be a smarter subroutine.
46  
47      
48 <    type(atype), pointer :: Atype_i
49 <    type(atype), pointer :: Atype_j
48 >    call init_lj_FF(my_status)
49 >    if (my_status /= 0) then
50 >       thisStat = -1
51 >       return
52 >    end if
53 >    
54 >    call check_sticky_FF(my_status)
55 >    if (my_status /= 0) then
56 >       thisStat = -1
57 >       return
58 >    end if
59 >    
60 >    do_forces_initialized = .true.    
61 >    
62 >  end subroutine init_FF
63  
64  
65  
66 <
67 <  
68 <
66 >  !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
67 >  !------------------------------------------------------------->
68 >  subroutine do_force_loop(q, A, u_l, f, t, tau, pot, do_pot_c, do_stress_c, &
69 >       error)
70 >    !! Position array provided by C, dimensioned by getNlocal
71 >    real ( kind = dp ), dimension(3,getNlocal()) :: q
72 >    !! Rotation Matrix for each long range particle in simulation.
73 >    real( kind = dp), dimension(9,getNlocal()) :: A    
74 >    !! Unit vectors for dipoles (lab frame)
75 >    real( kind = dp ), dimension(3,getNlocal()) :: u_l
76 >    !! Force array provided by C, dimensioned by getNlocal
77 >    real ( kind = dp ), dimension(3,getNlocal()) :: f
78 >    !! Torsion array provided by C, dimensioned by getNlocal
79 >    real( kind = dp ), dimension(3,getNlocal()) :: t    
80 >    !! Stress Tensor
81 >    real( kind = dp), dimension(9) :: tau  
82 >    real ( kind = dp ) :: pot
83 >    logical ( kind = 2) :: do_pot_c, do_stress_c
84 >    logical :: do_pot
85 >    logical :: do_stress
86   #ifdef IS_MPI
87 <  real( kind = DP ) :: pot_local
88 <
89 < !! Local arrays needed for MPI
71 <
72 < #endif
73 <
74 <
75 <
76 <  real( kind = DP )   :: pe
77 <  logical             :: update_nlist
78 <
79 <
80 <  integer ::  i, j, jbeg, jend, jnab, idim, jdim, idim2, jdim2, dim, dim2
81 <  integer :: nlist
82 <  integer :: j_start
83 <
84 <  real( kind = DP ) ::  r_ij, pot, ftmp, dudr, d2, drdx1, kt1, kt2, kt3, ktmp
85 <
86 <  real( kind = DP ) ::  rx_ij, ry_ij, rz_ij, rijsq
87 <  real( kind = DP ) ::  rlistsq, rcutsq,rlist,rcut
88 <
89 <  
90 <
91 < ! a rig that need to be fixed.
92 < #ifdef IS_MPI
93 <  real( kind = dp ) :: pe_local
94 <  integer :: nlocal
87 >    real( kind = DP ) :: pot_local
88 >    integer :: nrow
89 >    integer :: ncol
90   #endif
91 <  integer :: nrow
92 <  integer :: ncol
93 <  integer :: natoms
94 <  integer :: neighborListSize
95 <  integer :: listerror
96 < !! should we calculate the stress tensor
97 <  logical  :: do_stress = .false.
91 >    integer :: nlocal
92 >    integer :: natoms    
93 >    logical :: update_nlist  
94 >    integer :: i, j, jbeg, jend, jnab
95 >    integer :: nlist
96 >    real( kind = DP ) ::  rijsq, rlistsq, rcutsq, rlist, rcut
97 >    real(kind=dp),dimension(3) :: d
98 >    real(kind=dp) :: rfpot, mu_i, virial
99 >    integer :: me_i
100 >    logical :: is_dp_i
101 >    integer :: neighborListSize
102 >    integer :: listerror, error
103  
104 +    !! initialize local variables  
105  
105  FFerror = 0
106
107 ! Make sure we are properly initialized.
108  if (.not. isFFInit) then
109     write(default_error,*) "ERROR: lj_FF has not been properly initialized"
110     FFerror = -1
111     return
112  endif
106   #ifdef IS_MPI
107 <    if (.not. isMPISimSet()) then
108 <     write(default_error,*) "ERROR: mpiSimulation has not been properly initialized"
109 <     FFerror = -1
110 <     return
111 <  endif
107 >    nlocal = getNlocal()
108 >    nrow   = getNrow(plan_row)
109 >    ncol   = getNcol(plan_col)
110 > #else
111 >    nlocal = getNlocal()
112 >    natoms = nlocal
113   #endif
114  
115 < !! initialize local variables  
116 <  natoms = getNlocal()
117 <  call getRcut(rcut,rcut2=rcutsq)
118 <  call getRlist(rlist,rlistsq)
115 >    call getRcut(rcut,rcut2=rcutsq)
116 >    call getRlist(rlist,rlistsq)
117 >    
118 >    call check_initialization()
119 >    call zero_work_arrays()
120  
121 < !! Find ensemble
122 <  if (isEnsemble("NPT")) do_stress = .true.
128 < !! set to wrap
129 <  if (isPBC()) wrap = .true.
121 >    do_pot = do_pot_c
122 >    do_stress = do_stress_c
123  
124 <
125 <
133 <  
134 < !! See if we need to update neighbor lists
135 <  call check(q,update_nlist)
136 <
137 < !--------------WARNING...........................
138 < ! Zero variables, NOTE:::: Forces are zeroed in C
139 < ! Zeroing them here could delete previously computed
140 < ! Forces.
141 < !------------------------------------------------
142 <  call zero_module_variables()
143 <
144 <
145 < ! communicate MPI positions
124 >    ! Gather all information needed by all force loops:
125 >    
126   #ifdef IS_MPI    
127 +
128      call gather(q,q_Row,plan_row3d)
129      call gather(q,q_Col,plan_col3d)
130 <
131 <    call gather(u_l,u_l_Row,plan_row3d)
132 <    call gather(u_l,u_l_Col,plan_col3d)
133 <
134 <    call gather(A,A_Row,plan_row_rotation)
135 <    call gather(A,A_Col,plan_col_rotation)
130 >        
131 >    if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then
132 >       call gather(u_l,u_l_Row,plan_row3d)
133 >       call gather(u_l,u_l_Col,plan_col3d)
134 >      
135 >       call gather(A,A_Row,plan_row_rotation)
136 >       call gather(A,A_Col,plan_col_rotation)
137 >    endif
138 >    
139   #endif
140 <
141 <
140 >    
141 >    if (FF_RequiresPrepairCalc() .and. SimRequiresPrepairCalc()) then
142 >       !! See if we need to update neighbor lists
143 >       call checkNeighborList(nlocal, q, rcut, rlist, update_nlist)  
144 >       !! if_mpi_gather_stuff_for_prepair
145 >       !! do_prepair_loop_if_needed
146 >       !! if_mpi_scatter_stuff_from_prepair
147 >       !! if_mpi_gather_stuff_from_prepair_to_main_loop
148 >    else
149 >       !! See if we need to update neighbor lists
150 >       call checkNeighborList(nlocal, q, rcut, rlist, update_nlist)  
151 >    endif
152 >    
153   #ifdef IS_MPI
154      
155      if (update_nlist) then
156        
157 <       ! save current configuration, contruct neighbor list,
158 <       ! and calculate forces
157 >       !! save current configuration, construct neighbor list,
158 >       !! and calculate forces
159         call save_neighborList(q)
160        
161         neighborListSize = getNeighborListSize()
162 <       nlist = 0
162 >       nlist = 0      
163        
169       nrow = getNrow(plan_row)
170       ncol = getNcol(plan_col)
171       nlocal = getNlocal()
172      
164         do i = 1, nrow
165            point(i) = nlist + 1
175          Atype_i => identPtrListRow(i)%this
166            
167            inner: do j = 1, ncol
178             Atype_j => identPtrListColumn(j)%this
168              
169 <             call get_interatomic_vector(i,j,q_Row(:,i),q_Col(:,j),&
181 <                  rxij,ryij,rzij,rijsq,r)
169 >             if (checkExcludes(i,j)) cycle inner:
170              
171 <             ! skip the loop if the atoms are identical
184 <             if (mpi_cycle_jLoop(i,j)) cycle inner:
171 >             call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
172              
173               if (rijsq <  rlistsq) then            
174                  
175                  nlist = nlist + 1
176                  
177                  if (nlist > neighborListSize) then
178 <                   call expandList(listerror)
178 >                   call expandNeighborList(nlocal, listerror)
179                     if (listerror /= 0) then
180 <                      FFerror = -1
180 >                      error = -1
181                        write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
182                        return
183                     end if
184                  endif
185                  
186                  list(nlist) = j
187 <                
201 <                
187 >                                
188                  if (rijsq <  rcutsq) then
189 <                   call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
189 >                   call do_pair(i, j, rijsq, d, do_pot, do_stress)
190                  endif
191               endif
192            enddo inner
# Line 208 | Line 194 | contains
194  
195         point(nrow + 1) = nlist + 1
196        
197 <    else !! (update)
197 >    else  !! (of update_check)
198  
199         ! use the list to find the neighbors
200         do i = 1, nrow
# Line 216 | Line 202 | contains
202            JEND = POINT(i+1) - 1
203            ! check thiat molecule i has neighbors
204            if (jbeg .le. jend) then
205 <
220 <             Atype_i => identPtrListRow(i)%this
205 >            
206               do jnab = jbeg, jend
207                  j = list(jnab)
208 <                Atype_j = identPtrListColumn(j)%this
209 <                call get_interatomic_vector(i,j,q_Row(:,i),q_Col(:,j),&
210 <                     rxij,ryij,rzij,rijsq,r)
211 <                
227 <                call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
208 >
209 >                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
210 >                call do_pair(i, j, rijsq, d, do_pot, do_stress)
211 >
212               enddo
213            endif
214         enddo
215      endif
216 <
216 >    
217   #else
218      
219      if (update_nlist) then
# Line 241 | Line 225 | contains
225         neighborListSize = getNeighborListSize()
226         nlist = 0
227        
244    
228         do i = 1, natoms-1
229            point(i) = nlist + 1
230 <          Atype_i   => identPtrList(i)%this
248 <
230 >          
231            inner: do j = i+1, natoms
232 <             Atype_j   => identPtrList(j)%this
233 <             call get_interatomic_vector(i,j,q(:,i),q(:,j),&
234 <                  rxij,ryij,rzij,rijsq,r)
232 >            
233 >             if (checkExcludes(i,j)) cycle inner:
234 >            
235 >             call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
236            
237               if (rijsq <  rlistsq) then
238 <
238 >                
239                  nlist = nlist + 1
240                  
241                  if (nlist > neighborListSize) then
242 <                   call expandList(listerror)
242 >                   call expandList(natoms, listerror)
243                     if (listerror /= 0) then
244 <                      FFerror = -1
244 >                      error = -1
245                        write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
246                        return
247                     end if
248                  endif
249                  
250                  list(nlist) = j
251 <
269 <    
251 >                
252                  if (rijsq <  rcutsq) then
253 <                   call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
253 >                   call do_pair(i, j, rijsq, d, do_pot, do_stress)
254                  endif
255               endif
256            enddo inner
# Line 279 | Line 261 | contains
261      else !! (update)
262        
263         ! use the list to find the neighbors
264 <       do i = 1, nrow
264 >       do i = 1, natoms-1
265            JBEG = POINT(i)
266            JEND = POINT(i+1) - 1
267            ! check thiat molecule i has neighbors
268            if (jbeg .le. jend) then
269              
288             Atype_i => identPtrList(i)%this
270               do jnab = jbeg, jend
271                  j = list(jnab)
272 <                Atype_j = identPtrList(j)%this
273 <                call get_interatomic_vector(i,j,q(:,i),q(:,j),&
274 <                     rxij,ryij,rzij,rijsq,r)
275 <                call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
272 >
273 >                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
274 >                call do_pair(i, j, rijsq, d, do_pot, do_stress)
275 >
276               enddo
277            endif
278         enddo
279      endif
280 <
280 >    
281   #endif
282 <
283 <
282 >    
283 >    ! phew, done with main loop.
284 >    
285   #ifdef IS_MPI
304    !! distribute all reaction field stuff (or anything for post-pair):
305    call scatter(rflRow,rflTemp1,plan_row3d)
306    call scatter(rflCol,rflTemp2,plan_col3d)
307    do i = 1,nlocal
308       rflTemp(1:3,i) = rflTemp1(1:3,i) + rflTemp2(1:3,i)
309    end do
310 #endif
311
312 ! This is the post-pair loop:
313 #ifdef IS_MPI
314
315    if (system_has_postpair_atoms) then
316       do i = 1, nlocal
317          Atype_i => identPtrListRow(i)%this
318          call do_postpair(i, Atype_i)
319       enddo
320    endif
321
322 #else
323
324    if (system_has_postpair_atoms) then
325       do i = 1, natoms
326          Atype_i => identPtr(i)%this
327          call do_postpair(i, Atype_i)
328       enddo
329    endif
330
331 #endif
332
333
334 #ifdef IS_MPI
286      !!distribute forces
287 <
287 >    
288      call scatter(f_Row,f,plan_row3d)
289      call scatter(f_Col,f_temp,plan_col3d)
290      do i = 1,nlocal
291         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
292      end do
293 <
294 <    if (doTorque()) then
293 >    
294 >    if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then
295         call scatter(t_Row,t,plan_row3d)
296         call scatter(t_Col,t_temp,plan_col3d)
297 <    
297 >      
298         do i = 1,nlocal
299            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
300         end do
# Line 366 | Line 317 | contains
317            pot_local = pot_local + pot_Temp(i)
318         enddo
319        
320 <       pot = pot_local
320 >    endif    
321 > #endif
322 >
323 >    if (FF_RequiresPostpairCalc() .and. SimRequiresPostpairCalc()) then
324 >      
325 >       if (FF_uses_RF .and. SimUsesRF()) then
326 >          
327 > #ifdef IS_MPI
328 >          call scatter(rf_Row,rf,plan_row3d)
329 >          call scatter(rf_Col,rf_Temp,plan_col3d)
330 >          do i = 1,nlocal
331 >             rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
332 >          end do
333 > #endif
334 >          
335 >          do i = 1, getNlocal()
336 >
337 >             rfpot = 0.0_DP
338 > #ifdef IS_MPI
339 >             me_i = atid_row(i)
340 > #else
341 >             me_i = atid(i)
342 > #endif
343 >             call getElementProperty(atypes, me_i, "is_DP", is_DP_i)      
344 >             if ( is_DP_i ) then
345 >                call getElementProperty(atypes, me_i, "dipole_moment", mu_i)
346 >                !! The reaction field needs to include a self contribution
347 >                !! to the field:
348 >                call accumulate_self_rf(i, mu_i, u_l)            
349 >                !! Get the reaction field contribution to the
350 >                !! potential and torques:
351 >                call reaction_field_final(i, mu_i, u_l, rfpot, t, do_pot)
352 > #ifdef IS_MPI
353 >                pot_local = pot_local + rfpot
354 > #else
355 >                pot = pot + rfpot
356 > #endif
357 >             endif            
358 >          enddo
359 >       endif
360      endif
361  
362 <    if (doStress()) then
363 <       mpi_allreduce(tau, tau_Temp,9,mpi_double_precision,mpi_sum, &
362 >
363 > #ifdef IS_MPI
364 >
365 >    if (do_pot) then
366 >       pot = pot_local
367 >       !! we assume the c code will do the allreduce to get the total potential
368 >       !! we could do it right here if we needed to...
369 >    endif
370 >
371 >    if (do_stress) then
372 >       call mpi_allreduce(tau, tau_Temp,9,mpi_double_precision,mpi_sum, &
373              mpi_comm_world,mpi_err)
374 <       mpi_allreduce(virial, virial_Temp,1,mpi_double_precision,mpi_sum, &
374 >       call mpi_allreduce(virial, virial_Temp,1,mpi_double_precision,mpi_sum, &
375              mpi_comm_world,mpi_err)
376      endif
377  
378 < #endif
378 > #else
379  
380 <    if (doStress()) then
380 >    if (do_stress) then
381         tau = tau_Temp
382         virial = virial_Temp
383      endif
384  
385 + #endif
386 +    
387    end subroutine do_force_loop
388  
389  
# Line 394 | Line 395 | contains
395  
396    end subroutine do_preForce
397  
398 <
398 <
399 <
400 <
401 <
402 <
403 <
404 <
405 <
406 <
407 <
408 <
409 < !! Calculate any post force loop components, i.e. reaction field, etc.
398 >  !! Calculate any post force loop components, i.e. reaction field, etc.
399    subroutine do_postForce()
400  
401  
402  
403    end subroutine do_postForce
404  
405 +  subroutine do_pair(i, j, rijsq, d, do_pot, do_stress)
406  
407 +    real( kind = dp ) :: pot
408 +    real( kind = dp ), dimension(3,getNlocal()) :: u_l
409 +    real (kind=dp), dimension(9,getNlocal()) :: A
410 +    real (kind=dp), dimension(3,getNlocal()) :: f
411 +    real (kind=dp), dimension(3,getNlocal()) :: t
412  
413 +    logical, intent(inout) :: do_pot, do_stress
414 +    integer, intent(in) :: i, j
415 +    real ( kind = dp ), intent(in)    :: rijsq
416 +    real ( kind = dp )                :: r
417 +    real ( kind = dp ), intent(inout) :: d(3)
418 +    logical :: is_LJ_i, is_LJ_j
419 +    logical :: is_DP_i, is_DP_j
420 +    logical :: is_Sticky_i, is_Sticky_j
421 +    integer :: me_i, me_j
422  
423 <
420 <
421 <
422 <
423 <
424 <
425 <
426 <
427 <
428 <
429 <
430 <
431 <
432 <  subroutine do_pair(atype_i,atype_j,i,j,r_ij,rx_ij,ry_ij,rz_ij)
433 <    type (atype ), pointer, intent(inout) :: atype_i
434 <    type (atype ), pointer, intent(inout) :: atype_j
435 <    integer :: i
436 <    integer :: j
437 <    real ( kind = dp ), intent(inout) :: rx_ij
438 <    real ( kind = dp ), intent(inout) :: ry_ij
439 <    real ( kind = dp ), intent(inout) :: rz_ij
440 <
441 <
442 <    real( kind = dp ) :: fx = 0.0_dp
443 <    real( kind = dp ) :: fy = 0.0_dp
444 <    real( kind = dp ) :: fz = 0.0_dp  
445 <  
446 <    real( kind = dp ) ::  drdx = 0.0_dp
447 <    real( kind = dp ) ::  drdy = 0.0_dp
448 <    real( kind = dp ) ::  drdz = 0.0_dp
423 >    r = sqrt(rijsq)
424      
450
425   #ifdef IS_MPI
426  
427 <    if (Atype_i%is_LJ .and. Atype_j%is_LJ) then
428 <       call do_lj_pair(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
455 <            pot, f)
456 <    endif
427 >    me_i = atid_row(i)
428 >    me_j = atid_col(j)
429  
430 <    if (Atype_i%is_dp .and. Atype_j%is_dp) then
430 > #else
431  
432 <       call do_dipole_pair(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
433 <            rt, rrf, pot, u_l, f, t)
432 >    me_i = atid(i)
433 >    me_j = atid(j)
434  
435 <       if (do_reaction_field) then
464 <          call accumulate_rf(i, j, r_ij, rt, rrf)
465 <       endif
435 > #endif
436  
467    endif
437  
438 <    if (Atype_i%is_sticky .and. Atype_j%is_sticky) then
439 <       call getstickyforce(r, pot, dudr, Atype_i, Atype_j)
438 >    if (FF_uses_LJ .and. SimUsesLJ()) then
439 >       call getElementProperty(atypes, me_i, "is_LJ", is_LJ_i)
440 >       call getElementProperty(atypes, me_j, "is_LJ", is_LJ_j)
441 >      
442 >       if ( is_LJ_i .and. is_LJ_j ) &
443 >            call do_lj_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
444      endif
445 +      
446  
447 < #else
448 <
449 <    if (Atype_i%is_LJ .and. Atype_j%is_LJ) then
450 <       call do_lj_pair(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
451 <            pot, f)
447 >    if (FF_uses_dipoles .and. SimUsesDipoles()) then
448 >       call getElementProperty(atypes, me_i, "is_DP", is_DP_i)
449 >       call getElementProperty(atypes, me_j, "is_DP", is_DP_j)
450 >      
451 >       if ( is_DP_i .and. is_DP_j ) then
452 >          
453 >          call do_dipole_pair(i, j, d, r, pot, u_l, f, t, do_pot, do_stress)
454 >          
455 >          if (FF_uses_RF .and. SimUsesRF()) then
456 >            
457 >             call accumulate_rf(i, j, r, u_l)
458 >             call rf_correct_forces(i, j, d, r, u_l, f, do_stress)
459 >            
460 >          endif
461 >          
462 >       endif
463      endif
464  
465 <    if (Atype_i%is_dp .and. Atype_j%is_dp) then
481 <       call do_dipole_pair(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
482 <            rt, rrf, pot, u_l, f, t)
465 >    if (FF_uses_Sticky .and. SimUsesSticky()) then
466  
467 <       if (do_reaction_field) then
468 <          call accumulate_rf(i, j, r_ij, rt, rrf)
467 >       call getElementProperty(atypes, me_i, "is_Sticky", is_Sticky_i)
468 >       call getElementProperty(atypes, me_j, "is_Sticky", is_Sticky_j)
469 >      
470 >       if ( is_Sticky_i .and. is_Sticky_j ) then
471 >          call do_sticky_pair(i, j, d, r, rijsq, A, pot, f, t, &
472 >               do_pot, do_stress)
473         endif
487
474      endif
489
490    if (Atype_i%is_sticky .and. Atype_j%is_sticky) then
491       call getstickyforce(r,pot,dudr, Atype_i, Atype_j)
492    endif
493
494 #endif
495
475        
476    end subroutine do_pair
477  
478  
479 <
480 <
502 <
503 <
504 <
505 <
506 <
507 <
508 <
509 <
510 <
511 <
512 <
513 <
514 <  subroutine get_interatomic_vector(q_i,q_j,rx_ij,ry_ij,rz_ij,r_sq,r_ij)
515 < !---------------- Arguments-------------------------------
516 <   !! index i
517 <
518 <    !! Position array
479 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
480 >    
481      real (kind = dp), dimension(3) :: q_i
482      real (kind = dp), dimension(3) :: q_j
521    !! x component of vector between i and j
522    real ( kind = dp ), intent(out)  :: rx_ij
523    !! y component of vector between i and j
524    real ( kind = dp ), intent(out)  :: ry_ij
525    !! z component of vector between i and j
526    real ( kind = dp ), intent(out)  :: rz_ij
527    !! magnitude of r squared
483      real ( kind = dp ), intent(out) :: r_sq
529    !! magnitude of vector r between atoms i and j.
530    real ( kind = dp ), intent(out) :: r_ij
531    !! wrap into periodic box.
532    logical, intent(in) :: wrap
533
534 !--------------- Local Variables---------------------------
535    !! Distance between i and j
484      real( kind = dp ) :: d(3)
537 !---------------- END DECLARATIONS-------------------------
485  
539
540 ! Find distance between i and j
486      d(1:3) = q_i(1:3) - q_j(1:3)
542
543 ! Wrap back into periodic box if necessary
544    if ( wrap ) then
545       d(1:3) = d(1:3) - thisSim%box(1:3) * sign(1.0_dp,thisSim%box(1:3)) * &
546            int(abs(d(1:3)/thisSim%box(1:3) + 0.5_dp)
547    end if
487      
488 < !   Find Magnitude of the vector
488 >    ! Wrap back into periodic box if necessary
489 >    if ( SimUsesPBC() ) then
490 >       d(1:3) = d(1:3) - box(1:3) * sign(1.0_dp,box(1:3)) * &
491 >            int(abs(d(1:3)/box(1:3) + 0.5_dp))
492 >    endif
493 >    
494      r_sq = dot_product(d,d)
495 <    r_ij = sqrt(r_sq)
495 >        
496 >  end subroutine get_interatomic_vector
497  
498 < !   Set each component for force calculation
499 <    rx_ij = d(1)
555 <    ry_ij = d(2)
556 <    rz_ij = d(3)
498 >  subroutine check_initialization(error)
499 >    integer, intent(out) :: error
500  
501 +    error = 0
502 +    ! Make sure we are properly initialized.
503 +    if (.not. do_Forces_initialized) then
504 +       write(default_error,*) "ERROR: do_Forces has not been initialized!"
505 +       error = -1
506 +       return
507 +    endif
508 + #ifdef IS_MPI
509 +    if (.not. isMPISimSet()) then
510 +       write(default_error,*) "ERROR: mpiSimulation has not been initialized!"
511 +       error = -1
512 +       return
513 +    endif
514 + #endif
515  
516 <  end subroutine get_interatomic_vector
516 >    return
517 >  end subroutine check_initialization
518  
519 <  subroutine zero_module_variables()
519 >  
520 >  subroutine zero_work_arrays()
521 >    
522 > #ifdef IS_MPI
523  
524 < #ifndef IS_MPI
525 <
565 <    pe = 0.0E0_DP
566 <    tauTemp = 0.0_dp
567 <    fTemp = 0.0_dp
568 <    tTemp = 0.0_dp
569 < #else
570 <    qRow = 0.0_dp
571 <    qCol = 0.0_dp
524 >    q_Row = 0.0_dp
525 >    q_Col = 0.0_dp  
526      
527 <    muRow = 0.0_dp
528 <    muCol = 0.0_dp
527 >    u_l_Row = 0.0_dp
528 >    u_l_Col = 0.0_dp
529      
530 <    u_lRow = 0.0_dp
531 <    u_lCol = 0.0_dp
530 >    A_Row = 0.0_dp
531 >    A_Col = 0.0_dp
532      
533 <    ARow = 0.0_dp
534 <    ACol = 0.0_dp
535 <    
536 <    fRow = 0.0_dp
537 <    fCol = 0.0_dp
538 <    
539 <  
586 <    tRow = 0.0_dp
587 <    tCol = 0.0_dp
533 >    f_Row = 0.0_dp
534 >    f_Col = 0.0_dp
535 >    f_Temp = 0.0_dp
536 >      
537 >    t_Row = 0.0_dp
538 >    t_Col = 0.0_dp
539 >    t_Temp = 0.0_dp
540  
541 <  
541 >    pot_Row = 0.0_dp
542 >    pot_Col = 0.0_dp
543 >    pot_Temp = 0.0_dp
544  
591    eRow = 0.0_dp
592    eCol = 0.0_dp
593    eTemp = 0.0_dp
545   #endif
546  
547 <  end subroutine zero_module_variables
547 >    tau_Temp = 0.0_dp
548 >    virial_Temp = 0.0_dp
549 >    
550 >  end subroutine zero_work_arrays
551 >  
552  
553 +  !! Function to properly build neighbor lists in MPI using newtons 3rd law.
554 +  !! We don't want 2 processors doing the same i j pair twice.
555 +  !! Also checks to see if i and j are the same particle.
556  
599 !! Function to properly build neighbor lists in MPI using newtons 3rd law.
600 !! We don't want 2 processors doing the same i j pair twice.
601 !! Also checks to see if i and j are the same particle.
557    function checkExcludes(atom1,atom2) result(do_cycle)
558 < !--------------- Arguments--------------------------
559 < ! Index i
558 >    !--------------- Arguments--------------------------
559 >    ! Index i
560      integer,intent(in) :: atom1
561 < ! Index j
561 >    ! Index j
562      integer,intent(in), optional :: atom2
563 < ! Result do_cycle
563 >    ! Result do_cycle
564      logical :: do_cycle
565 < !--------------- Local variables--------------------
565 >    !--------------- Local variables--------------------
566      integer :: tag_i
567      integer :: tag_j
568 <    integer :: i
569 < !--------------- END DECLARATIONS------------------  
568 >    integer :: i, j
569 >    !--------------- END DECLARATIONS------------------  
570      do_cycle = .false.
571 <
571 >    
572   #ifdef IS_MPI
573      tag_i = tagRow(atom1)
574   #else
575      tag_i = tag(atom1)
576   #endif
577 <
578 < !! Check global excludes first
577 >    
578 >    !! Check global excludes first
579      if (.not. present(atom2)) then
580 <       do i = 1,nGlobalExcludes
580 >       do i = 1, nExcludes_global
581            if (excludeGlobal(i) == tag_i) then
582               do_cycle = .true.
583               return
# Line 631 | Line 586 | contains
586         return !! return after checking globals
587      end if
588  
589 < !! we return if j not present here.
590 <    tag_j = tagColumn(j)
591 <
637 <
638 <
589 >    !! we return if atom2 not present here.
590 >    tag_j = tagColumn(atom2)
591 >    
592      if (tag_i == tag_j) then
593         do_cycle = .true.
594         return
595      end if
596 <
596 >    
597      if (tag_i < tag_j) then
598         if (mod(tag_i + tag_j,2) == 0) do_cycle = .true.
599         return
600      else                
601         if (mod(tag_i + tag_j,2) == 1) do_cycle = .true.
602      endif
603 <
604 <
605 <
653 <    do i = 1, nLocalExcludes
654 <       if (tag_i = excludes(1,i) .and. excludes(2,i) < 0) then
603 >            
604 >    do i = 1, nExcludes_local
605 >       if ((tag_i == excludesLocal(1,i)) .and. (excludesLocal(2,i) < 0)) then
606            do_cycle = .true.
607            return
608         end if
609      end do
610 <      
611 <
610 >    
611 >    
612    end function checkExcludes
613  
614 <
614 >  function FF_UsesDirectionalAtoms() result(doesit)
615 >    logical :: doesit
616 >    doesit = FF_uses_dipoles .or. FF_uses_sticky .or. &
617 >         FF_uses_GB .or. FF_uses_RF
618 >  end function FF_UsesDirectionalAtoms
619 >  
620 >  function FF_RequiresPrepairCalc() result(doesit)
621 >    logical :: doesit
622 >    doesit = FF_uses_EAM
623 >  end function FF_RequiresPrepairCalc
624 >  
625 >  function FF_RequiresPostpairCalc() result(doesit)
626 >    logical :: doesit
627 >    doesit = FF_uses_RF
628 >  end function FF_RequiresPostpairCalc
629 >  
630   end module do_Forces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines