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

Comparing trunk/OOPSE/libmdtools/do_Forces.F90 (file contents):
Revision 1144 by tim, Sat May 1 18:52:38 2004 UTC vs.
Revision 1197 by gezelter, Wed May 26 16:41:23 2004 UTC

# Line 4 | Line 4
4  
5   !! @author Charles F. Vardeman II
6   !! @author Matthew Meineke
7 < !! @version $Id: do_Forces.F90,v 1.53 2004-05-01 18:52:38 tim Exp $, $Date: 2004-05-01 18:52:38 $, $Name: not supported by cvs2svn $, $Revision: 1.53 $
7 > !! @version $Id: do_Forces.F90,v 1.62 2004-05-26 16:41:23 gezelter Exp $, $Date: 2004-05-26 16:41:23 $, $Name: not supported by cvs2svn $, $Revision: 1.62 $
8  
9   module do_Forces
10    use force_globals
11    use simulation
12    use definitions
13    use atype_module
14 +  use switcheroo
15    use neighborLists  
16    use lj
17    use sticky_pair
# Line 30 | Line 31 | module do_Forces
31  
32   #define __FORTRAN90
33   #include "fForceField.h"
34 + #include "fSwitchingFunction.h"
35  
36 +  INTEGER, PARAMETER:: PREPAIR_LOOP = 1
37 +  INTEGER, PARAMETER:: PAIR_LOOP    = 2
38 +
39    logical, save :: haveRlist = .false.
40    logical, save :: haveNeighborList = .false.
41    logical, save :: havePolicies = .false.
# Line 63 | Line 68 | module do_Forces
68    public :: do_force_loop
69    public :: setRlistDF
70  
66
71   #ifdef PROFILE
72    public :: getforcetime
73    real, save :: forceTime = 0
# Line 279 | Line 283 | contains
283      
284      !! Assume sanity (for the sake of argument)
285      haveSaneForceField = .true.
282    !!
283    if (FF_uses_charges) then
284      dielect = getDielect()
285      call initialize_charge(dielect)
286    endif
286  
288
287      !! check to make sure the FF_uses_RF setting makes sense
288      
289      if (FF_uses_dipoles) then
# Line 364 | Line 362 | contains
362         endif
363         haveNeighborList = .true.
364      endif
365 +
366      
367 +    
368    end subroutine init_FF
369    
370  
371    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
372    !------------------------------------------------------------->
373 <  subroutine do_force_loop(q, qcom, A, u_l, f, t, tau, pot, &
373 >  subroutine do_force_loop(q, q_group, A, u_l, f, t, tau, pot, &
374         do_pot_c, do_stress_c, error)
375      !! Position array provided by C, dimensioned by getNlocal
376 <    real ( kind = dp ), dimension(3,nLocal) :: q
376 >    real ( kind = dp ), dimension(3, nLocal) :: q
377      !! molecular center-of-mass position array
378 <    real ( kind = dp ), dimension(3,nLocal) :: qcom
378 >    real ( kind = dp ), dimension(3, nGroup) :: q_group
379      !! Rotation Matrix for each long range particle in simulation.
380 <    real( kind = dp), dimension(9,nLocal) :: A    
380 >    real( kind = dp), dimension(9, nLocal) :: A    
381      !! Unit vectors for dipoles (lab frame)
382      real( kind = dp ), dimension(3,nLocal) :: u_l
383      !! Force array provided by C, dimensioned by getNlocal
# Line 391 | Line 391 | contains
391      logical ( kind = 2) :: do_pot_c, do_stress_c
392      logical :: do_pot
393      logical :: do_stress
394 +    logical :: in_switching_region
395   #ifdef IS_MPI
396      real( kind = DP ) :: pot_local
397      integer :: nrow
398      integer :: ncol
399      integer :: nprocs
400 +    integer :: nrow_group
401 +    integer :: ncol_group
402   #endif
403      integer :: natoms    
404      logical :: update_nlist  
405 <    integer :: i, j, jbeg, jend, jnab
405 >    integer :: i, j, jstart, jend, jnab
406 >    integer :: istart, iend
407 >    integer :: ia, jb, atom1, atom2
408      integer :: nlist
409 <    real( kind = DP ) ::  rijsq, rcijsq
410 <    real(kind=dp),dimension(3) :: d, dc
409 >    real( kind = DP ) :: ratmsq, rgrpsq, rgrp, vpair, vij
410 >    real( kind = DP ) :: sw, dswdr, swderiv, mf
411 >    real(kind=dp),dimension(3) :: d_atm, d_grp, fpair, fij
412      real(kind=dp) :: rfpot, mu_i, virial
413 <    integer :: me_i, me_j
413 >    integer :: me_i, me_j, n_in_i, n_in_j
414      logical :: is_dp_i
415      integer :: neighborListSize
416      integer :: listerror, error
417      integer :: localError
418      integer :: propPack_i, propPack_j
419 +    integer :: loopStart, loopEnd, loop
420  
421      real(kind=dp) :: listSkin = 1.0  
422      
# Line 419 | Line 426 | contains
426      pot_local = 0.0_dp
427      nrow   = getNrow(plan_row)
428      ncol   = getNcol(plan_col)
429 +    nrow_group   = getNrowGroup(plan_row)
430 +    ncol_group   = getNcolGroup(plan_col)
431   #else
432      natoms = nlocal
433   #endif
# Line 438 | Line 447 | contains
447      
448   #ifdef IS_MPI    
449      
450 <    call gather(q,q_Row,plan_row3d)
451 <    call gather(q,q_Col,plan_col3d)
452 <    
453 <    if (SIM_uses_molecular_cutoffs) then
454 <       call gather(qcom,qcom_Row,plan_row3d)
455 <       call gather(qcom,qcom_Col,plan_col3d)
447 <    endif
448 <    
450 >    call gather(q, q_Row, plan_row3d)
451 >    call gather(q, q_Col, plan_col3d)
452 >
453 >    call gather(q_group, q_group_Row, plan_row_Group_3d)
454 >    call gather(q_group, q_group_Col, plan_col_Group_3d)
455 >        
456      if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then
457         call gather(u_l,u_l_Row,plan_row3d)
458         call gather(u_l,u_l_Col,plan_col3d)
# Line 462 | Line 469 | contains
469      nloops = nloops + 1
470   #endif
471      
472 +    loopEnd = PAIR_LOOP
473      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
474 <       !! See if we need to update neighbor lists
475 <       if (SIM_uses_molecular_cutoffs) then
476 <          call checkNeighborList(nlocal, qcom, listSkin, update_nlist)
477 <       else
478 <          call checkNeighborList(nlocal, q, listSkin, update_nlist)  
474 >       loopStart = PREPAIR_LOOP
475 >    else
476 >       loopStart = PAIR_LOOP
477 >    endif
478 >
479 >    do loop = loopStart, loopEnd
480 >
481 >       ! See if we need to update neighbor lists
482 >       ! (but only on the first time through):
483 >       if (loop .eq. loopStart) then
484 >          call checkNeighborList(nGroup, q_group, listSkin, update_nlist)
485         endif
472       !! if_mpi_gather_stuff_for_prepair
473       !! do_prepair_loop_if_needed
474       !! if_mpi_scatter_stuff_from_prepair
475       !! if_mpi_gather_stuff_from_prepair_to_main_loop
486        
477       !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>>
478 #ifdef IS_MPI
479      
487         if (update_nlist) then
488 <          
489 <          !! save current configuration, construct neighbor list,
483 <          !! and calculate forces
484 <          if (SIM_uses_molecular_cutoffs) then
485 <             call saveNeighborList(nlocal, qcom)
486 <          else
487 <             call saveNeighborList(nlocal, q)
488 <          endif
489 <          
488 >          !! save current configuration and construct neighbor list
489 >          call saveNeighborList(nGroup, q_group)          
490            neighborListSize = size(list)
491 <          nlist = 0      
492 <          
493 <          do i = 1, nrow
494 <             point(i) = nlist + 1
495 <            
496 <             prepair_inner: do j = 1, ncol
497 <                
498 <                if (skipThisPair(i,j)) cycle prepair_inner
499 <                
500 <                if (SIM_uses_molecular_cutoffs) then
501 <                   call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), &
502 <                        dc, rcijsq)
503 <                else
504 <                   call get_interatomic_vector(q_Row(:,i), q_Col(:,j), &
505 <                        dc, rcijsq)
506 <                endif
507 <                
508 <                if (rcijsq < rlistsq) then            
509 <                  
510 <                   nlist = nlist + 1
511 <                  
512 <                   if (nlist > neighborListSize) then
513 <                      call expandNeighborList(nlocal, listerror)
514 <                      if (listerror /= 0) then
515 <                         error = -1
516 <                         write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
517 <                         return
518 <                      end if
519 <                      neighborListSize = size(list)
520 <                   endif
521 <                  
522 <                   list(nlist) = j
523 <                  
524 <                   if (SIM_uses_molecular_cutoffs) then
525 <                      ! since the simulation distances were in molecular COMs:
526 <                      call get_interatomic_vector(q_Row(:,i), q_Col(:,j), &
527 <                           d, rijsq)
528 <                   else
529 <                      d(1:3) = dc(1:3)
530 <                      rijsq = rcijsq
531 <                   endif
532 <                  
533 <                   call do_prepair(i, j, rijsq, d, rcijsq, dc, &
534 <                        do_pot, do_stress, u_l, A, f, t, pot_local)
535 <                endif
536 <             enddo prepair_inner
537 <          enddo
538 <          
539 <          point(nrow + 1) = nlist + 1
540 <          
541 <       else  !! (of update_check)
542 <          
543 <          ! use the list to find the neighbors
544 <          do i = 1, nrow
545 <             JBEG = POINT(i)
546 <             JEND = POINT(i+1) - 1
547 <             ! check thiat molecule i has neighbors
548 <             if (jbeg .le. jend) then
549 <                
550 <                do jnab = jbeg, jend
551 <                   j = list(jnab)
552 <                                      
553 <                   call get_interatomic_vector(q_Row(:,i), q_Col(:,j), &
554 <                        d, rijsq)
555 <                   if (SIM_uses_molecular_cutoffs) then
556 <                      call get_interatomic_vector(qcom_Row(:,i),qcom_Col(:,j),&
557 <                           dc, rcijsq)
558 <                   else
559 <                      dc(1:3) = d(1:3)
560 <                      rcijsq = rijsq
561 <                   endif
562 <                  
563 <                   call do_prepair(i, j, rijsq, d, rcijsq, dc, &
564 <                        do_pot, do_stress, u_l, A, f, t, pot_local)
565 <                  
566 <                enddo
567 <             endif
568 <          enddo
491 >          nlist = 0
492         endif
493        
494 +       istart = 1
495 + #ifdef IS_MPI
496 +       iend = nrow_group
497   #else
498 <      
499 <       if (update_nlist) then
498 >       iend = nGroup - 1
499 > #endif
500 >       outer: do i = istart, iend
501            
502 <          ! save current configuration, contruct neighbor list,
576 <          ! and calculate forces
577 <          call saveNeighborList(natoms, q)
502 >          if (update_nlist) point(i) = nlist + 1
503            
504 <          neighborListSize = size(list)
504 >          n_in_i = groupStart(i+1) - groupStart(i)
505            
506 <          nlist = 0
506 >          if (update_nlist) then
507 > #ifdef IS_MPI
508 >             jstart = 1
509 >             jend = ncol_group
510 > #else
511 >             jstart = i+1
512 >             jend = nGroup
513 > #endif
514 >          else            
515 >             jstart = point(i)
516 >             jend = point(i+1) - 1
517 >             ! make sure group i has neighbors
518 >             if (jstart .gt. jend) cycle outer
519 >          endif
520            
521 <          do i = 1, natoms-1
522 <             point(i) = nlist + 1
523 <            
524 <             prepair_inner: do j = i+1, natoms
525 <                
526 <                if (skipThisPair(i,j))  cycle prepair_inner
527 <                
528 <                if (SIM_uses_molecular_cutoffs) then
529 <                   call get_interatomic_vector(qcom(:,i), qcom(:,j), &
530 <                        dc, rcijsq)
531 <                else
532 <                   call get_interatomic_vector(q(:,i), q(:,j), dc, rcijsq)
533 <                endif
534 <                
535 <                if (rcijsq < rlistsq) then
598 <                  
521 >          do jnab = jstart, jend
522 >             if (update_nlist) then
523 >                j = jnab
524 >             else
525 >                j = list(jnab)
526 >             endif
527 > #ifdef IS_MPI
528 >             call get_interatomic_vector(q_group_Row(:,i), &
529 >                  q_group_Col(:,j), d_grp, rgrpsq)
530 > #else
531 >             call get_interatomic_vector(q_group(:,i), &
532 >                  q_group(:,j), d_grp, rgrpsq)
533 > #endif
534 >             if (rgrpsq < rlistsq) then
535 >                if (update_nlist) then
536                     nlist = nlist + 1
537                    
538                     if (nlist > neighborListSize) then
539 <                      call expandNeighborList(natoms, listerror)
539 >                      call expandNeighborList(nGroup, listerror)
540                        if (listerror /= 0) then
541                           error = -1
542                           write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
# Line 609 | Line 546 | contains
546                     endif
547                    
548                     list(nlist) = j
612                  
613                  
614                   if (SIM_uses_molecular_cutoffs) then
615                      ! since the simulation distances were in molecular COMs:
616                      call get_interatomic_vector(q(:,i), q(:,j), &
617                           d, rijsq)
618                   else
619                      dc(1:3) = d(1:3)
620                      rcijsq = rijsq
621                   endif
622                  
623                   call do_prepair(i, j, rijsq, d, rcijsq, dc, &
624                        do_pot, do_stress, u_l, A, f, t, pot)
625                  
549                  endif
627             enddo prepair_inner
628          enddo
629          
630          point(natoms) = nlist + 1
631          
632       else !! (update)
633          
634          ! use the list to find the neighbors
635          do i = 1, natoms-1
636             JBEG = POINT(i)
637             JEND = POINT(i+1) - 1
638             ! check thiat molecule i has neighbors
639             if (jbeg .le. jend) then
550                  
551 <                do jnab = jbeg, jend
552 <                   j = list(jnab)
553 <                  
644 <                   call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
645 <                   if (SIM_uses_molecular_cutoffs) then
646 <                      call get_interatomic_vector(qcom(:,i), qcom(:,j), &
647 <                           dc, rcijsq)
648 <                   else
649 <                      dc(1:3) = d(1:3)
650 <                      rcijsq = rijsq
651 <                   endif
652 <                  
653 <                   call do_prepair(i, j, rijsq, d, rcijsq, dc, &
654 <                        do_pot, do_stress, u_l, A, f, t, pot)
655 <                  
656 <                enddo
657 <             endif
658 <          enddo
659 <       endif
660 < #endif
661 <       !! Do rest of preforce calculations
662 <       !! do necessary preforce calculations  
663 <       call do_preforce(nlocal,pot)
664 <       ! we have already updated the neighbor list set it to false...
665 <       update_nlist = .false.
666 <    else
667 <       !! See if we need to update neighbor lists for non pre-pair
668 <       call checkNeighborList(nlocal, q, listSkin, update_nlist)  
669 <    endif
670 <    
671 <    !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>
672 <    
673 < #ifdef IS_MPI
674 <    
675 <    if (update_nlist) then
676 <       !! save current configuration, construct neighbor list,
677 <       !! and calculate forces
678 <       call saveNeighborList(nlocal, q)
679 <      
680 <       neighborListSize = size(list)
681 <       nlist = 0      
682 <      
683 <       do i = 1, nrow
684 <          
685 <          point(i) = nlist + 1
686 <          
687 <          inner: do j = 1, ncol
688 <            
689 <             if (skipThisPair(i,j)) cycle inner
690 <            
691 <             if (SIM_uses_molecular_cutoffs) then
692 <                call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), &
693 <                     dc, rcijsq)
694 <             else
695 <                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), &
696 <                     dc, rcijsq)
697 <             endif
698 <            
699 <             if (rcijsq < rlistsq) then            
700 <                
701 <                nlist = nlist + 1
702 <                
703 <                if (nlist > neighborListSize) then
704 <                   call expandNeighborList(nlocal, listerror)
705 <                   if (listerror /= 0) then
706 <                      error = -1
707 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
708 <                      return
709 <                   end if
710 <                   neighborListSize = size(list)
551 >                if (loop .eq. PAIR_LOOP) then
552 >                   vij = 0.0d0
553 >                   fij(1:3) = 0.0d0
554                  endif
555                  
556 <                list(nlist) = j
556 >                call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
557 >                     in_switching_region)
558                  
559 <                if (SIM_uses_molecular_cutoffs) then
716 <                   call get_interatomic_vector(q_Row(:,i), q_Col(:,j), &
717 <                        d, rijsq)
718 <                else
719 <                   d(1:3) = dc(1:3)
720 <                   rijsq = rcijsq
721 <                endif
559 >                n_in_j = groupStart(j+1) - groupStart(j)
560                  
561 <                call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, &
562 <                     do_pot, do_stress, u_l, A, f, t, pot_local)
563 <                
564 <             endif
565 <          enddo inner
566 <       enddo
567 <      
568 <       point(nrow + 1) = nlist + 1
569 <      
570 <    else  !! (of update_check)
571 <      
572 <       ! use the list to find the neighbors
573 <       do i = 1, nrow
574 <          JBEG = POINT(i)
575 <          JEND = POINT(i+1) - 1
576 <          ! check thiat molecule i has neighbors
577 <          if (jbeg .le. jend) then
740 <            
741 <             do jnab = jbeg, jend
742 <                j = list(jnab)
743 <                
744 <                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
745 <                if (SIM_uses_molecular_cutoffs) then
746 <                   call get_interatomic_vector(qcom_Row(:,i), qcom_Col(:,j), &
747 <                        dc, rcijsq)
748 <                else
749 <                   dc(1:3) = d(1:3)
750 <                   rcijsq = rijsq
751 <                endif
752 <                
753 <                call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, &
754 <                     do_pot, do_stress, u_l, A, f, t, pot_local)
755 <                
756 <             enddo
757 <          endif
758 <       enddo
759 <    endif
760 <    
561 >                do ia = groupStart(i), groupStart(i+1)-1
562 >                  
563 >                   atom1 = groupList(ia)
564 >                  
565 >                   inner: do jb = groupStart(j), groupStart(j+1)-1
566 >                      
567 >                      atom2 = groupList(jb)
568 >                      
569 >                      if (skipThisPair(atom1, atom2)) cycle inner
570 >                      
571 >                      if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
572 >                         d_atm(1:3) = d_grp(1:3)
573 >                         ratmsq = rgrpsq
574 >                      else
575 > #ifdef IS_MPI
576 >                         call get_interatomic_vector(q_Row(:,atom1), &
577 >                              q_Col(:,atom2), d_atm, ratmsq)
578   #else
579 <    
580 <    if (update_nlist) then
581 <      
582 <       ! save current configuration, contruct neighbor list,
583 <       ! and calculate forces
584 <       call saveNeighborList(natoms, q)
585 <      
586 <       neighborListSize = size(list)
587 <      
588 <       nlist = 0
589 <      
590 <       do i = 1, natoms-1
591 <          point(i) = nlist + 1
592 <          
593 <          inner: do j = i+1, natoms
594 <            
595 <             if (skipThisPair(i,j))  cycle inner
596 <            
597 <             if (SIM_uses_molecular_cutoffs) then
598 <                call get_interatomic_vector(qcom(:,i), qcom(:,j), &
599 <                     dc, rcijsq)
600 <             else
601 <                call get_interatomic_vector(q(:,i), q(:,j), &
602 <                     dc, rcijsq)
603 <             endif
604 <            
605 <             if (rcijsq < rlistsq) then
579 >                         call get_interatomic_vector(q(:,atom1), &
580 >                              q(:,atom2), d_atm, ratmsq)
581 > #endif
582 >                      endif
583 >                      if (loop .eq. PREPAIR_LOOP) then
584 > #ifdef IS_MPI                      
585 >                         call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
586 >                              rgrpsq, d_grp, do_pot, do_stress, &
587 >                              u_l, A, f, t, pot_local)
588 > #else
589 >                         call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
590 >                              rgrpsq, d_grp, do_pot, do_stress, &
591 >                              u_l, A, f, t, pot)
592 > #endif                                              
593 >                      else
594 > #ifdef IS_MPI                      
595 >                         call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
596 >                              do_pot, &
597 >                              u_l, A, f, t, pot_local, vpair, fpair)
598 > #else
599 >                         call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
600 >                              do_pot,  &
601 >                              u_l, A, f, t, pot, vpair, fpair)
602 > #endif
603 >                         vij = vij + vpair
604 >                         fij(1:3) = fij(1:3) + fpair(1:3)
605 >                      endif
606 >                   enddo inner
607 >                enddo
608                  
609 <                nlist = nlist + 1
610 <                
611 <                if (nlist > neighborListSize) then
612 <                   call expandNeighborList(natoms, listerror)
613 <                   if (listerror /= 0) then
614 <                      error = -1
615 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
616 <                      return
617 <                   end if
618 <                   neighborListSize = size(list)
609 >                if (loop .eq. PAIR_LOOP) then
610 >                   if (in_switching_region) then
611 >                      swderiv = vij*dswdr/rgrp
612 >                      fij(1) = fij(1) + swderiv*d_grp(1)
613 >                      fij(2) = fij(2) + swderiv*d_grp(2)
614 >                      fij(3) = fij(3) + swderiv*d_grp(3)
615 >                      
616 >                      do ia=groupStart(i), groupStart(i+1)-1
617 >                         atom1=groupList(ia)
618 >                         mf = mfact(atom1)
619 > #ifdef IS_MPI
620 >                         f_Row(1,atom1) = f_Row(1,atom1) + swderiv*d_grp(1)*mf
621 >                         f_Row(2,atom1) = f_Row(2,atom1) + swderiv*d_grp(2)*mf
622 >                         f_Row(3,atom1) = f_Row(3,atom1) + swderiv*d_grp(3)*mf
623 > #else
624 >                         f(1,atom1) = f(1,atom1) + swderiv*d_grp(1)*mf
625 >                         f(2,atom1) = f(2,atom1) + swderiv*d_grp(2)*mf
626 >                         f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
627 > #endif
628 >                      enddo
629 >                      
630 >                      do jb=groupStart(j), groupStart(j+1)-1
631 >                         atom2=groupList(jb)
632 >                         mf = mfact(atom2)
633 > #ifdef IS_MPI
634 >                         f_Col(1,atom2) = f_Col(1,atom2) - swderiv*d_grp(1)*mf
635 >                         f_Col(2,atom2) = f_Col(2,atom2) - swderiv*d_grp(2)*mf
636 >                         f_Col(3,atom2) = f_Col(3,atom2) - swderiv*d_grp(3)*mf
637 > #else
638 >                         f(1,atom2) = f(1,atom2) - swderiv*d_grp(1)*mf
639 >                         f(2,atom2) = f(2,atom2) - swderiv*d_grp(2)*mf
640 >                         f(3,atom2) = f(3,atom2) - swderiv*d_grp(3)*mf
641 > #endif
642 >                      enddo
643 >                   endif
644 >                  
645 >                   if (do_stress) call add_stress_tensor(d_grp, fij)
646                  endif
647 <                
648 <                list(nlist) = j
649 <                
804 <                if (SIM_uses_molecular_cutoffs) then
805 <                   call get_interatomic_vector(q(:,i), q(:,j), &
806 <                        d, rijsq)
807 <                else
808 <                   d(1:3) = dc(1:3)
809 <                   rijsq = rcijsq
810 <                endif
811 <                
812 <                call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, &
813 <                     do_pot, do_stress, u_l, A, f, t, pot)
814 <                
815 <             endif
816 <          enddo inner
817 <       enddo
647 >             end if
648 >          enddo
649 >       enddo outer
650        
651 <       point(natoms) = nlist + 1
652 <      
653 <    else !! (update)
654 <      
655 <       ! use the list to find the neighbors
656 <       do i = 1, natoms-1
657 <          JBEG = POINT(i)
658 <          JEND = POINT(i+1) - 1
659 <          ! check thiat molecule i has neighbors
660 <          if (jbeg .le. jend) then
661 <            
830 <             do jnab = jbeg, jend
831 <                j = list(jnab)
832 <
833 <
834 <                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
835 <                if (SIM_uses_molecular_cutoffs) then
836 <                   call get_interatomic_vector(qcom(:,i), qcom(:,j), &
837 <                        dc, rcijsq)
838 <                else
839 <                   dc(1:3) = d(1:3)
840 <                   rcijsq = rijsq
841 <                endif
842 <                
843 <                call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, &
844 <                     do_pot, do_stress, u_l, A, f, t, pot)
845 <                
846 <             enddo
651 >       if (update_nlist) then
652 > #ifdef IS_MPI
653 >          point(nrow_group + 1) = nlist + 1
654 > #else
655 >          point(nGroup) = nlist + 1
656 > #endif
657 >          if (loop .eq. PREPAIR_LOOP) then
658 >             ! we just did the neighbor list update on the first
659 >             ! pass, so we don't need to do it
660 >             ! again on the second pass
661 >             update_nlist = .false.                              
662            endif
663 <       enddo
664 <    endif
663 >       endif
664 >            
665 >       if (loop .eq. PREPAIR_LOOP) then
666 >          call do_preforce(nlocal, pot)
667 >       endif
668 >      
669 >    enddo
670      
851 #endif
852    
853    ! phew, done with main loop.
854    
671      !! Do timing
672   #ifdef PROFILE
673      call cpu_time(forceTimeFinal)
674      forceTime = forceTime + forceTimeFinal - forceTimeInitial
675 < #endif
675 > #endif    
676      
861    
677   #ifdef IS_MPI
678      !!distribute forces
679      
# Line 904 | Line 719 | contains
719         do i = 1, nlocal
720            pot_local = pot_local + pot_Temp(i)
721         enddo
722 <
722 >      
723      endif
724   #endif
725      
# Line 974 | Line 789 | contains
789      endif
790      
791   #endif
792 <    
978 <    
792 >      
793    end subroutine do_force_loop
794    
795 <  subroutine do_pair(i, j, rijsq, d, rcijsq, dc, mfact, do_pot, do_stress, &
796 <       u_l, A, f, t, pot)
795 >  subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
796 >       u_l, A, f, t, pot, vpair, fpair)
797  
798 <    real( kind = dp ) :: pot
798 >    real( kind = dp ) :: pot, vpair, sw
799 >    real( kind = dp ), dimension(3) :: fpair
800      real( kind = dp ), dimension(nLocal)   :: mfact
801      real( kind = dp ), dimension(3,nLocal) :: u_l
802      real( kind = dp ), dimension(9,nLocal) :: A
803      real( kind = dp ), dimension(3,nLocal) :: f
804      real( kind = dp ), dimension(3,nLocal) :: t
805  
806 <    logical, intent(inout) :: do_pot, do_stress
806 >    logical, intent(inout) :: do_pot
807      integer, intent(in) :: i, j
808 <    real ( kind = dp ), intent(inout) :: rijsq, rcijsq
809 <    real ( kind = dp )                :: r, rc
810 <    real ( kind = dp ), intent(inout) :: d(3), dc(3)
808 >    real ( kind = dp ), intent(inout) :: rijsq
809 >    real ( kind = dp )                :: r
810 >    real ( kind = dp ), intent(inout) :: d(3)
811      integer :: me_i, me_j
812  
813      r = sqrt(rijsq)
814 <    if (SIM_uses_molecular_cutoffs) then
815 <       rc = sqrt(rcijsq)
1001 <    else
1002 <       rc = r
1003 <    endif
814 >    vpair = 0.0d0
815 >    fpair(1:3) = 0.0d0
816  
1005
817   #ifdef IS_MPI
818      if (tagRow(i) .eq. tagColumn(j)) then
819         write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
# Line 1017 | Line 828 | contains
828      if (FF_uses_LJ .and. SIM_uses_LJ) then
829        
830         if ( PropertyMap(me_i)%is_LJ .and. PropertyMap(me_j)%is_LJ ) then
831 <          call do_lj_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
831 >          !write(*,*) 'calling lj with'
832 >          !write(*,*) i, j, r, rijsq
833 >          !write(*,'(3es12.3)') d(1), d(2), d(3)
834 >          !write(*,'(3es12.3)') sw, vpair, pot
835 >          !write(*,*)
836 >
837 >          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
838         endif
839        
840      endif
# Line 1025 | Line 842 | contains
842      if (FF_uses_charges .and. SIM_uses_charges) then
843        
844         if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then
845 <          call do_charge_pair(i, j, d, r, rijsq, dc, rc, rcijsq, mfact, &
1029 <               pot, f, do_pot, do_stress, SIM_uses_molecular_cutoffs)
845 >          call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
846         endif
847        
848      endif
# Line 1034 | Line 850 | contains
850      if (FF_uses_dipoles .and. SIM_uses_dipoles) then
851        
852         if ( PropertyMap(me_i)%is_DP .and. PropertyMap(me_j)%is_DP) then
853 <          call do_dipole_pair(i, j, d, r, rijsq, pot, u_l, f, t, &
854 <               do_pot, do_stress)
853 >          call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
854 >               do_pot)
855            if (FF_uses_RF .and. SIM_uses_RF) then
856 <             call accumulate_rf(i, j, r, u_l)
857 <             call rf_correct_forces(i, j, d, r, u_l, f, do_stress)
856 >             call accumulate_rf(i, j, r, u_l, sw)
857 >             call rf_correct_forces(i, j, d, r, u_l, sw, f, fpair)
858            endif          
859         endif
860  
# Line 1047 | Line 863 | contains
863      if (FF_uses_Sticky .and. SIM_uses_sticky) then
864  
865         if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
866 <          call do_sticky_pair(i, j, d, r, rijsq, A, pot, f, t, &
867 <               do_pot, do_stress)
866 >          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, A, f, t, &
867 >               do_pot)
868         endif
869  
870      endif
# Line 1057 | Line 873 | contains
873      if (FF_uses_GB .and. SIM_uses_GB) then
874        
875         if ( PropertyMap(me_i)%is_GB .and. PropertyMap(me_j)%is_GB) then
876 <          call do_gb_pair(i, j, d, r, rijsq, u_l, pot, f, t, &
877 <               do_pot, do_stress)          
876 >          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
877 >               do_pot)
878         endif
879  
880      endif
# Line 1066 | Line 882 | contains
882      if (FF_uses_EAM .and. SIM_uses_EAM) then
883        
884         if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
885 <          call do_eam_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
885 >          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
886 >               do_pot)
887         endif
888        
889      endif
890 <
890 >    
891    end subroutine do_pair
892  
893 <
1077 <
1078 <  subroutine do_prepair(i, j, rijsq, d, rcijsq, dc, &
893 >  subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
894         do_pot, do_stress, u_l, A, f, t, pot)
895 <   real( kind = dp ) :: pot
895 >
896 >   real( kind = dp ) :: pot, sw
897     real( kind = dp ), dimension(3,nLocal) :: u_l
898     real (kind=dp), dimension(9,nLocal) :: A
899     real (kind=dp), dimension(3,nLocal) :: f
# Line 1104 | Line 920 | contains
920  
921   #ifdef IS_MPI
922     if (tagRow(i) .eq. tagColumn(j)) then
923 <      write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
923 >      write(0,*) 'do_prepair is doing', i , j, tagRow(i), tagColumn(j)
924     endif
925    
926     me_i = atid_row(i)
# Line 1116 | Line 932 | contains
932     me_j = atid(j)
933    
934   #endif
935 <    
935 >  
936     if (FF_uses_EAM .and. SIM_uses_EAM) then
937 <
937 >      
938        if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
939             call calc_EAM_prepair_rho(i, j, d, r, rijsq )
940 <
940 >      
941     endif
942    
943   end subroutine do_prepair
944 <
945 <
1130 <
1131 <
944 >
945 >
946   subroutine do_preforce(nlocal,pot)
947     integer :: nlocal
948     real( kind = dp ) :: pot
# Line 1199 | Line 1013 | contains
1013     q_Row = 0.0_dp
1014     q_Col = 0.0_dp
1015  
1016 <   qcom_Row = 0.0_dp
1017 <   qcom_Col = 0.0_dp  
1016 >   q_group_Row = 0.0_dp
1017 >   q_group_Col = 0.0_dp  
1018    
1019     u_l_Row = 0.0_dp
1020     u_l_Col = 0.0_dp
# Line 1307 | Line 1121 | contains
1121        endif
1122     enddo
1123    
1124 <   do i = 1, nExcludes_local
1125 <      if (excludesLocal(1,i) == unique_id_1) then
1126 <         if (excludesLocal(2,i) == unique_id_2) then
1127 <            skip_it = .true.
1314 <            return
1315 <         endif
1316 <      else
1317 <         if (excludesLocal(1,i) == unique_id_2) then
1318 <            if (excludesLocal(2,i) == unique_id_1) then
1319 <               skip_it = .true.
1320 <               return
1321 <            endif
1322 <         endif
1124 >   do i = 1, nSkipsForAtom(unique_id_1)
1125 >      if (skipsForAtom(unique_id_1, i) .eq. unique_id_2) then
1126 >         skip_it = .true.
1127 >         return
1128        endif
1129     end do
1130    
# Line 1350 | Line 1155 | contains
1155   #endif
1156  
1157   !! This cleans componets of force arrays belonging only to fortran
1158 +
1159 + subroutine add_stress_tensor(dpair, fpair)
1160 +  
1161 +   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1162 +  
1163 +   ! because the d vector is the rj - ri vector, and
1164 +   ! because fx, fy, fz are the force on atom i, we need a
1165 +   ! negative sign here:  
1166 +  
1167 +   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1168 +   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1169 +   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1170 +   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1171 +   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1172 +   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1173 +   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1174 +   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1175 +   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1176 +  
1177 +   !write(*,'(6es12.3)')  fpair(1:3), tau_Temp(1), tau_Temp(5), tau_temp(9)
1178 +   virial_Temp = virial_Temp + &
1179 +        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1180 +  
1181 + end subroutine add_stress_tensor
1182  
1183   end module do_Forces
1184 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines