Octopus
output_mxll.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 F. Bonafe, R. Jestaedt, H. Appel
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
20#include "global.h"
21
23 use debug_oct_m
28 use global_oct_m
29 use grid_oct_m
31 use io_oct_m
33 use mesh_oct_m
36 use output_oct_m
38 use parser_oct_m
40 use space_oct_m
43 use string_oct_m
44 use unit_oct_m
46
47
48 implicit none
49
50 private
51 public :: &
54
55contains
56
57 ! ---------------------------------------------------------
58 subroutine output_mxll_init(outp, namespace, space)
59 type(output_t), intent(out) :: outp
60 type(namespace_t), intent(in) :: namespace
61 class(space_t), intent(in) :: space
62 integer :: what_i
63 push_sub(output_mxll_init)
64
65 !%Variable MaxwellOutput
66 !%Type block
67 !%Default none
68 !%Section Output
69 !%Description
70 !% Specifies what to print. The output files are written at the end of the run into the output directory for the
71 !% Maxwell run.
72 !% Time-dependent simulations print only per iteration, including always the last. The frequency of output per iteration
73 !% is set by <tt>OutputInterval</tt> and the directory is set by <tt>OutputIterDir</tt>.
74 !% Each option must be in a separate row. Optionally individual output formats and output intervals can be defined
75 !% for each row or they can be read separately from <tt>OutputFormat</tt> and <tt>MaxwellOutputInterval</tt> variables
76 !% in the input file.
77 !%
78 !% Example:
79 !% <br><br><tt>%MaxwellOutput
80 !% <br>&nbsp;&nbsp;electric_field
81 !% <br>&nbsp;&nbsp;magnetic_field
82 !% <br>%<br></tt>
83 !% This block supports all the formats of the <tt>Output</tt> block.
84 !% See <tt>Output</tt>.
85 !%Option electric_field 1
86 !% Output of the electric field
87 !%Option magnetic_field 2
88 !% Output of the magnetic field
89 !%Option trans_electric_field 3
90 !% Output of the transversal electric field
91 !%Option trans_magnetic_field 4
92 !% Output of the transversal magnetic field
93 !%Option long_electric_field 5
94 !% Output of the longitudinal electric field
95 !%Option long_magnetic_field 6
96 !% Output of the longitudinal magnetic field
97 !%Option div_electric_field 7
98 !% Output of the divergence of the electric field
99 !%Option div_magnetic_field 8
100 !% Output of the divergence of the magnetic field
101 !%Option poynting_vector 9
102 !% Output of the Maxwell Poynting vector
103 !%Option maxwell_energy_density 10
104 !% Output of the electromagnetic density
105 !%Option external_current 11
106 !% Output of the external Maxwell current
107 !%Option charge_density 12
108 !% Output of the charge density calculated by the divergence of the electric field.
109 !%Option orbital_angular_momentum 13
110 !% Output of the orbital angular momentum
111 !%Option vector_potential_mag 14
112 !% Output of the vector potential from magnetic field
113 !%Option magnetic_field_diff 15
114 !% Output of the magnetic field difference
115 !%Option total_current_mxll 16
116 !% Output of the total current density
117 !%End
118
119 !%Variable MaxwellOutputInterval
120 !%Type integer
121 !%Default 50
122 !%Section Output
123 !%Description
124 !% The output requested by variable <tt>MaxwellOutput</tt> is written
125 !% to the directory <tt>MaxwellOutputIterDir</tt>
126 !% when the iteration number is a multiple of the <tt>MaxwellOutputInterval</tt> variable.
127 !% Subdirectories are named Y.X, where Y is <tt>td</tt>, <tt>scf</tt>, or <tt>unocc</tt>, and
128 !% X is the iteration number. To use the working directory, specify <tt>"."</tt>
129 !% Must be >= 0. If it is 0, then no output is written.
130 !% This variable can also be defined inside the <tt>MaxwellOutput</tt> block.
131 !% See <tt>MaxwellOutput</tt>.
132 !%End
133
134 outp%what = .false.
135 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval, &
136 'MaxwellOutput', 'OutputFormat', 'MaxwellOutputInterval')
137
138 do what_i = lbound(outp%what, 1), ubound(outp%what, 1)
139 ! xyz format is not available for Maxwell
140 if (bitand(outp%how(what_i), option__outputformat__xyz) /= 0) then
141 message(1) = "OutputFormat = xyz is not compatible with Maxwell systems"
142 call messages_warning(1)
143 end if
144 end do
145
146
147
148 !%Variable MaxwellOutputIterDir
149 !%Default "output_iter"
150 !%Type string
151 !%Section Output
152 !%Description
153 !% The name of the directory where <tt>Octopus</tt> stores information
154 !% such as the density, forces, etc. requested by variable <tt>MaxwellOutput</tt>
155 !% in the format specified by <tt>OutputHow</tt>.
156 !% This information is written while iterating <tt>CalculationMode = maxwell</tt>
157 !% according to <tt>OutputInterval</tt>, and has nothing to do with the restart information.
158 !%End
159 call parse_variable(namespace, 'MaxwellOutputIterDir', "output_iter", outp%iter_dir)
160 if (any(outp%what) .and. maxval(outp%output_interval) > 0) then
161 call io_mkdir(outp%iter_dir, namespace)
162 end if
163 call add_last_slash(outp%iter_dir)
164
165 if (parse_is_defined(namespace, 'MaxwellRestartWriteInterval')) then
166 write(message(1), '(a)') 'Input variable MaxwellRestartWriteInterval is obsolete.'
167 write(message(2), '(a)') 'Restart files are now written in periods of the wallclock time'
168 write(message(3), '(a)') 'given by RestartWallTimePeriod, so you can simply delete this variable.'
169 call messages_fatal(3, only_root_writes=.true., namespace=namespace)
170 end if
171
172 if (outp%what(option__maxwelloutput__electric_field)) then
173 outp%wfs_list = trim("1-3")
174 end if
175
176 if (outp%what(option__maxwelloutput__magnetic_field)) then
177 outp%wfs_list = trim("1-3")
178 end if
179
180 if (outp%what(option__maxwelloutput__trans_electric_field)) then
181 outp%wfs_list = trim("1-3")
182 end if
183
184 if (outp%what(option__maxwelloutput__trans_magnetic_field)) then
185 outp%wfs_list = trim("1-3")
186 end if
187
188
189 pop_sub(output_mxll_init)
190 end subroutine output_mxll_init
191
192
193 ! ---------------------------------------------------------
194 subroutine output_mxll(outp, namespace, space, gr_mxll, st_mxll, hm_mxll, helmholtz, time, dir, gr_elec, st_elec, hm_elec)
195 type(output_t), intent(in) :: outp
196 type(namespace_t), intent(in) :: namespace
197 class(space_t), intent(in) :: space
198 type(states_mxll_t), intent(inout) :: st_mxll
199 type(hamiltonian_mxll_t), intent(in) :: hm_mxll
200 type(grid_t), intent(in) :: gr_mxll
201 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
202 real(real64), intent(in) :: time
203 character(len=*), intent(in) :: dir
204 type(grid_t), optional, intent(inout) :: gr_elec
205 type(states_elec_t), optional, intent(inout) :: st_elec
206 type(hamiltonian_elec_t), optional, intent(in) :: hm_elec
207
208 push_sub(output_mxll)
209
210 if (any(outp%what)) then
211 message(1) = "Info: Writing output to " // trim(dir)
212 call messages_info(1, namespace=namespace)
213 call io_mkdir(dir, namespace)
214 end if
215
216 call output_states_mxll(outp, namespace, space, dir, st_mxll, gr_mxll)
217 call output_energy_density_mxll(outp, namespace, space, dir, st_mxll, gr_mxll)
218 call output_poynting_vector_orbital_angular_momentum(outp, namespace, space, dir, st_mxll, gr_mxll, hm_mxll%c_factor)
219 call output_transverse_rs_state(helmholtz, outp, namespace, space, dir, st_mxll, gr_mxll)
220 call output_longitudinal_rs_state(helmholtz, outp, namespace, space, dir, st_mxll, gr_mxll)
221 call output_vector_potential_mag(outp, helmholtz, namespace, gr_mxll, space, dir, st_mxll)
222 call output_divergence_rs_state(outp, namespace, space, dir, st_mxll, gr_mxll)
223 call output_external_current_density(outp, namespace, space, dir, st_mxll, gr_mxll, hm_mxll, time)
224 call output_total_current_mxll(outp, namespace, space, dir, st_mxll, gr_mxll, hm_mxll, time, st_mxll%ep, gr_mxll%np)
225 call output_charge_density_mxll(outp, namespace, space, dir, st_mxll, gr_mxll, hm_mxll)
226
227 if (present(hm_elec) .and. present(gr_elec) .and. present(st_elec)) then
228 call output_coupling_potentials(outp, namespace, dir, hm_elec, gr_elec)
229 call output_current_density(outp, namespace, dir, st_mxll, gr_mxll, hm_mxll, st_elec, gr_elec, hm_elec, time)
230 end if
231
232 pop_sub(output_mxll)
233 end subroutine output_mxll
234
235
236 ! ---------------------------------------------------------
237 subroutine output_states_mxll(outp, namespace, space, dir, st, mesh)
238 type(output_t), intent(in) :: outp
239 type(namespace_t), intent(in) :: namespace
240 class(space_t), intent(in) :: space
241 character(len=*), intent(in) :: dir
242 type(states_mxll_t), intent(in) :: st
243 class(mesh_t), intent(in) :: mesh
244
245 integer :: ierr
246 character(len=MAX_PATH_LEN) :: fname
247 type(unit_t) :: fn_unit
248 real(real64), allocatable :: dtmp(:,:)
249
250 push_sub(output_states_mxll)
251
252 ! Electric field
253 if (outp%what(option__maxwelloutput__electric_field)) then
254 fn_unit = units_out%energy/units_out%length
255 safe_allocate(dtmp(1:mesh%np, 1:space%dim))
256 call get_electric_field_state(st%rs_state, mesh, dtmp, st%ep, mesh%np)
257 fname = 'e_field'
258 call io_function_output_vector(outp%how(option__maxwelloutput__electric_field), dir, fname, namespace, space, &
259 mesh, dtmp, fn_unit, ierr)
260 safe_deallocate_a(dtmp)
261 end if
262
263 ! Magnetic field
264 if (outp%what(option__maxwelloutput__magnetic_field)) then
265 fn_unit = unit_one/units_out%length**2
266 safe_allocate(dtmp(1:mesh%np, 1:space%dim))
267 call get_magnetic_field_state(st%rs_state, mesh, st%rs_sign, dtmp, st%mu(1:mesh%np), mesh%np)
268 fname = 'b_field'
269 call io_function_output_vector(outp%how(option__maxwelloutput__magnetic_field), dir, fname, namespace, space, &
270 mesh, dtmp, fn_unit, ierr)
271 safe_deallocate_a(dtmp)
272 end if
273
274 pop_sub(output_states_mxll)
275 end subroutine output_states_mxll
276
277
278 !----------------------------------------------------------
279 subroutine output_energy_density_mxll(outp, namespace, space, dir, st, mesh) !< have to set unit output correctly
280 type(output_t), intent(in) :: outp
281 type(namespace_t), intent(in) :: namespace
282 class(space_t), intent(in) :: space
283 character(len=*), intent(in) :: dir
284 type(states_mxll_t), intent(in) :: st
285 class(mesh_t), intent(in) :: mesh
286
287 integer :: ierr
288 real(real64), allocatable :: energy_density(:), e_energy_density(:), b_energy_density(:)
289
291
292 ! Maxwell energy density
293 if (outp%what(option__maxwelloutput__maxwell_energy_density)) then
294 safe_allocate(energy_density(1:mesh%np))
295 safe_allocate(e_energy_density(1:mesh%np))
296 safe_allocate(b_energy_density(1:mesh%np))
297 ! calculate the energy density
298 call energy_density_calc(mesh, st, st%rs_state, energy_density, e_energy_density, b_energy_density)
299
300 call dio_function_output(outp%how(option__maxwelloutput__maxwell_energy_density), dir, "maxwell_energy_density", &
301 namespace, space, mesh, energy_density, units_out%energy/units_out%length**3, ierr)
302
303 safe_deallocate_a(energy_density)
304 safe_deallocate_a(e_energy_density)
305 safe_deallocate_a(b_energy_density)
306 end if
307
310
311
312 !----------------------------------------------------------
313 subroutine output_poynting_vector_orbital_angular_momentum(outp, namespace, space, dir, st, mesh, c_factor)
314 type(output_t), intent(in) :: outp
315 type(namespace_t), intent(in) :: namespace
316 class(space_t), intent(in) :: space
317 character(len=*), intent(in) :: dir
318 type(states_mxll_t), intent(in) :: st
319 class(mesh_t), intent(in) :: mesh
320 real(real64), intent(in) :: c_factor
321
322 integer :: ierr
323 character(len=MAX_PATH_LEN) :: fname
324 type(unit_t) :: fn_unit
325 real(real64), allocatable :: poynting_vector(:,:), oam(:,:)
326
328
329 if (outp%what(option__maxwelloutput__poynting_vector).or.outp%what(option__maxwelloutput__orbital_angular_momentum)) then
330
331 ! the Poynting vector is needed in both cases, so we compute it here first
332 fn_unit = units_out%energy/(units_out%time*units_out%length**2)
333 safe_allocate(poynting_vector(1:mesh%np, 1:space%dim))
334 call get_poynting_vector(mesh, st, st%rs_state, st%rs_sign, c_factor, poynting_vector, st%ep, st%mu)
335
336 if(outp%what(option__maxwelloutput__poynting_vector)) then
337 fname = 'poynting_vector'
338 call io_function_output_vector(outp%how(option__maxwelloutput__poynting_vector), dir, fname, namespace, space, &
339 mesh, poynting_vector, fn_unit, ierr)
340 end if
341
342 if(outp%what(option__maxwelloutput__orbital_angular_momentum)) then
343 safe_allocate(oam(1:mesh%np, 1:space%dim))
344 call get_orbital_angular_momentum(mesh, poynting_vector, oam)
345 fname = 'orbital_angular_momentum'
346 call io_function_output_vector(outp%how(option__maxwelloutput__orbital_angular_momentum), dir, fname, namespace, space, &
347 mesh, oam, fn_unit, ierr)
348 safe_deallocate_a(oam)
349 end if
350
351 safe_deallocate_a(poynting_vector)
352 end if
353
356
357
358 ! add documentation to magnetic field subtraction order
359 subroutine output_vector_potential_mag(outp, helmholtz, namespace, gr, space, dir, st) !< have to set unit output correctly
360 type(output_t), intent(in) :: outp
361 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
362 type(namespace_t), intent(in) :: namespace
363 type(grid_t), intent(in) :: gr
364 class(space_t), intent(in) :: space
365 character(len=*), intent(in) :: dir
366 type(states_mxll_t), intent(in) :: st
367
368 character(len=MAX_PATH_LEN) :: fname
369 integer :: ierr
370 type(unit_t) :: fn_unit
371 real(real64), allocatable :: dtmp(:,:),vtmp(:,:), mag_fromvec(:,:) , delta(:,:)
372
374
375 ! vector potential from magnetic field
376 if (outp%what(option__maxwelloutput__vector_potential_mag) .or. &
377 outp%what(option__maxwelloutput__magnetic_field_diff)) then
378
379 fn_unit = unit_one/units_out%length
380 safe_allocate(dtmp(1:gr%np_part, 1:space%dim))
381 safe_allocate(vtmp(1:gr%np_part, 1:space%dim))
382 call get_magnetic_field_state(st%rs_state, gr, st%rs_sign, dtmp, st%mu(1:gr%np), gr%np)
383 ! Get vector potential for magnetic field
384 call helmholtz%get_vector_potential(namespace, vtmp, trans_field=dtmp)
386 if (outp%what(option__maxwelloutput__vector_potential_mag)) then
387 message(1) = 'Vector potential is currently missing surface contributions'
388 message(2) = 'If in doubt, use magnetic_field_diff output which shows deviation of B field'
389 message(3) = 'Large B field deviations mean the calculated vector potential is unreliable'
390 call messages_warning(3)
391
392 fname = 'vector_potential_mag'
393 call io_function_output_vector(outp%how(option__maxwelloutput__vector_potential_mag), dir, fname, namespace, &
394 space, gr, vtmp, fn_unit, ierr)
395 end if
396
397 if (outp%what(option__maxwelloutput__magnetic_field_diff)) then
398 fn_unit = unit_one/units_out%length**2
399 safe_allocate(mag_fromvec(1:gr%np_part, 1:space%dim))
400 safe_allocate(delta(1:gr%np, 1:space%dim))
401 ! Get transverse field from vector potential
402 call helmholtz%get_trans_field(namespace, mag_fromvec, vector_potential=vtmp)
403 ! mag_fromvec is of size np_part, but should be used up to np
404 ! Due to how the Helmholtz decomposition works (see its documentation), we have to remove a stencil from dtmp
405 call helmholtz%apply_inner_stencil_mask(dtmp)
406 delta = dtmp(1:gr%np, 1:space%dim) - mag_fromvec(1:gr%np, 1:space%dim)
407 fname = 'magnetic_field_diff'
408 call io_function_output_vector(outp%how(option__maxwelloutput__magnetic_field_diff), dir, fname, namespace, &
409 space, gr, delta, fn_unit, ierr)
410 safe_deallocate_a(mag_fromvec)
411 safe_deallocate_a(delta)
412 end if
413
414 safe_deallocate_a(dtmp)
415 safe_deallocate_a(vtmp)
416 end if
417
419 end subroutine output_vector_potential_mag
420
421
422 !----------------------------------------------------------
423 subroutine output_transverse_rs_state(helmholtz, outp, namespace, space, dir, st, gr) !< have to set unit output correctly
424 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
425 type(output_t), intent(in) :: outp
426 type(namespace_t), intent(in) :: namespace
427 class(space_t), intent(in) :: space
428 character(len=*), intent(in) :: dir
429 type(states_mxll_t), intent(inout) :: st ! needs to be inout as st%rs_state is passed to get_trans_field
430 type(grid_t), intent(in) :: gr
432 character(len=MAX_PATH_LEN) :: fname
433 integer :: ierr
434 type(unit_t) :: fn_unit
435 real(real64), allocatable :: dtmp(:,:)
436
438
439 if (outp%what(option__maxwelloutput__trans_electric_field) .or. outp%what(option__maxwelloutput__trans_magnetic_field)) then
440 call helmholtz%get_trans_field(namespace, st%rs_state_trans, total_field=st%rs_state)
441 end if
442
443 ! transverse component of the electric field
444 if (outp%what(option__maxwelloutput__trans_electric_field)) then
445 fn_unit = units_out%energy/units_out%length
446 safe_allocate(dtmp(1:gr%np, 1:space%dim))
447 call get_electric_field_state(st%rs_state_trans, gr, dtmp, st%ep(1:gr%np), gr%np)
448 fname = 'e_field_trans'
449 call io_function_output_vector(outp%how(option__maxwelloutput__trans_electric_field), dir, fname, namespace, space, &
450 gr, dtmp, fn_unit, ierr)
451 safe_deallocate_a(dtmp)
452 end if
453
454 ! transverse component of the magnetic field
455 if (outp%what(option__maxwelloutput__trans_magnetic_field)) then
456 fn_unit = unit_one/units_out%length**2
457 safe_allocate(dtmp(1:gr%np, 1:space%dim))
458 call get_magnetic_field_state(st%rs_state_trans, gr, st%rs_sign, dtmp, st%mu(1:gr%np), gr%np)
459 fname = 'b_field_trans'
460 call io_function_output_vector(outp%how(option__maxwelloutput__trans_magnetic_field), dir, fname, namespace, space, &
461 gr, dtmp, fn_unit, ierr)
462 safe_deallocate_a(dtmp)
463 end if
464
466 end subroutine output_transverse_rs_state
467
468
469 !----------------------------------------------------------
470 !This subroutine is left here, will be corrected and called in near future
471 subroutine output_longitudinal_rs_state(helmholtz, outp, namespace, space, dir, st, gr) !< have to set unit output correctly
472 type(helmholtz_decomposition_t), intent(inout) :: helmholtz
473 type(output_t), intent(in) :: outp
474 type(namespace_t), intent(in) :: namespace
475 class(space_t), intent(in) :: space
476 character(len=*), intent(in) :: dir
477 type(states_mxll_t), intent(inout) :: st ! needs to be inout as st%rs_state is passed to get_long_field
478 type(grid_t), intent(in) :: gr
479
480 character(len=MAX_PATH_LEN) :: fname
481 integer :: ierr
482 type(unit_t) :: fn_unit
483 real(real64), allocatable :: dtmp(:,:)
484
486
487 if (outp%what(option__maxwelloutput__long_electric_field) .or. outp%what(option__maxwelloutput__long_magnetic_field)) then
488 call helmholtz%get_long_field(namespace, st%rs_state_long, total_field=st%rs_state)
489 end if
490
491 ! longitudinal component of the electric field
492 if (outp%what(option__maxwelloutput__long_electric_field)) then
493 fn_unit = units_out%energy/units_out%length
494 safe_allocate(dtmp(1:gr%np, 1:space%dim))
495 call get_electric_field_state(st%rs_state_long, gr, dtmp, st%ep(1:gr%np), gr%np)
496 fname = 'e_field_long'
497 call io_function_output_vector(outp%how(option__maxwelloutput__long_electric_field), dir, fname, namespace, space, &
498 gr, dtmp, fn_unit, ierr)
499 safe_deallocate_a(dtmp)
500 end if
501
502 ! longitudinal component of the magnetic field
503 if (outp%what(option__maxwelloutput__long_magnetic_field)) then
504 fn_unit = unit_one/units_out%length**2
505 safe_allocate(dtmp(1:gr%np, 1:space%dim))
506 call get_magnetic_field_state(st%rs_state_long, gr, st%rs_sign, dtmp, st%mu(1:gr%np), gr%np)
507 fname = 'b_field_long'
508 call io_function_output_vector(outp%how(option__maxwelloutput__long_magnetic_field), dir, fname, namespace, space, &
509 gr, dtmp, fn_unit, ierr)
510 safe_deallocate_a(dtmp)
511 end if
512
514 end subroutine output_longitudinal_rs_state
515
516
517 !----------------------------------------------------------
518 subroutine output_divergence_rs_state(outp, namespace, space, dir, st, gr) !< have to set unit output correctly
519 type(output_t), intent(in) :: outp
520 type(namespace_t), intent(in) :: namespace
521 class(space_t), intent(in) :: space
522 character(len=*), intent(in) :: dir
523 type(states_mxll_t), intent(in) :: st
524 type(grid_t), intent(in) :: gr
525
526 integer :: ierr
527 type(unit_t) :: fn_unit
528 real(real64), allocatable :: dtmp_1(:,:), dtmp_2(:)
529
531
532 ! divergence of the electric field
533 if (outp%what(option__maxwelloutput__div_electric_field)) then
534 fn_unit = units_out%length**(-space%dim)
535 safe_allocate(dtmp_1(1:gr%np_part, 1:space%dim))
536 safe_allocate(dtmp_2(1:gr%np))
537 dtmp_1 = m_zero
538 call get_electric_field_state(st%rs_state, gr, dtmp_1(1:gr%np,:), st%ep(1:gr%np), gr%np)
539 call get_divergence_field(gr, dtmp_1, dtmp_2, .false.)
540 call dio_function_output(outp%how(option__maxwelloutput__div_electric_field), dir, "e_field_div", namespace, space, &
541 gr, dtmp_2, fn_unit, ierr)
542 safe_deallocate_a(dtmp_1)
543 safe_deallocate_a(dtmp_2)
544 end if
545
546 ! divergence of the magnetic field
547 if (outp%what(option__maxwelloutput__div_magnetic_field)) then
548 ! unit does not matter, should be zero
549 fn_unit = unit_one
550 safe_allocate(dtmp_1(1:gr%np_part, 1:space%dim))
551 safe_allocate(dtmp_2(1:gr%np))
552 dtmp_1 = m_zero
553 call get_magnetic_field_state(st%rs_state, gr, st%rs_sign, dtmp_1(1:gr%np,:), st%mu(1:gr%np), gr%np)
554 call get_divergence_field(gr, dtmp_1, dtmp_2, .false.)
555 call dio_function_output(outp%how(option__maxwelloutput__div_magnetic_field), dir, "b_field_div", namespace, space, &
556 gr, dtmp_2, fn_unit, ierr)
557 safe_deallocate_a(dtmp_1)
558 safe_deallocate_a(dtmp_2)
559 end if
560
562 end subroutine output_divergence_rs_state
563
564
565 !------------------------------------------------------------
566 subroutine output_coupling_potentials(outp, namespace, dir, hm, gr) !< have to set unit output correctly
567 type(output_t), intent(in) :: outp
568 type(namespace_t), intent(in) :: namespace
569 character(len=*), intent(in) :: dir
570 type(hamiltonian_elec_t), intent(in) :: hm
571 type(grid_t), intent(in) :: gr
572
573 message(1) = "Maxwell-matter coupling potentials not implemented yet."
574 call messages_fatal(1, namespace=namespace)
575
576 end subroutine output_coupling_potentials
577
578
579 !----------------------------------------------------------
580 subroutine output_current_density(outp, namespace, dir, st_mxll, gr_mxll, hm_mxll, st_elec, gr_elec, hm_elec, time)
581 type(output_t), intent(in) :: outp
582 type(namespace_t), intent(in) :: namespace
583 character(len=*), intent(in) :: dir
584 type(states_mxll_t), intent(in) :: st_mxll
585 type(grid_t), intent(in) :: gr_mxll
586 type(hamiltonian_mxll_t), intent(in) :: hm_mxll
587 type(states_elec_t), intent(in) :: st_elec
588 type(grid_t), intent(in) :: gr_elec
589 type(hamiltonian_elec_t), intent(in) :: hm_elec
590 real(real64), intent(in) :: time
591
592 message(1) = "Current density can not yet be calculated in a Maxwell propagation."
593 call messages_fatal(1, namespace=namespace)
594
595 end subroutine output_current_density
596
597
598 !----------------------------------------------------------
599 subroutine output_external_current_density(outp, namespace, space, dir, st, mesh, hm, time)
600 type(output_t), intent(in) :: outp
601 type(namespace_t), intent(in) :: namespace
602 class(space_t), intent(in) :: space
603 character(len=*), intent(in) :: dir
604 type(states_mxll_t), intent(in) :: st
605 class(mesh_t), intent(in) :: mesh
606 type(hamiltonian_mxll_t), intent(in) :: hm
607 real(real64), intent(in) :: time
608
609 character(len=MAX_PATH_LEN) :: fname
610 integer :: ierr
611 real(real64), allocatable :: dtmp(:,:)
612 type(unit_t) :: fn_unit
613
615
616 ! Maxwell current density
617 if (outp%what(option__maxwelloutput__external_current)) then
618 if (hm%current_density_ext_flag) then
619 fn_unit = (unit_one/units_out%time)/(units_out%length**2)
620 safe_allocate(dtmp(1:mesh%np, 1:space%dim))
621 call external_current_calculation(st, space, mesh, time, dtmp)
622 fname = 'external_current'
623 call io_function_output_vector(outp%how(option__maxwelloutput__external_current), dir, fname, namespace, space, &
624 mesh, dtmp, fn_unit, ierr)
625 safe_deallocate_a(dtmp)
626 end if
627 end if
628
631
632 subroutine output_total_current_mxll(outp, namespace, space, dir, st, mesh, hm, time, ep_field, np)
633 type(output_t), intent(in) :: outp
634 type(namespace_t), intent(in) :: namespace
635 class(space_t), intent(in) :: space
636 character(len=*), intent(in) :: dir
637 type(states_mxll_t), intent(in) :: st
638 class(mesh_t), intent(in) :: mesh
639 type(hamiltonian_mxll_t), intent(in) :: hm
640 real(real64), intent(in) :: time
641 real(real64), contiguous, optional, intent(in) :: ep_field(:)
642 integer, optional, intent(in) :: np
643
644 real(real64), allocatable :: ctmp(:,:)
645 character(len=MAX_PATH_LEN) :: fname
646 integer :: ierr, ip, idim, np_, ff_dim
647 type(unit_t) :: fn_unit
648
650 safe_allocate(ctmp(1:mesh%np, 1:space%dim))
651 if (outp%what(option__maxwelloutput__total_current_mxll)) then
652 np_ = optional_default(np, mesh%np)
653 ff_dim = space%dim
654 if (present(ep_field)) then
655 do idim = 1, ff_dim
656 do ip = 1, np_
657 ctmp(ip, idim) = sqrt(m_two*ep_field(ip)) * real(st%rs_current_density_t1(ip, idim))
658 end do
659 end do
660 else
661 do idim = 1, ff_dim
662 do ip = 1, np_
663 ctmp(ip, idim) = sqrt(m_two*p_ep) * real(st%rs_current_density_t1(ip, idim))
664 end do
665 end do
666 end if
667
668 fn_unit = (unit_one/units_out%time)/(units_out%length**2)
669 fname = 'total_current_mxll'
670 call io_function_output_vector(outp%how(option__maxwelloutput__total_current_mxll), dir, fname, namespace, space, &
671 mesh, ctmp, fn_unit, ierr)
672 end if
673 safe_deallocate_a(ctmp)
675 end subroutine output_total_current_mxll
676
677
678 !----------------------------------------------------------
679 subroutine output_charge_density_mxll(outp, namespace, space, dir, st, gr, hm) !< have to set unit output correctly
680 type(output_t), intent(in) :: outp
681 type(namespace_t), intent(in) :: namespace
682 class(space_t), intent(in) :: space
683 character(len=*), intent(in) :: dir
684 type(states_mxll_t), intent(in) :: st
685 type(grid_t), intent(in) :: gr
686 type(hamiltonian_mxll_t), intent(in) :: hm
687
688 integer :: ierr
689 type(unit_t) :: fn_unit
690 real(real64), allocatable :: dtmp_1(:,:), dtmp_2(:)
691
693
694 ! charge density calculated by the divergence of the electric field
695 if (outp%what(option__maxwelloutput__charge_density)) then
696 fn_unit = units_out%length**(-space%dim)
697 safe_allocate(dtmp_1(1:gr%np_part,1:space%dim))
698 safe_allocate(dtmp_2(1:gr%np))
699 call get_electric_field_state(st%rs_state, gr, dtmp_1, st%ep, gr%np)
700 call get_divergence_field(gr, dtmp_1, dtmp_2, .true.)
701 call dio_function_output(outp%how(option__maxwelloutput__charge_density), dir, "charge_density", namespace, space, &
702 gr, dtmp_2(:), fn_unit, ierr)
703 safe_deallocate_a(dtmp_1)
704 safe_deallocate_a(dtmp_2)
705 end if
706
708 end subroutine output_charge_density_mxll
709
710end module output_mxll_oct_m
711
712!! Local Variables:
713!! mode: f90
714!! coding: utf-8
715!! End:
subroutine, public energy_density_calc(mesh, st, rs_field, energy_dens, e_energy_dens, b_energy_dens, plane_waves_check, rs_field_plane_waves, energy_dens_plane_waves)
subroutine, public external_current_calculation(st, space, mesh, time, current)
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public p_ep
Definition: global.F90:219
This module implements the underlying real-space grid.
Definition: grid.F90:96
The Helmholtz decomposition is intended to contain "only mathematical" functions and procedures to co...
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.
Definition: io.F90:93
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:338
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
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_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
this module contains the low-level part of the output system
Definition: output_low.F90:94
subroutine output_total_current_mxll(outp, namespace, space, dir, st, mesh, hm, time, ep_field, np)
subroutine output_states_mxll(outp, namespace, space, dir, st, mesh)
subroutine output_current_density(outp, namespace, dir, st_mxll, gr_mxll, hm_mxll, st_elec, gr_elec, hm_elec, time)
subroutine output_external_current_density(outp, namespace, space, dir, st, mesh, hm, time)
subroutine, public output_mxll_init(outp, namespace, space)
subroutine output_coupling_potentials(outp, namespace, dir, hm, gr)
subroutine output_transverse_rs_state(helmholtz, outp, namespace, space, dir, st, gr)
subroutine output_energy_density_mxll(outp, namespace, space, dir, st, mesh)
subroutine output_longitudinal_rs_state(helmholtz, outp, namespace, space, dir, st, gr)
subroutine, public output_mxll(outp, namespace, space, gr_mxll, st_mxll, hm_mxll, helmholtz, time, dir, gr_elec, st_elec, hm_elec)
subroutine output_vector_potential_mag(outp, helmholtz, namespace, gr, space, dir, st)
subroutine output_divergence_rs_state(outp, namespace, space, dir, st, gr)
subroutine output_poynting_vector_orbital_angular_momentum(outp, namespace, space, dir, st, mesh, c_factor)
subroutine output_charge_density_mxll(outp, namespace, space, dir, st, gr, hm)
this module contains the output system
Definition: output.F90:94
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
/* 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 get_poynting_vector(mesh, st, rs_state, rs_sign, c_factor, poynting_vector, ep_field, mu_field)
Poynting vector (1/mu) E x B of the Riemann-Silberstein state. The field propagates with the curl pre...
subroutine, public get_orbital_angular_momentum(mesh, poynting_vector, orbital_angular_momentum)
subroutine, public get_electric_field_state(rs_state, mesh, electric_field, ep_field, np)
subroutine, public get_divergence_field(gr, field, field_div, charge_density)
subroutine, public get_magnetic_field_state(rs_state, mesh, rs_sign, magnetic_field, mu_field, np)
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_t), public unit_one
some special units required for particular quantities
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
Describes mesh distribution to nodes.
Definition: mesh.F90:165
output handler class
Definition: output_low.F90:143
The states_elec_t class contains all electronic wave functions.
int true(void)