Skip to content

Commit

Permalink
Changed nearest neighbours to compute pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
BCHamstra committed Oct 23, 2023
1 parent 83f8331 commit 5aafaf1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions LIBSTELL/Sources/Modules/mumaterial_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,18 @@ SUBROUTINE mumaterial_init(getBfld, offset, comm)
IF (maxDist .gt. 0.d0) THEN ! Double approach since not using neighbours is faster for smaller objects
WRITE (*,*) "Determining nearest neighbours"
ALLOCATE(N_store(ntet))
DO i = 1, ntet
DO i = 1, ntet
ALLOCATE(nearestNeighbours(i)%idx(1))
nearestNeighbours(i)%idx(1) = i
DO j = 2, ntet
END DO

DO i = 1, ntet
IF (MOD(i, 1000) .eq. 0) THEN
WRITE(*,'(A6,I8,A9,F6.2,A1)') "Tile: ", i, "Complete: ", i*1.d2/ntet, '%'
END IF
DO j = i+1, ntet
IF (i .ne. j .AND. NORM2(tet_cen(:,i)-tet_cen(:,j)) .lt. maxDist) THEN
! set j as nearest neighbour for i
n = SIZE(nearestNeighbours(i)%idx)
ALLOCATE(neighbours_temp(n))
neighbours_temp = nearestNeighbours(i)%idx
Expand All @@ -319,13 +326,26 @@ SUBROUTINE mumaterial_init(getBfld, offset, comm)
nearestNeighbours(i)%idx(1:n) = neighbours_temp
nearestNeighbours(i)%idx(n+1) = j
DEALLOCATE(neighbours_temp)

! set i as nearest neighbour for j
n = SIZE(nearestNeighbours(j)%idx)
ALLOCATE(neighbours_temp(n))
neighbours_temp = nearestNeighbours(j)%idx
DEALLOCATE(nearestNeighbours(j)%idx)
ALLOCATE(nearestNeighbours(j)%idx(n+1))
nearestNeighbours(j)%idx(1:n) = neighbours_temp
nearestNeighbours(j)%idx(n+1) = i
DEALLOCATE(neighbours_temp)
END IF
END DO
ALLOCATE(N_store(i)%N(3,3,SIZE(nearestNeighbours(i)%idx)))
END DO

WRITE(*,*) "Determining N-tensors"
DO i = 1, ntet
IF (MOD(i, 1000) .eq. 0) THEN
WRITE(*,'(A6,I8,A9,F6.2,A1)') "Tile: ", i, "Complete: ", i*1.d2/ntet, '%'
END IF
DO j = 1, SIZE(nearestNeighbours(i)%idx)
CALL mumaterial_getN(vertex(:,tet(1,nearestNeighbours(i)%idx(j))), vertex(:,tet(2,nearestNeighbours(i)%idx(j))), vertex(:,tet(3,nearestNeighbours(i)%idx(j))), vertex(:,tet(4,nearestNeighbours(i)%idx(j))), tet_cen(:,i), N_store(i)%N(:,:,j))
END DO
Expand Down

0 comments on commit 5aafaf1

Please sign in to comment.