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 650 by chuckv, Thu Jul 24 19:57:35 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 78 | Line 85 | module eam
85  
86    public :: init_EAM_FF
87   !  public :: EAM_new_rcut
88 < !  public :: do_EAM_pair
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
# Line 306 | Line 339 | contains
339  
340    subroutine clean_EAM()
341  
342 < ! clean non-MPI first
342 > ! clean non-IS_MPI first
343      frho = 0.0_dp
344      rho  = 0.0_dp
345      dfrhodrho = 0.0_dp
346   ! clean MPI if needed
347 < #ifdef MPI
347 > #ifdef IS_MPI
348      frho_row = 0.0_dp
349      frho_col = 0.0_dp
350      rho_row  = 0.0_dp
# Line 421 | Line 454 | contains
454      real( kind = dp) :: drho,d2rho
455      integer :: eam_err
456    
457 +    integer :: myid_atom1
458 +    integer :: myid_atom2
459 +
460 + ! check to see if we need to be cleaned at the start of a force loop
461      if (cleanme) call clean_EAM
462      cleanme = .false.
463 +    
464  
465 <    call  calc_eam_rho(r,rho_i_at_j,drho,d2rho,atom1)
465 > #ifdef IS_MPI
466 >    myid_atom1 = atid_Row(atom1)
467 >    myid_atom2 = atid_Col(atom2)
468 > #else
469 >    myid_atom1 = atid(atom1)
470 >    myid_atom2 = atid(atom2)
471 > #endif
472  
473 < #ifdef  MPI
474 <    rho_col(atom2) = rho_col(atom2) + rho_i_at_j
473 >    if (r.lt.EAMList%EAMParams(myid_atom1)%eam_rcut) then
474 >
475 >
476 >
477 >       call eam_splint(EAMList%EAMParams(myid_atom1)%eam_nr, &
478 >            EAMList%EAMParams(myid_atom1)%eam_rvals, &
479 >            EAMList%EAMParams(myid_atom1)%eam_rho_r, &
480 >            EAMList%EAMParams(myid_atom1)%eam_rho_r_pp, &
481 >            r, rho_i_at_j,drho,d2rho)
482 >
483 >
484 >      
485 > #ifdef  IS_MPI
486 >       rho_col(atom2) = rho_col(atom2) + rho_i_at_j
487   #else
488 <    rho(atom2) = rho(atom2) + rho_i_at_j
488 >       rho(atom2) = rho(atom2) + rho_i_at_j
489   #endif
490 +       endif
491  
492 <    call calc_eam_rho(r,rho_j_at_i,drho,d2rho,atom2)
492 >       if (r.lt.EAMList%EAMParams(myid_atom2)%eam_rcut) then
493 >          call eam_splint(EAMList%EAMParams(myid_atom2)%eam_nr, &
494 >               EAMList%EAMParams(myid_atom2)%eam_rvals, &
495 >               EAMList%EAMParams(myid_atom2)%eam_rho_r, &
496 >               EAMList%EAMParams(myid_atom2)%eam_rho_r_pp, &
497 >               r, rho_j_at_i,drho,d2rho)
498  
499 < #ifdef  MPI
500 <    rho_row(atom1) = rho_row(atom1) + rho_j_at_i
499 >
500 >      
501 >      
502 > #ifdef  IS_MPI
503 >          rho_row(atom1) = rho_row(atom1) + rho_j_at_i
504   #else
505 <    rho(atom1) = rho(atom1) + rho_j_at_i
505 >          rho(atom1) = rho(atom1) + rho_j_at_i
506   #endif
507 +       endif
508 +
509    end subroutine calc_eam_prepair_rho
510  
511 <  !! Calculate the functional F(rho) for all atoms
512 <  subroutine calc_eam_prepair_Frho(nlocal,pot)
511 >
512 >
513 >
514 >  !! Calculate the functional F(rho) for all local atoms
515 >  subroutine calc_eam_preforce_Frho(nlocal,pot)
516      integer :: nlocal
517      real(kind=dp) :: pot
518      integer :: i,j
519 +    integer :: atom
520      real(kind=dp) :: U,U1,U2
521      integer :: atype1
522 +    integer :: me
523 +    integer :: n_rho_points
524      ! reset clean forces to be true at top of calc rho.
525      cleanme = .true.
526  
527 < !! Scatter the electron density in pre-pair
528 < #ifdef MPI
527 > !! Scatter the electron density from  pre-pair calculation back to local atoms
528 > #ifdef IS_MPI
529      call scatter(rho_row,rho,plan_row,eam_err)
530      if (eam_err /= 0 ) then
531        write(errMsg,*) " Error scattering rho_row into rho"
# Line 465 | Line 538 | contains
538     endif
539   #endif
540  
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
541  
542 < #ifdef MPI
543 <    !! communicate f(rho) and derivatives
542 > !! Calculate F(rho) and derivative
543 >    do atom = 1, nlocal
544 >       me = atid(atom)
545 >       n_rho_points = EAMList%EAMParams(me)%eam_nrho
546 >       !  Check to see that the density is not greater than the larges rho we have calculated
547 >       if (rho(atom) < EAMList%EAMParams(me)%eam_rhovals(n_rho_points)) then
548 >          call eam_splint(n_rho_points, &
549 >               EAMList%EAMParams(me)%eam_rhovals, &
550 >               EAMList%EAMParams(me)%eam_f_rho, &
551 >               EAMList%EAMParams(me)%eam_f_rho_pp, &
552 >               rho(atom), & ! Actual Rho
553 >               u, u1, u2)
554 >       else
555 >          ! Calculate F(rho with the largest available rho value
556 >          call eam_splint(n_rho_points, &
557 >               EAMList%EAMParams(me)%eam_rhovals, &
558 >               EAMList%EAMParams(me)%eam_f_rho, &
559 >               EAMList%EAMParams(me)%eam_f_rho_pp, &
560 >               EAMList%EAMParams(me)%eam_rhovals(n_rho_points), & ! Largest rho
561 >               u,u1,u2)
562 >       end if
563 >
564 >
565 >       frho(i) = u
566 >       dfrhodrho(i) = u1
567 >       d2frhodrhodrho(i) = u2
568 >       pot = pot + u
569 >    enddo
570 >
571 >
572 >
573 > #ifdef IS_MPI
574 >    !! communicate f(rho) and derivatives back into row and column arrays
575      call gather(frho,frho_row,plan_row, eam_err)
576      if (eam_err /=  0) then
577         call handleError("cal_eam_forces()","MPI gather frho_row failure")
# Line 492 | Line 589 | contains
589         call handleError("cal_eam_forces()","MPI gather dfrhodrho_col failure")
590      endif
591  
592 +
593 +
594 +
595 +
596      if (nmflag) then
597         call gather(d2frhodrhodrho,d2frhodrhodrho_row,plan_row)
598         call gather(d2frhodrhodrho,d2frhodrhodrho_col,plan_col)
599      endif
600   #endif
601  
602 +  end subroutine calc_eam_preforce_Frho
603  
502  end subroutine calc_eam_prepair_Frho
604  
605  
606  
607 <
608 <  subroutine calc_eam_pair(atom1,atom2,d,rij,r2,pot,f,do_pot,do_stress)
609 < !Arguments    
607 >  !! Does EAM pairwise Force calculation.  
608 >  subroutine do_eam_pair(atom1,atom2,d,rij,r2,pot,f,do_pot,do_stress)
609 >    !Arguments    
610      integer, intent(in) ::  atom1, atom2
611      real( kind = dp ), intent(in) :: rij, r2
612      real( kind = dp ) :: pot
613      real( kind = dp ), dimension(3,getNlocal()) :: f
614      real( kind = dp ), intent(in), dimension(3) :: d
615      logical, intent(in) :: do_pot, do_stress
616 <
616 >    
617      real( kind = dp ) :: drdx,drdy,drdz
618 +    real( kind = dp ) :: d2
619      real( kind = dp ) :: phab,pha,dvpdr,d2vpdrdr
620      real( kind = dp ) :: rha,drha,d2rha, dpha
621      real( kind = dp ) :: rhb,drhb,d2rhb, dphb
# Line 524 | Line 626 | contains
626      real( kind = dp ) :: d2rhojdrdr
627      real( kind = dp ) :: Fx,Fy,Fz
628      real( kind = dp ) :: r,d2pha,phb,d2phb
629 +
630      integer :: id1,id2
631 <    integer  :: atype1,atype2
631 >    integer  :: mytype_atom1
632 >    integer  :: mytype_atom2
633  
634  
635   !Local Variables
# Line 535 | Line 639 | contains
639      phab = 0.0E0_DP
640      dvpdr = 0.0E0_DP
641      d2vpdrdr = 0.0E0_DP
642 <      
643 <
642 >    
643 >    
644      if (rij .lt. EAM_rcut) then
645   #ifdef IS_MPI
646   !!!!! FIX ME
647 <       atype1 = atid_row(atom1)
647 >       mytype_atom1 = atid_row(atom1)
648   #else
649 <       atype1 = atid(atom1)
649 >       mytype_atom1 = atid(atom1)
650   #endif
651 <
651 >      
652         drdx = d(1)/rij
653         drdy = d(2)/rij
654         drdz = d(3)/rij
655        
656 <      
657 <       call calc_eam_rho(r, rha, drha, d2rha, atype1)
658 <       call calc_eam_phi(r, pha, dpha, d2pha, atype1)
659 <  !     rci = eam_rcut(eam_atype_map(atom1))
656 >
657 >       call eam_splint(EAMList%EAMParams(mytype_atom1)%eam_nr, &
658 >               EAMList%EAMParams(mytype_atom1)%eam_rvals, &
659 >               EAMList%EAMParams(mytype_atom1)%eam_rho_r, &
660 >               EAMList%EAMParams(mytype_atom1)%eam_rho_r_pp, &
661 >               rij, rha,drha,d2rha)
662 >
663 >       !! Calculate Phi(r) for atom1.
664 >       call eam_splint(EAMList%EAMParams(mytype_atom1)%eam_nr, &
665 >               EAMList%EAMParams(mytype_atom1)%eam_rvals, &
666 >               EAMList%EAMParams(mytype_atom1)%eam_phi_r, &
667 >               EAMList%EAMParams(mytype_atom1)%eam_phi_r_pp, &
668 >               rij, pha,dpha,d2pha)
669 >
670 >
671 > ! get cutoff for atom 1
672 >       rci = EAMList%EAMParams(mytype_atom1)%eam_rcut
673   #ifdef IS_MPI
674 <       atype2 = atid_col(atom2)
674 >       mytype_atom2 = atid_col(atom2)
675   #else
676 <       atype2 = atid(atom2)
676 >       mytype_atom2 = atid(atom2)
677   #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))
678  
679 <       if (r.lt.rci) then
679 >       ! Calculate rho,drho and d2rho for atom1
680 >       call eam_splint(EAMList%EAMParams(mytype_atom2)%eam_nr, &
681 >               EAMList%EAMParams(mytype_atom2)%eam_rvals, &
682 >               EAMList%EAMParams(mytype_atom2)%eam_rho_r, &
683 >               EAMList%EAMParams(mytype_atom2)%eam_rho_r_pp, &
684 >               rij, rhb,drhb,d2rhb)
685 >
686 >       !! Calculate Phi(r) for atom2.
687 >       call eam_splint(EAMList%EAMParams(mytype_atom2)%eam_nr, &
688 >               EAMList%EAMParams(mytype_atom2)%eam_rvals, &
689 >               EAMList%EAMParams(mytype_atom2)%eam_phi_r, &
690 >               EAMList%EAMParams(mytype_atom2)%eam_phi_r_pp, &
691 >               rij, phb,dphb,d2phb)
692 >
693 >
694 > ! get type specific cutoff for atom 2
695 >       rcj = EAMList%EAMParams(mytype_atom1)%eam_rcut
696 >
697 >
698 >
699 >       if (rij.lt.rci) then
700            phab = phab + 0.5E0_DP*(rhb/rha)*pha
701            dvpdr = dvpdr + 0.5E0_DP*((rhb/rha)*dpha + &
702                 pha*((drhb/rha) - (rhb*drha/rha/rha)))
# Line 574 | Line 707 | contains
707         endif
708        
709  
710 <       if (r.lt.rcj) then
710 >       if (rij.lt.rcj) then
711            phab = phab + 0.5E0_DP*(rha/rhb)*phb
712            dvpdr = dvpdr + 0.5E0_DP*((rha/rhb)*dphb + &
713                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)))
# Line 591 | Line 724 | contains
724         d2rhojdrdr = d2rhb
725  
726  
727 < #ifdef MPI
727 > #ifdef IS_MPI
728         dudr = drhojdr*dfrhodrho_row(atom1)+drhoidr*dfrhodrho_col(atom2) &
729              + dvpdr
730      
# Line 606 | Line 739 | contains
739         fz = dudr * drdz
740  
741  
742 < #ifdef MPI
742 > #ifdef IS_MPI
743         if (do_pot) then
744            pot_Row(atom1) = pot_Row(atom1) + phab*0.5
745            pot_Col(atom2) = pot_Col(atom2) + phab*0.5
# Line 615 | Line 748 | contains
748         f_Row(1,atom1) = f_Row(1,atom1) + fx
749         f_Row(2,atom1) = f_Row(2,atom1) + fy
750         f_Row(3,atom1) = f_Row(3,atom1) + fz
751 <
751 >      
752         f_Col(1,atom2) = f_Col(1,atom2) - fx
753         f_Col(2,atom2) = f_Col(2,atom2) - fy
754         f_Col(3,atom2) = f_Col(3,atom2) - fz
755   #else
756         if(do_pot) pot = pot + phab
757 <
757 >      
758         f(1,atom1) = f(1,atom1) + fx
759         f(2,atom1) = f(2,atom1) + fy
760         f(3,atom1) = f(3,atom1) + fz
761 <
761 >      
762         f(1,atom2) = f(1,atom2) - fx
763         f(2,atom2) = f(2,atom2) - fy
764         f(3,atom2) = f(3,atom2) - fz
765   #endif
766 +      
767 +       if (nmflag) then
768  
769 +          drhoidr = drha
770 +          drhojdr = drhb
771 +          d2rhoidrdr = d2rha
772 +          d2rhojdrdr = d2rhb
773  
774 + #ifdef IS_MPI
775 +          d2 = d2vpdrdr + &
776 +               d2rhoidrdr*dfrhodrho_col(atom2) + &
777 +               d2rhojdrdr*dfrhodrho_row(atom1) + &
778 +               drhoidr*drhoidr*d2frhodrhodrho_col(atom2) + &
779 +               drhojdr*drhojdr*d2frhodrhodrho_row(atom1)
780 +              
781 + #else
782  
783 +          d2 = d2vpdrdr + &
784 +               d2rhoidrdr*dfrhodrho(atom2) + &
785 +               d2rhojdrdr*dfrhodrho(atom1) + &
786 +               drhoidr*drhoidr*d2frhodrhodrho(atom2) + &
787 +               drhojdr*drhojdr*d2frhodrhodrho(atom1)
788 + #endif
789 +       end if
790  
637       if (do_stress) then
791  
792 < #ifdef MPI
792 >      
793 >      
794 >       if (do_stress) then
795 >          
796 > #ifdef IS_MPI
797            id1 = tagRow(atom1)
798            id2 = tagColumn(atom2)
799   #else
800            id1 = atom1
801            id2 = atom2
802   #endif
803 <
803 >          
804            if (molMembershipList(id1) .ne. molMembershipList(id2)) then
805              
806 <             tau_Temp(1) = tau_Temp(1) + fx * d(1)
807 <             tau_Temp(2) = tau_Temp(2) + fx * d(2)
808 <             tau_Temp(3) = tau_Temp(3) + fx * d(3)
809 <             tau_Temp(4) = tau_Temp(4) + fy * d(1)
810 <             tau_Temp(5) = tau_Temp(5) + fy * d(2)
811 <             tau_Temp(6) = tau_Temp(6) + fy * d(3)
812 <             tau_Temp(7) = tau_Temp(7) + fz * d(1)
813 <             tau_Temp(8) = tau_Temp(8) + fz * d(2)
814 <             tau_Temp(9) = tau_Temp(9) + fz * d(3)
806 >
807 >
808 >
809 >             tau_Temp(1) = tau_Temp(1) - d(1) * fx
810 >             tau_Temp(2) = tau_Temp(2) - d(1) * fy
811 >             tau_Temp(3) = tau_Temp(3) - d(1) * fz
812 >             tau_Temp(4) = tau_Temp(4) - d(2) * fx
813 >             tau_Temp(5) = tau_Temp(5) - d(2) * fy
814 >             tau_Temp(6) = tau_Temp(6) - d(2) * fz
815 >             tau_Temp(7) = tau_Temp(7) - d(3) * fx
816 >             tau_Temp(8) = tau_Temp(8) - d(3) * fy
817 >             tau_Temp(9) = tau_Temp(9) - d(3) * fz
818 >
819               virial_Temp = virial_Temp + &
820                    (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
821  
822            endif
823 <       endif
663 <      
823 >       endif  
824      endif
825  
826 <
827 < 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
826 >    
827 >  end subroutine do_eam_pair
828  
829  
830    subroutine eam_splint(nx, xa, ya, yppa, x, y, dy, d2y)
831  
742
832      integer :: atype, nx, j
833      real( kind = DP ), dimension(:) :: xa
834      real( kind = DP ), dimension(:) :: ya
835      real( kind = DP ), dimension(:) :: yppa
836 <    real( kind = DP ) :: x, y, dy, d2y
836 >    real( kind = DP ) :: x, y
837 >    real( kind = DP ) :: dy, d2y
838      real( kind = DP ) :: del, h, a, b, c, d
839 +    integer :: pp_arraySize
840  
841 <
751 <
752 <
753 <    
841 >
842      ! this spline code assumes that the x points are equally spaced
843      ! do not attempt to use this code if they are not.
844      
845      
846      ! find the closest point with a value below our own:
847 <    j = FLOOR(dble(nx-1) * (x - xa(1)) / (xa(nx) - xa(1))) + 1
847 >    j = FLOOR(real((nx-1),kind=dp) * (x - xa(1)) / (xa(nx) - xa(1))) + 1
848  
849      ! check to make sure we're inside the spline range:
850      if ((j.gt.nx).or.(j.lt.1)) then
851 <       write(default_error,*) "EAM_splint: x is outside bounds of spline"
851 >       write(errMSG,*) "EAM_splint: x is outside bounds of spline"
852 >       call handleError(routineName,errMSG)
853      endif
854      ! check to make sure we haven't screwed up the calculation of j:
855      if ((x.lt.xa(j)).or.(x.gt.xa(j+1))) then
856         if (j.ne.nx) then
857 <        write(default_error,*) "EAM_splint: x is outside bounding range"
857 >        write(errMSG,*) "EAM_splint:",x," x is outside bounding range"
858 >       call handleError(routineName,errMSG)
859         endif
860      endif
861  
# Line 778 | Line 868 | end subroutine calc_eam_pair
868      d = b*(b*b - 1.0E0_DP)*h*h/6.0E0_DP
869      
870      y = a*ya(j) + b*ya(j+1) + c*yppa(j) + d*yppa(j+1)
871 <    
872 <    dy = (ya(j+1)-ya(j))/h &
873 <         - (3.0E0_DP*a*a - 1.0E0_DP)*h*yppa(j)/6.0E0_DP &
874 <         + (3.0E0_DP*b*b - 1.0E0_DP)*h*yppa(j+1)/6.0E0_DP
875 <    
876 <    d2y = a*yppa(j) + b*yppa(j+1)
871 >  
872 >       dy = (ya(j+1)-ya(j))/h &
873 >            - (3.0E0_DP*a*a - 1.0E0_DP)*h*yppa(j)/6.0E0_DP &
874 >            + (3.0E0_DP*b*b - 1.0E0_DP)*h*yppa(j+1)/6.0E0_DP
875 >  
876 >  
877 >       d2y = a*yppa(j) + b*yppa(j+1)
878 >  
879  
880    end subroutine eam_splint
881  
882 +
883    subroutine eam_spline(nx, xa, ya, yppa, yp1, ypn, boundary)
884  
792  
885  
794
886      ! yp1 and ypn are the first derivatives of y at the two endpoints
887      ! if boundary is 'L' the lower derivative is used
888      ! if boundary is 'U' the upper derivative is used
# Line 805 | Line 896 | end subroutine calc_eam_pair
896      real( kind = DP ), dimension(:)        :: yppa
897      real( kind = DP ), dimension(size(xa)) :: u
898      real( kind = DP ) :: yp1,ypn,un,qn,sig,p
899 <    character boundary
899 >    character(len=*) :: boundary
900      
901 <    
901 >    ! make sure the sizes match
902 >    if ((nx /= size(xa)) .or. (nx /= size(ya))) then
903 >       call handleWarning("EAM_SPLINE","Array size mismatch")
904 >    end if
905 >
906      if ((boundary.eq.'l').or.(boundary.eq.'L').or. &
907           (boundary.eq.'b').or.(boundary.eq.'B')) then
908         yppa(1) = -0.5E0_DP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines