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

Comparing trunk/OOPSE/libmdtools/calc_eam.F90 (file contents):
Revision 653 by chuckv, Fri Jul 25 20:00:17 2003 UTC vs.
Revision 882 by chuckv, Wed Dec 17 20:13:33 2003 UTC

# Line 15 | Line 15 | module eam
15    logical, save :: EAM_FF_initialized = .false.
16    integer, save :: EAM_Mixing_Policy
17    real(kind = dp), save :: EAM_rcut
18 <  real(kind = dp), save :: EAM_rcut_orig
18 >  logical, save :: haveRcut = .false.
19  
20    character(len = statusMsgSize) :: errMesg
21    integer :: eam_err
# Line 60 | Line 60 | module eam
60  
61   !! Arrays for MPI storage
62   #ifdef IS_MPI
63 <  real( kind = dp), dimension(:), allocatable :: dfrhodrho_col
64 <  real( kind = dp), dimension(:), allocatable :: dfrhodrho_row
65 <  real( kind = dp), dimension(:), allocatable :: frho_row
66 <  real( kind = dp), dimension(:), allocatable :: frho_col
67 <  real( kind = dp), dimension(:), allocatable :: rho_row
68 <  real( kind = dp), dimension(:), allocatable :: rho_col
69 <  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho_col
70 <  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho_row
63 >  real( kind = dp),save, dimension(:), allocatable :: dfrhodrho_col
64 >  real( kind = dp),save, dimension(:), allocatable :: dfrhodrho_row
65 >  real( kind = dp),save, dimension(:), allocatable :: frho_row
66 >  real( kind = dp),save, dimension(:), allocatable :: frho_col
67 >  real( kind = dp),save, dimension(:), allocatable :: rho_row
68 >  real( kind = dp),save, dimension(:), allocatable :: rho_col
69 >  real( kind = dp),save, dimension(:), allocatable :: rho_tmp
70 >  real( kind = dp),save, dimension(:), allocatable :: d2frhodrhodrho_col
71 >  real( kind = dp),save, dimension(:), allocatable :: d2frhodrhodrho_row
72   #endif
73  
74    type, private :: EAMTypeList
# Line 78 | Line 79 | module eam
79    end type EAMTypeList
80  
81  
82 <  type (eamTypeList) :: EAMList
82 >  type (eamTypeList), save :: EAMList
83  
84    !! standard eam stuff  
85  
# Line 89 | Line 90 | module eam
90    public :: newEAMtype
91    public :: calc_eam_prepair_rho
92    public :: calc_eam_preforce_Frho
93 <  
93 >  public :: clean_EAM
94  
95   contains
96  
# Line 114 | Line 115 | contains
115      integer                                :: alloc_stat
116      integer                                :: current
117      integer,pointer                        :: Matchlist(:) => null()
118 <    type (EAMtype), pointer                :: makeEamtype => null()
118 >
119      status = 0
120  
121 +
122      !! Assume that atypes has already been set and get the total number of types in atypes
123      !! Also assume that every member of atypes is a EAM model.
124    
# Line 132 | Line 134 | contains
134      current = EAMList%currentAddition
135      
136  
137 <    call allocate_EAMType(eam_nrho,eam_nr,makeEamtype,stat=alloc_stat)
137 >    call allocate_EAMType(eam_nrho,eam_nr,EAMList%EAMParams(current),stat=alloc_stat)
138      if (alloc_stat /= 0) then
139         status = -1
140         return
141      end if
140    makeEamtype => EAMList%EAMParams(current)
142  
143      ! this is a possible bug, we assume a correspondence between the vector atypes and
144      ! EAMAtypes
# Line 147 | Line 148 | contains
148      EAMList%EAMParams(current)%eam_nrho     = eam_nrho
149      EAMList%EAMParams(current)%eam_drho     = eam_drho
150      EAMList%EAMParams(current)%eam_nr       = eam_nr
151 +    EAMList%EAMParams(current)%eam_dr       = eam_dr
152      EAMList%EAMParams(current)%eam_rcut     = rcut
153      EAMList%EAMParams(current)%eam_Z_r      = eam_Z_r
154      EAMList%EAMParams(current)%eam_rho_r    = eam_rho_r
# Line 164 | Line 166 | contains
166      integer :: number_r, number_rho
167  
168  
169 +    status = 0
170 +    if (EAMList%currentAddition == 0) then
171 +       call handleError("init_EAM_FF","No members in EAMList")
172 +       status = -1
173 +       return
174 +    end if
175  
176 +
177         do i = 1, EAMList%currentAddition
169  
170          EAMList%EAMParams(i)%eam_rvals(1:EAMList%EAMParams(i)%eam_nr) = &
171               real(EAMList%EAMParams(i)%eam_nr,kind=dp)* &
172               EAMList%EAMParams(i)%eam_dr
178  
179 <          EAMList%EAMParams(i)%eam_rhovals(1:EAMList%EAMParams(i)%eam_nrho) = &
175 <               real(EAMList%EAMParams(i)%eam_nrho,kind=dp)* &
176 <               EAMList%EAMParams(i)%eam_drho
179 > ! Build array of r values
180  
181 +          do j = 1,EAMList%EAMParams(i)%eam_nr
182 +             EAMList%EAMParams(i)%eam_rvals(j) = &
183 +                  real(j-1,kind=dp)* &
184 +                  EAMList%EAMParams(i)%eam_dr
185 +              end do
186 + ! Build array of rho values
187 +          do j = 1,EAMList%EAMParams(i)%eam_nrho
188 +             EAMList%EAMParams(i)%eam_rhovals(j) = &
189 +                  real(j-1,kind=dp)* &
190 +                  EAMList%EAMParams(i)%eam_drho
191 +          end do
192            ! convert from eV to kcal / mol:
193            EAMList%EAMParams(i)%eam_F_rho = EAMList%EAMParams(i)%eam_F_rho * 23.06054E0_DP
194  
195            ! precompute the pair potential and get it into kcal / mol:
196 <          EAMList%EAMParams(i)%eam_phi_r = 0.0E0_DP
196 >          EAMList%EAMParams(i)%eam_phi_r(1) = 0.0E0_DP
197            do j = 2, EAMList%EAMParams(i)%eam_nr
198               EAMList%EAMParams(i)%eam_phi_r(j) = (EAMList%EAMParams(i)%eam_Z_r(j)**2)/EAMList%EAMParams(i)%eam_rvals(j)
199               EAMList%EAMParams(i)%eam_phi_r(j) =  EAMList%EAMParams(i)%eam_phi_r(j)*331.999296E0_DP
200            enddo
201         end do
202 +      
203  
204         do i = 1,  EAMList%currentAddition
205            number_r   = EAMList%EAMParams(i)%eam_nr
# Line 207 | Line 222 | contains
222                 EAMList%EAMParams(i)%eam_phi_r_pp, &
223                 0.0E0_DP, 0.0E0_DP, 'N')
224         enddo
225 <      
226 <       current_rcut_max = EAMList%EAMParams(1)%eam_rcut
225 >
226 > !       current_rcut_max = EAMList%EAMParams(1)%eam_rcut
227         !! find the smallest rcut for any eam atype
228 <       do i = 2, EAMList%currentAddition
229 <          current_rcut_max = min(current_rcut_max,EAMList%EAMParams(i)%eam_rcut)
230 <       end do
228 > !       do i = 2, EAMList%currentAddition
229 > !          current_rcut_max =max(current_rcut_max,EAMList%EAMParams(i)%eam_rcut)
230 > !       end do
231  
232 <       EAM_rcut = current_rcut_max
233 <       EAM_rcut_orig = current_rcut_max
232 > !       EAM_rcut = current_rcut_max
233 > !       EAM_rcut_orig = current_rcut_max
234   !       do i = 1, EAMList%currentAddition
235   !          EAMList%EAMParam(i)s%eam_atype_map(eam_atype(i)) = i
236   !       end do
222
223
237         !! Allocate arrays for force calculation
238 <          call allocateEAM(alloc_stat)
239 <          if (alloc_stat /= 0 ) then
240 <             status = -1
241 <             return
242 <          endif
243 <
238 >      
239 >       call allocateEAM(alloc_stat)
240 >       if (alloc_stat /= 0 ) then
241 >          write(*,*) "allocateEAM failed"
242 >          status = -1
243 >          return
244 >       endif
245 >    
246    end subroutine init_EAM_FF
247  
248   !! routine checks to see if array is allocated, deallocates array if allocated
# Line 244 | Line 259 | contains
259  
260  
261      nlocal = getNlocal()
262 <
262 >    status = 0
263   #ifdef IS_MPI
264      nrow = getNrow(plan_row)
265      ncol = getNcol(plan_col)
# Line 279 | Line 294 | contains
294      
295   #ifdef IS_MPI
296  
297 +    if (allocated(rho_tmp)) deallocate(rho_tmp)
298 +    allocate(rho_tmp(nlocal),stat=alloc_stat)
299 +    if (alloc_stat /= 0) then
300 +       status = -1
301 +       return
302 +    end if
303 +
304 +
305      if (allocated(frho_row)) deallocate(frho_row)
306      allocate(frho_row(nrow),stat=alloc_stat)
307      if (alloc_stat /= 0) then
# Line 336 | Line 359 | contains
359  
360    end subroutine allocateEAM
361  
362 + !! C sets rcut to be the largest cutoff of any atype
363 + !! present in this simulation. Doesn't include all atypes
364 + !! sim knows about, just those in the simulation.
365    subroutine setCutoffEAM(rcut, status)
366      real(kind=dp) :: rcut
367      integer :: status
368 +    status = 0
369  
370 <    if (rcut < EAM_rcut) then
344 <       EAM_rcut = rcut
345 <    endif
370 >    EAM_rcut = rcut
371  
347
372    end subroutine setCutoffEAM
373  
374  
375  
376    subroutine clean_EAM()
377 <
378 < ! clean non-IS_MPI first
377 >  
378 >   ! clean non-IS_MPI first
379      frho = 0.0_dp
380      rho  = 0.0_dp
381      dfrhodrho = 0.0_dp
# Line 361 | Line 385 | contains
385      frho_col = 0.0_dp
386      rho_row  = 0.0_dp
387      rho_col  = 0.0_dp
388 +    rho_tmp  = 0.0_dp
389      dfrhodrho_row = 0.0_dp
390      dfrhodrho_col = 0.0_dp
391   #endif
# Line 371 | Line 396 | contains
396    subroutine allocate_EAMType(eam_n_rho,eam_n_r,thisEAMType,stat)
397      integer, intent(in)          :: eam_n_rho
398      integer, intent(in)          :: eam_n_r
399 <    type (EAMType), pointer      :: thisEAMType
399 >    type (EAMType)               :: thisEAMType
400      integer, optional   :: stat
401      integer             :: alloc_stat
402  
# Line 470 | Line 495 | contains
495      integer :: myid_atom2
496  
497   ! check to see if we need to be cleaned at the start of a force loop
498 <    if (cleanme) call clean_EAM
474 <    cleanme = .false.
475 <    
498 >      
499  
500 +
501 +
502   #ifdef IS_MPI
503      myid_atom1 = atid_Row(atom1)
504      myid_atom2 = atid_Col(atom2)
# Line 483 | Line 508 | contains
508   #endif
509  
510      if (r.lt.EAMList%EAMParams(myid_atom1)%eam_rcut) then
486
511  
512  
513 +
514         call eam_splint(EAMList%EAMParams(myid_atom1)%eam_nr, &
515              EAMList%EAMParams(myid_atom1)%eam_rvals, &
516              EAMList%EAMParams(myid_atom1)%eam_rho_r, &
# Line 499 | Line 524 | contains
524   #else
525         rho(atom2) = rho(atom2) + rho_i_at_j
526   #endif
527 + !       write(*,*) atom1,atom2,r,rho_i_at_j
528         endif
529  
530         if (r.lt.EAMList%EAMParams(myid_atom2)%eam_rcut) then
# Line 508 | Line 534 | contains
534                 EAMList%EAMParams(myid_atom2)%eam_rho_r_pp, &
535                 r, rho_j_at_i,drho,d2rho)
536  
537 <
537 >    
538        
539        
540   #ifdef  IS_MPI
# Line 518 | Line 544 | contains
544   #endif
545         endif
546  
547 +
548 +
549 +
550 +
551 +
552    end subroutine calc_eam_prepair_rho
553  
554  
# Line 533 | Line 564 | contains
564      integer :: atype1
565      integer :: me
566      integer :: n_rho_points
536    ! reset clean forces to be true at top of calc rho.
537    cleanme = .true.
567  
568 < !! Scatter the electron density from  pre-pair calculation back to local atoms
568 >  
569 >    cleanme = .true.
570 >    !! Scatter the electron density from  pre-pair calculation back to local atoms
571   #ifdef IS_MPI
572      call scatter(rho_row,rho,plan_row,eam_err)
573      if (eam_err /= 0 ) then
574        write(errMsg,*) " Error scattering rho_row into rho"
575        call handleError(RoutineName,errMesg)
576     endif      
577 <    call scatter(rho_col,rho,plan_col,eam_err)
577 >    call scatter(rho_col,rho_tmp,plan_col,eam_err)
578      if (eam_err /= 0 ) then
579        write(errMsg,*) " Error scattering rho_col into rho"
580        call handleError(RoutineName,errMesg)
581     endif
582 +
583 +      rho(1:nlocal) = rho(1:nlocal) + rho_tmp(1:nlocal)
584   #endif
585  
586  
587 +
588   !! Calculate F(rho) and derivative
589      do atom = 1, nlocal
590         me = atid(atom)
# Line 574 | Line 608 | contains
608         end if
609  
610  
611 <       frho(i) = u
612 <       dfrhodrho(i) = u1
613 <       d2frhodrhodrho(i) = u2
611 >       frho(atom) = u
612 >       dfrhodrho(atom) = u1
613 >       d2frhodrhodrho(atom) = u2
614         pot = pot + u
615 +
616      enddo
617  
618 +  
619  
584
620   #ifdef IS_MPI
621      !! communicate f(rho) and derivatives back into row and column arrays
622      call gather(frho,frho_row,plan_row, eam_err)
# Line 611 | Line 646 | contains
646      endif
647   #endif
648  
649 +  
650    end subroutine calc_eam_preforce_Frho
651  
652  
# Line 643 | Line 679 | contains
679      integer  :: mytype_atom1
680      integer  :: mytype_atom2
681  
646
682   !Local Variables
683      
684 +   ! write(*,*) "Frho: ", Frho(atom1)
685  
650    
686      phab = 0.0E0_DP
687      dvpdr = 0.0E0_DP
688      d2vpdrdr = 0.0E0_DP
689 <    
655 <    
689 >
690      if (rij .lt. EAM_rcut) then
691   #ifdef IS_MPI
692   !!!!! FIX ME
# Line 739 | Line 773 | contains
773   #ifdef IS_MPI
774         dudr = drhojdr*dfrhodrho_row(atom1)+drhoidr*dfrhodrho_col(atom2) &
775              + dvpdr
776 <    
776 >
777   #else
778         dudr = drhojdr*dfrhodrho(atom1)+drhoidr*dfrhodrho(atom2) &
779              + dvpdr
780 <
780 >      ! write(*,*) "Atom1,Atom2, dfrhodrho(atom1) dfrhodrho(atom2): ", atom1,atom2,dfrhodrho(atom1),dfrhodrho(atom2)
781   #endif
782  
783         fx = dudr * drdx
# Line 765 | Line 799 | contains
799         f_Col(2,atom2) = f_Col(2,atom2) - fy
800         f_Col(3,atom2) = f_Col(3,atom2) - fz
801   #else
802 <       if(do_pot) pot = pot + phab
803 <      
802 >
803 >       if(do_pot) then
804 >          pot = pot + phab
805 >       end if
806 >
807         f(1,atom1) = f(1,atom1) + fx
808         f(2,atom1) = f(2,atom1) + fy
809         f(3,atom1) = f(3,atom1) + fz
# Line 814 | Line 851 | contains
851   #endif
852            
853            if (molMembershipList(id1) .ne. molMembershipList(id2)) then
817            
854  
819
820
855               tau_Temp(1) = tau_Temp(1) - d(1) * fx
856               tau_Temp(2) = tau_Temp(2) - d(1) * fy
857               tau_Temp(3) = tau_Temp(3) - d(1) * fz

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines