-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathNSSOLVER.f
342 lines (277 loc) · 10.2 KB
/
NSSOLVER.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
! This software is Copyright (c) 2012-2015 The Regents of the
! University of California. All Rights Reserved.
!
! Permission to copy and modify this software and its documentation
! for educational, research and non-profit purposes, without fee,
! and without a written agreement is hereby granted, provided that
! the above copyright notice, this paragraph and the following three
! paragraphs appear in all copies.
!
! Permission to make commercial use of this software may be obtained
! by contacting:
!
! Technology Transfer Office
! 9500 Gilman Drive, Mail Code 0910
! University of California
! La Jolla, CA 92093-0910
! (858) 534-5815
!
! This software program and documentation are copyrighted by The
! Regents of the University of California. The software program and
! documentation are supplied "as is", without any accompanying
! services from The Regents. The Regents does not warrant that the
! operation of the program will be uninterrupted or error-free. The
! end-user understands that the program was developed for research
! purposes and is advised not to rely exclusively on the program for
! any reason.
!
! IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
! PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
! DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
! SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
! CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
! WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
! SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
! UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
! MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
SUBROUTINE NSSOLVER(nFaces, gnNo, dof, nNo, nnz, mynNo, commu,
2 cS, face, ls, rowPtr, colPtr, Val, Ri)
INCLUDE "svLS_STD.h"
INTEGER, INTENT(IN) :: nFaces, gnNo, dof, nNo, nnz, mynNo
TYPE(svLS_commuType), INTENT(IN) :: commu
TYPE(svLS_cSType), INTENT(IN) :: cS(commu%nTasks)
TYPE(svLS_faceType), INTENT(INOUT) :: face(nFaces)
TYPE(svLS_lsType), INTENT(INOUT) :: ls
INTEGER, INTENT(IN) :: rowPtr(2,nNo), colPtr(nnz)
REAL*8, INTENT(IN) :: Val(dof*dof,nnz)
REAL*8, INTENT(INOUT) :: Ri(dof,nNo)
INTEGER i, j, k, iB, iBB, nB, nsd
REAL*8 CPUT, NORMS, NORMV, DOTS, DOTV, eps
REAL*8, ALLOCATABLE :: U(:,:,:), P(:,:),
2 MU(:,:,:), MP(:,:), A(:,:), B(:), xB(:), mK(:,:), mG(:,:),
3 mD(:,:), mL(:), Gt(:,:), Rm(:,:), Rc(:), Rmi(:,:), Rci(:)
nsd = dof - 1
iB = ls%RI%mItr
nB = 2*iB
ALLOCATE(Rm(nsd,nNo), Rc(nNo), Rmi(nsd,nNo), Rci(nNo),
2 U(nsd,nNo,iB), P(nNo,iB), MU(nsd,nNo,nB), MP(nNo,nB),
3 A(nB,nB), B(nB), xB(nB))
Rmi = Ri(1:nsd,:)
Rci = Ri(dof,:)
xB = 0D0
B = 0D0
Rm = Rmi
Rc = Rci
eps = SQRT(NORMV(nsd, mynNo, commu, Rm)**2D0
2 + NORMS( mynNo, commu, Rc)**2D0)
ls%RI%iNorm = eps
ls%RI%fNorm = eps
ls%CG%callD = 0D0
ls%GM%callD = 0D0
ls%CG%itr = 0
ls%GM%itr = 0
ls%RI%callD = CPUT()
ls%RI%suc = .FALSE.
eps = MAX(ls%RI%absTol,ls%RI%relTol*eps)
CALL DEPART
CALL BCPRE
DO i=1, ls%RI%mItr
iB = 2*i - 1
iBB = 2*i
ls%RI%dB = ls%RI%fNorm
CALL GMRES(nFaces, nsd, nNo, nnz, mynNo, commu, cS, face,
2 ls%GM, rowPtr, colPtr, mK, Rm, U(:,:,i))
CALL SPARMULVS(nsd, nNo, nnz, commu, cS,
2 rowPtr, colPtr, mD, U(:,:,i), P(:,i))
P(:,i) = Rc - P(:,i)
CALL CGRAD(nFaces, nsd, nNo, nnz, mynNo, commu, cS, face,
2 ls%CG, rowPtr, colPtr, Gt, mG, mL, P(:,i))
CALL SPARMULSV(nsd, nNo, nnz, commu, cS,
2 rowPtr, colPtr, mG, P(:,i), MU(:,:,iB))
MU(:,:,iBB) = Rm - MU(:,:,iB)
CALL GMRES(nFaces, nsd, nNo, nnz, mynNo, commu, cS, face,
2 ls%GM, rowPtr, colPtr, mK, MU(:,:,iBB), U(:,:,i))
CALL SPARMULVV(nsd, nNo, nnz, commu, cS,
2 rowPtr, colPtr, mK, U(:,:,i), MU(:,:,iBB))
CALL ADDBCMUL(BCOP_TYPE_ADD, nFaces, nsd, nNo, mynNo, commu,
2 face, U(:,:,i), MU(:,:,iBB))
CALL SPARMULSS(nNo, nnz, commu, cS,
2 rowPtr, colPtr, mL, P(:,i), MP(:,iB))
CALL SPARMULVS(nsd, nNo, nnz, commu, cS,
2 rowPtr, colPtr, mD, U(:,:,i), MP(:,iBB))
DO k=iB, iBB
DO j=1, k - 1
A(j,k) = DOTV(nsd, mynNo, commu, MU(:,:,j), MU(:,:,k))
2 + DOTS( mynNo, commu, MP(:,j), MP(:,k))
A(k,j) = A(j,k)
END DO
A(k,k) = NORMV(nsd, mynNo, commu, MU(:,:,k))**2D0
2 + NORMS( mynNo, commu, MP(:,k))**2D0
B(k) = DOTV (nsd, mynNo, commu, MU(:,:,k), Rmi)
2 + DOTS ( mynNo, commu, MP(:,k), Rci)
END DO
xB = B
CALL GE(iBB, A(1:iBB,1:iBB), xB(1:iBB))
ls%RI%fNorm = SQRT(ls%RI%iNorm**2D0 - SUM(xB(1:iBB)*B(1:iBB)))
IF(ls%RI%fNorm .LT. eps) THEN
ls%RI%suc = .TRUE.
EXIT
END IF
Rm = Rmi - xB(1)*MU(:,:,1)
Rc = Rci - xB(1)*MP(:,1)
DO j=2, iBB
Rm = Rm - xB(j)*MU(:,:,j)
Rc = Rc - xB(j)*MP(:,j)
END DO
END DO
IF (i .GT. ls%RI%mItr) THEN
ls%RI%itr = ls%RI%mItr
ELSE
ls%RI%itr = i
Rc = Rci - xB(1)*MP(:,1)
DO j=2, iBB
Rc = Rc - xB(j)*MP(:,j)
END DO
END IF
ls%Resc = NINT(1D2*(NORMS(mynNo, commu, Rc)/
2 ls%RI%fNorm)**2D0)
ls%Resm = 100 - ls%Resc
Rmi = xB(2)*U(:,:,1)
Rci = xB(1)*P(:,1)
DO i=2, ls%RI%itr
iB = 2*i - 1
iBB = 2*i
Rmi = Rmi + xB(iBB)*U(:,:,i)
Rci = Rci + xB(iB)*P(:,i)
END DO
ls%RI%callD = CPUT() - ls%RI%callD
ls%RI%dB = 1D1*LOG(ls%RI%fNorm/ls%RI%dB)
Ri(1:nsd,:) = Rmi
Ri(dof,:) = Rci
DEALLOCATE (Rm, Rc, Rmi, Rci, U, P, MU, MP, A, B, mK, mD, mG, mL,
2 Gt)
IF (commu%masF) CALL LOGFILE
RETURN
CONTAINS
!====================================================================
SUBROUTINE DEPART
IMPLICIT NONE
INTEGER i, j, k, l
REAL*8, ALLOCATABLE :: tmp(:)
ALLOCATE(mK(nsd*nsd,nnz), mG(nsd,nnz), mD(nsd,nnz), mL(nnz),
2 Gt(nsd,nnz), tmp((nsd+1)*(nsd+1)))
IF (nsd .EQ. 2) THEN
DO i=1, nnz
tmp = Val(:,i)
mK(1,i) = tmp(1)
mK(2,i) = tmp(2)
mK(3,i) = tmp(4)
mK(4,i) = tmp(5)
mG(1,i) = tmp(3)
mG(2,i) = tmp(6)
mD(1,i) = tmp(7)
mD(2,i) = tmp(8)
mL(i) = tmp(9)
END DO
ELSE IF(nsd .EQ. 3) THEN
DO i=1, nnz
tmp = Val(:,i)
mK(1,i) = tmp(1)
mK(2,i) = tmp(2)
mK(3,i) = tmp(3)
mK(4,i) = tmp(5)
mK(5,i) = tmp(6)
mK(6,i) = tmp(7)
mK(7,i) = tmp(9)
mK(8,i) = tmp(10)
mK(9,i) = tmp(11)
mG(1,i) = tmp(4)
mG(2,i) = tmp(8)
mG(3,i) = tmp(12)
mD(1,i) = tmp(13)
mD(2,i) = tmp(14)
mD(3,i) = tmp(15)
mL(i) = tmp(16)
END DO
ELSE
PRINT *, "Not defined nsd for DEPART", nsd
END IF
DO i=1, nNo
Do j=rowPtr(1,i), rowPtr(2,i)
k = colPtr(j)
DO l=rowPtr(1,k), rowPtr(2,k)
IF (colPtr(l) .EQ. i) THEN
Gt(:,l) = -mG(:,j)
EXIT
END IF
END DO
END DO
END DO
RETURN
END SUBROUTINE DEPART
!====================================================================
SUBROUTINE BCPRE
IMPLICIT NONE
INTEGER faIn, i, a, Ac
REAL*8 NORMV
REAL*8, ALLOCATABLE :: v(:,:)
DO faIn=1, nFaces
IF (face(faIn)%coupledFlag) THEN
IF (face(faIn)%sharedFlag) THEN
IF (.NOT.ALLOCATED(v)) ALLOCATE(v(nsd,nNo))
v = 0D0
DO a=1, face(faIn)%nNo
Ac = face(faIn)%glob(a)
DO i=1, nsd
v(i,Ac) = face(faIn)%valM(i,a)
END DO
END DO
face(faIn)%nS = NORMV(nsd, mynNo, commu, v)**2D0
ELSE
face(faIn)%nS = 0D0
DO a=1, face(faIn)%nNo
Ac = face(faIn)%glob(a)
DO i=1, nsd
face(faIn)%nS = face(faIn)%nS +
2 face(faIn)%valM(i,a)**2D0
END DO
END DO
END IF
END IF
END DO
RETURN
END SUBROUTINE BCPRE
!====================================================================
SUBROUTINE LOGFILE
IMPLICIT NONE
LOGICAL flag
INTEGER fid, i, j
CHARACTER*16, PARAMETER :: fName = 'svLS_NS.log'
INQUIRE(FILE=fName, EXIST=flag)
fid = 11232
OPEN(fid, FILE=fName, POSITION='APPEND')
IF (.NOT.flag) THEN
i = 0
DO j=1, nFaces
IF (face(j)%coupledFlag) i = i + 1
END DO
WRITE(fid,*) gnNo, commu%nTasks, i
END IF
i = 0
IF (ls%RI%suc) i = i + 100
IF (ls%GM%suc) i = i + 10
IF (ls%CG%suc) i = i + 1
WRITE(fid,"(I4.3,I3,I4,I5,3I4,3ES9.2E2,3I4)")
2 i, ls%RI%itr, ls%GM%itr, ls%CG%itr,
3 NINT((ls%RI%CallD-ls%GM%CallD-ls%CG%CallD)/ls%RI%CallD*1D2),
4 NINT(ls%GM%callD/ls%RI%CallD*1D2),
5 NINT(ls%CG%callD/ls%RI%CallD*1D2),
6 ls%RI%iNorm, ls%RI%fNorm/ls%RI%iNorm, ls%RI%CallD,
7 ls%Resm, ls%Resc, NINT(ls%RI%dB)
CLOSE(fid)
RETURN
END SUBROUTINE LOGFILE
END SUBROUTINE NSSOLVER