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.
74 !% This can be used to check the grid points of the medium region.
75 !%Option permittivity 2
76 !% Output of the (static) space-dependent relative permittivity
77 !%Option permeability 3
78 !% Output of the (static) space-dependent relative permeability
79 !%Option speed_of_light 3
80 !% Output of the speed of light in atomic units
81 !%End
82
83 outp%what = .false.
84 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval, &
85 'LinearMediumOutput', 'OutputFormat', 'OutputInterval')
86
87
88 !%Variable LinearMediumOutputDir
89 !%Default "output_iter"
90 !%Type string
91 !%Section Output
92 !%Description
93 !% The name of the directory where <tt>Octopus</tt> stores the information
94 !% about the linear medium system, as required by the <tt>LinearMediumOutput</tt> variable.
95 !%End
96 call parse_variable(namespace, 'LinearMediumOutputDir', "static", outp%iter_dir)
97 if (any(outp%what) .and. maxval(outp%output_interval) > 0) then
98 call io_mkdir(outp%iter_dir, namespace)
99 end if
100 call add_last_slash(outp%iter_dir)
101
103 end subroutine output_linear_medium_init
104
105
106 ! ---------------------------------------------------------
107 subroutine output_linear_medium(outp, namespace, space, mesh, dir, points_map, ep, mu, cc)
108 type(output_t), intent(in) :: outp
109 type(namespace_t), intent(in) :: namespace
110 class(space_t), intent(in) :: space
111 class(mesh_t), intent(in) :: mesh
112 character(len=*), intent(in) :: dir
113 real(real64), intent(in) :: ep(:)
114 real(real64), intent(in) :: mu(:)
115 real(real64), intent(in) :: cc(:)
116 integer, intent(in) :: points_map(:)
117
118 integer :: ierr
119 real(real64), allocatable :: dtmp(:), dtmp2(:)
120 character(len=MAX_PATH_LEN) :: fname
121
122 push_sub(output_linear_medium)
123
124 if (any(outp%what)) then
125 message(1) = "Info: Writing output to " // trim(dir)
126 call messages_info(1, namespace=namespace)
127 call io_mkdir(dir, namespace)
128 endif
129
130 ! Permittivity
131 if (outp%what(option__linearmediumoutput__permittivity)) then
132 write(fname, '(1a)') 'medium-permittivity'
133 safe_allocate(dtmp(1:mesh%np))
134 dtmp(:) = p_ep
135 call get_medium_property(ep, points_map, dtmp) ! ep already has the P_ep factor
136 dtmp(:) = dtmp / p_ep ! to print relative permittivity
137 call dio_function_output(outp%how(option__linearmediumoutput__permittivity), dir, fname, namespace, space, &
138 mesh, dtmp(:), unit_one, ierr)
139 safe_deallocate_a(dtmp)
140 end if
141
142 ! Permeability
143 if (outp%what(option__linearmediumoutput__permeability)) then
144 write(fname, '(1a)') 'medium-permeability'
145 safe_allocate(dtmp(1:mesh%np))
146 dtmp(:) = p_mu
147 call get_medium_property(mu, points_map, dtmp) ! mu alredy has the P_mu factor
148 dtmp(:) = dtmp / p_mu ! to print relative permability
149 call dio_function_output(outp%how(option__linearmediumoutput__permeability), dir, fname, namespace, space, &
150 mesh, dtmp(:), unit_one, ierr)
151 safe_deallocate_a(dtmp)
152 end if
153
154 ! Speed of light
155 if (outp%what(option__linearmediumoutput__speed_of_light)) then
156 write(fname, '(1a)') 'medium-speed-of-light'
157 safe_allocate(dtmp(1:mesh%np))
158 dtmp(:) = p_c
159 call get_medium_property(cc, points_map, dtmp)
160 call dio_function_output(outp%how(option__linearmediumoutput__speed_of_light), dir, fname, namespace, space, &
161 mesh, dtmp(:), unit_one, ierr)
162 safe_deallocate_a(dtmp)
163 end if
164
165 ! Only points
166 if (outp%what(option__linearmediumoutput__points)) then
167 write(fname, '(1a)') 'medium-points'
168 safe_allocate(dtmp(1:mesh%np))
169 safe_allocate(dtmp2(1:mesh%np))
170 dtmp(:) = m_zero
171 dtmp2(:) = m_one
172 call get_medium_property(dtmp2, points_map, dtmp) ! dtmp will have 1 only at the medium grid points
173 call dio_function_output(outp%how(option__linearmediumoutput__points), dir, fname, namespace, space, &
174 mesh, dtmp(:), unit_one, ierr)
175 safe_deallocate_a(dtmp)
176 safe_deallocate_a(dtmp2)
177 end if
178
179
180 pop_sub(output_linear_medium)
181
182 contains
183
184 subroutine get_medium_property(medium_func, points_map, io_func)
185 real(real64), intent(in) :: medium_func(:)
186 integer, intent(in) :: points_map(:)
187 real(real64), intent(out) :: io_func(:)
188
189 integer :: ip, ip_in
190
191 do ip_in = 1, size(points_map)
192 ip = points_map(ip_in)
193 io_func(ip) = medium_func(ip_in)
194 end do
195 end subroutine get_medium_property
196
197 end subroutine output_linear_medium
198
201
202!! Local Variables:
203!! mode: f90
204!! coding: utf-8
real(real64), parameter, public m_zero
Definition: global.F90:188
real(real64), parameter, public p_mu
Definition: global.F90:229
real(real64), parameter, public p_ep
Definition: global.F90:228
real(real64), parameter, public p_c
Electron gyromagnetic ratio, see Phys. Rev. Lett. 130, 071801 (2023)
Definition: global.F90:224
real(real64), parameter, public m_one
Definition: global.F90:189
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:311
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:616
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 low-level part of 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)