-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibscrapcode2.f
190 lines (151 loc) · 4.95 KB
/
ibscrapcode2.f
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
c Routine for cell classification
subroutine genib(xs,ys,xnxs,xnys,xc,yc,dist,distg,hh,weight,acoef,bcoef,
c nlist,itag,lpri,idif,jdif,ii,jj,nlistmx,nintpts,nobjs,power)
implicit real(a-h,o-z)
c ---- real variables passed from outside
dimension xs(nlistmx,nobjs),ys(nlistmx,nobjs)
dimension xnxs(nlistmx,nobjs),xnys(nlistmx,nobjs)
dimension xc(1:ii+1,1:jj+1)
dimension yc(1:ii+1,1:jj+1)
dimension dist(1:ii+1,1:jj+1,nobjs)
dimension distg(1:ii+1,1:jj+1)
dimension hh(1:ii+1,1:jj+1)
dimension weight(1:ii+1,1:jj+1,nintpts)
dimension acoef(1:ii+1,1:jj+1)
dimension bcoef(1:ii+1,1:jj+1)
c ---- integer variables passed from outside
dimension nlist(nobjs)
dimension idif(nintpts), jdif(nintpts)
dimension itag(1:ii+1,1:jj+1,nobjs)
dimension lpri(1:ii+1,1:jj+1)
c ---------------------------------------------------------
c ---- Step 1: Classify Cells
c ---------------------------------------------------------
c ---- Step 1a: determine local signed distance
do n=1,nobjs
do j=1,jj+1
do i=1,ii+1
dist(i,j,n) = 1e12
do k=1,nlist(n)
dd = (xc(i,j)-xs(k,n))**2 + (yc(i,j)-ys(k,n))**2
if(dd.lt.dist(i,j,n)) then
itag(i,j,n) = k !tag for nearest surface point
dist(i,j,n) = dd
endif
enddo
dist(i,j,n) = sqrt(dist(i,j,n))
dotp = (xc(i,j)-xs(itag(i,j,n),n))*xnxs(itag(i,j,n),n)
c + (yc(i,j)-ys(itag(i,j,n),n))*xnys(itag(i,j,n),n)
dist(i,j,n) = dist(i,j,n)*sign(1.0,dotp)
enddo
enddo
enddo
c ---- Step 1b: determine global signed distance
do j=1,jj+1
do i=1,ii+1
distg(i,j) = 1e6
lpri(i,j) = 1
do n=1,nobjs
distg(i,j) = min(distg(i,j),dist(i,j,n))
if(distg(i,j).eq.dist(i,j,n)) lpri(i,j) = n
enddo
enddo
enddo
c ---- Step 1c: determine Heaviside function
do j=2,jj
do i=2,ii
icflg = 0
do k=1,nintpts
iq = i+idif(k)
jq = j+jdif(k)
if(distg(i,j).gt.0.0 .and. distg(iq,jq).lt.0.0) icflg = 1
enddo
if(icflg.eq.1) hh(i,j) = 1.0
if(distg(i,j).lt.0.0) hh(i,j) = 1.0
enddo
enddo
hh(1,:) = hh(2,:)
hh(ii+1,:) = hh(ii,:)
hh(:,1) = hh(:,2)
hh(:,jj+1) = hh(:,jj)
c -------------------------------------------------------------
c ---- now you have four arrays that define cell classification
c
c distg(i,j) = global signed distance function
c hh(i,j) = Heaviside function (1.0 if interior or band; 0.0 otherwise)
c lpri(i,j) = tag that tells which object is closest
c itag(i,j,l) = index for nearest point on object 'l'
c -------------------------------------------------------------
c ---------------------------------------------------------
c ---- Step 2: Determine interpolation data
c ---------------------------------------------------------
! deldsum1 is same as deld1
! deldsum1d is same as deld2
do j=2,jj
do i=2,ii
if(hh(i,j).eq.1.0 .and. distg(i,j).gt.0.0) then
weight(i,j,1:nintpts) = 0.0
xnxd = xnxs(itag(i,j,lpri(i,j)),lpri(i,j))
xnyd = xnys(itag(i,j,lpri(i,j)),lpri(i,j))
xcd = xc(i,j)
ycd = yc(i,j)
deldsum1 = 0.0
deldsum1d = 0.0
do k=1,nintpts
iq = i + idif(k)
jq = j + jdif(k)
xcp = xc(iq,jq)
ycp = yc(iq,jq)
dx = xcp - xcd
dy = ycp - ycd
distance = sqrt(dx**2 + dy**2)
deld = dx*xnxd + dy*xnyd
dcross = sqrt(distance**2-deld**2)
if(deld.gt.0.0.and.hh(iq,jq).eq.0.0) then ! consider only field cells
dcross = 1.0/(dcross + 1e-12)
weight(i,j,k) = dcross
deldsum1 = deldsum1 + dcross
deldsum1d = deldsum1d + dcross*deld
endif
enddo
if(deldsum1.eq.0.0) then ! consider band and field cells
deldsum1 = 0.0
deldsum1d = 0.0
do k=1,nintpts
iq = i + idif(k)
jq = j + jdif(k)
xcp = xc(iq,jq)
ycp = yc(iq,jq)
dx = xcp - xcd
dy = ycp - ycd
distance = sqrt(dx**2 + dy**2)
deld = dx*xnxd + dy*xnyd
dcross = sqrt(distance**2-deld**2)
if(deld.gt.0.0.and.hh(iq,jq).ge.0.0) then
dcross = 1.0/(dcross + 1e-12)
weight(i,j,k) = dcross
deldsum1 = deldsum1 + dcross
deldsum1d = deldsum1d + dcross*deld
endif
enddo
endif
if(deldsum1.ne.0.0) then
weight(i,j,1:nintpts) = weight(i,j,1:nintpts)/deldsum1
deld = deldsum1d/deldsum1
else
write(6,*) 'no interpolation point found'
weight = 0.0
deld = 0.0
endif
dratio = deld/distg(i,j)
acoef(i,j) = (1.0/(1.0+dratio))**power
diste = distg(i,j) + 0.5*deld
distd = 0.5*distg(i,j)
term = (distd/diste)**power/dratio
bcoef(i,j) = term/(1.0 + term) ! attempts to satisfy continuity
c bcoef(i,j) = distg(i,j)/(deld+distg(i,j)) ! linear behavior
endif
enddo
enddo
return
end