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
52 use lasers_oct_m
53 use lda_u_oct_m
56 use loct_oct_m
57 use math_oct_m
59 use mesh_oct_m
62 use mpi_oct_m
68 use parser_oct_m
71 use smear_oct_m
72 use space_oct_m
77 use stress_oct_m
78 use string_oct_m
82 use unit_oct_m
84 use utils_oct_m
86 use v_ks_oct_m
87 use xc_oct_m
88 use xc_oep_oct_m
90 use xc_f03_lib_m
91 use xc_vxc_oct_m
92
93 implicit none
95 private
96 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:3) = dcross_product(outp%plane%u(1:3), outp%plane%v(1:3))
279
280 case (2)
281
282 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
283 call parse_block_float(blk, 0, 1, outp%line%origin(2), units_inp%length)
284 call parse_block_float(blk, 1, 0, outp%line%u(1))
285 call parse_block_float(blk, 1, 1, outp%line%u(2))
286 call parse_block_float(blk, 2, 0, outp%line%spacing, units_inp%length)
287 call parse_block_integer(blk, 3, 0, outp%line%nu)
288 call parse_block_integer(blk, 3, 1, outp%line%mu)
289
290 norm = norm2(outp%line%u(1:2))
291 if (norm < m_epsilon) then
292 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
293 call messages_fatal(1, namespace=namespace)
294 end if
295 outp%line%u(1:2) = outp%line%u(1:2) / norm
296
297 outp%line%n(1) = -outp%line%u(2)
298 outp%line%n(2) = outp%line%u(1)
299
300 case (1)
301
302 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
303
304 case default
305
306 call messages_not_implemented("CurrentThroughPlane for 4D or higher", namespace=namespace)
307
308 end select
309 call parse_block_end(blk)
310 end if
311
312 if (outp%what(option__output__matrix_elements)) then
313 call output_me_init(outp%me, namespace, space, st, gr, nst)
314 else
315 outp%me%what = .false.
316 end if
317
318 if (outp%what(option__output__berkeleygw)) then
319 if (accel_is_enabled()) then
320 message(1) = "BerkeleyGW is not compatible with GPUs."
321 call messages_fatal(1, namespace=namespace)
322 end if
323 call output_berkeleygw_init(nst, namespace, outp%bgw, space%periodic_dim)
324 end if
325
326 ! required for output_hamiltonian()
327 if (outp%what(option__output__potential_gradient) .and. .not. outp%what(option__output__potential)) then
328 outp%what(option__output__potential) = .true.
329 outp%output_interval(option__output__potential) = outp%output_interval(option__output__potential_gradient)
330 end if
331
332
333 !%Variable OutputDuringSCF
334 !%Type logical
335 !%Default no
336 !%Section Output
337 !%Description
338 !% During <tt>gs</tt> and <tt>unocc</tt> runs, if this variable is set to yes,
339 !% output will be written after every <tt>OutputInterval</tt> iterations.
340 !%End
341 call parse_variable(namespace, 'OutputDuringSCF', .false., outp%duringscf)
342
343 if (parse_is_defined(namespace, 'RestartWriteInterval')) then
344 write(message(1), '(a)') 'Input variable RestartWriteInterval is obsolete.'
345 write(message(2), '(a)') 'Restart files are now written in periods of the wallclock time'
346 write(message(3), '(a)') 'given by RestartWallTimePeriod, so you can simply delete this variable.'
347 call messages_fatal(3, only_root_writes=.true., namespace=namespace)
348 end if
349
350 !%Variable OutputIterDir
351 !%Default "output_iter"
352 !%Type string
353 !%Section Output
354 !%Description
355 !% The name of the directory where <tt>Octopus</tt> stores information
356 !% such as the density, forces, etc. requested by variable <tt>Output</tt>
357 !% in the format specified by <tt>OutputFormat</tt>.
358 !% This information is written while iterating <tt>CalculationMode = gs</tt>, <tt>unocc</tt>, or <tt>td</tt>,
359 !% according to <tt>OutputInterval</tt>, and has nothing to do with the restart information.
360 !%End
361 call parse_variable(namespace, 'OutputIterDir', "output_iter", outp%iter_dir)
362 if (any(outp%what) .and. any(outp%output_interval > 0)) then
363 call io_mkdir(outp%iter_dir, namespace)
364 end if
365 call add_last_slash(outp%iter_dir)
366
367 ! At this point, we don`t know whether the states will be real or complex.
368 ! We therefore pass .false. to states_are_real, and need to check for real states later.
369
370 if (output_needs_current(outp, .false.)) then
371 call v_ks_calculate_current(ks, .true.)
372 else
373 call v_ks_calculate_current(ks, .false.)
374 end if
375
376 if (outp%what(option__output__current_dia)) then
377 message(1) = "The diamagnetic current will be calculated only if CalculateDiamagneticCurrent = yes."
378 call messages_warning(1, namespace=namespace)
379 end if
380
381 pop_sub(output_init)
382 end subroutine output_init
383
384 ! ---------------------------------------------------------
392 subroutine output_check_generalized_overlap(outp, st, namespace)
393 type(output_t), intent(in) :: outp
394 type(states_elec_t), intent(in) :: st
395 type(namespace_t), intent(in) :: namespace
396
398
399 if (st%requires_generalized_overlap) then
400 ! The current density is experimental.
401 if (outp%what(option__output__current) .or. outp%what(option__output__current_dia) .or. &
402 outp%what(option__output__current_kpt) .or. outp%what(option__output__j_flow)) then
403 call messages_experimental("Output of the current density with ultrasoft/PAW", namespace=namespace)
404 end if
405
406 ! The heat (energy) current is a different operator, which is not yet implemented for USPP.
407 if (outp%what(option__output__heat_current)) then
408 call messages_not_implemented("Output of the heat current with ultrasoft/PAW", namespace=namespace)
409 end if
410 if (outp%what(option__output__elf) .or. outp%what(option__output__elf_basins) .or. &
411 outp%what(option__output__energy_density) .or. outp%what(option__output__kinetic_energy_density) .or. &
412 outp%what(option__output__el_pressure)) then
414 "Output of ELF / (kinetic-)energy-density / electronic pressure with ultrasoft/PAW", namespace=namespace)
415 end if
416 ! Matrix elements and orbital projections miss the augmentation (and the S-weighted projection)
417 if (outp%what(option__output__matrix_elements)) then
418 call messages_not_implemented("Output of matrix elements with ultrasoft/PAW", namespace=namespace)
419 end if
420 if (outp%what(option__output__pdos)) then
421 call messages_not_implemented("Output of the projected DOS (pdos) with ultrasoft/PAW", namespace=namespace)
422 end if
423 end if
424
427
428 ! ---------------------------------------------------------
429 subroutine output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
430 type(output_t), intent(in) :: outp
431 type(namespace_t), intent(in) :: namespace
432 class(space_t), intent(in) :: space
433 character(len=*), intent(in) :: dir
434 type(grid_t), intent(in) :: gr
435 type(ions_t), intent(in) :: ions
436 integer, intent(in) :: iter
437 type(states_elec_t), intent(inout) :: st
438 type(hamiltonian_elec_t), intent(inout) :: hm
439 type(v_ks_t), intent(inout) :: ks
440
441 integer :: idir, ierr, iunit
442 character(len=MAX_PATH_LEN) :: fname
443
444 push_sub(output_all)
445 call profiling_in("OUTPUT_ALL")
446
447 if (any(outp%what)) then
448 message(1) = "Info: Writing output to " // trim(dir)
449 call messages_info(1, namespace=namespace)
450 call io_mkdir(dir, namespace)
451 end if
452
453 if (outp%what_now(option__output__mesh_r, iter)) then
454 do idir = 1, space%dim
455 write(fname, '(a,a)') 'mesh_r-', index2axis(idir)
456 call dio_function_output(outp%how(option__output__mesh_r), dir, fname, namespace, space, &
457 gr, gr%x_t(:,idir), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
458 end do
459 end if
460
461 call output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
462 call output_hamiltonian(outp, namespace, space, dir, hm, st, gr%der, ions, gr, iter, st%st_kpt_mpi_grp)
463
464 ! We can only test against the theory level here, as it is not set in the call of output_init().
465 if (outp%what_now(option__output__el_pressure, iter)) then
466 if(ks%theory_level /= kohn_sham_dft) then
467 call messages_not_implemented("el_pressure for TheoryLevel different from kohn_sham", namespace=namespace)
468 end if
469 if (st%d%spin_channels > 1) then
470 call messages_not_implemented("el_pressure for spin-polarized or spinors", namespace=namespace)
471 end if
472 end if
473
474 !hm not initialized yet when calling output_init()
475 if (outp%what(option__output__kanamoriu) .and. hm%lda_u_level /= dft_u_acbn0) then
476 message(1) = "kanamoriU output can only be computed for DFTULevel = dft_u_acbn0"
477 call messages_fatal(1, namespace=namespace)
478 end if
479
480
481 call output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
482
483 if (outp%what_now(option__output__j_flow, iter)) then
484 call output_current_flow(outp, namespace, space, dir, gr, st, hm%kpoints)
485 end if
486
487 if (outp%what_now(option__output__geometry, iter)) then
488 if (bitand(outp%how(option__output__geometry), option__outputformat__xcrysden) /= 0) then
489 call write_xsf_geometry_file(dir, "geometry", space, ions%latt, ions%pos, ions%atom, gr, ions%grp, namespace)
490 end if
491 if (bitand(outp%how(option__output__geometry), option__outputformat__xyz) /= 0) then
492 call ions%write_xyz(trim(dir)//'/geometry')
493 if (ions%space%is_periodic()) then
494 call ions%write_crystal(dir)
495 end if
496 end if
497 if (bitand(outp%how(option__output__geometry), option__outputformat__vtk) /= 0) then
498 call ions%write_vtk_geometry(trim(dir)//'/geometry')
499 end if
500 if (bitand(outp%how(option__output__geometry), option__outputformat__poscar) /= 0) then
501 call ions%write_poscar(trim(dir)//'/POSCAR')
502 end if
503 end if
504
505 if (outp%what_now(option__output__forces, iter)) then
506 if (bitand(outp%how(option__output__forces), option__outputformat__bild) /= 0) then
507 call ions%write_bild_forces_file(dir, "forces")
508 else
509 call write_xsf_geometry_file(dir, "forces", space, ions%latt, ions%pos, ions%atom, &
510 gr, st%system_grp, namespace, total_forces = ions%tot_force)
511 end if
512 end if
513
514 if (outp%what_now(option__output__matrix_elements, iter)) then
515 call output_me(outp%me, namespace, space, dir, st, gr, ions, hm)
516 end if
517
518 if (outp%what_now(option__output__berkeleygw, iter)) then
519 call output_berkeleygw(outp%bgw, namespace, space, dir, st, gr, ks, hm, ions)
520 end if
521
522 if (outp%what_now(option__output__energy_density, iter)) then
523 call output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
524 end if
525
526 if (outp%what_now(option__output__stress, iter)) then
527 call io_mkdir(dir, namespace)
528 iunit = io_open(trim(dir)//'/stress', namespace, action='write')
529 call output_stress(iunit, space%periodic_dim, st%stress_tensors, st%system_grp)
530 call io_close(iunit)
531 end if
532
533 if (hm%lda_u_level /= dft_u_none) then
534 if (outp%what_now(option__output__occ_matrices, iter))&
535 call lda_u_write_occupation_matrices(dir, hm%lda_u, st, namespace)
536
537 if (outp%what_now(option__output__effectiveu, iter))&
538 call lda_u_write_effectiveu(dir, hm%lda_u, st, namespace)
539
540 if (outp%what_now(option__output__magnetization, iter))&
541 call lda_u_write_magnetization(dir, hm%lda_u, ions, gr, st, namespace)
542
543 if (outp%what_now(option__output__local_orbitals, iter))&
544 call output_dftu_orbitals(outp, dir, namespace, space, hm%lda_u, st, gr, ions, hm%phase%is_allocated())
545
546 if (outp%what_now(option__output__kanamoriu, iter))&
547 call lda_u_write_kanamoriu(dir, st, hm%lda_u, namespace)
548
549 if (ks%v_ks_photons%oep_full()) then
550 if (outp%what_now(option__output__photon_correlator, iter)) then
551 write(fname, '(a)') 'photon_correlator'
552 call dio_function_output(outp%how(option__output__photon_correlator), dir, trim(fname), namespace, space, &
553 gr, ks%v_ks_photons%correlator(), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
554 end if
555 end if
556 end if
557
558 ! We can only test against the theory level here, as it is not set in the call of output_init().
559 if (outp%what_now(option__output__xc_torque, iter)) then
560 if (ks%theory_level /= kohn_sham_dft .and. ks%theory_level /= generalized_kohn_sham_dft) then
561 write(message(1), '(a)') 'The output xc_torque can only be computed when there is a xc potential.'
562 call messages_fatal(1, namespace=namespace)
563 end if
564 end if
565
566 call output_xc_torque(outp, namespace, dir, gr, hm, st, ions, ions%space)
567
568 call profiling_out("OUTPUT_ALL")
569 pop_sub(output_all)
570 end subroutine output_all
571
572
573 ! ---------------------------------------------------------
574 subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
575 type(output_t), intent(in) :: outp
576 type(namespace_t), intent(in) :: namespace
577 class(space_t), intent(in) :: space
578 character(len=*), intent(in) :: dir
579 type(states_elec_t), intent(inout) :: st
580 type(hamiltonian_elec_t), intent(in) :: hm
581 type(grid_t), intent(in) :: gr
582 type(ions_t), intent(in) :: ions
583 integer, intent(in) :: iter
584
585 real(real64), allocatable :: f_loc(:,:)
586 character(len=MAX_PATH_LEN) :: fname
587 integer :: is, ierr, imax
588 type(mpi_grp_t) :: mpi_grp
589
591
592 mpi_grp = st%dom_st_kpt_mpi_grp
593
594 ! if SPIN_POLARIZED or SPINORS, the ELF contains one extra channel: the total ELF
595 imax = 1
596 if (st%d%ispin /= unpolarized) imax = 3
597
598 safe_allocate(f_loc(1:gr%np, 1:max(imax, st%d%nspin)))
599
600 ! First the ELF in real space
601 if (outp%what_now(option__output__elf, iter) .or. outp%what_now(option__output__elf_basins, iter)) then
602 assert(space%dim /= 1)
603
604 call elf_calc(space, st, gr, hm%kpoints, f_loc(:, 1:imax))
605
606 ! output ELF in real space
607 if (outp%what_now(option__output__elf, iter)) then
608 write(fname, '(a)') 'elf_rs'
609 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
610 f_loc(:,imax), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
611 ! this quantity is dimensionless
612
613 if (st%d%ispin /= unpolarized) then
614 do is = 1, 2
615 write(fname, '(a,i1)') 'elf_rs-sp', is
616 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
617 f_loc(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
618 ! this quantity is dimensionless
619 end do
620 end if
621 end if
622
623 if (outp%what_now(option__output__elf_basins, iter)) then
624 call out_basins(f_loc(:,imax), "elf_rs_basins", outp%how(option__output__elf_basins))
625 end if
626 end if
627
628 ! Now Bader analysis
629 if (outp%what_now(option__output__bader, iter)) then
630 do is = 1, st%d%nspin
631 call dderivatives_lapl(gr%der, st%rho(:,is), f_loc(:,is))
632
633 fname = get_filename_with_spin('bader', st%d%nspin, is)
634
635 call dio_function_output(outp%how(option__output__bader), dir, trim(fname), namespace, space, gr, &
636 f_loc(:,is), units_out%length**(-2 - space%dim), ierr, &
637 pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
638
639 fname = get_filename_with_spin('bader_basins', st%d%nspin, is)
640 call out_basins(f_loc(:, is), fname, outp%how(option__output__bader))
641 end do
642 end if
643
644 ! Now the pressure
645 if (outp%what_now(option__output__el_pressure, iter)) then
646 call calc_electronic_pressure(st, hm, gr, f_loc(:,1))
647 call dio_function_output(outp%how(option__output__el_pressure), dir, "el_pressure", namespace, space, gr, &
648 f_loc(:,1), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
649 ! this quantity is dimensionless
650 end if
651
652 safe_deallocate_a(f_loc)
653
655
656 contains
657 ! ---------------------------------------------------------
658 subroutine out_basins(ff, filename, output_how)
659 real(real64), contiguous, intent(in) :: ff(:)
660 character(len=*), intent(in) :: filename
661 integer(int64), intent(in) :: output_how
662
663 character(len=MAX_PATH_LEN) :: fname
664 type(basins_t) :: basins
665 integer :: iunit
666
668
669 call basins_init(basins, namespace, gr)
670 call basins_analyze(basins, namespace, gr, ff(:), st%rho(:, 1:st%d%spin_channels), 0.01_real64)
671
672 call dio_function_output(output_how, dir, trim(filename), namespace, space, gr, &
673 real(basins%map, real64) , unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
674 ! this quantity is dimensionless
675
676 write(fname,'(4a)') trim(dir), '/', trim(filename), '.info'
677 iunit = io_open(trim(fname), namespace, action = 'write')
678 call basins_write(basins, gr, iunit)
679 call io_close(iunit)
680
681 call basins_end(basins)
682
684 end subroutine out_basins
685
686 end subroutine output_localization_funct
687
688
689 ! ---------------------------------------------------------
690 subroutine calc_electronic_pressure(st, hm, gr, pressure)
691 type(states_elec_t), intent(inout) :: st
692 type(hamiltonian_elec_t), intent(in) :: hm
693 type(grid_t), intent(in) :: gr
694 real(real64), contiguous, intent(out) :: pressure(:)
695
696 real(real64), allocatable :: rho(:,:), lrho(:), tau(:,:)
697 real(real64) :: p_tf, dens
698 integer :: is, ii
699
701
702 safe_allocate( rho(1:gr%np_part, 1:st%d%nspin))
703 safe_allocate(lrho(1:gr%np))
704 safe_allocate( tau(1:gr%np, 1:st%d%nspin))
705
706 rho = m_zero
707 call density_calc(st, gr, rho)
708 call states_elec_calc_quantities(gr, st, hm%kpoints, .false., kinetic_energy_density = tau)
709
710 pressure = m_zero
711 do is = 1, st%d%spin_channels
712 lrho = m_zero
713 call dderivatives_lapl(gr%der, rho(:, is), lrho)
714
715 pressure(:) = pressure(:) + &
716 tau(:, is)/m_three - lrho(:)/m_four
717 end do
718
719 do ii = 1, gr%np
720 dens = sum(rho(ii,1:st%d%spin_channels))
721
722 p_tf = m_two/m_five*(m_three*m_pi**2)**(m_two/m_three)* &
723 dens**(m_five/m_three)
724
725 ! add XC pressure
726 ! FIXME: Not correct for spinors and spin-polarized here
727 pressure(ii) = pressure(ii) + (dens*hm%ks_pot%vxc(ii,1) - hm%energy%exchange - hm%energy%correlation)
728
729 pressure(ii) = pressure(ii)/p_tf
730 pressure(ii) = m_half*(m_one + pressure(ii)/sqrt(m_one + pressure(ii)**2))
731 end do
732
734 end subroutine calc_electronic_pressure
735
736
737 ! ---------------------------------------------------------
738 subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
739 type(output_t), intent(in) :: outp
740 type(namespace_t), intent(in) :: namespace
741 class(space_t), intent(in) :: space
742 character(len=*), intent(in) :: dir
743 type(hamiltonian_elec_t), intent(in) :: hm
744 type(v_ks_t), intent(inout) :: ks
745 type(states_elec_t), intent(in) :: st
746 type(ions_t), intent(in) :: ions
747 type(grid_t), intent(in) :: gr
748
749 integer :: is, ierr, ip
750 character(len=MAX_PATH_LEN) :: fname
751 type(unit_t) :: fn_unit
752 real(real64), allocatable :: energy_density(:, :)
753 real(real64), allocatable :: ex_density(:)
754 real(real64), allocatable :: ec_density(:)
755 real(real64) :: xc_energy
756
757 push_sub(output_energy_density)
758
759 fn_unit = units_out%energy*units_out%length**(-space%dim)
760 safe_allocate(energy_density(1:gr%np, 1:st%d%nspin))
761
762 ! the kinetic energy density
763 call states_elec_calc_quantities(gr, st, hm%kpoints, .true., kinetic_energy_density = energy_density)
764
765 ! the external potential energy density
766 do is = 1, st%d%spin_channels
767 do ip = 1, gr%np
768 energy_density(ip, is) = energy_density(ip, is) + st%rho(ip, is)*hm%ep%vpsl(ip)
769 end do
770 end do
771
772 ! the hartree energy density
773 do is = 1, st%d%spin_channels
774 do ip = 1, gr%np
775 energy_density(ip, is) = energy_density(ip, is) + m_half*st%rho(ip, is)*hm%ks_pot%vhartree(ip)
776 end do
777 end do
778
779 ! the XC energy density
780 safe_allocate(ex_density(1:gr%np))
781 safe_allocate(ec_density(1:gr%np))
782
783 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
784 hm%ions%latt%rcell_volume, ex_density = ex_density, ec_density = ec_density)
785 !$omp parallel do private(ip, is, xc_energy)
786 do ip = 1, gr%np
787 xc_energy = ex_density(ip) + ec_density(ip)
788 do is = 1, st%d%spin_channels
789 energy_density(ip, is) = energy_density(ip, is) + xc_energy
790 end do
791 end do
792
793 safe_deallocate_a(ex_density)
794 safe_deallocate_a(ec_density)
795
796 do is = 1, st%d%spin_channels
797 fname = get_filename_with_spin('energy_density', st%d%nspin, is)
798 call dio_function_output(outp%how(option__output__energy_density), dir, trim(fname), namespace, space, gr, &
799 energy_density(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
800 end do
801 safe_deallocate_a(energy_density)
802
803 pop_sub(output_energy_density)
804 end subroutine output_energy_density
805
806 !--------------------------------------------------------------
807
808 logical function output_need_exchange(outp) result(need_exx)
809 type(output_t), intent(in) :: outp
811 need_exx =(outp%what(option__output__berkeleygw) &
812 .or. outp%me%what(option__outputmatrixelements__two_body) &
813 .or. outp%me%what(option__outputmatrixelements__two_body_exc_k))
814 end function output_need_exchange
815
816
817 ! ---------------------------------------------------------
818 subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
819 type(output_t), intent(in) :: outp
820 character(len=*), intent(in) :: dir
821 type(namespace_t), intent(in) :: namespace
822 class(space_t), intent(in) :: space
823 type(lda_u_t), intent(in) :: this
824 type(states_elec_t), intent(in) :: st
825 class(mesh_t), intent(in) :: mesh
826 type(ions_t), intent(in) :: ions
827 logical, intent(in) :: has_phase
828
829 integer :: ios, im, ik, idim, ierr
830 complex(real64), allocatable :: tmp(:)
831 real(real64), allocatable :: dtmp(:)
832 type(orbitalset_t), pointer :: os
833 type(unit_t) :: fn_unit
834 character(len=MAX_PATH_LEN) :: fname
835
836 push_sub(output_dftu_orbitals)
837
838 fn_unit = sqrt(units_out%length**(-space%dim))
839
840 if (this%basis%use_submesh) then
841 if (states_are_real(st)) then
842 safe_allocate(dtmp(1:mesh%np))
843 else
844 safe_allocate(tmp(1:mesh%np))
845 end if
846 end if
847
848 do ios = 1, this%norbsets
849 os => this%orbsets(ios)
850 do ik = st%d%kpt%start, st%d%kpt%end
851 do im = 1, this%orbsets(ios)%norbs
852 do idim = 1, min(os%ndim, st%d%dim)
853 if (st%nik > 1) then
854 if (min(os%ndim, st%d%dim) > 1) then
855 write(fname, '(a,i1,a,i3.3,a,i8.8,a,i1)') 'orb', im, '-os', ios, '-k', ik, '-sp', idim
856 else
857 write(fname, '(a,i1,a,i3.3,a,i8.8)') 'orb', im, '-os', ios, '-k', ik
858 end if
859 else
860 if (min(os%ndim, st%d%dim) > 1) then
861 write(fname, '(a,i1,a,i3.3,a,i1)') 'orb', im, '-os', ios, '-sp', idim
862 else
863 write(fname, '(a,i1,a,i3.3)') 'orb', im, '-os', ios
864 end if
865 end if
866 if (has_phase) then
867 if (.not. this%basis%use_submesh) then
868 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
869 mesh, os%eorb_mesh(1:mesh%np,im,idim,ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
870 else
871 tmp = m_z0
872 call submesh_add_to_mesh(os%sphere, os%eorb_submesh(1:os%sphere%np,idim,im,ik), tmp)
873 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
874 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
875 end if
876 else
877 if (.not. this%basis%use_submesh) then
878 if (states_are_real(st)) then
879 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
880 os%dorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
881 else
882 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
883 os%zorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
884 end if
885 else
886 if (states_are_real(st)) then
887 dtmp = m_zero
888 call submesh_add_to_mesh(os%sphere, os%dorb(1:os%sphere%np,idim,im), dtmp)
889 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
890 mesh, dtmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
891 else
892 tmp = m_z0
893 call submesh_add_to_mesh(os%sphere, os%zorb(1:os%sphere%np,idim,im), tmp)
894 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
895 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
896 end if
897 end if
898 end if
899 end do
900 end do
901 end do
902 end do
903
904 safe_deallocate_a(tmp)
905 safe_deallocate_a(dtmp)
906
907 pop_sub(output_dftu_orbitals)
908 end subroutine output_dftu_orbitals
909
910 ! ---------------------------------------------------------
911 logical function output_needs_current(outp, states_are_real)
912 type(output_t), intent(in) :: outp
913 logical, intent(in) :: states_are_real
914
915 output_needs_current = .false.
916
917 if (outp%what(option__output__current) &
918 .or. outp%what(option__output__current_dia) &
919 .or. outp%what(option__output__heat_current) &
920 .or. outp%what(option__output__j_flow) &
921 .or. outp%what(option__output__current_kpt)) then
922 if (.not. states_are_real) then
924 else
925 message(1) = 'No current density output for real states since it is identically zero.'
926 call messages_warning(1)
927 end if
928 end if
929
930
931 end function
932
933#include "output_states_inc.F90"
934
935#include "output_h_inc.F90"
936
937#include "undef.F90"
938#include "complex.F90"
939#include "output_linear_response_inc.F90"
940
941#include "undef.F90"
942#include "real.F90"
943#include "output_linear_response_inc.F90"
944
945end module output_oct_m
946
947!! Local Variables:
948!! mode: f90
949!! coding: utf-8
950!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
subroutine, public basins_write(this, mesh, iunit)
Definition: basins.F90:331
subroutine, public basins_init(this, namespace, mesh)
Definition: basins.F90:130
subroutine, public basins_analyze(this, namespace, mesh, f, rho, threshold)
Definition: basins.F90:167
subroutine, public basins_end(this)
Definition: basins.F90:149
This module implements a calculator for the density and defines related functions.
Definition: density.F90:99
subroutine, public density_calc(st, gr, density, istin, ep, vnl, phase)
Computes the density from the orbitals in st.
Definition: density.F90:832
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:95
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
subroutine, public elf_calc(space, st, gr, kpoints, elf, de)
(time-dependent) electron localization function, (TD)ELF.
Definition: elf.F90:146
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:97
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_four
Definition: global.F90:177
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
complex(real64), parameter, public m_z0
Definition: global.F90:183
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:223
integer, parameter, public kohn_sham_dft
Definition: global.F90:223
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public m_one
Definition: global.F90:174
real(real64), parameter, public m_three
Definition: global.F90:176
real(real64), parameter, public m_five
Definition: global.F90:178
This module implements the underlying real-space grid.
Definition: grid.F90:96
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, mpi_grp, namespace, total_forces)
Definition: io.F90:93
subroutine, public io_close(iunit, grp)
Definition: io.F90:444
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:338
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:379
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:135
subroutine, public lda_u_write_kanamoriu(dir, st, this, namespace)
Definition: lda_u_io.F90:329
subroutine, public lda_u_write_effectiveu(dir, this, st, namespace)
Definition: lda_u_io.F90:243
subroutine, public lda_u_write_magnetization(dir, this, ions, mesh, st, namespace)
Definition: lda_u_io.F90:457
integer, parameter, public dft_u_none
Definition: lda_u.F90:184
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:184
System information (time, memory, sysname)
Definition: loct.F90:94
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
pure real(real64) function, dimension(1:3), public dcross_product(a, b)
Definition: math.F90:1975
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
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:94
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:210
subroutine, public output_me_init(this, namespace, space, st, gr, nst)
Definition: output_me.F90:134
subroutine, public output_me(this, namespace, space, dir, st, gr, ions, hm)
Definition: output_me.F90:265
this module contains the output system
Definition: output.F90:94
subroutine calc_electronic_pressure(st, hm, gr, pressure)
Definition: output.F90:763
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1026
subroutine, public output_scalar_pot(outp, namespace, space, dir, mesh, ions, ext_partners, grp, time)
Definition: output.F90:1623
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:984
subroutine, public output_hamiltonian(outp, namespace, space, dir, hm, st, der, ions, gr, iter, grp)
Definition: output.F90:1339
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:502
logical function, public output_need_exchange(outp)
Definition: output.F90:881
subroutine, public output_init(outp, namespace, space, st, gr, nst, ks)
Definition: output.F90:185
subroutine output_xc_torque(outp, namespace, dir, mesh, hm, st, ions, space)
Definition: output.F90:1661
subroutine, public output_current_flow(outp, namespace, space, dir, gr, st, kpoints)
Definition: output.F90:1224
subroutine, public output_check_generalized_overlap(outp, st, namespace)
Fence the requested outputs that are not yet correct with a generalized overlap.
Definition: output.F90:465
subroutine, public zoutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:1768
subroutine, public doutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:2006
subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
Definition: output.F90:811
subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
Definition: output.F90:891
subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
Definition: output.F90:647
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:600
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
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:97
subroutine, public output_stress(iunit, space_dim, stress_tensors, mpi_grp, all_terms)
Definition: stress.F90:1169
subroutine, public add_last_slash(str)
Adds a '/' in the end of the string, only if it missing. Useful for directories.
Definition: string.F90:139
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
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:99
character pure function, public index2axis(idir)
Definition: utils.F90:191
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1524
Definition: xc.F90:97
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:168
subroutine out_basins(ff, filename, output_how)
Definition: output.F90:731
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
Class to describe DFT+U parameters.
Definition: lda_u.F90:197
Describes mesh distribution to nodes.
Definition: mesh.F90:165
This is defined even when running serial.
Definition: mpi.F90:121
Output information for BerkeleyGW.
Definition: output_low.F90:124
output handler class
Definition: output_low.F90:143
The states_elec_t class contains all electronic wave functions.
int true(void)