ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/do_Forces.F90
(Generate patch)

Comparing trunk/OOPSE/libmdtools/do_Forces.F90 (file contents):
Revision 388 by chuckv, Fri Mar 21 22:11:50 2003 UTC vs.
Revision 480 by chuckv, Tue Apr 8 17:16:22 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.2 2003-03-21 22:11:50 chuckv Exp $, $Date: 2003-03-21 22:11:50 $, $Name: not supported by cvs2svn $, $Revision: 1.2 $
7 > !! @version $Id: do_Forces.F90,v 1.12 2003-04-08 17:16:22 chuckv Exp $, $Date: 2003-04-08 17:16:22 $, $Name: not supported by cvs2svn $, $Revision: 1.12 $
8  
9   module do_Forces
10    use force_globals
# Line 140 | Line 140 | contains
140  
141      if (FF_uses_GB .and. FF_uses_LJ) then
142      endif
143 <
143 >    if (.not. do_forces_initialized) then
144 >       !! Create neighbor lists
145 >       call expandNeighborList(getNlocal(), my_status)
146 >       if (my_Status /= 0) then
147 >          write(default_error,*) "SimSetup: ExpandNeighborList returned error."
148 >          thisStat = -1
149 >          return
150 >       endif
151 >    endif
152  
153      do_forces_initialized = .true.    
154  
# Line 167 | Line 175 | contains
175      logical ( kind = 2) :: do_pot_c, do_stress_c
176      logical :: do_pot
177      logical :: do_stress
178 < #ifdef IS_MPI
178 > #ifdef IS_MPI
179      real( kind = DP ) :: pot_local
180      integer :: nrow
181      integer :: ncol
# Line 189 | Line 197 | contains
197      !! initialize local variables  
198  
199   #ifdef IS_MPI
200 +    pot_local = 0.0_dp
201      nlocal = getNlocal()
202      nrow   = getNrow(plan_row)
203      ncol   = getNcol(plan_col)
# Line 196 | Line 205 | contains
205      nlocal = getNlocal()
206      natoms = nlocal
207   #endif
208 <
208 >  
209      call getRcut(rcut,rc2=rcutsq)
210      call getRlist(rlist,rlistsq)
211      
# Line 209 | Line 218 | contains
218  
219      do_pot = do_pot_c
220      do_stress = do_stress_c
221 +    
222  
223      ! Gather all information needed by all force loops:
224      
# Line 245 | Line 255 | contains
255        
256         !! save current configuration, construct neighbor list,
257         !! and calculate forces
258 <       call saveNeighborList(q)
258 >       call saveNeighborList(nlocal, q)
259        
260         neighborListSize = size(list)
261         nlist = 0      
# Line 277 | Line 287 | contains
287                                  
288                  if (rijsq <  rcutsq) then
289                     call do_pair(i, j, rijsq, d, do_pot, do_stress, &
290 <                        u_l, A, f, t,pot)
290 >                        u_l, A, f, t, pot_local)
291                  endif
292               endif
293            enddo inner
# Line 299 | Line 309 | contains
309  
310                  call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
311                  call do_pair(i, j, rijsq, d, do_pot, do_stress, &
312 <                     u_l, A, f, t,pot)
312 >                     u_l, A, f, t, pot_local)
313  
314               enddo
315            endif
# Line 312 | Line 322 | contains
322        
323         ! save current configuration, contruct neighbor list,
324         ! and calculate forces
325 <       call saveNeighborList(q)
325 >       call saveNeighborList(natoms, q)
326        
327         neighborListSize = size(list)
328    
# Line 346 | Line 356 | contains
356                  
357                  if (rijsq <  rcutsq) then
358                     call do_pair(i, j, rijsq, d, do_pot, do_stress, &
359 <                        u_l, A, f, t,pot)
359 >                        u_l, A, f, t, pot)
360                  endif
361               endif
362            enddo inner
# Line 368 | Line 378 | contains
378  
379                  call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
380                  call do_pair(i, j, rijsq, d, do_pot, do_stress, &
381 <                     u_l, A, f, t,pot)
381 >                     u_l, A, f, t, pot)
382  
383               enddo
384            endif
# Line 381 | Line 391 | contains
391      
392   #ifdef IS_MPI
393      !!distribute forces
394 <    
395 <    call scatter(f_Row,f,plan_row3d)
394 >  
395 >    f_temp = 0.0_dp
396 >    call scatter(f_Row,f_temp,plan_row3d)
397 >    do i = 1,nlocal
398 >       f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
399 >    end do
400 >
401 >    f_temp = 0.0_dp
402      call scatter(f_Col,f_temp,plan_col3d)
403      do i = 1,nlocal
404         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
405      end do
406      
407      if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then
408 <       call scatter(t_Row,t,plan_row3d)
408 >       t_temp = 0.0_dp
409 >       call scatter(t_Row,t_temp,plan_row3d)
410 >       do i = 1,nlocal
411 >          t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
412 >       end do
413 >       t_temp = 0.0_dp
414         call scatter(t_Col,t_temp,plan_col3d)
415        
416         do i = 1,nlocal
# Line 400 | Line 421 | contains
421      if (do_pot) then
422         ! scatter/gather pot_row into the members of my column
423         call scatter(pot_Row, pot_Temp, plan_row)
424 <      
424 >
425         ! scatter/gather pot_local into all other procs
426         ! add resultant to get total pot
427         do i = 1, nlocal
428            pot_local = pot_local + pot_Temp(i)
429         enddo
430 +      
431 +       pot_Temp = 0.0_DP
432  
410       pot_Temp = 0.0_DP
411
433         call scatter(pot_Col, pot_Temp, plan_col)
434         do i = 1, nlocal
435            pot_local = pot_local + pot_Temp(i)
436         enddo
437 <      
437 >
438      endif    
439   #endif
440  
# Line 461 | Line 482 | contains
482   #ifdef IS_MPI
483  
484      if (do_pot) then
485 <       pot = pot_local
485 >       pot = pot + pot_local
486         !! we assume the c code will do the allreduce to get the total potential
487         !! we could do it right here if we needed to...
488      endif
489  
490      if (do_stress) then
491 <       call mpi_allreduce(tau, tau_Temp,9,mpi_double_precision,mpi_sum, &
491 >       call mpi_allreduce(tau_Temp, tau,9,mpi_double_precision,mpi_sum, &
492              mpi_comm_world,mpi_err)
493 <       call mpi_allreduce(virial, virial_Temp,1,mpi_double_precision,mpi_sum, &
493 >       call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
494              mpi_comm_world,mpi_err)
495      endif
496  
# Line 484 | Line 505 | contains
505      
506    end subroutine do_force_loop
507  
508 <  subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t,pot)
508 >  subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot)
509  
510      real( kind = dp ) :: pot
511 <    real( kind = dp ), dimension(:,:) :: u_l
512 <    real (kind=dp), dimension(:,:) :: A
513 <    real (kind=dp), dimension(:,:) :: f
514 <    real (kind=dp), dimension(:,:) :: t
511 >    real( kind = dp ), dimension(3,getNlocal()) :: u_l
512 >    real (kind=dp), dimension(9,getNlocal()) :: A
513 >    real (kind=dp), dimension(3,getNlocal()) :: f
514 >    real (kind=dp), dimension(3,getNlocal()) :: t
515  
516      logical, intent(inout) :: do_pot, do_stress
517      integer, intent(in) :: i, j
# Line 578 | Line 599 | contains
599      d_old = d
600      ! Wrap back into periodic box if necessary
601      if ( SimUsesPBC() ) then
602 <
602 >      
603         d(1:3) = d(1:3) - box(1:3) * sign(1.0_dp,d(1:3)) * &
604              int(abs(d(1:3)/box(1:3)) + 0.5_dp)
605 <
605 >      
606      endif
607      r_sq = dot_product(d,d)
608          
# Line 643 | Line 664 | contains
664      rf = 0.0_dp
665      tau_Temp = 0.0_dp
666      virial_Temp = 0.0_dp
646    
667    end subroutine zero_work_arrays
668    
669    function skipThisPair(atom1, atom2) result(skip_it)
# Line 687 | Line 707 | contains
707   #else
708      unique_id_2 = atom2
709   #endif
710 <    
710 >
711   #ifdef IS_MPI
712      !! this situation should only arise in MPI simulations
713      if (unique_id_1 == unique_id_2) then
# Line 697 | Line 717 | contains
717      
718      !! this prevents us from doing the pair on multiple processors
719      if (unique_id_1 < unique_id_2) then
720 <       if (mod(unique_id_1 + unique_id_2,2) == 0) skip_it = .true.
721 <       return
720 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
721 >          skip_it = .true.
722 >          return
723 >       endif
724      else                
725 <       if (mod(unique_id_1 + unique_id_2,2) == 1) skip_it = .true.
726 <       return
725 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
726 >          skip_it = .true.
727 >          return
728 >       endif
729      endif
730   #endif
731 <
731 >
732      !! the rest of these situations can happen in all simulations:
733      do i = 1, nExcludes_global      
734         if ((excludesGlobal(i) == unique_id_1) .or. &
# Line 713 | Line 737 | contains
737            return
738         endif
739      enddo
740 <
740 >
741      do i = 1, nExcludes_local
742         if (excludesLocal(1,i) == unique_id_1) then
743            if (excludesLocal(2,i) == unique_id_2) then

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines