Skip to content

Commit

Permalink
Fix some warnings (#1139)
Browse files Browse the repository at this point in the history
* Fix undefined behavior warning in constrain_pot.f90

Signed-off-by: Igor S. Gerasimov <[email protected]>

* Compute once those that does not depend on k

Signed-off-by: Igor S. Gerasimov <[email protected]>

* Remove legacy comma

Signed-off-by: Igor S. Gerasimov <[email protected]>

* Proper interface for eigsort4

Signed-off-by: Igor S. Gerasimov <[email protected]>

* Fix shortest_distance interface

Signed-off-by: Igor S. Gerasimov <[email protected]>

---------

Signed-off-by: Igor S. Gerasimov <[email protected]>
  • Loading branch information
foxtran authored Dec 22, 2024
1 parent 99b3583 commit c3cfd38
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
51 changes: 26 additions & 25 deletions src/constrain_pot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ subroutine qpothess2(fix,n,at,xyz,h)
! calculate hessian
do i = 1, fix%n !loop over all atoms
ii = (fix%atoms(i)-1)*3
do k = 1, 3 !loop diagonal elements (xyz components)
do j = 1, fix%n !inner loop for sum over all atoms
if (i.ne.j) then
rij = xyz(:,fix%atoms(j))-xyz(:,fix%atoms(i))
r = norm2(rij)
r2 = r*r
r3 = r2*r
ij = lin(i-1,j-1)+1
r0 = fix%val(ij)
dr = r-r0
do j = 1, fix%n !inner loop for sum over all atoms
if (i.ne.j) then
rij = xyz(:,fix%atoms(j))-xyz(:,fix%atoms(i))
r = norm2(rij)
r2 = r*r
r3 = r2*r
ij = lin(i-1,j-1)+1
r0 = fix%val(ij)
dr = r-r0
do k = 1, 3 !loop diagonal elements (xyz components)
dx = xyz(k,fix%atoms(i))-xyz(k,fix%atoms(j))
dx2 = dx*dx
iik = lin(ii+k,ii+k)
Expand All @@ -123,32 +123,33 @@ subroutine qpothess2(fix,n,at,xyz,h)
iikl = lin(ii+k,ii+l)
h(iikl) = h(iikl) + 2.0_wp*fix%fc*r0*dx*dy/r3
enddo !end loop same-atom block-diagonal elements
endif
enddo !end inner loop for sum over all atoms
do j = i+1, fix%n !loop over the rest (mixed atoms)
rij = xyz(:,fix%atoms(j))-xyz(:,fix%atoms(i))
r = norm2(rij)
r2 = r*r
r3 = r2*r
ij = lin(i-1,j-1)+1
r0 = fix%val(ij)
dr = r-r0
jj = (fix%atoms(j)-1)*3
enddo !end loop diagonal elements (xyz components)
endif
enddo !end inner loop for sum over all atoms
do j = i+1, fix%n !loop over the rest (mixed atoms)
rij = xyz(:,fix%atoms(j))-xyz(:,fix%atoms(i))
r = norm2(rij)
r2 = r*r
r3 = r2*r
ij = lin(i-1,j-1)+1
r0 = fix%val(ij)
dr = r-r0
jj = (fix%atoms(j)-1)*3
do k = 1, 3 !loop diagonal elements (xyz components)
dx = xyz(k,fix%atoms(i))-xyz(k,fix%atoms(j))
do m = 1, 3
if (k.eq.m) then !same component case
dx = xyz(k,fix%atoms(i))-xyz(k,fix%atoms(j))
dx2 = dx*dx
ijk = lin(ii+k,jj+k)
h(ijk) = h(ijk) - 2.0_wp*fix%fc*(1.0_wp+dx2/r2-dx2*dr/r3-r0/r)
else !different component case
dx = xyz(k,fix%atoms(i))-xyz(k,fix%atoms(j))
dy = xyz(m,fix%atoms(i))-xyz(m,fix%atoms(j))
ikjm = lin(ii+k,jj+m)
h(ikjm) = h(ikjm) - 2.0_wp*fix%fc*r0*dx*dy/r3
endif
enddo
enddo
enddo !end loop diagonal elements (xyz components)
enddo !end loop diagonal elements (xyz components)
enddo
enddo !end loop atoms

contains
Expand Down
22 changes: 7 additions & 15 deletions src/gfnff/frag_hess.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,17 @@ function shortest_distance(nspin, start, goal, numnb, neighbours, input_distance
integer, intent(in) :: start
integer, intent(in) :: goal
integer, intent(in) :: numnb
integer, intent(in) :: neighbours(20, nspin)
integer, intent(in) :: neighbours(numnb, nspin, 1)
real(wp), intent(in) :: input_distances(nspin, nspin)
logical, intent(out) :: visited(nspin)
integer, intent(out) :: precessor(nspin)
integer :: current
integer :: neighbour
integer :: i_neighbours
integer :: bonds
real(wp) :: alt_dist
real(wp) :: distance(nspin)
end function shortest_distance
subroutine eigsort4(lab,ew,u)
subroutine eigsort4(lab,u,ew)
use xtb_mctc_accuracy, only : sp
implicit none
integer :: ii,k, j, i
real(sp) :: pp, hilf
integer :: lab
real(sp) :: ew(lab)
real(sp) :: u(lab,lab)
integer, intent(in) :: lab
real(sp), intent(inout) :: u(lab,lab)
real(sp), intent(inout) :: ew(lab)
end subroutine eigsort4
end interface

Expand Down Expand Up @@ -486,9 +478,9 @@ subroutine eigsort4(lab,u,ew)
integer :: ii,k, j, i
real(sp) :: pp, hilf

integer, intent(in) :: lab
real(sp), intent(inout) :: ew(lab)
integer, intent(in) :: lab
real(sp), intent(inout) :: u(lab,lab)
real(sp), intent(inout) :: ew(lab)

do ii = 2, lab
i = ii - 1
Expand Down
2 changes: 1 addition & 1 deletion src/gfnff/gfnff_eg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ subroutine egbond_hb(i,iat,jat,iTr,rab,rij,drij,drijdcn,hb_cn,hb_dcn,n,at,xyz,e,
hbH=jat
hbA=iat
else
write(*,'(10x,"No H-atom found in this bond ",i0,1x,i0)'), iat,jat
write(*,'(10x,"No H-atom found in this bond ",i0,1x,i0)') iat,jat
return
end if

Expand Down

0 comments on commit c3cfd38

Please sign in to comment.