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

Go to the source code of this file.

Functions/Subroutines

subroutine near2d (xo, yo, x, y, nx, ny, xp, yp, n, neighbor, k)
 

Function/Subroutine Documentation

◆ near2d()

subroutine near2d ( real*8, dimension(n)  xo,
real*8, dimension(n)  yo,
real*8, dimension(n)  x,
real*8, dimension(n)  y,
integer, dimension(n)  nx,
integer, dimension(n)  ny,
real*8  xp,
real*8  yp,
integer  n,
integer, dimension(k)  neighbor,
integer  k 
)
20 !
21 ! determines the k closest nodes out of n with coordinates in
22 ! (xo,yo) to the point with coordinates (xp,yp);
23 !
24  implicit none
25 !
26  integer n,nx(n),ny(n),ir(k+4),nr,neighbor(k),kflag,iflag,
27  & i,j,k,l,m,id,idx,idy,four,idummy,node
28 !
29  real*8 x(n),y(n),xo(n),yo(n),xp,yp,r(k+4),xr,yr,c(4),dd,
30  & xw,xe,ys,yn,sqrt_rmaxini
31 !
32  data iflag /1/
33  data kflag /2/
34  data four /4/
35 !
36  if(k.gt.n) then
37  k=n
38  endif
39 !
40 ! identify position of xp and yp
41 !
42  call ident(x,xp,n,idx)
43  call ident(y,yp,n,idy)
44 !
45 ! initialization of r and ir
46 !
47  do i=1,k
48  xr=xo(i)-xp
49  yr=yo(i)-yp
50  r(i)=xr*xr+yr*yr
51  ir(i)=i
52  enddo
53  call dsort(r,ir,k,kflag)
54  sqrt_rmaxini=1.d30
55 !
56 ! initialization of the maximal distance in each direction
57 !
58  xw=0.d0
59  xe=0.d0
60  ys=0.d0
61  yn=0.d0
62 !
63  i=1
64 !
65  do
66 !
67  nr=k
68 !
69 ! west
70 !
71  id=idx+1-i
72  if(id.gt.0) then
73  node=nx(id)
74  xw=xo(node)-xp
75  yr=yo(node)-yp
76  dd=xw*xw+yr*yr
77  if(dd.lt.r(k)) then
78  nr=nr+1
79  ir(nr)=node
80  r(nr)=dd
81  endif
82  elseif(id.eq.0) then
83  xw=sqrt_rmaxini
84  endif
85 !
86 ! east
87 !
88  id=idx+i
89  if(id.le.n) then
90  node=nx(id)
91  xe=xo(node)-xp
92  yr=yo(node)-yp
93  dd=xe*xe+yr*yr
94  if(dd.lt.r(k)) then
95  nr=nr+1
96  ir(nr)=node
97  r(nr)=dd
98  endif
99  elseif(id.eq.n+1) then
100  xe=sqrt_rmaxini
101  endif
102 !
103 ! south
104 !
105  id=idy+1-i
106  if(id.gt.0) then
107  node=ny(id)
108  xr=xo(node)-xp
109  ys=yo(node)-yp
110  dd=xr*xr+ys*ys
111  if(dd.lt.r(k)) then
112  nr=nr+1
113  ir(nr)=node
114  r(nr)=dd
115  endif
116  elseif(id.eq.0) then
117  ys=sqrt_rmaxini
118  endif
119 !
120 ! north
121 !
122  id=idy+i
123  if(id.le.n) then
124  node=ny(id)
125  xr=xo(node)-xp
126  yn=yo(node)-yp
127  dd=xr*xr+yn*yn
128  if(dd.lt.r(k)) then
129  nr=nr+1
130  ir(nr)=node
131  r(nr)=dd
132  endif
133  elseif(id.eq.n+1) then
134  yn=sqrt_rmaxini
135  endif
136 !
137 ! check the corners of the box
138 !
139  c(1)=xe*xe+yn*yn
140  c(2)=xw*xw+yn*yn
141  c(3)=xw*xw+ys*ys
142  c(4)=xe*xe+ys*ys
143  call dsort(c,idummy,four,iflag)
144 !
145 ! check for new entries
146 !
147  if(nr.gt.k) then
148  call dsort(r,ir,nr,kflag)
149 !
150 ! reject equal entries
151 !
152  m=1
153  if(m.lt.k) then
154  loop: do j=2,nr
155  do l=m,1,-1
156  if(ir(j).eq.ir(l)) cycle loop
157  enddo
158  m=m+1
159  r(m)=r(j)
160  ir(m)=ir(j)
161  if(m.eq.k) exit
162  enddo loop
163  endif
164  endif
165  if(c(1).ge.r(k)) exit
166 !
167  i=i+1
168 !
169  enddo
170 !
171  do i=1,k
172  neighbor(i)=ir(i)
173  enddo
174 !
175  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)