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