91 subroutine construct (this, opts)
93 class(solutionhandler) :: this
94 class(options),
intent(in) :: opts
98 this % symmetry_type = opts % sym_group_flag
99 this % io_unit = opts % ci_output_unit
100 this % continuum_dimen = opts % seq_num_last_continuum_csf
101 this % vec_dimen = opts % contracted_mat_size
102 this % num_eigenpairs = opts % num_eigenpairs
103 this % vector_storage = opts % vector_storage_method
104 this % print_all_eigs = opts % print_flags(2)
106 if (.not.(
allocated(this % energy_shifts)))
then
107 allocate(this % energy_shifts(this % num_eigenpairs))
108 n = min(this % num_eigenpairs,
size(opts % energy_shifts))
109 this % energy_shifts = 0.0_wp
110 this % energy_shifts(1:n) = opts % energy_shifts(1:n)
147 subroutine write_header_sol (this, option, integrals)
149 class(solutionhandler) :: this
150 class(options),
intent(in) :: option
151 class(baseintegral),
intent(in) :: integrals
153 integer :: print_header
154 integer :: nnuc, nrec, i, buf(1), n = 1, tag = 0
155 integer :: ierror, nth, nhd(10)
158 this % core_energy = integrals % get_core_energy()
160 if (grid % grank /= master)
return
161 this % nciset = option % output_ci_set_number
162 if (option % output_ci_set_number < 0)
return
167 if (option % preceding_writer >= 0)
then
168 call mpi_mod_recv(option % preceding_writer, tag, buf, n)
171 this % size_phase = min(
size(option % phase_index), this % vec_dimen)
173 if (.not.(
allocated(this % phase)))
then
174 allocate(this % phase(this % vec_dimen))
176 this % phase(1:this % size_phase) = option % phase_index(1:this % size_phase)
179 nset = option % output_ci_set_number
182 print_header = option % print_dataset_heading
190 call movep(this % io_unit, nth, ierror, print_header, stdout)
192 if (ierror /= 0)
then
193 call mpi_xermsg(
'SolutionHandler_module',
'write_header_sol', &
194 ' ERROR POSITIONING FOR OUTPUT OF CI COEFFICIENTS', 1, 1)
198 nnuc = integrals % get_num_nuclei()
199 nrec = nnuc + this % num_eigenpairs + 1
201 write (this % io_unit) c8stars, cblank, cblank, ccidata
202 write (this % io_unit) nset, nrec, option % diag_name(1:120), nnuc, option % contracted_mat_size, &
203 this % num_eigenpairs, option % lambda, option % spin, option % spin_z, &
204 option % num_electrons, this % core_energy, option % num_target_sym, &
205 (option % lambda_continuum_orbitals_target(i), &
206 option % num_continuum_orbitals_target(i), i = 1, option % num_target_sym)
208 call integrals % write_geometries(this % io_unit)
213 call movew(this % io_unit, nth, ierror, print_header, stdout)
215 if (ierror /= 0)
then
216 call mpi_xermsg(
'SolutionHandler_module',
'write_header_sol', &
217 ' ERROR POSITIONING FOR OUTPUT OF CI COEFFICIENTS', 2, 1)
221 nhd( 2) = option % contracted_mat_size
222 nhd( 3) = this % num_eigenpairs
223 nhd( 4) = option % num_syms
224 nhd( 8) = option % contracted_mat_size
225 nhd( 9) = integrals % get_num_nuclei()
226 nhd(10) = merge(1, 0, this % num_eigenpairs < option % contracted_mat_size)
229 write (this % io_unit) nth, nhd, option % diag_name(1:120), integrals % NHE, integrals % DTNUC
233 write (stdout,
"(' CI data will be stored as set number',I3)") nset
246 subroutine export_header_sol (this, option, integrals)
248 class(solutionhandler) :: this
249 class(options),
intent(in) :: option
250 class(baseintegral),
intent(in) :: integrals
255 this % core_energy = integrals % get_core_energy()
256 this % size_phase = min(
size(option % phase_index), this % vec_dimen)
258 if (.not.(
allocated(this % phase)))
then
259 allocate(this % phase(this % vec_dimen), stat = err)
261 call mpi_xermsg(
'SolutionHandler_module',
'export_header_sol', &
262 'Error allocating internal phase array', 1, 1)
265 this % phase(1:this % size_phase) = option % phase_index(1:this % size_phase)
269 this % ci_vec % Nset = option % output_ci_set_number
270 this % ci_vec % nrec = integrals % get_num_nuclei() + this % num_eigenpairs + 1
271 this % ci_vec % name = option % diag_name
272 this % ci_vec % nnuc = integrals % get_num_nuclei()
273 this % ci_vec % nocsf = option % contracted_mat_size
274 this % ci_vec % nstat = this % num_eigenpairs
275 this % ci_vec % mgvn = option % lambda
276 this % ci_vec % s = option % spin
277 this % ci_vec % sz = option % spin_z
278 this % ci_vec % nelt = option % num_electrons
279 this % ci_vec % e0 = this % core_energy
281 if (this % ci_vec % nnuc > maxnuc)
then
282 call mpi_xermsg(
'SolutionHandler_module',
'export_header_sol', &
283 'Increase the value of maxnuc in cdenprop_defs and recompile', 2, 1)
286 select type (integrals)
287 type is (ukrmolintegral)
288 this % ci_vec % cname (1:this % ci_vec % nnuc) = integrals % cname (1:this % ci_vec % nnuc)
289 this % ci_vec % charge(1:this % ci_vec % nnuc) = integrals % charge(1:this % ci_vec % nnuc)
290 this % ci_vec % xnuc (1:this % ci_vec % nnuc) = integrals % xnuc (1:this % ci_vec % nnuc)
291 this % ci_vec % ynuc (1:this % ci_vec % nnuc) = integrals % ynuc (1:this % ci_vec % nnuc)
292 this % ci_vec % znuc (1:this % ci_vec % nnuc) = integrals % znuc (1:this % ci_vec % nnuc)
293 type is (swedenintegral)
294 this % ci_vec % cname (1:this % ci_vec % nnuc) = integrals % cname (1:this % ci_vec % nnuc)
295 this % ci_vec % charge(1:this % ci_vec % nnuc) = integrals % charge(1:this % ci_vec % nnuc)
296 this % ci_vec % xnuc (1:this % ci_vec % nnuc) = integrals % xnuc (1:this % ci_vec % nnuc)
297 this % ci_vec % ynuc (1:this % ci_vec % nnuc) = integrals % ynuc (1:this % ci_vec % nnuc)
298 this % ci_vec % znuc (1:this % ci_vec % nnuc) = integrals % znuc (1:this % ci_vec % nnuc)
300 call mpi_xermsg(
'SolutionHandler_module',
'export_header_sol', &
301 'Geometry export implemented only for UKRMOLIntegral, SWEDENIntegral', 3, 1)
304 write (stdout,
'(/,"CI VECTOR HEADER DATA:")')
305 write (stdout,
'("----------------------")')
306 write (stdout, *) this % ci_vec % nset, &
307 this % ci_vec % nrec, &
308 this % ci_vec % NAME, &
309 this % ci_vec % nnuc, &
310 this % ci_vec % nocsf, &
311 this % ci_vec % nstat, &
312 this % ci_vec % mgvn, &
314 this % ci_vec % sz, &
315 this % ci_vec % nelt, &
317 do i = 1, this % ci_vec % nnuc
318 write (stdout, *) this % ci_vec % cname(i), &
319 this % ci_vec % xnuc(i), &
320 this % ci_vec % ynuc(i), &
321 this % ci_vec % znuc(i), &
322 this % ci_vec % charge(i)
324 write (stdout,
'("----------------------")')
326 call mpi_xermsg(
'SolutionHandler_module',
'export_header_sol', &
327 'Output of ALCHEMY header not implemented yet', 4, 1)
330 write (stdout,
'(" CI data will be stored in memory for use in subsequent subroutines")')
342 subroutine shift_eigenvalues (this, output_eigenvalues, num_eigenpairs)
344 class(solutionhandler) :: this
345 integer,
intent(in) :: num_eigenpairs
346 real(wp),
intent(inout) :: output_eigenvalues(num_eigenpairs)
347 integer :: ido, jdo, neig
349 if (grid % grank /= master)
return
350 if (this % nciset < 0)
return
352 output_eigenvalues = output_eigenvalues + this % energy_shifts
354 neig = this % num_eigenpairs
355 if (this % print_all_eigs == 0)
then
356 neig = min(this % num_eigenpairs,
max_neig)
359 write (stdout,
'("ENERGY SHIFTS TO BE APPLIED")')
361 write (stdout,
"(5F20.10)") (this % energy_shifts(jdo), jdo = ido, min(ido + 4, neig))
374 subroutine write_eigenvalues (this, eigenvalues, diagonals, num_eigenpairs, vec_dimen)
376 class(solutionhandler) :: this
377 integer,
intent(in) :: num_eigenpairs, vec_dimen
378 real(wp),
intent(in) :: eigenvalues(num_eigenpairs), diagonals(vec_dimen)
379 real(wp) :: output_eigenvalues(num_eigenpairs)
380 integer :: ido, jdo, neig
382 if (grid % grank /= master)
return
383 if (this % nciset < 0)
return
385 output_eigenvalues = eigenvalues
387 neig = this % num_eigenpairs
388 if (this % print_all_eigs == 0)
then
389 neig = min(this % num_eigenpairs,
max_neig)
392 if (sum(abs(this % energy_shifts)) .gt. 0_wp)
then
393 write (stdout,
'("ORIGINAL EIGEN-ENERGIES")')
395 write (stdout,
"(16X,5F20.10)") (output_eigenvalues(jdo) + this % core_energy, jdo = ido, min(ido + 4, neig))
397 call this % shift_eigenvalues(output_eigenvalues, num_eigenpairs)
400 write (stdout,
'("EIGEN-ENERGIES")')
402 write (stdout,
"(16X,5F20.10)") (output_eigenvalues(jdo) + this % core_energy, jdo = ido, min(ido + 4, neig))
404 write (this % io_unit) this % phase, output_eigenvalues, diagonals
416 subroutine export_eigenvalues (this, eigenvalues, diagonals, num_eigenpairs, vec_dimen, ei, iphz)
418 class(solutionhandler) :: this
419 integer,
intent(in) :: num_eigenpairs, vec_dimen
420 real(wp),
intent(in) :: eigenvalues(num_eigenpairs), diagonals(vec_dimen)
421 real(wp),
allocatable :: ei(:)
422 real(wp) :: output_eigenvalues(num_eigenpairs)
423 integer,
allocatable :: iphz(:)
424 integer :: ido, jdo, err
426 output_eigenvalues = eigenvalues
428 if (sum(abs(this % energy_shifts)) .gt. 0_wp)
then
429 call this % shift_eigenvalues(output_eigenvalues, num_eigenpairs)
432 if (
allocated(ei))
deallocate(ei)
433 allocate(ei, source = output_eigenvalues, stat = err)
435 call mpi_xermsg(
'SolutionHandler_module',
'export_eigenvalues',
'Error allocating ei',
size(output_eigenvalues), 1)
438 if (
allocated(iphz))
deallocate(iphz)
439 allocate(iphz, source = this % phase, stat = err)
441 call mpi_xermsg(
'SolutionHandler_module',
'export_eigenvalues',
'Error allocating iphz',
size(this % phase), 1)
454 subroutine write_eigenvector (this, eigenvector, vec_dimen)
456 class(solutionhandler) :: this
457 integer,
intent(in) :: vec_dimen
458 real(wp),
intent(in) :: eigenvector(vec_dimen)
459 integer :: start_dimen, end_dimen, ido, j
461 if (grid % grank /= master)
return
462 if (this % nciset < 0)
return
464 this % current_eigenvector = this % current_eigenvector + 1
467 end_dimen = this % vec_dimen
470 end_dimen = this % continuum_dimen
473 start_dimen = this % continuum_dimen + 1
476 write (this % io_unit) this % current_eigenvector, (eigenvector(j), j = start_dimen, end_dimen)
490 class(solutionhandler) :: this
491 class(options),
intent(in) :: option
492 integer :: print_header, ierror, nset, nrec, nnuc, nth, nocsf, nstat, mgvn, nelt, i, j, m
493 integer(blasint) :: one = 1
494 real(wp) :: e0, s, sz
495 real(wp),
allocatable :: vec(:), ei(:), phase(:)
496 character(len=NAME_LEN_MAX) :: diag_name
498 nset = option % output_ci_set_number
500 print_header = option % print_dataset_heading
502 this % ci_vec % CV_is_scalapack = .true.
503 this % ci_vec % blacs_context = grid % gcntxt
504 this % ci_vec % myrow = grid % mygrow
505 this % ci_vec % mycol = grid % mygcol
506 this % ci_vec % nprow = grid % gprows
507 this % ci_vec % npcol = grid % gpcols
509 call this % ci_vec % init_CV(this % vec_dimen, this % num_eigenpairs)
511 allocate (this % ci_vec % ei(this % num_eigenpairs), ei(this % num_eigenpairs))
512 allocate (this % ci_vec % iphz(this % num_eigenpairs), phase(this % num_eigenpairs))
513 allocate (vec(this % vec_dimen))
515 if (grid % grank == master)
then
516 call movep(this % io_unit, nth, ierror, print_header, stdout)
518 if (ierror /= 0)
then
519 call mpi_xermsg(
'SolutionHandler_module',
'read_from_file',
'Failed to read eigensolution', 1, 1)
523 read (this % io_unit)
524 read (this % io_unit) nset, nrec, diag_name, nnuc, nocsf, nstat, mgvn, s, sz, nelt, e0
528 read (this % io_unit)
532 read (this % io_unit) phase, ei
538#if defined(usempi) && defined(scalapack)
540 call dgsum2d(grid % gcntxt,
'all',
' ', this % vec_dimen, one, phase, this % vec_dimen, -one, -one)
541 call dgsum2d(grid % gcntxt,
'all',
' ', this % vec_dimen, one, ei, this % vec_dimen, -one, -one)
544 this % ci_vec % iphz = phase
545 this % ci_vec % ei = ei
548 do j = 1, this % num_eigenpairs
551 if (grid % grank == master)
then
552 read (this % io_unit) m, vec
554#if defined(usempi) && defined(scalapack)
556 call dgsum2d(grid % gcntxt,
'all',
' ', this % vec_dimen, one, vec, this % vec_dimen, -one, -one)
559 do i = 1, this % vec_dimen
560 call this % ci_vec % set_CV_element(vec(i), i, j)
575 subroutine finalize_solutions_sol (this, option)
577 class(solutionhandler) :: this
578 class(options),
intent(in) :: option
580 integer :: buf(1), tag = 0, n = 1
582 flush(this % io_unit)
583 close(this % io_unit)
585 if (option % following_writer >= 0)
then
586 call mpi_mod_isend(option % following_writer, buf, tag, n)