CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
near3d.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine near3d (xo, yo, zo, x, y, z, nx, ny, nz, xp, yp, zp, n, neighbor, k)
 

Function/Subroutine Documentation

◆ near3d()

subroutine near3d ( real*8, dimension(n), intent(in)  xo,
real*8, dimension(n), intent(in)  yo,
real*8, dimension(n), intent(in)  zo,
real*8, dimension(n), intent(in)  x,
real*8, dimension(n), intent(in)  y,
real*8, dimension(n), intent(in)  z,
integer, dimension(n), intent(in)  nx,
integer, dimension(n), intent(in)  ny,
integer, dimension(n), intent(in)  nz,
real*8, intent(in)  xp,
real*8, intent(in)  yp,
real*8, intent(in)  zp,
integer, intent(in)  n,
integer, dimension(k), intent(inout)  neighbor,
integer, intent(inout)  k 
)
20 !
21 ! determines the k closest nodes out of n with coordinates in
22 ! (xo,yo,zo) to the point with coordinates (xp,yp,zp);
23 !
24  implicit none
25 !
26  integer n,nx(n),ny(n),nz(n),ir(k+6),nr,neighbor(k),kflag,iflag,
27  & i,j,k,m,id,idx,idy,idz,eight,idummy,node,l
28 !
29  real*8 x(n),y(n),z(n),xo(n),yo(n),zo(n),xp,yp,zp,r(k+6),xr,yr,
30  & zr,c(8),dd,xw,xe,ys,yn,zb,zt,sqrt_rmaxini
31 !
32  intent(in) xo,yo,zo,x,y,z,nx,ny,nz,xp,yp,zp,n
33 !
34  intent(inout) k,neighbor
35 !
36  iflag=1
37  kflag=2
38  eight=8
39 !
40  if(k.gt.n) then
41  k=n
42  endif
43 !
44 ! identify position of xp, yp and zp
45 !
46  call ident(x,xp,n,idx)
47  call ident(y,yp,n,idy)
48  call ident(z,zp,n,idz)
49 !
50 ! initialization of r and ir
51 !
52  do i=1,k
53  xr=xo(i)-xp
54  yr=yo(i)-yp
55  zr=zo(i)-zp
56  r(i)=xr*xr+yr*yr+zr*zr
57  ir(i)=i
58  enddo
59  call dsort(r,ir,k,kflag)
60  sqrt_rmaxini=1.d30
61 !
62 ! initialization of the maximal distance in each direction
63 !
64  xw=0.d0
65  xe=0.d0
66  ys=0.d0
67  yn=0.d0
68  zb=0.d0
69  zt=0.d0
70 !
71  i=1
72 !
73  do
74 !
75  nr=k
76 !
77 ! west
78 !
79  id=idx+1-i
80  if(id.gt.0) then
81  node=nx(id)
82  xw=xo(node)-xp
83  yr=yo(node)-yp
84  zr=zo(node)-zp
85  dd=xw*xw+yr*yr+zr*zr
86  if(dd.lt.r(k)) then
87  nr=nr+1
88  ir(nr)=node
89  r(nr)=dd
90  endif
91  elseif(id.eq.0) then
92  xw=sqrt_rmaxini
93  endif
94 !
95 ! east
96 !
97  id=idx+i
98  if(id.le.n) then
99  node=nx(id)
100  xe=xo(node)-xp
101  yr=yo(node)-yp
102  zr=zo(node)-zp
103  dd=xe*xe+yr*yr+zr*zr
104  if(dd.lt.r(k)) then
105  nr=nr+1
106  ir(nr)=node
107  r(nr)=dd
108  endif
109  elseif(id.eq.n+1) then
110  xe=sqrt_rmaxini
111  endif
112 !
113 ! south
114 !
115  id=idy+1-i
116  if(id.gt.0) then
117  node=ny(id)
118  xr=xo(node)-xp
119  ys=yo(node)-yp
120  zr=zo(node)-zp
121  dd=xr*xr+ys*ys+zr*zr
122  if(dd.lt.r(k)) then
123  nr=nr+1
124  ir(nr)=node
125  r(nr)=dd
126  endif
127  elseif(id.eq.0) then
128  ys=sqrt_rmaxini
129  endif
130 !
131 ! north
132 !
133  id=idy+i
134  if(id.le.n) then
135  node=ny(id)
136  xr=xo(node)-xp
137  yn=yo(node)-yp
138  zr=zo(node)-zp
139  dd=xr*xr+yn*yn+zr*zr
140  if(dd.lt.r(k)) then
141  nr=nr+1
142  ir(nr)=node
143  r(nr)=dd
144  endif
145  elseif(id.eq.n+1) then
146  yn=sqrt_rmaxini
147  endif
148 !
149 ! bottom
150 !
151  id=idz+1-i
152  if(id.gt.0) then
153  node=nz(id)
154  xr=xo(node)-xp
155  yr=yo(node)-yp
156  zb=zo(node)-zp
157  dd=xr*xr+yr*yr+zb*zb
158  if(dd.lt.r(k)) then
159  nr=nr+1
160  ir(nr)=node
161  r(nr)=dd
162  endif
163  elseif(id.eq.0) then
164  zb=sqrt_rmaxini
165  endif
166 !
167 ! top
168 !
169  id=idz+i
170  if(id.le.n) then
171  node=nz(id)
172  xr=xo(node)-xp
173  yr=yo(node)-yp
174  zt=zo(node)-zp
175  dd=xr*xr+yr*yr+zt*zt
176  if(dd.lt.r(k)) then
177  nr=nr+1
178  ir(nr)=node
179  r(nr)=dd
180  endif
181  elseif(id.eq.n+1) then
182  zt=sqrt_rmaxini
183  endif
184 !
185 ! check the corners of the box
186 !
187  c(1)=xe*xe+yn*yn+zb*zb
188  c(2)=xw*xw+yn*yn+zb*zb
189  c(3)=xw*xw+ys*ys+zb*zb
190  c(4)=xe*xe+ys*ys+zb*zb
191  c(5)=xe*xe+yn*yn+zt*zt
192  c(6)=xw*xw+yn*yn+zt*zt
193  c(7)=xw*xw+ys*ys+zt*zt
194  c(8)=xe*xe+ys*ys+zt*zt
195  call dsort(c,idummy,eight,iflag)
196 !
197 ! check for new entries
198 !
199  if(nr.gt.k) then
200  call dsort(r,ir,nr,kflag)
201 !
202 ! reject equal entries
203 !
204  m=1
205  if(m.lt.k) then
206  loop: do j=2,nr
207  do l=m,1,-1
208  if(ir(j).eq.ir(l)) cycle loop
209  enddo
210  m=m+1
211  r(m)=r(j)
212  ir(m)=ir(j)
213  if(m.eq.k) exit
214  enddo loop
215  endif
216  endif
217  if(c(1).ge.r(k)) exit
218 !
219  i=i+1
220 !
221  enddo
222 !
223  do i=1,k
224  neighbor(i)=ir(i)
225  enddo
226 !
227  return
subroutine ident(x, px, n, id)
Definition: ident.f:26
subroutine dsort(dx, iy, n, kflag)
Definition: dsort.f:6
Hosted by OpenAircraft.com, (Michigan UAV, LLC)