MFIX  2016-1
nsquare.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2 ! C
3 ! Module name: NSQUARE C
5 ! C
6 ! C
7 ! Author: Jay Boyalakuntla Date: 12-Jun-04 C
8 ! Reviewer: Sreekanth Pannala Date: 09-Nov-06 C
9 ! C
10 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
11 
12  SUBROUTINE nsquare
13 
14  use des_allocate
15  use des_bc
16  use des_thermo
17  use discretelement
18  use functions
19  use geometry, only: do_k, xlength, ylength, zlength
20  use param1, only: zero
21 
22  IMPLICIT NONE
23 
24 !-----------------------------------------------
25 ! Local variables
26 !-----------------------------------------------
27  INTEGER I, J, K
28  INTEGER L, LL, CC
29  DOUBLE PRECISION DISTVEC(3), DIST, R_LM
30 ! Temporary variables to adjust particle position in event of periodic
31 ! boundaries
32  DOUBLE PRECISION XPOS(2), YPOS(2), ZPOS(2), TMPPOS(3)
33 ! Max loop limit in each coordinate direction
34  INTEGER II, JJ, KK
35 ! Index to track accounted for particles
36  INTEGER PC
37 ! Index to track unaccounted for particles
38  INTEGER PNPC
39 !-----------------------------------------------
40 
41  pc=1
42  DO l=1, max_pip
43 
44  neighbor_index(l) = 1
45  if (l .gt. 1) neighbor_index(l) = neighbor_index(l-1)
46 
47  IF(pc .GE. pip ) EXIT
48  IF(is_nonexistent(l)) cycle
49 
50  pnpc = pip - pc
51  DO ll = l+1, max_pip
52 
53  IF(pnpc .LE. 0) EXIT
54  IF(is_nonexistent(ll)) cycle
55 
56  r_lm = des_radius(l) + des_radius(ll)
57  r_lm = factor_rlm*r_lm
58 
59 ! the following section adjusts the neighbor check routine when
60 ! any boundary is periodic
61 ! ------------------------------
62  IF (des_periodic_walls) THEN
63  xpos(:) = des_pos_new(ll,1)
64  ypos(:) = des_pos_new(ll,2)
65  ii = 1
66  jj = 1
67  kk = 1
68 
69  IF(des_periodic_walls_x) THEN
70  IF (des_pos_new(l,1) + r_lm > xlength) THEN
71  ii = 2
72  xpos(ii) = des_pos_new(ll,1) + xlength
73  ELSEIF (des_pos_new(l,1) - r_lm < zero) THEN
74  ii = 2
75  xpos(ii) = des_pos_new(ll,1) - xlength
76  ENDIF
77  ENDIF
78  IF(des_periodic_walls_y) THEN
79  IF (des_pos_new(l,2) + r_lm > ylength) THEN
80  jj = 2
81  ypos(jj) = des_pos_new(ll,2) + ylength
82  ELSEIF (des_pos_new(l,2) - r_lm < ylength) THEN
83  jj = 2
84  ypos(jj) = des_pos_new(ll,2) - ylength
85  ENDIF
86  ENDIF
87  IF(do_k) THEN
88  zpos(:) = des_pos_new(ll,3)
89  IF(des_periodic_walls_z) THEN
90  IF (des_pos_new(l,3) + r_lm > zlength) THEN
91  kk = 2
92  zpos(kk) = des_pos_new(ll,3) + zlength
93  ELSEIF (des_pos_new(l,3) - r_lm < zero) THEN
94  kk = 2
95  zpos(kk) = des_pos_new(ll,3) - zlength
96  ENDIF
97  ENDIF
98  ENDIF
99 
100 ! if particle L is within R_LM of a periodic boundary then check
101 ! particles LL current position and its position shifted to the
102 ! opposite boundary for neighbor contact
103  outer: DO i = 1,ii
104  DO j = 1,jj
105  tmppos(1) = xpos(i)
106  tmppos(2) = ypos(j)
107  IF (do_k) THEN
108  DO k = 1,kk
109  tmppos(3) = zpos(k)
110  distvec(:) = tmppos(:) - des_pos_new(l,:)
111  dist = dot_product(distvec,distvec)
112  IF (dist.LE.r_lm) EXIT outer
113  ENDDO
114  ELSE
115  distvec(:) = tmppos(:) - des_pos_new(l,:)
116  dist = dot_product(distvec,distvec)
117  IF (dist.LE.r_lm) EXIT outer
118  ENDIF
119  ENDDO
120  ENDDO outer
121 
122  ELSE ! if .not.des_periodic_walls
123  distvec(:) = des_pos_new(ll,:) - des_pos_new(l,:)
124  dist = dot_product(distvec,distvec)
125  ENDIF ! endif des_periodic_walls
126 ! ------------------------------
127 
128  IF (dist < r_lm**2) THEN
129  cc = add_pair(l, ll)
130  ENDIF
131  pnpc = pnpc - 1
132  ENDDO ! end loop over LL
133 
134  pc = pc + 1
135  ENDDO ! end loop over L
136 
137  RETURN
138  END SUBROUTINE nsquare
subroutine nsquare
Purpose: DES - N-Square neighbor search.
Definition: nsquare.f:13
double precision xlength
Definition: geometry_mod.f:33
logical do_k
Definition: geometry_mod.f:30
double precision ylength
Definition: geometry_mod.f:35
double precision, parameter zero
Definition: param1_mod.f:27
double precision zlength
Definition: geometry_mod.f:37
double precision function, public add_pair(ii, jj)