4 |
|
|
5 |
|
!! @author Charles F. Vardeman II |
6 |
|
!! @author Matthew Meineke |
7 |
< |
!! @version $Id: do_Forces.F90,v 1.2 2003-03-21 22:11:50 chuckv Exp $, $Date: 2003-03-21 22:11:50 $, $Name: not supported by cvs2svn $, $Revision: 1.2 $ |
7 |
> |
!! @version $Id: do_Forces.F90,v 1.20 2003-07-15 22:22:41 mmeineke Exp $, $Date: 2003-07-15 22:22:41 $, $Name: not supported by cvs2svn $, $Revision: 1.20 $ |
8 |
|
|
9 |
|
module do_Forces |
10 |
|
use force_globals |
140 |
|
|
141 |
|
if (FF_uses_GB .and. FF_uses_LJ) then |
142 |
|
endif |
143 |
+ |
if (.not. do_forces_initialized) then |
144 |
+ |
!! Create neighbor lists |
145 |
+ |
call expandNeighborList(getNlocal(), my_status) |
146 |
+ |
if (my_Status /= 0) then |
147 |
+ |
write(default_error,*) "SimSetup: ExpandNeighborList returned error." |
148 |
+ |
thisStat = -1 |
149 |
+ |
return |
150 |
+ |
endif |
151 |
+ |
endif |
152 |
|
|
144 |
– |
|
153 |
|
do_forces_initialized = .true. |
154 |
|
|
155 |
|
end subroutine init_FF |
175 |
|
logical ( kind = 2) :: do_pot_c, do_stress_c |
176 |
|
logical :: do_pot |
177 |
|
logical :: do_stress |
178 |
< |
#ifdef IS_MPI |
178 |
> |
#ifdef IS_MPI |
179 |
|
real( kind = DP ) :: pot_local |
180 |
|
integer :: nrow |
181 |
|
integer :: ncol |
185 |
|
logical :: update_nlist |
186 |
|
integer :: i, j, jbeg, jend, jnab |
187 |
|
integer :: nlist |
188 |
< |
real( kind = DP ) :: rijsq, rlistsq, rcutsq, rlist, rcut |
188 |
> |
real( kind = DP ) :: rijsq, rlistsq, rcutsq, rlist, rcut, rrf, rt, dielect |
189 |
|
real(kind=dp),dimension(3) :: d |
190 |
|
real(kind=dp) :: rfpot, mu_i, virial |
191 |
|
integer :: me_i |
193 |
|
integer :: neighborListSize |
194 |
|
integer :: listerror, error |
195 |
|
integer :: localError |
196 |
+ |
|
197 |
|
|
198 |
|
!! initialize local variables |
199 |
|
|
200 |
|
#ifdef IS_MPI |
201 |
+ |
pot_local = 0.0_dp |
202 |
|
nlocal = getNlocal() |
203 |
|
nrow = getNrow(plan_row) |
204 |
|
ncol = getNcol(plan_col) |
206 |
|
nlocal = getNlocal() |
207 |
|
natoms = nlocal |
208 |
|
#endif |
209 |
< |
|
209 |
> |
|
210 |
|
call getRcut(rcut,rc2=rcutsq) |
211 |
|
call getRlist(rlist,rlistsq) |
212 |
+ |
rt = getRt() |
213 |
+ |
rrf = getRrf() |
214 |
+ |
dielect = getDielect() |
215 |
+ |
|
216 |
+ |
if( FF_uses_LJ) then |
217 |
+ |
call lj_new_rcut( rcut, localError ) |
218 |
+ |
if ( localError .ne. 0 ) then |
219 |
+ |
error = -1 |
220 |
+ |
return |
221 |
+ |
end if |
222 |
+ |
end if |
223 |
+ |
|
224 |
+ |
|
225 |
+ |
if( FF_uses_dipoles ) then |
226 |
+ |
|
227 |
+ |
if( rcut .lt. rrf ) then |
228 |
+ |
rcut = rrf |
229 |
+ |
rlist = rcut + 1.0_dp |
230 |
+ |
rcutsq = rcut * rcut |
231 |
+ |
rlistsq = rlist * rlist |
232 |
+ |
end if |
233 |
+ |
|
234 |
+ |
call initialize_dipole( rrf, rt ) |
235 |
+ |
end if |
236 |
+ |
|
237 |
+ |
if( FF_uses_RF )call initialize_rf( rrf, rt, dielect ) |
238 |
|
|
239 |
+ |
|
240 |
|
call check_initialization(localError) |
241 |
|
if ( localError .ne. 0 ) then |
242 |
|
error = -1 |
282 |
|
|
283 |
|
!! save current configuration, construct neighbor list, |
284 |
|
!! and calculate forces |
285 |
< |
call saveNeighborList(q) |
285 |
> |
call saveNeighborList(nlocal, q) |
286 |
|
|
287 |
|
neighborListSize = size(list) |
288 |
|
nlist = 0 |
314 |
|
|
315 |
|
if (rijsq < rcutsq) then |
316 |
|
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
317 |
< |
u_l, A, f, t,pot) |
317 |
> |
u_l, A, f, t, pot_local) |
318 |
|
endif |
319 |
|
endif |
320 |
|
enddo inner |
336 |
|
|
337 |
|
call get_interatomic_vector(q_Row(:,i), q_Col(:,j), d, rijsq) |
338 |
|
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
339 |
< |
u_l, A, f, t,pot) |
339 |
> |
u_l, A, f, t, pot_local) |
340 |
|
|
341 |
|
enddo |
342 |
|
endif |
349 |
|
|
350 |
|
! save current configuration, contruct neighbor list, |
351 |
|
! and calculate forces |
352 |
< |
call saveNeighborList(q) |
352 |
> |
call saveNeighborList(natoms, q) |
353 |
|
|
354 |
|
neighborListSize = size(list) |
355 |
|
|
383 |
|
|
384 |
|
if (rijsq < rcutsq) then |
385 |
|
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
386 |
< |
u_l, A, f, t,pot) |
386 |
> |
u_l, A, f, t, pot) |
387 |
|
endif |
388 |
|
endif |
389 |
|
enddo inner |
405 |
|
|
406 |
|
call get_interatomic_vector(q(:,i), q(:,j), d, rijsq) |
407 |
|
call do_pair(i, j, rijsq, d, do_pot, do_stress, & |
408 |
< |
u_l, A, f, t,pot) |
408 |
> |
u_l, A, f, t, pot) |
409 |
|
|
410 |
|
enddo |
411 |
|
endif |
418 |
|
|
419 |
|
#ifdef IS_MPI |
420 |
|
!!distribute forces |
421 |
< |
|
422 |
< |
call scatter(f_Row,f,plan_row3d) |
421 |
> |
|
422 |
> |
f_temp = 0.0_dp |
423 |
> |
call scatter(f_Row,f_temp,plan_row3d) |
424 |
> |
do i = 1,nlocal |
425 |
> |
f(1:3,i) = f(1:3,i) + f_temp(1:3,i) |
426 |
> |
end do |
427 |
> |
|
428 |
> |
f_temp = 0.0_dp |
429 |
|
call scatter(f_Col,f_temp,plan_col3d) |
430 |
|
do i = 1,nlocal |
431 |
|
f(1:3,i) = f(1:3,i) + f_temp(1:3,i) |
432 |
|
end do |
433 |
|
|
434 |
|
if (FF_UsesDirectionalAtoms() .and. SimUsesDirectionalAtoms()) then |
435 |
< |
call scatter(t_Row,t,plan_row3d) |
435 |
> |
t_temp = 0.0_dp |
436 |
> |
call scatter(t_Row,t_temp,plan_row3d) |
437 |
> |
do i = 1,nlocal |
438 |
> |
t(1:3,i) = t(1:3,i) + t_temp(1:3,i) |
439 |
> |
end do |
440 |
> |
t_temp = 0.0_dp |
441 |
|
call scatter(t_Col,t_temp,plan_col3d) |
442 |
|
|
443 |
|
do i = 1,nlocal |
448 |
|
if (do_pot) then |
449 |
|
! scatter/gather pot_row into the members of my column |
450 |
|
call scatter(pot_Row, pot_Temp, plan_row) |
451 |
< |
|
451 |
> |
|
452 |
|
! scatter/gather pot_local into all other procs |
453 |
|
! add resultant to get total pot |
454 |
|
do i = 1, nlocal |
455 |
|
pot_local = pot_local + pot_Temp(i) |
456 |
|
enddo |
457 |
+ |
|
458 |
+ |
pot_Temp = 0.0_DP |
459 |
|
|
410 |
– |
pot_Temp = 0.0_DP |
411 |
– |
|
460 |
|
call scatter(pot_Col, pot_Temp, plan_col) |
461 |
|
do i = 1, nlocal |
462 |
|
pot_local = pot_local + pot_Temp(i) |
463 |
|
enddo |
464 |
< |
|
464 |
> |
|
465 |
|
endif |
466 |
|
#endif |
467 |
|
|
509 |
|
#ifdef IS_MPI |
510 |
|
|
511 |
|
if (do_pot) then |
512 |
< |
pot = pot_local |
512 |
> |
pot = pot + pot_local |
513 |
|
!! we assume the c code will do the allreduce to get the total potential |
514 |
|
!! we could do it right here if we needed to... |
515 |
|
endif |
516 |
|
|
517 |
|
if (do_stress) then |
518 |
< |
call mpi_allreduce(tau, tau_Temp,9,mpi_double_precision,mpi_sum, & |
518 |
> |
call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, & |
519 |
|
mpi_comm_world,mpi_err) |
520 |
< |
call mpi_allreduce(virial, virial_Temp,1,mpi_double_precision,mpi_sum, & |
520 |
> |
call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, & |
521 |
|
mpi_comm_world,mpi_err) |
522 |
|
endif |
523 |
|
|
532 |
|
|
533 |
|
end subroutine do_force_loop |
534 |
|
|
535 |
< |
subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t,pot) |
535 |
> |
subroutine do_pair(i, j, rijsq, d, do_pot, do_stress, u_l, A, f, t, pot) |
536 |
|
|
537 |
|
real( kind = dp ) :: pot |
538 |
< |
real( kind = dp ), dimension(:,:) :: u_l |
539 |
< |
real (kind=dp), dimension(:,:) :: A |
540 |
< |
real (kind=dp), dimension(:,:) :: f |
541 |
< |
real (kind=dp), dimension(:,:) :: t |
538 |
> |
real( kind = dp ), dimension(3,getNlocal()) :: u_l |
539 |
> |
real (kind=dp), dimension(9,getNlocal()) :: A |
540 |
> |
real (kind=dp), dimension(3,getNlocal()) :: f |
541 |
> |
real (kind=dp), dimension(3,getNlocal()) :: t |
542 |
|
|
543 |
|
logical, intent(inout) :: do_pot, do_stress |
544 |
|
integer, intent(in) :: i, j |
554 |
|
r = sqrt(rijsq) |
555 |
|
|
556 |
|
#ifdef IS_MPI |
557 |
+ |
if (tagRow(i) .eq. tagColumn(j)) then |
558 |
+ |
write(0,*) 'do_pair is doing', i , j, tagRow(i), tagColumn(j) |
559 |
+ |
endif |
560 |
|
|
561 |
|
me_i = atid_row(i) |
562 |
|
me_j = atid_col(j) |
615 |
|
endif |
616 |
|
endif |
617 |
|
|
618 |
+ |
|
619 |
+ |
|
620 |
|
end subroutine do_pair |
621 |
|
|
622 |
|
|
625 |
|
real (kind = dp), dimension(3) :: q_i |
626 |
|
real (kind = dp), dimension(3) :: q_j |
627 |
|
real ( kind = dp ), intent(out) :: r_sq |
628 |
< |
real( kind = dp ) :: d(3) |
629 |
< |
real( kind = dp ) :: d_old(3) |
630 |
< |
d(1:3) = q_i(1:3) - q_j(1:3) |
631 |
< |
d_old = d |
628 |
> |
real( kind = dp ) :: d(3), scaled(3) |
629 |
> |
integer i |
630 |
> |
|
631 |
> |
d(1:3) = q_j(1:3) - q_i(1:3) |
632 |
> |
|
633 |
|
! Wrap back into periodic box if necessary |
634 |
|
if ( SimUsesPBC() ) then |
635 |
+ |
|
636 |
+ |
if( .not.boxIsOrthorhombic ) then |
637 |
+ |
! calc the scaled coordinates. |
638 |
+ |
|
639 |
+ |
scaled = matmul(HmatInv, d) |
640 |
+ |
|
641 |
+ |
! wrap the scaled coordinates |
642 |
|
|
643 |
< |
d(1:3) = d(1:3) - box(1:3) * sign(1.0_dp,d(1:3)) * & |
644 |
< |
int(abs(d(1:3)/box(1:3)) + 0.5_dp) |
643 |
> |
scaled = scaled - anint(scaled) |
644 |
> |
|
645 |
> |
|
646 |
> |
! calc the wrapped real coordinates from the wrapped scaled |
647 |
> |
! coordinates |
648 |
> |
|
649 |
> |
d = matmul(Hmat,scaled) |
650 |
> |
|
651 |
> |
else |
652 |
> |
! calc the scaled coordinates. |
653 |
> |
|
654 |
> |
do i = 1, 3 |
655 |
> |
scaled(i) = d(i) * HmatInv(i,i) |
656 |
> |
|
657 |
> |
! wrap the scaled coordinates |
658 |
> |
|
659 |
> |
scaled(i) = scaled(i) - anint(scaled(i)) |
660 |
> |
|
661 |
> |
! calc the wrapped real coordinates from the wrapped scaled |
662 |
> |
! coordinates |
663 |
|
|
664 |
+ |
d(i) = scaled(i)*Hmat(i,i) |
665 |
+ |
enddo |
666 |
+ |
endif |
667 |
+ |
|
668 |
|
endif |
669 |
+ |
|
670 |
|
r_sq = dot_product(d,d) |
671 |
< |
|
671 |
> |
|
672 |
|
end subroutine get_interatomic_vector |
673 |
< |
|
673 |
> |
|
674 |
|
subroutine check_initialization(error) |
675 |
|
integer, intent(out) :: error |
676 |
|
|
727 |
|
rf = 0.0_dp |
728 |
|
tau_Temp = 0.0_dp |
729 |
|
virial_Temp = 0.0_dp |
646 |
– |
|
730 |
|
end subroutine zero_work_arrays |
731 |
|
|
732 |
|
function skipThisPair(atom1, atom2) result(skip_it) |
770 |
|
#else |
771 |
|
unique_id_2 = atom2 |
772 |
|
#endif |
773 |
< |
|
773 |
> |
|
774 |
|
#ifdef IS_MPI |
775 |
|
!! this situation should only arise in MPI simulations |
776 |
|
if (unique_id_1 == unique_id_2) then |
780 |
|
|
781 |
|
!! this prevents us from doing the pair on multiple processors |
782 |
|
if (unique_id_1 < unique_id_2) then |
783 |
< |
if (mod(unique_id_1 + unique_id_2,2) == 0) skip_it = .true. |
784 |
< |
return |
783 |
> |
if (mod(unique_id_1 + unique_id_2,2) == 0) then |
784 |
> |
skip_it = .true. |
785 |
> |
return |
786 |
> |
endif |
787 |
|
else |
788 |
< |
if (mod(unique_id_1 + unique_id_2,2) == 1) skip_it = .true. |
789 |
< |
return |
788 |
> |
if (mod(unique_id_1 + unique_id_2,2) == 1) then |
789 |
> |
skip_it = .true. |
790 |
> |
return |
791 |
> |
endif |
792 |
|
endif |
793 |
|
#endif |
794 |
< |
|
794 |
> |
|
795 |
|
!! the rest of these situations can happen in all simulations: |
796 |
|
do i = 1, nExcludes_global |
797 |
|
if ((excludesGlobal(i) == unique_id_1) .or. & |
800 |
|
return |
801 |
|
endif |
802 |
|
enddo |
803 |
< |
|
803 |
> |
|
804 |
|
do i = 1, nExcludes_local |
805 |
|
if (excludesLocal(1,i) == unique_id_1) then |
806 |
|
if (excludesLocal(2,i) == unique_id_2) then |