Debian Codegraph @

native/deprecated/expokit/dgexpv-beast.f

raw symbols SCIP
1 *----------------------------------------------------------------------|
2 subroutine DGEXPVms( n, nz, m, t, v, w, tol, anorm, ia, ja, a,
3 . wsp,lwsp, iwsp,liwsp, itrace,iflag )
4
5 implicit none
6 integer n, nz, m, lwsp, liwsp, itrace, iflag, iwsp(liwsp)
7 double precision t, tol, anorm, v(n), w(n), wsp(lwsp)
8 integer ia(nz), ja(nz)
9 double precision a(nz)
10
11 *-----Purpose----------------------------------------------------------|
12 *
13 *--- DGEXPVms computes w = exp(t*A)*v - for a General matrix A.
14 *
15 * It does not compute the matrix exponential in isolation but
16 * instead, it computes directly the action of the exponential
17 * operator on the operand vector. This way of doing so allows
18 * for addressing large sparse problems.
19 *
20 * The method used is based on Krylov subspace projection
21 * techniques and the matrix under consideration interacts only
22 * via the external routine `matvec' performing the matrix-vector
23 * product (matrix-free method).
24 *
25 *-----Arguments--------------------------------------------------------|
26 *
27 * n : (input) order of the principal matrix A.
28 *
29 * nz : (input) number of non-zero matrix elements in A
30 *
31 * m : (input) maximum size for the Krylov basis.
32 *
33 * t : (input) time at wich the solution is needed (can be < 0).
34 *
35 * v(n) : (input) given operand vector.
36 *
37 * w(n) : (output) computed approximation of exp(t*A)*v.
38 *
39 * tol : (input/output) the requested accuracy tolerance on w.
40 * If on input tol=0.0d0 or tol is too small (tol.le.eps)
41 * the internal value sqrt(eps) is used, and tol is set to
42 * sqrt(eps) on output (`eps' denotes the machine epsilon).
43 * (`Happy breakdown' is assumed if h(j+1,j) .le. anorm*tol)
44 *
45 * anorm : (input) an approximation of some norm of A.
46 *
47 * ia(nz) : (input) first index for non-zero entries of A
48 *
49 * ja(nz) : (input) second index for non-zero entries of A
50 *
51 * a(nz) : (input) non-zero entries of A
52 *
53 * wsp(lwsp): (workspace) lwsp .ge. n*(m+1)+n+(m+2)^2+4*(m+2)^2+ideg+1
54 * +---------+-------+---------------+
55 * (actually, ideg=6) V H wsp for PADE
56 *
57 * iwsp(liwsp): (workspace) liwsp .ge. m+2
58 *
59 * matvec : external subroutine for matrix-vector multiplication.
60 * synopsis: matvec( x, y )
61 * double precision x(*), y(*)
62 * computes: y(1:n) <- A*x(1:n)
63 * where A is the principal matrix.
64 *
65 * itrace : (input) running mode. 0=silent, 1=print step-by-step info
66 *
67 * iflag : (output) exit flag.
68 * <0 - bad input arguments
69 * 0 - no problem
70 * 1 - maximum number of steps reached without convergence
71 * 2 - requested tolerance was too high
72 *
73 *-----Accounts on the computation--------------------------------------|
74 * Upon exit, an interested user may retrieve accounts on the
75 * computations. They are located in wsp and iwsp as indicated below:
76 *
77 * location mnemonic description
78 * -----------------------------------------------------------------|
79 * iwsp(1) = nmult, number of matrix-vector multiplications used
80 * iwsp(2) = nexph, number of Hessenberg matrix exponential evaluated
81 * iwsp(3) = nscale, number of repeated squaring involved in Pade
82 * iwsp(4) = nstep, number of integration steps used up to completion
83 * iwsp(5) = nreject, number of rejected step-sizes
84 * iwsp(6) = ibrkflag, set to 1 if `happy breakdown' and 0 otherwise
85 * iwsp(7) = mbrkdwn, if `happy brkdown', basis-size when it occured
86 * -----------------------------------------------------------------|
87 * wsp(1) = step_min, minimum step-size used during integration
88 * wsp(2) = step_max, maximum step-size used during integration
89 * wsp(3) = dummy
90 * wsp(4) = dummy
91 * wsp(5) = x_error, maximum among all local truncation errors
92 * wsp(6) = s_error, global sum of local truncation errors
93 * wsp(7) = tbrkdwn, if `happy breakdown', time when it occured
94 * wsp(8) = t_now, integration domain successfully covered
95 * wsp(9) = hump, i.e., max||exp(sA)||, s in [0,t] (or [t,0] if t<0)
96 * wsp(10) = ||w||/||v||, scaled norm of the solution w.
97 * -----------------------------------------------------------------|
98 * The `hump' is a measure of the conditioning of the problem. The
99 * matrix exponential is well-conditioned if hump = 1, whereas it is
100 * poorly-conditioned if hump >> 1. However the solution can still be
101 * relatively fairly accurate even when the hump is large (the hump
102 * is an upper bound), especially when the hump and the scaled norm
103 * of w [this is also computed and returned in wsp(10)] are of the
104 * same order of magnitude (further details in reference below).
105 *
106 *----------------------------------------------------------------------|
107 *-----The following parameters may also be adjusted herein-------------|
108 *
109 integer mxstep, mxreject, ideg
110 double precision delta, gamma
111 parameter( mxstep = 1000,
112 . mxreject = 0,
113 . ideg = 6,
114 . delta = 1.2d0,
115 . gamma = 0.9d0 )
116
117 * mxstep : maximum allowable number of integration steps.
118 * The value 0 means an infinite number of steps.
119 *
120 * mxreject: maximum allowable number of rejections at each step.
121 * The value 0 means an infinite number of rejections.
122 *
123 * ideg : the Pade approximation of type (ideg,ideg) is used as
124 * an approximation to exp(H). The value 0 switches to the
125 * uniform rational Chebyshev approximation of type (14,14)
126 *
127 * delta : local truncation error `safety factor'
128 *
129 * gamma : stepsize `shrinking factor'
130 *
131 *----------------------------------------------------------------------|
132 * Roger B. Sidje ([email protected])
133 * EXPOKIT: Software Package for Computing Matrix Exponentials.
134 * ACM - Transactions On Mathematical Software, 24(1):130-156, 1998
135 *----------------------------------------------------------------------|
136 *
137 integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,
138 . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,
139 . nstep
140 double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,
141 . s_error, x_error, t_now, t_new, t_step, t_old,
142 . xm, beta, break_tol, p1, p2, p3, eps, rndoff,
143 . vnorm, avnorm, hj1j, hij, hump, SQR1
144
145 intrinsic AINT,ABS,DBLE,LOG10,MAX,MIN,NINT,SIGN,SQRT
146 double precision DDOT, DNRM2
147
148 *--- check restrictions on input parameters ...
149 iflag = 0
150 if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1
151 if ( liwsp.lt.m+2 ) iflag = -2
152 if ( m.ge.n .or. m.le.0 ) iflag = -3
153 if ( iflag.ne.0 ) stop 'bad sizes (in input of DGEXPV)'
154 *
155 *--- initialisations ...
156 *
157
158
159 k1 = 2
160 mh = m + 2
161 iv = 1
162 ih = iv + n*(m+1) + n
163 ifree = ih + mh*mh
164 lfree = lwsp - ifree + 1
165
166 ibrkflag = 0
167 mbrkdwn = m
168 nmult = 0
169 nreject = 0
170 nexph = 0
171 nscale = 0
172
173 t_out = ABS( t )
174 tbrkdwn = 0.0d0
175 step_min = t_out
176 step_max = 0.0d0
177 nstep = 0
178 s_error = 0.0d0
179 x_error = 0.0d0
180 t_now = 0.0d0
181 t_new = 0.0d0
182
183 p1 = 4.0d0/3.0d0
184 1 p2 = p1 - 1.0d0
185 p3 = p2 + p2 + p2
186 eps = ABS( p3-1.0d0 )
187 if ( eps.eq.0.0d0 ) go to 1
188 if ( tol.le.eps ) tol = SQRT( eps )
189 rndoff = eps*anorm
190
191 break_tol = 1.0d-7
192 *>>> break_tol = tol
193 *>>> break_tol = anorm*tol
194
195 sgn = SIGN( 1.0d0,t )
196 call DCOPY( n, v,1, w,1 )
197 beta = DNRM2( n, w,1 )
198 vnorm = beta
199 hump = beta
200 *
201 *--- obtain the very first stepsize ...
202 *
203 SQR1 = SQRT( 0.1d0 )
204 xm = 1.0d0/DBLE( m )
205 p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))
206 t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm
207 p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)
208 t_new = AINT( t_new/p1 + 0.55d0 ) * p1
209 *
210 *--- step-by-step integration ...
211 *
212 100 if ( t_now.ge.t_out ) goto 500
213
214 nstep = nstep + 1
215 t_step = MIN( t_out-t_now, t_new )
216
217 p1 = 1.0d0/beta
218 do i = 1,n
219 wsp(iv + i-1) = p1*w(i)
220 enddo
221 do i = 1,mh*mh
222 wsp(ih+i-1) = 0.0d0
223 enddo
224 *
225 *--- Arnoldi loop ...
226 *
227 j1v = iv + n
228 do 200 j = 1,m
229 nmult = nmult + 1
230 * stop 'before'
231 call dgcoovms( wsp(j1v-n), wsp(j1v), n, nz, a, ia, ja )
232
233 * integer inew, jnew
234 * do jnew = 1,
235
236
237 * stop 'after'
238
239 do i = 1,j
240 hij = DDOT( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )
241 call DAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )
242 wsp(ih+(j-1)*mh+i-1) = hij
243 enddo
244 hj1j = DNRM2( n, wsp(j1v),1 )
245 *--- if `happy breakdown' go straightforward at the end ...
246 if ( hj1j.le.break_tol ) then
247 print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j
248 k1 = 0
249 ibrkflag = 1
250 mbrkdwn = j
251 tbrkdwn = t_now
252 t_step = t_out-t_now
253 goto 300
254 endif
255 wsp(ih+(j-1)*mh+j) = hj1j
256 call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )
257 j1v = j1v + n
258 200 continue
259 nmult = nmult + 1
260 call dgcoovms( wsp(j1v-n), wsp(j1v), n, nz, a, ia, ja )
261 avnorm = DNRM2( n, wsp(j1v),1 )
262 *
263 *--- set 1 for the 2-corrected scheme ...
264 *
265 300 continue
266 wsp(ih+m*mh+m+1) = 1.0d0
267 *
268 *--- loop while ireject<mxreject until the tolerance is reached ...
269 *
270 ireject = 0
271 401 continue
272
273 *
274 *--- compute w = beta*V*exp(t_step*H)*e1 ...
275 *
276 nexph = nexph + 1
277 mx = mbrkdwn + k1
278 if ( ideg.ne.0 ) then
279 *--- irreducible rational Pade approximation ...
280 call DGPADM( ideg, mx, sgn*t_step, wsp(ih),mh,
281 . wsp(ifree),lfree, iwsp, iexph, ns, iflag )
282 iexph = ifree + iexph - 1
283 nscale = nscale + ns
284 else
285 *--- uniform rational Chebyshev approximation ...
286 iexph = ifree
287 do i = 1,mx
288 wsp(iexph+i-1) = 0.0d0
289 enddo
290 wsp(iexph) = 1.0d0
291 call DNCHBV(mx,sgn*t_step,wsp(ih),mh,wsp(iexph),wsp(ifree+mx))
292 endif
293
294 402 continue
295 *
296 *--- error estimate ...
297 *
298 if ( k1.eq.0 ) then
299 err_loc = tol
300 else
301 p1 = ABS( wsp(iexph+m) ) * beta
302 p2 = ABS( wsp(iexph+m+1) ) * beta * avnorm
303 if ( p1.gt.10.0d0*p2 ) then
304 err_loc = p2
305 xm = 1.0d0/DBLE( m )
306 elseif ( p1.gt.p2 ) then
307 err_loc = (p1*p2)/(p1-p2)
308 xm = 1.0d0/DBLE( m )
309 else
310 err_loc = p1
311 xm = 1.0d0/DBLE( m-1 )
312 endif
313 endif
314 *
315 *--- reject the step-size if the error is not acceptable ...
316 *
317 if ( (k1.ne.0) .and. (err_loc.gt.delta*t_step*tol) .and.
318 . (mxreject.eq.0 .or. ireject.lt.mxreject) ) then
319 t_old = t_step
320 t_step = gamma * t_step * (t_step*tol/err_loc)**xm
321 p1 = 10.0d0**(NINT( LOG10( t_step )-SQR1 )-1)
322 t_step = AINT( t_step/p1 + 0.55d0 ) * p1
323 if ( itrace.ne.0 ) then
324 print*,'t_step =',t_old
325 print*,'err_loc =',err_loc
326 print*,'err_required =',delta*t_old*tol
327 print*,'stepsize rejected, stepping down to:',t_step
328 endif
329 ireject = ireject + 1
330 nreject = nreject + 1
331 if ( mxreject.ne.0 .and. ireject.gt.mxreject ) then
332 print*,"Failure in DGEXPV: ---"
333 print*,"The requested tolerance is too high."
334 Print*,"Rerun with a smaller value."
335 iflag = 2
336 return
337 endif
338 goto 401
339 endif
340 *
341 *--- now update w = beta*V*exp(t_step*H)*e1 and the hump ...
342 *
343 mx = mbrkdwn + MAX( 0,k1-1 )
344 call DGEMV( 'n', n,mx,beta,wsp(iv),n,wsp(iexph),1,0.0d0,w,1 )
345 beta = DNRM2( n, w,1 )
346 hump = MAX( hump, beta )
347 *
348 *--- suggested value for the next stepsize ...
349 *
350 t_new = gamma * t_step * (t_step*tol/err_loc)**xm
351 p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)
352 t_new = AINT( t_new/p1 + 0.55d0 ) * p1
353
354 err_loc = MAX( err_loc,rndoff )
355 *
356 *--- update the time covered ...
357 *
358 t_now = t_now + t_step
359 *
360 *--- display and keep some information ...
361 *
362 if ( itrace.ne.0 ) then
363 print*,'integration',nstep,'---------------------------------'
364 print*,'scale-square =',ns
365 print*,'step_size =',t_step
366 print*,'err_loc =',err_loc
367 print*,'next_step =',t_new
368 endif
369
370 step_min = MIN( step_min, t_step )
371 step_max = MAX( step_max, t_step )
372 s_error = s_error + err_loc
373 x_error = MAX( x_error, err_loc )
374
375 if ( mxstep.eq.0 .or. nstep.lt.mxstep ) goto 100
376 iflag = 1
377
378 500 continue
379
380 iwsp(1) = nmult
381 iwsp(2) = nexph
382 iwsp(3) = nscale
383 iwsp(4) = nstep
384 iwsp(5) = nreject
385 iwsp(6) = ibrkflag
386 iwsp(7) = mbrkdwn
387
388 wsp(1) = step_min
389 wsp(2) = step_max
390 wsp(3) = 0.0d0
391 wsp(4) = 0.0d0
392 wsp(5) = x_error
393 wsp(6) = s_error
394 wsp(7) = tbrkdwn
395 wsp(8) = sgn*t_now
396 wsp(9) = hump/vnorm
397 wsp(10) = beta/vnorm
398 END
399 *----------------------------------------------------------------------|
400
401
402
403
404
405
406 *
407 *--- Computes y = A*x. A is passed via a fortran `common statement'.
408 *--- A is assumed here to be under the COOrdinates storage format.
409 *
410 subroutine dgcoovms ( x, y, n, nz, a, ia, ja )
411 implicit none
412 double precision x(*), y(*)
413 integer n, nz
414 double precision a(nz)
415 integer ia(nz), ja(nz)
416
417 integer i, j
418
419 do j = 1,n
420 y(j) = 0.0d0
421 enddo
422 do i = 1,nz
423 y(ia(i)) = y(ia(i)) + a(i)*x(ja(i))
424 enddo
425 END