-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdfiles.F
523 lines (454 loc) · 14.9 KB
/
rdfiles.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
C***********************************************************************
C
C ANALYSE programs module RDFILES
C
C This file contains routines to read the files output by the
C MCTDH program
C
C rdpsi: read the wavefunction from the psi file
C rdpsigrid: read the wavefunction from the psi file and transform it
C to the full grid (primitive basis) representation.
C rdgridpop: read the gridpop file
C
C
C***********************************************************************
C***********************************************************************
C
C RDPSI
C
C Called by the various ANALYSE programs in order to read the
C psi file data which is formatted differently depending
C on selected options.
C
C***********************************************************************
subroutine rdpsi(unit,psi,spsi,jindx)
implicit none
#include "parameter.inc"
#include "global.inc"
#include "aglobal.inc"
#include "griddat.inc"
#include "psidef.inc"
#include "daten.inc"
#include "compdat.inc"
#include "compdat1.inc"
integer unit,dgl,jindx(*)
! integer actblock(maxsta),dgldim1,zeig,s
complex*8 spsi(dgldim)
complex*16 psi(dgldim)
logical lpsisp,lpsicm,lerr,lselect
integer m,s
lend = .false.
lpsisp=lpsiopt(1)
lpsicm=lpsiopt(2)
lselect=lpsiopt(4)
lerr = .true.
C-----------------------------------------------------------------------
C read indices for compact output wavefunction
C-----------------------------------------------------------------------
if (lpsicm) then
routine='rdpsi'
message='psi in compact form is not supported'
call errormsg
! dgldim1=dgldim
! zeig=0
! do s=1,nstate
! read (unit,end=10) actblock(s)
! read (unit,end=10) (jindx(zeig+dgl),dgl=1,actblock(s))
! zeig=zeig+actblock(s)
! dgldim1=dgldim1 - (block(s)-actblock(s))
! enddo
else if (lselect) then
routine='rdpsi'
message='Selected CI is not supported'
call errormsg
! do s=1,nstate
! read (unit,end=10) (jindx(zpsi(s)+dgl),dgl=1,block(s))
! enddo
endif
C-----------------------------------------------------------------------
C read wavefunction
C-----------------------------------------------------------------------
CDWF If dynamical WF: read extra info about the wavefunction
if (psitype.eq.10) then
read (unit,end=10,err=30) dgldim,
+ ((dim(m,s),m=1,nmode),s=1,nstate)
call psidat
endif
if (lpsisp) then
read (unit,end=10,err=30) (spsi(dgl),dgl=1,dgldim)
do dgl=1,dgldim
psi(dgl)=spsi(dgl)
enddo
! else if (lpsicm) then
! read (unit,end=10,err=30) (spsi(dgl),dgl=1,dgldim1)
!
! zeig=1
! do s=1,nstate
! call cmavec(psi(zpsi(s)),spsi(zeig),jindx(zeig),
! + block(s),actblock(s))
! zeig=zeig+actblock(s)
! enddo
!
! do dgl=adim+1,dgldim
! psi(dgl)=spsi(zeig)
! zeig=zeig+1
! enddo
else
read (unit,end=10,err=30) (psi(dgl),dgl=1,dgldim)
endif
goto 20
10 lend=.true.
20 continue
return
30 write(6,*) 'ERROR in rdpsi (source/analyse/rdfiles.F).'
write(6,*) 'Error occurred while reading channel ',unit
write(6,*) 'psi : unit=8; psi1 : unit=48'
write(6,*) 'dgl =', dgl,', dgldim =', dgldim
write(6,*) 'lpsicm, lpsisp :',lpsicm, lpsisp
stop 1
end
C#######################################################################
C
C CMAVEC
C
C copies the truncated A-vector, stored in compact storage mode,
C to the psi vector, filling in blank spaces with 0
C
C#######################################################################
subroutine cmavec(psi,spsi,jindx,block,actblock)
implicit none
integer block,actblock,jindx(actblock),
+ b1,b2
complex*8 spsi(actblock)
complex*16 psi(block)
if (actblock .eq. 0) then
call zerovxz(psi,block)
return
endif
b1=1
do b2=1,block
if (b2 .eq. jindx(b1)) then
psi(b2)=spsi(b1)
if (b1 .lt. actblock) b1=b1+1
else
psi(b2)=0.0d0
endif
enddo
return
end
C***********************************************************************
C
C RDPSIGRID
C
C Called by the various ANALYSE programs in order to read the
C psi file data, and transform the wavefunction to the full grid
C (primitive basis) representation
C
C***********************************************************************
subroutine rdpsigrid(unit,psi,spsi,jindx,workc,lrst)
implicit none
#include "parameter.inc"
#include "global.inc"
#include "aglobal.inc"
#include "griddat.inc"
#include "psidef.inc"
#include "daten.inc"
#include "compdat.inc"
#include "compdat1.inc"
integer unit,zeig1,zeig2,zgrd,m,s,jindx(adim)
integer swapzeig,vdim1,i
complex*8 spsi(dgldim)
complex*16 psi(griddim),workc(dgldim+2*(griddim/nstate))
logical lrst
! Check if the workspace dimension is large enough
if(dgldim+2*(griddim/nstate).gt.workcdim) then
routine='rdpsigrid'
message='workcdim is too small'
write(6,*) 'workcdim = ', workcdim
write(6,*) 'dgldim+2*(griddim/nstate) =',
+ dgldim+2*(griddim/nstate)
call errormsg
endif
! zeig1 points after the wf data
zeig1=dgldim+1
! zeig2 points after the zeig1 by an offset of griddim/nstate
zeig2=zeig1+griddim/nstate
! Read mctdh wavefunction into array spsi (single precision psi)
if(lrst) then
read(unit,err=999) (workc(i),i=1,dgldim)
else
call rdpsi(unit,workc,spsi,jindx)
endif
zgrd=1
do s=1,nstate
! For each state s, the A-vector coeff are copied to the workc
call cpvxz(workc(zpsi(s)),workc(zeig2),block(s))
vdim1=1
do m=1,nmode
! For each mode m in state s, a tensor mutiplication is done
! and the A-vector coeff and SPFs are combined to obtain the wf
! in the grid representation
! Swap pointers for buffers
swapzeig=zeig1
zeig1=zeig2
zeig2=swapzeig
! Use mtxxzz function for matrix-tensor multiplication
call mtxxzz (workc(zetf(m,s)),workc(zeig1),
+ workc(zeig2),vdim1,dim(m,s),ndim(m,s),subdim(m))
! Update dimension multiplier by grid points in m
vdim1=vdim1*subdim(m)
! do i=1,subdim(m)+1
! write(6,*) "grid:", i, "psi:", workc(i)
! enddo
enddo
! Copy result to the appropriate grid position in psi
call cpvxz(workc(zeig2),psi(zgrd),griddim/nstate)
! zgrid now points at the starting index for the next state
zgrd=zgrd+griddim/nstate
enddo
return
999 write(6,*) ' ERROR reading restart file (-rst)'
stop
end
!***********************************************************************
!
! PSI_SP
!
! Called by the various ANALYSE programs to read the
! psi file data and calculate the wavefunction at a single point of
! the grid (primitive basis) for several electronic states.
!
! EMILIO R.C. 09/2024
!***********************************************************************
subroutine psi_sp(psi_value,psi,grid_indices,dim_idx,lrst, unit)
implicit none
! Include the global variables
#include "parameter.inc"
#include "global.inc"
#include "aglobal.inc"
#include "griddat.inc"
#include "psidef.inc"
#include "daten.inc"
! Declare parameters and variables
integer unit
logical lrst
integer dim_idx
integer grid_indices(dim_idx)
complex*8 spsi(dgldim)
complex*16 psi_value(nstate)
complex*16 psi(dgldim)
complex*16 workc(dgldim+2*(griddim/nstate))
! Local variables
integer s,m,n,f, i, idx, config_index,b
integer jindx(adim), spf_start, a_start
integer spf_indices(nmode),lin_idx(nmode),stride
complex*16 spf_values(nmode, maxspf)
complex*16 a_coeff, product
integer total_configs
integer dima(nmode)
integer indices(nmode)
complex*16 psi_work(dgldim)
! Read the wavefunction into psi
if(lrst) then
read(unit,err=999) (workc(i),i=1,dgldim)
else
call rdpsi(unit,workc,spsi,jindx)
endif
! Loop over states
do s = 1, nstate
psi_value(s) = (1.0d0, 0.0d0) ! Initialize psi_value to zero
a_coeff = (0.0d0, 0.0d0)
! Loop over A-vector coefficients
do b = zpsi(s), zpsi(s) + block(s) - 1
a_coeff = a_coeff + workc(b)
end do ! Loop over A-vector coefficients
do m = 1, nmode ! Loop over modes
! Initialize the linear index and stride for the mode
lin_idx(m) = 1
stride = 1
do n = 1, nspfdof(m) ! Loop over dofs
f = spfdof(n, m) ! Index of the dof
! Calculate the linear index for the mode
lin_idx(m) = lin_idx(m) + (grid_indices(f) - 1) * stride
! Update the stride for the next dof
stride = stride * gdim(f)
end do ! Loop over dofs
psi_value(s) = psi_value(s) * workc(zetf(m,s) + lin_idx(m))
end do ! Loop over modes
psi_value(s) = psi_value(s) * a_coeff
end do ! Loop over states
return
999 write(6, *) 'ERROR reading wavefunction'
stop
end
C***********************************************************************
C
C RDGRIDPOP
C
C Called by the various ANALYSE programs in order to read the
C gridpop file data
C
C***********************************************************************
subroutine rdgridpop(unit,fgpop,gpop1,gpop2)
implicit none
#include "parameter.inc"
#include "global.inc"
#include "aglobal.inc"
#include "griddat.inc"
#include "psidef.inc"
#include "daten.inc"
#include "compdat.inc"
#include "compdat1.inc"
integer unit,g,s,m,n,f,ggdim
real*4 fgpop(2*maxgdim)
real*8 gpop1(ortdim,nstate),gpop2(ortdim,nstate)
lend=.false.
if (lgpel .or. nstate .eq. 1) then
do s=1,nstate
do m=1,nmode
do n=1,nspfdof(m)
f=spfdof(n,m)
ggdim = gdim(f)
if(basis(f).eq.12) ggdim = ipbaspar(3,f)
read(unit,err=900,end=999)
+ (fgpop(g),g=1,gdim(f))
+ ,(fgpop(g),g=gdim(f)+1,gdim(f)+ggdim)
do g=1,gdim(f)
gpop1(zort(f)-1+g,s)=fgpop(g)
enddo
do g=1,ggdim
gpop2(zort(f)-1+g,s)=fgpop(gdim(f)+g)
enddo
enddo
enddo
enddo
else
do m=1,nmode
do n=1,nspfdof(m)
f=spfdof(n,m)
ggdim = gdim(f)
if(basis(f).eq.12) ggdim = ipbaspar(3,f)
read(unit,err=900,end=999)(fgpop(g),g=1,gdim(f)+ggdim)
do g=1,gdim(f)
gpop1(zort(f)-1+g,1)=fgpop(g)
enddo
do g=1,ggdim
gpop2(zort(f)-1+g,1)=fgpop(gdim(f)+g)
enddo
enddo
enddo
endif
go to 20
999 lend=.true.
20 continue
return
900 routine='Rdgridpop'
write(message,'(a,i5)' )
+ 'Error reading gridpop file on channel : ',unit
call errormsg
end
C***********************************************************************
C
C RDCHK
C
C Called by the various ANALYSE programs in order to read the
C check file data
C
C the array lrdchk(3) enables storage of data in various arrays
C (see aglobal.inc). See analyse/statepop.F for example.
C
C if lrdchk(n)=.true., following is read and stored
C lrdchk(1) state populations -> spop, energies -> euncorr, etot
C lrdchk(2) natural orbital populations -> dicht3
C lrdchk(3) properties -> prop
C
C Arrays specified by lrdchk must be correctly assigned in calling
C routine.
C
C***********************************************************************
subroutine rdchk(unit,ecorr,etot,spop,dicht3,prop)
implicit none
#include "parameter.inc"
#include "global.inc"
#include "aglobal.inc"
#include "griddat.inc"
#include "psidef.inc"
#include "daten.inc"
#include "compdat.inc"
#include "compdat1.inc"
#include "channels.inc"
integer unit,i,s,m,n,f
real*8 spop(nstate),ecorr(nstate),etot(nstate),
+ dicht3(d3matdim),prop(maxdim,maxsta,maxprop),
+ q,dq,expn,dexpn
C-----------------------------------------------------------------------
C check maxprop large enough to read properties written in check file
C-----------------------------------------------------------------------
if (maxprop .lt. 4) then
routine='Rdchk'
message='Increase MAXPROP. Minimum : 4'
call errormsg
endif
C-----------------------------------------------------------------------
C read state populations
C-----------------------------------------------------------------------
if (lrdchk(1)) then
read(ichk,err=900,end=999)
+ (spop(s),ecorr(s),etot(s),s=1,nstate)
else
read(ichk,err=900,end=999)
endif
C-----------------------------------------------------------------------
C read natural orbital populations
C-----------------------------------------------------------------------
if (lrdchk(2)) then
do s=1,nstate
do m=1,nmode
read(ichk,err=900,end=999)
+ (dicht3(d3mat(m,s)+i),i=0,dim(m,s)-1)
enddo
enddo
else
do s=1,nstate
do m=1,nmode
read(ichk,err=900,end=999)
enddo
enddo
endif
C-----------------------------------------------------------------------
C read other properties
C-----------------------------------------------------------------------
c ----- read <q>,<dq>,<n> and <dn>
if (filever(ichk).ge.8.2002d0) then
do s=1,nstate
do m=1,nmode
do n=1,nspfdof(m)
f=spfdof(n,m)
if (ldvr(f) .or. basis(f) .eq. 4 .or.
+ basis(f) .eq. 6) then
read(ichk,end=999,err=900) q,dq,expn,dexpn
else
q=0.0d0
dq=0.0d0
expn=0.0d0
dexpn=0.0d0
endif
if (lrdchk(3)) then
prop(f,s,1)=q
prop(f,s,2)=dq
prop(f,s,3)=expn
prop(f,s,4)=dexpn
endif
enddo
enddo
enddo
endif
go to 20
999 lend=.true.
20 continue
return
900 routine='Rdchck'
write(message,'(a,i5)' )
+ 'Error reading check file on channel : ',unit
call errormsg
end