-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrwgf.f90
322 lines (256 loc) · 10.3 KB
/
rwgf.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
! MODULE: rwgf
! AUTHOR: Jouni Makitalo
! DESCRIPTION:
! Routines for the evaluation of RWG basis function and its surface divergence.
! Routines with prefix 'v' are vectorized with respect to evaluation point.
MODULE rwgf
USE mesh
USE quad
IMPLICIT NONE
CONTAINS
FUNCTION rwg(r, faceind, edgeind, mesh) RESULT(res)
REAL (KIND=dp), DIMENSION(3), INTENT(IN) :: r
INTEGER, INTENT(IN) :: faceind, edgeind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp), DIMENSION(3) :: res, v
REAL (KIND=dp) :: L, A
L = mesh%edges(mesh%faces(faceind)%edge_indices(edgeind))%length
A = mesh%faces(faceind)%area
IF(get_face_sign(faceind, edgeind, mesh)>0) THEN
v = get_posit_bnode(faceind, edgeind, mesh)
res = L/(2.0_dp*A)*(r-v)
ELSE IF(get_face_sign(faceind, edgeind, mesh)<0) THEN
v = get_negat_bnode(faceind, edgeind, mesh)
res = L/(2.0_dp*A)*(v-r)
ELSE
WRITE(*,*) 'Invalid evaluation of RWG function!'
END IF
END FUNCTION rwg
FUNCTION rwgDiv(faceind, edgeind, mesh) RESULT(res)
INTEGER, INTENT(IN) :: faceind, edgeind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp) :: L, A, res, sign
IF(get_face_sign(faceind, edgeind, mesh)>0) THEN
sign = 1.0_dp
ELSE IF(get_face_sign(faceind, edgeind, mesh)<0) THEN
sign = -1.0_dp
ELSE
WRITE(*,*) 'Invalid evaluation of RWG divergence function!'
STOP
END IF
L = mesh%edges(mesh%faces(faceind)%edge_indices(edgeind))%length
A = mesh%faces(faceind)%area
res = sign*L/A
END FUNCTION rwgDiv
SUBROUTINE vrwg(r, faceind, edgeind, mesh, res)
REAL (KIND=dp), DIMENSION(:,:), INTENT(IN) :: r
INTEGER, INTENT(IN) :: faceind, edgeind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp), DIMENSION(3) :: v
REAL (KIND=dp), DIMENSION(SIZE(r,1),SIZE(r,2)), INTENT(INOUT) :: res
REAL (KIND=dp) :: L, A
L = mesh%edges(mesh%faces(faceind)%edge_indices(edgeind))%length
A = mesh%faces(faceind)%area
IF(get_face_sign(faceind, edgeind, mesh)>0) THEN
v = get_posit_bnode(faceind, edgeind, mesh)
res(1,:) = L/(2.0_dp*A)*(r(1,:)-v(1))
res(2,:) = L/(2.0_dp*A)*(r(2,:)-v(2))
res(3,:) = L/(2.0_dp*A)*(r(3,:)-v(3))
ELSE IF(get_face_sign(faceind, edgeind, mesh)<0) THEN
v = get_negat_bnode(faceind, edgeind, mesh)
res(1,:) = L/(2.0_dp*A)*(v(1)-r(1,:))
res(2,:) = L/(2.0_dp*A)*(v(2)-r(2,:))
res(3,:) = L/(2.0_dp*A)*(v(3)-r(3,:))
ELSE
WRITE(*,*) 'Invalid evaluation of RWG function!'
END IF
END SUBROUTINE vrwg
SUBROUTINE vsolid_rwg(r, solidind, faceind, mesh, res)
REAL (KIND=dp), DIMENSION(:,:), INTENT(IN) :: r
INTEGER, INTENT(IN) :: solidind, faceind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp), DIMENSION(3) :: v
REAL (KIND=dp), DIMENSION(SIZE(r,1),SIZE(r,2)), INTENT(INOUT) :: res
REAL (KIND=dp) :: A, vol
A = mesh%solid_faces(mesh%solids(solidind)%solid_face_indices(faceind))%area
vol = mesh%solids(solidind)%volume
IF(get_solid_face_sign(solidind, faceind, mesh)>0) THEN
v = get_posit_solid_bnode(solidind, faceind, mesh)
res(1,:) = A/(3.0_dp*vol)*(r(1,:)-v(1))
res(2,:) = A/(3.0_dp*vol)*(r(2,:)-v(2))
res(3,:) = A/(3.0_dp*vol)*(r(3,:)-v(3))
ELSE IF(get_solid_face_sign(solidind, faceind, mesh)<0) THEN
v = get_negat_solid_bnode(solidind, faceind, mesh)
res(1,:) = A/(3.0_dp*vol)*(v(1)-r(1,:))
res(2,:) = A/(3.0_dp*vol)*(v(2)-r(2,:))
res(3,:) = A/(3.0_dp*vol)*(v(3)-r(3,:))
ELSE
WRITE(*,*) 'Invalid evaluation of solid RWG function!'
END IF
END SUBROUTINE vsolid_rwg
FUNCTION solid_rwg(r, solidind, faceind, mesh) RESULT(res)
REAL (KIND=dp), DIMENSION(3), INTENT(IN) :: r
INTEGER, INTENT(IN) :: solidind, faceind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp), DIMENSION(3) :: res, v
REAL (KIND=dp) :: A, vol
A = mesh%solid_faces(mesh%solids(solidind)%solid_face_indices(faceind))%area
vol = mesh%solids(solidind)%volume
IF(get_solid_face_sign(solidind, faceind, mesh)>0) THEN
v = get_posit_solid_bnode(solidind, faceind, mesh)
res = A/(3.0_dp*vol)*(r-v)
ELSE IF(get_solid_face_sign(solidind, faceind, mesh)<0) THEN
v = get_negat_solid_bnode(solidind, faceind, mesh)
res = A/(3.0_dp*vol)*(v-r)
ELSE
WRITE(*,*) 'Invalid evaluation of solid RWG function!'
END IF
END FUNCTION solid_rwg
FUNCTION solid_rwgDiv(solidind, faceind, mesh) RESULT(res)
INTEGER, INTENT(IN) :: solidind, faceind
TYPE(mesh_container), INTENT(IN) :: mesh
REAL (KIND=dp) :: A, vol, res, sign
IF(get_solid_face_sign(solidind, faceind, mesh)>0) THEN
sign = 1.0_dp
ELSE IF(get_solid_face_sign(solidind, faceind, mesh)<0) THEN
sign = -1.0_dp
ELSE
WRITE(*,*) 'Invalid evaluation of solid RWG divergence function!'
STOP
END IF
A = mesh%solid_faces(mesh%solids(solidind)%solid_face_indices(faceind))%area
vol = mesh%solids(solidind)%volume
res = sign*A/vol
END FUNCTION solid_rwgDiv
! Computes numerically the RWG moment matrix that has elements M_mn = <f_m,f_n>.
SUBROUTINE rwg_moments(mesh, qd, F)
TYPE(mesh_container), INTENT(IN) :: mesh
TYPE(quad_data), INTENT(IN) :: qd
COMPLEX (KIND=dp), DIMENSION(mesh%nedges,mesh%nedges), INTENT(INOUT) :: F
INTEGER :: nbasis, nweights, n, m, q, p, r, t, s, faceind
REAL (KIND=dp) :: A, int
REAL (KIND=dp), DIMENSION(3) :: fm, fn
REAL (KIND=dp), DIMENSION(3,qd%num_nodes) :: qp
WRITE(*,*) 'Building an F-matrix'
F(:,:) = 0.0_dp
nbasis = mesh%nedges
nweights = qd%num_nodes
DO m=1,mesh%nedges
DO s=1,2
faceind = mesh%edges(m)%face_indices(s)
IF(faceind==-1) THEN
CYCLE
END IF
qp = quad_tri_points(qd, faceind, mesh)
A = mesh%faces(faceind)%area
q = local_edge_index(mesh, faceind, m)
int = 0.0_dp
DO r=1,nweights
fm = rwg(qp(:,r),faceind,q,mesh)
int = int + qd%weights(r)*dotr(fm, fm)
END DO
int = int*A
F(m,m) = F(m,m) + int
END DO
DO n=m+1,mesh%nedges
! Find out the index of the common face.
IF(mesh%edges(m)%face_indices(1)/=-1 .AND. (mesh%edges(m)%face_indices(1)==mesh%edges(n)%face_indices(1) .OR.&
mesh%edges(m)%face_indices(1)==mesh%edges(n)%face_indices(2))) THEN
faceind = mesh%edges(m)%face_indices(1)
ELSE IF(mesh%edges(m)%face_indices(2)/=-1 .AND. (mesh%edges(m)%face_indices(2)==mesh%edges(n)%face_indices(1) .OR.&
mesh%edges(m)%face_indices(2)==mesh%edges(n)%face_indices(2))) THEN
faceind = mesh%edges(m)%face_indices(2)
ELSE
CYCLE
END IF
q = local_edge_index(mesh, faceind, m)
p = local_edge_index(mesh, faceind, n)
qp = quad_tri_points(qd, faceind, mesh)
A = mesh%faces(faceind)%area
int = 0.0_dp
DO r=1,nweights
fm = rwg(qp(:,r),faceind,q,mesh)
fn = rwg(qp(:,r),faceind,p,mesh)
int = int + qd%weights(r)*dotr(fm, fn)
END DO
int = int*A
F(m,n) = int
F(n,m) = int
END DO
END DO
END SUBROUTINE rwg_moments
! Computes numerically the RWG moment matrix that has elements M_mn = <normal x f_m,f_n>.
SUBROUTINE rwg_moments2(mesh, qd, F)
TYPE(mesh_container), INTENT(IN) :: mesh
TYPE(quad_data), INTENT(IN) :: qd
COMPLEX (KIND=dp), DIMENSION(mesh%nedges,mesh%nedges), INTENT(INOUT) :: F
INTEGER :: nbasis, nweights, n, m, q, p, r, t, s, faceind
REAL (KIND=dp) :: A, int
REAL (KIND=dp), DIMENSION(3) :: fm, fn
REAL (KIND=dp), DIMENSION(3,qd%num_nodes) :: qp
WRITE(*,*) 'Building an F-matrix'
F(:,:) = 0.0_dp
nbasis = mesh%nedges
nweights = qd%num_nodes
DO m=1,mesh%nedges
DO n=m+1,mesh%nedges
! Find out the index of the common face.
IF(mesh%edges(m)%face_indices(1)/=-1 .AND. (mesh%edges(m)%face_indices(1)==mesh%edges(n)%face_indices(1) .OR.&
mesh%edges(m)%face_indices(1)==mesh%edges(n)%face_indices(2))) THEN
faceind = mesh%edges(m)%face_indices(1)
ELSE IF(mesh%edges(m)%face_indices(2)/=-1 .AND. (mesh%edges(m)%face_indices(2)==mesh%edges(n)%face_indices(1) .OR.&
mesh%edges(m)%face_indices(2)==mesh%edges(n)%face_indices(2))) THEN
faceind = mesh%edges(m)%face_indices(2)
ELSE
CYCLE
END IF
q = local_edge_index(mesh, faceind, m)
p = local_edge_index(mesh, faceind, n)
qp = quad_tri_points(qd, faceind, mesh)
A = mesh%faces(faceind)%area
int = 0.0_dp
DO r=1,nweights
fm = rwg(qp(:,r),faceind,q,mesh)
fn = rwg(qp(:,r),faceind,p,mesh)
int = int + qd%weights(r)*dotr(crossr(mesh%faces(faceind)%n, fm), fn)
END DO
int = int*A
F(m,n) = int
F(n,m) = -int
END DO
END DO
END SUBROUTINE rwg_moments2
! Evaluate a function expanded in RWG functions over
! the given surface mesh.
FUNCTION rwg_exp(pt, mesh, faceind, coef) RESULT(res)
INTEGER, INTENT(IN) :: faceind
REAL (KIND=dp), DIMENSION(3), INTENT(IN) :: pt
COMPLEX (KIND=dp), DIMENSION(:), INTENT(IN) :: coef
TYPE(mesh_container), INTENT(IN) :: mesh
COMPLEX (KIND=dp), DIMENSION(3) :: res
REAL (KIND=dp), DIMENSION(3) :: fm
INTEGER :: q, index
res(:) = 0.0_dp
DO q=1,3
fm = rwg(pt, faceind, q, mesh)
index = mesh%faces(faceind)%edge_indices(q)
res = res + fm*coef(index)
END DO
END FUNCTION rwg_exp
! Evaluate the surface divergence of a function expanded in RWG functions over
! the given surface mesh.
FUNCTION div_rwg_exp(mesh, faceind, coef) RESULT(res)
INTEGER, INTENT(IN) :: faceind
COMPLEX (KIND=dp), DIMENSION(:), INTENT(IN) :: coef
TYPE(mesh_container), INTENT(IN) :: mesh
COMPLEX (KIND=dp) :: res
REAL (KIND=dp) :: fmDiv
INTEGER :: q, index
res = 0.0_dp
DO q=1,3
fmDiv = rwgDiv(faceind, q, mesh)
index = mesh%faces(faceind)%edge_indices(q)
res = res + fmDiv*coef(index)
END DO
END FUNCTION div_rwg_exp
END MODULE rwgf