Octopus
output_linear_medium.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 F. Bonafe
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
24 use global_oct_m
25 use grid_oct_m
26 use io_oct_m
29 use mesh_oct_m
32 use parser_oct_m
34 use space_oct_m
35 use string_oct_m
36 use unit_oct_m
38
39 implicit none
40
41 private
42 public :: &
45
46contains
47
48 ! ---------------------------------------------------------
49 subroutine output_linear_medium_init(outp, namespace, space)
50 type(output_t), intent(out) :: outp
51 type(namespace_t), intent(in) :: namespace
52 class(space_t), intent(in) :: space
53
55
56 !%Variable LinearMediumOutput
57 !%Type block
58 !%Default none
59 !%Section Output
60 !%Description
61 !% Specifies what to print. The output files are written at the beginning of the run into the output directory for the
62 !% linear medium.
63 !% Each option must be in a separate row. Optionally individual output formats can be defined
64 !% for each row (VTK format is supported) or they can be read separately from <tt>OutputFormat</tt> in the input file.
65 !%
66 !% Example:
67 !% <br><br><tt>%LinearMediumOutput
68 !% <br>&nbsp;&nbsp;permittivity
69 !% <br>&nbsp;&nbsp;permeability
70 !% <br>%<br></tt>
71 !% This block supports all the formats of the <tt>Output</tt> block. See <tt>Output</tt>.
72 !%Option points 1
73 !% Outputs 1 if the a given point is inside the medium, and 0 otherwise. This can be used to check the grid points of the medium region.
74 !%Option permittivity 2
75 !% Output of the (static) space-dependent relative permittivity
76 !%Option permeability 3
77 !% Output of the (static) space-dependent relative permeability
78 !%Option speed_of_light 3
79 !% Output of the speed of light in atomic units
80 !%End
81
82 outp%what = .false.
83 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval, &
84 'LinearMediumOutput', 'OutputFormat', 'OutputInterval')
85
86
87 !%Variable LinearMediumOutputDir
88 !%Default "output_iter"
89 !%Type string
90 !%Section Output
91 !%Description
92 !% The name of the directory where <tt>Octopus</tt> stores the information
93 !% about the linear medium system, as required by the <tt>LinearMediumOutput</tt> variable.
94 !%End
95 call parse_variable(namespace, 'LinearMediumOutputDir', "static", outp%iter_dir)
96 if (any(outp%what) .and. maxval(outp%output_interval) > 0) then
97 call io_mkdir(outp%iter_dir, namespace)
98 end if
99 call add_last_slash(outp%iter_dir)
100
102 end subroutine output_linear_medium_init
103
104
105 ! ---------------------------------------------------------
106 subroutine output_linear_medium(outp, namespace, space, mesh, dir, points_map, ep, mu, cc)
107 type(output_t), intent(in) :: outp
108 type(namespace_t), intent(in) :: namespace
109 class(space_t), intent(in) :: space
110 class(mesh_t), intent(in) :: mesh
111 character(len=*), intent(in) :: dir
112 real(real64), intent(in) :: ep(:)
113 real(real64), intent(in) :: mu(:)
114 real(real64), intent(in) :: cc(:)
115 integer, intent(in) :: points_map(:)
116
117 integer :: ierr
118 real(real64), allocatable :: dtmp(:), dtmp2(:)
119 character(len=MAX_PATH_LEN) :: fname
120
121 push_sub(output_linear_medium)
122
123 if (any(outp%what)) then
124 message(1) = "Info: Writing output to " // trim(dir)
125 call messages_info(1, namespace=namespace)
126 call io_mkdir(dir, namespace)
127 endif
128
129 ! Permittivity
130 if (outp%what(option__linearmediumoutput__permittivity)) then
131 write(fname, '(1a)') 'medium-permittivity'
132 safe_allocate(dtmp(1:mesh%np))
133 dtmp(:) = p_ep
134 call get_medium_property(ep, points_map, dtmp) ! ep already has the P_ep factor
135 dtmp(:) = dtmp / p_ep ! to print relative permittivity
136 call dio_function_output(outp%how(option__linearmediumoutput__permittivity), dir, fname, namespace, space, &
137 mesh, dtmp(:), unit_one, ierr)
138 safe_deallocate_a(dtmp)
139 end if
140
141 ! Permeability
142 if (outp%what(option__linearmediumoutput__permeability)) then
143 write(fname, '(1a)') 'medium-permeability'
144 safe_allocate(dtmp(1:mesh%np))
145 dtmp(:) = p_mu
146 call get_medium_property(mu, points_map, dtmp) ! mu alredy has the P_mu factor
147 dtmp(:) = dtmp / p_mu ! to print relative permability
148 call dio_function_output(outp%how(option__linearmediumoutput__permeability), dir, fname, namespace, space, &
149 mesh, dtmp(:), unit_one, ierr)
150 safe_deallocate_a(dtmp)
151 end if
152
153 ! Speed of light
154 if (outp%what(option__linearmediumoutput__speed_of_light)) then
155 write(fname, '(1a)') 'medium-speed-of-light'
156 safe_allocate(dtmp(1:mesh%np))
157 dtmp(:) = p_c
158 call get_medium_property(cc, points_map, dtmp)
159 call dio_function_output(outp%how(option__linearmediumoutput__speed_of_light), dir, fname, namespace, space, &
160 mesh, dtmp(:), unit_one, ierr)
161 safe_deallocate_a(dtmp)
162 end if
163
164 ! Only points
165 if (outp%what(option__linearmediumoutput__points)) then
166 write(fname, '(1a)') 'medium-points'
167 safe_allocate(dtmp(1:mesh%np))
168 safe_allocate(dtmp2(1:mesh%np))
169 dtmp(:) = m_zero
170 dtmp2(:) = m_one
171 call get_medium_property(dtmp2, points_map, dtmp) ! dtmp will have 1 only at the medium grid points
172 call dio_function_output(outp%how(option__linearmediumoutput__points), dir, fname, namespace, space, &
173 mesh, dtmp(:), unit_one, ierr)
174 safe_deallocate_a(dtmp)
175 safe_deallocate_a(dtmp2)
176 end if
177
178
179 pop_sub(output_linear_medium)
180
181 contains
182
183 subroutine get_medium_property(medium_func, points_map, io_func)
184 real(real64), intent(in) :: medium_func(:)
185 integer, intent(in) :: points_map(:)
186 real(real64), intent(out) :: io_func(:)
187
188 integer :: ip, ip_in
189
190 do ip_in = 1, size(points_map)
191 ip = points_map(ip_in)
192 io_func(ip) = medium_func(ip_in)
193 end do
194 end subroutine get_medium_property
195
196 end subroutine output_linear_medium
197
200
201!! Local Variables:
202!! mode: f90
203!! coding: utf-8
real(real64), parameter, public m_zero
Definition: global.F90:187
real(real64), parameter, public p_mu
Definition: global.F90:228
real(real64), parameter, public p_ep
Definition: global.F90:227
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:223
real(real64), parameter, public m_one
Definition: global.F90:188
This module implements the underlying real-space grid.
Definition: grid.F90:117
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:114
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:354
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
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 output_linear_medium(outp, namespace, space, mesh, dir, points_map, ep, mu, cc)
subroutine, public output_linear_medium_init(outp, namespace, space)
this module contains the output system
Definition: output_low.F90:115
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_t), public unit_one
some special units required for particular quantities
subroutine get_medium_property(medium_func, points_map, io_func)