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 297 by gezelter, Thu Mar 6 22:08:29 2003 UTC vs.
Revision 328 by gezelter, Wed Mar 12 20:00:58 2003 UTC

# Line 1 | Line 1
1 + !! do_Forces.F90
2 + !! module do_Forces
3   !! Calculates Long Range forces.
4 +
5   !! @author Charles F. Vardeman II
6   !! @author Matthew Meineke
7 < !! @version $Id: do_Forces.F90,v 1.4 2003-03-06 22:08:29 gezelter Exp $, $Date: 2003-03-06 22:08:29 $, $Name: not supported by cvs2svn $, $Revision: 1.4 $
7 > !! @version $Id: do_Forces.F90,v 1.14 2003-03-12 20:00:58 gezelter Exp $, $Date: 2003-03-12 20:00:58 $, $Name: not supported by cvs2svn $, $Revision: 1.14 $
8  
9  
10  
11   module do_Forces
12    use simulation
13    use definitions
14 <  use generic_atypes
15 <  use neighborLists
16 <  
14 >  use forceGlobals
15 >  use atype_module
16 >  use neighborLists  
17    use lj_FF
18    use sticky_FF
19 <  use dp_FF
19 >  use dipole_dipole
20    use gb_FF
21  
22   #ifdef IS_MPI
# Line 22 | Line 25 | module do_Forces
25    implicit none
26    PRIVATE
27  
28 < !! Number of lj_atypes in lj_atype_list
26 <  integer, save :: n_atypes = 0
28 >  public :: do_force_loop
29  
30 < !! Global list of lj atypes in simulation
31 <  type (atype), pointer :: ListHead => null()
30 <  type (atype), pointer :: ListTail => null()
30 >  logical :: do_pot
31 >  logical :: do_stress
32  
33 + contains
34  
35 +  !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
36 +  !------------------------------------------------------------->
37 +  subroutine do_force_loop(q, A, u_l, f, t, tau, pot, do_pot_c, do_stress_c, &
38 +       FFerror)
39 +    !! Position array provided by C, dimensioned by getNlocal
40 +    real ( kind = dp ), dimension(3,getNlocal()) :: q
41 +    !! Rotation Matrix for each long range particle in simulation.
42 +    real( kind = dp), dimension(9,getNlocal()) :: A    
43 +    !! Unit vectors for dipoles (lab frame)
44 +    real( kind = dp ), dimension(3,getNlocal()) :: u_l
45 +    !! Force array provided by C, dimensioned by getNlocal
46 +    real ( kind = dp ), dimension(3,getNlocal()) :: f
47 +    !! Torsion array provided by C, dimensioned by getNlocal
48 +    real( kind = dp ), dimension(3,getNlocal()) :: t    
49 +    !! Stress Tensor
50 +    real( kind = dp), dimension(9) :: tau  
51 +    real ( kind = dp ) :: pot
52 +    logical ( kind = 2) :: do_pot_c, do_stress_c
53 +    integer :: FFerror
54  
34
35  logical, save :: firstTime = .True.
36
37 !! Atype identity pointer lists
55   #ifdef IS_MPI
56 < !! Row lj_atype pointer list
40 <  type (identPtrList), dimension(:), pointer :: identPtrListRow => null()
41 < !! Column lj_atype pointer list
42 <  type (identPtrList), dimension(:), pointer :: identPtrListColumn => null()
43 < #else
44 <  type(identPtrList ), dimension(:), pointer :: identPtrList => null()
56 >    real( kind = DP ) :: pot_local
57   #endif
46
47
48 !! Logical has lj force field module been initialized?
49  logical, save :: isFFinit = .false.
50
51 !! Use periodic boundry conditions
52  logical :: wrap = .false.
53
54 !! Potential energy global module variables
55 #ifdef IS_MPI
56  real(kind = dp), dimension(3,getNrow(plan_row)) :: qRow = 0.0_dp
57  real(kind = dp), dimension(3,getNcol(plan_col)) :: qCol = 0.0_dp
58
59  real(kind = dp), dimension(3,getNrow(plan_row)) :: muRow = 0.0_dp
60  real(kind = dp), dimension(3,getNcol(plan_col)) :: muCol = 0.0_dp
61
62  real(kind = dp), dimension(3,getNrow(plan_row)) :: u_lRow = 0.0_dp
63  real(kind = dp), dimension(3,getNcol(plan_col)) :: u_lCol = 0.0_dp
64
65  real(kind = dp), dimension(9,getNrow(plan_row)) :: ARow = 0.0_dp
66  real(kind = dp), dimension(9,getNcol(plan_col)) :: ACol = 0.0_dp  
67
68  real(kind = dp), dimension(3,getNrow(plan_row)) :: fRow = 0.0_dp
69  real(kind = dp), dimension(3,getNcol(plan_col)) :: fCol = 0.0_dp
70  real(kind = dp), dimension(3,getNlocal()) :: fTemp1 = 0.0_dp
71  real(kind = dp), dimension(3,getNlocal()) :: tTemp1 = 0.0_dp
72  real(kind = dp), dimension(3,getNlocal()) :: fTemp2 = 0.0_dp
73  real(kind = dp), dimension(3,getNlocal()) :: tTemp2 = 0.0_dp
74  real(kind = dp), dimension(3,getNlocal()) :: fTemp = 0.0_dp
75  real(kind = dp), dimension(3,getNlocal()) :: tTemp = 0.0_dp
76
77  real(kind = dp), dimension(3,getNrow(plan_row)) :: tRow = 0.0_dp
78  real(kind = dp), dimension(3,getNcol(plan_col)) :: tCol = 0.0_dp
79
80  real(kind = dp), dimension(3,getNrow(plan_row)) :: rflRow = 0.0_dp
81  real(kind = dp), dimension(3,getNcol(plan_col)) :: rflCol = 0.0_dp
82  real(kind = dp), dimension(3,getNlocal()) :: rflTemp = 0.0_dp
83
84  real(kind = dp), dimension(getNrow(plan_row)) :: eRow = 0.0_dp
85  real(kind = dp), dimension(getNcol(plan_col)) :: eCol = 0.0_dp
86
87  real(kind = dp), dimension(getNlocal()) :: eTemp = 0.0_dp
88 #endif
89  real(kind = dp) :: pe = 0.0_dp
90  real(kind = dp), dimension(3,natoms) :: fTemp = 0.0_dp
91  real(kind = dp), dimension(3,natoms) :: tTemp = 0.0_dp
92  real(kind = dp), dimension(3,natoms) :: rflTemp = 0.0_dp
93  real(kind = dp), dimension(9) :: tauTemp = 0.0_dp
94
95  logical :: do_preForce  = .false.
96  logical :: do_postForce = .false.
97
98
99
100 !! Public methods and data
101  public :: new_atype
102  public :: do_forceLoop
103  public :: init_FF
104
105  
106
107
108 contains
109
110 !! Adds a new lj_atype to the list.
111  subroutine new_atype(ident,mass,epsilon,sigma, &
112       is_LJ,is_Sticky,is_DP,is_GB,w0,v0,dipoleMoment,status)
113    real( kind = dp ), intent(in) :: mass
114    real( kind = dp ), intent(in) :: epsilon
115    real( kind = dp ), intent(in) :: sigma
116    real( kind = dp ), intent(in) :: w0
117    real( kind = dp ), intent(in) :: v0
118    real( kind = dp ), intent(in) :: dipoleMoment
119
120    integer, intent(in) :: ident
121    integer, intent(out) :: status
122    integer, intent(in) :: is_Sticky
123    integer, intent(in) :: is_DP
124    integer, intent(in) :: is_GB
125    integer, intent(in) :: is_LJ
126
127
128    type (atype), pointer :: the_new_atype
129    integer :: alloc_error
130    integer :: atype_counter = 0
131    integer :: alloc_size
132    integer :: err_stat
133    status = 0
134
135
136
137 ! allocate a new atype    
138    allocate(the_new_atype,stat=alloc_error)
139    if (alloc_error /= 0 ) then
140       status = -1
141       return
142    end if
143
144 ! assign our new atype information
145    the_new_atype%mass        = mass
146    the_new_atype%epsilon     = epsilon
147    the_new_atype%sigma       = sigma
148    the_new_atype%sigma2      = sigma * sigma
149    the_new_atype%sigma6      = the_new_atype%sigma2 * the_new_atype%sigma2 &
150         * the_new_atype%sigma2
151    the_new_atype%w0       = w0
152    the_new_atype%v0       = v0
153    the_new_atype%dipoleMoment       = dipoleMoment
154
58      
59 < ! assume that this atype will be successfully added
60 <    the_new_atype%atype_ident = ident
61 <    the_new_atype%atype_number = n_lj_atypes + 1
62 <    
160 <    if ( is_Sticky /= 0 )    the_new_atype%is_Sticky   = .true.
161 <    if ( is_GB /= 0 )        the_new_atype%is_GB       = .true.
162 <    if ( is_LJ /= 0 )        the_new_atype%is_LJ       = .true.
163 <    if ( is_DP /= 0 )        the_new_atype%is_DP       = .true.
59 >    logical :: update_nlist  
60 >    integer :: i, j, jbeg, jend, jnab
61 >    integer :: nlist
62 >    real( kind = DP ) ::  rijsq, rlistsq, rcutsq, rlist, rcut
63  
165    call add_atype(the_new_atype,ListHead,ListTail,err_stat)
166    if (err_stat /= 0 ) then
167       status = -1
168       return
169    endif
170
171    n_atypes = n_atypes + 1
172
173
174  end subroutine new_atype
175
176
177  subroutine init_FF(nComponents,ident, status)
178 !! Number of components in ident array
179    integer, intent(inout) :: nComponents
180 !! Array of identities nComponents long corresponding to
181 !! ljatype ident.
182    integer, dimension(nComponents),intent(inout) :: ident
183 !!  Result status, success = 0, error = -1
184    integer, intent(out) :: Status
185
186    integer :: alloc_stat
187
188    integer :: thisStat
189    integer :: i
190
191    integer :: myNode
64   #ifdef IS_MPI
65 <    integer, allocatable, dimension(:) :: identRow
66 <    integer, allocatable, dimension(:) :: identCol
65 >    integer :: nlocal
66 > #endif
67      integer :: nrow
68      integer :: ncol
69 < #endif
70 <    status = 0
71 <  
69 >    integer :: natoms
70 >    integer :: neighborListSize
71 >    integer :: listerror
72 >    FFerror = 0
73  
74 <    
74 >    do_pot = do_pot_c
75 >    do_stress = do_stress_c
76  
77 < !! if were're not in MPI, we just update ljatypePtrList
78 < #ifndef IS_MPI
79 <    call create_IdentPtrlst(ident,ListHead,identPtrList,thisStat)
80 <    if ( thisStat /= 0 ) then
207 <       status = -1
77 >    ! Make sure we are properly initialized.
78 >    if (.not. isFFInit) then
79 >       write(default_error,*) "ERROR: lj_FF has not been properly initialized"
80 >       FFerror = -1
81         return
82      endif
83 <
211 <    
212 < ! if were're in MPI, we also have to worry about row and col lists    
213 < #else
214 <  
215 < ! We can only set up forces if mpiSimulation has been setup.
83 > #ifdef IS_MPI
84      if (.not. isMPISimSet()) then
85 <       write(default_error,*) "MPI is not set"
86 <       status = -1
219 <       return
220 <    endif
221 <    nrow = getNrow(plan_row)
222 <    ncol = getNcol(plan_col)
223 <    mynode = getMyNode()
224 < !! Allocate temperary arrays to hold gather information
225 <    allocate(identRow(nrow),stat=alloc_stat)
226 <    if (alloc_stat /= 0 ) then
227 <       status = -1
85 >       write(default_error,*) "ERROR: mpiSimulation has not been properly initialized"
86 >       FFerror = -1
87         return
88      endif
230
231    allocate(identCol(ncol),stat=alloc_stat)
232    if (alloc_stat /= 0 ) then
233       status = -1
234       return
235    endif
236
237 !! Gather idents into row and column idents
238
239    call gather(ident,identRow,plan_row)
240    call gather(ident,identCol,plan_col)
241    
242  
243 !! Create row and col pointer lists
244  
245    call create_IdentPtrlst(identRow,ListHead,identPtrListRow,thisStat)
246    if (thisStat /= 0 ) then
247       status = -1
248       return
249    endif
250  
251    call create_IdentPtrlst(identCol,ListHead,identPtrListColumn,thisStat)
252    if (thisStat /= 0 ) then
253       status = -1
254       return
255    endif
256
257 !! free temporary ident arrays
258    if (allocated(identCol)) then
259       deallocate(identCol)
260    end if
261    if (allocated(identCol)) then
262       deallocate(identRow)
263    endif
264
89   #endif
90      
91 <    call initForce_Modules(thisStat)
92 <    if (thisStat /= 0) then
93 <       status = -1
94 <       return
271 <    endif
272 <
273 < !! Create neighbor lists
274 <    call expandList(thisStat)
275 <    if (thisStat /= 0) then
276 <       status = -1
277 <       return
278 <    endif
279 <
280 <    isFFinit = .true.
281 <
282 <
283 <  end subroutine init_FF
284 <
285 <
286 <
287 <
288 <  subroutine initForce_Modules(thisStat)
289 <    integer, intent(out) :: thisStat
290 <    integer :: my_status
91 >    !! initialize local variables  
92 >    natoms = getNlocal()
93 >    call getRcut(rcut,rcut2=rcutsq)
94 >    call getRlist(rlist,rlistsq)
95      
96 <    thisStat = 0
97 <    call init_lj_FF(ListHead,my_status)
294 <    if (my_status /= 0) then
295 <       thisStat = -1
296 <       return
297 <    end if
298 <
299 <  end subroutine initForce_Modules
300 <
301 <
302 <
303 <
304 < !! FORCE routine Calculates Lennard Jones forces.
305 < !------------------------------------------------------------->
306 <  subroutine do_force_loop(q,A,mu,u_l,f,t,tau,potE,do_pot,FFerror)
307 < !! Position array provided by C, dimensioned by getNlocal
308 <    real ( kind = dp ), dimension(3,getNlocal()) :: q
309 <  !! Rotation Matrix for each long range particle in simulation.
310 <    real( kind = dp), dimension(9,getNlocal()) :: A
311 <
312 <  !! Magnitude dipole moment
313 <    real( kind = dp ), dimension(3,getNlocal()) :: mu
314 <  !! Unit vectors for dipoles (lab frame)
315 <    real( kind = dp ), dimension(3,getNlocal()) :: u_l
316 < !! Force array provided by C, dimensioned by getNlocal
317 <    real ( kind = dp ), dimension(3,getNlocal()) :: f
318 < !! Torsion array provided by C, dimensioned by getNlocal
319 <    real( kind = dp ), dimension(3,getNlocal()) :: t
320 <
321 < !! Stress Tensor
322 <    real( kind = dp), dimension(9) :: tau
323 <
324 <    real ( kind = dp ) :: potE
325 <    logical ( kind = 2) :: do_pot
326 <    integer :: FFerror
327 <
96 >    !! See if we need to update neighbor lists
97 >    call checkNeighborList(natoms, q, rcut, rlist, update_nlist)
98      
99 <    type(atype), pointer :: Atype_i
100 <    type(atype), pointer :: Atype_j
99 >    !--------------WARNING...........................
100 >    ! Zero variables, NOTE:::: Forces are zeroed in C
101 >    ! Zeroing them here could delete previously computed
102 >    ! Forces.
103 >    !------------------------------------------------
104 >    call zero_module_variables()
105  
106 <
333 <
334 <
335 <  
336 <
337 < #ifdef IS_MPI
338 <  real( kind = DP ) :: pot_local
339 <
340 < !! Local arrays needed for MPI
341 <
342 < #endif
343 <
344 <
345 <
346 <  real( kind = DP )   :: pe
347 <  logical             :: update_nlist
348 <
349 <
350 <  integer ::  i, j, jbeg, jend, jnab, idim, jdim, idim2, jdim2, dim, dim2
351 <  integer :: nlist
352 <  integer :: j_start
353 <
354 <  real( kind = DP ) ::  r_ij, pot, ftmp, dudr, d2, drdx1, kt1, kt2, kt3, ktmp
355 <
356 <  real( kind = DP ) ::  rx_ij, ry_ij, rz_ij, rijsq
357 <  real( kind = DP ) ::  rlistsq, rcutsq,rlist,rcut
358 <
359 <  real( kind = DP ) :: dielectric = 0.0_dp
360 <
361 < ! a rig that need to be fixed.
362 < #ifdef IS_MPI
363 <  real( kind = dp ) :: pe_local
364 <  integer :: nlocal
365 < #endif
366 <  integer :: nrow
367 <  integer :: ncol
368 <  integer :: natoms
369 <  integer :: neighborListSize
370 <  integer :: listerror
371 < !! should we calculate the stress tensor
372 <  logical  :: do_stress = .false.
373 <
374 <
375 <  FFerror = 0
376 <
377 < ! Make sure we are properly initialized.
378 <  if (.not. isFFInit) then
379 <     write(default_error,*) "ERROR: lj_FF has not been properly initialized"
380 <     FFerror = -1
381 <     return
382 <  endif
383 < #ifdef IS_MPI
384 <    if (.not. isMPISimSet()) then
385 <     write(default_error,*) "ERROR: mpiSimulation has not been properly initialized"
386 <     FFerror = -1
387 <     return
388 <  endif
389 < #endif
390 <
391 < !! initialize local variables  
392 <  natoms = getNlocal()
393 <  call getRcut(rcut,rcut2=rcutsq)
394 <  call getRlist(rlist,rlistsq)
395 <
396 < !! Find ensemble
397 <  if (isEnsemble("NPT")) do_stress = .true.
398 < !! set to wrap
399 <  if (isPBC()) wrap = .true.
400 <
401 <
402 <
403 <  
404 < !! See if we need to update neighbor lists
405 <  call check(q,update_nlist)
406 <
407 < !--------------WARNING...........................
408 < ! Zero variables, NOTE:::: Forces are zeroed in C
409 < ! Zeroing them here could delete previously computed
410 < ! Forces.
411 < !------------------------------------------------
412 <  call zero_module_variables()
413 <
414 <
415 < ! communicate MPI positions
106 >    ! communicate MPI positions
107   #ifdef IS_MPI    
108 <    call gather(q,qRow,plan_row3d)
109 <    call gather(q,qCol,plan_col3d)
110 <
111 <    call gather(mu,muRow,plan_row3d)
112 <    call gather(mu,muCol,plan_col3d)
113 <
114 <    call gather(u_l,u_lRow,plan_row3d)
115 <    call gather(u_l,u_lCol,plan_col3d)
425 <
426 <    call gather(A,ARow,plan_row_rotation)
427 <    call gather(A,ACol,plan_col_rotation)
108 >    call gather(q,q_Row,plan_row3d)
109 >    call gather(q,q_Col,plan_col3d)
110 >    
111 >    call gather(u_l,u_l_Row,plan_row3d)
112 >    call gather(u_l,u_l_Col,plan_col3d)
113 >    
114 >    call gather(A,A_Row,plan_row_rotation)
115 >    call gather(A,A_Col,plan_col_rotation)
116   #endif
117  
118  
# Line 445 | Line 133 | contains
133        
134         do i = 1, nrow
135            point(i) = nlist + 1
448          Atype_i => identPtrListRow(i)%this
136            
137            inner: do j = 1, ncol
451             Atype_j => identPtrListColumn(j)%this
138              
139 <             call get_interatomic_vector(i,j,qRow(:,i),qCol(:,j),&
140 <                  rxij,ryij,rzij,rijsq,r)
141 <            
142 <             ! skip the loop if the atoms are identical
457 <             if (mpi_cycle_jLoop(i,j)) cycle inner:
458 <            
139 >             if (check_exclude(i,j)) cycle inner:
140 >
141 >             call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
142 >            
143               if (rijsq <  rlistsq) then            
144                  
145                  nlist = nlist + 1
146                  
147                  if (nlist > neighborListSize) then
148 <                   call expandList(listerror)
148 >                   call expandNeighborList(nlocal, listerror)
149                     if (listerror /= 0) then
150                        FFerror = -1
151                        write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
152                        return
153                     end if
154                  endif
471                
472                list(nlist) = j
155                  
156 <                
156 >                list(nlist) = j
157 >                                
158                  if (rijsq <  rcutsq) then
159 <                   call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
159 >                   call do_pair(i, j, rijsq, d)
160                  endif
161               endif
162            enddo inner
# Line 489 | Line 172 | contains
172            JEND = POINT(i+1) - 1
173            ! check thiat molecule i has neighbors
174            if (jbeg .le. jend) then
175 <
493 <             Atype_i => identPtrListRow(i)%this
175 >            
176               do jnab = jbeg, jend
177                  j = list(jnab)
178 <                Atype_j = identPtrListColumn(j)%this
179 <                call get_interatomic_vector(i,j,qRow(:,i),qCol(:,j),&
180 <                     rxij,ryij,rzij,rijsq,r)
181 <                
500 <                call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
178 >
179 >                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
180 >                call do_pair(i, j, rijsq, d)
181 >
182               enddo
183            endif
184         enddo
# Line 513 | Line 194 | contains
194        
195         neighborListSize = getNeighborListSize()
196         nlist = 0
197 <      
517 <    
197 >          
198         do i = 1, natoms-1
199            point(i) = nlist + 1
520          Atype_i   => identPtrList(i)%this
200  
201            inner: do j = i+1, natoms
202 <             Atype_j   => identPtrList(j)%this
203 <             call get_interatomic_vector(i,j,q(:,i),q(:,j),&
204 <                  rxij,ryij,rzij,rijsq,r)
202 >
203 >             if (check_exclude(i,j)) cycle inner:
204 >
205 >             call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
206            
207               if (rijsq <  rlistsq) then
208 <
208 >                
209                  nlist = nlist + 1
210                  
211                  if (nlist > neighborListSize) then
212 <                   call expandList(listerror)
212 >                   call expandList(natoms, listerror)
213                     if (listerror /= 0) then
214                        FFerror = -1
215                        write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
# Line 538 | Line 218 | contains
218                  endif
219                  
220                  list(nlist) = j
221 <
542 <    
221 >                    
222                  if (rijsq <  rcutsq) then
223 <                   call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
223 >                   call do_pair(i, j, rijsq, d)
224                  endif
225               endif
226            enddo inner
# Line 558 | Line 237 | contains
237            ! check thiat molecule i has neighbors
238            if (jbeg .le. jend) then
239              
561             Atype_i => identPtrList(i)%this
240               do jnab = jbeg, jend
241                  j = list(jnab)
242 <                Atype_j = identPtrList(j)%this
243 <                call get_interatomic_vector(i,j,q(:,i),q(:,j),&
244 <                     rxij,ryij,rzij,rijsq,r)
245 <                call do_pair(Atype_i,Atype_j,i,j,r,rxij,ryij,rzij)
242 >
243 >                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
244 >                call do_pair(i, j, rijsq, d)
245 >
246               enddo
247            endif
248         enddo
249      endif
250 <
250 >    
251   #endif
252 <
253 <
252 >    
253 >    
254   #ifdef IS_MPI
255      !! distribute all reaction field stuff (or anything for post-pair):
256      call scatter(rflRow,rflTemp1,plan_row3d)
# Line 581 | Line 259 | contains
259         rflTemp(1:3,i) = rflTemp1(1:3,i) + rflTemp2(1:3,i)
260      end do
261   #endif
262 <
262 >    
263   ! This is the post-pair loop:
264   #ifdef IS_MPI
265 <
265 >    
266      if (system_has_postpair_atoms) then
267         do i = 1, nlocal
268            Atype_i => identPtrListRow(i)%this
269            call do_postpair(i, Atype_i)
270         enddo
271      endif
272 <
272 >    
273   #else
274 <
274 >    
275      if (system_has_postpair_atoms) then
276         do i = 1, natoms
277            Atype_i => identPtr(i)%this
278            call do_postpair(i, Atype_i)
279         enddo
280      endif
281 <
281 >    
282   #endif
283 +    
284  
606
607
608
285   #ifdef IS_MPI
286      !!distribute forces
287  
288 <    call scatter(fRow,fTemp1,plan_row3d)
289 <    call scatter(fCol,fTemp2,plan_col3d)
614 <
615 <
288 >    call scatter(f_Row,f,plan_row3d)
289 >    call scatter(f_Col,f_temp,plan_col3d)
290      do i = 1,nlocal
291 <       fTemp(1:3,i) = fTemp1(1:3,i) + fTemp2(1:3,i)
291 >       f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
292      end do
293  
294 <    if (do_torque) then
295 <       call scatter(tRow,tTemp1,plan_row3d)
296 <       call scatter(tCol,tTemp2,plan_col3d)
294 >    if (doTorque()) then
295 >       call scatter(t_Row,t,plan_row3d)
296 >       call scatter(t_Col,t_temp,plan_col3d)
297      
298         do i = 1,nlocal
299 <          tTemp(1:3,i) = tTemp1(1:3,i) + tTemp2(1:3,i)
299 >          t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
300         end do
301      endif
302 <
302 >    
303      if (do_pot) then
304         ! scatter/gather pot_row into the members of my column
305 <       call scatter(eRow,eTemp,plan_row)
305 >       call scatter(pot_Row, pot_Temp, plan_row)
306        
307         ! scatter/gather pot_local into all other procs
308         ! add resultant to get total pot
309         do i = 1, nlocal
310 <          pe_local = pe_local + eTemp(i)
310 >          pot_local = pot_local + pot_Temp(i)
311         enddo
312  
313 <       eTemp = 0.0E0_DP
314 <       call scatter(eCol,eTemp,plan_col)
313 >       pot_Temp = 0.0_DP
314 >
315 >       call scatter(pot_Col, pot_Temp, plan_col)
316         do i = 1, nlocal
317 <          pe_local = pe_local + eTemp(i)
317 >          pot_local = pot_local + pot_Temp(i)
318         enddo
319        
320 <       pe = pe_local
320 >       pot = pot_local
321      endif
647 #else
648 ! Copy local array into return array for c
649    f = f+fTemp
650    t = t+tTemp
651 #endif
322  
323 <    potE = pe
323 >    if (doStress()) then
324 >       mpi_allreduce(tau, tau_Temp,9,mpi_double_precision,mpi_sum, &
325 >            mpi_comm_world,mpi_err)
326 >       mpi_allreduce(virial, virial_Temp,1,mpi_double_precision,mpi_sum, &
327 >            mpi_comm_world,mpi_err)
328 >    endif
329  
330 + #endif
331  
332 <    if (do_stress) then
333 < #ifdef IS_MPI
334 <       mpi_allreduce = (tau,tauTemp,9,mpi_double_precision,mpi_sum, &
659 <            mpi_comm_world,mpi_err)
660 < #else
661 <       tau = tauTemp
662 < #endif      
332 >    if (doStress()) then
333 >       tau = tau_Temp
334 >       virial = virial_Temp
335      endif
336  
337    end subroutine do_force_loop
338  
339  
668
669
670
671
672
673
674
675
340   !! Calculate any pre-force loop components and update nlist if necessary.
341    subroutine do_preForce(updateNlist)
342      logical, intent(inout) :: updateNlist
# Line 681 | Line 345 | contains
345  
346    end subroutine do_preForce
347  
684
685
686
687
688
689
690
691
692
693
694
695
348   !! Calculate any post force loop components, i.e. reaction field, etc.
349    subroutine do_postForce()
350  
# Line 700 | Line 352 | contains
352  
353    end subroutine do_postForce
354  
355 +  subroutine do_pair(i, j, rijsq, d)
356  
357 +    integer, intent(in) :: i, j
358 +    real ( kind = dp ), intent(in)    :: rijsq
359 +    real ( kind = dp )                :: r
360 +    real ( kind = dp ), intent(inout) :: d(3)
361  
362 +    r = sqrt(rijsq)
363 +    
364 +    logical :: is_LJ_i, is_LJ_j
365 +    logical :: is_DP_i, is_DP_j
366 +    logical :: is_Sticky_i, is_Sticky_j
367 +    integer :: me_i, me_j
368  
369 + #ifdef IS_MPI
370  
371 +    me_i = atid_row(i)
372 +    me_j = atid_col(j)
373  
374 + #else
375  
376 +    me_i = atid(i)
377 +    me_j = atid(j)
378  
379 + #endif
380  
381 +    call getElementProperty(atypes, me_i, "is_LJ", is_LJ_i)
382 +    call getElementProperty(atypes, me_j, "is_LJ", is_LJ_j)
383  
384 +    if ( is_LJ_i .and. is_LJ_j ) &
385 +         call do_lj_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
386  
387 +    call getElementProperty(atypes, me_i, "is_DP", is_DP_i)
388 +    call getElementProperty(atypes, me_j, "is_DP", is_DP_j)
389  
390 +    if ( is_DP_i .and. is_DP_j ) then
391  
392 +       call do_dipole_pair(i, j, d, r, pot, u_l, f, t, do_pot, do_stress)
393  
716
717
718
719  subroutine do_pair(atype_i,atype_j,i,j,r_ij,rx_ij,ry_ij,rz_ij)
720    type (atype ), pointer, intent(inout) :: atype_i
721    type (atype ), pointer, intent(inout) :: atype_j
722    integer :: i
723    integer :: j
724    real ( kind = dp ), intent(inout) :: rx_ij
725    real ( kind = dp ), intent(inout) :: ry_ij
726    real ( kind = dp ), intent(inout) :: rz_ij
727
728
729    real( kind = dp ) :: fx = 0.0_dp
730    real( kind = dp ) :: fy = 0.0_dp
731    real( kind = dp ) :: fz = 0.0_dp  
732  
733    real( kind = dp ) ::  drdx = 0.0_dp
734    real( kind = dp ) ::  drdy = 0.0_dp
735    real( kind = dp ) ::  drdz = 0.0_dp
736    
737
738    if (Atype_i%is_LJ .and. Atype_j%is_LJ) then
739       call getLJForce(r,pot,dudr,ljAtype_i,ljAtype_j,fx,fy,fz)
740    endif
741
742    if (Atype_i%is_dp .and. Atype_j%is_dp) then
743
744 #ifdef IS_MPI
745       call dipole_dipole(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
746            ulRow(:,i), ulCol(:,j), rt, rrf, pot)
747 #else
748       call dipole_dipole(i, j, atype_i, atype_j, rx_ij, ry_ij, rz_ij, r_ij, &
749            ul(:,i), ul(:,j), rt, rrf, pot)
750 #endif
751
394         if (do_reaction_field) then
395 < #ifdef IS_MPI
754 <          call accumulate_rf(i, j, r_ij, rflRow(:,i), rflCol(:j), &
755 <               ulRow(:i), ulCol(:,j), rt, rrf)
756 < #else
757 <          call accumulate_rf(i, j, r_ij, rfl(:,i), rfl(:j), &
758 <               ul(:,i), ul(:,j), rt, rrf)
759 < #endif
395 >          call accumulate_rf(i, j, r)
396         endif
397  
762
398      endif
399  
400 <    if (Atype_i%is_sticky .and. Atype_j%is_sticky) then
401 <       call getstickyforce(r,pot,dudr,ljAtype_i,ljAtype_j)
400 >    call getElementProperty(atypes, me_i, "is_Sticky", is_Sticky_i)
401 >    call getElementProperty(atypes, me_j, "is_Sticky", is_Sticky_j)
402 >
403 >    if ( is_Sticky_i .and. is_Sticky_j ) then
404 >       call do_sticky_pair(i, j, d, r, rijsq, A, pot, f, t, do_pot, do_stress)
405      endif
406  
407 <      
770 < #ifdef IS_MPI
771 <                eRow(i) = eRow(i) + pot*0.5
772 <                eCol(i) = eCol(i) + pot*0.5
773 < #else
774 <                    pe = pe + pot
775 < #endif                
776 <            
777 <                drdx = -rxij / r
778 <                drdy = -ryij / r
779 <                drdz = -rzij / r
780 <                
781 <                fx = dudr * drdx
782 <                fy = dudr * drdy
783 <                fz = dudr * drdz
784 <
785 <
786 <
787 <
788 <
789 <
790 <                
791 < #ifdef IS_MPI
792 <                fCol(1,j) = fCol(1,j) - fx
793 <                fCol(2,j) = fCol(2,j) - fy
794 <                fCol(3,j) = fCol(3,j) - fz
795 <                
796 <                fRow(1,j) = fRow(1,j) + fx
797 <                fRow(2,j) = fRow(2,j) + fy
798 <                fRow(3,j) = fRow(3,j) + fz
799 < #else
800 <                fTemp(1,j) = fTemp(1,j) - fx
801 <                fTemp(2,j) = fTemp(2,j) - fy
802 <                fTemp(3,j) = fTemp(3,j) - fz
803 <                fTemp(1,i) = fTemp(1,i) + fx
804 <                fTemp(2,i) = fTemp(2,i) + fy
805 <                fTemp(3,i) = fTemp(3,i) + fz
806 < #endif
807 <                
808 <                if (do_stress) then
809 <                   tauTemp(1) = tauTemp(1) + fx * rxij
810 <                   tauTemp(2) = tauTemp(2) + fx * ryij
811 <                   tauTemp(3) = tauTemp(3) + fx * rzij
812 <                   tauTemp(4) = tauTemp(4) + fy * rxij
813 <                   tauTemp(5) = tauTemp(5) + fy * ryij
814 <                   tauTemp(6) = tauTemp(6) + fy * rzij
815 <                   tauTemp(7) = tauTemp(7) + fz * rxij
816 <                   tauTemp(8) = tauTemp(8) + fz * ryij
817 <                   tauTemp(9) = tauTemp(9) + fz * rzij
818 <                endif
819 <
820 <
821 <
407 >      
408    end subroutine do_pair
409  
410  
411 <
412 <
827 <
828 <
829 <
830 <
831 <
832 <
833 <
834 <
835 <
836 <
837 <
838 <
839 <  subroutine get_interatomic_vector(q_i,q_j,rx_ij,ry_ij,rz_ij,r_sq,r_ij)
840 < !---------------- Arguments-------------------------------
841 <   !! index i
842 <
843 <    !! Position array
411 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
412 >    
413      real (kind = dp), dimension(3) :: q_i
414      real (kind = dp), dimension(3) :: q_j
846    !! x component of vector between i and j
847    real ( kind = dp ), intent(out)  :: rx_ij
848    !! y component of vector between i and j
849    real ( kind = dp ), intent(out)  :: ry_ij
850    !! z component of vector between i and j
851    real ( kind = dp ), intent(out)  :: rz_ij
852    !! magnitude of r squared
415      real ( kind = dp ), intent(out) :: r_sq
854    !! magnitude of vector r between atoms i and j.
855    real ( kind = dp ), intent(out) :: r_ij
856    !! wrap into periodic box.
857    logical, intent(in) :: wrap
858
859 !--------------- Local Variables---------------------------
860    !! Distance between i and j
416      real( kind = dp ) :: d(3)
862 !---------------- END DECLARATIONS-------------------------
417  
864
865 ! Find distance between i and j
418      d(1:3) = q_i(1:3) - q_j(1:3)
419 <
420 < ! Wrap back into periodic box if necessary
421 <    if ( wrap ) then
419 >    
420 >    ! Wrap back into periodic box if necessary
421 >    if ( isPBC() ) then
422         d(1:3) = d(1:3) - thisSim%box(1:3) * sign(1.0_dp,thisSim%box(1:3)) * &
423              int(abs(d(1:3)/thisSim%box(1:3) + 0.5_dp)
424 <    end if
424 >    endif
425      
874 !   Find Magnitude of the vector
426      r_sq = dot_product(d,d)
427 <    r_ij = sqrt(r_sq)
877 <
878 < !   Set each component for force calculation
879 <    rx_ij = d(1)
880 <    ry_ij = d(2)
881 <    rz_ij = d(3)
882 <
883 <
427 >        
428    end subroutine get_interatomic_vector
429 +  
430 +  subroutine zero_work_arrays()
431 +    
432 + #ifdef IS_MPI
433  
434 <  subroutine zero_module_variables()
435 <
888 < #ifndef IS_MPI
889 <
890 <    pe = 0.0E0_DP
891 <    tauTemp = 0.0_dp
892 <    fTemp = 0.0_dp
893 <    tTemp = 0.0_dp
894 < #else
895 <    qRow = 0.0_dp
896 <    qCol = 0.0_dp
434 >    q_Row = 0.0_dp
435 >    q_Col = 0.0_dp  
436      
437 <    muRow = 0.0_dp
438 <    muCol = 0.0_dp
437 >    u_l_Row = 0.0_dp
438 >    u_l_Col = 0.0_dp
439      
440 <    u_lRow = 0.0_dp
441 <    u_lCol = 0.0_dp
440 >    A_Row = 0.0_dp
441 >    A_Col = 0.0_dp
442      
443 <    ARow = 0.0_dp
444 <    ACol = 0.0_dp
445 <    
446 <    fRow = 0.0_dp
447 <    fCol = 0.0_dp
448 <    
449 <  
911 <    tRow = 0.0_dp
912 <    tCol = 0.0_dp
443 >    f_Row = 0.0_dp
444 >    f_Col = 0.0_dp
445 >    f_Temp = 0.0_dp
446 >      
447 >    t_Row = 0.0_dp
448 >    t_Col = 0.0_dp
449 >    t_Temp = 0.0_dp
450  
451 <  
451 >    pot_Row = 0.0_dp
452 >    pot_Col = 0.0_dp
453 >    pot_Temp = 0.0_dp
454  
916    eRow = 0.0_dp
917    eCol = 0.0_dp
918    eTemp = 0.0_dp
455   #endif
456  
457 <  end subroutine zero_module_variables
457 >    tau_Temp = 0.0_dp
458 >    virial_Temp = 0.0_dp
459 >    
460 >  end subroutine zero_work_arrays
461 >  
462  
923 #ifdef IS_MPI
463   !! Function to properly build neighbor lists in MPI using newtons 3rd law.
464   !! We don't want 2 processors doing the same i j pair twice.
465   !! Also checks to see if i and j are the same particle.
466 <  function mpi_cycle_jLoop(i,j) result(do_cycle)
466 >  function checkExcludes(atom1,atom2) result(do_cycle)
467   !--------------- Arguments--------------------------
468   ! Index i
469 <    integer,intent(in) :: i
469 >    integer,intent(in) :: atom1
470   ! Index j
471 <    integer,intent(in) :: j
471 >    integer,intent(in), optional :: atom2
472   ! Result do_cycle
473      logical :: do_cycle
474   !--------------- Local variables--------------------
475      integer :: tag_i
476      integer :: tag_j
477 < !--------------- END DECLARATIONS------------------    
478 <    tag_i = tagRow(i)
477 >    integer :: i
478 > !--------------- END DECLARATIONS------------------  
479 >    do_cycle = .false.
480 >
481 > #ifdef IS_MPI
482 >    tag_i = tagRow(atom1)
483 > #else
484 >    tag_i = tag(atom1)
485 > #endif
486 >
487 > !! Check global excludes first
488 >    if (.not. present(atom2)) then
489 >       do i = 1,nGlobalExcludes
490 >          if (excludeGlobal(i) == tag_i) then
491 >             do_cycle = .true.
492 >             return
493 >          end if
494 >       end do
495 >       return !! return after checking globals
496 >    end if
497 >
498 > !! we return if j not present here.
499      tag_j = tagColumn(j)
500  
501 <    do_cycle = .false.
501 >
502  
503      if (tag_i == tag_j) then
504         do_cycle = .true.
# Line 952 | Line 511 | contains
511      else                
512         if (mod(tag_i + tag_j,2) == 1) do_cycle = .true.
513      endif
955  end function mpi_cycle_jLoop
956 #endif
514  
515 +
516 +
517 +    do i = 1, nLocalExcludes
518 +       if (tag_i = excludes(1,i) .and. excludes(2,i) < 0) then
519 +          do_cycle = .true.
520 +          return
521 +       end if
522 +    end do
523 +      
524 +
525 +  end function checkExcludes
526 +
527 +
528   end module do_Forces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines