ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/DarkSide/shapes.F90
(Generate patch)

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/shapes.F90 (file contents):
Revision 1689 by chrisfen, Fri Oct 29 22:28:45 2004 UTC vs.
Revision 2277 by chrisfen, Fri Aug 26 21:30:41 2005 UTC

# Line 1 | Line 1
1 + !!
2 + !! Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 + !!
4 + !! The University of Notre Dame grants you ("Licensee") a
5 + !! non-exclusive, royalty free, license to use, modify and
6 + !! redistribute this software in source and binary code form, provided
7 + !! that the following conditions are met:
8 + !!
9 + !! 1. Acknowledgement of the program authors must be made in any
10 + !!    publication of scientific results based in part on use of the
11 + !!    program.  An acceptable form of acknowledgement is citation of
12 + !!    the article in which the program was described (Matthew
13 + !!    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 + !!    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 + !!    Parallel Simulation Engine for Molecular Dynamics,"
16 + !!    J. Comput. Chem. 26, pp. 252-271 (2005))
17 + !!
18 + !! 2. Redistributions of source code must retain the above copyright
19 + !!    notice, this list of conditions and the following disclaimer.
20 + !!
21 + !! 3. Redistributions in binary form must reproduce the above copyright
22 + !!    notice, this list of conditions and the following disclaimer in the
23 + !!    documentation and/or other materials provided with the
24 + !!    distribution.
25 + !!
26 + !! This software is provided "AS IS," without a warranty of any
27 + !! kind. All express or implied conditions, representations and
28 + !! warranties, including any implied warranty of merchantability,
29 + !! fitness for a particular purpose or non-infringement, are hereby
30 + !! excluded.  The University of Notre Dame and its licensors shall not
31 + !! be liable for any damages suffered by licensee as a result of
32 + !! using, modifying or distributing the software or its
33 + !! derivatives. In no event will the University of Notre Dame or its
34 + !! licensors be liable for any lost revenue, profit or data, or for
35 + !! direct, indirect, special, consequential, incidental or punitive
36 + !! damages, however caused and regardless of the theory of liability,
37 + !! arising out of the use of or inability to use software, even if the
38 + !! University of Notre Dame has been advised of the possibility of
39 + !! such damages.
40 + !!
41 +
42 +
43   module shapes
44  
45    use force_globals
# Line 13 | Line 55 | module shapes
55    implicit none
56  
57    PRIVATE
58 <  
58 >
59    INTEGER, PARAMETER:: CHEBYSHEV_TN = 1
60    INTEGER, PARAMETER:: CHEBYSHEV_UN = 2
61    INTEGER, PARAMETER:: LAGUERRE     = 3
# Line 26 | Line 68 | module shapes
68    public :: do_shape_pair
69    public :: newShapeType
70    public :: complete_Shape_FF
71 +  public :: destroyShapeTypes
72 +  public :: getShapeCut
73  
30
74    type, private :: Shape
75       integer :: atid
76       integer :: nContactFuncs
# Line 51 | Line 94 | module shapes
94       real ( kind = dp )  :: epsilon
95       real ( kind = dp )  :: sigma
96    end type Shape
97 <  
97 >
98    type, private :: ShapeList
99       integer :: n_shapes = 0
100       integer :: currentShape = 0
101 <     type (Shape), pointer :: Shapes(:)      => null()
102 <     integer, pointer      :: atidToShape(:) => null()
101 >     type(Shape), pointer :: Shapes(:)      => null()
102 >     integer, pointer     :: atidToShape(:) => null()
103    end type ShapeList
104    
105    type(ShapeList), save :: ShapeMap
106 <
106 >  
107    integer :: lmax
108 <  real (kind=dp), allocatable, dimension(:,:) :: plm_i, dlm_i, plm_j, dlm_j
66 <  real (kind=dp), allocatable, dimension(:) :: tm_i, dtm_i, um_i, dum_i
67 <  real (kind=dp), allocatable, dimension(:) :: tm_j, dtm_j, um_j, dum_j
68 <
108 >  
109   contains  
110 <
110 >  
111    subroutine newShapeType(nContactFuncs, ContactFuncLValue, &
112         ContactFuncMValue, ContactFunctionType, ContactFuncCoefficient, &
113         nRangeFuncs, RangeFuncLValue, RangeFuncMValue, RangeFunctionType, &
114         RangeFuncCoefficient, nStrengthFuncs, StrengthFuncLValue, &
115         StrengthFuncMValue, StrengthFunctionType, StrengthFuncCoefficient, &
116 <       myATID, status)
117 <
116 >       c_ident, status)
117 >    
118      integer :: nContactFuncs
119      integer :: nRangeFuncs
120      integer :: nStrengthFuncs
121      integer :: shape_ident
122      integer :: status
123 +    integer :: c_ident
124      integer :: myATID
125      integer :: bigL
126      integer :: bigM
# Line 105 | Line 146 | contains  
146  
147         call getMatchingElementList(atypes, "is_Shape", .true., &
148              nShapeTypes, MatchList)
149 <      
149 >
150         call getMatchingElementList(atypes, "is_LennardJones", .true., &
151              nLJTypes, MatchList)
152 <      
152 >
153         ShapeMap%n_shapes = nShapeTypes + nLJTypes
154 <      
154 >
155         allocate(ShapeMap%Shapes(nShapeTypes + nLJTypes))
156 <      
156 >
157         ntypes = getSize(atypes)
158 <      
159 <       allocate(ShapeMap%atidToShape(0:ntypes))
158 >
159 >       allocate(ShapeMap%atidToShape(ntypes))
160      end if
161 <    
161 >
162      ShapeMap%currentShape = ShapeMap%currentShape + 1
163      current = ShapeMap%currentShape
164  
# Line 128 | Line 169 | contains  
169         return
170      endif
171  
172 <    call getElementProperty(atypes, myATID, 'c_ident', me)
172 >    myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
173  
174 <    ShapeMap%atidToShape(me)                         = current
175 <    ShapeMap%Shapes(current)%atid                    = me
174 >    ShapeMap%atidToShape(myATID)                     = current
175 >    ShapeMap%Shapes(current)%atid                    = myATID
176      ShapeMap%Shapes(current)%nContactFuncs           = nContactFuncs
177      ShapeMap%Shapes(current)%nRangeFuncs             = nRangeFuncs
178      ShapeMap%Shapes(current)%nStrengthFuncs          = nStrengthFuncs
# Line 150 | Line 191 | contains  
191  
192      bigL = -1
193      bigM = -1
194 <    
194 >
195      do j = 1, ShapeMap%Shapes(current)%nContactFuncs
196         if (ShapeMap%Shapes(current)%ContactFuncLValue(j) .gt. bigL) then
197            bigL = ShapeMap%Shapes(current)%ContactFuncLValue(j)
# Line 188 | Line 229 | contains  
229      type(Shape), intent(inout) :: myShape
230      integer, intent(out) :: stat
231      integer :: alloc_stat
232 <
232 >
233      stat = 0
234      if (associated(myShape%contactFuncLValue)) then
235         deallocate(myShape%contactFuncLValue)
# Line 292 | Line 333 | contains  
333      return
334  
335    end subroutine allocateShape
336 <    
336 >
337    subroutine complete_Shape_FF(status)
338      integer :: status
339      integer :: i, j, l, m, lm, function_type
340      real(kind=dp) :: thisDP, sigma
341 <    integer :: alloc_stat, iTheta, iPhi, nSteps, nAtypes, thisIP, current
341 >    integer :: alloc_stat, iTheta, iPhi, nSteps, nAtypes, myATID, current
342      logical :: thisProperty
343  
344      status = 0
# Line 306 | Line 347 | contains  
347         status = -1
348         return
349      end if
350 <    
350 >
351      nAtypes = getSize(atypes)
352  
353      if (nAtypes == 0) then
354         status = -1
355         return
356 <    end if
356 >    end if      
357  
358      ! atypes comes from c side
359 <    do i = 0, nAtypes
360 <      
361 <       call getElementProperty(atypes, i, "is_LennardJones", thisProperty)
362 <      
359 >    do i = 1, nAtypes
360 >    
361 >       myATID = getFirstMatchingElement(atypes, 'c_ident', i)
362 >       call getElementProperty(atypes, myATID, "is_LennardJones", thisProperty)
363 >        
364         if (thisProperty) then
323          
365            ShapeMap%currentShape = ShapeMap%currentShape + 1
366            current = ShapeMap%currentShape
367  
368 <          call getElementProperty(atypes, i, "c_ident",  thisIP)
369 <          ShapeMap%atidToShape(thisIP) = current
329 <          ShapeMap%Shapes(current)%atid = thisIP
368 >          ShapeMap%atidToShape(myATID) = current
369 >          ShapeMap%Shapes(current)%atid = myATID
370  
371            ShapeMap%Shapes(current)%isLJ = .true.
372  
373 <          ShapeMap%Shapes(current)%epsilon = getEpsilon(thisIP)
374 <          ShapeMap%Shapes(current)%sigma = getSigma(thisIP)
375 <          
373 >          ShapeMap%Shapes(current)%epsilon = getEpsilon(myATID)
374 >          ShapeMap%Shapes(current)%sigma = getSigma(myATID)
375 >
376         endif
377 <      
377 >
378      end do
379  
380      haveShapeMap = .true.
381 <    
381 >
382 > !    do i = 1, ShapeMap%n_shapes
383 > !       write(*,*) 'i = ', i, ' isLJ = ', ShapeMap%Shapes(i)%isLJ
384 > !    end do
385 >
386    end subroutine complete_Shape_FF
387 <    
387 >
388 >  function getShapeCut(atomID) result(cutValue)
389 >    integer, intent(in) :: atomID
390 >    real(kind=dp) :: cutValue, whoopdedoo
391 >
392 >    !! this is just a placeholder for a cutoff value, hopefully we'll
393 >    !! develop a method to calculate a sensible value
394 >    whoopdedoo = 9.0_dp
395 >
396 >    cutValue = whoopdedoo
397 >
398 >  end function getShapeCut
399 >
400    subroutine do_shape_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, &
401         pot, A, f, t, do_pot)
402 <    
402 >
403      INTEGER, PARAMETER:: LMAX         = 64
404      INTEGER, PARAMETER:: MMAX         = 64
405  
# Line 351 | Line 407 | contains  
407      real (kind=dp), intent(inout) :: rij, r2
408      real (kind=dp), dimension(3), intent(in) :: d
409      real (kind=dp), dimension(3), intent(inout) :: fpair
410 <    real (kind=dp) :: pot, vpair, sw
410 >    real (kind=dp) :: pot, vpair, sw, dswdr
411      real (kind=dp), dimension(9,nLocal) :: A
412      real (kind=dp), dimension(3,nLocal) :: f
413      real (kind=dp), dimension(3,nLocal) :: t
# Line 362 | Line 418 | contains  
418      integer :: l, m, lm, id1, id2, localError, function_type
419      real (kind=dp) :: sigma_i, s_i, eps_i, sigma_j, s_j, eps_j
420      real (kind=dp) :: coeff
421 +    real (kind=dp) :: pot_temp
422  
423      real (kind=dp) :: dsigmaidx, dsigmaidy, dsigmaidz
424      real (kind=dp) :: dsigmaidux, dsigmaiduy, dsigmaiduz
# Line 380 | Line 437 | contains  
437  
438      real (kind=dp) :: xi, yi, zi, xj, yj, zj, xi2, yi2, zi2, xj2, yj2, zj2
439  
440 +    real (kind=dp) :: sti2, stj2
441 +
442      real (kind=dp) :: proji, proji3, projj, projj3
443      real (kind=dp) :: cti, ctj, cpi, cpj, spi, spj
444      real (kind=dp) :: Phunc, sigma, s, eps, rtdenom, rt
# Line 411 | Line 470 | contains  
470      real (kind=dp) :: dsduxi, dsduyi, dsduzi
471      real (kind=dp) :: dsdxj, dsdyj, dsdzj
472      real (kind=dp) :: dsduxj, dsduyj, dsduzj
473 <    
473 >
474      real (kind=dp) :: depsdxi, depsdyi, depsdzi
475      real (kind=dp) :: depsduxi, depsduyi, depsduzi
476      real (kind=dp) :: depsdxj, depsdyj, depsdzj
# Line 438 | Line 497 | contains  
497      real (kind=dp) :: fxji, fyji, fzji, fxjj, fyjj, fzjj
498      real (kind=dp) :: fxradial, fyradial, fzradial
499  
500 <    real (kind=dp) :: plm_i(LMAX,MMAX), dlm_i(LMAX,MMAX)
442 <    real (kind=dp) :: plm_j(LMAX,MMAX), dlm_j(LMAX,MMAX)
443 <    real (kind=dp) :: tm_i(MMAX), dtm_i(MMAX), um_i(MMAX), dum_i(MMAX)
444 <    real (kind=dp) :: tm_j(MMAX), dtm_j(MMAX), um_j(MMAX), dum_j(MMAX)
500 >    real (kind=dp) :: xihat, yihat, zihat, xjhat, yjhat, zjhat
501  
502 +    real (kind=dp) :: plm_i(0:LMAX,0:MMAX), dlm_i(0:LMAX,0:MMAX)
503 +    real (kind=dp) :: plm_j(0:LMAX,0:MMAX), dlm_j(0:LMAX,0:MMAX)
504 +    real (kind=dp) :: tm_i(0:MMAX), dtm_i(0:MMAX), um_i(0:MMAX), dum_i(0:MMAX)
505 +    real (kind=dp) :: tm_j(0:MMAX), dtm_j(0:MMAX), um_j(0:MMAX), dum_j(0:MMAX)
506 +
507      if (.not.haveShapeMap) then
508         call handleError("calc_shape", "NO SHAPEMAP!!!!")
509         return      
510      endif
511 <    
511 >
512      !! We assume that the rotation matrices have already been calculated
513      !! and placed in the A array.
453
514      r3 = r2*rij
515      r5 = r3*r2
516 <    
516 >
517      drdxi = -d(1) / rij
518      drdyi = -d(2) / rij
519      drdzi = -d(3) / rij
520 +    drduxi = 0.0d0
521 +    drduyi = 0.0d0
522 +    drduzi = 0.0d0
523  
524      drdxj = d(1) / rij
525      drdyj = d(2) / rij
526      drdzj = d(3) / rij
527 <    
527 >    drduxj = 0.0d0
528 >    drduyj = 0.0d0
529 >    drduzj = 0.0d0
530 >
531      ! find the atom type id (atid) for each atom:
532   #ifdef IS_MPI
533      atid1 = atid_Row(atom1)
# Line 474 | Line 540 | contains  
540      ! use the atid to find the shape type (st) for each atom:
541      st1 = ShapeMap%atidToShape(atid1)
542      st2 = ShapeMap%atidToShape(atid2)
543 +    
544 + !    write(*,*) atom1, atom2, atid1, atid2, st1, st2, ShapeMap%Shapes(st1)%isLJ, ShapeMap%Shapes(st2)%isLJ
545  
546      if (ShapeMap%Shapes(st1)%isLJ) then
547  
# Line 503 | Line 571 | contains  
571   #ifdef IS_MPI
572         ! rotate the inter-particle separation into the two different
573         ! body-fixed coordinate systems:
574 <      
574 >
575         xi = A_row(1,atom1)*d(1) + A_row(2,atom1)*d(2) + A_row(3,atom1)*d(3)
576         yi = A_row(4,atom1)*d(1) + A_row(5,atom1)*d(2) + A_row(6,atom1)*d(3)
577         zi = A_row(7,atom1)*d(1) + A_row(8,atom1)*d(2) + A_row(9,atom1)*d(3)
578 <      
578 >
579   #else
580         ! rotate the inter-particle separation into the two different
581         ! body-fixed coordinate systems:
582 <      
582 >
583         xi = a(1,atom1)*d(1) + a(2,atom1)*d(2) + a(3,atom1)*d(3)
584         yi = a(4,atom1)*d(1) + a(5,atom1)*d(2) + a(6,atom1)*d(3)
585         zi = a(7,atom1)*d(1) + a(8,atom1)*d(2) + a(9,atom1)*d(3)
518      
519 #endif
586  
587 + #endif
588 +       xihat = xi / rij
589 +       yihat = yi / rij
590 +       zihat = zi / rij
591         xi2 = xi*xi
592         yi2 = yi*yi
593 <       zi2 = zi*zi
524 <      
525 <       proji = sqrt(xi2 + yi2)
526 <       proji3 = proji*proji*proji
527 <      
593 >       zi2 = zi*zi            
594         cti = zi / rij
595  
596 +       if (cti .gt. 1.0_dp) cti = 1.0_dp
597 +       if (cti .lt. -1.0_dp) cti = -1.0_dp
598 +
599         dctidx = - zi * xi / r3
600         dctidy = - zi * yi / r3
601         dctidz = 1.0d0 / rij - zi2 / r3
602 <       dctidux =  yi / rij
603 <       dctiduy = -xi / rij
604 <       dctiduz = 0.0d0
536 <      
537 <       cpi = xi / proji
538 <       dcpidx = 1.0d0 / proji - xi2 / proji3
539 <       dcpidy = - xi * yi / proji3
540 <       dcpidz = 0.0d0
541 <       dcpidux = xi * yi * zi / proji3
542 <       dcpiduy = -zi * (1.0d0 / proji - xi2 / proji3)
543 <       dcpiduz = -yi * (1.0d0 / proji - xi2 / proji3)  - (xi2 * yi / proji3)
544 <      
545 <       spi = yi / proji
546 <       dspidx = - xi * yi / proji3
547 <       dspidy = 1.0d0 / proji - yi2 / proji3
548 <       dspidz = 0.0d0
549 <       dspidux = -zi * (1.0d0 / proji - yi2 / proji3)
550 <       dspiduy = xi * yi * zi / proji3
551 <       dspiduz = xi * (1.0d0 / proji - yi2 / proji3) + (xi * yi2 / proji3)
602 >       dctidux = yi / rij ! - (zi * xi2) / r3
603 >       dctiduy = -xi / rij !- (zi * yi2) / r3
604 >       dctiduz = 0.0d0 !zi / rij - (zi2 * zi) / r3
605  
606 <       call Associated_Legendre(cti, ShapeMap%Shapes(st1)%bigL, &
607 <            ShapeMap%Shapes(st1)%bigM, LMAX, &
606 >       ! this is an attempt to try to truncate the singularity when
607 >       ! sin(theta) is near 0.0:
608 >
609 >       sti2 = 1.0_dp - cti*cti
610 >       if (dabs(sti2) .lt. 1.0d-12) then
611 >          proji = sqrt(rij * 1.0d-12)
612 >          dcpidx = 1.0d0 / proji
613 >          dcpidy = 0.0d0
614 >          dcpidux = xi / proji
615 >          dcpiduy = 0.0d0
616 >          dspidx = 0.0d0
617 >          dspidy = 1.0d0 / proji
618 >          dspidux = 0.0d0
619 >          dspiduy = yi / proji
620 >       else
621 >          proji = sqrt(xi2 + yi2)
622 >          proji3 = proji*proji*proji
623 >          dcpidx = 1.0d0 / proji - xi2 / proji3
624 >          dcpidy = - xi * yi / proji3
625 >          dcpidux = xi / proji - (xi2 * xi) / proji3
626 >          dcpiduy = - (xi * yi2) / proji3
627 >          dspidx = - xi * yi / proji3
628 >          dspidy = 1.0d0 / proji - yi2 / proji3
629 >          dspidux = - (yi * xi2) / proji3
630 >          dspiduy = yi / proji - (yi2 * yi) / proji3
631 >       endif
632 >
633 >       cpi = xi / proji
634 >       dcpidz = 0.0d0
635 >       dcpiduz = 0.0d0
636 >
637 >       spi = yi / proji
638 >       dspidz = 0.0d0
639 >       dspiduz = 0.0d0
640 >
641 >       call Associated_Legendre(cti, ShapeMap%Shapes(st1)%bigM, &
642 >            ShapeMap%Shapes(st1)%bigL, LMAX, &
643              plm_i, dlm_i)
644  
645         call Orthogonal_Polynomial(cpi, ShapeMap%Shapes(st1)%bigM, MMAX, &
646              CHEBYSHEV_TN, tm_i, dtm_i)
647         call Orthogonal_Polynomial(cpi, ShapeMap%Shapes(st1)%bigM, MMAX, &
648              CHEBYSHEV_UN, um_i, dum_i)
649 <      
649 >
650         sigma_i = 0.0d0
651         s_i = 0.0d0
652         eps_i = 0.0d0
# Line 588 | Line 676 | contains  
676            function_type = ShapeMap%Shapes(st1)%ContactFunctionType(lm)
677  
678            if ((function_type .eq. SH_COS).or.(m.eq.0)) then
591           !  write(*,*) tm_i(m), ' is tm_i'
679               Phunc = coeff * tm_i(m)
680               dPhuncdX = coeff * dtm_i(m) * dcpidx
681               dPhuncdY = coeff * dtm_i(m) * dcpidy
682               dPhuncdZ = coeff * dtm_i(m) * dcpidz
683 <             dPhuncdUz = coeff * dtm_i(m) * dcpidux
683 >             dPhuncdUx = coeff * dtm_i(m) * dcpidux
684               dPhuncdUy = coeff * dtm_i(m) * dcpiduy
685               dPhuncdUz = coeff * dtm_i(m) * dcpiduz
686            else
# Line 606 | Line 693 | contains  
693               dPhuncdUz = coeff*(spi * dum_i(m-1)*dcpiduz + dspiduz *um_i(m-1))
694            endif
695  
696 <          sigma_i = sigma_i + plm_i(l,m)*Phunc
697 <          write(*,*) plm_i(l,m), l, m
698 <          dsigmaidx = dsigmaidx + plm_i(l,m)*dPhuncdX + &
699 <               Phunc * dlm_i(l,m) * dctidx
700 <          dsigmaidy = dsigmaidy + plm_i(l,m)*dPhuncdY + &
701 <               Phunc * dlm_i(l,m) * dctidy
702 <          dsigmaidz = dsigmaidz + plm_i(l,m)*dPhuncdZ + &
703 <               Phunc * dlm_i(l,m) * dctidz
704 <          
705 <          dsigmaidux = dsigmaidux + plm_i(l,m)* dPhuncdUx + &
706 <               Phunc * dlm_i(l,m) * dctidux
707 <          dsigmaiduy = dsigmaiduy + plm_i(l,m)* dPhuncdUy + &
708 <               Phunc * dlm_i(l,m) * dctiduy
709 <          dsigmaiduz = dsigmaiduz + plm_i(l,m)* dPhuncdUz + &
710 <               Phunc * dlm_i(l,m) * dctiduz
711 <
696 >          sigma_i = sigma_i + plm_i(m,l)*Phunc
697 > !!$          write(*,*) 'dsigmaidux = ', dsigmaidux
698 > !!$          write(*,*) 'Phunc = ', Phunc
699 >          dsigmaidx = dsigmaidx + plm_i(m,l)*dPhuncdX + &
700 >               Phunc * dlm_i(m,l) * dctidx
701 >          dsigmaidy = dsigmaidy + plm_i(m,l)*dPhuncdY + &
702 >               Phunc * dlm_i(m,l) * dctidy
703 >          dsigmaidz = dsigmaidz + plm_i(m,l)*dPhuncdZ + &
704 >               Phunc * dlm_i(m,l) * dctidz
705 >          dsigmaidux = dsigmaidux + plm_i(m,l)* dPhuncdUx + &
706 >               Phunc * dlm_i(m,l) * dctidux
707 >          dsigmaiduy = dsigmaiduy + plm_i(m,l)* dPhuncdUy + &
708 >               Phunc * dlm_i(m,l) * dctiduy
709 >          dsigmaiduz = dsigmaiduz + plm_i(m,l)* dPhuncdUz + &
710 >               Phunc * dlm_i(m,l) * dctiduz
711 > !!$          write(*,*) 'dsigmaidux = ', dsigmaidux, '; dPhuncdUx = ', dPhuncdUx, &
712 > !!$                     '; dctidux = ', dctidux, '; plm_i(m,l) = ', plm_i(m,l), &
713 > !!$                     '; dlm_i(m,l) = ', dlm_i(m,l), '; m = ', m, '; l = ', l
714         end do
715  
716         do lm = 1, ShapeMap%Shapes(st1)%nRangeFuncs
# Line 629 | Line 718 | contains  
718            m = ShapeMap%Shapes(st1)%RangeFuncMValue(lm)
719            coeff = ShapeMap%Shapes(st1)%RangeFuncCoefficient(lm)
720            function_type = ShapeMap%Shapes(st1)%RangeFunctionType(lm)
721 <          
721 >
722            if ((function_type .eq. SH_COS).or.(m.eq.0)) then
723               Phunc = coeff * tm_i(m)
724               dPhuncdX = coeff * dtm_i(m) * dcpidx
725               dPhuncdY = coeff * dtm_i(m) * dcpidy
726               dPhuncdZ = coeff * dtm_i(m) * dcpidz
727 <             dPhuncdUz = coeff * dtm_i(m) * dcpidux
727 >             dPhuncdUx = coeff * dtm_i(m) * dcpidux
728               dPhuncdUy = coeff * dtm_i(m) * dcpiduy
729               dPhuncdUz = coeff * dtm_i(m) * dcpiduz
730            else
# Line 648 | Line 737 | contains  
737               dPhuncdUz = coeff*(spi * dum_i(m-1)*dcpiduz + dspiduz *um_i(m-1))
738            endif
739  
740 <          s_i = s_i + plm_i(l,m)*Phunc
652 <          
653 <          dsidx = dsidx + plm_i(l,m)*dPhuncdX + &
654 <               Phunc * dlm_i(l,m) * dctidx
655 <          dsidy = dsidy + plm_i(l,m)*dPhuncdY + &
656 <               Phunc * dlm_i(l,m) * dctidy
657 <          dsidz = dsidz + plm_i(l,m)*dPhuncdZ + &
658 <               Phunc * dlm_i(l,m) * dctidz
659 <          
660 <          dsidux = dsidux + plm_i(l,m)* dPhuncdUx + &
661 <               Phunc * dlm_i(l,m) * dctidux
662 <          dsiduy = dsiduy + plm_i(l,m)* dPhuncdUy + &
663 <               Phunc * dlm_i(l,m) * dctiduy
664 <          dsiduz = dsiduz + plm_i(l,m)* dPhuncdUz + &
665 <               Phunc * dlm_i(l,m) * dctiduz      
740 >          s_i = s_i + plm_i(m,l)*Phunc
741  
742 +          dsidx = dsidx + plm_i(m,l)*dPhuncdX + &
743 +               Phunc * dlm_i(m,l) * dctidx
744 +          dsidy = dsidy + plm_i(m,l)*dPhuncdY + &
745 +               Phunc * dlm_i(m,l) * dctidy
746 +          dsidz = dsidz + plm_i(m,l)*dPhuncdZ + &
747 +               Phunc * dlm_i(m,l) * dctidz
748 +
749 +          dsidux = dsidux + plm_i(m,l)* dPhuncdUx + &
750 +               Phunc * dlm_i(m,l) * dctidux
751 +          dsiduy = dsiduy + plm_i(m,l)* dPhuncdUy + &
752 +               Phunc * dlm_i(m,l) * dctiduy
753 +          dsiduz = dsiduz + plm_i(m,l)* dPhuncdUz + &
754 +               Phunc * dlm_i(m,l) * dctiduz      
755 +
756         end do
757 <              
757 >
758         do lm = 1, ShapeMap%Shapes(st1)%nStrengthFuncs
759            l = ShapeMap%Shapes(st1)%StrengthFuncLValue(lm)
760            m = ShapeMap%Shapes(st1)%StrengthFuncMValue(lm)
761            coeff = ShapeMap%Shapes(st1)%StrengthFuncCoefficient(lm)
762            function_type = ShapeMap%Shapes(st1)%StrengthFunctionType(lm)
763 <          
763 >
764            if ((function_type .eq. SH_COS).or.(m.eq.0)) then
765               Phunc = coeff * tm_i(m)
766               dPhuncdX = coeff * dtm_i(m) * dcpidx
767               dPhuncdY = coeff * dtm_i(m) * dcpidy
768               dPhuncdZ = coeff * dtm_i(m) * dcpidz
769 <             dPhuncdUz = coeff * dtm_i(m) * dcpidux
769 >             dPhuncdUx = coeff * dtm_i(m) * dcpidux
770               dPhuncdUy = coeff * dtm_i(m) * dcpiduy
771               dPhuncdUz = coeff * dtm_i(m) * dcpiduz
772            else
# Line 689 | Line 778 | contains  
778               dPhuncdUy = coeff*(spi * dum_i(m-1)*dcpiduy + dspiduy *um_i(m-1))
779               dPhuncdUz = coeff*(spi * dum_i(m-1)*dcpiduz + dspiduz *um_i(m-1))
780            endif
692          !write(*,*) eps_i, plm_i(l,m), Phunc
693          eps_i = eps_i + plm_i(l,m)*Phunc
694          
695          depsidx = depsidx + plm_i(l,m)*dPhuncdX + &
696               Phunc * dlm_i(l,m) * dctidx
697          depsidy = depsidy + plm_i(l,m)*dPhuncdY + &
698               Phunc * dlm_i(l,m) * dctidy
699          depsidz = depsidz + plm_i(l,m)*dPhuncdZ + &
700               Phunc * dlm_i(l,m) * dctidz
701          
702          depsidux = depsidux + plm_i(l,m)* dPhuncdUx + &
703               Phunc * dlm_i(l,m) * dctidux
704          depsiduy = depsiduy + plm_i(l,m)* dPhuncdUy + &
705               Phunc * dlm_i(l,m) * dctiduy
706          depsiduz = depsiduz + plm_i(l,m)* dPhuncdUz + &
707               Phunc * dlm_i(l,m) * dctiduz      
781  
782 +          eps_i = eps_i + plm_i(m,l)*Phunc
783 +
784 +          depsidx = depsidx + plm_i(m,l)*dPhuncdX + &
785 +               Phunc * dlm_i(m,l) * dctidx
786 +          depsidy = depsidy + plm_i(m,l)*dPhuncdY + &
787 +               Phunc * dlm_i(m,l) * dctidy
788 +          depsidz = depsidz + plm_i(m,l)*dPhuncdZ + &
789 +               Phunc * dlm_i(m,l) * dctidz
790 +
791 +          depsidux = depsidux + plm_i(m,l)* dPhuncdUx + &
792 +               Phunc * dlm_i(m,l) * dctidux
793 +          depsiduy = depsiduy + plm_i(m,l)* dPhuncdUy + &
794 +               Phunc * dlm_i(m,l) * dctiduy
795 +          depsiduz = depsiduz + plm_i(m,l)* dPhuncdUz + &
796 +               Phunc * dlm_i(m,l) * dctiduz      
797 +
798         end do
799  
800      endif
712      
713       ! now do j:
801  
802 +    ! now do j:
803 +
804      if (ShapeMap%Shapes(st2)%isLJ) then
805         sigma_j = ShapeMap%Shapes(st2)%sigma
806         s_j = ShapeMap%Shapes(st2)%sigma
# Line 735 | Line 824 | contains  
824         depsjduy = 0.0d0
825         depsjduz = 0.0d0
826      else
827 <      
827 >
828   #ifdef IS_MPI
829         ! rotate the inter-particle separation into the two different
830         ! body-fixed coordinate systems:
831         ! negative sign because this is the vector from j to i:
832 <      
832 >
833         xj = -(A_Col(1,atom2)*d(1) + A_Col(2,atom2)*d(2) + A_Col(3,atom2)*d(3))
834         yj = -(A_Col(4,atom2)*d(1) + A_Col(5,atom2)*d(2) + A_Col(6,atom2)*d(3))
835         zj = -(A_Col(7,atom2)*d(1) + A_Col(8,atom2)*d(2) + A_Col(9,atom2)*d(3))
# Line 748 | Line 837 | contains  
837         ! rotate the inter-particle separation into the two different
838         ! body-fixed coordinate systems:
839         ! negative sign because this is the vector from j to i:
840 <      
840 >
841         xj = -(a(1,atom2)*d(1) + a(2,atom2)*d(2) + a(3,atom2)*d(3))
842         yj = -(a(4,atom2)*d(1) + a(5,atom2)*d(2) + a(6,atom2)*d(3))
843         zj = -(a(7,atom2)*d(1) + a(8,atom2)*d(2) + a(9,atom2)*d(3))
844   #endif
845 <      
845 >
846 >       xjhat = xj / rij
847 >       yjhat = yj / rij
848 >       zjhat = zj / rij
849         xj2 = xj*xj
850         yj2 = yj*yj
851         zj2 = zj*zj
760      
761       projj = sqrt(xj2 + yj2)
762       projj3 = projj*projj*projj
763      
852         ctj = zj / rij
853 +
854 +       if (ctj .gt. 1.0_dp) ctj = 1.0_dp
855 +       if (ctj .lt. -1.0_dp) ctj = -1.0_dp
856 +
857         dctjdx = - zj * xj / r3
858         dctjdy = - zj * yj / r3
859         dctjdz = 1.0d0 / rij - zj2 / r3
860 <       dctjdux =  yj / rij
861 <       dctjduy = -xj / rij
862 <       dctjduz = 0.0d0
863 <      
860 >       dctjdux = yj / rij !- (zi * xj2) / r3
861 >       dctjduy = -xj / rij !- (zj * yj2) / r3
862 >       dctjduz = 0.0d0 !zj / rij - (zj2 * zj) / r3
863 >
864 >       ! this is an attempt to try to truncate the singularity when
865 >       ! sin(theta) is near 0.0:
866 >
867 >       stj2 = 1.0_dp - ctj*ctj
868 >       if (dabs(stj2) .lt. 1.0d-12) then
869 >          projj = sqrt(rij * 1.0d-12)
870 >          dcpjdx = 1.0d0 / projj
871 >          dcpjdy = 0.0d0
872 >          dcpjdux = xj / projj
873 >          dcpjduy = 0.0d0
874 >          dspjdx = 0.0d0
875 >          dspjdy = 1.0d0 / projj
876 >          dspjdux = 0.0d0
877 >          dspjduy = yj / projj
878 >       else
879 >          projj = sqrt(xj2 + yj2)
880 >          projj3 = projj*projj*projj
881 >          dcpjdx = 1.0d0 / projj - xj2 / projj3
882 >          dcpjdy = - xj * yj / projj3
883 >          dcpjdux = xj / projj - (xj2 * xj) / projj3
884 >          dcpjduy = - (xj * yj2) / projj3
885 >          dspjdx = - xj * yj / projj3
886 >          dspjdy = 1.0d0 / projj - yj2 / projj3
887 >          dspjdux = - (yj * xj2) / projj3
888 >          dspjduy = yj / projj - (yj2 * yj) / projj3
889 >       endif
890 >
891         cpj = xj / projj
773       dcpjdx = 1.0d0 / projj - xj2 / projj3
774       dcpjdy = - xj * yj / projj3
892         dcpjdz = 0.0d0
893 <       dcpjdux = xj * yj * zj / projj3
894 <       dcpjduy = -zj * (1.0d0 / projj - xj2 / projj3)
778 <       dcpjduz = -yj * (1.0d0 / projj - xj2 / projj3)  - (xj2 * yj / projj3)
779 <      
893 >       dcpjduz = 0.0d0
894 >
895         spj = yj / projj
781       dspjdx = - xj * yj / projj3
782       dspjdy = 1.0d0 / projj - yj2 / projj3
896         dspjdz = 0.0d0
897 <       dspjdux = -zj * (1.0d0 / projj - yj2 / projj3)
898 <       dspjduy = xj * yj * zj / projj3
899 <       dspjduz = xj * (1.0d0 / projj - yi2 / projj3) + (xj * yj2 / projj3)
900 <      
901 <       call Associated_Legendre(ctj, ShapeMap%Shapes(st2)%bigL, &
902 <            ShapeMap%Shapes(st2)%bigM, LMAX, &
897 >       dspjduz = 0.0d0
898 >
899 >
900 > !       write(*,*) 'dcpdu = ' ,dcpidux, dcpiduy, dcpiduz
901 > !       write(*,*) 'dcpdu = ' ,dcpjdux, dcpjduy, dcpjduz
902 >       call Associated_Legendre(ctj, ShapeMap%Shapes(st2)%bigM, &
903 >            ShapeMap%Shapes(st2)%bigL, LMAX, &
904              plm_j, dlm_j)
905 <      
905 >
906         call Orthogonal_Polynomial(cpj, ShapeMap%Shapes(st2)%bigM, MMAX, &
907              CHEBYSHEV_TN, tm_j, dtm_j)
908         call Orthogonal_Polynomial(cpj, ShapeMap%Shapes(st2)%bigM, MMAX, &
909              CHEBYSHEV_UN, um_j, dum_j)
910 <      
910 >
911         sigma_j = 0.0d0
912         s_j = 0.0d0
913         eps_j = 0.0d0
# Line 827 | Line 941 | contains  
941               dPhuncdX = coeff * dtm_j(m) * dcpjdx
942               dPhuncdY = coeff * dtm_j(m) * dcpjdy
943               dPhuncdZ = coeff * dtm_j(m) * dcpjdz
944 <             dPhuncdUz = coeff * dtm_j(m) * dcpjdux
944 >             dPhuncdUx = coeff * dtm_j(m) * dcpjdux
945               dPhuncdUy = coeff * dtm_j(m) * dcpjduy
946               dPhuncdUz = coeff * dtm_j(m) * dcpjduz
947            else
# Line 839 | Line 953 | contains  
953               dPhuncdUy = coeff*(spj * dum_j(m-1)*dcpjduy + dspjduy *um_j(m-1))
954               dPhuncdUz = coeff*(spj * dum_j(m-1)*dcpjduz + dspjduz *um_j(m-1))
955            endif
842
843          sigma_j = sigma_j + plm_j(l,m)*Phunc
844          
845          dsigmajdx = dsigmajdx + plm_j(l,m)*dPhuncdX + &
846               Phunc * dlm_j(l,m) * dctjdx
847          dsigmajdy = dsigmajdy + plm_j(l,m)*dPhuncdY + &
848               Phunc * dlm_j(l,m) * dctjdy
849          dsigmajdz = dsigmajdz + plm_j(l,m)*dPhuncdZ + &
850               Phunc * dlm_j(l,m) * dctjdz
851          
852          dsigmajdux = dsigmajdux + plm_j(l,m)* dPhuncdUx + &
853               Phunc * dlm_j(l,m) * dctjdux
854          dsigmajduy = dsigmajduy + plm_j(l,m)* dPhuncdUy + &
855               Phunc * dlm_j(l,m) * dctjduy
856          dsigmajduz = dsigmajduz + plm_j(l,m)* dPhuncdUz + &
857               Phunc * dlm_j(l,m) * dctjduz
956  
957 +          sigma_j = sigma_j + plm_j(m,l)*Phunc
958 +
959 +          dsigmajdx = dsigmajdx + plm_j(m,l)*dPhuncdX + &
960 +               Phunc * dlm_j(m,l) * dctjdx
961 +          dsigmajdy = dsigmajdy + plm_j(m,l)*dPhuncdY + &
962 +               Phunc * dlm_j(m,l) * dctjdy
963 +          dsigmajdz = dsigmajdz + plm_j(m,l)*dPhuncdZ + &
964 +               Phunc * dlm_j(m,l) * dctjdz
965 +
966 +          dsigmajdux = dsigmajdux + plm_j(m,l)* dPhuncdUx + &
967 +               Phunc * dlm_j(m,l) * dctjdux
968 +          dsigmajduy = dsigmajduy + plm_j(m,l)* dPhuncdUy + &
969 +               Phunc * dlm_j(m,l) * dctjduy
970 +          dsigmajduz = dsigmajduz + plm_j(m,l)* dPhuncdUz + &
971 +               Phunc * dlm_j(m,l) * dctjduz
972 +
973         end do
974  
975         do lm = 1, ShapeMap%Shapes(st2)%nRangeFuncs
# Line 869 | Line 983 | contains  
983               dPhuncdX = coeff * dtm_j(m) * dcpjdx
984               dPhuncdY = coeff * dtm_j(m) * dcpjdy
985               dPhuncdZ = coeff * dtm_j(m) * dcpjdz
986 <             dPhuncdUz = coeff * dtm_j(m) * dcpjdux
986 >             dPhuncdUx = coeff * dtm_j(m) * dcpjdux
987               dPhuncdUy = coeff * dtm_j(m) * dcpjduy
988               dPhuncdUz = coeff * dtm_j(m) * dcpjduz
989            else
# Line 882 | Line 996 | contains  
996               dPhuncdUz = coeff*(spj * dum_j(m-1)*dcpjduz + dspjduz *um_j(m-1))
997            endif
998  
999 <          s_j = s_j + plm_j(l,m)*Phunc
886 <          
887 <          dsjdx = dsjdx + plm_j(l,m)*dPhuncdX + &
888 <               Phunc * dlm_j(l,m) * dctjdx
889 <          dsjdy = dsjdy + plm_j(l,m)*dPhuncdY + &
890 <               Phunc * dlm_j(l,m) * dctjdy
891 <          dsjdz = dsjdz + plm_j(l,m)*dPhuncdZ + &
892 <               Phunc * dlm_j(l,m) * dctjdz
893 <          
894 <          dsjdux = dsjdux + plm_j(l,m)* dPhuncdUx + &
895 <               Phunc * dlm_j(l,m) * dctjdux
896 <          dsjduy = dsjduy + plm_j(l,m)* dPhuncdUy + &
897 <               Phunc * dlm_j(l,m) * dctjduy
898 <          dsjduz = dsjduz + plm_j(l,m)* dPhuncdUz + &
899 <               Phunc * dlm_j(l,m) * dctjduz
999 >          s_j = s_j + plm_j(m,l)*Phunc
1000  
1001 +          dsjdx = dsjdx + plm_j(m,l)*dPhuncdX + &
1002 +               Phunc * dlm_j(m,l) * dctjdx
1003 +          dsjdy = dsjdy + plm_j(m,l)*dPhuncdY + &
1004 +               Phunc * dlm_j(m,l) * dctjdy
1005 +          dsjdz = dsjdz + plm_j(m,l)*dPhuncdZ + &
1006 +               Phunc * dlm_j(m,l) * dctjdz
1007 +
1008 +          dsjdux = dsjdux + plm_j(m,l)* dPhuncdUx + &
1009 +               Phunc * dlm_j(m,l) * dctjdux
1010 +          dsjduy = dsjduy + plm_j(m,l)* dPhuncdUy + &
1011 +               Phunc * dlm_j(m,l) * dctjduy
1012 +          dsjduz = dsjduz + plm_j(m,l)* dPhuncdUz + &
1013 +               Phunc * dlm_j(m,l) * dctjduz
1014 +
1015         end do
1016  
1017         do lm = 1, ShapeMap%Shapes(st2)%nStrengthFuncs
# Line 924 | Line 1038 | contains  
1038               dPhuncdUz = coeff*(spj * dum_j(m-1)*dcpjduz + dspjduz *um_j(m-1))
1039            endif
1040  
1041 <          eps_j = eps_j + plm_j(l,m)*Phunc
1042 <          
1043 <          depsjdx = depsjdx + plm_j(l,m)*dPhuncdX + &
1044 <               Phunc * dlm_j(l,m) * dctjdx
1045 <          depsjdy = depsjdy + plm_j(l,m)*dPhuncdY + &
1046 <               Phunc * dlm_j(l,m) * dctjdy
1047 <          depsjdz = depsjdz + plm_j(l,m)*dPhuncdZ + &
1048 <               Phunc * dlm_j(l,m) * dctjdz
1049 <          
1050 <          depsjdux = depsjdux + plm_j(l,m)* dPhuncdUx + &
1051 <               Phunc * dlm_j(l,m) * dctjdux
1052 <          depsjduy = depsjduy + plm_j(l,m)* dPhuncdUy + &
1053 <               Phunc * dlm_j(l,m) * dctjduy
1054 <          depsjduz = depsjduz + plm_j(l,m)* dPhuncdUz + &
1055 <               Phunc * dlm_j(l,m) * dctjduz
1041 > !          write(*,*) 'l,m = ', l, m, coeff, dPhuncdUx, dPhuncdUy, dPhuncdUz
1042 >
1043 >          eps_j = eps_j + plm_j(m,l)*Phunc
1044 >
1045 >          depsjdx = depsjdx + plm_j(m,l)*dPhuncdX + &
1046 >               Phunc * dlm_j(m,l) * dctjdx
1047 >          depsjdy = depsjdy + plm_j(m,l)*dPhuncdY + &
1048 >               Phunc * dlm_j(m,l) * dctjdy
1049 >          depsjdz = depsjdz + plm_j(m,l)*dPhuncdZ + &
1050 >               Phunc * dlm_j(m,l) * dctjdz
1051 >
1052 >          depsjdux = depsjdux + plm_j(m,l)* dPhuncdUx + &
1053 >               Phunc * dlm_j(m,l) * dctjdux
1054 >          depsjduy = depsjduy + plm_j(m,l)* dPhuncdUy + &
1055 >               Phunc * dlm_j(m,l) * dctjduy
1056 >          depsjduz = depsjduz + plm_j(m,l)* dPhuncdUz + &
1057 >               Phunc * dlm_j(m,l) * dctjduz
1058  
1059         end do
1060  
# Line 947 | Line 1063 | contains  
1063      ! phew, now let's assemble the potential energy:
1064  
1065      sigma = 0.5*(sigma_i + sigma_j)
1066 <
1066 > !    write(*,*) sigma_i, ' = sigma_i; ', sigma_j, ' = sigma_j'
1067      dsigmadxi = 0.5*dsigmaidx
1068      dsigmadyi = 0.5*dsigmaidy
1069      dsigmadzi = 0.5*dsigmaidz
# Line 977 | Line 1093 | contains  
1093      dsduxj = 0.5*dsjdux
1094      dsduyj = 0.5*dsjduy
1095      dsduzj = 0.5*dsjduz
980    !write(*,*) eps_i, eps_j
981    eps = sqrt(eps_i * eps_j)
1096  
1097 +    eps = sqrt(eps_i * eps_j)
1098 + !!$    write(*,*) 'dsidu = ', dsidux, dsiduy, dsiduz
1099 + !!$    write(*,*) 'dsigidu = ', dsigmaidux, dsigmaiduy, dsigmaiduz
1100 + !!$    write(*,*) sigma_j, ' is sigma j; ', s_j, ' is s j; ', eps_j, ' is eps j'
1101      depsdxi = eps_j * depsidx / (2.0d0 * eps)
1102      depsdyi = eps_j * depsidy / (2.0d0 * eps)
1103      depsdzi = eps_j * depsidz / (2.0d0 * eps)
# Line 993 | Line 1111 | contains  
1111      depsduxj = eps_i * depsjdux / (2.0d0 * eps)
1112      depsduyj = eps_i * depsjduy / (2.0d0 * eps)
1113      depsduzj = eps_i * depsjduz / (2.0d0 * eps)
1114 <    
1114 >
1115 > !!$    write(*,*) 'depsidu = ', depsidux, depsiduy, depsiduz
1116 >
1117 > !!$    write(*,*) 'depsjdu = ', depsjdux, depsjduy, depsjduz
1118 > !!$    write(*,*) 'depsduj = ', depsduxj, depsduyj, depsduzj
1119 > !!$
1120 > !!$    write(*,*) 's, sig, eps = ', s, sigma, eps
1121 >
1122      rtdenom = rij-sigma+s
1123      rt = s / rtdenom
1124  
1125 <    drtdxi = (dsdxi + rt * (drdxi - dsigmadxi + dsdxi)) / rtdenom
1126 <    drtdyi = (dsdyi + rt * (drdyi - dsigmadyi + dsdyi)) / rtdenom
1127 <    drtdzi = (dsdzi + rt * (drdzi - dsigmadzi + dsdzi)) / rtdenom
1128 <    drtduxi = (dsduxi + rt * (drduxi - dsigmaduxi + dsduxi)) / rtdenom
1129 <    drtduyi = (dsduyi + rt * (drduyi - dsigmaduyi + dsduyi)) / rtdenom
1130 <    drtduzi = (dsduzi + rt * (drduzi - dsigmaduzi + dsduzi)) / rtdenom
1131 <    drtdxj = (dsdxj + rt * (drdxj - dsigmadxj + dsdxj)) / rtdenom
1132 <    drtdyj = (dsdyj + rt * (drdyj - dsigmadyj + dsdyj)) / rtdenom
1133 <    drtdzj = (dsdzj + rt * (drdzj - dsigmadzj + dsdzj)) / rtdenom
1134 <    drtduxj = (dsduxj + rt * (drduxj - dsigmaduxj + dsduxj)) / rtdenom
1135 <    drtduyj = (dsduyj + rt * (drduyj - dsigmaduyj + dsduyj)) / rtdenom
1136 <    drtduzj = (dsduzj + rt * (drduzj - dsigmaduzj + dsduzj)) / rtdenom
1137 <    
1125 >    drtdxi = (dsdxi - rt * (drdxi - dsigmadxi + dsdxi)) / rtdenom
1126 >    drtdyi = (dsdyi - rt * (drdyi - dsigmadyi + dsdyi)) / rtdenom
1127 >    drtdzi = (dsdzi - rt * (drdzi - dsigmadzi + dsdzi)) / rtdenom
1128 >    drtduxi = (dsduxi - rt * (drduxi - dsigmaduxi + dsduxi)) / rtdenom
1129 >    drtduyi = (dsduyi - rt * (drduyi - dsigmaduyi + dsduyi)) / rtdenom
1130 >    drtduzi = (dsduzi - rt * (drduzi - dsigmaduzi + dsduzi)) / rtdenom
1131 >    drtdxj = (dsdxj - rt * (drdxj - dsigmadxj + dsdxj)) / rtdenom
1132 >    drtdyj = (dsdyj - rt * (drdyj - dsigmadyj + dsdyj)) / rtdenom
1133 >    drtdzj = (dsdzj - rt * (drdzj - dsigmadzj + dsdzj)) / rtdenom
1134 >    drtduxj = (dsduxj - rt * (drduxj - dsigmaduxj + dsduxj)) / rtdenom
1135 >    drtduyj = (dsduyj - rt * (drduyj - dsigmaduyj + dsduyj)) / rtdenom
1136 >    drtduzj = (dsduzj - rt * (drduzj - dsigmaduzj + dsduzj)) / rtdenom
1137 >
1138 > !!$    write(*,*) 'drtd_i = ', drtdxi, drtdyi, drtdzi
1139 > !!$    write(*,*) 'drtdu_j = ', drtduxj, drtduyj, drtduzj
1140 >
1141      rt2 = rt*rt
1142      rt3 = rt2*rt
1143      rt5 = rt2*rt3
# Line 1018 | Line 1146 | contains  
1146      rt12 = rt6*rt6
1147      rt126 = rt12 - rt6
1148  
1149 +    pot_temp = 4.0d0 * eps * rt126
1150 +
1151 +    vpair = vpair + pot_temp
1152      if (do_pot) then
1153   #ifdef IS_MPI
1154 <       pot_row(atom1) = pot_row(atom1) + 2.0d0*eps*rt126*sw
1155 <       pot_col(atom2) = pot_col(atom2) + 2.0d0*eps*rt126*sw
1154 >       pot_row(atom1) = pot_row(atom1) + 0.5d0*pot_temp*sw
1155 >       pot_col(atom2) = pot_col(atom2) + 0.5d0*pot_temp*sw
1156   #else
1157 <       pot = pot + 4.0d0*eps*rt126*sw
1157 >       pot = pot + pot_temp*sw
1158   #endif
1159      endif
1160 <    
1160 >
1161 > !!$    write(*,*) 'drtdu, depsdu = ', drtduxi, depsduxi
1162 >
1163      dvdxi = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtdxi + 4.0d0*depsdxi*rt126
1164      dvdyi = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtdyi + 4.0d0*depsdyi*rt126
1165      dvdzi = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtdzi + 4.0d0*depsdzi*rt126
# Line 1040 | Line 1173 | contains  
1173      dvduxj = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtduxj + 4.0d0*depsduxj*rt126
1174      dvduyj = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtduyj + 4.0d0*depsduyj*rt126
1175      dvduzj = 24.0d0*eps*(2.0d0*rt11 - rt5)*drtduzj + 4.0d0*depsduzj*rt126
1176 <
1176 > !!$    write(*,*) 'drtduxi = ', drtduxi, ' depsduxi = ', depsduxi
1177      ! do the torques first since they are easy:
1178      ! remember that these are still in the body fixed axes
1179  
1180 <    txi = dvduxi * sw
1181 <    tyi = dvduyi * sw
1182 <    tzi = dvduzi * sw
1180 >    txi = 0.0d0
1181 >    tyi = 0.0d0
1182 >    tzi = 0.0d0
1183  
1184 <    txj = dvduxj * sw
1185 <    tyj = dvduyj * sw
1186 <    tzj = dvduzj * sw
1184 >    txj = 0.0d0
1185 >    tyj = 0.0d0
1186 >    tzj = 0.0d0
1187  
1188 +    txi = (dvduyi - dvduzi) * sw
1189 +    tyi = (dvduzi - dvduxi) * sw
1190 +    tzi = (dvduxi - dvduyi) * sw
1191 +
1192 +    txj = (dvduyj - dvduzj) * sw
1193 +    tyj = (dvduzj - dvduxj) * sw
1194 +    tzj = (dvduxj - dvduyj) * sw
1195 +
1196 + !!$    txi = dvduxi * sw
1197 + !!$    tyi = dvduyi * sw
1198 + !!$    tzi = dvduzi * sw
1199 + !!$
1200 + !!$    txj = dvduxj * sw
1201 + !!$    tyj = dvduyj * sw
1202 + !!$    tzj = dvduzj * sw
1203 +
1204 +    write(*,*) 't1 = ', txi, tyi, tzi
1205 +    write(*,*) 't2 = ', txj, tyj, tzj
1206 +
1207      ! go back to lab frame using transpose of rotation matrix:
1208 <    
1208 >
1209   #ifdef IS_MPI
1210      t_Row(1,atom1) = t_Row(1,atom1) + a_Row(1,atom1)*txi + &
1211           a_Row(4,atom1)*tyi + a_Row(7,atom1)*tzi
# Line 1061 | Line 1213 | contains  
1213           a_Row(5,atom1)*tyi + a_Row(8,atom1)*tzi
1214      t_Row(3,atom1) = t_Row(3,atom1) + a_Row(3,atom1)*txi + &
1215           a_Row(6,atom1)*tyi + a_Row(9,atom1)*tzi
1216 <    
1216 >
1217      t_Col(1,atom2) = t_Col(1,atom2) + a_Col(1,atom2)*txj + &
1218           a_Col(4,atom2)*tyj + a_Col(7,atom2)*tzj
1219      t_Col(2,atom2) = t_Col(2,atom2) + a_Col(2,atom2)*txj + &
1220 <            a_Col(5,atom2)*tyj + a_Col(8,atom2)*tzj
1220 >         a_Col(5,atom2)*tyj + a_Col(8,atom2)*tzj
1221      t_Col(3,atom2) = t_Col(3,atom2) + a_Col(3,atom2)*txj + &
1222           a_Col(6,atom2)*tyj + a_Col(9,atom2)*tzj
1223   #else
1224      t(1,atom1) = t(1,atom1) + a(1,atom1)*txi + a(4,atom1)*tyi + a(7,atom1)*tzi
1225      t(2,atom1) = t(2,atom1) + a(2,atom1)*txi + a(5,atom1)*tyi + a(8,atom1)*tzi
1226      t(3,atom1) = t(3,atom1) + a(3,atom1)*txi + a(6,atom1)*tyi + a(9,atom1)*tzi
1227 <    
1227 >
1228      t(1,atom2) = t(1,atom2) + a(1,atom2)*txj + a(4,atom2)*tyj + a(7,atom2)*tzj
1229      t(2,atom2) = t(2,atom2) + a(2,atom2)*txj + a(5,atom2)*tyj + a(8,atom2)*tzj
1230      t(3,atom2) = t(3,atom2) + a(3,atom2)*txj + a(6,atom2)*tyj + a(9,atom2)*tzj
1231 +
1232   #endif
1233      ! Now, on to the forces:
1234 <    
1234 >
1235      ! first rotate the i terms back into the lab frame:
1083    
1084    fxi = dvdxi * sw
1085    fyi = dvdyi * sw
1086    fzi = dvdzi * sw
1236  
1237 <    fxj = dvdxj * sw
1238 <    fyj = dvdyj * sw
1239 <    fzj = dvdzj * sw
1237 >    fxi = -dvdxi * sw
1238 >    fyi = -dvdyi * sw
1239 >    fzi = -dvdzi * sw
1240  
1241 +    fxj = -dvdxj * sw
1242 +    fyj = -dvdyj * sw
1243 +    fzj = -dvdzj * sw
1244 +
1245 +
1246   #ifdef IS_MPI
1247      fxii = a_Row(1,atom1)*fxi + a_Row(4,atom1)*fyi + a_Row(7,atom1)*fzi
1248      fyii = a_Row(2,atom1)*fxi + a_Row(5,atom1)*fyi + a_Row(8,atom1)*fzi
# Line 1101 | Line 1255 | contains  
1255      fxii = a(1,atom1)*fxi + a(4,atom1)*fyi + a(7,atom1)*fzi
1256      fyii = a(2,atom1)*fxi + a(5,atom1)*fyi + a(8,atom1)*fzi
1257      fzii = a(3,atom1)*fxi + a(6,atom1)*fyi + a(9,atom1)*fzi
1258 <    
1258 >
1259      fxjj = a(1,atom2)*fxj + a(4,atom2)*fyj + a(7,atom2)*fzj
1260      fyjj = a(2,atom2)*fxj + a(5,atom2)*fyj + a(8,atom2)*fzj
1261      fzjj = a(3,atom2)*fxj + a(6,atom2)*fyj + a(9,atom2)*fzj
# Line 1110 | Line 1264 | contains  
1264      fxij = -fxii
1265      fyij = -fyii
1266      fzij = -fzii
1267 <    
1267 >
1268      fxji = -fxjj
1269      fyji = -fyjj
1270      fzji = -fzjj
1271  
1272 <    fxradial = fxii + fxji
1273 <    fyradial = fyii + fyji
1274 <    fzradial = fzii + fzji
1275 <
1272 >    fxradial = (fxii + fxji)
1273 >    fyradial = (fyii + fyji)
1274 >    fzradial = (fzii + fzji)
1275 > !!$    write(*,*) fxradial, ' is fxrad; ', fyradial, ' is fyrad; ', fzradial, 'is fzrad'
1276   #ifdef IS_MPI
1277      f_Row(1,atom1) = f_Row(1,atom1) + fxradial
1278      f_Row(2,atom1) = f_Row(2,atom1) + fyradial
1279      f_Row(3,atom1) = f_Row(3,atom1) + fzradial
1280 <    
1280 >
1281      f_Col(1,atom2) = f_Col(1,atom2) - fxradial
1282      f_Col(2,atom2) = f_Col(2,atom2) - fyradial
1283      f_Col(3,atom2) = f_Col(3,atom2) - fzradial
# Line 1131 | Line 1285 | contains  
1285      f(1,atom1) = f(1,atom1) + fxradial
1286      f(2,atom1) = f(2,atom1) + fyradial
1287      f(3,atom1) = f(3,atom1) + fzradial
1288 <    
1288 >
1289      f(1,atom2) = f(1,atom2) - fxradial
1290      f(2,atom2) = f(2,atom2) - fyradial
1291      f(3,atom2) = f(3,atom2) - fzradial
# Line 1144 | Line 1298 | contains  
1298      id1 = atom1
1299      id2 = atom2
1300   #endif
1301 <    
1301 >
1302      if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1303 <      
1303 >
1304         fpair(1) = fpair(1) + fxradial
1305         fpair(2) = fpair(2) + fyradial
1306         fpair(3) = fpair(3) + fzradial
1307 <      
1307 >
1308      endif
1309 <    
1309 >
1310    end subroutine do_shape_pair
1311 <    
1311 >
1312    SUBROUTINE Associated_Legendre(x, l, m, lmax, plm, dlm)        
1313  
1314      ! Purpose: Compute the associated Legendre functions
# Line 1172 | Line 1326 | contains  
1326      !
1327      ! The original Fortran77 codes can be found here:
1328      ! http://iris-lee3.ece.uiuc.edu/~jjin/routines/routines.html
1329 <    
1329 >
1330      real (kind=dp), intent(in) :: x
1331      integer, intent(in) :: l, m, lmax
1332      real (kind=dp), dimension(0:lmax,0:m), intent(out) :: PLM, DLM
# Line 1189 | Line 1343 | contains  
1343  
1344      ! start with 0,0:
1345      PLM(0,0) = 1.0D0
1346 <  
1346 >
1347      ! x = +/- 1 functions are easy:
1348      IF (abs(X).EQ.1.0D0) THEN
1349         DO I = 1, m
# Line 1244 | Line 1398 | contains  
1398  
1399  
1400    subroutine Orthogonal_Polynomial(x, m, mmax, function_type, pl, dpl)
1401 <  
1401 >
1402      ! Purpose: Compute orthogonal polynomials: Tn(x) or Un(x),
1403      !          or Ln(x) or Hn(x), and their derivatives
1404      ! Input :  function_type --- Function code
# Line 1263 | Line 1417 | contains  
1417      !
1418      ! The original Fortran77 codes can be found here:
1419      ! http://iris-lee3.ece.uiuc.edu/~jjin/routines/routines.html
1420 <  
1420 >
1421      real(kind=8), intent(in) :: x
1422      integer, intent(in):: m, mmax
1423      integer, intent(in):: function_type
1424      real(kind=8), dimension(0:mmax), intent(inout) :: pl, dpl
1425 <  
1425 >
1426      real(kind=8) :: a, b, c, y0, y1, dy0, dy1, yn, dyn
1427      integer :: k
1428  
# Line 1311 | Line 1465 | contains  
1465         DY0 = DY1
1466         DY1 = DYN
1467      end DO
1468 +
1469 +
1470      RETURN
1471 <    
1471 >
1472    end subroutine Orthogonal_Polynomial
1317  
1318 end module shapes
1473  
1474 < subroutine makeShape(nContactFuncs, ContactFuncLValue, &
1475 <     ContactFuncMValue, ContactFunctionType, ContactFuncCoefficient, &
1322 <     nRangeFuncs, RangeFuncLValue, RangeFuncMValue, RangeFunctionType, &
1323 <     RangeFuncCoefficient, nStrengthFuncs, StrengthFuncLValue, &
1324 <     StrengthFuncMValue, StrengthFunctionType, StrengthFuncCoefficient, &
1325 <     myATID, status)
1326 <
1327 <  use definitions
1328 <  use shapes, only: newShapeType
1329 <  
1330 <  integer :: nContactFuncs
1331 <  integer :: nRangeFuncs
1332 <  integer :: nStrengthFuncs
1333 <  integer :: status
1334 <  integer :: myATID
1335 <  
1336 <  integer, dimension(nContactFuncs) :: ContactFuncLValue          
1337 <  integer, dimension(nContactFuncs) :: ContactFuncMValue          
1338 <  integer, dimension(nContactFuncs) :: ContactFunctionType        
1339 <  real(kind=dp), dimension(nContactFuncs) :: ContactFuncCoefficient
1340 <  integer, dimension(nRangeFuncs) :: RangeFuncLValue            
1341 <  integer, dimension(nRangeFuncs) :: RangeFuncMValue            
1342 <  integer, dimension(nRangeFuncs) :: RangeFunctionType          
1343 <  real(kind=dp), dimension(nRangeFuncs) :: RangeFuncCoefficient  
1344 <  integer, dimension(nStrengthFuncs) :: StrengthFuncLValue          
1345 <  integer, dimension(nStrengthFuncs) :: StrengthFuncMValue          
1346 <  integer, dimension(nStrengthFuncs) :: StrengthFunctionType        
1347 <  real(kind=dp), dimension(nStrengthFuncs) :: StrengthFuncCoefficient
1348 <  
1349 <  call newShapeType(nContactFuncs, ContactFuncLValue, &
1350 <       ContactFuncMValue, ContactFunctionType, ContactFuncCoefficient, &
1351 <       nRangeFuncs, RangeFuncLValue, RangeFuncMValue, RangeFunctionType, &
1352 <       RangeFuncCoefficient, nStrengthFuncs, StrengthFuncLValue, &
1353 <       StrengthFuncMValue, StrengthFunctionType, StrengthFuncCoefficient, &
1354 <       myATID, status)
1355 <
1356 <  return
1357 < end subroutine makeShape
1358 <
1359 < subroutine completeShapeFF(status)
1360 <
1361 <  use shapes, only: complete_Shape_FF
1474 >  subroutine deallocateShapes(this)
1475 >    type(Shape), pointer :: this
1476  
1477 <  integer, intent(out)  :: status
1478 <  integer :: myStatus
1477 >    if (associated( this%ContactFuncLValue)) then
1478 >       deallocate(this%ContactFuncLValue)
1479 >       this%ContactFuncLValue => null()
1480 >    end if
1481  
1482 <  myStatus = 0
1482 >    if (associated( this%ContactFuncMValue)) then
1483 >       deallocate( this%ContactFuncMValue)
1484 >       this%ContactFuncMValue => null()
1485 >    end if
1486 >    if (associated( this%ContactFunctionType)) then
1487 >       deallocate(this%ContactFunctionType)
1488 >       this%ContactFunctionType => null()
1489 >    end if
1490  
1491 <  call complete_Shape_FF(myStatus)
1491 >    if (associated( this%ContactFuncCoefficient)) then
1492 >       deallocate(this%ContactFuncCoefficient)
1493 >       this%ContactFuncCoefficient => null()
1494 >    end if
1495  
1496 <  status = myStatus
1496 >    if (associated( this%RangeFuncLValue)) then
1497 >       deallocate(this%RangeFuncLValue)
1498 >       this%RangeFuncLValue => null()
1499 >    end if
1500 >    if (associated( this%RangeFuncMValue)) then
1501 >       deallocate( this%RangeFuncMValue)
1502 >       this%RangeFuncMValue => null()
1503 >    end if
1504  
1505 <  return
1506 < end subroutine completeShapeFF
1505 >    if (associated( this%RangeFunctionType)) then
1506 >       deallocate( this%RangeFunctionType)
1507 >       this%RangeFunctionType => null()
1508 >    end if
1509 >    if (associated( this%RangeFuncCoefficient)) then
1510 >       deallocate(this%RangeFuncCoefficient)
1511 >       this%RangeFuncCoefficient => null()
1512 >    end if
1513  
1514 +    if (associated( this%StrengthFuncLValue)) then
1515 +       deallocate(this%StrengthFuncLValue)
1516 +       this%StrengthFuncLValue => null()
1517 +    end if
1518 +
1519 +    if (associated( this%StrengthFuncMValue )) then
1520 +       deallocate(this%StrengthFuncMValue)
1521 +       this%StrengthFuncMValue => null()
1522 +    end if
1523 +
1524 +    if(associated( this%StrengthFunctionType)) then
1525 +       deallocate(this%StrengthFunctionType)
1526 +       this%StrengthFunctionType => null()
1527 +    end if
1528 +    if (associated( this%StrengthFuncCoefficient )) then
1529 +       deallocate(this%StrengthFuncCoefficient)
1530 +       this%StrengthFuncCoefficient => null()
1531 +    end if
1532 +  end subroutine deallocateShapes
1533 +
1534 +  subroutine destroyShapeTypes
1535 +    integer :: i
1536 +    type(Shape), pointer :: thisShape
1537 +
1538 +    ! First walk through and kill the shape
1539 +    do i = 1,ShapeMap%n_shapes
1540 +       thisShape => ShapeMap%Shapes(i)
1541 +       call deallocateShapes(thisShape)
1542 +    end do
1543 +
1544 +    ! set shape map to starting values
1545 +    ShapeMap%n_shapes = 0
1546 +    ShapeMap%currentShape = 0
1547 +
1548 +    if (associated(ShapeMap%Shapes)) then
1549 +       deallocate(ShapeMap%Shapes)
1550 +       ShapeMap%Shapes => null()
1551 +    end if
1552 +
1553 +    if (associated(ShapeMap%atidToShape)) then
1554 +       deallocate(ShapeMap%atidToShape)
1555 +       ShapeMap%atidToShape => null()
1556 +    end if
1557 +
1558 +
1559 +  end subroutine destroyShapeTypes
1560 +
1561 +
1562 + end module shapes

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines