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 631 by chuckv, Thu Jul 17 19:25:51 2003 UTC vs.
Revision 653 by chuckv, Fri Jul 25 20:00:17 2003 UTC

# Line 4 | Line 4 | module eam
4    use force_globals
5    use status
6    use atype_module
7 < #ifdef MPI
7 >  use Vector_class
8 > #ifdef IS_MPI
9    use mpiSimulation
10   #endif
11    implicit none
# Line 14 | 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
19  
20 +  character(len = statusMsgSize) :: errMesg
21 +  integer :: eam_err
22 +
23    character(len = 200) :: errMsg
24    character(len=*), parameter :: RoutineName =  "EAM MODULE"
25 + !! Logical that determines if eam arrays should be zeroed
26    logical :: cleanme = .true.
27 +  logical :: nmflag  = .false.
28  
22
29  
30    type, private :: EAMtype
31       integer           :: eam_atype      
# Line 49 | Line 55 | module eam
55    real( kind = dp), dimension(:), allocatable :: rho
56  
57    real( kind = dp), dimension(:), allocatable :: dfrhodrho
58 < !  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho
58 >  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho
59  
60  
61   !! Arrays for MPI storage
62 < #ifdef MPI
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 <
69 >  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho_col
70 >  real( kind = dp), dimension(:), allocatable :: d2frhodrhodrho_row
71   #endif
72  
73    type, private :: EAMTypeList
# Line 77 | Line 84 | module eam
84  
85  
86    public :: init_EAM_FF
87 < !  public :: EAM_new_rcut
88 < !  public :: do_EAM_pair
87 >  public :: setCutoffEAM
88 >  public :: do_eam_pair
89    public :: newEAMtype
90 <
90 >  public :: calc_eam_prepair_rho
91 >  public :: calc_eam_preforce_Frho
92    
93  
94   contains
# Line 106 | Line 114 | contains
114      integer                                :: alloc_stat
115      integer                                :: current
116      integer,pointer                        :: Matchlist(:) => null()
117 +    type (EAMtype), pointer                :: makeEamtype => null()
118      status = 0
119  
120      !! Assume that atypes has already been set and get the total number of types in atypes
# Line 123 | Line 132 | contains
132      current = EAMList%currentAddition
133      
134  
135 <    !call allocate_EAMType(eam_nrho,eam_nr,EAMList%EAMParams(current),stat=alloc_stat)
135 >    call allocate_EAMType(eam_nrho,eam_nr,makeEamtype,stat=alloc_stat)
136      if (alloc_stat /= 0) then
137         status = -1
138         return
139      end if
140 +    makeEamtype => EAMList%EAMParams(current)
141  
132
142      ! this is a possible bug, we assume a correspondence between the vector atypes and
143      ! EAMAtypes
144        
# Line 154 | Line 163 | contains
163      integer :: alloc_stat
164      integer :: number_r, number_rho
165  
166 +
167 +
168         do i = 1, EAMList%currentAddition
169    
170            EAMList%EAMParams(i)%eam_rvals(1:EAMList%EAMParams(i)%eam_nr) = &
# Line 198 | Line 209 | contains
209         enddo
210        
211         current_rcut_max = EAMList%EAMParams(1)%eam_rcut
212 <       !! find the smallest rcut
212 >       !! find the smallest rcut for any eam atype
213         do i = 2, EAMList%currentAddition
214            current_rcut_max = min(current_rcut_max,EAMList%EAMParams(i)%eam_rcut)
215         end do
216  
217         EAM_rcut = current_rcut_max
218 +       EAM_rcut_orig = current_rcut_max
219   !       do i = 1, EAMList%currentAddition
220   !          EAMList%EAMParam(i)s%eam_atype_map(eam_atype(i)) = i
221   !       end do
# Line 224 | Line 236 | contains
236      integer, intent(out) :: status
237  
238      integer :: nlocal
239 < #ifdef MPI
239 > #ifdef IS_MPI
240      integer :: nrow
241      integer :: ncol
242   #endif
# Line 233 | Line 245 | contains
245  
246      nlocal = getNlocal()
247  
248 < #ifdef MPI
248 > #ifdef IS_MPI
249      nrow = getNrow(plan_row)
250      ncol = getNcol(plan_col)
251   #endif
# Line 250 | Line 262 | contains
262         status = -1
263         return
264      end if
265 +
266      if (allocated(dfrhodrho)) deallocate(dfrhodrho)
267      allocate(dfrhodrho(nlocal),stat=alloc_stat)
268      if (alloc_stat /= 0) then
269         status = -1
270         return
271      end if
272 +
273 +    if (allocated(d2frhodrhodrho)) deallocate(d2frhodrhodrho)
274 +    allocate(d2frhodrhodrho(nlocal),stat=alloc_stat)
275 +    if (alloc_stat /= 0) then
276 +       status = -1
277 +       return
278 +    end if
279      
280 < #ifdef MPI
280 > #ifdef IS_MPI
281  
282      if (allocated(frho_row)) deallocate(frho_row)
283      allocate(frho_row(nrow),stat=alloc_stat)
# Line 277 | Line 297 | contains
297         status = -1
298         return
299      end if
300 +    if (allocated(d2frhodrhodrho_row)) deallocate(d2frhodrhodrho_row)
301 +    allocate(d2frhodrhodrho_row(nrow),stat=alloc_stat)
302 +    if (alloc_stat /= 0) then
303 +       status = -1
304 +       return
305 +    end if
306  
307 +
308   ! Now do column arrays
309  
310      if (allocated(frho_col)) deallocate(frho_col)
# Line 298 | Line 325 | contains
325         status = -1
326         return
327      end if
328 <
328 >    if (allocated(d2frhodrhodrho_col)) deallocate(d2frhodrhodrho_col)
329 >    allocate(d2frhodrhodrho_col(ncol),stat=alloc_stat)
330 >    if (alloc_stat /= 0) then
331 >       status = -1
332 >       return
333 >    end if
334 >  
335   #endif
336  
337    end subroutine allocateEAM
338 +
339 +  subroutine setCutoffEAM(rcut, status)
340 +    real(kind=dp) :: rcut
341 +    integer :: status
342  
343 +    if (rcut < EAM_rcut) then
344 +       EAM_rcut = rcut
345 +    endif
346  
347 +
348 +  end subroutine setCutoffEAM
349 +
350 +
351 +
352    subroutine clean_EAM()
353  
354 < ! clean non-MPI first
354 > ! clean non-IS_MPI first
355      frho = 0.0_dp
356      rho  = 0.0_dp
357      dfrhodrho = 0.0_dp
358   ! clean MPI if needed
359 < #ifdef MPI
359 > #ifdef IS_MPI
360      frho_row = 0.0_dp
361      frho_col = 0.0_dp
362      rho_row  = 0.0_dp
# Line 421 | Line 466 | contains
466      real( kind = dp) :: drho,d2rho
467      integer :: eam_err
468    
469 +    integer :: myid_atom1
470 +    integer :: myid_atom2
471 +
472 + ! check to see if we need to be cleaned at the start of a force loop
473      if (cleanme) call clean_EAM
474      cleanme = .false.
475 +    
476  
477 <    call  calc_eam_rho(r,rho_i_at_j,drho,d2rho,atom1)
478 <
479 < #ifdef  MPI
430 <    rho_col(atom2) = rho_col(atom2) + rho_i_at_j
477 > #ifdef IS_MPI
478 >    myid_atom1 = atid_Row(atom1)
479 >    myid_atom2 = atid_Col(atom2)
480   #else
481 <    rho(atom2) = rho(atom2) + rho_i_at_j
481 >    myid_atom1 = atid(atom1)
482 >    myid_atom2 = atid(atom2)
483   #endif
484  
485 <    call calc_eam_rho(r,rho_j_at_i,drho,d2rho,atom2)
485 >    if (r.lt.EAMList%EAMParams(myid_atom1)%eam_rcut) then
486 >
487  
488 < #ifdef  MPI
489 <    rho_row(atom1) = rho_row(atom1) + rho_j_at_i
488 >
489 >       call eam_splint(EAMList%EAMParams(myid_atom1)%eam_nr, &
490 >            EAMList%EAMParams(myid_atom1)%eam_rvals, &
491 >            EAMList%EAMParams(myid_atom1)%eam_rho_r, &
492 >            EAMList%EAMParams(myid_atom1)%eam_rho_r_pp, &
493 >            r, rho_i_at_j,drho,d2rho)
494 >
495 >
496 >      
497 > #ifdef  IS_MPI
498 >       rho_col(atom2) = rho_col(atom2) + rho_i_at_j
499   #else
500 <    rho(atom1) = rho(atom1) + rho_j_at_i
500 >       rho(atom2) = rho(atom2) + rho_i_at_j
501   #endif
502 +       endif
503 +
504 +       if (r.lt.EAMList%EAMParams(myid_atom2)%eam_rcut) then
505 +          call eam_splint(EAMList%EAMParams(myid_atom2)%eam_nr, &
506 +               EAMList%EAMParams(myid_atom2)%eam_rvals, &
507 +               EAMList%EAMParams(myid_atom2)%eam_rho_r, &
508 +               EAMList%EAMParams(myid_atom2)%eam_rho_r_pp, &
509 +               r, rho_j_at_i,drho,d2rho)
510 +
511 +
512 +      
513 +      
514 + #ifdef  IS_MPI
515 +          rho_row(atom1) = rho_row(atom1) + rho_j_at_i
516 + #else
517 +          rho(atom1) = rho(atom1) + rho_j_at_i
518 + #endif
519 +       endif
520 +
521    end subroutine calc_eam_prepair_rho
522  
523 <  !! Calculate the functional F(rho) for all atoms
524 <  subroutine calc_eam_prepair_Frho(nlocal,pot)
523 >
524 >
525 >
526 >  !! Calculate the functional F(rho) for all local atoms
527 >  subroutine calc_eam_preforce_Frho(nlocal,pot)
528      integer :: nlocal
529      real(kind=dp) :: pot
530      integer :: i,j
531 +    integer :: atom
532      real(kind=dp) :: U,U1,U2
533      integer :: atype1
534 +    integer :: me
535 +    integer :: n_rho_points
536      ! reset clean forces to be true at top of calc rho.
537      cleanme = .true.
538  
539 < !! Scatter the electron density in pre-pair
540 < #ifdef MPI
539 > !! Scatter the electron density from  pre-pair calculation back to local atoms
540 > #ifdef IS_MPI
541      call scatter(rho_row,rho,plan_row,eam_err)
542      if (eam_err /= 0 ) then
543        write(errMsg,*) " Error scattering rho_row into rho"
# Line 465 | Line 550 | contains
550     endif
551   #endif
552  
468   do i = 1, nlocal
469      call calc_eam_frho(rho(i),u,u1,u2,atype1)
470      frho(i) = u
471      dfrhodrho(i) = u1
472 !      d2frhodrhodrho(i) = u2
473      pot = pot + u
474   enddo
553  
554 < #ifdef MPI
555 <    !! communicate f(rho) and derivatives
554 > !! Calculate F(rho) and derivative
555 >    do atom = 1, nlocal
556 >       me = atid(atom)
557 >       n_rho_points = EAMList%EAMParams(me)%eam_nrho
558 >       !  Check to see that the density is not greater than the larges rho we have calculated
559 >       if (rho(atom) < EAMList%EAMParams(me)%eam_rhovals(n_rho_points)) then
560 >          call eam_splint(n_rho_points, &
561 >               EAMList%EAMParams(me)%eam_rhovals, &
562 >               EAMList%EAMParams(me)%eam_f_rho, &
563 >               EAMList%EAMParams(me)%eam_f_rho_pp, &
564 >               rho(atom), & ! Actual Rho
565 >               u, u1, u2)
566 >       else
567 >          ! Calculate F(rho with the largest available rho value
568 >          call eam_splint(n_rho_points, &
569 >               EAMList%EAMParams(me)%eam_rhovals, &
570 >               EAMList%EAMParams(me)%eam_f_rho, &
571 >               EAMList%EAMParams(me)%eam_f_rho_pp, &
572 >               EAMList%EAMParams(me)%eam_rhovals(n_rho_points), & ! Largest rho
573 >               u,u1,u2)
574 >       end if
575 >
576 >
577 >       frho(i) = u
578 >       dfrhodrho(i) = u1
579 >       d2frhodrhodrho(i) = u2
580 >       pot = pot + u
581 >    enddo
582 >
583 >
584 >
585 > #ifdef IS_MPI
586 >    !! communicate f(rho) and derivatives back into row and column arrays
587      call gather(frho,frho_row,plan_row, eam_err)
588      if (eam_err /=  0) then
589         call handleError("cal_eam_forces()","MPI gather frho_row failure")
# Line 492 | Line 601 | contains
601         call handleError("cal_eam_forces()","MPI gather dfrhodrho_col failure")
602      endif
603  
604 +
605 +
606 +
607 +
608      if (nmflag) then
609         call gather(d2frhodrhodrho,d2frhodrhodrho_row,plan_row)
610         call gather(d2frhodrhodrho,d2frhodrhodrho_col,plan_col)
611      endif
612   #endif
613  
614 +  end subroutine calc_eam_preforce_Frho
615  
502  end subroutine calc_eam_prepair_Frho
616  
617  
618  
619 <
620 <  subroutine calc_eam_pair(atom1,atom2,d,rij,r2,pot,f,do_pot,do_stress)
621 < !Arguments    
619 >  !! Does EAM pairwise Force calculation.  
620 >  subroutine do_eam_pair(atom1,atom2,d,rij,r2,pot,f,do_pot,do_stress)
621 >    !Arguments    
622      integer, intent(in) ::  atom1, atom2
623      real( kind = dp ), intent(in) :: rij, r2
624      real( kind = dp ) :: pot
625      real( kind = dp ), dimension(3,getNlocal()) :: f
626      real( kind = dp ), intent(in), dimension(3) :: d
627      logical, intent(in) :: do_pot, do_stress
628 <
628 >    
629      real( kind = dp ) :: drdx,drdy,drdz
630 +    real( kind = dp ) :: d2
631      real( kind = dp ) :: phab,pha,dvpdr,d2vpdrdr
632      real( kind = dp ) :: rha,drha,d2rha, dpha
633      real( kind = dp ) :: rhb,drhb,d2rhb, dphb
# Line 524 | Line 638 | contains
638      real( kind = dp ) :: d2rhojdrdr
639      real( kind = dp ) :: Fx,Fy,Fz
640      real( kind = dp ) :: r,d2pha,phb,d2phb
641 +
642      integer :: id1,id2
643 <    integer  :: atype1,atype2
643 >    integer  :: mytype_atom1
644 >    integer  :: mytype_atom2
645  
646  
647   !Local Variables
# Line 535 | Line 651 | contains
651      phab = 0.0E0_DP
652      dvpdr = 0.0E0_DP
653      d2vpdrdr = 0.0E0_DP
654 <      
655 <
654 >    
655 >    
656      if (rij .lt. EAM_rcut) then
657   #ifdef IS_MPI
658   !!!!! FIX ME
659 <       atype1 = atid_row(atom1)
659 >       mytype_atom1 = atid_row(atom1)
660   #else
661 <       atype1 = atid(atom1)
661 >       mytype_atom1 = atid(atom1)
662   #endif
663 <
663 >      
664         drdx = d(1)/rij
665         drdy = d(2)/rij
666         drdz = d(3)/rij
667        
552      
553       call calc_eam_rho(r, rha, drha, d2rha, atype1)
554       call calc_eam_phi(r, pha, dpha, d2pha, atype1)
555  !     rci = eam_rcut(eam_atype_map(atom1))
556 #ifdef IS_MPI
557       atype2 = atid_col(atom2)
558 #else
559       atype2 = atid(atom2)
560 #endif
561      
562       call calc_eam_rho(r, rhb, drhb, d2rhb, atype2)
563       call calc_eam_phi(r, phb, dphb, d2phb, atype2)
564  !     rcj = eam_rcut(eam_atype_map(atype2))
668  
669 <       if (r.lt.rci) then
669 >       call eam_splint(EAMList%EAMParams(mytype_atom1)%eam_nr, &
670 >               EAMList%EAMParams(mytype_atom1)%eam_rvals, &
671 >               EAMList%EAMParams(mytype_atom1)%eam_rho_r, &
672 >               EAMList%EAMParams(mytype_atom1)%eam_rho_r_pp, &
673 >               rij, rha,drha,d2rha)
674 >
675 >       !! Calculate Phi(r) for atom1.
676 >       call eam_splint(EAMList%EAMParams(mytype_atom1)%eam_nr, &
677 >               EAMList%EAMParams(mytype_atom1)%eam_rvals, &
678 >               EAMList%EAMParams(mytype_atom1)%eam_phi_r, &
679 >               EAMList%EAMParams(mytype_atom1)%eam_phi_r_pp, &
680 >               rij, pha,dpha,d2pha)
681 >
682 >
683 > ! get cutoff for atom 1
684 >       rci = EAMList%EAMParams(mytype_atom1)%eam_rcut
685 > #ifdef IS_MPI
686 >       mytype_atom2 = atid_col(atom2)
687 > #else
688 >       mytype_atom2 = atid(atom2)
689 > #endif
690 >
691 >       ! Calculate rho,drho and d2rho for atom1
692 >       call eam_splint(EAMList%EAMParams(mytype_atom2)%eam_nr, &
693 >               EAMList%EAMParams(mytype_atom2)%eam_rvals, &
694 >               EAMList%EAMParams(mytype_atom2)%eam_rho_r, &
695 >               EAMList%EAMParams(mytype_atom2)%eam_rho_r_pp, &
696 >               rij, rhb,drhb,d2rhb)
697 >
698 >       !! Calculate Phi(r) for atom2.
699 >       call eam_splint(EAMList%EAMParams(mytype_atom2)%eam_nr, &
700 >               EAMList%EAMParams(mytype_atom2)%eam_rvals, &
701 >               EAMList%EAMParams(mytype_atom2)%eam_phi_r, &
702 >               EAMList%EAMParams(mytype_atom2)%eam_phi_r_pp, &
703 >               rij, phb,dphb,d2phb)
704 >
705 >
706 > ! get type specific cutoff for atom 2
707 >       rcj = EAMList%EAMParams(mytype_atom1)%eam_rcut
708 >
709 >
710 >
711 >       if (rij.lt.rci) then
712            phab = phab + 0.5E0_DP*(rhb/rha)*pha
713            dvpdr = dvpdr + 0.5E0_DP*((rhb/rha)*dpha + &
714                 pha*((drhb/rha) - (rhb*drha/rha/rha)))
# Line 574 | Line 719 | contains
719         endif
720        
721  
722 <       if (r.lt.rcj) then
722 >       if (rij.lt.rcj) then
723            phab = phab + 0.5E0_DP*(rha/rhb)*phb
724            dvpdr = dvpdr + 0.5E0_DP*((rha/rhb)*dphb + &
725                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)))
# Line 591 | Line 736 | contains
736         d2rhojdrdr = d2rhb
737  
738  
739 < #ifdef MPI
739 > #ifdef IS_MPI
740         dudr = drhojdr*dfrhodrho_row(atom1)+drhoidr*dfrhodrho_col(atom2) &
741              + dvpdr
742      
# Line 606 | Line 751 | contains
751         fz = dudr * drdz
752  
753  
754 < #ifdef MPI
754 > #ifdef IS_MPI
755         if (do_pot) then
756            pot_Row(atom1) = pot_Row(atom1) + phab*0.5
757            pot_Col(atom2) = pot_Col(atom2) + phab*0.5
# Line 615 | Line 760 | contains
760         f_Row(1,atom1) = f_Row(1,atom1) + fx
761         f_Row(2,atom1) = f_Row(2,atom1) + fy
762         f_Row(3,atom1) = f_Row(3,atom1) + fz
763 <
763 >      
764         f_Col(1,atom2) = f_Col(1,atom2) - fx
765         f_Col(2,atom2) = f_Col(2,atom2) - fy
766         f_Col(3,atom2) = f_Col(3,atom2) - fz
767   #else
768         if(do_pot) pot = pot + phab
769 <
769 >      
770         f(1,atom1) = f(1,atom1) + fx
771         f(2,atom1) = f(2,atom1) + fy
772         f(3,atom1) = f(3,atom1) + fz
773 <
773 >      
774         f(1,atom2) = f(1,atom2) - fx
775         f(2,atom2) = f(2,atom2) - fy
776         f(3,atom2) = f(3,atom2) - fz
777   #endif
778 +      
779 +       if (nmflag) then
780  
781 +          drhoidr = drha
782 +          drhojdr = drhb
783 +          d2rhoidrdr = d2rha
784 +          d2rhojdrdr = d2rhb
785  
786 + #ifdef IS_MPI
787 +          d2 = d2vpdrdr + &
788 +               d2rhoidrdr*dfrhodrho_col(atom2) + &
789 +               d2rhojdrdr*dfrhodrho_row(atom1) + &
790 +               drhoidr*drhoidr*d2frhodrhodrho_col(atom2) + &
791 +               drhojdr*drhojdr*d2frhodrhodrho_row(atom1)
792 +              
793 + #else
794  
795 +          d2 = d2vpdrdr + &
796 +               d2rhoidrdr*dfrhodrho(atom2) + &
797 +               d2rhojdrdr*dfrhodrho(atom1) + &
798 +               drhoidr*drhoidr*d2frhodrhodrho(atom2) + &
799 +               drhojdr*drhojdr*d2frhodrhodrho(atom1)
800 + #endif
801 +       end if
802  
637       if (do_stress) then
803  
804 < #ifdef MPI
804 >      
805 >      
806 >       if (do_stress) then
807 >          
808 > #ifdef IS_MPI
809            id1 = tagRow(atom1)
810            id2 = tagColumn(atom2)
811   #else
812            id1 = atom1
813            id2 = atom2
814   #endif
815 <
815 >          
816            if (molMembershipList(id1) .ne. molMembershipList(id2)) then
817              
818 <             tau_Temp(1) = tau_Temp(1) + fx * d(1)
819 <             tau_Temp(2) = tau_Temp(2) + fx * d(2)
820 <             tau_Temp(3) = tau_Temp(3) + fx * d(3)
821 <             tau_Temp(4) = tau_Temp(4) + fy * d(1)
822 <             tau_Temp(5) = tau_Temp(5) + fy * d(2)
823 <             tau_Temp(6) = tau_Temp(6) + fy * d(3)
824 <             tau_Temp(7) = tau_Temp(7) + fz * d(1)
825 <             tau_Temp(8) = tau_Temp(8) + fz * d(2)
826 <             tau_Temp(9) = tau_Temp(9) + fz * d(3)
818 >
819 >
820 >
821 >             tau_Temp(1) = tau_Temp(1) - d(1) * fx
822 >             tau_Temp(2) = tau_Temp(2) - d(1) * fy
823 >             tau_Temp(3) = tau_Temp(3) - d(1) * fz
824 >             tau_Temp(4) = tau_Temp(4) - d(2) * fx
825 >             tau_Temp(5) = tau_Temp(5) - d(2) * fy
826 >             tau_Temp(6) = tau_Temp(6) - d(2) * fz
827 >             tau_Temp(7) = tau_Temp(7) - d(3) * fx
828 >             tau_Temp(8) = tau_Temp(8) - d(3) * fy
829 >             tau_Temp(9) = tau_Temp(9) - d(3) * fz
830 >
831               virial_Temp = virial_Temp + &
832                    (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
833  
834            endif
835 <       endif
663 <      
835 >       endif  
836      endif
837  
838 <
839 < end subroutine calc_eam_pair
668 <
669 < !!$subroutine calc_eam_rho(r, rho, drho, d2rho, atype)
670 < !!$
671 < !!$  !  include 'headers/sizes.h'
672 < !!$
673 < !!$
674 < !!$integer atype, etype, number_r
675 < !!$real( kind = DP )  :: r, rho, drho, d2rho
676 < !!$integer :: i
677 < !!$
678 < !!$
679 < !!$etype = eam_atype_map(atype)
680 < !!$
681 < !!$if (r.lt.eam_rcut(etype)) then
682 < !!$number_r = eam_nr(etype)
683 < !!$call eam_splint(etype, number_r, eam_rvals, eam_rho_r, &
684 < !!$   eam_rho_r_pp, r, rho, drho, d2rho)
685 < !!$else
686 < !!$rho = 0.0E0_DP
687 < !!$drho = 0.0E0_DP
688 < !!$d2rho = 0.0E0_DP
689 < !!$endif
690 < !!$
691 < !!$return
692 < !!$end subroutine calc_eam_rho
693 < !!$
694 < !!$subroutine calc_eam_frho(dens, u, u1, u2, atype)
695 < !!$
696 < !!$  ! include 'headers/sizes.h'
697 < !!$
698 < !!$integer atype, etype, number_rho
699 < !!$real( kind = DP ) :: dens, u, u1, u2
700 < !!$real( kind = DP ) :: rho_vals
701 < !!$
702 < !!$etype = eam_atype_map(atype)
703 < !!$number_rho = eam_nrho(etype)
704 < !!$if (dens.lt.eam_rhovals(number_rho, etype)) then
705 < !!$call eam_splint(etype, number_rho, eam_rhovals, eam_f_rho, &
706 < !!$   eam_f_rho_pp, dens, u, u1, u2)
707 < !!$else
708 < !!$rho_vals = eam_rhovals(number_rho,etype)
709 < !!$call eam_splint(etype, number_rho, eam_rhovals, eam_f_rho, &
710 < !!$   eam_f_rho_pp, rho_vals, u, u1, u2)
711 < !!$endif
712 < !!$
713 < !!$return
714 < !!$end subroutine calc_eam_frho
715 < !!$
716 < !!$subroutine calc_eam_phi(r, phi, dphi, d2phi, atype)
717 < !!$
718 < !!$
719 < !!$
720 < !!$
721 < !!$integer atype, etype, number_r
722 < !!$real( kind = DP ) :: r, phi, dphi, d2phi
723 < !!$
724 < !!$etype = eam_atype_map(atype)
725 < !!$
726 < !!$if (r.lt.eam_rcut(etype)) then
727 < !!$number_r = eam_nr(etype)
728 < !!$call eam_splint(etype, number_r, eam_rvals, eam_phi_r, &
729 < !!$   eam_phi_r_pp, r, phi, dphi, d2phi)
730 < !!$else
731 < !!$phi = 0.0E0_DP
732 < !!$dphi = 0.0E0_DP
733 < !!$d2phi = 0.0E0_DP
734 < !!$endif
735 < !!$
736 < !!$return
737 < !!$end subroutine calc_eam_phi
838 >    
839 >  end subroutine do_eam_pair
840  
841  
842    subroutine eam_splint(nx, xa, ya, yppa, x, y, dy, d2y)
843  
742
844      integer :: atype, nx, j
845      real( kind = DP ), dimension(:) :: xa
846      real( kind = DP ), dimension(:) :: ya
847      real( kind = DP ), dimension(:) :: yppa
848 <    real( kind = DP ) :: x, y, dy, d2y
848 >    real( kind = DP ) :: x, y
849 >    real( kind = DP ) :: dy, d2y
850      real( kind = DP ) :: del, h, a, b, c, d
851 +    integer :: pp_arraySize
852  
853 <
751 <
752 <
753 <    
853 >
854      ! this spline code assumes that the x points are equally spaced
855      ! do not attempt to use this code if they are not.
856      
857      
858      ! find the closest point with a value below our own:
859 <    j = FLOOR(dble(nx-1) * (x - xa(1)) / (xa(nx) - xa(1))) + 1
859 >    j = FLOOR(real((nx-1),kind=dp) * (x - xa(1)) / (xa(nx) - xa(1))) + 1
860  
861      ! check to make sure we're inside the spline range:
862      if ((j.gt.nx).or.(j.lt.1)) then
863 <       write(default_error,*) "EAM_splint: x is outside bounds of spline"
863 >       write(errMSG,*) "EAM_splint: x is outside bounds of spline"
864 >       call handleError(routineName,errMSG)
865      endif
866      ! check to make sure we haven't screwed up the calculation of j:
867      if ((x.lt.xa(j)).or.(x.gt.xa(j+1))) then
868         if (j.ne.nx) then
869 <        write(default_error,*) "EAM_splint: x is outside bounding range"
869 >        write(errMSG,*) "EAM_splint:",x," x is outside bounding range"
870 >       call handleError(routineName,errMSG)
871         endif
872      endif
873  
# Line 778 | Line 880 | end subroutine calc_eam_pair
880      d = b*(b*b - 1.0E0_DP)*h*h/6.0E0_DP
881      
882      y = a*ya(j) + b*ya(j+1) + c*yppa(j) + d*yppa(j+1)
883 <    
884 <    dy = (ya(j+1)-ya(j))/h &
885 <         - (3.0E0_DP*a*a - 1.0E0_DP)*h*yppa(j)/6.0E0_DP &
886 <         + (3.0E0_DP*b*b - 1.0E0_DP)*h*yppa(j+1)/6.0E0_DP
887 <    
888 <    d2y = a*yppa(j) + b*yppa(j+1)
883 >  
884 >       dy = (ya(j+1)-ya(j))/h &
885 >            - (3.0E0_DP*a*a - 1.0E0_DP)*h*yppa(j)/6.0E0_DP &
886 >            + (3.0E0_DP*b*b - 1.0E0_DP)*h*yppa(j+1)/6.0E0_DP
887 >  
888 >  
889 >       d2y = a*yppa(j) + b*yppa(j+1)
890 >  
891  
892    end subroutine eam_splint
893  
894 +
895    subroutine eam_spline(nx, xa, ya, yppa, yp1, ypn, boundary)
896  
792  
897  
794
898      ! yp1 and ypn are the first derivatives of y at the two endpoints
899      ! if boundary is 'L' the lower derivative is used
900      ! if boundary is 'U' the upper derivative is used
# Line 805 | Line 908 | end subroutine calc_eam_pair
908      real( kind = DP ), dimension(:)        :: yppa
909      real( kind = DP ), dimension(size(xa)) :: u
910      real( kind = DP ) :: yp1,ypn,un,qn,sig,p
911 <    character boundary
911 >    character(len=*) :: boundary
912      
913 <    
913 >    ! make sure the sizes match
914 >    if ((nx /= size(xa)) .or. (nx /= size(ya))) then
915 >       call handleWarning("EAM_SPLINE","Array size mismatch")
916 >    end if
917 >
918      if ((boundary.eq.'l').or.(boundary.eq.'L').or. &
919           (boundary.eq.'b').or.(boundary.eq.'B')) then
920         yppa(1) = -0.5E0_DP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines