Octopus
output.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22module output_oct_m
23 use accel_oct_m
24 use basins_oct_m
25 use box_oct_m
26 use comm_oct_m
27 use cube_oct_m
30 use debug_oct_m
33 use dos_oct_m
35 use elf_oct_m
38 use fft_oct_m
41 use global_oct_m
42 use grid_oct_m
45 use io_oct_m
47 use ions_oct_m
48 use, intrinsic :: iso_fortran_env
51 use lasers_oct_m
52 use lda_u_oct_m
55 use loct_oct_m
56 use math_oct_m
58 use mesh_oct_m
61 use mpi_oct_m
67 use parser_oct_m
70 use smear_oct_m
71 use space_oct_m
76 use stress_oct_m
77 use string_oct_m
81 use unit_oct_m
83 use utils_oct_m
85 use v_ks_oct_m
86 use xc_oct_m
87 use xc_oep_oct_m
89 use xc_f03_lib_m
90 use xc_vxc_oct_m
91
92 implicit none
93
94 private
95 public :: &
100 output_all, &
102 doutput_lr, &
103 zoutput_lr, &
107
108contains
109
110 subroutine output_init(outp, namespace, space, st, gr, nst, ks)
111 type(output_t), intent(out) :: outp
112 type(namespace_t), intent(in) :: namespace
113 class(space_t), intent(in) :: space
114 type(states_elec_t), intent(in) :: st
115 type(grid_t), intent(in) :: gr
116 integer, intent(in) :: nst
117 type(v_ks_t), intent(inout) :: ks
118
119 type(block_t) :: blk
120 real(real64) :: norm
121 character(len=80) :: nst_string, default
122
123 push_sub(output_init)
124 outp%what = .false.
125
126 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval)
127
128 if (outp%what(option__output__wfs_fourier)) then
129 if (accel_is_enabled()) then
130 message(1) = "Wave functions in Fourier space not supported on GPUs."
131 call messages_fatal(1, namespace=namespace)
132 end if
133 call messages_experimental("Wave-functions in Fourier space", namespace=namespace)
134 end if
135
136 ! cannot calculate the ELF in 1D
137 if (outp%what(option__output__elf) .or. outp%what(option__output__elf_basins)) then
138 if (space%dim /= 2 .and. space%dim /= 3) then
139 outp%what(option__output__elf) = .false.
140 outp%what(option__output__elf_basins) = .false.
141 write(message(1), '(a)') 'Cannot calculate ELF except in 2D and 3D.'
142 call messages_warning(1, namespace=namespace)
143 end if
144 end if
145
146
147 if (outp%what(option__output__mmb_wfs)) then
148 call messages_experimental("Model many-body wfs", namespace=namespace)
149 end if
150
151 if (outp%what(option__output__xc_torque)) then
152 if (st%d%ispin /= spinors) then
153 write(message(1), '(a)') 'The output xc_torque can only be computed for spinors.'
154 call messages_fatal(1, namespace=namespace)
155 end if
156 if (space%dim /= 3) then
157 write(message(1), '(a)') 'The output xc_torque can only be computed in the 3D case.'
158 call messages_fatal(1, namespace=namespace)
159 end if
160 end if
161 if (outp%what(option__output__mmb_den)) then
162 call messages_experimental("Model many-body density matrix", namespace=namespace)
163 ! NOTES:
164 ! could be made into block to be able to specify which dimensions to trace
165 ! in principle all combinations are interesting, but this means we need to
166 ! be able to output density matrices for multiple particles or multiple
167 ! dimensions. The current 1D 1-particle case is simple.
168 end if
169
170 if (outp%what(option__output__energy_density)) call messages_experimental("'Output = energy_density'", namespace=namespace)
171 if (outp%what(option__output__heat_current)) call messages_experimental("'Output = heat_current'", namespace=namespace)
172
173 if (outp%what(option__output__wfs) .or. outp%what(option__output__wfs_sqmod)) then
174
175 !%Variable OutputWfsNumber
176 !%Type string
177 !%Default all states
178 !%Section Output
179 !%Description
180 !% Which wavefunctions to print, in list form: <i>i.e.</i>, "1-5" to print the first
181 !% five states, "2,3" to print the second and the third state, etc.
182 !% If more states are specified than available, extra ones will be ignored.
183 !%End
184
185 write(nst_string,'(i6)') nst
186 write(default,'(a,a)') "1-", trim(adjustl(nst_string))
187 call parse_variable(namespace, 'OutputWfsNumber', default, outp%wfs_list)
188 end if
189
190 if (parse_block(namespace, 'CurrentThroughPlane', blk) == 0) then
191 if (.not. outp%what(option__output__j_flow)) then
192 outp%what(option__output__j_flow) = .true.
193 call parse_variable(namespace, 'OutputInterval', 50, outp%output_interval(option__output__j_flow))
194 end if
195
196 !%Variable CurrentThroughPlane
197 !%Type block
198 !%Section Output
199 !%Description
200 !% The code can calculate current
201 !% traversing a user-defined portion of a plane, as specified by this block.
202 !% A small plain-text file <tt>current-flow</tt> will be written containing this information.
203 !% Only available for 1D, 2D, or 3D.
204 !% In the format below, <tt>origin</tt> is a point in the plane.
205 !% <tt>u</tt> and <tt>v</tt> are the (dimensionless) vectors defining the plane;
206 !% they will be normalized. <tt>spacing</tt> is the fineness of the mesh
207 !% on the plane. Integers <tt>nu</tt> and <tt>mu</tt> are the length and
208 !% width of the portion of the plane, in units of <tt>spacing</tt>.
209 !% Thus, the grid points included in the plane are
210 !% <tt>x_ij = origin + i*spacing*u + j*spacing*v</tt>,
211 !% for <tt>nu <= i <= mu</tt> and <tt>nv <= j <= mv</tt>.
212 !% Analogously, in the 2D case, the current flow is calculated through a line;
213 !% in the 1D case, the current flow is calculated through a point. Note that the spacing
214 !% can differ from the one used in the main calculation; an interpolation will be performed.
215 !%
216 !% Example (3D):
217 !%
218 !% <tt>%CurrentThroughPlane
219 !% <br>&nbsp;&nbsp; 0.0 | 0.0 | 0.0 # origin
220 !% <br>&nbsp;&nbsp; 0.0 | 1.0 | 0.0 # u
221 !% <br>&nbsp;&nbsp; 0.0 | 0.0 | 1.0 # v
222 !% <br>&nbsp;&nbsp; 0.2 # spacing
223 !% <br>&nbsp;&nbsp; 0 | 50 # nu | mu
224 !% <br>&nbsp;&nbsp; -50 | 50 # nv | mv
225 !% <br>%</tt>
226 !%
227 !% Example (2D):
228 !%
229 !% <tt>%CurrentThroughPlane
230 !% <br>&nbsp;&nbsp; 0.0 | 0.0 # origin
231 !% <br>&nbsp;&nbsp; 1.0 | 0.0 # u
232 !% <br>&nbsp;&nbsp; 0.2 # spacing
233 !% <br>&nbsp;&nbsp; 0 | 50 # nu | mu
234 !% <br>%</tt>
235 !%
236 !% Example (1D):
237 !%
238 !% <tt>%CurrentThroughPlane
239 !% <br>&nbsp;&nbsp; 0.0 # origin
240 !% <br>%</tt>
241 !%
242 !%End
243
244 select case (space%dim)
245 case (3)
246
247 call parse_block_float(blk, 0, 0, outp%plane%origin(1), units_inp%length)
248 call parse_block_float(blk, 0, 1, outp%plane%origin(2), units_inp%length)
249 call parse_block_float(blk, 0, 2, outp%plane%origin(3), units_inp%length)
250 call parse_block_float(blk, 1, 0, outp%plane%u(1))
251 call parse_block_float(blk, 1, 1, outp%plane%u(2))
252 call parse_block_float(blk, 1, 2, outp%plane%u(3))
253 call parse_block_float(blk, 2, 0, outp%plane%v(1))
254 call parse_block_float(blk, 2, 1, outp%plane%v(2))
255 call parse_block_float(blk, 2, 2, outp%plane%v(3))
256 call parse_block_float(blk, 3, 0, outp%plane%spacing, units_inp%length)
257 call parse_block_integer(blk, 4, 0, outp%plane%nu)
258 call parse_block_integer(blk, 4, 1, outp%plane%mu)
259 call parse_block_integer(blk, 5, 0, outp%plane%nv)
260 call parse_block_integer(blk, 5, 1, outp%plane%mv)
261
262 norm = norm2(outp%plane%u(1:3))
263 if (norm < m_epsilon) then
264 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
265 call messages_fatal(1, namespace=namespace)
266 end if
267 outp%plane%u(1:3) = outp%plane%u(1:3) / norm
268
269 norm = norm2(outp%plane%v(1:3))
270 if (norm < m_epsilon) then
271 write(message(1), '(a)') 'v-vector for CurrentThroughPlane cannot have norm zero.'
272 call messages_fatal(1, namespace=namespace)
273 end if
274 outp%plane%v(1:3) = outp%plane%v(1:3) / norm
275
276 outp%plane%n(1:3) = dcross_product(outp%plane%u(1:3), outp%plane%v(1:3))
277
278 case (2)
279
280 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
281 call parse_block_float(blk, 0, 1, outp%line%origin(2), units_inp%length)
282 call parse_block_float(blk, 1, 0, outp%line%u(1))
283 call parse_block_float(blk, 1, 1, outp%line%u(2))
284 call parse_block_float(blk, 2, 0, outp%line%spacing, units_inp%length)
285 call parse_block_integer(blk, 3, 0, outp%line%nu)
286 call parse_block_integer(blk, 3, 1, outp%line%mu)
287
288 norm = norm2(outp%line%u(1:2))
289 if (norm < m_epsilon) then
290 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
291 call messages_fatal(1, namespace=namespace)
292 end if
293 outp%line%u(1:2) = outp%line%u(1:2) / norm
294
295 outp%line%n(1) = -outp%line%u(2)
296 outp%line%n(2) = outp%line%u(1)
297
298 case (1)
299
300 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
301
302 case default
303
304 call messages_not_implemented("CurrentThroughPlane for 4D or higher", namespace=namespace)
305
306 end select
307 call parse_block_end(blk)
308 end if
309
310 if (outp%what(option__output__matrix_elements)) then
311 call output_me_init(outp%me, namespace, space, st, gr, nst)
312 else
313 outp%me%what = .false.
314 end if
315
316 if (outp%what(option__output__berkeleygw)) then
317 if (accel_is_enabled()) then
318 message(1) = "BerkeleyGW is not compatible with GPUs."
319 call messages_fatal(1, namespace=namespace)
320 end if
321 call output_berkeleygw_init(nst, namespace, outp%bgw, space%periodic_dim)
322 end if
323
324 ! required for output_hamiltonian()
325 if (outp%what(option__output__potential_gradient) .and. .not. outp%what(option__output__potential)) then
326 outp%what(option__output__potential) = .true.
327 outp%output_interval(option__output__potential) = outp%output_interval(option__output__potential_gradient)
328 end if
329
330
331 !%Variable OutputDuringSCF
332 !%Type logical
333 !%Default no
334 !%Section Output
335 !%Description
336 !% During <tt>gs</tt> and <tt>unocc</tt> runs, if this variable is set to yes,
337 !% output will be written after every <tt>OutputInterval</tt> iterations.
338 !%End
339 call parse_variable(namespace, 'OutputDuringSCF', .false., outp%duringscf)
340
341 if (parse_is_defined(namespace, 'RestartWriteInterval')) then
342 write(message(1), '(a)') 'Input variable RestartWriteInterval is obsolete.'
343 write(message(2), '(a)') 'Restart files are now written in periods of the wallclock time'
344 write(message(3), '(a)') 'given by RestartWallTimePeriod, so you can simply delete this variable.'
345 call messages_fatal(3, only_root_writes=.true., namespace=namespace)
346 end if
347
348 !%Variable OutputIterDir
349 !%Default "output_iter"
350 !%Type string
351 !%Section Output
352 !%Description
353 !% The name of the directory where <tt>Octopus</tt> stores information
354 !% such as the density, forces, etc. requested by variable <tt>Output</tt>
355 !% in the format specified by <tt>OutputFormat</tt>.
356 !% This information is written while iterating <tt>CalculationMode = gs</tt>, <tt>unocc</tt>, or <tt>td</tt>,
357 !% according to <tt>OutputInterval</tt>, and has nothing to do with the restart information.
358 !%End
359 call parse_variable(namespace, 'OutputIterDir', "output_iter", outp%iter_dir)
360 if (any(outp%what) .and. any(outp%output_interval > 0)) then
361 call io_mkdir(outp%iter_dir, namespace)
362 end if
363 call add_last_slash(outp%iter_dir)
364
365 ! At this point, we don`t know whether the states will be real or complex.
366 ! We therefore pass .false. to states_are_real, and need to check for real states later.
367
368 if (output_needs_current(outp, .false.)) then
369 call v_ks_calculate_current(ks, .true.)
370 else
371 call v_ks_calculate_current(ks, .false.)
372 end if
373
374 if (outp%what(option__output__current_dia)) then
375 message(1) = "The diamagnetic current will be calculated only if CalculateDiamagneticCurrent = yes."
376 call messages_warning(1, namespace=namespace)
377 end if
378
379 pop_sub(output_init)
380 end subroutine output_init
381
382 ! ---------------------------------------------------------
383 subroutine output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
384 type(output_t), intent(in) :: outp
385 type(namespace_t), intent(in) :: namespace
386 class(space_t), intent(in) :: space
387 character(len=*), intent(in) :: dir
388 type(grid_t), intent(in) :: gr
389 type(ions_t), intent(in) :: ions
390 integer, intent(in) :: iter
391 type(states_elec_t), intent(inout) :: st
392 type(hamiltonian_elec_t), intent(inout) :: hm
393 type(v_ks_t), intent(inout) :: ks
394
395 integer :: idir, ierr, iunit
396 character(len=MAX_PATH_LEN) :: fname
397
398 push_sub(output_all)
399 call profiling_in("OUTPUT_ALL")
400
401 if (any(outp%what)) then
402 message(1) = "Info: Writing output to " // trim(dir)
403 call messages_info(1, namespace=namespace)
404 call io_mkdir(dir, namespace)
405 end if
406
407 if (outp%what_now(option__output__mesh_r, iter)) then
408 do idir = 1, space%dim
409 write(fname, '(a,a)') 'mesh_r-', index2axis(idir)
410 call dio_function_output(outp%how(option__output__mesh_r), dir, fname, namespace, space, &
411 gr, gr%x_t(:,idir), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
412 end do
413 end if
414
415 call output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
416 call output_hamiltonian(outp, namespace, space, dir, hm, st, gr%der, ions, gr, iter, st%st_kpt_mpi_grp)
417
418 ! We can only test against the theory level here, as it is not set in the call of output_init().
419 if (outp%what_now(option__output__el_pressure, iter)) then
420 if(ks%theory_level /= kohn_sham_dft) then
421 call messages_not_implemented("el_pressure for TheoryLevel different from kohn_sham", namespace=namespace)
422 end if
423 if (st%d%spin_channels > 1) then
424 call messages_not_implemented("el_pressure for spin-polarized or spinors", namespace=namespace)
425 end if
426 end if
427
428 !hm not initialized yet when calling output_init()
429 if (outp%what(option__output__kanamoriu) .and. hm%lda_u_level /= dft_u_acbn0) then
430 message(1) = "kanamoriU output can only be computed for DFTULevel = dft_u_acbn0"
431 call messages_fatal(1, namespace=namespace)
432 end if
433
434
435 call output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
436
437 if (outp%what_now(option__output__j_flow, iter)) then
438 call output_current_flow(outp, namespace, space, dir, gr, st, hm%kpoints)
439 end if
440
441 if (outp%what_now(option__output__geometry, iter)) then
442 if (bitand(outp%how(option__output__geometry), option__outputformat__xcrysden) /= 0) then
443 call write_xsf_geometry_file(dir, "geometry", space, ions%latt, ions%pos, ions%atom, gr, namespace)
444 end if
445 if (bitand(outp%how(option__output__geometry), option__outputformat__xyz) /= 0) then
446 call ions%write_xyz(trim(dir)//'/geometry')
447 if (ions%space%is_periodic()) then
448 call ions%write_crystal(dir)
449 end if
450 end if
451 if (bitand(outp%how(option__output__geometry), option__outputformat__vtk) /= 0) then
452 call ions%write_vtk_geometry(trim(dir)//'/geometry')
453 end if
454 if (bitand(outp%how(option__output__geometry), option__outputformat__poscar) /= 0) then
455 call ions%write_poscar(trim(dir)//'/POSCAR')
456 end if
457 end if
458
459 if (outp%what_now(option__output__forces, iter)) then
460 if (bitand(outp%how(option__output__forces), option__outputformat__bild) /= 0) then
461 call ions%write_bild_forces_file(dir, "forces")
462 else
463 call write_xsf_geometry_file(dir, "forces", space, ions%latt, ions%pos, ions%atom, &
464 gr, namespace, total_forces = ions%tot_force)
465 end if
466 end if
467
468 if (outp%what_now(option__output__matrix_elements, iter)) then
469 call output_me(outp%me, namespace, space, dir, st, gr, ions, hm)
470 end if
471
472 if (outp%what_now(option__output__berkeleygw, iter)) then
473 call output_berkeleygw(outp%bgw, namespace, space, dir, st, gr, ks, hm, ions)
474 end if
475
476 if (outp%what_now(option__output__energy_density, iter)) then
477 call output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
478 end if
479
480 if (outp%what_now(option__output__stress, iter)) then
481 call io_mkdir(dir, namespace)
482 iunit = io_open(trim(dir)//'/stress', namespace, action='write')
483 call output_stress(iunit, space%periodic_dim, st%stress_tensors)
484 call io_close(iunit)
485 end if
486
487 if (hm%lda_u_level /= dft_u_none) then
488 if (outp%what_now(option__output__occ_matrices, iter))&
489 call lda_u_write_occupation_matrices(dir, hm%lda_u, st, namespace)
490
491 if (outp%what_now(option__output__effectiveu, iter))&
492 call lda_u_write_effectiveu(dir, hm%lda_u, st, namespace)
493
494 if (outp%what_now(option__output__magnetization, iter))&
495 call lda_u_write_magnetization(dir, hm%lda_u, ions, gr, st, namespace)
496
497 if (outp%what_now(option__output__local_orbitals, iter))&
498 call output_dftu_orbitals(outp, dir, namespace, space, hm%lda_u, st, gr, ions, hm%phase%is_allocated())
499
500 if (outp%what_now(option__output__kanamoriu, iter))&
501 call lda_u_write_kanamoriu(dir, st, hm%lda_u, namespace)
502
503 if (ks%v_ks_photons%oep_full()) then
504 if (outp%what_now(option__output__photon_correlator, iter)) then
505 write(fname, '(a)') 'photon_correlator'
506 call dio_function_output(outp%how(option__output__photon_correlator), dir, trim(fname), namespace, space, &
507 gr, ks%v_ks_photons%correlator(), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
508 end if
509 end if
510 end if
511
512 ! We can only test against the theory level here, as it is not set in the call of output_init().
513 if (outp%what_now(option__output__xc_torque, iter)) then
514 if (ks%theory_level /= kohn_sham_dft .and. ks%theory_level /= generalized_kohn_sham_dft) then
515 write(message(1), '(a)') 'The output xc_torque can only be computed when there is a xc potential.'
516 call messages_fatal(1, namespace=namespace)
517 end if
518 end if
519
520 call output_xc_torque(outp, namespace, dir, gr, hm, st, ions, ions%space)
521
522 call profiling_out("OUTPUT_ALL")
523 pop_sub(output_all)
524 end subroutine output_all
525
526
527 ! ---------------------------------------------------------
528 subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
529 type(output_t), intent(in) :: outp
530 type(namespace_t), intent(in) :: namespace
531 class(space_t), intent(in) :: space
532 character(len=*), intent(in) :: dir
533 type(states_elec_t), intent(inout) :: st
534 type(hamiltonian_elec_t), intent(in) :: hm
535 type(grid_t), intent(in) :: gr
536 type(ions_t), intent(in) :: ions
537 integer, intent(in) :: iter
538
539 real(real64), allocatable :: f_loc(:,:)
540 character(len=MAX_PATH_LEN) :: fname
541 integer :: is, ierr, imax
542 type(mpi_grp_t) :: mpi_grp
543
545
546 mpi_grp = st%dom_st_kpt_mpi_grp
547
548 ! if SPIN_POLARIZED, the ELF contains one extra channel: the total ELF
549 imax = st%d%nspin
550 if (st%d%ispin == spin_polarized) imax = 3
551
552 safe_allocate(f_loc(1:gr%np, 1:imax))
553
554 ! First the ELF in real space
555 if (outp%what_now(option__output__elf, iter) .or. outp%what_now(option__output__elf_basins, iter)) then
556 assert(space%dim /= 1)
557
558 call elf_calc(space, st, gr, hm%kpoints, f_loc)
559
560 ! output ELF in real space
561 if (outp%what_now(option__output__elf, iter)) then
562 write(fname, '(a)') 'elf_rs'
563 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
564 f_loc(:,imax), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
565 ! this quantity is dimensionless
566
567 if (st%d%ispin /= unpolarized) then
568 do is = 1, 2
569 write(fname, '(a,i1)') 'elf_rs-sp', is
570 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
571 f_loc(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
572 ! this quantity is dimensionless
573 end do
574 end if
575 end if
576
577 if (outp%what_now(option__output__elf_basins, iter)) then
578 call out_basins(f_loc(:,1), "elf_rs_basins", outp%how(option__output__elf_basins))
579 end if
580 end if
581
582 ! Now Bader analysis
583 if (outp%what_now(option__output__bader, iter)) then
584 do is = 1, st%d%nspin
585 call dderivatives_lapl(gr%der, st%rho(:,is), f_loc(:,is))
586
587 fname = get_filename_with_spin('bader', st%d%nspin, is)
588
589 call dio_function_output(outp%how(option__output__bader), dir, trim(fname), namespace, space, gr, &
590 f_loc(:,is), units_out%length**(-2 - space%dim), ierr, &
591 pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
592
593 fname = get_filename_with_spin('bader_basins', st%d%nspin, is)
594 call out_basins(f_loc(:, is), fname, outp%how(option__output__bader))
595 end do
596 end if
597
598 ! Now the pressure
599 if (outp%what_now(option__output__el_pressure, iter)) then
600 call calc_electronic_pressure(st, hm, gr, f_loc(:,1))
601 call dio_function_output(outp%how(option__output__el_pressure), dir, "el_pressure", namespace, space, gr, &
602 f_loc(:,1), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
603 ! this quantity is dimensionless
604 end if
605
606 safe_deallocate_a(f_loc)
607
609
610 contains
611 ! ---------------------------------------------------------
612 subroutine out_basins(ff, filename, output_how)
613 real(real64), intent(in) :: ff(:)
614 character(len=*), intent(in) :: filename
615 integer(int64), intent(in) :: output_how
616
617 character(len=MAX_PATH_LEN) :: fname
618 type(basins_t) :: basins
619 integer :: iunit
620
622
623 call basins_init(basins, namespace, gr)
624 call basins_analyze(basins, namespace, gr, ff(:), st%rho, 0.01_real64)
625
626 call dio_function_output(output_how, dir, trim(filename), namespace, space, gr, &
627 real(basins%map, real64) , unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
628 ! this quantity is dimensionless
629
630 write(fname,'(4a)') trim(dir), '/', trim(filename), '.info'
631 iunit = io_open(trim(fname), namespace, action = 'write')
632 call basins_write(basins, gr, iunit)
633 call io_close(iunit)
634
635 call basins_end(basins)
636
638 end subroutine out_basins
639
640 end subroutine output_localization_funct
641
642
643 ! ---------------------------------------------------------
644 subroutine calc_electronic_pressure(st, hm, gr, pressure)
645 type(states_elec_t), intent(inout) :: st
646 type(hamiltonian_elec_t), intent(in) :: hm
647 type(grid_t), intent(in) :: gr
648 real(real64), intent(out) :: pressure(:)
649
650 real(real64), allocatable :: rho(:,:), lrho(:), tau(:,:)
651 real(real64) :: p_tf, dens
652 integer :: is, ii
653
655
656 safe_allocate( rho(1:gr%np_part, 1:st%d%nspin))
657 safe_allocate(lrho(1:gr%np))
658 safe_allocate( tau(1:gr%np, 1:st%d%nspin))
659
660 rho = m_zero
661 call density_calc(st, gr, rho)
662 call states_elec_calc_quantities(gr, st, hm%kpoints, .false., kinetic_energy_density = tau)
663
664 pressure = m_zero
665 do is = 1, st%d%spin_channels
666 lrho = m_zero
667 call dderivatives_lapl(gr%der, rho(:, is), lrho)
668
669 pressure(:) = pressure(:) + &
670 tau(:, is)/m_three - lrho(:)/m_four
671 end do
672
673 do ii = 1, gr%np
674 dens = sum(rho(ii,1:st%d%spin_channels))
675
676 p_tf = m_two/m_five*(m_three*m_pi**2)**(m_two/m_three)* &
677 dens**(m_five/m_three)
678
679 ! add XC pressure
680 ! FIXME: Not correct for spinors and spin-polarized here
681 pressure(ii) = pressure(ii) + (dens*hm%ks_pot%vxc(ii,1) - hm%energy%exchange - hm%energy%correlation)
682
683 pressure(ii) = pressure(ii)/p_tf
684 pressure(ii) = m_half*(m_one + pressure(ii)/sqrt(m_one + pressure(ii)**2))
685 end do
686
688 end subroutine calc_electronic_pressure
689
690
691 ! ---------------------------------------------------------
692 subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
693 type(output_t), intent(in) :: outp
694 type(namespace_t), intent(in) :: namespace
695 class(space_t), intent(in) :: space
696 character(len=*), intent(in) :: dir
697 type(hamiltonian_elec_t), intent(in) :: hm
698 type(v_ks_t), intent(inout) :: ks
699 type(states_elec_t), intent(in) :: st
700 type(ions_t), intent(in) :: ions
701 type(grid_t), intent(in) :: gr
702
703 integer :: is, ierr, ip
704 character(len=MAX_PATH_LEN) :: fname
705 type(unit_t) :: fn_unit
706 real(real64), allocatable :: energy_density(:, :)
707 real(real64), allocatable :: ex_density(:)
708 real(real64), allocatable :: ec_density(:)
709
710 push_sub(output_energy_density)
711
712 fn_unit = units_out%energy*units_out%length**(-space%dim)
713 safe_allocate(energy_density(1:gr%np, 1:st%d%nspin))
714
715 ! the kinetic energy density
716 call states_elec_calc_quantities(gr, st, hm%kpoints, .true., kinetic_energy_density = energy_density)
717
718 ! the external potential energy density
719 do is = 1, st%d%nspin
720 do ip = 1, gr%np
721 energy_density(ip, is) = energy_density(ip, is) + st%rho(ip, is)*hm%ep%vpsl(ip)
722 end do
723 end do
724
725 ! the hartree energy density
726 do is = 1, st%d%nspin
727 do ip = 1, gr%np
728 energy_density(ip, is) = energy_density(ip, is) + m_half*st%rho(ip, is)*hm%ks_pot%vhartree(ip)
729 end do
730 end do
731
732 ! the XC energy density
733 safe_allocate(ex_density(1:gr%np))
734 safe_allocate(ec_density(1:gr%np))
735
736 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
737 hm%ions%latt%rcell_volume, ex_density = ex_density, ec_density = ec_density)
738 do is = 1, st%d%nspin
739 do ip = 1, gr%np
740 energy_density(ip, is) = energy_density(ip, is) + ex_density(ip) + ec_density(ip)
741 end do
742 end do
743
744 safe_deallocate_a(ex_density)
745 safe_deallocate_a(ec_density)
746
747 do is = 1, st%d%spin_channels
748 fname = get_filename_with_spin('energy_density', st%d%nspin, is)
749 call dio_function_output(outp%how(option__output__energy_density), dir, trim(fname), namespace, space, gr, &
750 energy_density(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
751 end do
752 safe_deallocate_a(energy_density)
753
754 pop_sub(output_energy_density)
755 end subroutine output_energy_density
756
757 !--------------------------------------------------------------
758
759 logical function output_need_exchange(outp) result(need_exx)
760 type(output_t), intent(in) :: outp
761
762 need_exx =(outp%what(option__output__berkeleygw) &
763 .or. outp%me%what(option__outputmatrixelements__two_body) &
764 .or. outp%me%what(option__outputmatrixelements__two_body_exc_k))
765 end function output_need_exchange
766
767
768 ! ---------------------------------------------------------
769 subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
770 type(output_t), intent(in) :: outp
771 character(len=*), intent(in) :: dir
772 type(namespace_t), intent(in) :: namespace
773 class(space_t), intent(in) :: space
774 type(lda_u_t), intent(in) :: this
775 type(states_elec_t), intent(in) :: st
776 class(mesh_t), intent(in) :: mesh
777 type(ions_t), intent(in) :: ions
778 logical, intent(in) :: has_phase
779
780 integer :: ios, im, ik, idim, ierr
781 complex(real64), allocatable :: tmp(:)
782 real(real64), allocatable :: dtmp(:)
783 type(orbitalset_t), pointer :: os
784 type(unit_t) :: fn_unit
785 character(len=MAX_PATH_LEN) :: fname
786
788
789 fn_unit = sqrt(units_out%length**(-space%dim))
790
791 if (this%basis%use_submesh) then
792 if (states_are_real(st)) then
793 safe_allocate(dtmp(1:mesh%np))
794 else
795 safe_allocate(tmp(1:mesh%np))
796 end if
797 end if
798
799 do ios = 1, this%norbsets
800 os => this%orbsets(ios)
801 do ik = st%d%kpt%start, st%d%kpt%end
802 do im = 1, this%orbsets(ios)%norbs
803 do idim = 1, min(os%ndim, st%d%dim)
804 if (st%nik > 1) then
805 if (min(os%ndim, st%d%dim) > 1) then
806 write(fname, '(a,i1,a,i3.3,a,i8.8,a,i1)') 'orb', im, '-os', ios, '-k', ik, '-sp', idim
807 else
808 write(fname, '(a,i1,a,i3.3,a,i8.8)') 'orb', im, '-os', ios, '-k', ik
809 end if
810 else
811 if (min(os%ndim, st%d%dim) > 1) then
812 write(fname, '(a,i1,a,i3.3,a,i1)') 'orb', im, '-os', ios, '-sp', idim
813 else
814 write(fname, '(a,i1,a,i3.3)') 'orb', im, '-os', ios
815 end if
816 end if
817 if (has_phase) then
818 if (.not. this%basis%use_submesh) then
819 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
820 mesh, os%eorb_mesh(1:mesh%np,im,idim,ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
821 else
822 tmp = m_z0
823 call submesh_add_to_mesh(os%sphere, os%eorb_submesh(1:os%sphere%np,idim,im,ik), tmp)
824 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
825 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
826 end if
827 else
828 if (.not. this%basis%use_submesh) then
829 if (states_are_real(st)) then
830 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
831 os%dorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
832 else
833 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
834 os%zorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
835 end if
836 else
837 if (states_are_real(st)) then
838 dtmp = m_zero
839 call submesh_add_to_mesh(os%sphere, os%dorb(1:os%sphere%np,idim,im), dtmp)
840 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
841 mesh, dtmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
842 else
843 tmp = m_z0
844 call submesh_add_to_mesh(os%sphere, os%zorb(1:os%sphere%np,idim,im), tmp)
845 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
846 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
847 end if
848 end if
849 end if
850 end do
851 end do
852 end do
853 end do
855 safe_deallocate_a(tmp)
856 safe_deallocate_a(dtmp)
857
858 pop_sub(output_dftu_orbitals)
859 end subroutine output_dftu_orbitals
860
861 ! ---------------------------------------------------------
862 logical function output_needs_current(outp, states_are_real)
863 type(output_t), intent(in) :: outp
864 logical, intent(in) :: states_are_real
865
866 output_needs_current = .false.
867
868 if (outp%what(option__output__current) &
869 .or. outp%what(option__output__current_dia) &
870 .or. outp%what(option__output__heat_current) &
871 .or. outp%what(option__output__current_kpt)) then
872 if (.not. states_are_real) then
874 else
875 message(1) = 'No current density output for real states since it is identically zero.'
876 call messages_warning(1)
877 end if
878 end if
879
880
881 end function
882
883#include "output_states_inc.F90"
884
885#include "output_h_inc.F90"
886
887#include "undef.F90"
888#include "complex.F90"
889#include "output_linear_response_inc.F90"
890
891#include "undef.F90"
892#include "real.F90"
893#include "output_linear_response_inc.F90"
894
895end module output_oct_m
896
897!! Local Variables:
898!! mode: f90
899!! coding: utf-8
900!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
subroutine, public basins_write(this, mesh, iunit)
Definition: basins.F90:354
subroutine, public basins_init(this, namespace, mesh)
Definition: basins.F90:153
subroutine, public basins_analyze(this, namespace, mesh, f, rho, threshold)
Definition: basins.F90:190
subroutine, public basins_end(this)
Definition: basins.F90:172
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
Module that handles computing and output of various density of states.
Definition: dos.F90:118
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
subroutine, public elf_calc(space, st, gr, kpoints, elf, de)
(time-dependent) electron localization function, (TD)ELF.
Definition: elf.F90:169
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:120
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
complex(real64), parameter, public m_z0
Definition: global.F90:210
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
real(real64), parameter, public m_three
Definition: global.F90:203
real(real64), parameter, public m_five
Definition: global.F90:205
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines classes and functions for interaction partners.
subroutine, public zio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
subroutine, public io_function_read_what_how_when(namespace, space, what, how, output_interval, what_tag_in, how_tag_in, output_interval_tag_in, ignore_error)
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
subroutine, public write_xsf_geometry_file(dir, fname, space, latt, pos, atoms, mesh, namespace, total_forces)
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
A module to handle KS potential, without the external potential.
subroutine, public lda_u_write_occupation_matrices(dir, this, st, namespace)
Prints the occupation matrices at the end of the scf calculation.
Definition: lda_u_io.F90:158
subroutine, public lda_u_write_kanamoriu(dir, st, this, namespace)
Definition: lda_u_io.F90:352
subroutine, public lda_u_write_effectiveu(dir, this, st, namespace)
Definition: lda_u_io.F90:266
subroutine, public lda_u_write_magnetization(dir, this, ions, mesh, st, namespace)
Definition: lda_u_io.F90:480
integer, parameter, public dft_u_none
Definition: lda_u.F90:205
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:205
System information (time, memory, sysname)
Definition: loct.F90:117
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
pure real(real64) function, dimension(1:3), public dcross_product(a, b)
Definition: math.F90:1909
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
subroutine, public output_berkeleygw(bgw, namespace, space, dir, st, gr, ks, hm, ions)
subroutine, public output_berkeleygw_init(nst, namespace, bgw, periodic_dim)
this module contains the low-level part of the output system
Definition: output_low.F90:117
character(len=max_path_len) function, public get_filename_with_spin(output, nspin, spin_index)
Returns the filame as output, or output-spX is spin polarized.
Definition: output_low.F90:233
subroutine, public output_me_init(this, namespace, space, st, gr, nst)
Definition: output_me.F90:157
subroutine, public output_me(this, namespace, space, dir, st, gr, ions, hm)
Definition: output_me.F90:288
this module contains the output system
Definition: output.F90:117
subroutine calc_electronic_pressure(st, hm, gr, pressure)
Definition: output.F90:740
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:999
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:958
subroutine, public output_hamiltonian(outp, namespace, space, dir, hm, st, der, ions, gr, iter, grp)
Definition: output.F90:1307
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:479
logical function, public output_need_exchange(outp)
Definition: output.F90:855
subroutine, public output_init(outp, namespace, space, st, gr, nst, ks)
Definition: output.F90:206
subroutine output_xc_torque(outp, namespace, dir, mesh, hm, st, ions, space)
Definition: output.F90:1630
subroutine, public output_current_flow(outp, namespace, space, dir, gr, st, kpoints)
Definition: output.F90:1197
subroutine, public zoutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:1737
subroutine, public doutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:1970
subroutine, public output_scalar_pot(outp, namespace, space, dir, mesh, ions, ext_partners, time)
Definition: output.F90:1593
subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
Definition: output.F90:788
subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
Definition: output.F90:865
subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
Definition: output.F90:624
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
pure logical function, public states_are_real(st)
This module defines routines to write information about states.
subroutine, public states_elec_calc_quantities(gr, st, kpoints, nlcc, kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, gi_kinetic_energy_density, st_end)
calculated selected quantities
This module implements the calculation of the stress tensor.
Definition: stress.F90:120
subroutine, public output_stress(iunit, space_dim, stress_tensors, all_terms)
Definition: stress.F90:1080
subroutine, public add_last_slash(str)
Adds a '/' in the end of the string, only if it missing. Useful for directories.
Definition: string.F90:162
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120
character pure function, public index2axis(idir)
Definition: utils.F90:205
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1457
Definition: xc.F90:120
subroutine, public xc_get_vxc(gr, xcs, st, kpoints, psolver, namespace, space, rho, ispin, rcell_volume, vxc, ex, ec, deltaxc, vtau, ex_density, ec_density, stress_xc, force_orbitalfree, force_host)
Definition: xc_vxc.F90:191
subroutine out_basins(ff, filename, output_how)
Definition: output.F90:708
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Class to describe DFT+U parameters.
Definition: lda_u.F90:218
Describes mesh distribution to nodes.
Definition: mesh.F90:187
This is defined even when running serial.
Definition: mpi.F90:144
Output information for BerkeleyGW.
Definition: output_low.F90:147
output handler class
Definition: output_low.F90:166
The states_elec_t class contains all electronic wave functions.
int true(void)