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 480 by chuckv, Tue Apr 8 17:16:22 2003 UTC vs.
Revision 845 by gezelter, Thu Oct 30 18:59:20 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.12 2003-04-08 17:16:22 chuckv Exp $, $Date: 2003-04-08 17:16:22 $, $Name: not supported by cvs2svn $, $Revision: 1.12 $
7 > !! @version $Id: do_Forces.F90,v 1.36 2003-10-30 18:59:20 gezelter Exp $, $Date: 2003-10-30 18:59:20 $, $Name: not supported by cvs2svn $, $Revision: 1.36 $
8  
9   module do_Forces
10    use force_globals
# Line 17 | Line 17 | module do_Forces
17    use dipole_dipole
18    use reaction_field
19    use gb_pair
20 +  use vector_class
21 +  use eam
22 +  use status
23   #ifdef IS_MPI
24    use mpiSimulation
25   #endif
# Line 27 | Line 30 | module do_Forces
30   #define __FORTRAN90
31   #include "fForceField.h"
32  
33 <  logical, save :: do_forces_initialized = .false.
33 >  logical, save :: do_forces_initialized = .false., haveRlist = .false.
34 >  logical, save :: havePolicies = .false.
35    logical, save :: FF_uses_LJ
36    logical, save :: FF_uses_sticky
37    logical, save :: FF_uses_dipoles
# Line 35 | Line 39 | module do_Forces
39    logical, save :: FF_uses_GB
40    logical, save :: FF_uses_EAM
41  
42 +  real(kind=dp), save :: rlist, rlistsq
43 +
44    public :: init_FF
45    public :: do_force_loop
46 +  public :: setRlistDF
47  
48 + #ifdef PROFILE
49 +  real(kind = dp) :: forceTime
50 +  real(kind = dp) :: forceTimeInitial, forceTimeFinal
51 +  real(kind = dp) :: globalForceTime
52 +  real(kind = dp) :: maxForceTime
53 +  integer, save :: nloops = 0
54 + #endif
55 +
56   contains
57  
58 +  subroutine setRlistDF( this_rlist )
59 +    
60 +    real(kind=dp) :: this_rlist
61 +
62 +    rlist = this_rlist
63 +    rlistsq = rlist * rlist
64 +    
65 +    haveRlist = .true.
66 +    if( havePolicies ) do_forces_initialized = .true.
67 +
68 +  end subroutine setRlistDF    
69 +
70    subroutine init_FF(LJMIXPOLICY, use_RF_c, thisStat)
71  
72      integer, intent(in) :: LJMIXPOLICY
# Line 87 | Line 114 | contains
114      !! check to make sure the FF_uses_RF setting makes sense
115      
116      if (FF_uses_dipoles) then
90       rrf = getRrf()
91       rt = getRt()      
92       call initialize_dipole(rrf, rt)
117         if (FF_uses_RF) then
118            dielect = getDielect()
119 <          call initialize_rf(rrf, rt, dielect)
119 >          call initialize_rf(dielect)
120         endif
121      else
122         if (FF_uses_RF) then          
# Line 100 | Line 124 | contains
124            thisStat = -1
125            return
126         endif
127 <    endif
127 >    endif
128  
129      if (FF_uses_LJ) then
130        
107       call getRcut(rcut)
108
131         select case (LJMIXPOLICY)
132         case (LB_MIXING_RULE)
133 <          call init_lj_FF(LB_MIXING_RULE, rcut, my_status)            
133 >          call init_lj_FF(LB_MIXING_RULE, my_status)            
134         case (EXPLICIT_MIXING_RULE)
135 <          call init_lj_FF(EXPLICIT_MIXING_RULE, rcut, my_status)
135 >          call init_lj_FF(EXPLICIT_MIXING_RULE, my_status)
136         case default
137            write(default_error,*) 'unknown LJ Mixing Policy!'
138            thisStat = -1
# Line 129 | Line 151 | contains
151            return
152         end if
153      endif
154 +
155 +
156 +    if (FF_uses_EAM) then
157 +         call init_EAM_FF(my_status)
158 +       if (my_status /= 0) then
159 +          write(*,*) "init_EAM_FF returned a bad status"
160 +          thisStat = -1
161 +          return
162 +       end if
163 +    endif
164 +
165 +
166      
167      if (FF_uses_GB) then
168         call check_gb_pair_FF(my_status)
# Line 149 | Line 183 | contains
183            return
184         endif
185      endif
186 +    
187  
188 <    do_forces_initialized = .true.    
189 <
188 >    havePolicies = .true.
189 >    if( haveRlist ) do_forces_initialized = .true.
190 >
191    end subroutine init_FF
192    
193  
# Line 179 | Line 215 | contains
215      real( kind = DP ) :: pot_local
216      integer :: nrow
217      integer :: ncol
218 +    integer :: nprocs
219   #endif
220      integer :: nlocal
221      integer :: natoms    
222      logical :: update_nlist  
223      integer :: i, j, jbeg, jend, jnab
224      integer :: nlist
225 <    real( kind = DP ) ::  rijsq, rlistsq, rcutsq, rlist, rcut
225 >    real( kind = DP ) ::  rijsq
226      real(kind=dp),dimension(3) :: d
227      real(kind=dp) :: rfpot, mu_i, virial
228      integer :: me_i
# Line 194 | Line 231 | contains
231      integer :: listerror, error
232      integer :: localError
233  
234 +    real(kind=dp) :: listSkin = 1.0  
235 +
236      !! initialize local variables  
237  
238   #ifdef IS_MPI
# Line 205 | Line 244 | contains
244      nlocal = getNlocal()
245      natoms = nlocal
246   #endif
247 <  
209 <    call getRcut(rcut,rc2=rcutsq)
210 <    call getRlist(rlist,rlistsq)
211 <    
247 >
248      call check_initialization(localError)
249      if ( localError .ne. 0 ) then
250 +       call handleError("do_force_loop","Not Initialized")
251         error = -1
252         return
253      end if
# Line 218 | Line 255 | contains
255  
256      do_pot = do_pot_c
257      do_stress = do_stress_c
221    
258  
259 +
260      ! Gather all information needed by all force loops:
261      
262   #ifdef IS_MPI    
# Line 236 | Line 273 | contains
273      endif
274      
275   #endif
276 <    
276 >
277 > !! Begin force loop timing:
278 > #ifdef PROFILE
279 >    call cpu_time(forceTimeInitial)
280 >    nloops = nloops + 1
281 > #endif
282 >  
283      if (FF_RequiresPrepairCalc() .and. SimRequiresPrepairCalc()) then
284         !! See if we need to update neighbor lists
285 <       call checkNeighborList(nlocal, q, rcut, rlist, update_nlist)  
285 >       call checkNeighborList(nlocal, q, listSkin, update_nlist)  
286         !! if_mpi_gather_stuff_for_prepair
287         !! do_prepair_loop_if_needed
288         !! if_mpi_scatter_stuff_from_prepair
289         !! if_mpi_gather_stuff_from_prepair_to_main_loop
290 <    else
291 <       !! See if we need to update neighbor lists
292 <       call checkNeighborList(nlocal, q, rcut, rlist, update_nlist)  
290 >    
291 > !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>>
292 > #ifdef IS_MPI
293 >    
294 >    if (update_nlist) then
295 >      
296 >       !! save current configuration, construct neighbor list,
297 >       !! and calculate forces
298 >       call saveNeighborList(nlocal, q)
299 >      
300 >       neighborListSize = size(list)
301 >       nlist = 0      
302 >      
303 >       do i = 1, nrow
304 >          point(i) = nlist + 1
305 >          
306 >          prepair_inner: do j = 1, ncol
307 >            
308 >             if (skipThisPair(i,j)) cycle prepair_inner
309 >            
310 >             call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
311 >            
312 >             if (rijsq < rlistsq) then            
313 >                
314 >                nlist = nlist + 1
315 >                
316 >                if (nlist > neighborListSize) then
317 >                   call expandNeighborList(nlocal, listerror)
318 >                   if (listerror /= 0) then
319 >                      error = -1
320 >                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
321 >                      return
322 >                   end if
323 >                   neighborListSize = size(list)
324 >                endif
325 >                
326 >                list(nlist) = j
327 >                call do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot_local)                      
328 >             endif
329 >          enddo prepair_inner
330 >       enddo
331 >
332 >       point(nrow + 1) = nlist + 1
333 >      
334 >    else  !! (of update_check)
335 >
336 >       ! use the list to find the neighbors
337 >       do i = 1, nrow
338 >          JBEG = POINT(i)
339 >          JEND = POINT(i+1) - 1
340 >          ! check thiat molecule i has neighbors
341 >          if (jbeg .le. jend) then
342 >            
343 >             do jnab = jbeg, jend
344 >                j = list(jnab)
345 >
346 >                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
347 >                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
348 >                     u_l, A, f, t, pot_local)
349 >
350 >             enddo
351 >          endif
352 >       enddo
353      endif
354      
355 + #else
356 +    
357 +    if (update_nlist) then
358 +      
359 +       ! save current configuration, contruct neighbor list,
360 +       ! and calculate forces
361 +       call saveNeighborList(natoms, q)
362 +      
363 +       neighborListSize = size(list)
364 +  
365 +       nlist = 0
366 +
367 +       do i = 1, natoms-1
368 +          point(i) = nlist + 1
369 +          
370 +          prepair_inner: do j = i+1, natoms
371 +            
372 +             if (skipThisPair(i,j))  cycle prepair_inner
373 +                          
374 +             call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
375 +          
376 +
377 +             if (rijsq < rlistsq) then
378 +
379 +          
380 +                nlist = nlist + 1
381 +              
382 +                if (nlist > neighborListSize) then
383 +                   call expandNeighborList(natoms, listerror)
384 +                   if (listerror /= 0) then
385 +                      error = -1
386 +                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
387 +                      return
388 +                   end if
389 +                   neighborListSize = size(list)
390 +                endif
391 +                
392 +                list(nlist) = j
393 +                
394 +                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
395 +                        u_l, A, f, t, pot)
396 +                
397 +             endif
398 +          enddo prepair_inner
399 +       enddo
400 +      
401 +       point(natoms) = nlist + 1
402 +      
403 +    else !! (update)
404 +  
405 +       ! use the list to find the neighbors
406 +       do i = 1, natoms-1
407 +          JBEG = POINT(i)
408 +          JEND = POINT(i+1) - 1
409 +          ! check thiat molecule i has neighbors
410 +          if (jbeg .le. jend) then
411 +            
412 +             do jnab = jbeg, jend
413 +                j = list(jnab)
414 +
415 +                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
416 +                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
417 +                     u_l, A, f, t, pot)
418 +
419 +             enddo
420 +          endif
421 +       enddo
422 +    endif    
423 + #endif
424 +    !! Do rest of preforce calculations
425 +    !! do necessary preforce calculations  
426 +    call do_preforce(nlocal,pot)
427 +   ! we have already updated the neighbor list set it to false...
428 +   update_nlist = .false.
429 +    else
430 +       !! See if we need to update neighbor lists for non pre-pair
431 +       call checkNeighborList(nlocal, q, listSkin, update_nlist)  
432 +    endif
433 +
434 +
435 +
436 +
437 +
438 + !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>>>>>>>>>>>>>>>>
439 +
440 +
441 +
442 +
443 +  
444   #ifdef IS_MPI
445      
446      if (update_nlist) then
# Line 269 | Line 461 | contains
461              
462               call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
463              
464 <             if (rijsq <  rlistsq) then            
464 >             if (rijsq < rlistsq) then            
465                  
466                  nlist = nlist + 1
467                  
# Line 285 | Line 477 | contains
477                  
478                  list(nlist) = j
479                                  
480 <                if (rijsq <  rcutsq) then
481 <                   call do_pair(i, j, rijsq, d, do_pot, do_stress, &
482 <                        u_l, A, f, t, pot_local)
291 <                endif
480 >                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
481 >                     u_l, A, f, t, pot_local)
482 >                
483               endif
484            enddo inner
485         enddo
# Line 338 | Line 529 | contains
529               call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
530            
531  
532 <             if (rijsq <  rlistsq) then
532 >             if (rijsq < rlistsq) then
533                  
534                  nlist = nlist + 1
535                
# Line 354 | Line 545 | contains
545                  
546                  list(nlist) = j
547                  
548 <                if (rijsq <  rcutsq) then
358 <                   call do_pair(i, j, rijsq, d, do_pot, do_stress, &
548 >                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
549                          u_l, A, f, t, pot)
550 <                endif
550 >                
551               endif
552            enddo inner
553         enddo
# Line 388 | Line 578 | contains
578   #endif
579      
580      ! phew, done with main loop.
581 <    
581 >
582 > !! Do timing
583 > #ifdef PROFILE
584 >    call cpu_time(forceTimeFinal)
585 >    forceTime = forceTime + forceTimeFinal - forceTimeInitial
586 > #endif
587 >
588 >
589   #ifdef IS_MPI
590      !!distribute forces
591    
# Line 488 | Line 685 | contains
685      endif
686  
687      if (do_stress) then
688 <       call mpi_allreduce(tau_Temp, tau,9,mpi_double_precision,mpi_sum, &
688 >      call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
689              mpi_comm_world,mpi_err)
690         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
691              mpi_comm_world,mpi_err)
# Line 502 | Line 699 | contains
699      endif
700  
701   #endif
702 <    
702 >
703 > #ifdef PROFILE
704 >    if (do_pot) then
705 >
706 > #ifdef IS_MPI
707 >
708 >      
709 >       call printCommTime()
710 >
711 >       call mpi_allreduce(forceTime,globalForceTime,1,MPI_DOUBLE_PRECISION, &
712 >            mpi_sum,mpi_comm_world,mpi_err)
713 >
714 >       call mpi_allreduce(forceTime,maxForceTime,1,MPI_DOUBLE_PRECISION, &
715 >            MPI_MAX,mpi_comm_world,mpi_err)
716 >      
717 >       call mpi_comm_size( MPI_COMM_WORLD, nprocs,mpi_err)
718 >      
719 >       if (getMyNode() == 0) then
720 >          write(*,*) "Total processor time spent in force calculations is: ", globalForceTime
721 >          write(*,*) "Total Time spent in force loop per processor is: ", globalforceTime/nprocs
722 >          write(*,*) "Maximum force time on any processor is: ", maxForceTime
723 >       end if
724 > #else
725 >       write(*,*) "Time spent in force loop is: ", forceTime
726 > #endif
727 >
728 >    
729 >    endif
730 >
731 > #endif
732 >
733    end subroutine do_force_loop
734  
735    subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot)
# Line 521 | Line 748 | contains
748      logical :: is_LJ_i, is_LJ_j
749      logical :: is_DP_i, is_DP_j
750      logical :: is_GB_i, is_GB_j
751 +    logical :: is_EAM_i,is_EAM_j
752      logical :: is_Sticky_i, is_Sticky_j
753      integer :: me_i, me_j
754  
755      r = sqrt(rijsq)
756  
757   #ifdef IS_MPI
758 +    if (tagRow(i) .eq. tagColumn(j)) then
759 +       write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
760 +    endif
761  
762      me_i = atid_row(i)
763      me_j = atid_col(j)
# Line 551 | Line 782 | contains
782         call getElementProperty(atypes, me_j, "is_DP", is_DP_j)
783        
784         if ( is_DP_i .and. is_DP_j ) then
554          
785            call do_dipole_pair(i, j, d, r, rijsq, pot, u_l, f, t, &
786                 do_pot, do_stress)
787            if (FF_uses_RF .and. SimUsesRF()) then
# Line 576 | Line 806 | contains
806  
807      if (FF_uses_GB .and. SimUsesGB()) then
808  
809 +
810         call getElementProperty(atypes, me_i, "is_GB", is_GB_i)
811         call getElementProperty(atypes, me_j, "is_GB", is_GB_j)
812        
# Line 585 | Line 816 | contains
816         endif
817      endif
818      
819 +
820 +  
821 +   if (FF_uses_EAM .and. SimUsesEAM()) then
822 +      call getElementProperty(atypes, me_i, "is_EAM", is_EAM_i)
823 +      call getElementProperty(atypes, me_j, "is_EAM", is_EAM_j)
824 +      
825 +      if ( is_EAM_i .and. is_EAM_j ) &
826 +           call do_eam_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
827 +   endif
828 +
829 +
830 +
831 +
832    end subroutine do_pair
833 +
834 +
835 +
836 +  subroutine do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot)
837 +   real( kind = dp ) :: pot
838 +   real( kind = dp ), dimension(3,getNlocal()) :: u_l
839 +   real (kind=dp), dimension(9,getNlocal()) :: A
840 +   real (kind=dp), dimension(3,getNlocal()) :: f
841 +   real (kind=dp), dimension(3,getNlocal()) :: t
842 +  
843 +   logical, intent(inout) :: do_pot, do_stress
844 +   integer, intent(in) :: i, j
845 +   real ( kind = dp ), intent(inout)    :: rijsq
846 +   real ( kind = dp )                :: r
847 +   real ( kind = dp ), intent(inout) :: d(3)
848 +  
849 +   logical :: is_EAM_i, is_EAM_j
850 +  
851 +   integer :: me_i, me_j
852 +  
853 +   r = sqrt(rijsq)
854 +  
855  
856 + #ifdef IS_MPI
857 +   if (tagRow(i) .eq. tagColumn(j)) then
858 +      write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
859 +   endif
860 +  
861 +   me_i = atid_row(i)
862 +   me_j = atid_col(j)
863 +  
864 + #else
865 +  
866 +   me_i = atid(i)
867 +   me_j = atid(j)
868 +  
869 + #endif
870 +    
871 +   if (FF_uses_EAM .and. SimUsesEAM()) then
872 +      call getElementProperty(atypes, me_i, "is_EAM", is_EAM_i)
873 +      call getElementProperty(atypes, me_j, "is_EAM", is_EAM_j)
874 +      
875 +      if ( is_EAM_i .and. is_EAM_j ) &
876 +           call calc_EAM_prepair_rho(i, j, d, r, rijsq )
877 +   endif
878  
879 + end subroutine do_prepair
880 +
881 +
882 +
883 +
884 +  subroutine do_preforce(nlocal,pot)
885 +    integer :: nlocal
886 +    real( kind = dp ) :: pot
887 +
888 +    if (FF_uses_EAM .and. SimUsesEAM()) then
889 +       call calc_EAM_preforce_Frho(nlocal,pot)
890 +    endif
891 +
892 +
893 +  end subroutine do_preforce
894 +  
895 +  
896    subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
897      
898      real (kind = dp), dimension(3) :: q_i
899      real (kind = dp), dimension(3) :: q_j
900      real ( kind = dp ), intent(out) :: r_sq
901 <    real( kind = dp ) :: d(3)
902 <    real( kind = dp ) :: d_old(3)
903 <    d(1:3) = q_i(1:3) - q_j(1:3)
904 <    d_old = d
901 >    real( kind = dp ) :: d(3), scaled(3)
902 >    integer i
903 >
904 >    d(1:3) = q_j(1:3) - q_i(1:3)
905 >
906      ! Wrap back into periodic box if necessary
907      if ( SimUsesPBC() ) then
908        
909 <       d(1:3) = d(1:3) - box(1:3) * sign(1.0_dp,d(1:3)) * &
910 <            int(abs(d(1:3)/box(1:3)) + 0.5_dp)
909 >       if( .not.boxIsOrthorhombic ) then
910 >          ! calc the scaled coordinates.
911 >          
912 >          scaled = matmul(HmatInv, d)
913 >          
914 >          ! wrap the scaled coordinates
915 >
916 >          scaled = scaled  - anint(scaled)
917 >          
918 >
919 >          ! calc the wrapped real coordinates from the wrapped scaled
920 >          ! coordinates
921 >
922 >          d = matmul(Hmat,scaled)
923 >
924 >       else
925 >          ! calc the scaled coordinates.
926 >          
927 >          do i = 1, 3
928 >             scaled(i) = d(i) * HmatInv(i,i)
929 >            
930 >             ! wrap the scaled coordinates
931 >            
932 >             scaled(i) = scaled(i) - anint(scaled(i))
933 >            
934 >             ! calc the wrapped real coordinates from the wrapped scaled
935 >             ! coordinates
936 >
937 >             d(i) = scaled(i)*Hmat(i,i)
938 >          enddo
939 >       endif
940        
941      endif
942 +    
943      r_sq = dot_product(d,d)
944 <        
944 >    
945    end subroutine get_interatomic_vector
946 <
946 >  
947    subroutine check_initialization(error)
948      integer, intent(out) :: error
949      
950      error = 0
951      ! Make sure we are properly initialized.
952      if (.not. do_forces_initialized) then
953 +       write(*,*) "Forces not initialized"
954         error = -1
955         return
956      endif
# Line 661 | Line 998 | contains
998  
999   #endif
1000  
1001 +
1002 +    if (FF_uses_EAM .and. SimUsesEAM()) then
1003 +       call clean_EAM()
1004 +    endif
1005 +
1006 +
1007 +
1008 +
1009 +
1010      rf = 0.0_dp
1011      tau_Temp = 0.0_dp
1012      virial_Temp = 0.0_dp
# Line 773 | Line 1119 | end module do_Forces
1119      doesit = FF_uses_RF
1120    end function FF_RequiresPostpairCalc
1121    
1122 + !! This cleans componets of force arrays belonging only to fortran
1123 +
1124   end module do_Forces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines