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.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 |
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. |
60 |
|
logical, save :: SIM_requires_prepair_calc |
61 |
|
logical, save :: SIM_uses_directional_atoms |
62 |
|
logical, save :: SIM_uses_PBC |
63 |
+ |
logical, save :: SIM_uses_molecular_cutoffs |
64 |
|
|
65 |
|
real(kind=dp), save :: rlist, rlistsq |
66 |
|
|
68 |
|
public :: do_force_loop |
69 |
|
public :: setRlistDF |
70 |
|
|
65 |
– |
|
71 |
|
#ifdef PROFILE |
72 |
|
public :: getforcetime |
73 |
|
real, save :: forceTime = 0 |
165 |
|
SIM_requires_prepair_calc = SimRequiresPrepairCalc() |
166 |
|
SIM_uses_directional_atoms = SimUsesDirectionalAtoms() |
167 |
|
SIM_uses_PBC = SimUsesPBC() |
168 |
+ |
!SIM_uses_molecular_cutoffs = SimUsesMolecularCutoffs() |
169 |
|
|
170 |
|
haveSIMvariables = .true. |
171 |
|
|
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, A, u_l, f, t, tau, pot, do_pot_c, do_stress_c, & |
374 |
< |
error) |
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 |
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 |
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 |
410 |
< |
real(kind=dp),dimension(3) :: d |
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 |
< |
|
422 |
> |
|
423 |
|
!! initialize local variables |
424 |
< |
|
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) |
431 |
|
#else |
432 |
|
natoms = nlocal |
433 |
|
#endif |
434 |
< |
|
434 |
> |
|
435 |
|
call doReadyCheck(localError) |
436 |
|
if ( localError .ne. 0 ) then |
437 |
|
call handleError("do_force_loop", "Not Initialized") |
439 |
|
return |
440 |
|
end if |
441 |
|
call zero_work_arrays() |
442 |
< |
|
442 |
> |
|
443 |
|
do_pot = do_pot_c |
444 |
|
do_stress = do_stress_c |
445 |
< |
|
445 |
> |
|
446 |
|
! Gather all information needed by all force loops: |
447 |
|
|
448 |
|
#ifdef IS_MPI |
449 |
+ |
|
450 |
+ |
call gather(q, q_Row, plan_row3d) |
451 |
+ |
call gather(q, q_Col, plan_col3d) |
452 |
|
|
453 |
< |
call gather(q,q_Row,plan_row3d) |
454 |
< |
call gather(q,q_Col,plan_col3d) |
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) |
462 |
|
endif |
463 |
|
|
464 |
|
#endif |
465 |
< |
|
466 |
< |
!! Begin force loop timing: |
465 |
> |
|
466 |
> |
!! Begin force loop timing: |
467 |
|
#ifdef PROFILE |
468 |
|
call cpu_time(forceTimeInitial) |
469 |
|
nloops = nloops + 1 |
470 |
|
#endif |
449 |
– |
|
450 |
– |
if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then |
451 |
– |
!! See if we need to update neighbor lists |
452 |
– |
call checkNeighborList(nlocal, q, listSkin, update_nlist) |
453 |
– |
!! if_mpi_gather_stuff_for_prepair |
454 |
– |
!! do_prepair_loop_if_needed |
455 |
– |
!! if_mpi_scatter_stuff_from_prepair |
456 |
– |
!! if_mpi_gather_stuff_from_prepair_to_main_loop |
457 |
– |
|
458 |
– |
!--------------------PREFORCE LOOP----------->>>>>>>>>>>>>>>>>>>>>>>>>>> |
459 |
– |
#ifdef IS_MPI |
471 |
|
|
472 |
< |
if (update_nlist) then |
473 |
< |
|
474 |
< |
!! save current configuration, construct neighbor list, |
475 |
< |
!! and calculate forces |
476 |
< |
call saveNeighborList(nlocal, q) |
472 |
> |
loopEnd = PAIR_LOOP |
473 |
> |
if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then |
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 |
486 |
|
|
487 |
< |
neighborListSize = size(list) |
488 |
< |
nlist = 0 |
487 |
> |
if (update_nlist) then |
488 |
> |
!! save current configuration and construct neighbor list |
489 |
> |
call saveNeighborList(nGroup, q_group) |
490 |
> |
neighborListSize = size(list) |
491 |
> |
nlist = 0 |
492 |
> |
endif |
493 |
|
|
494 |
< |
do i = 1, nrow |
495 |
< |
point(i) = nlist + 1 |
494 |
> |
istart = 1 |
495 |
> |
#ifdef IS_MPI |
496 |
> |
iend = nrow_group |
497 |
> |
#else |
498 |
> |
iend = nGroup - 1 |
499 |
> |
#endif |
500 |
> |
outer: do i = istart, iend |
501 |
|
|
502 |
< |
prepair_inner: do j = 1, ncol |
503 |
< |
|
504 |
< |
if (skipThisPair(i,j)) cycle prepair_inner |
505 |
< |
|
506 |
< |
call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) |
507 |
< |
|
508 |
< |
if (rijsq < 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 |
< |
call do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot_local) |
502 |
> |
if (update_nlist) point(i) = nlist + 1 |
503 |
> |
|
504 |
> |
n_in_i = groupStart(i+1) - groupStart(i) |
505 |
> |
|
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 jnab = jstart, jend |
522 |
> |
if (update_nlist) then |
523 |
> |
j = jnab |
524 |
> |
else |
525 |
> |
j = list(jnab) |
526 |
|
endif |
527 |
< |
enddo prepair_inner |
528 |
< |
enddo |
529 |
< |
|
499 |
< |
point(nrow + 1) = nlist + 1 |
500 |
< |
|
501 |
< |
else !! (of update_check) |
502 |
< |
|
503 |
< |
! use the list to find the neighbors |
504 |
< |
do i = 1, nrow |
505 |
< |
JBEG = POINT(i) |
506 |
< |
JEND = POINT(i+1) - 1 |
507 |
< |
! check thiat molecule i has neighbors |
508 |
< |
if (jbeg .le. jend) then |
509 |
< |
|
510 |
< |
do jnab = jbeg, jend |
511 |
< |
j = list(jnab) |
512 |
< |
|
513 |
< |
call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) |
514 |
< |
call do_prepair(i, j, rijsq, d, do_pot, do_stress, & |
515 |
< |
u_l, A, f, t, pot_local) |
516 |
< |
|
517 |
< |
enddo |
518 |
< |
endif |
519 |
< |
enddo |
520 |
< |
endif |
521 |
< |
|
527 |
> |
#ifdef IS_MPI |
528 |
> |
call get_interatomic_vector(q_group_Row(:,i), & |
529 |
> |
q_group_Col(:,j), d_grp, rgrpsq) |
530 |
|
#else |
531 |
< |
|
532 |
< |
if (update_nlist) then |
533 |
< |
|
534 |
< |
! save current configuration, contruct neighbor list, |
535 |
< |
! and calculate forces |
536 |
< |
call saveNeighborList(natoms, q) |
537 |
< |
|
538 |
< |
neighborListSize = size(list) |
539 |
< |
|
540 |
< |
nlist = 0 |
541 |
< |
|
542 |
< |
do i = 1, natoms-1 |
543 |
< |
point(i) = nlist + 1 |
544 |
< |
|
545 |
< |
prepair_inner: do j = i+1, natoms |
546 |
< |
|
547 |
< |
if (skipThisPair(i,j)) cycle prepair_inner |
548 |
< |
|
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) |
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(nGroup, listerror) |
540 |
> |
if (listerror /= 0) then |
541 |
> |
error = -1 |
542 |
> |
write(DEFAULT_ERROR,*) "ERROR: nlist > list size and max allocations exceeded." |
543 |
> |
return |
544 |
> |
end if |
545 |
> |
neighborListSize = size(list) |
546 |
> |
endif |
547 |
> |
|
548 |
> |
list(nlist) = j |
549 |
|
endif |
550 |
|
|
551 |
< |
list(nlist) = j |
551 |
> |
if (loop .eq. PAIR_LOOP) then |
552 |
> |
vij = 0.0d0 |
553 |
> |
fij(1:3) = 0.0d0 |
554 |
> |
endif |
555 |
|
|
556 |
< |
call do_prepair(i, j, rijsq, d, do_pot, do_stress, & |
557 |
< |
u_l, A, f, t, pot) |
556 |
> |
call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, & |
557 |
> |
in_switching_region) |
558 |
|
|
559 |
< |
endif |
560 |
< |
enddo prepair_inner |
561 |
< |
enddo |
562 |
< |
|
563 |
< |
point(natoms) = nlist + 1 |
564 |
< |
|
565 |
< |
else !! (update) |
566 |
< |
|
567 |
< |
! use the list to find the neighbors |
568 |
< |
do i = 1, natoms-1 |
569 |
< |
JBEG = POINT(i) |
570 |
< |
JEND = POINT(i+1) - 1 |
571 |
< |
! check thiat molecule i has neighbors |
572 |
< |
if (jbeg .le. jend) then |
573 |
< |
|
574 |
< |
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 |
590 |
< |
#endif |
591 |
< |
!! Do rest of preforce calculations |
592 |
< |
!! do necessary preforce calculations |
593 |
< |
call do_preforce(nlocal,pot) |
594 |
< |
! we have already updated the neighbor list set it to false... |
595 |
< |
update_nlist = .false. |
596 |
< |
else |
597 |
< |
!! See if we need to update neighbor lists for non pre-pair |
598 |
< |
call checkNeighborList(nlocal, q, listSkin, update_nlist) |
599 |
< |
endif |
600 |
< |
|
601 |
< |
|
602 |
< |
|
603 |
< |
|
604 |
< |
|
605 |
< |
!---------------------------------MAIN Pair LOOP->>>>>>>>>>>>>>>>>>>>>>>>>>>> |
606 |
< |
|
607 |
< |
|
608 |
< |
|
609 |
< |
|
610 |
< |
|
559 |
> |
n_in_j = groupStart(j+1) - groupStart(j) |
560 |
> |
|
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 |
< |
|
577 |
< |
if (update_nlist) then |
578 |
< |
!! save current configuration, construct neighbor list, |
579 |
< |
!! and calculate forces |
580 |
< |
call saveNeighborList(nlocal, q) |
581 |
< |
|
582 |
< |
neighborListSize = size(list) |
583 |
< |
nlist = 0 |
584 |
< |
|
585 |
< |
do i = 1, nrow |
586 |
< |
|
587 |
< |
point(i) = nlist + 1 |
588 |
< |
|
589 |
< |
inner: do j = 1, ncol |
590 |
< |
|
591 |
< |
if (skipThisPair(i,j)) cycle inner |
592 |
< |
|
593 |
< |
call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) |
594 |
< |
|
595 |
< |
if (rijsq < rlistsq) then |
576 |
> |
call get_interatomic_vector(q_Row(:,atom1), & |
577 |
> |
q_Col(:,atom2), d_atm, ratmsq) |
578 |
> |
#else |
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(nlocal, 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 |
< |
|
647 |
< |
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
648 |
< |
u_l, A, f, t, pot_local) |
649 |
< |
|
650 |
< |
endif |
651 |
< |
enddo inner |
652 |
< |
enddo |
653 |
< |
|
654 |
< |
point(nrow + 1) = nlist + 1 |
647 |
> |
end if |
648 |
> |
enddo |
649 |
> |
enddo outer |
650 |
|
|
651 |
< |
else !! (of update_check) |
652 |
< |
|
653 |
< |
! use the list to find the neighbors |
654 |
< |
do i = 1, nrow |
655 |
< |
JBEG = POINT(i) |
656 |
< |
JEND = POINT(i+1) - 1 |
657 |
< |
! check thiat molecule i has neighbors |
658 |
< |
if (jbeg .le. jend) then |
659 |
< |
|
660 |
< |
do jnab = jbeg, jend |
661 |
< |
j = list(jnab) |
667 |
< |
|
668 |
< |
call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) |
669 |
< |
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
670 |
< |
u_l, A, f, t, pot_local) |
671 |
< |
|
672 |
< |
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 |
675 |
< |
endif |
676 |
< |
|
677 |
< |
#else |
678 |
< |
|
679 |
< |
if (update_nlist) then |
680 |
< |
|
681 |
< |
! save current configuration, contruct neighbor list, |
682 |
< |
! and calculate forces |
683 |
< |
call saveNeighborList(natoms, q) |
684 |
< |
|
685 |
< |
neighborListSize = size(list) |
686 |
< |
|
687 |
< |
nlist = 0 |
688 |
< |
|
689 |
< |
do i = 1, natoms-1 |
690 |
< |
point(i) = nlist + 1 |
691 |
< |
|
692 |
< |
inner: do j = i+1, natoms |
663 |
> |
endif |
664 |
|
|
665 |
< |
if (skipThisPair(i,j)) cycle inner |
666 |
< |
|
667 |
< |
call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) |
697 |
< |
|
698 |
< |
|
699 |
< |
if (rijsq < rlistsq) then |
700 |
< |
|
701 |
< |
nlist = nlist + 1 |
702 |
< |
|
703 |
< |
if (nlist > neighborListSize) then |
704 |
< |
call expandNeighborList(natoms, 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) |
711 |
< |
endif |
712 |
< |
|
713 |
< |
list(nlist) = j |
714 |
< |
|
715 |
< |
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
716 |
< |
u_l, A, f, t, pot) |
717 |
< |
|
718 |
< |
endif |
719 |
< |
enddo inner |
720 |
< |
enddo |
665 |
> |
if (loop .eq. PREPAIR_LOOP) then |
666 |
> |
call do_preforce(nlocal, pot) |
667 |
> |
endif |
668 |
|
|
669 |
< |
point(natoms) = nlist + 1 |
723 |
< |
|
724 |
< |
else !! (update) |
725 |
< |
|
726 |
< |
! use the list to find the neighbors |
727 |
< |
do i = 1, natoms-1 |
728 |
< |
JBEG = POINT(i) |
729 |
< |
JEND = POINT(i+1) - 1 |
730 |
< |
! check thiat molecule i has neighbors |
731 |
< |
if (jbeg .le. jend) then |
732 |
< |
|
733 |
< |
do jnab = jbeg, jend |
734 |
< |
j = list(jnab) |
735 |
< |
|
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) |
739 |
< |
|
740 |
< |
enddo |
741 |
< |
endif |
742 |
< |
enddo |
743 |
< |
endif |
669 |
> |
enddo |
670 |
|
|
671 |
< |
#endif |
746 |
< |
|
747 |
< |
! phew, done with main loop. |
748 |
< |
|
749 |
< |
!! Do timing |
671 |
> |
!! Do timing |
672 |
|
#ifdef PROFILE |
673 |
|
call cpu_time(forceTimeFinal) |
674 |
|
forceTime = forceTime + forceTimeFinal - forceTimeInitial |
675 |
< |
#endif |
676 |
< |
|
755 |
< |
|
675 |
> |
#endif |
676 |
> |
|
677 |
|
#ifdef IS_MPI |
678 |
|
!!distribute forces |
679 |
< |
|
679 |
> |
|
680 |
|
f_temp = 0.0_dp |
681 |
|
call scatter(f_Row,f_temp,plan_row3d) |
682 |
|
do i = 1,nlocal |
683 |
|
f(1:3,i) = f(1:3,i) + f_temp(1:3,i) |
684 |
|
end do |
685 |
< |
|
685 |
> |
|
686 |
|
f_temp = 0.0_dp |
687 |
|
call scatter(f_Col,f_temp,plan_col3d) |
688 |
|
do i = 1,nlocal |
706 |
|
if (do_pot) then |
707 |
|
! scatter/gather pot_row into the members of my column |
708 |
|
call scatter(pot_Row, pot_Temp, plan_row) |
709 |
< |
|
709 |
> |
|
710 |
|
! scatter/gather pot_local into all other procs |
711 |
|
! add resultant to get total pot |
712 |
|
do i = 1, nlocal |
714 |
|
enddo |
715 |
|
|
716 |
|
pot_Temp = 0.0_DP |
717 |
< |
|
717 |
> |
|
718 |
|
call scatter(pot_Col, pot_Temp, plan_col) |
719 |
|
do i = 1, nlocal |
720 |
|
pot_local = pot_local + pot_Temp(i) |
721 |
|
enddo |
722 |
< |
|
723 |
< |
endif |
722 |
> |
|
723 |
> |
endif |
724 |
|
#endif |
725 |
< |
|
725 |
> |
|
726 |
|
if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then |
727 |
|
|
728 |
|
if (FF_uses_RF .and. SIM_uses_RF) then |
729 |
< |
|
729 |
> |
|
730 |
|
#ifdef IS_MPI |
731 |
|
call scatter(rf_Row,rf,plan_row3d) |
732 |
|
call scatter(rf_Col,rf_Temp,plan_col3d) |
736 |
|
#endif |
737 |
|
|
738 |
|
do i = 1, nLocal |
739 |
< |
|
739 |
> |
|
740 |
|
rfpot = 0.0_DP |
741 |
|
#ifdef IS_MPI |
742 |
|
me_i = atid_row(i) |
743 |
|
#else |
744 |
|
me_i = atid(i) |
745 |
|
#endif |
746 |
< |
|
746 |
> |
|
747 |
|
if (PropertyMap(me_i)%is_DP) then |
748 |
< |
|
748 |
> |
|
749 |
|
mu_i = PropertyMap(me_i)%dipole_moment |
750 |
< |
|
750 |
> |
|
751 |
|
!! The reaction field needs to include a self contribution |
752 |
|
!! to the field: |
753 |
|
call accumulate_self_rf(i, mu_i, u_l) |
764 |
|
enddo |
765 |
|
endif |
766 |
|
endif |
767 |
< |
|
768 |
< |
|
767 |
> |
|
768 |
> |
|
769 |
|
#ifdef IS_MPI |
770 |
< |
|
770 |
> |
|
771 |
|
if (do_pot) then |
772 |
|
pot = pot + pot_local |
773 |
|
!! we assume the c code will do the allreduce to get the total potential |
774 |
|
!! we could do it right here if we needed to... |
775 |
|
endif |
776 |
< |
|
776 |
> |
|
777 |
|
if (do_stress) then |
778 |
< |
call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, & |
778 |
> |
call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, & |
779 |
|
mpi_comm_world,mpi_err) |
780 |
|
call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, & |
781 |
|
mpi_comm_world,mpi_err) |
782 |
|
endif |
783 |
< |
|
783 |
> |
|
784 |
|
#else |
785 |
< |
|
785 |
> |
|
786 |
|
if (do_stress) then |
787 |
|
tau = tau_Temp |
788 |
|
virial = virial_Temp |
789 |
|
endif |
790 |
|
|
791 |
|
#endif |
792 |
< |
|
872 |
< |
|
873 |
< |
|
792 |
> |
|
793 |
|
end subroutine do_force_loop |
794 |
+ |
|
795 |
+ |
subroutine do_pair(i, j, rijsq, d, sw, do_pot, & |
796 |
+ |
u_l, A, f, t, pot, vpair, fpair) |
797 |
|
|
798 |
< |
subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) |
799 |
< |
|
800 |
< |
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 |
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 |
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 |
+ |
vpair = 0.0d0 |
815 |
+ |
fpair(1:3) = 0.0d0 |
816 |
|
|
817 |
|
#ifdef IS_MPI |
818 |
|
if (tagRow(i) .eq. tagColumn(j)) then |
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 |
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, pot, f, do_pot, do_stress) |
845 |
> |
call do_charge_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot) |
846 |
|
endif |
847 |
|
|
848 |
|
endif |
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 |
|
|
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 |
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 |
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 |
+ |
subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, & |
894 |
+ |
do_pot, do_stress, u_l, A, f, t, pot) |
895 |
|
|
896 |
< |
|
964 |
< |
subroutine do_prepair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) |
965 |
< |
real( kind = dp ) :: pot |
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 |
901 |
|
|
902 |
|
logical, intent(inout) :: do_pot, do_stress |
903 |
|
integer, intent(in) :: i, j |
904 |
< |
real ( kind = dp ), intent(inout) :: rijsq |
905 |
< |
real ( kind = dp ) :: r |
906 |
< |
real ( kind = dp ), intent(inout) :: d(3) |
904 |
> |
real ( kind = dp ), intent(inout) :: rijsq, rcijsq |
905 |
> |
real ( kind = dp ) :: r, rc |
906 |
> |
real ( kind = dp ), intent(inout) :: d(3), dc(3) |
907 |
|
|
908 |
|
logical :: is_EAM_i, is_EAM_j |
909 |
|
|
910 |
|
integer :: me_i, me_j |
911 |
|
|
912 |
< |
r = sqrt(rijsq) |
912 |
> |
|
913 |
> |
r = sqrt(rijsq) |
914 |
> |
if (SIM_uses_molecular_cutoffs) then |
915 |
> |
rc = sqrt(rcijsq) |
916 |
> |
else |
917 |
> |
rc = r |
918 |
> |
endif |
919 |
|
|
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) |
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 |
1007 |
– |
|
1008 |
– |
|
1009 |
– |
|
1010 |
– |
|
1011 |
– |
subroutine do_preforce(nlocal,pot) |
1012 |
– |
integer :: nlocal |
1013 |
– |
real( kind = dp ) :: pot |
1014 |
– |
|
1015 |
– |
if (FF_uses_EAM .and. SIM_uses_EAM) then |
1016 |
– |
call calc_EAM_preforce_Frho(nlocal,pot) |
1017 |
– |
endif |
1018 |
– |
|
1019 |
– |
|
1020 |
– |
end subroutine do_preforce |
1021 |
– |
|
1022 |
– |
|
1023 |
– |
subroutine get_interatomic_vector(q_i, q_j, d, r_sq) |
1024 |
– |
|
1025 |
– |
real (kind = dp), dimension(3) :: q_i |
1026 |
– |
real (kind = dp), dimension(3) :: q_j |
1027 |
– |
real ( kind = dp ), intent(out) :: r_sq |
1028 |
– |
real( kind = dp ) :: d(3), scaled(3) |
1029 |
– |
integer i |
1030 |
– |
|
1031 |
– |
d(1:3) = q_j(1:3) - q_i(1:3) |
1032 |
– |
|
1033 |
– |
! Wrap back into periodic box if necessary |
1034 |
– |
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 |
1090 |
– |
|
1091 |
– |
t_Row = 0.0_dp |
1092 |
– |
t_Col = 0.0_dp |
1093 |
– |
t_Temp = 0.0_dp |
944 |
|
|
1095 |
– |
pot_Row = 0.0_dp |
1096 |
– |
pot_Col = 0.0_dp |
1097 |
– |
pot_Temp = 0.0_dp |
1098 |
– |
|
1099 |
– |
rf_Row = 0.0_dp |
1100 |
– |
rf_Col = 0.0_dp |
1101 |
– |
rf_Temp = 0.0_dp |
1102 |
– |
|
1103 |
– |
#endif |
1104 |
– |
|
945 |
|
|
946 |
< |
if (FF_uses_EAM .and. SIM_uses_EAM) then |
947 |
< |
call clean_EAM() |
948 |
< |
endif |
949 |
< |
|
950 |
< |
|
951 |
< |
|
952 |
< |
|
953 |
< |
|
954 |
< |
rf = 0.0_dp |
955 |
< |
tau_Temp = 0.0_dp |
956 |
< |
virial_Temp = 0.0_dp |
957 |
< |
end subroutine zero_work_arrays |
958 |
< |
|
959 |
< |
function skipThisPair(atom1, atom2) result(skip_it) |
960 |
< |
integer, intent(in) :: atom1 |
961 |
< |
integer, intent(in), optional :: atom2 |
962 |
< |
logical :: skip_it |
963 |
< |
integer :: unique_id_1, unique_id_2 |
964 |
< |
integer :: me_i,me_j |
965 |
< |
integer :: i |
966 |
< |
|
967 |
< |
skip_it = .false. |
968 |
< |
|
969 |
< |
!! there are a number of reasons to skip a pair or a particle |
970 |
< |
!! mostly we do this to exclude atoms who are involved in short |
971 |
< |
!! range interactions (bonds, bends, torsions), but we also need |
972 |
< |
!! to exclude some overcounted interactions that result from |
973 |
< |
!! the parallel decomposition |
974 |
< |
|
975 |
< |
#ifdef IS_MPI |
976 |
< |
!! in MPI, we have to look up the unique IDs for each atom |
977 |
< |
unique_id_1 = tagRow(atom1) |
978 |
< |
#else |
979 |
< |
!! in the normal loop, the atom numbers are unique |
980 |
< |
unique_id_1 = atom1 |
981 |
< |
#endif |
982 |
< |
|
983 |
< |
!! We were called with only one atom, so just check the global exclude |
984 |
< |
!! list for this atom |
985 |
< |
if (.not. present(atom2)) then |
986 |
< |
do i = 1, nExcludes_global |
987 |
< |
if (excludesGlobal(i) == unique_id_1) then |
988 |
< |
skip_it = .true. |
989 |
< |
return |
990 |
< |
end if |
991 |
< |
end do |
992 |
< |
return |
993 |
< |
end if |
994 |
< |
|
995 |
< |
#ifdef IS_MPI |
996 |
< |
unique_id_2 = tagColumn(atom2) |
997 |
< |
#else |
998 |
< |
unique_id_2 = atom2 |
999 |
< |
#endif |
946 |
> |
subroutine do_preforce(nlocal,pot) |
947 |
> |
integer :: nlocal |
948 |
> |
real( kind = dp ) :: pot |
949 |
> |
|
950 |
> |
if (FF_uses_EAM .and. SIM_uses_EAM) then |
951 |
> |
call calc_EAM_preforce_Frho(nlocal,pot) |
952 |
> |
endif |
953 |
> |
|
954 |
> |
|
955 |
> |
end subroutine do_preforce |
956 |
> |
|
957 |
> |
|
958 |
> |
subroutine get_interatomic_vector(q_i, q_j, d, r_sq) |
959 |
> |
|
960 |
> |
real (kind = dp), dimension(3) :: q_i |
961 |
> |
real (kind = dp), dimension(3) :: q_j |
962 |
> |
real ( kind = dp ), intent(out) :: r_sq |
963 |
> |
real( kind = dp ) :: d(3), scaled(3) |
964 |
> |
integer i |
965 |
> |
|
966 |
> |
d(1:3) = q_j(1:3) - q_i(1:3) |
967 |
> |
|
968 |
> |
! Wrap back into periodic box if necessary |
969 |
> |
if ( SIM_uses_PBC ) then |
970 |
> |
|
971 |
> |
if( .not.boxIsOrthorhombic ) then |
972 |
> |
! calc the scaled coordinates. |
973 |
> |
|
974 |
> |
scaled = matmul(HmatInv, d) |
975 |
> |
|
976 |
> |
! wrap the scaled coordinates |
977 |
> |
|
978 |
> |
scaled = scaled - anint(scaled) |
979 |
> |
|
980 |
> |
|
981 |
> |
! calc the wrapped real coordinates from the wrapped scaled |
982 |
> |
! coordinates |
983 |
> |
|
984 |
> |
d = matmul(Hmat,scaled) |
985 |
> |
|
986 |
> |
else |
987 |
> |
! calc the scaled coordinates. |
988 |
> |
|
989 |
> |
do i = 1, 3 |
990 |
> |
scaled(i) = d(i) * HmatInv(i,i) |
991 |
> |
|
992 |
> |
! wrap the scaled coordinates |
993 |
> |
|
994 |
> |
scaled(i) = scaled(i) - anint(scaled(i)) |
995 |
> |
|
996 |
> |
! calc the wrapped real coordinates from the wrapped scaled |
997 |
> |
! coordinates |
998 |
> |
|
999 |
> |
d(i) = scaled(i)*Hmat(i,i) |
1000 |
> |
enddo |
1001 |
> |
endif |
1002 |
> |
|
1003 |
> |
endif |
1004 |
> |
|
1005 |
> |
r_sq = dot_product(d,d) |
1006 |
> |
|
1007 |
> |
end subroutine get_interatomic_vector |
1008 |
> |
|
1009 |
> |
subroutine zero_work_arrays() |
1010 |
> |
|
1011 |
> |
#ifdef IS_MPI |
1012 |
> |
|
1013 |
> |
q_Row = 0.0_dp |
1014 |
> |
q_Col = 0.0_dp |
1015 |
|
|
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 |
1021 |
+ |
|
1022 |
+ |
A_Row = 0.0_dp |
1023 |
+ |
A_Col = 0.0_dp |
1024 |
+ |
|
1025 |
+ |
f_Row = 0.0_dp |
1026 |
+ |
f_Col = 0.0_dp |
1027 |
+ |
f_Temp = 0.0_dp |
1028 |
+ |
|
1029 |
+ |
t_Row = 0.0_dp |
1030 |
+ |
t_Col = 0.0_dp |
1031 |
+ |
t_Temp = 0.0_dp |
1032 |
+ |
|
1033 |
+ |
pot_Row = 0.0_dp |
1034 |
+ |
pot_Col = 0.0_dp |
1035 |
+ |
pot_Temp = 0.0_dp |
1036 |
+ |
|
1037 |
+ |
rf_Row = 0.0_dp |
1038 |
+ |
rf_Col = 0.0_dp |
1039 |
+ |
rf_Temp = 0.0_dp |
1040 |
+ |
|
1041 |
+ |
#endif |
1042 |
+ |
|
1043 |
+ |
if (FF_uses_EAM .and. SIM_uses_EAM) then |
1044 |
+ |
call clean_EAM() |
1045 |
+ |
endif |
1046 |
+ |
|
1047 |
+ |
rf = 0.0_dp |
1048 |
+ |
tau_Temp = 0.0_dp |
1049 |
+ |
virial_Temp = 0.0_dp |
1050 |
+ |
end subroutine zero_work_arrays |
1051 |
+ |
|
1052 |
+ |
function skipThisPair(atom1, atom2) result(skip_it) |
1053 |
+ |
integer, intent(in) :: atom1 |
1054 |
+ |
integer, intent(in), optional :: atom2 |
1055 |
+ |
logical :: skip_it |
1056 |
+ |
integer :: unique_id_1, unique_id_2 |
1057 |
+ |
integer :: me_i,me_j |
1058 |
+ |
integer :: i |
1059 |
+ |
|
1060 |
+ |
skip_it = .false. |
1061 |
+ |
|
1062 |
+ |
!! there are a number of reasons to skip a pair or a particle |
1063 |
+ |
!! mostly we do this to exclude atoms who are involved in short |
1064 |
+ |
!! range interactions (bonds, bends, torsions), but we also need |
1065 |
+ |
!! to exclude some overcounted interactions that result from |
1066 |
+ |
!! the parallel decomposition |
1067 |
+ |
|
1068 |
|
#ifdef IS_MPI |
1069 |
< |
!! this situation should only arise in MPI simulations |
1070 |
< |
if (unique_id_1 == unique_id_2) then |
1071 |
< |
skip_it = .true. |
1072 |
< |
return |
1073 |
< |
end if |
1167 |
< |
|
1168 |
< |
!! this prevents us from doing the pair on multiple processors |
1169 |
< |
if (unique_id_1 < unique_id_2) then |
1170 |
< |
if (mod(unique_id_1 + unique_id_2,2) == 0) then |
1171 |
< |
skip_it = .true. |
1172 |
< |
return |
1173 |
< |
endif |
1174 |
< |
else |
1175 |
< |
if (mod(unique_id_1 + unique_id_2,2) == 1) then |
1176 |
< |
skip_it = .true. |
1177 |
< |
return |
1178 |
< |
endif |
1179 |
< |
endif |
1069 |
> |
!! in MPI, we have to look up the unique IDs for each atom |
1070 |
> |
unique_id_1 = tagRow(atom1) |
1071 |
> |
#else |
1072 |
> |
!! in the normal loop, the atom numbers are unique |
1073 |
> |
unique_id_1 = atom1 |
1074 |
|
#endif |
1075 |
+ |
|
1076 |
+ |
!! We were called with only one atom, so just check the global exclude |
1077 |
+ |
!! list for this atom |
1078 |
+ |
if (.not. present(atom2)) then |
1079 |
+ |
do i = 1, nExcludes_global |
1080 |
+ |
if (excludesGlobal(i) == unique_id_1) then |
1081 |
+ |
skip_it = .true. |
1082 |
+ |
return |
1083 |
+ |
end if |
1084 |
+ |
end do |
1085 |
+ |
return |
1086 |
+ |
end if |
1087 |
+ |
|
1088 |
+ |
#ifdef IS_MPI |
1089 |
+ |
unique_id_2 = tagColumn(atom2) |
1090 |
+ |
#else |
1091 |
+ |
unique_id_2 = atom2 |
1092 |
+ |
#endif |
1093 |
+ |
|
1094 |
+ |
#ifdef IS_MPI |
1095 |
+ |
!! this situation should only arise in MPI simulations |
1096 |
+ |
if (unique_id_1 == unique_id_2) then |
1097 |
+ |
skip_it = .true. |
1098 |
+ |
return |
1099 |
+ |
end if |
1100 |
+ |
|
1101 |
+ |
!! this prevents us from doing the pair on multiple processors |
1102 |
+ |
if (unique_id_1 < unique_id_2) then |
1103 |
+ |
if (mod(unique_id_1 + unique_id_2,2) == 0) then |
1104 |
+ |
skip_it = .true. |
1105 |
+ |
return |
1106 |
+ |
endif |
1107 |
+ |
else |
1108 |
+ |
if (mod(unique_id_1 + unique_id_2,2) == 1) then |
1109 |
+ |
skip_it = .true. |
1110 |
+ |
return |
1111 |
+ |
endif |
1112 |
+ |
endif |
1113 |
+ |
#endif |
1114 |
+ |
|
1115 |
+ |
!! the rest of these situations can happen in all simulations: |
1116 |
+ |
do i = 1, nExcludes_global |
1117 |
+ |
if ((excludesGlobal(i) == unique_id_1) .or. & |
1118 |
+ |
(excludesGlobal(i) == unique_id_2)) then |
1119 |
+ |
skip_it = .true. |
1120 |
+ |
return |
1121 |
+ |
endif |
1122 |
+ |
enddo |
1123 |
+ |
|
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 |
+ |
|
1131 |
+ |
return |
1132 |
+ |
end function skipThisPair |
1133 |
|
|
1134 |
< |
!! the rest of these situations can happen in all simulations: |
1135 |
< |
do i = 1, nExcludes_global |
1136 |
< |
if ((excludesGlobal(i) == unique_id_1) .or. & |
1137 |
< |
(excludesGlobal(i) == unique_id_2)) then |
1138 |
< |
skip_it = .true. |
1139 |
< |
return |
1140 |
< |
endif |
1141 |
< |
enddo |
1142 |
< |
|
1143 |
< |
do i = 1, nExcludes_local |
1144 |
< |
if (excludesLocal(1,i) == unique_id_1) then |
1145 |
< |
if (excludesLocal(2,i) == unique_id_2) then |
1146 |
< |
skip_it = .true. |
1147 |
< |
return |
1148 |
< |
endif |
1149 |
< |
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 |
< |
|
1134 |
> |
function FF_UsesDirectionalAtoms() result(doesit) |
1135 |
> |
logical :: doesit |
1136 |
> |
doesit = FF_uses_dipoles .or. FF_uses_sticky .or. & |
1137 |
> |
FF_uses_GB .or. FF_uses_RF |
1138 |
> |
end function FF_UsesDirectionalAtoms |
1139 |
> |
|
1140 |
> |
function FF_RequiresPrepairCalc() result(doesit) |
1141 |
> |
logical :: doesit |
1142 |
> |
doesit = FF_uses_EAM |
1143 |
> |
end function FF_RequiresPrepairCalc |
1144 |
> |
|
1145 |
> |
function FF_RequiresPostpairCalc() result(doesit) |
1146 |
> |
logical :: doesit |
1147 |
> |
doesit = FF_uses_RF |
1148 |
> |
end function FF_RequiresPostpairCalc |
1149 |
> |
|
1150 |
|
#ifdef PROFILE |
1151 |
< |
function getforcetime() result(totalforcetime) |
1152 |
< |
real(kind=dp) :: totalforcetime |
1153 |
< |
totalforcetime = forcetime |
1154 |
< |
end function getforcetime |
1151 |
> |
function getforcetime() result(totalforcetime) |
1152 |
> |
real(kind=dp) :: totalforcetime |
1153 |
> |
totalforcetime = forcetime |
1154 |
> |
end function getforcetime |
1155 |
|
#endif |
1156 |
+ |
|
1157 |
+ |
!! This cleans componets of force arrays belonging only to fortran |
1158 |
|
|
1159 |
< |
!! This cleans componets of force arrays belonging only to fortran |
1160 |
< |
|
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 |
+ |
|