Octopus
layer_pcm.F90
Go to the documentation of this file.
1!! Copyright (C) 2024 Jannis Krumland
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#include "global.h"
19
20module layer_pcm_oct_m
21
22 use accel_oct_m
23 use fft_oct_m
24 use debug_oct_m
25 use global_oct_m
26 use math_oct_m
28 use parser_oct_m
34
35
36 implicit none
37
38 private
39
40 public :: &
41 layer_t, &
50
52 integer, public, parameter :: &
53 LPCM_MODE_EQ = 0, & !< static
55
57 integer, public, parameter :: &
58 LPCM_S_POLARIZATION = 1, &
60
62 integer, parameter :: &
63 LPCM_IMPINGING = 1, &
65
67 logical, public, parameter :: &
68 LPCM_DELTA = .true., &
69 lpcm_sigma = .false.
70
71
78 type layer_t
79 real(real64) :: eps_static_para
80 real(real64) :: eps_static_perp
81 real(real64) :: eps_infty_para
82 real(real64) :: eps_infty_perp
83 real(real64) :: thickness
84 logical :: has_dynamic
85 integer :: mode = 1
86 contains
87 procedure :: get_eps_para => layer_get_eps_para
88 procedure :: get_eps_perp => layer_get_eps_perp
89 end type layer_t
90
91
96 type reflection_t
97 logical :: is_present = .false.
98 integer :: nfields
99 real(real64), allocatable :: wavevectors(:, :)
100 real(real64) :: dt
101 integer :: niter
102 type(fft_t) :: fft_handler
103 type(namespace_t) :: namespace
104 end type reflection_t
105
106
114 logical :: is_present = .false.
115 logical :: has_dynamic
116 integer :: mode
117 real(real64) :: eps_static_solv
118 real(real64) :: eps_infty_solv
119 real(real64) :: origin(3)
120 real(real64) :: normal(3)
121 integer :: nlayers
122 type(namespace_t) :: namespace
123 type(layer_t), allocatable :: layers(:)
124 type(reflection_t) :: reflection
125 contains
126 procedure :: get_eps_solv => substrate_get_eps_solv
127 procedure :: set_mode => substrate_set_mode
128 procedure :: iset_static => substrate_iset_static
129 procedure :: iset_dynamic => substrate_iset_dynamic
130 procedure :: check_if_dynamic => substrate_check_if_dynamic
131 procedure :: check_distance_to_surface => substrate_check_distance_to_surface
132 end type lpcm_substrate_t
133
135contains
136
137
138 real(real64) function layer_get_eps_para(this) result (eps_para)
139 class(layer_t) :: this
140 push_sub(layer_get_eps_para)
141 if (this%has_dynamic .and. this%mode == lpcm_mode_noneq) then
142 eps_para = this%eps_infty_para
143 else
144 eps_para = this%eps_static_para
145 end if
146 pop_sub(layer_get_eps_para)
147 end function layer_get_eps_para
148
149
150 real(real64) function layer_get_eps_perp(this) result (eps_perp)
151 class(layer_t) :: this
153 if (this%has_dynamic .and. this%mode == lpcm_mode_noneq) then
154 eps_perp = this%eps_infty_perp
155 else
156 eps_perp = this%eps_static_perp
157 end if
158 pop_sub(layer_get_eps_perp)
161
162 real(real64) function substrate_get_eps_solv(this) result (eps_solvent)
163 class(lpcm_substrate_t) :: this
164 push_sub(substrate_get_eps_solv)
165 if (this%mode == lpcm_mode_noneq) then
166 eps_solvent = this%eps_infty_solv
167 else
168 eps_solvent = this%eps_static_solv
169 end if
174 subroutine substrate_set_mode(this, mode)
175 class(lpcm_substrate_t) :: this
176 integer, intent(in) :: mode
177 integer :: ilayer
178 push_sub(substrate_set_mode)
179 if (this%is_present) then
180 this%mode = mode
181 do ilayer = 1, this%nlayers
182 this%layers(ilayer)%mode = mode
183 end do
184 end if
186 end subroutine substrate_set_mode
190 function substrate_iset_static(this) result (substrate_updated)
191 class(lpcm_substrate_t), target :: this
192 class(lpcm_substrate_t), pointer :: substrate_updated
194 call this%set_mode(lpcm_mode_eq)
195 substrate_updated => this
197 end function substrate_iset_static
201 function substrate_iset_dynamic(this) result (substrate_updated)
202 class(lpcm_substrate_t), target :: this
203 class(lpcm_substrate_t), pointer :: substrate_updated
204 push_sub(substrate.substrate_iset_dynamic)
205 call this%set_mode(lpcm_mode_noneq)
206 substrate_updated => this
207 pop_sub(substrate.substrate_iset_dynamic)
208 end function substrate_iset_dynamic
209
214 subroutine layer_pcm_substrate_init(substrate, namespace)
215 type(lpcm_substrate_t), intent(inout) :: substrate
216 type(namespace_t), intent(in) :: namespace
217
218 type(block_t) :: block
219 integer, parameter :: irow = 0, success = 0
220
223 substrate%namespace = namespace_t("LayerPCM", parent=namespace)
224 substrate%reflection%namespace = namespace_t("LayerPCMReflection", parent=namespace)
225
226 !%Variable LayerPCMIncludeSubstrate
227 !%Type logical
228 !%Default no
229 !%Section Hamiltonian::PCM
230 !%Description
231 !% If true, a substrate is included in the PCM calculation
232 !%End
233 call parse_variable(substrate%namespace, 'LayerPCMIncludeSubstrate', .false., substrate%is_present)
235 !%Variable LayerPCMIncludeReflection
236 !%Type logical
237 !%Default no
238 !%Section Hamiltonian::PCM
239 !%Description
240 !% If true, the fields that the substrate reflects are added to the electric fields of
241 !% <tt>TDExternalFields</tt>. Requires <tt>LayerPCMIncludeSubstrate = yes</tt> and the block
242 !% <tt>LayerPCMWaveVectors</tt>.
243 !%End
244 call parse_variable(substrate%reflection%namespace, 'LayerPCMIncludeReflection', .false., substrate%reflection%is_present)
245
246 if (.not. substrate%is_present) then
248 return
249 end if
250
251 if (accel_is_enabled()) then
252 call messages_not_implemented("LayerPCM on GPUs", namespace=namespace)
253 end if
254
255 !%Variable LayerPCMSurfacePoint
256 !%Type block
257 !%Section Hamiltonian::PCM
258 !%Description
259 !%Specifies a point on the surface of the substrate
260 !%End
261 if (parse_block(substrate%namespace, "LayerPCMSurfacePoint", block) /= success) then
262 message(1) = "'LayerPCMIncludeSubstrate = yes', but 'LayerPCMSurfacePoint' block missing"
263 call messages_fatal(1)
264 end if
265 call parse_vector_row(block, irow, substrate%origin)
266 call parse_block_end(block)
267
268 !%Variable LayerPCMSurfaceNormalVector
269 !%Type block
270 !%Section Hamiltonian::PCM
271 !%Description
272 !%Specifies a vector orthogonal to the surface of the substrate
273 !%End
274 if (parse_block(substrate%namespace, "LayerPCMSurfaceNormalVector", block) /= success) then
275 message(1) = "'LayerPCMIncludeSubstrate = yes', but 'LayerPCMSurfaceNormalVector' block missing"
276 call messages_fatal(1)
277 end if
278 call parse_vector_row(block, irow, substrate%normal)
279 substrate%normal = substrate%normal / norm2(substrate%normal)
280 call parse_block_end(block)
281
282 call parse_layers(substrate)
283 call substrate%check_if_dynamic()
284
285 call parse_variable(substrate%namespace, 'PCMStaticEpsilon', m_one, substrate%eps_static_solv)
286 call parse_variable(substrate%namespace, 'PCMDynamicEpsilon', substrate%eps_static_solv, substrate%eps_infty_solv)
287
289 end subroutine layer_pcm_substrate_init
290
291
292 subroutine layer_pcm_substrate_reflection_init(substrate, namespace)
293 type(lpcm_substrate_t), intent(inout) :: substrate
294 type(namespace_t), intent(in) :: namespace
296 call layer_pcm_substrate_init(substrate, namespace)
297 if (substrate%is_present .and. substrate%reflection%is_present) then
298 call parse_wave_vectors(substrate%reflection)
299 call parse_other_reflection_parameters(substrate%reflection)
300 end if
303
304
306 subroutine parse_vector_row(block, irow, target_array, ioffset)
307 type(block_t), intent(in) :: block
308 integer, intent(in) :: irow
309 integer, optional, intent(in) :: ioffset
310 real(real64), intent(inout) :: target_array(3)
311 integer :: ixyz, icol
312 push_sub(parse_vector_row)
313 do ixyz = 1, 3
314 icol = ixyz - 1
315 if (present(ioffset)) then
316 icol = icol + ioffset
317 end if
318 call parse_block_float(block, irow, icol, target_array(ixyz))
319 end do
320 pop_sub(parse_vector_row)
321 end subroutine parse_vector_row
322
323
325 subroutine parse_layers(substrate)
326 type(lpcm_substrate_t), intent(inout) :: substrate
327 type(block_t) :: block
328 integer :: ilayer
329 integer, parameter :: success = 0
330 push_sub(lpcm_substrate_init.parse_layers)
331 !%Variable LayerPCMLayers
332 !%Type block
333 !%Section Hamiltonian::PCM
334 !%Description
335 !% Block to define layers of a stratified substrate.
336 !% Each row represents one layer, strarting from the surface downwards.
337 !% Last row is the semi-infinite substrate.
338 !% Each row has the following form:
339 !% Thickness | Mode | EpsilonStaticParallel | EpilonStaticsPerpedicular (| EpsilonInftyParallel | EpsilonInftyPerpendicular)
340 !% For the final row (semi-infinite substrate), Thickness = substrate
341 !% For Mode, the options Mode = eq for equilibrium-PCM and Mode = noneq for non-equilibrium-PCM are possible
342 !%Option eq 0
343 !% Stack always completely in equilibrium with adsorbat
344 !%Option noneq 1
345 !% Only part of the stack in equilibrium with adsorbat
346 !%Option substrate -1.0
347 !% for setting the thickness of the semi-infinite substrate
348 !%End
349 if (parse_block(substrate%namespace, 'LayerPCMLayers', block) /= success) then
350 message(1) = "'LayerPCMIncludeSubstrate = yes', but 'LayerPCMLayers' block missing"
351 call messages_fatal(1)
352 end if
353 substrate%nlayers = get_nlayers(block)
354 safe_allocate(substrate%layers(1:substrate%nlayers))
355 do ilayer = 1, substrate%nlayers
356 call parse_layer_row(block, ilayer, substrate%layers(ilayer))
357 end do
358 call parse_block_end(block)
359 pop_sub(lpcm_substrate_init.parse_layers)
360 end subroutine parse_layers
361
365 class(lpcm_substrate_t), intent(inout) :: this
366 integer :: ilayer
368 this%has_dynamic = .false.
369 do ilayer = 1, this%nlayers
370 this%has_dynamic = (this%has_dynamic .or. this%layers(ilayer)%has_dynamic)
371 end do
373 end subroutine substrate_check_if_dynamic
374
375
377 function get_nlayers(block) result(nlayers)
378 type(block_t), intent(in) :: block
379 integer :: nlayers, irow, nrows_block
380 real(real64) :: thickness
381 real(real64), parameter :: thickness_substrate = -m_one
382 integer, parameter :: icol_thickness = 0
383 push_sub(lpcm_substrate_init.parse_layers.get_nlayers)
384 nrows_block = parse_block_n(block)
385 nlayers = nrows_block
386 do irow = 0, nrows_block - 1
387 call parse_block_float(block, irow, icol_thickness, thickness)
388 ! use is_close with zero tolerance to get exact floating point equality
389 if(is_close(thickness, thickness_substrate, rtol=m_zero, atol=m_zero)) then
390 nlayers = irow + 1
391 exit
392 end if
393 end do
394 pop_sub(lpcm_substrate_init.parse_layers.get_nlayers)
395 end function get_nlayers
396
399 subroutine parse_layer_row(block, ilayer, layer)
400 type(block_t), intent(in) :: block
401 integer, intent(in) :: ilayer
402 type(layer_t), intent(inout) :: layer
403 integer :: irow
404 integer, parameter :: icol_thickness = 0, icol_mode = 1, icol_eps_para = 2, icol_eps_perp = 3
405 integer, parameter :: icol_eps_infty_para = 4, icol_eps_infty_perp = 5
406 integer, parameter :: ncols_eq = 4, ncols_noneq = 6
407 push_sub(lpcm_substrate_init.parse_layers.parse_layer_row)
408 irow = ilayer - 1
409 call parse_block_integer(block, irow, icol_mode, layer%mode)
410 layer%has_dynamic = (layer%mode == lpcm_mode_noneq)
411 call parse_block_float(block, irow, icol_thickness, layer%thickness)
412 call parse_block_float(block, irow, icol_eps_para, layer%eps_static_para)
413 call parse_block_float(block, irow, icol_eps_perp, layer%eps_static_perp)
414 if (layer%has_dynamic) then
415 if (parse_block_cols(block, irow) /= ncols_noneq) then
416 message(1) = "Wrong number of entries in LayerPCMLayers block"
417 call messages_fatal(1)
418 end if
419 call parse_block_float(block, irow, icol_eps_infty_para, layer%eps_infty_para)
420 call parse_block_float(block, irow, icol_eps_infty_perp, layer%eps_infty_perp)
421 else if (parse_block_cols(block, irow) /= ncols_eq) then
422 message(1) = "Wrong number of entries in LayerPCMLayers block"
423 call messages_fatal(1)
424 end if
425 pop_sub(lpcm_substrate_init.parse_layers.parse_layer_row)
426 end subroutine parse_layer_row
427
428
430 subroutine parse_wave_vectors(reflection)
431 type(reflection_t), intent(inout) :: reflection
432 type(block_t) :: block
433 integer :: ifield, irow
434 real(real64) :: wave_vector(3)
435 real(real64), allocatable :: polarization_vectors(:,:)
436 integer, parameter :: success = 0
437 push_sub(parse_wave_vectors)
438 if (parse_block(reflection%namespace, "TDExternalFields", block) /= success) then
439 message(1) = "'LayerPCMIncludeReflection = yes', but 'TDExternalFields' block missing"
440 call messages_fatal(1)
441 end if
442 reflection%nfields = parse_block_n(block)
443 safe_allocate(polarization_vectors(1:reflection%nfields, 1:3))
444 do ifield = 1, reflection%nfields
445 irow = ifield-1
446 call parse_vector_row(block, irow, polarization_vectors(ifield, :), ioffset=1)
447 end do
448 call parse_block_end(block)
449 !%Variable LayerPCMWaveVectors
450 !%Type block
451 !%Section Hamiltonian::PCM
452 !%Description
453 !% Specifies the direction of the wave vectors in the solvent/outside the substrate.
454 !% Each row is assigned to the corresponding row in the TDExternalFields block.
455 !%End
456 if (parse_block(reflection%namespace, "LayerPCMWaveVectors", block) /= success) then
457 message(1) = "'LayerPCMIncludeReflection = yes', but 'LayerPCMWaveVectors' block missing"
458 call messages_fatal(1)
459 end if
460 safe_allocate(reflection%wavevectors(1:reflection%nfields, 1:3))
461 do ifield = 1, reflection%nfields
462 irow = ifield-1
463 call parse_vector_row(block, irow, wave_vector)
464 wave_vector = wave_vector / norm2(wave_vector)
465 if (abs(dot_product(wave_vector, polarization_vectors(ifield, :))) > m_epsilon) then
466 message(1) = "Not all 'LayerPCMWaveVectors' are perpendicular to the corresponding polarization vectors"
467 call messages_fatal(1)
468 end if
469 reflection%wavevectors(ifield, :) = wave_vector
470 end do
471 call parse_block_end(block)
472 safe_deallocate_a(polarization_vectors)
473 pop_sub(parse_wave_vectors)
474 end subroutine parse_wave_vectors
475
476
478 subroutine parse_other_reflection_parameters(reflection)
479 type(reflection_t), intent(inout) :: reflection
480 real(real64) :: dt
481 integer :: niter
482 real(real64) :: propagation_time
483 integer :: default_niter
484 push_sub(lpcm_substrate_init.parse_other_reflection_parameters)
485 call parse_variable(reflection%namespace, 'TDTimeStep', -m_one, dt, unit=units_inp%time)
486 if (dt < m_zero) then
487 message(1) = "Please provide time step explicitly for calculation of reflected fields."
488 call messages_fatal(1)
489 end if
490 call parse_variable(reflection%namespace, 'TDPropagationTime', -m_one, propagation_time, unit=units_inp%time)
491 default_niter = 1500
492 if (propagation_time > m_zero) default_niter = nint(propagation_time / dt)
493 call parse_variable(reflection%namespace, 'TDMaxSteps', default_niter, niter)
494 reflection%dt = dt
495 reflection%niter = niter
496 pop_sub(lpcm_substrate_init.parse_other_reflection_parameters)
498
499
500 subroutine layer_pcm_substrate_end(substrate)
501 type(lpcm_substrate_t), intent(inout) :: substrate
503 if(substrate%is_present) then
504 safe_deallocate_a(substrate%layers)
505 if(substrate%reflection%is_present) then
506 safe_deallocate_a(substrate%reflection%wavevectors)
507 end if
508 end if
510 end subroutine layer_pcm_substrate_end
511
512
514 subroutine layer_pcm_add_image_term(n_tess, tess, substrate, delta, sigma)
515 integer, intent(in) :: n_tess
516 type(pcm_tessera_t), intent(in) :: tess(:)
517 type(lpcm_substrate_t), intent(in) :: substrate
518 real(real64), intent(inout) :: delta(:,:), sigma(:,:)
519 integer :: itess, jtess
521 do itess = 1, n_tess
522 do jtess = 1, n_tess
523 delta(itess,jtess) = delta(itess,jtess) &
524 + layer_pcm_get_image_matrix_element(lpcm_delta, tess(itess), tess(jtess), substrate)
525 sigma(itess,jtess) = sigma(itess,jtess) &
526 + layer_pcm_get_image_matrix_element(lpcm_sigma, tess(itess), tess(jtess), substrate)
527 end do
528 end do
530 end subroutine layer_pcm_add_image_term
531
532
573 function layer_pcm_get_image_matrix_element(imatrix, tessi, tessj, substrate) result(image_matrix_element)
574 logical, intent(in) :: imatrix
575 type(pcm_tessera_t), intent(in) :: tessi, tessj
576 type(lpcm_substrate_t), intent(in) :: substrate
577 real(real64) :: image_matrix_element
578 integer :: ii
579 real(real64) :: eps_solv, eps_1_para, eps_1_perp, len_dr_para, prefactor, normalization_factor
580 real(real64) :: dr_para(3)
581 real(real64) :: eps_bar, beta_infty, decay, scale, distance
582 ! Gauss-Laguerre quadrature of order n = 20: the abscissas x_i are the roots of the Laguerre polynomial L_n
583 ! and the weights are w_i = x_i / ((n + 1) L_{n+1}(x_i))^2. Values from numpy.polynomial.laguerre.laggauss(20).
584 real(real64), parameter :: laguerre_abscissas(20) = [ &
585 7.0539889691988308e-02_real64, 3.7212681800161168e-01_real64, &
586 9.1658210248327365e-01_real64, 1.7073065310283433e+00_real64, &
587 2.7491992553094318e+00_real64, 4.0489253138508872e+00_real64, &
588 5.6151749708616165e+00_real64, 7.4590174536710636e+00_real64, &
589 9.5943928695810978e+00_real64, 1.2038802546964316e+01_real64, &
590 1.4814293442630740e+01_real64, 1.7948895520519375e+01_real64, &
591 2.1478788240285009e+01_real64, 2.5451702793186907e+01_real64, &
592 2.9932554631700611e+01_real64, 3.5013434240479000e+01_real64, &
593 4.0833057056728570e+01_real64, 4.7619994047346502e+01_real64, &
594 5.5810795750063896e+01_real64, 6.6524416525615749e+01_real64 ]
595 real(real64), parameter :: laguerre_weights(20) = [ &
596 1.6874680185110752e-01_real64, 2.9125436200607041e-01_real64, &
597 2.6668610286700473e-01_real64, 1.6600245326950702e-01_real64, &
598 7.4826064668792922e-02_real64, 2.4964417309283345e-02_real64, &
599 6.2025508445722657e-03_real64, 1.1449623864769113e-03_real64, &
600 1.5574177302781308e-04_real64, 1.5401440865224925e-05_real64, &
601 1.0864863665179882e-06_real64, 5.3301209095566816e-08_real64, &
602 1.7579811790505961e-09_real64, 3.7255024025123219e-11_real64, &
603 4.7675292515781967e-13_real64, 3.3728442433624263e-15_real64, &
604 1.1550143395003870e-17_real64, 1.5395221405823417e-20_real64, &
605 5.2864427255693058e-24_real64, 1.6564566124990406e-28_real64 ]
607 call substrate%check_distance_to_surface(tessi%point)
608 call substrate%check_distance_to_surface(tessj%point)
609 call assign_epsilons(substrate, eps_solv, eps_1_para, eps_1_perp)
610 dr_para = get_dr_para(tessi%point, tessj%point, substrate)
611 len_dr_para = norm2(dr_para)
612 normalization_factor = dot_product(tessi%point + tessj%point - 2 * substrate%origin, substrate%normal)
613 ! Image charge of the half-space formed by the first layer, the limit of the prefactor for large q
614 eps_bar = sqrt(eps_1_para * eps_1_perp)
615 beta_infty = (eps_solv - eps_bar) / (eps_solv + eps_bar)
616 distance = sqrt(len_dr_para**2 + normalization_factor**2)
617 ! The remaining prefactor decays as exp(-q decay), which is included in the weight of the quadrature
618 image_matrix_element = m_zero
619 if (substrate%nlayers > 1) then
620 decay = m_two * sqrt(eps_1_para / eps_1_perp) * substrate%layers(1)%thickness
621 scale = normalization_factor + decay
622 do ii = 1, size(laguerre_abscissas)
623 prefactor = get_prefactor(eps_solv, eps_1_para, eps_1_perp, laguerre_abscissas(ii), scale, substrate)
624 prefactor = (prefactor - beta_infty) * exp(laguerre_abscissas(ii) * decay / scale)
625 select case(imatrix)
626 case(lpcm_sigma)
627 image_matrix_element = image_matrix_element &
628 + get_sigma_image(laguerre_abscissas(ii), laguerre_weights(ii), len_dr_para, prefactor, scale)
629 case(lpcm_delta)
630 image_matrix_element = image_matrix_element &
631 + get_delta_image(laguerre_abscissas(ii), laguerre_weights(ii), len_dr_para, prefactor, scale, &
632 dr_para, tessj%normal, substrate)
633 end select
634 end do
635 select case (imatrix)
636 case (lpcm_sigma)
637 image_matrix_element = image_matrix_element / scale / eps_solv
638 case (lpcm_delta)
639 image_matrix_element = -image_matrix_element * tessj%area / scale ** 2
640 end select
641 end if
642 select case (imatrix)
643 case (lpcm_sigma)
644 image_matrix_element = image_matrix_element + beta_infty / (eps_solv * distance)
646 image_matrix_element = image_matrix_element + tessj%area * beta_infty / distance**3 * &
647 (dot_product(tessj%normal, dr_para) - dot_product(tessj%normal, substrate%normal) * normalization_factor)
648 end select
651
652
654 subroutine substrate_check_distance_to_surface(this, point)
655 class(lpcm_substrate_t), intent(in) :: this
656 real(real64), intent(in) :: point(3)
657 if (dot_product(point, this%normal) < dot_product(this%origin, this%normal)) then
658 message(1) = "The substrate is too close to the molecule!"
659 call messages_fatal(1)
660 end if
662
663
665 subroutine assign_epsilons(substrate, eps_solv, eps_1_para, eps_1_perp)
666 type(lpcm_substrate_t), intent(in) :: substrate
667 real(real64), intent(out) :: eps_solv, eps_1_para, eps_1_perp
668 push_sub(pcm_matrix.add_image_term.get_image_matrix_element.assign_epsilons)
669 eps_solv = substrate%get_eps_solv()
670 eps_1_para = substrate%layers(1)%get_eps_para()
671 eps_1_perp = substrate%layers(1)%get_eps_perp()
672 pop_sub(pcm_matrix.add_image_term.get_image_matrix_element.assign_epsilons)
673 end subroutine assign_epsilons
674
675
677 function get_dr_para(point_i, point_j, substrate) result(dr_para)
678 real(real64), intent(in) :: point_i(3), point_j(3)
679 type(lpcm_substrate_t), intent(in) :: substrate
680 real(real64) :: dr_para(3)
681 real(real64) :: dr(3)
682 push_sub(pcm_matrix.add_image_term.image_matrix_element.get_dr_para)
683 dr = point_i - point_j
684 dr_para = dr - dot_product(dr, substrate%normal) * substrate%normal
685 pop_sub(pcm_matrix.add_image_term.image_matrix_element.get_dr_para)
686 end function get_dr_para
687
688
700 function get_prefactor(eps_solv, eps_1_para, eps_1_perp, laguerre_abscissa, normalization_factor, substrate) result(prefactor)
701 real(real64), intent(in) :: eps_solv, eps_1_para, eps_1_perp, laguerre_abscissa, normalization_factor
702 type(lpcm_substrate_t), intent(in) :: substrate
703 real(real64) :: prefactor
704 real(real64) :: eps_subs
705 push_sub(pcm_matrix.add_image_term.image_matrix_element.get_prefactor)
706 eps_subs = sqrt(eps_1_para * eps_1_perp)
707 eps_subs = eps_subs * get_gamma_factor(laguerre_abscissa / normalization_factor, substrate)
708 prefactor = (eps_solv - eps_subs) / (eps_solv + eps_subs)
709 pop_sub(pcm_matrix.add_image_term.image_matrix_element.get_prefactor)
710 end function get_prefactor
711
712
714 function get_sigma_image(laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor) result(sigma_image)
715 real(real64), intent(in) :: laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor
716 real(real64) :: sigma_image
717 push_sub(pcm_matrix.add_image_term.image_matrix_element.get_sigma_image)
718 sigma_image = laguerre_weight * prefactor * bessel_jn(0, laguerre_abscissa * len_dr_para / normalization_factor)
719 pop_sub(pcm_matrix.add_image_term.image_matrix_element.get_sigma_image)
720 end function get_sigma_image
721
722
724 function get_delta_image(laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor, &
725 dr_para, normalj, substrate) result(delta_image)
726 real(real64), intent(in) :: laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor
727 real(real64), intent(in) :: dr_para(3), normalj(3)
728 type(lpcm_substrate_t), intent(in) :: substrate
729 real(real64) :: delta_image
730 real(real64) :: bessel_argument
731 push_sub(pcm_matrix.add_image_term.image_matrix_element.get_delta_image)
732 if (len_dr_para < m_epsilon) then
733 delta_image = dot_product(normalj, laguerre_abscissa * laguerre_weight * prefactor * substrate%normal)
734 else
735 bessel_argument = laguerre_abscissa * len_dr_para / normalization_factor
736 delta_image = dot_product(normalj, laguerre_abscissa * laguerre_weight * prefactor * &
737 (bessel_jn(0, bessel_argument) * substrate%normal - bessel_jn(1, bessel_argument) * dr_para / len_dr_para))
738 end if
739 pop_sub(pcm_matrix.add_image_term.image_matrix_element.get_delta_image)
740 end function get_delta_image
741
742
746 function get_gamma_factor(q1, substrate) result(gamma_factor)
747 real(real64), intent(in) :: q1
748 type(lpcm_substrate_t), intent(in) :: substrate
749 real(real64) :: gamma_factor
750 real(real64) :: t_matrix(2,2), d_matrix(2,2)
751 real(real64) :: xi_i, xi_ip1, eps_bar_ii, eps_bar_iip1
752 integer :: ilayer
753 real(real64), allocatable :: thickness(:)
754 real(real64), allocatable :: eps_para(:), eps_perp(:)
755 real(real64) :: exponential
756 push_sub(pcm_matrix.add_image_term.image_matrix_element.get_gamma_factor)
757 safe_allocate(thickness(1:substrate%nlayers))
758 safe_allocate(eps_para(1:substrate%nlayers))
759 safe_allocate(eps_perp(1:substrate%nlayers))
760 do ilayer = 1, substrate%nlayers
761 thickness(ilayer) = substrate%layers(ilayer)%thickness
762 eps_para(ilayer) = substrate%layers(ilayer)%get_eps_para()
763 eps_perp(ilayer) = substrate%layers(ilayer)%get_eps_perp()
764 end do
765 t_matrix(1,1) = m_one
766 t_matrix(1,2) = m_zero
767 t_matrix(2,1) = m_zero
768 t_matrix(2,2) = m_one
769 do ilayer = substrate%nlayers-1, 1, -1
770 xi_i = sqrt(eps_para(ilayer) / eps_perp(ilayer))
771 xi_ip1 = sqrt(eps_para(ilayer+1) / eps_perp(ilayer+1))
772 eps_bar_ii = xi_i * eps_perp(ilayer)
773 eps_bar_iip1 = xi_ip1 * eps_perp(ilayer+1)
774 exponential = exp(-m_two * q1 * xi_i * thickness(ilayer))
775 d_matrix(1,1) = eps_bar_ii + eps_bar_iip1
776 d_matrix(2,1) = exponential * (eps_bar_ii - eps_bar_iip1)
777 d_matrix(1,2) = eps_bar_ii - eps_bar_iip1
778 d_matrix(2,2) = exponential * (eps_bar_ii + eps_bar_iip1)
779 t_matrix = matmul(d_matrix, t_matrix)
780 end do
781 gamma_factor = (t_matrix(1,1) - t_matrix(2,1)) / (t_matrix(1,1) + t_matrix(2,1))
782 safe_deallocate_a(thickness)
783 safe_deallocate_a(eps_para)
784 safe_deallocate_a(eps_perp)
785 pop_sub(pcm_matrix.add_image_term.image_matrix_element.get_gamma_factor)
786 end function get_gamma_factor
787
788
792 subroutine get_reflected(ifield, polarization, substrate, phase_factor, w0, tdf_enve, tdf_phase)
793 integer, intent(in) :: ifield, polarization
794 complex(real64), intent(in) :: phase_factor
795 real(real64), intent(in) :: w0
796 type(lpcm_substrate_t), intent(in) :: substrate
797 type(tdf_t), intent(inout) :: tdf_enve
798 type(tdf_t), intent(inout) :: tdf_phase
799 real(real64), allocatable :: field_tdomain(:)
800 complex(real64), allocatable :: field_wdomain(:)
801 type(fft_t) :: fft_handler
802 integer :: nvals_t, nvals_w
803 real(real64) :: step_t, step_w
804 push_sub(get_reflected)
805 call write_lengths_and_steps(tdf_enve, nvals_t, step_t, nvals_w, step_w)
806 call reflection_fft_init(nvals_t, nvals_w, fft_handler, field_tdomain, field_wdomain)
807 call write_field_to_array(tdf_enve, tdf_phase, w0, phase_factor, nvals_t, step_t, field_tdomain)
808 call dfft_forward(fft_handler, field_tdomain, field_wdomain)
809 call multiply_by_reflectivity(ifield, polarization, substrate, nvals_w, step_w, field_wdomain)
810 call dfft_backward(fft_handler, field_wdomain, field_tdomain)
811 call tdf_set_numerical(tdf_enve, field_tdomain)
812 field_tdomain = m_zero
813 call tdf_set_numerical(tdf_phase, field_tdomain)
814 call reflection_fft_end(fft_handler, field_tdomain, field_wdomain)
815 pop_sub(get_reflected)
816 end subroutine get_reflected
817
820 subroutine write_field_to_array(tdf_enve, tdf_phase, w0, phase_factor, nvals_t, step_t, vals_t)
821 type(tdf_t), intent(in) :: tdf_enve
822 type(tdf_t), intent(in) :: tdf_phase
823 real(real64), intent(in) :: w0
824 complex(real64), intent(in) :: phase_factor
825 integer, intent(in) :: nvals_t
826 real(real64), intent(in) :: step_t
827 real(real64), intent(inout) :: vals_t(:)
828 real(real64) :: phase
829 integer :: ival
830 push_sub(write_field_to_array)
831 phase = atan2(aimag(phase_factor), real(phase_factor))
832 do ival = 1, nvals_t
833 vals_t(ival) = abs(phase_factor) * tdf(tdf_enve, ival) * cos(tdf(tdf_phase, ival) + w0 * (ival - 1) * step_t + phase)
834 end do
835 pop_sub(write_field_to_array)
836 end subroutine write_field_to_array
837
838
840 subroutine multiply_by_reflectivity(ifield, polarization, substrate, nvals_w, step_w, vals_w)
841 integer, intent(in) :: ifield, polarization
842 type(lpcm_substrate_t), intent(in) :: substrate
843 integer, intent(in) :: nvals_w
844 real(real64), intent(in) :: step_w
845 complex(real64), intent(inout) :: vals_w(:)
846 integer :: ival
848 do ival = 1, nvals_w
849 vals_w(ival) = vals_w(ival) * layer_pcm_get_reflectivity(ifield, polarization, substrate, (ival - 1) * step_w)
850 end do
852 end subroutine multiply_by_reflectivity
853
854
856 subroutine reflection_fft_init(nvals_t, nvals_w, fft, vals_t, vals_w)
857 integer, intent(in) :: nvals_t, nvals_w
858 type(fft_t), intent(inout) :: fft
859 real(real64), allocatable, intent(inout) :: vals_t(:)
860 complex(real64), allocatable, intent(inout) :: vals_w(:)
861 integer :: fft_size(3)
862 integer, parameter :: fft_dim = 1
863 logical, parameter :: fft_opt(3) = (/.false., .false., .false./)
864 integer, parameter :: FFT_OPT_PAR(3) = (/-1, -1, -1/)
865 push_sub(reflection_fft_init)
866 fft_size = (/nvals_t, 1, 1/)
867 call fft_init(fft, fft_size, fft_dim, fft_real, fftlib_fftw, fft_opt, fft_opt_par)
868 safe_allocate(vals_t(1:nvals_t))
869 safe_allocate(vals_w(1:nvals_w))
870 vals_w = m_zero
871 pop_sub(reflection_fft_init)
872 end subroutine reflection_fft_init
873
874
876 subroutine reflection_fft_end(fft_handler, vals_t, vals_w)
877 type(fft_t), intent(inout) :: fft_handler
878 real(real64), allocatable, intent(inout) :: vals_t(:)
879 complex(real64), allocatable, intent(inout) :: vals_w(:)
880 push_sub(reflection_fft_end)
881 safe_deallocate_a(vals_t)
882 safe_deallocate_a(vals_w)
883 call fft_end(fft_handler)
884 pop_sub(reflection_fft_end)
885 end subroutine reflection_fft_end
886
887
889 subroutine write_lengths_and_steps(tdf, nvals_t, step_t, nvals_w, step_w)
890 type(tdf_t), intent(in) :: tdf
891 integer, intent(out) :: nvals_t, nvals_w
892 real(real64), intent(out) :: step_t, step_w
894 nvals_t = tdf_niter(tdf) + 1
895 step_t = tdf_dt(tdf)
896 nvals_w = nvals_t / 2 + 1
897 step_w = 2 * m_pi / (nvals_t * step_t)
899 end subroutine write_lengths_and_steps
900
901
905 subroutine calculate_polarization_vector(direction, wave_vector_in, polarization, normal, perpendicular, polarization_vector)
906 integer, intent(in) :: direction
907 real(real64), intent(in) :: wave_vector_in(3)
908 integer, intent(in) :: polarization
909 real(real64), intent(in) :: normal(3)
910 logical, intent(out) :: perpendicular
911 complex(real64), intent(out) :: polarization_vector(3)
912 real(real64) :: s_polarization_vector(3), wave_vector_out(3)
914 polarization_vector = m_z0
915 s_polarization_vector = dcross_product(wave_vector_in, normal)
916 perpendicular = sum(abs(s_polarization_vector)) < m_epsilon
917 if (.not. perpendicular) then
918 s_polarization_vector = dcross_product(wave_vector_in, normal)
919 select case (polarization)
921 polarization_vector = s_polarization_vector / norm2(s_polarization_vector)
923 return
925 select case (direction)
926 case (lpcm_impinging)
927 polarization_vector = dcross_product(wave_vector_in, s_polarization_vector)
929 wave_vector_out = wave_vector_in - 2 * normal * dot_product(normal, wave_vector_in)
930 polarization_vector = dcross_product(s_polarization_vector, wave_vector_out)
931 end select
932 polarization_vector = polarization_vector / norm2(abs(polarization_vector))
933 end select
934 end if
936 end subroutine calculate_polarization_vector
937
938
940 subroutine check_wave_vector(wave_vector, polarization_vector, normal_vector)
941 real(real64), intent(in) :: wave_vector(3)
942 complex(real64), intent(in) :: polarization_vector(3)
943 real(real64), intent(in) :: normal_vector(3)
944 push_sub(check_wave_vector)
945 if (abs(dot_product(wave_vector, polarization_vector)) >= m_epsilon) then
946 message(1) = "At least one of the wave vectors is not perpendicular to its polarization."
947 call messages_fatal(1)
948 end if
949 if (dot_product(wave_vector, normal_vector) >= m_epsilon) then
950 message(1) = "At least one of the waves does not propagate towards the substrate."
951 call messages_fatal(1)
952 end if
953 pop_sub(check_wave_vector)
954 end subroutine check_wave_vector
955
956
966 subroutine layer_pcm_calculate_reflected_fields(polarizations_tot, frequencies_tot, envelopes_tot, phases_tot, &
967 polarizations_imp, frequencies_imp, envelopes_imp, phases_imp, substrate)
968 complex(real64), allocatable, intent(out) :: polarizations_tot(:,:)
969 real(real64), allocatable, intent(out) :: frequencies_tot(:)
970 type(tdf_t), allocatable, intent(out) :: envelopes_tot(:)
971 type(tdf_t), allocatable, intent(out) :: phases_tot(:)
972 complex(real64), intent(in) :: polarizations_imp(:,:)
973 real(real64), intent(in) :: frequencies_imp(:)
974 type(tdf_t), intent(in) :: envelopes_imp(:)
975 type(tdf_t), intent(in) :: phases_imp(:)
976 type(lpcm_substrate_t), intent(in) :: substrate
977 real(real64), allocatable :: response(:)
978 complex(real64) :: projection
979 complex(real64) :: polarization_vector(3)
980 integer :: nlasers_imp, nlasers_tot, ilaser, jlaser, polarization
981 logical :: perpendicular_to_surface
983 nlasers_tot = get_nlasers(substrate%reflection%wavevectors, polarizations_imp, substrate%normal)
984 safe_allocate(polarizations_tot(1:nlasers_tot, 1:3))
985 safe_allocate(frequencies_tot(1:nlasers_tot))
986 safe_allocate(envelopes_tot(1:nlasers_tot))
987 safe_allocate(phases_tot(1:nlasers_tot))
988 do jlaser = 1, nlasers_tot
989 call tdf_init(envelopes_tot(jlaser))
990 call tdf_init(phases_tot(jlaser))
991 end do
992 nlasers_imp = size(frequencies_imp)
993 jlaser = 0
994 do ilaser = 1, nlasers_imp
995 jlaser = jlaser + 1
996 call tdf_copy(envelopes_tot(jlaser), envelopes_imp(ilaser))
997 call tdf_copy(phases_tot(jlaser), phases_imp(ilaser))
998 polarizations_tot(jlaser,:) = polarizations_imp(ilaser,:)
999 frequencies_tot(jlaser) = frequencies_imp(ilaser)
1000 do polarization = lpcm_s_polarization, lpcm_p_polarization
1001 jlaser = jlaser + 1
1002 call calculate_polarization_vector(lpcm_impinging, substrate%reflection%wavevectors(ilaser,:), polarization, &
1003 substrate%normal, perpendicular_to_surface, polarization_vector)
1004 if (perpendicular_to_surface) then
1005 projection = m_one
1006 polarizations_tot(jlaser,:) = polarizations_imp(ilaser,:)
1007 else if (abs(dot_product(polarization_vector, polarizations_imp(ilaser,:))) < m_epsilon) then
1008 jlaser = jlaser - 1
1009 cycle
1010 else
1011 projection = dot_product(polarization_vector, polarizations_imp(ilaser,:)) / norm2(abs(polarizations_imp(ilaser,:)))
1012 call calculate_polarization_vector(lpcm_reflected, substrate%reflection%wavevectors(ilaser,:), polarization, &
1013 substrate%normal, perpendicular_to_surface, polarizations_tot(jlaser,:))
1014 end if
1015 frequencies_tot(jlaser) = m_zero
1016 call tdf_copy(envelopes_tot(jlaser), envelopes_imp(ilaser))
1017 call tdf_copy(phases_tot(jlaser), phases_imp(ilaser))
1018 call tdf_to_numerical(envelopes_tot(jlaser), substrate%reflection%niter, substrate%reflection%dt, m_zero)
1019 call tdf_to_numerical(phases_tot(jlaser), substrate%reflection%niter, substrate%reflection%dt, m_zero)
1020 call get_reflected(ilaser, polarization, substrate, projection, &
1021 frequencies_imp(ilaser), envelopes_tot(jlaser), phases_tot(jlaser))
1022 safe_deallocate_a(response)
1023 if(perpendicular_to_surface) exit
1024 end do
1025 end do
1028
1029
1033 integer function get_nlasers(wave_vectors, polarization_vectors, normal) result (nlasers)
1034 real(real64), intent(in) :: wave_vectors(:,:)
1035 complex(real64), intent(in) :: polarization_vectors(:,:)
1036 real(real64), intent(in) :: normal(3)
1037 complex(real64) :: pure_polarization_vector(3)
1038 logical :: purely_s_or_p, perpendicular
1039 integer :: iwave
1040 push_sub(get_nlasers)
1041 nlasers = 0
1042 do iwave = 1, size(polarization_vectors, 1)
1043 call check_wave_vector(wave_vectors(iwave, :), polarization_vectors(iwave, :), normal)
1045 normal, perpendicular, pure_polarization_vector)
1046 purely_s_or_p = abs(dot_product(pure_polarization_vector, polarization_vectors(iwave, :))) < m_epsilon
1048 normal, perpendicular, pure_polarization_vector)
1049 purely_s_or_p = purely_s_or_p .or. abs(dot_product(pure_polarization_vector, polarization_vectors(iwave, :))) < m_epsilon
1050 if (perpendicular .or. purely_s_or_p) then
1051 nlasers = nlasers + 2
1052 else
1053 nlasers = nlasers + 3
1054 end if
1055 end do
1056 pop_sub(get_nlasers)
1057 end function get_nlasers
1058
1059
1066 complex(real64) function layer_pcm_get_reflectivity(ifield, polarization, substrate, frequency) result (reflectivity)
1067 integer, intent(in) :: ifield, polarization
1068 type(lpcm_substrate_t), intent(in) :: substrate
1069 real(real64), intent(in) :: frequency
1070 complex(real64) :: t_mat(2,2), d_mat(2,2)
1071 real(real64) :: k_para(3)
1072 real(real64) :: q1, ww, eps_para, eps_perp, eps_solv, thickness
1073 complex(real64) :: kz
1074 integer :: ilayer
1076 ww = frequency
1077 if(ww < m_epsilon) ww = m_epsilon
1078 k_para = substrate%reflection%wavevectors(ifield, :)
1079 k_para = k_para - substrate%normal * dot_product(substrate%normal, k_para)
1080 eps_solv = substrate%get_eps_solv()
1081 q1 = sqrt(eps_solv) * ww / p_c * norm2(k_para)
1082 t_mat(1,1) = m_one
1083 t_mat(1,2) = m_one
1084 eps_para = substrate%layers(substrate%nlayers)%get_eps_para()
1085 eps_perp = substrate%layers(substrate%nlayers)%get_eps_perp()
1086 kz = get_wave_vector_z(polarization, eps_para, eps_perp, ww, q1)
1087 select case(polarization)
1088 case (lpcm_s_polarization)
1089 t_mat(2,1) = -kz
1090 t_mat(2,2) = kz
1091 case (lpcm_p_polarization)
1092 t_mat(2,1) = -kz / eps_para
1093 t_mat(2,2) = kz / eps_para
1094 end select
1095 do ilayer = substrate%nlayers-1, 1, -1
1096 eps_para = substrate%layers(ilayer)%get_eps_para()
1097 eps_perp = substrate%layers(ilayer)%get_eps_perp()
1098 thickness = substrate%layers(ilayer)%thickness
1099 kz = get_wave_vector_z(polarization, eps_para, eps_perp, ww, q1)
1100 d_mat(1,1) = cos(kz * thickness)
1101 d_mat(2,2) = d_mat(1,1)
1102 select case (polarization)
1103 case (lpcm_s_polarization)
1104 d_mat(2,1) = -m_zi * kz * sin(kz * thickness)
1105 d_mat(1,2) = d_mat(2,1) / kz ** 2
1106 case (lpcm_p_polarization)
1107 d_mat(2,1) = -m_zi * kz * sin(kz * thickness) / eps_para
1108 d_mat(1,2) = d_mat(2,1)/kz ** 2 * eps_para ** 2
1109 end select
1110 t_mat = matmul(d_mat, t_mat)
1111 end do
1112 kz = get_wave_vector_z(polarization, eps_solv, eps_solv, ww, q1)
1113 select case (polarization)
1114 case (lpcm_s_polarization)
1115 d_mat(1,1) = kz
1116 d_mat(2,1) = kz
1117 case (lpcm_p_polarization)
1118 d_mat(1,1) = kz / eps_solv
1119 d_mat(2,1) = kz / eps_solv
1120 end select
1121 d_mat(1,2) = -m_one
1122 d_mat(2,2) = m_one
1123 t_mat = matmul(d_mat, t_mat)
1124 reflectivity = t_mat(2,1) / t_mat(1,1)
1125 if (polarization == lpcm_p_polarization) reflectivity = -reflectivity
1127 end function layer_pcm_get_reflectivity
1128
1129
1134 complex(real64) function get_wave_vector_z(polarization, eps_para, eps_perp, ww, q1) result (wave_vector_z)
1135 integer, intent(in) :: polarization
1136 real(real64), intent(in) :: eps_para, eps_perp, ww, q1
1137 real(real64) :: kz2
1139 kz2 = (ww / p_c) ** 2 * eps_para
1140 select case (polarization)
1141 case (lpcm_s_polarization)
1142 kz2 = kz2 - q1 ** 2
1143 case (lpcm_p_polarization)
1144 kz2 = kz2 - eps_para / eps_perp * q1 ** 2
1145 end select
1146 wave_vector_z = conjg(sqrt(cmplx(kz2, m_zero, real64)))
1147 pop_sub(get_wave_vector_z)
1148 end function get_wave_vector_z
1149
1150
1151end module layer_pcm_oct_m
1152
1153!! Local Variables:
1154!! mode: f90
1155!! coding: utf-8
1156!! End:
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug mode(NDEBUG ! is defined). Otherwise it is merely a logical assertion that
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
double atan2(double __y, double __x) __attribute__((__nothrow__
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:97
integer, parameter lpcm_reflected
Definition: layer_pcm.F90:134
subroutine parse_layers(substrate)
Parses the PCMLayers block.
Definition: layer_pcm.F90:398
real(real64) function layer_get_eps_para(this)
Definition: layer_pcm.F90:211
integer function get_nlasers(wave_vectors, polarization_vectors, normal)
Returns the total number of lasers (incoming and reflected)
Definition: layer_pcm.F90:1106
real(real64) function, dimension(3) get_dr_para(point_i, point_j, substrate)
Returns in-plane component of the difference vector dr_ij = r_i - r_j.
Definition: layer_pcm.F90:750
complex(real64) function, public layer_pcm_get_reflectivity(ifield, polarization, substrate, frequency)
Returns the reflectivity r(w) of the substrate for a given frequency w (differs for s and p polarizat...
Definition: layer_pcm.F90:1139
subroutine write_lengths_and_steps(tdf, nvals_t, step_t, nvals_w, step_w)
Extracts time and frequency array lengths and steps.
Definition: layer_pcm.F90:962
subroutine calculate_polarization_vector(direction, wave_vector_in, polarization, normal, perpendicular, polarization_vector)
Calculates polarization vector of impinging or reflected (direction), s- or p-polarized field (polari...
Definition: layer_pcm.F90:978
subroutine, public layer_pcm_substrate_end(substrate)
Definition: layer_pcm.F90:573
logical, parameter, public lpcm_sigma
S_e.
Definition: layer_pcm.F90:139
real(real64) function, public layer_pcm_get_image_matrix_element(imatrix, tessi, tessj, substrate)
Returns substrate image term M_ij^img to be added to the matrix element M_ij, where M = S_e or D_e.
Definition: layer_pcm.F90:646
subroutine parse_layer_row(block, ilayer, layer)
Parses a row of the PCMLayersBlock.
Definition: layer_pcm.F90:472
subroutine parse_wave_vectors(reflection)
Parses electric field wave vectors, asserting that they are perpendicular to the corresponding polari...
Definition: layer_pcm.F90:503
logical, parameter, public lpcm_delta
D_e.
Definition: layer_pcm.F90:139
integer, parameter, public lpcm_mode_eq
static
Definition: layer_pcm.F90:124
subroutine, public layer_pcm_substrate_init(substrate, namespace)
Parses the substrate.
Definition: layer_pcm.F90:287
real(real64) function get_delta_image(laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor, dr_para, normalj, substrate)
Returns the contribution w_i * f(x_i) of a given abcissa x_i/weight w_i to the numerical D_e integrat...
Definition: layer_pcm.F90:798
subroutine substrate_set_mode(this, mode)
Definition: layer_pcm.F90:247
real(real64) function layer_get_eps_perp(this)
Definition: layer_pcm.F90:223
subroutine multiply_by_reflectivity(ifield, polarization, substrate, nvals_w, step_w, vals_w)
Multiplies frequency-domain array vals_w by reflectivity array r(w), component-wise.
Definition: layer_pcm.F90:913
integer, parameter, public lpcm_mode_noneq
dynamic, where provided
Definition: layer_pcm.F90:124
real(real64) function get_sigma_image(laguerre_abscissa, laguerre_weight, len_dr_para, prefactor, normalization_factor)
Returns the contribution w_i * f(x_i) of a given abcissa x_i/weight w_i to the numerical S_e integrat...
Definition: layer_pcm.F90:787
subroutine parse_other_reflection_parameters(reflection)
Reparses time step and propagation time steps.
Definition: layer_pcm.F90:551
subroutine, public layer_pcm_substrate_reflection_init(substrate, namespace)
Definition: layer_pcm.F90:365
class(lpcm_substrate_t) function, pointer substrate_iset_static(this)
Sets substrate mode to static and returns reference the substrate object.
Definition: layer_pcm.F90:263
integer, parameter, public lpcm_s_polarization
Polarization of a field with respect to the plane of incidence.
Definition: layer_pcm.F90:129
integer function get_nlayers(block)
Returns the number of layers in the substrate.
Definition: layer_pcm.F90:450
subroutine write_field_to_array(tdf_enve, tdf_phase, w0, phase_factor, nvals_t, step_t, vals_t)
Writes field from envelope (tdf_enve) and phase functions (tdf_phase) to numerical array (vals_t)
Definition: layer_pcm.F90:893
real(real64) function get_gamma_factor(q1, substrate)
Returns the factor (T_11 - T_21) / (T_11 + T_21), which is proportional to eps_subs [Eq....
Definition: layer_pcm.F90:819
real(real64) function get_prefactor(eps_solv, eps_1_para, eps_1_perp, laguerre_abscissa, normalization_factor, substrate)
Returns prefactor multiplying the exponential in Eq. (22)
Definition: layer_pcm.F90:773
subroutine reflection_fft_init(nvals_t, nvals_w, fft, vals_t, vals_w)
Initializes the FFT handler as well as corresponding time and frequency series.
Definition: layer_pcm.F90:929
complex(real64) function get_wave_vector_z(polarization, eps_para, eps_perp, ww, q1)
Returns the out-of-plane component of the wave vector in an anisotropic dielectric layer (differs for...
Definition: layer_pcm.F90:1207
subroutine check_wave_vector(wave_vector, polarization_vector, normal_vector)
This can be removed (together with the line where it is currently used), as the orthogonality is now ...
Definition: layer_pcm.F90:1013
subroutine assign_epsilons(substrate, eps_solv, eps_1_para, eps_1_perp)
Assigns the dielectric constants of the solvent and of the first layer to the arguments.
Definition: layer_pcm.F90:738
subroutine get_reflected(ifield, polarization, substrate, phase_factor, w0, tdf_enve, tdf_phase)
Calculates reflected field by forward-FFT-ing incoming field, multiplying it with reflectivity,...
Definition: layer_pcm.F90:865
subroutine substrate_check_distance_to_surface(this, point)
Asserts that the PCM cavity and the surface do not intersect.
Definition: layer_pcm.F90:727
subroutine reflection_fft_end(fft_handler, vals_t, vals_w)
Terminates the FFT handler as well as corresponding time and frequency series.
Definition: layer_pcm.F90:949
class(lpcm_substrate_t) function, pointer substrate_iset_dynamic(this)
Sets substrate mode to dynamic and returns reference the substrate object.
Definition: layer_pcm.F90:274
subroutine, public layer_pcm_calculate_reflected_fields(polarizations_tot, frequencies_tot, envelopes_tot, phases_tot, polarizations_imp, frequencies_imp, envelopes_imp, phases_imp, substrate)
Calculates parameters of reflected fields from those of the impinging fields, saving them in the corr...
Definition: layer_pcm.F90:1040
subroutine, public layer_pcm_add_image_term(n_tess, tess, substrate, delta, sigma)
Adds substrate polarization terms to the IEF-PCM D_e (delta) and S_e (sigma) matrices.
Definition: layer_pcm.F90:587
real(real64) function substrate_get_eps_solv(this)
Definition: layer_pcm.F90:235
subroutine parse_vector_row(block, irow, target_array, ioffset)
Parses a three-component vector from a block row.
Definition: layer_pcm.F90:379
integer, parameter, public lpcm_p_polarization
Definition: layer_pcm.F90:129
subroutine substrate_check_if_dynamic(this)
Checks whether at least at least 1 dynamic dielectric constant has been provided for the substrate (s...
Definition: layer_pcm.F90:437
integer, parameter lpcm_impinging
Propagation direction of a field with respect to the surface.
Definition: layer_pcm.F90:134
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
This module defines the unit system, used for input and output.
Holding parameters characterizing a dielectric layer.
Definition: layer_pcm.F90:150
Holding parameters characterizing a stack of dielectric layers.
Definition: layer_pcm.F90:185
Holding parameters and utilities needed for calculating reflected fields.
Definition: layer_pcm.F90:168
tesselation derived type
Definition: pcm_eom.F90:121
int true(void)