65 type(namespace_t),
intent(in) :: namespace
66 class(space_t),
intent(in) :: space
67 class(mesh_t),
intent(inout) :: mesh
68 type(derivatives_t),
intent(in) :: der
69 type(states_mxll_t),
intent(inout) :: st
70 type(bc_mxll_t),
intent(inout) :: bc
71 complex(real64),
contiguous,
intent(inout) :: user_def_rs_state(:,:)
74 integer :: il, nlines, idim, ncols, ip, state_from, ierr, maxwell_field
75 real(real64) :: xx(space%dim), rr, e_value, dummy, b_value
76 real(real64),
allocatable :: e_field(:), b_field(:)
77 real(real64),
allocatable :: total_efield(:,:), total_bfield(:,:)
78 complex(real64),
allocatable :: rs_state_add(:), rs_state(:,:)
79 character(len=150),
pointer :: filename_e_field, filename_b_field
82 integer,
parameter :: &
83 STATE_FROM_FORMULA = 1, &
84 state_from_incident_waves = 2, &
85 state_from_file = -10010
143 if (
parse_block(namespace,
'UserDefinedInitialMaxwellStates', blk) == 0)
then
145 safe_allocate(rs_state_add(1:mesh%np_part))
146 safe_allocate(rs_state(1:mesh%np, 1:3))
149 user_def_rs_state(:,:) =
m_zero
154 write(
message(1),
'(a)')
'Maxwell electromagnetic fields are added.'
159 safe_allocate(total_efield(1:mesh%np, 1:3))
160 safe_allocate(total_bfield(1:mesh%np, 1:3))
168 if (ncols /= 1 .and. ncols /= 4)
then
169 message(1) =
'Each line in the UserDefinedMaxwellStates block must have'
170 message(2) =
'one or four columns.'
179 write(cdim,
'(I1)')idim
184 select case (state_from)
186 case (state_from_formula)
192 if (maxwell_field == option__userdefinedinitialmaxwellstates__electric_field)
then
194 call messages_write(
" E-field in dimension "//trim(cdim)//
" : "//trim(st%user_def_e_field(idim)), fmt=
'(a,i1,2a)')
196 else if (maxwell_field == option__userdefinedinitialmaxwellstates__magnetic_field)
then
198 call messages_write(
" B-field in dimension "//trim(cdim)//
" : "//trim(st%user_def_b_field(idim)), fmt=
'(a,i1,2a)')
202 if (maxwell_field == option__userdefinedinitialmaxwellstates__electric_field)
then
210 st%user_def_e_field(idim))
211 total_efield(ip, idim) = total_efield(ip, idim) + e_value
214 else if (maxwell_field == option__userdefinedinitialmaxwellstates__magnetic_field)
then
221 st%user_def_b_field(idim))
222 total_bfield(ip, idim) = total_bfield(ip, idim) + b_value
227 case (state_from_file)
234 safe_allocate(e_field(1:mesh%np))
235 safe_allocate(b_field(1:mesh%np))
238 if (maxwell_field == option__userdefinedinitialmaxwellstates__electric_field)
then
240 call messages_write(
" E-field in dimension "//trim(cdim)//
" : "//trim(filename_e_field), fmt=
'(a,i1,2a)')
243 message(1) =
'Could not read the file!'
244 write(
message(2),
'(a,i1)')
'Error code: ', ierr
247 else if (maxwell_field == option__userdefinedinitialmaxwellstates__magnetic_field)
then
249 call messages_write(
" B-field in dimension "//trim(cdim)//
" : "//trim(filename_b_field), fmt=
'(a,i1,2a)')
252 message(1) =
'Could not read the file!'
253 write(
message(2),
'(a,i1)')
'Error code: ', ierr
258 call build_rs_vector(e_field(:), b_field(:), st%rs_sign, rs_state_add(:), st%ep(ip), st%mu(ip))
260 safe_deallocate_a(e_field)
261 safe_deallocate_a(b_field)
263 call lalg_axpy(mesh%np,
m_one, rs_state_add, user_def_rs_state(:,idim))
265 case (state_from_incident_waves)
271 message(1) =
'Wrong entry in UserDefinedMaxwellStates, column 2.'
272 message(2) =
'You may state "formula", "file" or "use_incident_waves" here.'
278 if (state_from == state_from_formula)
then
280 call build_rs_state(total_efield, total_bfield, st%rs_sign, rs_state, mesh, st%ep, st%mu)
285 safe_deallocate_a(total_efield)
286 safe_deallocate_a(total_bfield)
288 safe_deallocate_a(rs_state)
289 safe_deallocate_a(rs_state_add)
304 subroutine states_mxll_dump(restart, st, space, mesh, zff, zff_dim, ierr, iter, verbose)
307 class(
space_t),
intent(in) :: space
308 class(
mesh_t),
intent(in) :: mesh
309 complex(real64),
intent(in) :: zff(:,:)
310 integer,
intent(in) :: zff_dim
311 integer,
intent(out) :: ierr
312 integer,
optional,
intent(in) :: iter
313 logical,
optional,
intent(in) :: verbose
315 integer :: iunit_wfns, iunit_states
316 integer :: err, err2(2), ist, idim, itot
318 character(len=MAX_PATH_LEN) :: filename
319 character(len=300) :: lines(3)
320 logical :: should_write, verbose_
328 if (restart%skip())
then
334 message(1) =
"Info: Writing Maxwell states."
342 iunit_states = restart%open(
'maxwell_states')
343 write(lines(1),*) zff_dim
344 call restart%write(iunit_states, lines, 1, err)
345 if (err /= 0) ierr = ierr + 1
346 call restart%close(iunit_states)
348 iunit_wfns = restart%open(
'wfns')
349 lines(1) =
'# #dim filename'
350 lines(2) =
'%RS States'
351 call restart%write(iunit_wfns, lines, 2, err)
352 if (err /= 0) ierr = ierr + 2
364 write(filename,
'(i10.10)') itot
366 write(lines(1),
'(i8,3a)') idim,
' | "', trim(filename),
'"'
367 call restart%write(iunit_wfns, lines, 1, err)
368 if (err /= 0) err2(1) = err2(1) + 1
370 should_write = st%st_start <= ist .and. ist <= st%st_end
372 if (should_write)
then
373 call restart%write_mesh_function(filename, mesh, zff(:,idim), err, root = root)
374 if (err /= 0) err2(2) = err2(2) + 1
378 if (err2(1) /= 0) ierr = ierr + 8
379 if (err2(2) /= 0) ierr = ierr + 16
382 call restart%write(iunit_wfns, lines, 1, err)
383 if (err /= 0) ierr = ierr + 64
384 if (
present(iter))
then
385 write(lines(1),
'(a,i7)')
'Iter = ', iter
386 call restart%write(iunit_wfns, lines, 1, err)
387 if (err /= 0) ierr = ierr + 128
390 call restart%close(iunit_wfns)
393 message(1) =
"Info: Finished writing Maxwell states."
406 subroutine states_mxll_load(restart, st, mesh, namespace, space, zff, zff_dim, ierr, iter, lowest_missing, label, verbose)
409 class(
mesh_t),
intent(in) :: mesh
411 class(
space_t),
intent(in) :: space
412 complex(real64),
contiguous,
intent(inout) :: zff(:,:)
413 integer,
intent(in) :: zff_dim
414 integer,
intent(out) :: ierr
415 integer,
optional,
intent(out) :: iter
416 integer,
optional,
intent(out) :: lowest_missing(:)
417 character(len=*),
optional,
intent(in) :: label
418 logical,
optional,
intent(in) :: verbose
420 integer :: states_file, wfns_file, err, ist, idim, dim, mx_st_start, mx_st_end
421 integer :: idone, iread, ntodo
422 character(len=12) :: filename
423 character(len=1) :: char
424 logical,
allocatable :: filled(:, :)
425 character(len=256) :: lines(3), label_
428 character(len=256),
allocatable :: restart_file(:, :)
429 logical,
allocatable :: restart_file_present(:, :)
438 if (
present(lowest_missing)) lowest_missing = 1
439 if (
present(iter)) iter = 0
441 if (restart%skip())
then
452 if (
present(label))
then
456 message(1) =
'Info: Reading Maxwell states'
457 if (len(trim(label_)) > 0)
then
463 states_file = restart%open(
'maxwell_states')
464 call restart%read(states_file, lines, 1, err)
468 read(lines(1), *) idim
470 call restart%close(states_file)
473 wfns_file = restart%open(
'wfns')
474 call restart%read(wfns_file, lines, 2, err)
482 call restart%close(wfns_file)
488 safe_allocate(restart_file(1:zff_dim, st%st_start:st%st_end))
489 safe_allocate(restart_file_present(1:zff_dim,st%st_start:st%st_end))
490 restart_file_present = .false.
496 call restart%read(wfns_file, lines, 1, err)
498 read(lines(1),
'(a)') char
499 if (char ==
'%')
then
503 read(lines(1), *) idim, char, filename
507 if (ist >= st%st_start .and. ist <= st%st_end)
then
508 restart_file(idim, ist) = trim(filename)
509 restart_file_present(idim, ist) = .
true.
513 if (
present(iter))
then
514 call restart%read(wfns_file, lines, 1, err)
518 read(lines(1), *) filename, filename, iter
522 call restart%close(wfns_file)
528 mx_st_start=st%st_start
530 safe_allocate(filled(1:zff_dim,mx_st_start:mx_st_end))
533 if (
present(lowest_missing)) lowest_missing = st%nst + 1
536 if (st%system_grp%is_root() .and. verbose_)
then
538 ntodo = st%lnst*zff_dim
544 if (.not. restart_file_present(idim, ist))
then
545 if (
present(lowest_missing))
then
546 lowest_missing(idim) = min(lowest_missing(idim), ist)
551 call restart%read_mesh_function(restart_file(idim, ist), mesh, zff(:,idim), err)
554 filled(idim, ist) = .
true.
556 else if (
present(lowest_missing))
then
557 lowest_missing(idim) = min(lowest_missing(idim), ist)
560 if (st%system_grp%is_root() .and. verbose_)
then
567 safe_deallocate_a(restart_file)
568 safe_deallocate_a(restart_file_present)
569 safe_deallocate_a(filled)
571 if (st%system_grp%is_root() .and. verbose_)
then
575 if (ierr == 0 .and. iread /= st%nst * zff_dim)
then
584 write(
message(1),
'(a,i6,a,i6,a)')
'Only ', iread,
' files out of ', &
585 st%nst * zff_dim,
' could be read.'
590 message(1) =
'Info: Maxwell states reading done.'
constant times a vector plus a vector
block signals while writing the restart files
unblock signals when writing restart is finished
This module implements batches of mesh functions.
This module implements common operations on batches of mesh functions.
This module handles the calculation mode.
integer, parameter, public p_strategy_max
integer, parameter, public p_strategy_domains
parallelization in domains
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64), parameter, public m_zero
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public dio_function_input(filename, namespace, space, mesh, ff, ierr, map)
Reads a mesh function from file filename, and puts it into ff. If the map argument is passed,...
System information (time, memory, sysname)
subroutine, public loct_progress_bar(a, maxcount)
A wrapper around the progress bar, such that it can be silenced without needing to dress the call wit...
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
character(len=512), private msg
subroutine, public messages_variable_is_block(namespace, name)
subroutine, public print_date(str)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This module handles the communicators for the various parallelization strategies.
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
subroutine, public plane_waves_in_box_calculation(bc, time, mesh, der, st, rs_state)
This module handles spin dimensions of the states and the k-point distribution.
This module handles reading and writing restart information for the states_elec_t.
subroutine, public build_rs_vector(e_vector, b_vector, rs_sign, rs_vector, ep_element, mu_element)
subroutine, public build_rs_state(e_field, b_field, rs_sign, rs_state, mesh, ep_field, mu_field, np)
subroutine, public states_mxll_load(restart, st, mesh, namespace, space, zff, zff_dim, ierr, iter, lowest_missing, label, verbose)
subroutine, public states_mxll_dump(restart, st, space, mesh, zff, zff_dim, ierr, iter, verbose)
subroutine, public states_mxll_read_user_def(namespace, space, mesh, der, st, bc, user_def_rs_state)
subroutine, public conv_to_c_string(str)
converts to c string
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
This module defines the unit system, used for input and output.
Describes mesh distribution to nodes.