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 1113 by tim, Thu Apr 15 16:18:26 2004 UTC vs.
Revision 1144 by tim, Sat May 1 18:52:38 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.49 2004-04-15 16:18:26 tim Exp $, $Date: 2004-04-15 16:18:26 $, $Name: not supported by cvs2svn $, $Revision: 1.49 $
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 $
8  
9   module do_Forces
10    use force_globals
# Line 55 | Line 55 | module do_Forces
55    logical, save :: SIM_requires_prepair_calc
56    logical, save :: SIM_uses_directional_atoms
57    logical, save :: SIM_uses_PBC
58 +  logical, save :: SIM_uses_molecular_cutoffs
59  
60    real(kind=dp), save :: rlist, rlistsq
61  
# Line 160 | Line 161 | contains
161      SIM_requires_prepair_calc = SimRequiresPrepairCalc()
162      SIM_uses_directional_atoms = SimUsesDirectionalAtoms()
163      SIM_uses_PBC = SimUsesPBC()
164 +    !SIM_uses_molecular_cutoffs = SimUsesMolecularCutoffs()
165  
166      haveSIMvariables = .true.
167  
# Line 277 | Line 279 | contains
279      
280      !! Assume sanity (for the sake of argument)
281      haveSaneForceField = .true.
282 +    !!
283 +    if (FF_uses_charges) then
284 +      dielect = getDielect()
285 +      call initialize_charge(dielect)
286 +    endif
287  
288 +
289      !! check to make sure the FF_uses_RF setting makes sense
290      
291      if (FF_uses_dipoles) then
# Line 362 | Line 370 | contains
370  
371    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
372    !------------------------------------------------------------->
373 <  subroutine do_force_loop(q, A, u_l, f, t, tau, pot, do_pot_c, do_stress_c, &
374 <       error)
373 >  subroutine do_force_loop(q, qcom, 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
377 +    !! molecular center-of-mass position array
378 +    real ( kind = dp ), dimension(3,nLocal) :: qcom
379      !! Rotation Matrix for each long range particle in simulation.
380      real( kind = dp), dimension(9,nLocal) :: A    
381      !! Unit vectors for dipoles (lab frame)
# Line 391 | Line 401 | contains
401      logical :: update_nlist  
402      integer :: i, j, jbeg, jend, jnab
403      integer :: nlist
404 <    real( kind = DP ) ::  rijsq
405 <    real(kind=dp),dimension(3) :: d
404 >    real( kind = DP ) ::  rijsq, rcijsq
405 >    real(kind=dp),dimension(3) :: d, dc
406      real(kind=dp) :: rfpot, mu_i, virial
407      integer :: me_i, me_j
408      logical :: is_dp_i
# Line 402 | Line 412 | contains
412      integer :: propPack_i, propPack_j
413  
414      real(kind=dp) :: listSkin = 1.0  
415 <
415 >    
416      !! initialize local variables  
417 <
417 >    
418   #ifdef IS_MPI
419      pot_local = 0.0_dp
420      nrow   = getNrow(plan_row)
# Line 412 | Line 422 | contains
422   #else
423      natoms = nlocal
424   #endif
425 <
425 >    
426      call doReadyCheck(localError)
427      if ( localError .ne. 0 ) then
428         call handleError("do_force_loop", "Not Initialized")
# Line 420 | Line 430 | contains
430         return
431      end if
432      call zero_work_arrays()
433 <
433 >        
434      do_pot = do_pot_c
435      do_stress = do_stress_c
436 <
436 >    
437      ! Gather all information needed by all force loops:
438      
439   #ifdef IS_MPI    
440 <
440 >    
441      call gather(q,q_Row,plan_row3d)
442      call gather(q,q_Col,plan_col3d)
443 <        
443 >    
444 >    if (SIM_uses_molecular_cutoffs) then
445 >       call gather(qcom,qcom_Row,plan_row3d)
446 >       call gather(qcom,qcom_Col,plan_col3d)
447 >    endif
448 >    
449      if (FF_UsesDirectionalAtoms() .and. SIM_uses_directional_atoms) then
450         call gather(u_l,u_l_Row,plan_row3d)
451         call gather(u_l,u_l_Col,plan_col3d)
# Line 440 | Line 455 | contains
455      endif
456      
457   #endif
458 <
459 < !! Begin force loop timing:
458 >    
459 >    !! Begin force loop timing:
460   #ifdef PROFILE
461      call cpu_time(forceTimeInitial)
462      nloops = nloops + 1
463   #endif
464 <  
464 >    
465      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
466         !! See if we need to update neighbor lists
467 <       call checkNeighborList(nlocal, q, listSkin, update_nlist)  
467 >       if (SIM_uses_molecular_cutoffs) then
468 >          call checkNeighborList(nlocal, qcom, listSkin, update_nlist)
469 >       else
470 >          call checkNeighborList(nlocal, q, listSkin, update_nlist)  
471 >       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
476 <    
477 < !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>>
476 >      
477 >       !--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>>
478   #ifdef IS_MPI
460    
461    if (update_nlist) then
479        
480 <       !! save current configuration, construct neighbor list,
464 <       !! and calculate forces
465 <       call saveNeighborList(nlocal, q)
466 <      
467 <       neighborListSize = size(list)
468 <       nlist = 0      
469 <      
470 <       do i = 1, nrow
471 <          point(i) = nlist + 1
480 >       if (update_nlist) then
481            
482 <          prepair_inner: do j = 1, ncol
482 >          !! 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 >          
490 >          neighborListSize = size(list)
491 >          nlist = 0      
492 >          
493 >          do i = 1, nrow
494 >             point(i) = nlist + 1
495              
496 <             if (skipThisPair(i,j)) cycle prepair_inner
476 <            
477 <             call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
478 <            
479 <             if (rijsq < rlistsq) then            
496 >             prepair_inner: do j = 1, ncol
497                  
498 <                nlist = nlist + 1
498 >                if (skipThisPair(i,j)) cycle prepair_inner
499                  
500 <                if (nlist > neighborListSize) then
501 <                   call expandNeighborList(nlocal, listerror)
502 <                   if (listerror /= 0) then
503 <                      error = -1
504 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
505 <                      return
489 <                   end if
490 <                   neighborListSize = size(list)
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 <                list(nlist) = j
509 <                call do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot_local)                      
510 <             endif
511 <          enddo prepair_inner
512 <       enddo
513 <
514 <       point(nrow + 1) = nlist + 1
515 <      
516 <    else  !! (of update_check)
517 <
518 <       ! use the list to find the neighbors
519 <       do i = 1, nrow
520 <          JBEG = POINT(i)
521 <          JEND = POINT(i+1) - 1
522 <          ! check thiat molecule i has neighbors
523 <          if (jbeg .le. jend) then
524 <            
525 <             do jnab = jbeg, jend
526 <                j = list(jnab)
527 <
528 <                call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
529 <                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
530 <                     u_l, A, f, t, pot_local)
531 <
532 <             enddo
533 <          endif
534 <       enddo
535 <    endif
536 <    
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
569 >       endif
570 >      
571   #else
523    
524    if (update_nlist) then
572        
573 <       ! save current configuration, contruct neighbor list,
527 <       ! and calculate forces
528 <       call saveNeighborList(natoms, q)
529 <      
530 <       neighborListSize = size(list)
531 <  
532 <       nlist = 0
533 <
534 <       do i = 1, natoms-1
535 <          point(i) = nlist + 1
573 >       if (update_nlist) then
574            
575 <          prepair_inner: do j = i+1, natoms
575 >          ! save current configuration, contruct neighbor list,
576 >          ! and calculate forces
577 >          call saveNeighborList(natoms, q)
578 >          
579 >          neighborListSize = size(list)
580 >          
581 >          nlist = 0
582 >          
583 >          do i = 1, natoms-1
584 >             point(i) = nlist + 1
585              
586 <             if (skipThisPair(i,j))  cycle prepair_inner
540 <                          
541 <             call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
542 <          
543 <
544 <             if (rijsq < rlistsq) then
545 <
546 <          
547 <                nlist = nlist + 1
548 <              
549 <                if (nlist > neighborListSize) then
550 <                   call expandNeighborList(natoms, listerror)
551 <                   if (listerror /= 0) then
552 <                      error = -1
553 <                      write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
554 <                      return
555 <                   end if
556 <                   neighborListSize = size(list)
557 <                endif
586 >             prepair_inner: do j = i+1, natoms
587                  
588 <                list(nlist) = j
588 >                if (skipThisPair(i,j))  cycle prepair_inner
589                  
590 <                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
591 <                        u_l, A, f, t, pot)
590 >                if (SIM_uses_molecular_cutoffs) then
591 >                   call get_interatomic_vector(qcom(:,i), qcom(:,j), &
592 >                        dc, rcijsq)
593 >                else
594 >                   call get_interatomic_vector(q(:,i), q(:,j), dc, rcijsq)
595 >                endif
596 >                
597 >                if (rcijsq < rlistsq) then
598 >                  
599 >                   nlist = nlist + 1
600 >                  
601 >                   if (nlist > neighborListSize) then
602 >                      call expandNeighborList(natoms, listerror)
603 >                      if (listerror /= 0) then
604 >                         error = -1
605 >                         write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded."
606 >                         return
607 >                      end if
608 >                      neighborListSize = size(list)
609 >                   endif
610 >                  
611 >                   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 >                  
626 >                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
640                  
641 +                do jnab = jbeg, jend
642 +                   j = list(jnab)
643 +                  
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 prepair_inner
659 <       enddo
567 <      
568 <       point(natoms) = nlist + 1
569 <      
570 <    else !! (update)
571 <  
572 <       ! use the list to find the neighbors
573 <       do i = 1, natoms-1
574 <          JBEG = POINT(i)
575 <          JEND = POINT(i+1) - 1
576 <          ! check thiat molecule i has neighbors
577 <          if (jbeg .le. jend) then
578 <            
579 <             do jnab = jbeg, jend
580 <                j = list(jnab)
581 <
582 <                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
583 <                call do_prepair(i, j, rijsq, d, do_pot, do_stress, &
584 <                     u_l, A, f, t, pot)
585 <
586 <             enddo
587 <          endif
588 <       enddo
589 <    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.
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 <
672 <
603 <
604 <
605 < !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>>>>>>>>>>>>>>>>
606 <
607 <
608 <
609 <
610 <  
670 >    
671 >    !---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>
672 >    
673   #ifdef IS_MPI
674      
675      if (update_nlist) then
# Line 619 | Line 681 | contains
681         nlist = 0      
682        
683         do i = 1, nrow
684 <
684 >          
685            point(i) = nlist + 1
686            
687            inner: do j = 1, ncol
688              
689               if (skipThisPair(i,j)) cycle inner
690              
691 <             call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
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 (rijsq < rlistsq) then            
699 >             if (rcijsq < rlistsq) then            
700                  
701                  nlist = nlist + 1
702                  
# Line 643 | Line 711 | contains
711                  endif
712                  
713                  list(nlist) = j
646                                
647                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
648                     u_l, A, f, t, pot_local)
714                  
715 +                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
722 +                
723 +                call do_pair(i, j, rijsq, d, rcijsq, dc, mfact, &
724 +                     do_pot, do_stress, u_l, A, f, t, pot_local)
725 +                
726               endif
727            enddo inner
728         enddo
729 <
729 >      
730         point(nrow + 1) = nlist + 1
731        
732      else  !! (of update_check)
733 <
733 >      
734         ! use the list to find the neighbors
735         do i = 1, nrow
736            JBEG = POINT(i)
# Line 664 | Line 740 | contains
740              
741               do jnab = jbeg, jend
742                  j = list(jnab)
743 <
743 >                
744                  call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq)
745 <                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
746 <                     u_l, A, f, t, pot_local)
747 <
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
# Line 677 | Line 761 | contains
761   #else
762      
763      if (update_nlist) then
764 <
764 >      
765         ! save current configuration, contruct neighbor list,
766         ! and calculate forces
767         call saveNeighborList(natoms, q)
768        
769         neighborListSize = size(list)
770 <  
770 >      
771         nlist = 0
772        
773         do i = 1, natoms-1
# Line 692 | Line 776 | contains
776            inner: do j = i+1, natoms
777              
778               if (skipThisPair(i,j))  cycle inner
779 <                          
780 <             call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
781 <          
782 <
783 <             if (rijsq < rlistsq) then
779 >            
780 >             if (SIM_uses_molecular_cutoffs) then
781 >                call get_interatomic_vector(qcom(:,i), qcom(:,j), &
782 >                     dc, rcijsq)
783 >             else
784 >                call get_interatomic_vector(q(:,i), q(:,j), &
785 >                     dc, rcijsq)
786 >             endif
787 >            
788 >             if (rcijsq < rlistsq) then
789                  
790                  nlist = nlist + 1
791 <              
791 >                
792                  if (nlist > neighborListSize) then
793                     call expandNeighborList(natoms, listerror)
794                     if (listerror /= 0) then
# Line 712 | Line 801 | contains
801                  
802                  list(nlist) = j
803                  
804 <                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
805 <                        u_l, A, f, t, pot)
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
# Line 733 | Line 830 | contains
830               do jnab = jbeg, jend
831                  j = list(jnab)
832  
736                call get_interatomic_vector(q(:,i), q(:,j), d, rijsq)
737                call do_pair(i, j, rijsq, d, do_pot, do_stress, &
738                     u_l, A, f, t, pot)
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
847            endif
848         enddo
# Line 745 | Line 851 | contains
851   #endif
852      
853      ! phew, done with main loop.
854 <
855 < !! Do timing
854 >    
855 >    !! Do timing
856   #ifdef PROFILE
857      call cpu_time(forceTimeFinal)
858      forceTime = forceTime + forceTimeFinal - forceTimeInitial
859   #endif
860 <
861 <
860 >    
861 >    
862   #ifdef IS_MPI
863      !!distribute forces
864 <  
864 >    
865      f_temp = 0.0_dp
866      call scatter(f_Row,f_temp,plan_row3d)
867      do i = 1,nlocal
868         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
869      end do
870 <
870 >    
871      f_temp = 0.0_dp
872      call scatter(f_Col,f_temp,plan_col3d)
873      do i = 1,nlocal
# Line 785 | Line 891 | contains
891      if (do_pot) then
892         ! scatter/gather pot_row into the members of my column
893         call scatter(pot_Row, pot_Temp, plan_row)
894 <
894 >      
895         ! scatter/gather pot_local into all other procs
896         ! add resultant to get total pot
897         do i = 1, nlocal
# Line 793 | Line 899 | contains
899         enddo
900        
901         pot_Temp = 0.0_DP
902 <
902 >      
903         call scatter(pot_Col, pot_Temp, plan_col)
904         do i = 1, nlocal
905            pot_local = pot_local + pot_Temp(i)
906         enddo
907  
908 <    endif    
908 >    endif
909   #endif
910 <
910 >    
911      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
912        
913         if (FF_uses_RF .and. SIM_uses_RF) then
914 <
914 >          
915   #ifdef IS_MPI
916            call scatter(rf_Row,rf,plan_row3d)
917            call scatter(rf_Col,rf_Temp,plan_col3d)
# Line 815 | Line 921 | contains
921   #endif
922            
923            do i = 1, nLocal
924 <
924 >            
925               rfpot = 0.0_DP
926   #ifdef IS_MPI
927               me_i = atid_row(i)
928   #else
929               me_i = atid(i)
930   #endif
931 <
931 >            
932               if (PropertyMap(me_i)%is_DP) then
933 <
933 >                
934                  mu_i = PropertyMap(me_i)%dipole_moment
935 <
935 >                
936                  !! The reaction field needs to include a self contribution
937                  !! to the field:
938                  call accumulate_self_rf(i, mu_i, u_l)
# Line 843 | Line 949 | contains
949            enddo
950         endif
951      endif
952 <
953 <
952 >    
953 >    
954   #ifdef IS_MPI
955 <
955 >    
956      if (do_pot) then
957         pot = pot + pot_local
958         !! we assume the c code will do the allreduce to get the total potential
959         !! we could do it right here if we needed to...
960      endif
961 <
961 >    
962      if (do_stress) then
963 <      call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
963 >       call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
964              mpi_comm_world,mpi_err)
965         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
966              mpi_comm_world,mpi_err)
967      endif
968 <
968 >    
969   #else
970 <
970 >    
971      if (do_stress) then
972         tau = tau_Temp
973         virial = virial_Temp
# Line 870 | Line 976 | contains
976   #endif
977      
978      
873    
979    end subroutine do_force_loop
980 +  
981 +  subroutine do_pair(i, j, rijsq, d, rcijsq, dc, mfact, do_pot, do_stress, &
982 +       u_l, A, f, t, pot)
983  
876  subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot)
877
984      real( kind = dp ) :: pot
985 +    real( kind = dp ), dimension(nLocal)   :: mfact
986      real( kind = dp ), dimension(3,nLocal) :: u_l
987 <    real (kind=dp), dimension(9,nLocal) :: A
988 <    real (kind=dp), dimension(3,nLocal) :: f
989 <    real (kind=dp), dimension(3,nLocal) :: t
987 >    real( kind = dp ), dimension(9,nLocal) :: A
988 >    real( kind = dp ), dimension(3,nLocal) :: f
989 >    real( kind = dp ), dimension(3,nLocal) :: t
990  
991      logical, intent(inout) :: do_pot, do_stress
992      integer, intent(in) :: i, j
993 <    real ( kind = dp ), intent(inout)    :: rijsq
994 <    real ( kind = dp )                :: r
995 <    real ( kind = dp ), intent(inout) :: d(3)
993 >    real ( kind = dp ), intent(inout) :: rijsq, rcijsq
994 >    real ( kind = dp )                :: r, rc
995 >    real ( kind = dp ), intent(inout) :: d(3), dc(3)
996      integer :: me_i, me_j
997  
998      r = sqrt(rijsq)
999 +    if (SIM_uses_molecular_cutoffs) then
1000 +       rc = sqrt(rcijsq)
1001 +    else
1002 +       rc = r
1003 +    endif
1004  
1005 +
1006   #ifdef IS_MPI
1007      if (tagRow(i) .eq. tagColumn(j)) then
1008         write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j)
# Line 912 | Line 1025 | contains
1025      if (FF_uses_charges .and. SIM_uses_charges) then
1026        
1027         if (PropertyMap(me_i)%is_Charge .and. PropertyMap(me_j)%is_Charge) then
1028 <          call do_charge_pair(i, j, d, r, rijsq, pot, f, do_pot, do_stress)
1028 >          call do_charge_pair(i, j, d, r, rijsq, dc, rc, rcijsq, mfact, &
1029 >               pot, f, do_pot, do_stress, SIM_uses_molecular_cutoffs)
1030         endif
1031        
1032      endif
# Line 961 | Line 1075 | contains
1075  
1076  
1077  
1078 <  subroutine do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot)
1078 >  subroutine do_prepair(i, j, rijsq, d, rcijsq, dc, &
1079 >       do_pot, do_stress, u_l, A, f, t, pot)
1080     real( kind = dp ) :: pot
1081     real( kind = dp ), dimension(3,nLocal) :: u_l
1082     real (kind=dp), dimension(9,nLocal) :: A
# Line 970 | Line 1085 | contains
1085    
1086     logical, intent(inout) :: do_pot, do_stress
1087     integer, intent(in) :: i, j
1088 <   real ( kind = dp ), intent(inout)    :: rijsq
1089 <   real ( kind = dp )                :: r
1090 <   real ( kind = dp ), intent(inout) :: d(3)
1088 >   real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1089 >   real ( kind = dp )                :: r, rc
1090 >   real ( kind = dp ), intent(inout) :: d(3), dc(3)
1091    
1092     logical :: is_EAM_i, is_EAM_j
1093    
1094     integer :: me_i, me_j
1095    
1096 <   r = sqrt(rijsq)
1096 >
1097 >    r = sqrt(rijsq)
1098 >    if (SIM_uses_molecular_cutoffs) then
1099 >       rc = sqrt(rcijsq)
1100 >    else
1101 >       rc = r
1102 >    endif
1103    
1104  
1105   #ifdef IS_MPI
# Line 1008 | Line 1129 | contains
1129  
1130  
1131  
1132 <  subroutine do_preforce(nlocal,pot)
1133 <    integer :: nlocal
1134 <    real( kind = dp ) :: pot
1135 <
1136 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
1137 <       call calc_EAM_preforce_Frho(nlocal,pot)
1138 <    endif
1139 <
1140 <
1141 <  end subroutine do_preforce
1142 <  
1143 <  
1144 <  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1145 <    
1146 <    real (kind = dp), dimension(3) :: q_i
1147 <    real (kind = dp), dimension(3) :: q_j
1148 <    real ( kind = dp ), intent(out) :: r_sq
1149 <    real( kind = dp ) :: d(3), scaled(3)
1150 <    integer i
1151 <
1152 <    d(1:3) = q_j(1:3) - q_i(1:3)
1153 <
1154 <    ! Wrap back into periodic box if necessary
1155 <    if ( SIM_uses_PBC ) then
1035 <      
1036 <       if( .not.boxIsOrthorhombic ) then
1037 <          ! calc the scaled coordinates.
1038 <          
1039 <          scaled = matmul(HmatInv, d)
1040 <          
1041 <          ! wrap the scaled coordinates
1042 <
1043 <          scaled = scaled  - anint(scaled)
1044 <          
1045 <
1046 <          ! calc the wrapped real coordinates from the wrapped scaled
1047 <          ! coordinates
1048 <
1049 <          d = matmul(Hmat,scaled)
1050 <
1051 <       else
1052 <          ! calc the scaled coordinates.
1053 <          
1054 <          do i = 1, 3
1055 <             scaled(i) = d(i) * HmatInv(i,i)
1056 <            
1057 <             ! wrap the scaled coordinates
1058 <            
1059 <             scaled(i) = scaled(i) - anint(scaled(i))
1060 <            
1061 <             ! calc the wrapped real coordinates from the wrapped scaled
1062 <             ! coordinates
1063 <
1064 <             d(i) = scaled(i)*Hmat(i,i)
1065 <          enddo
1066 <       endif
1067 <      
1068 <    endif
1069 <    
1070 <    r_sq = dot_product(d,d)
1071 <    
1072 <  end subroutine get_interatomic_vector
1073 <  
1074 <  subroutine zero_work_arrays()
1075 <    
1076 < #ifdef IS_MPI
1077 <
1078 <    q_Row = 0.0_dp
1079 <    q_Col = 0.0_dp  
1080 <    
1081 <    u_l_Row = 0.0_dp
1082 <    u_l_Col = 0.0_dp
1083 <    
1084 <    A_Row = 0.0_dp
1085 <    A_Col = 0.0_dp
1086 <    
1087 <    f_Row = 0.0_dp
1088 <    f_Col = 0.0_dp
1089 <    f_Temp = 0.0_dp
1132 > subroutine do_preforce(nlocal,pot)
1133 >   integer :: nlocal
1134 >   real( kind = dp ) :: pot
1135 >  
1136 >   if (FF_uses_EAM .and. SIM_uses_EAM) then
1137 >      call calc_EAM_preforce_Frho(nlocal,pot)
1138 >   endif
1139 >  
1140 >  
1141 > end subroutine do_preforce
1142 >
1143 >
1144 > subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1145 >  
1146 >   real (kind = dp), dimension(3) :: q_i
1147 >   real (kind = dp), dimension(3) :: q_j
1148 >   real ( kind = dp ), intent(out) :: r_sq
1149 >   real( kind = dp ) :: d(3), scaled(3)
1150 >   integer i
1151 >  
1152 >   d(1:3) = q_j(1:3) - q_i(1:3)
1153 >  
1154 >   ! Wrap back into periodic box if necessary
1155 >   if ( SIM_uses_PBC ) then
1156        
1157 <    t_Row = 0.0_dp
1158 <    t_Col = 0.0_dp
1159 <    t_Temp = 0.0_dp
1157 >      if( .not.boxIsOrthorhombic ) then
1158 >         ! calc the scaled coordinates.
1159 >        
1160 >         scaled = matmul(HmatInv, d)
1161 >        
1162 >         ! wrap the scaled coordinates
1163 >        
1164 >         scaled = scaled  - anint(scaled)
1165 >        
1166 >        
1167 >         ! calc the wrapped real coordinates from the wrapped scaled
1168 >         ! coordinates
1169 >        
1170 >         d = matmul(Hmat,scaled)
1171 >        
1172 >      else
1173 >         ! calc the scaled coordinates.
1174 >        
1175 >         do i = 1, 3
1176 >            scaled(i) = d(i) * HmatInv(i,i)
1177 >            
1178 >            ! wrap the scaled coordinates
1179 >            
1180 >            scaled(i) = scaled(i) - anint(scaled(i))
1181 >            
1182 >            ! calc the wrapped real coordinates from the wrapped scaled
1183 >            ! coordinates
1184 >            
1185 >            d(i) = scaled(i)*Hmat(i,i)
1186 >         enddo
1187 >      endif
1188 >      
1189 >   endif
1190 >  
1191 >   r_sq = dot_product(d,d)
1192 >  
1193 > end subroutine get_interatomic_vector
1194  
1195 <    pot_Row = 0.0_dp
1196 <    pot_Col = 0.0_dp
1197 <    pot_Temp = 0.0_dp
1195 > subroutine zero_work_arrays()
1196 >  
1197 > #ifdef IS_MPI
1198 >  
1199 >   q_Row = 0.0_dp
1200 >   q_Col = 0.0_dp
1201  
1202 <    rf_Row = 0.0_dp
1203 <    rf_Col = 0.0_dp
1204 <    rf_Temp = 0.0_dp
1205 <
1202 >   qcom_Row = 0.0_dp
1203 >   qcom_Col = 0.0_dp  
1204 >  
1205 >   u_l_Row = 0.0_dp
1206 >   u_l_Col = 0.0_dp
1207 >  
1208 >   A_Row = 0.0_dp
1209 >   A_Col = 0.0_dp
1210 >  
1211 >   f_Row = 0.0_dp
1212 >   f_Col = 0.0_dp
1213 >   f_Temp = 0.0_dp
1214 >  
1215 >   t_Row = 0.0_dp
1216 >   t_Col = 0.0_dp
1217 >   t_Temp = 0.0_dp
1218 >  
1219 >   pot_Row = 0.0_dp
1220 >   pot_Col = 0.0_dp
1221 >   pot_Temp = 0.0_dp
1222 >  
1223 >   rf_Row = 0.0_dp
1224 >   rf_Col = 0.0_dp
1225 >   rf_Temp = 0.0_dp
1226 >  
1227   #endif
1104
1228  
1229 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
1230 <       call clean_EAM()
1231 <    endif
1232 <
1233 <
1234 <
1235 <
1236 <
1237 <    rf = 0.0_dp
1238 <    tau_Temp = 0.0_dp
1239 <    virial_Temp = 0.0_dp
1240 <  end subroutine zero_work_arrays
1241 <  
1242 <  function skipThisPair(atom1, atom2) result(skip_it)
1243 <    integer, intent(in) :: atom1
1244 <    integer, intent(in), optional :: atom2
1245 <    logical :: skip_it
1246 <    integer :: unique_id_1, unique_id_2
1247 <    integer :: me_i,me_j
1248 <    integer :: i
1249 <
1250 <    skip_it = .false.
1251 <    
1252 <    !! there are a number of reasons to skip a pair or a particle
1253 <    !! mostly we do this to exclude atoms who are involved in short
1131 <    !! range interactions (bonds, bends, torsions), but we also need
1132 <    !! to exclude some overcounted interactions that result from
1133 <    !! the parallel decomposition
1134 <    
1229 >   if (FF_uses_EAM .and. SIM_uses_EAM) then
1230 >      call clean_EAM()
1231 >   endif
1232 >  
1233 >   rf = 0.0_dp
1234 >   tau_Temp = 0.0_dp
1235 >   virial_Temp = 0.0_dp
1236 > end subroutine zero_work_arrays
1237 >
1238 > function skipThisPair(atom1, atom2) result(skip_it)
1239 >   integer, intent(in) :: atom1
1240 >   integer, intent(in), optional :: atom2
1241 >   logical :: skip_it
1242 >   integer :: unique_id_1, unique_id_2
1243 >   integer :: me_i,me_j
1244 >   integer :: i
1245 >  
1246 >   skip_it = .false.
1247 >  
1248 >   !! there are a number of reasons to skip a pair or a particle
1249 >   !! mostly we do this to exclude atoms who are involved in short
1250 >   !! range interactions (bonds, bends, torsions), but we also need
1251 >   !! to exclude some overcounted interactions that result from
1252 >   !! the parallel decomposition
1253 >  
1254   #ifdef IS_MPI
1255 <    !! in MPI, we have to look up the unique IDs for each atom
1256 <    unique_id_1 = tagRow(atom1)
1255 >   !! in MPI, we have to look up the unique IDs for each atom
1256 >   unique_id_1 = tagRow(atom1)
1257   #else
1258 <    !! in the normal loop, the atom numbers are unique
1259 <    unique_id_1 = atom1
1258 >   !! in the normal loop, the atom numbers are unique
1259 >   unique_id_1 = atom1
1260   #endif
1261 <
1262 <    !! We were called with only one atom, so just check the global exclude
1263 <    !! list for this atom
1264 <    if (.not. present(atom2)) then
1265 <       do i = 1, nExcludes_global
1266 <          if (excludesGlobal(i) == unique_id_1) then
1267 <             skip_it = .true.
1268 <             return
1269 <          end if
1270 <       end do
1271 <       return
1272 <    end if
1273 <    
1261 >  
1262 >   !! We were called with only one atom, so just check the global exclude
1263 >   !! list for this atom
1264 >   if (.not. present(atom2)) then
1265 >      do i = 1, nExcludes_global
1266 >         if (excludesGlobal(i) == unique_id_1) then
1267 >            skip_it = .true.
1268 >            return
1269 >         end if
1270 >      end do
1271 >      return
1272 >   end if
1273 >  
1274   #ifdef IS_MPI
1275 <    unique_id_2 = tagColumn(atom2)
1275 >   unique_id_2 = tagColumn(atom2)
1276   #else
1277 <    unique_id_2 = atom2
1277 >   unique_id_2 = atom2
1278   #endif
1279 <
1279 >  
1280   #ifdef IS_MPI
1281 <    !! this situation should only arise in MPI simulations
1282 <    if (unique_id_1 == unique_id_2) then
1283 <       skip_it = .true.
1284 <       return
1285 <    end if
1286 <    
1287 <    !! this prevents us from doing the pair on multiple processors
1288 <    if (unique_id_1 < unique_id_2) then
1289 <       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1290 <          skip_it = .true.
1291 <          return
1292 <       endif
1293 <    else                
1294 <       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1295 <          skip_it = .true.
1296 <          return
1297 <       endif
1298 <    endif
1281 >   !! this situation should only arise in MPI simulations
1282 >   if (unique_id_1 == unique_id_2) then
1283 >      skip_it = .true.
1284 >      return
1285 >   end if
1286 >  
1287 >   !! this prevents us from doing the pair on multiple processors
1288 >   if (unique_id_1 < unique_id_2) then
1289 >      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1290 >         skip_it = .true.
1291 >         return
1292 >      endif
1293 >   else                
1294 >      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1295 >         skip_it = .true.
1296 >         return
1297 >      endif
1298 >   endif
1299   #endif
1300 +  
1301 +   !! the rest of these situations can happen in all simulations:
1302 +   do i = 1, nExcludes_global      
1303 +      if ((excludesGlobal(i) == unique_id_1) .or. &
1304 +           (excludesGlobal(i) == unique_id_2)) then
1305 +         skip_it = .true.
1306 +         return
1307 +      endif
1308 +   enddo
1309 +  
1310 +   do i = 1, nExcludes_local
1311 +      if (excludesLocal(1,i) == unique_id_1) then
1312 +         if (excludesLocal(2,i) == unique_id_2) then
1313 +            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
1323 +      endif
1324 +   end do
1325 +  
1326 +   return
1327 + end function skipThisPair
1328  
1329 <    !! the rest of these situations can happen in all simulations:
1330 <    do i = 1, nExcludes_global      
1331 <       if ((excludesGlobal(i) == unique_id_1) .or. &
1332 <            (excludesGlobal(i) == unique_id_2)) then
1333 <          skip_it = .true.
1334 <          return
1335 <       endif
1336 <    enddo
1337 <
1338 <    do i = 1, nExcludes_local
1339 <       if (excludesLocal(1,i) == unique_id_1) then
1340 <          if (excludesLocal(2,i) == unique_id_2) then
1341 <             skip_it = .true.
1342 <             return
1343 <          endif
1344 <       else
1198 <          if (excludesLocal(1,i) == unique_id_2) then
1199 <             if (excludesLocal(2,i) == unique_id_1) then
1200 <                skip_it = .true.
1201 <                return
1202 <             endif
1203 <          endif
1204 <       endif
1205 <    end do
1206 <    
1207 <    return
1208 <  end function skipThisPair
1209 <
1210 <  function FF_UsesDirectionalAtoms() result(doesit)
1211 <    logical :: doesit
1212 <    doesit = FF_uses_dipoles .or. FF_uses_sticky .or. &
1213 <         FF_uses_GB .or. FF_uses_RF
1214 <  end function FF_UsesDirectionalAtoms
1215 <  
1216 <  function FF_RequiresPrepairCalc() result(doesit)
1217 <    logical :: doesit
1218 <    doesit = FF_uses_EAM
1219 <  end function FF_RequiresPrepairCalc
1220 <  
1221 <  function FF_RequiresPostpairCalc() result(doesit)
1222 <    logical :: doesit
1223 <    doesit = FF_uses_RF
1224 <  end function FF_RequiresPostpairCalc
1225 <  
1329 > function FF_UsesDirectionalAtoms() result(doesit)
1330 >   logical :: doesit
1331 >   doesit = FF_uses_dipoles .or. FF_uses_sticky .or. &
1332 >        FF_uses_GB .or. FF_uses_RF
1333 > end function FF_UsesDirectionalAtoms
1334 >
1335 > function FF_RequiresPrepairCalc() result(doesit)
1336 >   logical :: doesit
1337 >   doesit = FF_uses_EAM
1338 > end function FF_RequiresPrepairCalc
1339 >
1340 > function FF_RequiresPostpairCalc() result(doesit)
1341 >   logical :: doesit
1342 >   doesit = FF_uses_RF
1343 > end function FF_RequiresPostpairCalc
1344 >
1345   #ifdef PROFILE
1346 <  function getforcetime() result(totalforcetime)
1347 <    real(kind=dp) :: totalforcetime
1348 <    totalforcetime = forcetime
1349 <  end function getforcetime
1346 > function getforcetime() result(totalforcetime)
1347 >   real(kind=dp) :: totalforcetime
1348 >   totalforcetime = forcetime
1349 > end function getforcetime
1350   #endif
1351 <
1352 < !! This cleans componets of force arrays belonging only to fortran
1353 <
1351 >
1352 > !! This cleans componets of force arrays belonging only to fortran
1353 >
1354   end module do_Forces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines