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 1160 by gezelter, Tue May 11 21:31:15 2004 UTC vs.
Revision 1199 by gezelter, Thu May 27 15:21:20 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.55 2004-05-11 21:31:14 gezelter Exp $, $Date: 2004-05-11 21:31:14 $, $Name: not supported by cvs2svn $, $Revision: 1.55 $
7 > !! @version $Id: do_Forces.F90,v 1.64 2004-05-27 15:21:20 gezelter Exp $, $Date: 2004-05-27 15:21:20 $, $Name: not supported by cvs2svn $, $Revision: 1.64 $
8  
9   module do_Forces
10    use force_globals
# Line 33 | Line 33 | module do_Forces
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 370 | Line 373 | contains
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,nGroup) :: q_group
378 >    real ( kind = dp ), dimension(3, nGroups) :: 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 394 | contains
394      logical :: in_switching_region
395   #ifdef IS_MPI
396      real( kind = DP ) :: pot_local
397 <    integer :: nrow
398 <    integer :: ncol
397 >    integer :: nAtomsInRow
398 >    integer :: nAtomsInCol
399      integer :: nprocs
400 <    integer :: nrow_group
401 <    integer :: ncol_group
400 >    integer :: nGroupsInRow
401 >    integer :: nGroupsInCol
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 ) :: ratmsq, rgrpsq, rgrp, vpair, vab
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
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 424 | contains
424      
425   #ifdef IS_MPI
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)
427 >    nAtomsInRow   = getNatomsInRow(plan_atom_row)
428 >    nAtomsInCol   = getNatomsInCol(plan_atom_col)
429 >    nGroupsInRow  = getNgroupsInRow(plan_group_row)
430 >    nGroupsInCol  = getNgroupsInCol(plan_group_col)
431   #else
432      natoms = nlocal
433   #endif
# Line 442 | 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)
450 >    call gather(q, q_Row, plan_atom_row_3d)
451 >    call gather(q, q_Col, plan_atom_col_3d)
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)
453 >    call gather(q_group, q_group_Row, plan_group_row_3d)
454 >    call gather(q_group, q_group_Col, plan_group_col_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)
457 >       call gather(u_l, u_l_Row, plan_atom_row_3d)
458 >       call gather(u_l, u_l_Col, plan_atom_col_3d)
459        
460 <       call gather(A,A_Row,plan_row_rotation)
461 <       call gather(A,A_Col,plan_col_rotation)
460 >       call gather(A, A_Row, plan_atom_row_rotation)
461 >       call gather(A, A_Col, plan_atom_col_rotation)
462      endif
463      
464   #endif
# Line 464 | 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 <
476 <       call checkNeighborList(nGroup, q_group, listSkin, update_nlist)
474 >       loopStart = PREPAIR_LOOP
475 >    else
476 >       loopStart = PAIR_LOOP
477 >    endif
478  
479 <       !! if_mpi_gather_stuff_for_prepair
480 <       !! do_prepair_loop_if_needed
481 <       !! if_mpi_scatter_stuff_from_prepair
482 <       !! if_mpi_gather_stuff_from_prepair_to_main_loop
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(nGroups, q_group, listSkin, update_nlist)
485 >       endif
486        
487 <       !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>>
487 >       if (update_nlist) then
488 >          !! save current configuration and construct neighbor list
489   #ifdef IS_MPI
490 +          call saveNeighborList(nGroupsInRow, q_group)
491 + #else
492 +          call saveNeighborList(nGroups, q_group)
493 + #endif        
494 +          neighborListSize = size(list)
495 +          nlist = 0
496 +       endif
497        
498 <       if (update_nlist) then
498 >       istart = 1
499 > #ifdef IS_MPI
500 >       iend = nGroupsInRow
501 > #else
502 >       iend = nGroups - 1
503 > #endif
504 >       outer: do i = istart, iend
505            
506 <          !! save current configuration, construct neighbor list,
483 <          !! and calculate forces
484 <
485 <          call saveNeighborList(nGroup, q_group)
506 >          if (update_nlist) point(i) = nlist + 1
507            
508 <          neighborListSize = size(list)
488 <          nlist = 0      
508 >          n_in_i = groupStartRow(i+1) - groupStartRow(i)
509            
510 <          do i = 1, nrow_group
511 <             point(i) = nlist + 1
512 <            
513 <             do j = 1, ncol_group
494 <                
495 <                call get_interatomic_vector(q_group_Row(:,i), &
496 <                     q_group_Col(:,j), d_grp, rgrpsq)
497 <                
498 <                if (rgrpsq < rlistsq) then
499 <                   nlist = nlist + 1
500 <                  
501 <                   if (nlist > neighborListSize) then
502 <                      call expandNeighborList(nGroup, listerror)
503 <                      if (listerror /= 0) then
504 <                         error = -1
505 <                         write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
506 <                         return
507 <                      end if
508 <                      neighborListSize = size(list)
509 <                   endif
510 <                  
511 <                   list(nlist) = j
512 <                  
513 <                   do ia = groupStart(i), groupStart(i+1)-1
514 <                      atom1 = groupList(ia)
515 <
516 <                      prepair_inner: do jb = groupStart(j), groupStart(j+1)-1
517 <                         atom2 = groupList(jb)
518 <                        
519 <                         if (skipThisPair(atom1, atom2)) cycle prepair_inner
520 <                        
521 <                         call get_interatomic_vector(q_Row(:,atom1), &
522 <                              q_Col(:,atom2), d_atm, ratmsq)
523 <                        
524 <                         call do_prepair(atom1, atom2, ratmsq, d_atm, &
525 <                              rgrpsq, d_grp, do_pot, do_stress, &
526 <                              u_l, A, f, t, pot_local)
527 <
528 <                      enddo prepair_inner
529 <                   enddo
530 <                end if
531 <             enddo
532 <          enddo
533 <          point(nrow_group + 1) = nlist + 1          
534 <                          
535 <       else  !! (of update_check)
536 <          
537 <          ! use the list to find the neighbors
538 <          do i = 1, nrow_group
539 <             JBEG = POINT(i)
540 <             JEND = POINT(i+1) - 1
541 <             ! check that group i has neighbors
542 <             if (jbeg .le. jend) then
543 <                
544 <                do jnab = jbeg, jend
545 <                   j = list(jnab)
546 <                  
547 <                   do ia = groupStart(i), groupStart(i+1)-1
548 <                      atom1 = groupList(ia)
549 <
550 <                      do jb = groupStart(j), groupStart(j+1)-1
551 <                         atom2 = groupList(jb)                        
552 <                        
553 <                         call get_interatomic_vector(q_Row(:,atom1), &
554 <                              q_Col(:,atom2), d_atm, ratmsq)
555 <                        
556 <                         call do_prepair(atom1, atom2, ratmsq, d_atm, &
557 <                              rgrpsq, d_grp, do_pot, do_stress, &
558 <                              u_l, A, f, t, pot_local)
559 <                        
560 <                      enddo
561 <                   enddo
562 <                enddo
563 <             endif
564 <          enddo
565 <       endif
566 <      
510 >          if (update_nlist) then
511 > #ifdef IS_MPI
512 >             jstart = 1
513 >             jend = nGroupsInCol
514   #else
515 <
516 <       if (update_nlist) then
515 >             jstart = i+1
516 >             jend = nGroups
517 > #endif
518 >          else            
519 >             jstart = point(i)
520 >             jend = point(i+1) - 1
521 >             ! make sure group i has neighbors
522 >             if (jstart .gt. jend) cycle outer
523 >          endif
524            
525 <          !! save current configuration, construct neighbor list,
526 <          !! and calculate forces
527 <          
528 <          call saveNeighborList(nGroup, q_group)
529 <          
530 <          neighborListSize = size(list)
531 <          nlist = 0      
532 <          
533 <          do i = 1, nGroup-1
534 <             point(i) = nlist + 1
535 <            
536 <             do j = i+1, nGroup
537 <                
538 <                call get_interatomic_vector(q_group(:,i), &
539 <                     q_group(:,j), d_grp, rgrpsq)
540 <                
541 <                if (rgrpsq < rlistsq) then
525 >          do jnab = jstart, jend
526 >             if (update_nlist) then
527 >                j = jnab
528 >             else
529 >                j = list(jnab)
530 >             endif
531 >
532 > #ifdef IS_MPI
533 >             call get_interatomic_vector(q_group_Row(:,i), &
534 >                  q_group_Col(:,j), d_grp, rgrpsq)
535 > #else
536 >             call get_interatomic_vector(q_group(:,i), &
537 >                  q_group(:,j), d_grp, rgrpsq)
538 > #endif
539 >
540 >             if (rgrpsq < rlistsq) then
541 >                if (update_nlist) then
542                     nlist = nlist + 1
543                    
544                     if (nlist > neighborListSize) then
545 <                      call expandNeighborList(nGroup, listerror)
545 > #ifdef IS_MPI                
546 >                      call expandNeighborList(nGroupsInRow, listerror)
547 > #else
548 >                      call expandNeighborList(nGroups, listerror)
549 > #endif
550                        if (listerror /= 0) then
551                           error = -1
552                           write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
# Line 598 | Line 556 | contains
556                     endif
557                    
558                     list(nlist) = j
559 <                  
602 <                   do ia = groupStart(i), groupStart(i+1)-1
603 <                      atom1 = groupList(ia)
604 <                      
605 <                      prepair_inner: do jb = groupStart(j), groupStart(j+1)-1
606 <                         atom2 = groupList(jb)
607 <                        
608 <                         if (skipThisPair(atom1, atom2)) cycle prepair_inner
609 <                        
610 <                         call get_interatomic_vector(q(:,atom1), &
611 <                              q(:,atom2), d_atm, ratmsq)
612 <                        
613 <                         call do_prepair(atom1, atom2, ratmsq, d_atm, &
614 <                              rgrpsq, d_grp, do_pot, do_stress, &
615 <                              u_l, A, f, t, pot)
616 <                        
617 <                      enddo prepair_inner
618 <                   enddo
619 <                end if
620 <             enddo
621 <          enddo
622 <          point(nGroup) = nlist + 1          
623 <                          
624 <       else  !! (of update_check)
625 <          
626 <          ! use the list to find the neighbors
627 <          do i = 1, nGroup-1
628 <             JBEG = POINT(i)
629 <             JEND = POINT(i+1) - 1
630 <             ! check that group i has neighbors
631 <             if (jbeg .le. jend) then
559 >                endif
560                  
561 <                do jnab = jbeg, jend
562 <                   j = list(jnab)
563 <                  
636 <                   do ia = groupStart(i), groupStart(i+1)-1
637 <                      atom1 = groupList(ia)
638 <
639 <                      do jb = groupStart(j), groupStart(j+1)-1
640 <                         atom2 = groupList(jb)                        
641 <                        
642 <                         call get_interatomic_vector(q(:,atom1), &
643 <                              q(:,atom2), d_atm, ratmsq)
644 <                        
645 <                         call do_prepair(atom1, atom2, ratmsq, d_atm, &
646 <                              rgrpsq, d_grp, do_pot, do_stress, &
647 <                              u_l, A, f, t, pot)
648 <                        
649 <                      enddo
650 <                   enddo
651 <                enddo
652 <             endif
653 <          enddo
654 <       endif
655 <      
656 < #endif
657 <      
658 <       !! Do rest of preforce calculations
659 <       !! do necessary preforce calculations  
660 <       call do_preforce(nlocal,pot)
661 <       ! we have already updated the neighbor list set it to false...
662 <       update_nlist = .false.
663 <    else
664 <       !! See if we need to update neighbor lists for non pre-pair
665 <       call checkNeighborList(nGroup, q_group, listSkin, update_nlist)  
666 <    endif
667 <    
668 <    !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>
669 <    
670 < #ifdef IS_MPI
671 <    
672 <    if (update_nlist) then
673 <      
674 <       !! save current configuration, construct neighbor list,
675 <       !! and calculate forces
676 <      
677 <       call saveNeighborList(nGroup, q_group)
678 <      
679 <       neighborListSize = size(list)
680 <       nlist = 0      
681 <      
682 <       do i = 1, nrow_group
683 <          point(i) = nlist + 1
684 <          
685 <          do j = 1, ncol_group
686 <            
687 <             call get_interatomic_vector(q_group_Row(:,i), &
688 <                  q_group_Col(:,j), d_grp, rgrpsq)
689 <            
690 <             if (rgrpsq < rlistsq) then
691 <                nlist = nlist + 1
692 <                
693 <                if (nlist > neighborListSize) then
694 <                   call expandNeighborList(nGroup, listerror)
695 <                   if (listerror /= 0) then
696 <                      error = -1
697 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
698 <                      return
699 <                   end if
700 <                   neighborListSize = size(list)
561 >                if (loop .eq. PAIR_LOOP) then
562 >                   vij = 0.0d0
563 >                   fij(1:3) = 0.0d0
564                  endif
565                  
703                list(nlist) = j
704                
705                vab = 0.0d0
566                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
567                       in_switching_region)
568                  
569 <                do ia = groupStart(i), groupStart(i+1)-1
570 <                   atom1 = groupList(ia)
569 >                n_in_j = groupStartCol(j+1) - groupStartCol(j)
570 >                
571 >                do ia = groupStartRow(i), groupStartRow(i+1)-1
572                    
573 <                   inner: do jb = groupStart(j), groupStart(j+1)-1
574 <                      atom2 = groupList(jb)
573 >                   atom1 = groupListRow(ia)
574 >                  
575 >                   inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
576                        
577 +                      atom2 = groupListCol(jb)
578 +                      
579                        if (skipThisPair(atom1, atom2)) cycle inner
580                        
581 <                      call get_interatomic_vector(q_Row(:,atom1), &
582 <                           q_Col(:,atom2), d_atm, ratmsq)
583 <                      
584 <                      call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
585 <                           do_pot, do_stress, &
586 <                           u_l, A, f, t, pot_local, vpair)
587 <                      
588 <                      vab = vab + vpair
581 >                      if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
582 >                         d_atm(1:3) = d_grp(1:3)
583 >                         ratmsq = rgrpsq
584 >                      else
585 > #ifdef IS_MPI
586 >                         call get_interatomic_vector(q_Row(:,atom1), &
587 >                              q_Col(:,atom2), d_atm, ratmsq)
588 > #else
589 >                         call get_interatomic_vector(q(:,atom1), &
590 >                              q(:,atom2), d_atm, ratmsq)
591 > #endif
592 >                      endif
593 >                      if (loop .eq. PREPAIR_LOOP) then
594 > #ifdef IS_MPI                      
595 >                         call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
596 >                              rgrpsq, d_grp, do_pot, do_stress, &
597 >                              u_l, A, f, t, pot_local)
598 > #else
599 >                         call do_prepair(atom1, atom2, ratmsq, d_atm, sw, &
600 >                              rgrpsq, d_grp, do_pot, do_stress, &
601 >                              u_l, A, f, t, pot)
602 > #endif                                              
603 >                      else
604 > #ifdef IS_MPI                      
605 >                         call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
606 >                              do_pot, &
607 >                              u_l, A, f, t, pot_local, vpair, fpair)
608 > #else
609 >                         call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
610 >                              do_pot,  &
611 >                              u_l, A, f, t, pot, vpair, fpair)
612 > #endif
613 >                         vij = vij + vpair
614 >                         fij(1:3) = fij(1:3) + fpair(1:3)
615 >                      endif
616                     enddo inner
617                  enddo
618 <
619 <                if (in_switching_region) then
620 <                   swderiv = vab*dswdr/rgrp
621 <                  
622 <                   do ia=groupStart(i), groupStart(i+1)-1
623 <                      atom1=groupList(ia)
624 <                      mf = mfact(atom1)                  
625 <                      f_Row(1,atom1) = f_Row(1,atom1) - swderiv*d_grp(1)*mf
626 <                      f_Row(2,atom1) = f_Row(2,atom1) - swderiv*d_grp(2)*mf
627 <                      f_Row(3,atom1) = f_Row(3,atom1) - swderiv*d_grp(3)*mf
628 <                   enddo
629 <                  
630 <                   do jb=groupStart(j), groupStart(j+1)-1
631 <                      atom2=groupList(jb)
632 <                      mf = mfact(atom2)
633 <                      f_Col(1,atom2) = f_Col(1,atom2) + swderiv*d_grp(1)*mf
634 <                      f_Col(2,atom2) = f_Col(2,atom2) + swderiv*d_grp(2)*mf
635 <                      f_Col(3,atom2) = f_Col(3,atom2) + swderiv*d_grp(3)*mf
636 <                   enddo                        
637 <                endif
638 <
748 <             end if
749 <          enddo
750 <       enddo
751 <       point(nrow_group + 1) = nlist + 1          
752 <      
753 <    else  !! (of update_check)
754 <      
755 <       ! use the list to find the neighbors
756 <       do i = 1, nrow_group
757 <          JBEG = POINT(i)
758 <          JEND = POINT(i+1) - 1
759 <          ! check that group i has neighbors
760 <          if (jbeg .le. jend) then
761 <            
762 <             do jnab = jbeg, jend
763 <                j = list(jnab)
764 <                              
765 <                call get_interatomic_vector(q_group_Row(:,i), &
766 <                     q_group_Col(:,j), d_grp, rgrpsq)
767 <                
768 <                vab = 0.0d0
769 <                call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
770 <                     in_switching_region)
771 <                
772 <                do ia = groupStart(i), groupStart(i+1)-1
773 <                   atom1 = groupList(ia)
774 <                  
775 <                   do jb = groupStart(j), groupStart(j+1)-1
776 <                      atom2 = groupList(jb)                        
618 >                
619 >                if (loop .eq. PAIR_LOOP) then
620 >                   if (in_switching_region) then
621 >                      swderiv = vij*dswdr/rgrp
622 >                      fij(1) = fij(1) + swderiv*d_grp(1)
623 >                      fij(2) = fij(2) + swderiv*d_grp(2)
624 >                      fij(3) = fij(3) + swderiv*d_grp(3)
625 >                      
626 >                      do ia=groupStartRow(i), groupStartRow(i+1)-1
627 >                         atom1=groupListRow(ia)
628 >                         mf = mfactRow(atom1)
629 > #ifdef IS_MPI
630 >                         f_Row(1,atom1) = f_Row(1,atom1) + swderiv*d_grp(1)*mf
631 >                         f_Row(2,atom1) = f_Row(2,atom1) + swderiv*d_grp(2)*mf
632 >                         f_Row(3,atom1) = f_Row(3,atom1) + swderiv*d_grp(3)*mf
633 > #else
634 >                         f(1,atom1) = f(1,atom1) + swderiv*d_grp(1)*mf
635 >                         f(2,atom1) = f(2,atom1) + swderiv*d_grp(2)*mf
636 >                         f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
637 > #endif
638 >                      enddo
639                        
640 <                      call get_interatomic_vector(q_Row(:,atom1), &
641 <                           q_Col(:,atom2), d_atm, ratmsq)
642 <                                            
643 <                      call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
644 <                           do_pot, do_stress, &
645 <                           u_l, A, f, t, pot_local, vpair)
646 <                      
785 <                      vab = vab + vpair
786 <                                            
787 <                   enddo
788 <                enddo
789 <                
790 <                if (in_switching_region) then
791 <                   swderiv = vab*dswdr/rgrp
792 <  
793 <                   do ia=groupStart(i), groupStart(i+1)-1
794 <                      atom1=groupList(ia)
795 <                      mf = mfact(atom1)                  
796 <                      f_Row(1,atom1) = f_Row(1,atom1) - swderiv*d_grp(1)*mf
797 <                      f_Row(2,atom1) = f_Row(2,atom1) - swderiv*d_grp(2)*mf
798 <                      f_Row(3,atom1) = f_Row(3,atom1) - swderiv*d_grp(3)*mf
799 <                   enddo
800 <                  
801 <                   do jb=groupStart(j), groupStart(j+1)-1
802 <                      atom2=groupList(jb)
803 <                      mf = mfact(atom2)
804 <                      f_Col(1,atom2) = f_Col(1,atom2) + swderiv*d_grp(1)*mf
805 <                      f_Col(2,atom2) = f_Col(2,atom2) + swderiv*d_grp(2)*mf
806 <                      f_Col(3,atom2) = f_Col(3,atom2) + swderiv*d_grp(3)*mf
807 <                   enddo
808 <                endif
809 <
810 <             enddo
811 <          endif
812 <       enddo
813 <    endif
814 <    
640 >                      do jb=groupStartCol(j), groupStartCol(j+1)-1
641 >                         atom2=groupListCol(jb)
642 >                         mf = mfactCol(atom2)
643 > #ifdef IS_MPI
644 >                         f_Col(1,atom2) = f_Col(1,atom2) - swderiv*d_grp(1)*mf
645 >                         f_Col(2,atom2) = f_Col(2,atom2) - swderiv*d_grp(2)*mf
646 >                         f_Col(3,atom2) = f_Col(3,atom2) - swderiv*d_grp(3)*mf
647   #else
648 <
649 <    if (update_nlist) then
650 <      
651 <       !! save current configuration, construct neighbor list,
652 <       !! and calculate forces
653 <      
822 <       call saveNeighborList(nGroup, q_group)
823 <      
824 <       neighborListSize = size(list)
825 <       nlist = 0      
826 <      
827 <       do i = 1, nGroup-1
828 <          point(i) = nlist + 1
829 <          
830 <          do j = i+1, nGroup
831 <            
832 <             call get_interatomic_vector(q_group(:,i), &
833 <                  q_group(:,j), d_grp, rgrpsq)
834 <            
835 <             if (rgrpsq < rlistsq) then
836 <                nlist = nlist + 1
837 <                
838 <                if (nlist > neighborListSize) then
839 <                   call expandNeighborList(nGroup, listerror)
840 <                   if (listerror /= 0) then
841 <                      error = -1
842 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
843 <                      return
844 <                   end if
845 <                   neighborListSize = size(list)
846 <                endif
847 <                
848 <                list(nlist) = j
849 <
850 <                vab = 0.0d0
851 <                call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
852 <                     in_switching_region)
853 <                
854 <                do ia = groupStart(i), groupStart(i+1)-1
855 <                   atom1 = groupList(ia)
648 >                         f(1,atom2) = f(1,atom2) - swderiv*d_grp(1)*mf
649 >                         f(2,atom2) = f(2,atom2) - swderiv*d_grp(2)*mf
650 >                         f(3,atom2) = f(3,atom2) - swderiv*d_grp(3)*mf
651 > #endif
652 >                      enddo
653 >                   endif
654                    
655 <                   inner: do jb = groupStart(j), groupStart(j+1)-1
858 <                      atom2 = groupList(jb)
859 <                      
860 <                      if (skipThisPair(atom1, atom2)) cycle inner
861 <                      
862 <                      call get_interatomic_vector(q(:,atom1), &
863 <                           q(:,atom2), d_atm, ratmsq)
864 <                      
865 <                      call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
866 <                           do_pot, do_stress, &
867 <                           u_l, A, f, t, pot, vpair)
868 <                      
869 <                      vab = vab + vpair
870 <                      
871 <                   enddo inner
872 <                enddo
873 <
874 <                if (in_switching_region) then
875 <                   swderiv = vab*dswdr/rgrp
876 <                   do ia=groupStart(i), groupStart(i+1)-1
877 <                      atom1=groupList(ia)
878 <                      mf = mfact(atom1)                  
879 <                      f(1,atom1) = f(1,atom1) - swderiv*d_grp(1)*mf
880 <                      f(2,atom1) = f(2,atom1) - swderiv*d_grp(2)*mf
881 <                      f(3,atom1) = f(3,atom1) - swderiv*d_grp(3)*mf
882 <                   enddo
883 <                  
884 <                   do jb=groupStart(j), groupStart(j+1)-1
885 <                      atom2=groupList(jb)
886 <                      mf = mfact(atom2)
887 <                      f(1,atom2) = f(1,atom2) + swderiv*d_grp(1)*mf
888 <                      f(2,atom2) = f(2,atom2) + swderiv*d_grp(2)*mf
889 <                      f(3,atom2) = f(3,atom2) + swderiv*d_grp(3)*mf
890 <                   enddo
655 >                   if (do_stress) call add_stress_tensor(d_grp, fij)
656                  endif
892
657               end if
658            enddo
659 <       enddo
896 <       point(nGroup) = nlist + 1          
659 >       enddo outer
660        
661 <    else  !! (of update_check)
662 <      
663 <       ! use the list to find the neighbors
664 <       do i = 1, nGroup-1
665 <          JBEG = POINT(i)
666 <          JEND = POINT(i+1) - 1
667 <          ! check that group i has neighbors
668 <          if (jbeg .le. jend) then
661 >       if (update_nlist) then
662 > #ifdef IS_MPI
663 >          point(nGroupsInRow + 1) = nlist + 1
664 > #else
665 >          point(nGroups) = nlist + 1
666 > #endif
667 >          if (loop .eq. PREPAIR_LOOP) then
668 >             ! we just did the neighbor list update on the first
669 >             ! pass, so we don't need to do it
670 >             ! again on the second pass
671 >             update_nlist = .false.                              
672 >          endif
673 >       endif
674              
675 <             do jnab = jbeg, jend
676 <                j = list(jnab)
677 <
678 <                call get_interatomic_vector(q_group(:,i), &
679 <                     q_group(:,j), d_grp, rgrpsq)
912 <
913 <                vab = 0.0d0                    
914 <                call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
915 <                     in_switching_region)
916 <                                
917 <                do ia = groupStart(i), groupStart(i+1)-1
918 <                   atom1 = groupList(ia)
919 <                  
920 <                   do jb = groupStart(j), groupStart(j+1)-1
921 <                      atom2 = groupList(jb)                        
922 <                      
923 <                      call get_interatomic_vector(q(:,atom1), &
924 <                           q(:,atom2), d_atm, ratmsq)
925 <                      
926 <                      call do_pair(atom1, atom2, ratmsq, d_atm, sw, &
927 <                           do_pot, do_stress, &
928 <                           u_l, A, f, t, pot, vpair)
929 <                      
930 <                      vab = vab + vpair
931 <                      
932 <                   enddo
933 <                enddo
934 <                
935 <                if (in_switching_region) then
936 <                   swderiv = vab*dswdr/rgrp
937 <                  
938 <                   do ia=groupStart(i), groupStart(i+1)-1
939 <                      atom1=groupList(ia)
940 <                      mf = mfact(atom1)                  
941 <                      f(1,atom1) = f(1,atom1) - swderiv*d_grp(1)*mf
942 <                      f(2,atom1) = f(2,atom1) - swderiv*d_grp(2)*mf
943 <                      f(3,atom1) = f(3,atom1) - swderiv*d_grp(3)*mf
944 <                   enddo
945 <                  
946 <                   do jb=groupStart(j), groupStart(j+1)-1
947 <                      atom2=groupList(jb)
948 <                      mf = mfact(atom2)
949 <                      f(1,atom2) = f(1,atom2) + swderiv*d_grp(1)*mf
950 <                      f(2,atom2) = f(2,atom2) + swderiv*d_grp(2)*mf
951 <                      f(3,atom2) = f(3,atom2) + swderiv*d_grp(3)*mf
952 <                   enddo
953 <                endif
954 <             enddo
955 <          endif
956 <       enddo
957 <    endif
958 <        
959 < #endif
675 >       if (loop .eq. PREPAIR_LOOP) then
676 >          call do_preforce(nlocal, pot)
677 >       endif
678 >      
679 >    enddo
680      
961    ! phew, done with main loop.
962    
681      !! Do timing
682   #ifdef PROFILE
683      call cpu_time(forceTimeFinal)
# Line 970 | Line 688 | contains
688      !!distribute forces
689      
690      f_temp = 0.0_dp
691 <    call scatter(f_Row,f_temp,plan_row3d)
691 >    call scatter(f_Row,f_temp,plan_atom_row_3d)
692      do i = 1,nlocal
693         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
694      end do
695      
696      f_temp = 0.0_dp
697 <    call scatter(f_Col,f_temp,plan_col3d)
697 >    call scatter(f_Col,f_temp,plan_atom_col_3d)
698      do i = 1,nlocal
699         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
700      end do
701      
702      if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then
703         t_temp = 0.0_dp
704 <       call scatter(t_Row,t_temp,plan_row3d)
704 >       call scatter(t_Row,t_temp,plan_atom_row_3d)
705         do i = 1,nlocal
706            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
707         end do
708         t_temp = 0.0_dp
709 <       call scatter(t_Col,t_temp,plan_col3d)
709 >       call scatter(t_Col,t_temp,plan_atom_col_3d)
710        
711         do i = 1,nlocal
712            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
# Line 997 | Line 715 | contains
715      
716      if (do_pot) then
717         ! scatter/gather pot_row into the members of my column
718 <       call scatter(pot_Row, pot_Temp, plan_row)
718 >       call scatter(pot_Row, pot_Temp, plan_atom_row)
719        
720         ! scatter/gather pot_local into all other procs
721         ! add resultant to get total pot
# Line 1007 | Line 725 | contains
725        
726         pot_Temp = 0.0_DP
727        
728 <       call scatter(pot_Col, pot_Temp, plan_col)
728 >       call scatter(pot_Col, pot_Temp, plan_atom_col)
729         do i = 1, nlocal
730            pot_local = pot_local + pot_Temp(i)
731         enddo
# Line 1020 | Line 738 | contains
738         if (FF_uses_RF .and. SIM_uses_RF) then
739            
740   #ifdef IS_MPI
741 <          call scatter(rf_Row,rf,plan_row3d)
742 <          call scatter(rf_Col,rf_Temp,plan_col3d)
741 >          call scatter(rf_Row,rf,plan_atom_row_3d)
742 >          call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
743            do i = 1,nlocal
744               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
745            end do
# Line 1081 | Line 799 | contains
799      endif
800      
801   #endif
802 <    
1085 <    
802 >      
803    end subroutine do_force_loop
1087
804    
805 <  subroutine do_pair(i, j, rijsq, d, sw, do_pot, do_stress, &
806 <       u_l, A, f, t, pot, vpair)
805 >  subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
806 >       u_l, A, f, t, pot, vpair, fpair)
807  
808      real( kind = dp ) :: pot, vpair, sw
809 +    real( kind = dp ), dimension(3) :: fpair
810      real( kind = dp ), dimension(nLocal)   :: mfact
811      real( kind = dp ), dimension(3,nLocal) :: u_l
812      real( kind = dp ), dimension(9,nLocal) :: A
813      real( kind = dp ), dimension(3,nLocal) :: f
814      real( kind = dp ), dimension(3,nLocal) :: t
815  
816 <    logical, intent(inout) :: do_pot, do_stress
816 >    logical, intent(inout) :: do_pot
817      integer, intent(in) :: i, j
818      real ( kind = dp ), intent(inout) :: rijsq
819      real ( kind = dp )                :: r
# Line 1104 | Line 821 | contains
821      integer :: me_i, me_j
822  
823      r = sqrt(rijsq)
824 +    vpair = 0.0d0
825 +    fpair(1:3) = 0.0d0
826  
827   #ifdef IS_MPI
828 <    if (tagRow(i) .eq. tagColumn(j)) then
829 <       write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
828 >    if (AtomRowToGlobal(i) .eq. AtomColToGlobal(j)) then
829 >       write(0,*) 'do_pair is doing', i , j, AtomRowToGlobal(i), AtomColToGlobal(j)
830      endif
831      me_i = atid_row(i)
832      me_j = atid_col(j)
# Line 1119 | Line 838 | contains
838      if (FF_uses_LJ .and. SIM_uses_LJ) then
839        
840         if ( PropertyMap(me_i)%is_LJ .and. PropertyMap(me_j)%is_LJ ) then
841 <          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, &
842 <               do_stress)
841 >          !write(*,*) 'calling lj with'
842 >          !write(*,*) i, j, r, rijsq
843 >          !write(*,'(3es12.3)') d(1), d(2), d(3)
844 >          !write(*,'(3es12.3)') sw, vpair, pot
845 >          !write(*,*)
846 >
847 >          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
848         endif
849        
850      endif
# Line 1128 | Line 852 | contains
852      if (FF_uses_charges .and. SIM_uses_charges) then
853        
854         if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then
855 <          call do_charge_pair(i, j, d, r, rijsq, sw, vpair, pot, f, do_pot, &
1132 <               do_stress)
855 >          call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
856         endif
857        
858      endif
# Line 1137 | Line 860 | contains
860      if (FF_uses_dipoles .and. SIM_uses_dipoles) then
861        
862         if ( PropertyMap(me_i)%is_DP .and. PropertyMap(me_j)%is_DP) then
863 <          call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, &
864 <               do_pot, do_stress)
863 >          call do_dipole_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
864 >               do_pot)
865            if (FF_uses_RF .and. SIM_uses_RF) then
866               call accumulate_rf(i, j, r, u_l, sw)
867 <             call rf_correct_forces(i, j, d, r, u_l, sw, f, do_stress)
867 >             call rf_correct_forces(i, j, d, r, u_l, sw, f, fpair)
868            endif          
869         endif
870  
# Line 1150 | Line 873 | contains
873      if (FF_uses_Sticky .and. SIM_uses_sticky) then
874  
875         if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
876 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, pot, A, f, t, &
877 <               do_pot, do_stress)
876 >          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, A, f, t, &
877 >               do_pot)
878         endif
879  
880      endif
# Line 1160 | Line 883 | contains
883      if (FF_uses_GB .and. SIM_uses_GB) then
884        
885         if ( PropertyMap(me_i)%is_GB .and. PropertyMap(me_j)%is_GB) then
886 <          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, pot, u_l, f, t, &
887 <               do_pot, do_stress)          
886 >          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, u_l, f, t, &
887 >               do_pot)
888         endif
889  
890      endif
# Line 1169 | Line 892 | contains
892      if (FF_uses_EAM .and. SIM_uses_EAM) then
893        
894         if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
895 <          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, pot, f, &
896 <               do_pot, do_stress)
895 >          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
896 >               do_pot)
897         endif
898        
899      endif
900      
901    end subroutine do_pair
902  
903 <  subroutine do_prepair(i, j, rijsq, d, rcijsq, dc, &
903 >  subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
904         do_pot, do_stress, u_l, A, f, t, pot)
905 <   real( kind = dp ) :: pot
905 >
906 >   real( kind = dp ) :: pot, sw
907     real( kind = dp ), dimension(3,nLocal) :: u_l
908     real (kind=dp), dimension(9,nLocal) :: A
909     real (kind=dp), dimension(3,nLocal) :: f
# Line 1205 | Line 929 | contains
929    
930  
931   #ifdef IS_MPI
932 <   if (tagRow(i) .eq. tagColumn(j)) then
933 <      write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
932 >   if (AtomRowToGlobal(i) .eq. AtomColToGlobal(j)) then
933 >      write(0,*) 'do_prepair is doing', i , j, AtomRowToGlobal(i), AtomColToGlobal(j)
934     endif
935    
936     me_i = atid_row(i)
# Line 1218 | Line 942 | contains
942     me_j = atid(j)
943    
944   #endif
945 <    
945 >  
946     if (FF_uses_EAM .and. SIM_uses_EAM) then
947 <
947 >      
948        if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
949             call calc_EAM_prepair_rho(i, j, d, r, rijsq )
950 <
950 >      
951     endif
952    
953   end subroutine do_prepair
954 <
955 <
1232 <
1233 <
954 >
955 >
956   subroutine do_preforce(nlocal,pot)
957     integer :: nlocal
958     real( kind = dp ) :: pot
# Line 1355 | Line 1077 | contains
1077    
1078   #ifdef IS_MPI
1079     !! in MPI, we have to look up the unique IDs for each atom
1080 <   unique_id_1 = tagRow(atom1)
1080 >   unique_id_1 = AtomRowToGlobal(atom1)
1081   #else
1082     !! in the normal loop, the atom numbers are unique
1083     unique_id_1 = atom1
# Line 1374 | Line 1096 | contains
1096     end if
1097    
1098   #ifdef IS_MPI
1099 <   unique_id_2 = tagColumn(atom2)
1099 >   unique_id_2 = AtomColToGlobal(atom2)
1100   #else
1101     unique_id_2 = atom2
1102   #endif
# Line 1409 | Line 1131 | contains
1131        endif
1132     enddo
1133    
1134 <   do i = 1, nExcludes_local
1135 <      if (excludesLocal(1,i) == unique_id_1) then
1136 <         if (excludesLocal(2,i) == unique_id_2) then
1137 <            skip_it = .true.
1416 <            return
1417 <         endif
1418 <      else
1419 <         if (excludesLocal(1,i) == unique_id_2) then
1420 <            if (excludesLocal(2,i) == unique_id_1) then
1421 <               skip_it = .true.
1422 <               return
1423 <            endif
1424 <         endif
1134 >   do i = 1, nSkipsForAtom(unique_id_1)
1135 >      if (skipsForAtom(unique_id_1, i) .eq. unique_id_2) then
1136 >         skip_it = .true.
1137 >         return
1138        endif
1139     end do
1140    
# Line 1452 | Line 1165 | contains
1165   #endif
1166  
1167   !! This cleans componets of force arrays belonging only to fortran
1168 +
1169 + subroutine add_stress_tensor(dpair, fpair)
1170 +  
1171 +   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1172 +  
1173 +   ! because the d vector is the rj - ri vector, and
1174 +   ! because fx, fy, fz are the force on atom i, we need a
1175 +   ! negative sign here:  
1176 +  
1177 +   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1178 +   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1179 +   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1180 +   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1181 +   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1182 +   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1183 +   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1184 +   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1185 +   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1186 +  
1187 +   !write(*,'(6es12.3)')  fpair(1:3), tau_Temp(1), tau_Temp(5), tau_temp(9)
1188 +   virial_Temp = virial_Temp + &
1189 +        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1190 +  
1191 + end subroutine add_stress_tensor
1192  
1193   end module do_Forces
1194 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines