52 real(real64),
pointer :: vmf(:)
53 real(real64),
allocatable :: dipole(:)
54 real(real64),
allocatable :: dipole_former(:)
55 complex(real64),
allocatable :: integral(:)
56 real(real64),
allocatable :: pt_q(:), pt_p(:)
57 real(real64),
allocatable :: pt_q_former(:)
58 real(real64) :: time_former
59 real(real64),
pointer :: fmf(:)
60 logical :: has_restart
66 subroutine mf_init(this, gr, st, ions, pt_mode)
67 type(mf_t),
intent(out) :: this
68 type(grid_t),
intent(in) :: gr
69 type(states_elec_t),
intent(in) :: st
70 type(ions_t),
intent(in) :: ions
71 type(photon_mode_t),
intent(in) :: pt_mode
79 safe_allocate(this%vmf(1:gr%np))
80 safe_allocate(this%dipole(1:ions_dim))
81 safe_allocate(this%dipole_former(1:ions_dim))
83 safe_allocate(this%integral(1:pt_mode%nmodes))
84 safe_allocate(this%pt_q(1:pt_mode%nmodes))
85 safe_allocate(this%pt_p(1:pt_mode%nmodes))
86 safe_allocate(this%pt_q_former(1:pt_mode%nmodes))
87 safe_allocate(this%fmf(1:ions_dim))
90 this%has_restart = .false.
93 this%dipole = - ions%dipole() - st%dipole(gr)
95 this%dipole_former =
m_zero
98 if (pt_mode%has_q0_p0)
then
99 this%pt_q(1:pt_mode%nmodes) = pt_mode%pt_coord_q0(1:pt_mode%nmodes)
100 this%pt_p(1:pt_mode%nmodes) = pt_mode%pt_momen_p0(1:pt_mode%nmodes)
109 this%fmf(1:ions_dim) =
m_zero
117 type(mf_t),
intent(inout) :: this
121 safe_deallocate_p(this%vmf)
122 safe_deallocate_a(this%dipole_former)
123 safe_deallocate_a(this%dipole)
125 safe_deallocate_a(this%integral)
126 safe_deallocate_a(this%pt_p)
127 safe_deallocate_a(this%pt_q)
128 safe_deallocate_a(this%pt_q_former)
130 safe_deallocate_p(this%fmf)
137 subroutine mf_calc(this, gr, st, ions, pt_mode, time)
138 type(mf_t),
intent(inout) :: this
139 type(grid_t),
intent(inout) :: gr
140 type(states_elec_t),
intent(inout) :: st
141 type(ions_t),
intent(in) :: ions
142 type(photon_mode_t),
intent(inout) :: pt_mode
143 real(real64),
intent(in) :: time
145 real(real64) :: lambda_pol_dipole, lambda_pol_dipole_former
146 complex(real64) :: integrand
147 real(real64) :: q0, p0
148 integer :: ii, jj, ions_dim
149 logical,
save :: first = .
true.
153 ions_dim = gr%box%dim
155 if (.not. (first .and. this%has_restart))
then
156 do ii = 1, pt_mode%nmodes
157 this%pt_q_former(ii) = this%pt_q(ii)
160 this%dipole_former = this%dipole
161 this%dipole = - ions%dipole() - st%dipole(gr)
165 this%vmf(1:gr%np) =
m_zero
166 this%fmf(1:ions_dim) =
m_zero
168 do ii = 1, pt_mode%nmodes
169 lambda_pol_dipole =
m_zero
170 lambda_pol_dipole_former =
m_zero
172 lambda_pol_dipole = lambda_pol_dipole + &
173 pt_mode%lambda(ii)*pt_mode%pol(ii, jj)*this%dipole(jj)
174 lambda_pol_dipole_former = lambda_pol_dipole_former + &
175 pt_mode%lambda(ii)*pt_mode%pol(ii, jj)*this%dipole_former(jj)
178 if (.not.(first .and. this%has_restart))
then
180 this%integral(ii) =
m_zero
181 else if (abs(this%integral(ii)) <=
m_epsilon)
then
182 this%integral(ii) =
m_half*lambda_pol_dipole*
exp(-
m_zi*pt_mode%omega(ii)*(this%time_former))
184 this%integral(ii) = this%integral(ii) + lambda_pol_dipole*
exp(-
m_zi*pt_mode%omega(ii)*(this%time_former))
188 integrand = -(this%integral(ii)*
exp(
m_zi*pt_mode%omega(ii)*(time)*pt_mode%mu))* &
189 (time*pt_mode%mu - this%time_former)
191 this%pt_q(ii) = aimag(integrand)
192 this%pt_p(ii) = pt_mode%omega(ii)*real(integrand)
194 if (pt_mode%has_q0_p0)
then
195 q0 = pt_mode%pt_coord_q0(ii)*
cos(pt_mode%omega(ii)*(time)*pt_mode%mu)
196 q0 = q0 + pt_mode%pt_momen_p0(ii)/pt_mode%omega(ii)*
sin(pt_mode%omega(ii)*(time)*pt_mode%mu)
197 this%pt_q(ii) = this%pt_q(ii) + q0
199 p0 = -pt_mode%pt_coord_q0(ii)*pt_mode%omega(ii)*
sin(pt_mode%omega(ii)*(time)*pt_mode%mu)
200 p0 = p0 + pt_mode%pt_momen_p0(ii)*
cos(pt_mode%omega(ii)*(time)*pt_mode%mu)
201 this%pt_p(ii) = this%pt_p(ii) + p0
204 if (.not.
allocated(pt_mode%pol_dipole))
then
209 this%vmf(1:gr%np) = this%vmf(1:gr%np) - &
210 m_half*((lambda_pol_dipole + lambda_pol_dipole_former) + pt_mode%omega(ii)* &
211 (this%pt_q(ii) + this%pt_q_former(ii)))*(pt_mode%lambda(ii)*pt_mode%pol_dipole(1:gr%np,ii))
213 this%fmf(jj) = this%fmf(jj) - pt_mode%omega(ii)*pt_mode%lambda(ii)* &
214 pt_mode%pol(ii, jj)*(this%pt_q(ii) + lambda_pol_dipole/pt_mode%omega(ii))
218 if (first .and. this%has_restart)
then
222 this%time_former = time*pt_mode%mu
231 type(
mf_t),
intent(in) :: this
232 type(
grid_t),
intent(in) :: gr
233 real(real64),
intent(in) :: dt
235 integer,
intent(out) :: ierr
237 character(len=80),
allocatable :: lines(:)
238 integer :: iunit, err, jj, ions_dim
241 ions_dim = gr%box%dim
243 safe_allocate(lines(1:2*ions_dim + 4))
248 write(lines(1),
'(a10,2x,es19.12)')
'pt_integral_real', real(this%integral(1))
249 write(lines(2),
'(a10,2x,es19.12)')
'pt_integral_aimag', aimag(this%integral(1))
250 write(lines(3),
'(a10,2x,es19.12)')
'pt_q_former', this%pt_q_former(1)
251 write(lines(4),
'(a10,2x,es19.12)')
'pt_time_former', this%time_former - dt*pt_mode%mu
253 write(lines(4 + jj),
'(a10,2x,es19.12)')
'dipole', this%dipole(jj)
256 write(lines(4 + ions_dim + jj),
'(a10,2x,es19.12)')
'dipole_former', this%dipole_former(jj)
258 call restart_write(restart, iunit, lines, 2*ions_dim + 4, err)
259 if (err /= 0) ierr = ierr + 1
262 safe_deallocate_a(lines)
271 type(
mf_t),
intent(inout) :: this
272 type(
grid_t),
intent(in) :: gr
273 integer,
intent(out) :: ierr
275 integer :: err, iunit, jj, ions_dim
276 character(len=128),
allocatable :: lines(:)
277 character(len=7) :: dummy
278 real(real64),
allocatable :: rr(:)
283 ions_dim = gr%box%dim
292 message(1) =
"Debug: Reading Photons restart."
296 safe_allocate(rr(1:2*ions_dim + 4))
297 safe_allocate(lines(1:2*ions_dim + 4))
299 call restart_read(restart, iunit, lines, 2*ions_dim + 4, err)
303 do jj = 1, 2*ions_dim + 4
304 read(lines(jj),
'(a10,2x,es19.12)') dummy, rr(jj)
307 this%integral(1) = rr(1) +
m_zi*rr(2)
308 this%pt_q_former(1) = rr(3)
309 this%time_former = rr(4)
311 this%dipole(jj) = rr(jj + 4)
314 this%dipole_former(jj) = rr(jj + ions_dim + 4)
316 this%has_restart = .
true.
322 message(1) =
"Debug: Reading Photons restart done."
326 safe_deallocate_a(rr)
327 safe_deallocate_a(lines)
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
type(debug_t), save, public debug
real(real64), parameter, public m_zero
complex(real64), parameter, public m_zi
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
This module implements the underlying real-space grid.
This module defines various routines, operating on mesh functions.
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public mf_photons_load(restart, this, gr, ierr)
subroutine, public mf_init(this, gr, st, ions, pt_mode)
subroutine, public mf_photons_dump(restart, this, gr, dt, pt_mode, ierr)
subroutine, public mf_end(this)
subroutine, public mf_calc(this, gr, st, ions, pt_mode, time)
subroutine, public photon_mode_compute_dipoles(this, mesh)
Computes the polarization dipole.
subroutine, public restart_read(restart, iunit, lines, nlines, ierr)
subroutine, public restart_close(restart, iunit)
Close a file previously opened with restart_open.
subroutine, public restart_write(restart, iunit, lines, nlines, ierr)
logical pure function, public restart_skip(restart)
Returns true if the restart information should neither be read nor written. This might happen because...
integer function, public restart_open(restart, filename, status, position, silent)
Open file "filename" found inside the current restart directory. Depending on the type of restart,...
Description of the grid, containing information on derivatives, stencil, and symmetries.