-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmod_detect_nearest_neighbor.f90
107 lines (88 loc) · 2.71 KB
/
mod_detect_nearest_neighbor.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module mod_detect_nearest_neighbor
use mod_read_gmsh, only: nbelm,nbnode,coord_nodes,id_nodes
use mod_cell_2D
implicit none
contains
subroutine detect_neighbor
implicit none
integer(4) :: i,j,k,t
integer(4) :: idnode1,idnode2
integer(4) :: cnt
type(cell_2D),pointer :: pc => null()
type(cell_2D),pointer :: pr => null()
! do i = 1, nbelm
! do k = 1, 4
! write(*,*) cell(i)%p%vertex(k)%ident
! end do
! write(*,*)
! end do
do i = 1, nbelm
idnode1 = cell(i)%p%vertex(1)%ident
idnode2 = cell(i)%p%vertex(2)%ident
pc => cell(i)%p
do j = 1, nbelm
pr => cell(j)%p
cnt = 0
if (associated(pc,pr)) cycle
do t = 1, 4
if (idnode1 == pr%vertex(t)%ident) cnt = cnt + 1
if (idnode2 == pr%vertex(t)%ident) cnt = cnt + 1
end do
if (cnt == 2) then
pc%neighbor1 => pr
end if
end do
end do
do i = 1, nbelm
idnode1 = cell(i)%p%vertex(2)%ident
idnode2 = cell(i)%p%vertex(3)%ident
pc => cell(i)%p
do j = 1, nbelm
pr => cell(j)%p
cnt = 0
if (associated(pc,pr)) cycle
do t = 1, 4
if (idnode1 == pr%vertex(t)%ident) cnt = cnt + 1
if (idnode2 == pr%vertex(t)%ident) cnt = cnt + 1
end do
if (cnt == 2) then
pc%neighbor2 => pr
end if
end do
end do
do i = 1, nbelm
idnode1 = cell(i)%p%vertex(3)%ident
idnode2 = cell(i)%p%vertex(4)%ident
pc => cell(i)%p
do j = 1, nbelm
pr => cell(j)%p
cnt = 0
if (associated(pc,pr)) cycle
do t = 1, 4
if (idnode1 == pr%vertex(t)%ident) cnt = cnt + 1
if (idnode2 == pr%vertex(t)%ident) cnt = cnt + 1
end do
if (cnt == 2) then
pc%neighbor3 => pr
end if
end do
end do
do i = 1, nbelm
idnode1 = cell(i)%p%vertex(4)%ident
idnode2 = cell(i)%p%vertex(1)%ident
pc => cell(i)%p
do j = 1, nbelm
pr => cell(j)%p
cnt = 0
if (associated(pc,pr)) cycle
do t = 1, 4
if (idnode1 == pr%vertex(t)%ident) cnt = cnt + 1
if (idnode2 == pr%vertex(t)%ident) cnt = cnt + 1
end do
if (cnt == 2) then
pc%neighbor4 => pr
end if
end do
end do
end subroutine
end module