Octopus
pcm.F90
Go to the documentation of this file.
1!! Copyright (C) 2014 Alain Delgado Gran, Carlo Andrea Rozzi, Stefano Corni, Gabriel Gil
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#include "global.h"
20
21module pcm_oct_m
23 use debug_oct_m
24 use global_oct_m
25 use grid_oct_m
26 use, intrinsic :: iso_fortran_env
27 use index_oct_m
28 use io_oct_m
29 use ions_oct_m
31 use math_oct_m
33 use mesh_oct_m
35 use mpi_oct_m
38 use parser_oct_m
43 use space_oct_m
45
46 ! to output debug info
47 use unit_oct_m
51
53
54 implicit none
55
56 private
57
58 public :: &
59 pcm_t, &
60 pcm_min_t, &
62 pcm_init, &
63 pcm_end, &
66 pcm_pot_rs, &
70 pcm_update, &
73 pcm_dipole, &
74 pcm_eps, &
76 pcm_td_eq, &
77 pcm_td_neq, &
79
80
83 type pcm_sphere_t
84 private
85 real(real64) :: x !
86 real(real64) :: y
87 real(real64) :: z !
88 real(real64) :: r
89 end type pcm_sphere_t
90
92 integer, parameter :: PCM_DIM_SPACE = 3
94 type pcm_t
95 private
96 logical, public :: run_pcm
97 integer, public :: tdlevel
98 integer :: n_spheres
99 integer, public :: n_tesserae
100 type(pcm_sphere_t), allocatable :: spheres(:)
101 type(pcm_tessera_t), allocatable, public :: tess(:)
102 real(real64) :: scale_r
103 real(real64), allocatable :: matrix(:,:)
104 real(real64), allocatable :: matrix_d(:,:)
105 real(real64), allocatable :: matrix_lf(:,:)
106 real(real64), allocatable :: matrix_lf_d(:,:)
107 real(real64), allocatable, public :: q_e(:)
108 real(real64), allocatable :: q_n(:)
109 real(real64), allocatable, public :: q_e_in(:)
110 real(real64), allocatable :: rho_e(:)
111 real(real64), allocatable :: rho_n(:)
112 real(real64) :: qtot_e
113 real(real64) :: qtot_n
114 real(real64) :: qtot_e_in
115 real(real64) :: q_e_nominal
116 real(real64) :: q_n_nominal
117 logical :: renorm_charges
118 real(real64) :: q_tot_tol
119 real(real64) :: deltaQ_e
120 real(real64) :: deltaQ_n
121 real(real64), allocatable :: v_e(:)
122 real(real64), allocatable :: v_n(:)
123 real(real64), allocatable, public :: v_e_rs(:)
124 real(real64), allocatable, public :: v_n_rs(:)
125 real(real64), allocatable :: q_ext(:)
126 real(real64), allocatable :: q_ext_in(:)
127 real(real64), allocatable :: rho_ext(:)
128 real(real64) :: qtot_ext
129 real(real64) :: qtot_ext_in
130 real(real64), allocatable :: v_ext(:)
131 real(real64), allocatable, public :: v_ext_rs(:)
132 real(real64), allocatable :: q_kick(:)
133 real(real64), allocatable :: rho_kick(:)
134 real(real64) :: qtot_kick
135 real(real64), allocatable :: v_kick(:)
136 real(real64), allocatable, public :: v_kick_rs(:)
137 real(real64), public :: epsilon_0
138 real(real64), public :: epsilon_infty
139 integer, public :: which_eps
140 type(debye_param_t) :: deb
141 type(drude_param_t) :: drl
142 logical, public :: localf
143 logical, public :: solute
144 logical :: kick_is_present
145 ! !! (if localf is .false. this is irrelevant to PCM)
146 logical, public :: kick_like
147 integer :: initial_asc
148 real(real64) :: gaussian_width
149 integer :: info_unit
150 integer, public :: counter
151 character(len=80) :: input_cavity
152 integer :: update_iter
153 integer, public :: iter
154 integer :: calc_method
155 integer :: tess_nn
156 real(real64), public :: dt
158 type(lpcm_substrate_t) :: substrate
160 ! We will allow a copy to the namespace and space here,
161 ! as this type will become an extension to the system_t class at some point
162 type(namespace_t), pointer :: namespace
163 type(space_t) :: space
164 end type pcm_t
165
167 ! Components are public by default
168 logical :: run_pcm
169 logical :: localf
170 integer :: tdlevel
171 integer :: which_eps
174 end type pcm_min_t
176 real(real64), allocatable :: s_mat_act(:,:)
177 real(real64), allocatable :: d_mat_act(:,:)
178 real(real64), allocatable :: sigma(:,:)
179 real(real64), allocatable :: delta(:,:)
182 real(real64), allocatable :: mat_gamess(:,:)
184 integer, parameter :: &
189 integer, parameter, public :: &
193 integer, parameter :: &
197 integer, parameter :: n_tess_sphere = 60
198 ! !< cannot be changed without changing cav_gen subroutine
200contains
202 !-------------------------------------------------------------------------------------------------------
204 subroutine pcm_init(pcm, namespace, space, ions, grid, qtot, val_charge, external_potentials_present, kick_present)
205 type(pcm_t), intent(out) :: pcm
206 type(namespace_t), target, intent(in) :: namespace
207 class(space_t), intent(in) :: space
208 type(ions_t), intent(in) :: ions
209 type(grid_t), intent(in) :: grid
210 real(real64), intent(in) :: qtot
211 real(real64), intent(in) :: val_charge
212 logical, intent(in) :: external_potentials_present
213 logical, intent(in) :: kick_present
215 integer :: ia, ii, itess, jtess, pcm_vdw_type, subdivider
216 integer :: cav_unit_test, iunit, pcmmat_unit
217 integer :: pcmmat_gamess_unit, cav_gamess_unit
218 real(real64) :: min_distance
220 integer, parameter :: mxts = 10000
222 real(real64) :: default_value
223 real(real64) :: vdw_radius
225 type(pcm_tessera_t), allocatable :: dum2(:)
227 logical :: band
228 logical :: add_spheres_h
229 logical :: changed_default_nn
231 integer :: default_nn
232 real(real64) :: max_area
233
234 type(lpcm_substrate_t) :: substrate
236 push_sub(pcm_init)
237
238 pcm%kick_is_present = kick_present
239
240 pcm%localf = .false.
241 pcm%iter = 0
242 pcm%update_iter = 1
243 pcm%kick_like = .false.
245 pcm%namespace => namespace
246 pcm%space = space
247
248 !%Variable PCMCalculation
249 !%Type logical
250 !%Default no
251 !%Section Hamiltonian::PCM
252 !%Description
253 !% If true, the calculation is performed accounting for solvation effects
254 !% by using the Integral Equation Formalism Polarizable Continuum Model IEF-PCM
255 !% formulated in real-space and real-time (<i>J. Chem. Phys.</i> <b>143</b>, 144111 (2015),
256 !% <i>Chem. Rev.</i> <b>105</b>, 2999 (2005), <i>J. Chem. Phys.</i> <b>139</b>, 024105 (2013)).
257 !% At the moment, this option is available only for <tt>TheoryLevel = DFT</tt>.
258 !% PCM is tested for CalculationMode = gs, while still experimental for other values (in particular, CalculationMode = td).
259 !%End
260 call parse_variable(namespace, 'PCMCalculation', .false., pcm%run_pcm)
261 if (pcm%run_pcm) then
262 call messages_print_with_emphasis(msg='PCM', namespace=namespace)
263 if (pcm%space%dim /= pcm_dim_space) then
264 message(1) = "PCM is only available for 3d calculations"
265 call messages_fatal(1, namespace=namespace)
266 end if
267 select type (box => grid%box)
268 type is (box_minimum_t)
269 class default
270 message(1) = "PCM is only available for BoxShape = minimum"
271 call messages_fatal(1, namespace=namespace)
272 end select
273 else
274 pop_sub(pcm_init)
275 return
276 end if
277
278 call layer_pcm_substrate_init(substrate, namespace)
279
280 !%Variable PCMVdWRadii
281 !%Type integer
282 !%Default pcm_vdw_optimized
283 !%Section Hamiltonian::PCM
284 !%Description
285 !% This variable selects which van der Waals radius will be used to generate the solvent cavity.
286 !%Option pcm_vdw_optimized 1
287 !% Use the van der Waals radius optimized by Stefan Grimme in J. Comput. Chem. 27: 1787-1799, 2006,
288 !% except for C, N and O, reported in J. Chem. Phys. 120, 3893 (2004).
289 !%Option pcm_vdw_species 2
290 !% The vdW radii are set from the <tt>share/pseudopotentials/elements</tt> file. These values are obtained from
291 !% Alvarez S., Dalton Trans., 2013, 42, 8617-8636. Values can be changed in the <tt>Species</tt> block.
292 !%End
293 call parse_variable(namespace, 'PCMVdWRadii', pcm_vdw_optimized, pcm_vdw_type)
294 call messages_print_var_option("PCMVdWRadii", pcm_vdw_type, namespace=namespace)
295
296 select case (pcm_vdw_type)
297 case (pcm_vdw_optimized)
298 default_value = 1.2_real64
299 case (pcm_vdw_species)
300 default_value = m_one
301 end select
302
303 !%Variable PCMRadiusScaling
304 !%Type float
305 !%Section Hamiltonian::PCM
306 !%Description
307 !% Scales the radii of the spheres used to build the solute cavity surface.
308 !% The default value depends on the choice of <tt>PCMVdWRadii</tt>:
309 !% 1.2 for <tt>pcm_vdw_optimized</tt> and 1.0 for <tt>pcm_vdw_species</tt>.
310 !%End
311 call parse_variable(namespace, 'PCMRadiusScaling', default_value, pcm%scale_r)
312 call messages_print_var_value("PCMRadiusScaling", pcm%scale_r, namespace=namespace)
313
314 !%Variable PCMTDLevel
315 !%Type integer
316 !%Default eq
317 !%Section Hamiltonian::PCM
318 !%Description
319 !% When CalculationMode=td, PCMTDLevel it sets the way the time-depenendent solvent polarization is propagated.
320 !%Option eq 0
321 !% If PCMTDLevel=eq, the solvent is always in equilibrium with the solute or the external field, i.e.,
322 !% the solvent polarization follows instantaneously the changes in solute density or in the external field.
323 !% PCMTDLevel=neq and PCMTDLevel=eom are both nonequilibrium runs.
324 !%Option neq 1
325 !% If PCMTDLevel=neq, solvent polarization charges are splitted in two terms:
326 !% one that follows instantaneously the changes in the solute density or in the external field (dynamical polarization charges),
327 !% and another that lag behind in the evolution w.r.t. the solute density or the external field (inertial polarization charges).
328 !%Option eom 2
329 !% If PCMTDLevel=eom, solvent polarization charges evolves following an equation of motion, generalizing 'neq' propagation.
330 !% The equation of motion used here depends on the value of PCMEpsilonModel.
331 !%End
332 call parse_variable(namespace, 'PCMTDLevel', pcm_td_eq, pcm%tdlevel)
333 call messages_print_var_value("PCMTDLevel", pcm%tdlevel, namespace=namespace)
334
335 if (pcm%tdlevel /= pcm_td_eq .and. (.not. pcm%run_pcm)) then
336 call messages_write('Sorry, you have set PCMTDLevel /= eq, but PCMCalculation = no.')
337 call messages_new_line()
338 call messages_write('To spare you some time, Octopus will proceed as if PCMCalculation = yes.')
339 call messages_warning(namespace=namespace)
340 end if
341
342 !%Variable PCMStaticEpsilon
343 !%Type float
344 !%Default 1.0
345 !%Section Hamiltonian::PCM
346 !%Description
347 !% Static dielectric constant of the solvent (<math>\varepsilon_0</math>). 1.0 indicates gas phase.
348 !%End
349 call parse_variable(namespace, 'PCMStaticEpsilon', m_one, pcm%epsilon_0)
350 call messages_print_var_value("PCMStaticEpsilon", pcm%epsilon_0, namespace=namespace)
351
352 !%Variable PCMDynamicEpsilon
353 !%Type float
354 !%Default PCMStaticEpsilon
355 !%Section Hamiltonian::PCM
356 !%Description
357 !% High-frequency dielectric constant of the solvent (<math>\varepsilon_d</math>).
358 !% <math>\varepsilon_d=\varepsilon_0</math> indicate equilibrium with solvent.
359 !%End
360 call parse_variable(namespace, 'PCMDynamicEpsilon', pcm%epsilon_0, pcm%epsilon_infty)
361 call messages_print_var_value("PCMDynamicEpsilon", pcm%epsilon_infty, namespace=namespace)
362
363 !%Variable PCMEpsilonModel
364 !%Type integer
365 !%Default pcm_debye
366 !%Section Hamiltonian::PCM
367 !%Description
368 !% Define the dielectric function model.
369 !%Option pcm_debye 1
370 !% Debye model: <math>\varepsilon(\omega)=\varepsilon_d+\frac{\varepsilon_0-\varepsilon_d}{1-i\omega\tau}</math>
371 !%Option pcm_drude 2
372 !% Drude-Lorentz model: <math>\varepsilon(\omega)=1+\frac{A}{\omega_0^2-\omega^2+i\gamma\omega}</math>
373 !%End
374 call parse_variable(namespace, 'PCMEpsilonModel', pcm_debye_model, pcm%which_eps)
375 call messages_print_var_value("PCMEpsilonModel", pcm%which_eps, namespace=namespace)
376 if (.not. varinfo_valid_option('PCMEpsilonModel', pcm%which_eps)) call messages_input_error(namespace, 'PCMEpsilonModel')
377
378 if (pcm%tdlevel == pcm_td_eom .and. pcm%which_eps == pcm_drude_model) then
379 call messages_experimental("Drude-Lorentz EOM-PCM is experimental", namespace=namespace)
380 end if
381
382 if (pcm%which_eps /= pcm_debye_model .and. pcm%which_eps /= pcm_drude_model) then
383 call messages_write('Sorry, only Debye or Drude-Lorentz dielectric models are available.')
384 call messages_new_line()
385 call messages_write('To spare you some time, Octopus will proceed with the default choice (Debye).')
386 call messages_new_line()
387 call messages_write('You may change PCMEpsilonModel value for a Drude-Lorentz run.')
388 call messages_warning(namespace=namespace)
389 end if
390
391 if (pcm%tdlevel /= pcm_td_eq .and. pcm%which_eps == pcm_debye_model .and. is_close(pcm%epsilon_0, pcm%epsilon_infty)) then
392 call messages_write('Sorry, inertial/dynamic polarization splitting scheme for TD-PCM')
393 call messages_write('or Debye equation-of-motion TD-PCM')
394 call messages_new_line()
395 call messages_write('require both static and dynamic dielectric constants,')
396 call messages_write('and they must be different.')
397 call messages_new_line()
398 call messages_write('Octopus will run using TD-PCM version in equilibrium')
399 call messages_write('equilibrium with solvent at each time.')
400 call messages_warning(namespace=namespace)
401 pcm%tdlevel = pcm_td_eq
402 end if
403
404 !%Variable PCMEoMInitialCharges
405 !%Type integer
406 !%Default 0
407 !%Section Hamiltonian::PCM
408 !%Description
409 !% If =0 the propagation of the solvent polarization charges starts from internally generated initial charges
410 !% in equilibrium with the initial potential.
411 !% For Debye EOM-PCM, if >0 the propagation of the solvent polarization charges starts from initial charges from input file.
412 !% if =1, initial pol. charges due to solute electrons are read from input file.
413 !% else if =2, initial pol. charges due to external potential are read from input file.
414 !% else if =3, initial pol. charges due to solute electrons and external potential are read from input file.
415 !% Files should be located in pcm directory and are called ASC_e.dat and ASC_ext.dat, respectively.
416 !% The latter files are generated after any PCM run and contain the last values of the polarization charges.
417 !%End
418 call parse_variable(namespace, 'PCMEoMInitialCharges', 0, pcm%initial_asc)
419 call messages_print_var_value("PCMEoMInitialCharges", pcm%initial_asc, namespace=namespace)
420
421 if (pcm%initial_asc /= 0) then
422 call messages_experimental("The use of external initialization")
423 call messages_experimental("for the EOM-PCM charges is experimental", namespace=namespace)
424 if ((pcm%tdlevel /= pcm_td_eom .or. (pcm%tdlevel == pcm_td_eom .and. pcm%which_eps /= pcm_debye_model))) then
425 call messages_write('Sorry, initial polarization charges can only be read')
426 call messages_write('from input file for a Debye EOM-PCM run.')
427 call messages_new_line()
428 call messages_write('To spare you some time,')
429 call messages_write('Octopus will proceed as if PCMEoMInitialCharges = 0.')
430 call messages_warning(namespace=namespace)
431 pcm%initial_asc = 0
432 end if
433 end if
434
436 pcm%deb%eps_0 = pcm%epsilon_0
437 pcm%deb%eps_d = pcm%epsilon_infty
438
440 call parse_variable(namespace, 'TDTimeStep', m_zero, pcm%dt, unit = units_inp%time)
441
442 !%Variable PCMDebyeRelaxTime
443 !%Type float
444 !%Default 0.0
445 !%Section Hamiltonian::PCM
446 !%Description
447 !% Relaxation time of the solvent within Debye model (<math>\tau</math>). Recall Debye dieletric function:
448 !% <math>\varepsilon(\omega)=\varepsilon_d+\frac{\varepsilon_0-\varepsilon_d}{1-i\omega\tau}</math>
449 !%End
450 call parse_variable(namespace, 'PCMDebyeRelaxTime', m_zero, pcm%deb%tau)
451 call messages_print_var_value("PCMDebyeRelaxTime", pcm%deb%tau, namespace=namespace)
452
453 if (pcm%tdlevel == pcm_td_eom .and. pcm%which_eps == pcm_debye_model .and. &
454 (abs(pcm%deb%tau) <= m_epsilon .or. is_close(pcm%deb%eps_0, pcm%deb%eps_d))) then
455 call messages_write('Sorry, you have set PCMTDLevel = eom,')
456 call messages_write('but you have not included all required Debye model parameters.')
457 call messages_new_line()
458 call messages_write('You need PCMEpsilonStatic, PCMEpsilonDynamic')
459 call messages_write('and PCMDebyeRelaxTime for an EOM TD-PCM run.')
460 call messages_new_line()
461 call messages_write('Octopus will run using TD-PCM version in equilibrium')
462 call messages_write('equilibrium with solvent at each time.')
463 call messages_warning(namespace=namespace)
464 pcm%tdlevel = pcm_td_eq
465 end if
466
467 if (is_close(pcm%epsilon_0, m_one)) then
468 if (pcm%tdlevel == pcm_td_eom .and. pcm%which_eps == pcm_drude_model) then
469 message(1) = "PCMEpsilonStatic = 1 is incompatible with a Drude-Lorentz EOM-PCM run."
470 call messages_fatal(1, namespace=namespace)
471 end if
472 pcm%drl%w0 = m_zero
473 else
474 !%Variable PCMDrudeLOmega
475 !%Type float
476 !%Default <math>\sqrt{1/(\varepsilon_0-1)}</math>
477 !%Section Hamiltonian::PCM
478 !%Description
479 !% Resonance frequency of the solvent within Drude-Lorentz model (<math>\omega_0</math>).
480 !% Recall Drude-Lorentz dielectric function: <math>\varepsilon(\omega)=1+\frac{A}{\omega_0^2-\omega^2+i\gamma\omega}</math>
481 !% Default values of <math>\omega_0</math> guarantee to recover static dielectric constant.
482 !%End
483 call parse_variable(namespace, 'PCMDrudeLOmega', sqrt(m_one/(pcm%epsilon_0 - m_one)), pcm%drl%w0)
484 call messages_print_var_value("PCMDrudeLOmega", pcm%drl%w0, namespace=namespace)
485 end if
486
487 if (pcm%tdlevel == pcm_td_eom .and. pcm%which_eps == pcm_drude_model .and. abs(pcm%drl%w0) <= m_epsilon) then
488 call messages_write('Sorry, you have set PCMDrudeLOmega =')
489 call messages_write('but this is incompatible with a Drude-Lorentz EOM-PCM run.')
490 call messages_new_line()
491 if (.not. is_close(pcm%epsilon_0, m_one)) then
492 call messages_write('Octopus will run using the default value of PCMDrudeLOmega.')
493 call messages_warning(namespace=namespace)
494 pcm%drl%w0 = sqrt(m_one/(pcm%epsilon_0 - m_one))
495 else
496 message(1) = "PCMEpsilonStatic = 1 is incompatible with a Drude-Lorentz EOM-PCM run."
497 call messages_fatal(1, namespace=namespace)
498 end if
499 end if
500
501 !%Variable PCMDrudeLDamping
502 !%Type float
503 !%Default 0.0
504 !%Section Hamiltonian::PCM
505 !%Description
506 !% Damping factor of the solvent charges oscillations within Drude-Lorentz model (<math>\gamma</math>).
507 !% Recall Drude-Lorentz dielectric function: <math>\varepsilon(\omega)=1+\frac{A}{\omega_0^2-\omega^2+i\gamma\omega}</math>
508 !%End
509 call parse_variable(namespace, 'PCMDrudeLDamping', m_zero, pcm%drl%gm)
510 call messages_print_var_value("PCMDrudeLDamping", pcm%drl%gm, namespace=namespace)
511
512
513 pcm%drl%aa = (pcm%epsilon_0 - m_one)*pcm%drl%w0**2
514
515 !%Variable PCMLocalField
516 !%Type logical
517 !%Default no
518 !%Section Hamiltonian::PCM
519 !%Description
520 !% This variable is a flag for including local field effects when an external field is applied. The total field interacting with
521 !% the molecule (also known as cavity field) is not the bare field in the solvent (the so-called Maxwell field), but it also
522 !% include a contribution due to the polarization of the solvent. The latter is calculated here within the PCM framework.
523 !% See [G. Gil, et al., J. Chem. Theory Comput., 2019, 15 (4), pp 2306–2319].
524 !%End
525 call parse_variable(namespace, 'PCMLocalField', .false., pcm%localf)
526 call messages_print_var_value("PCMLocalField", pcm%localf, namespace=namespace)
527
528 if (pcm%localf .and. ((.not. external_potentials_present) .and. (.not. pcm%kick_is_present))) then
529 message(1) = "Sorry, you have set PCMLocalField = yes, but you have not included any external potentials."
530 call messages_fatal(1, namespace=namespace)
531 end if
532
533 !%Variable PCMSolute
534 !%Type logical
535 !%Default yes
536 !%Section Hamiltonian::PCM
537 !%Description
538 !% This variable is a flag for including polarization effects of the solvent due to the solute.
539 !% (Useful for analysis) When external fields are applied, turning off the solvent-molecule interaction (PCMSolute=no) and
540 !% activating the solvent polarization due to the applied field (PCMLocalField=yes) allows to include only local field effects.
541 !%End
542 call parse_variable(namespace, 'PCMSolute', .true., pcm%solute)
543 call messages_print_var_value("PCMSolute", pcm%solute, namespace=namespace)
544
545 if (pcm%run_pcm .and. (.not. pcm%solute)) then
546 call messages_write('N.B. This PCM run do not consider the polarization effects due to the solute.')
547 call messages_warning(namespace=namespace)
548 if (.not. pcm%localf) then
549 message(1) = "You have activated a PCM run without polarization effects. Octopus will halt."
550 call messages_fatal(1, namespace=namespace)
551 end if
552 end if
553
554 !%Variable PCMKick
555 !%Type logical
556 !%Default no
557 !%Section Hamiltonian::PCM
558 !%Description
559 !% This variable controls the effect the kick has on the polarization of the solvent.
560 !% If .true. ONLY the FAST degrees-of-freedom of the solvent follow the kick. The potential due to polarization charges behaves
561 !% as another kick, i.e., it is a delta-perturbation.
562 !% If .false. ALL degrees-of-freedom of the solvent follow the kick. The potential due to polarization charges evolves
563 !% following an equation of motion. When Debye dielectric model is used, just a part of the potential behaves as another kick.
564 !%End
565 call parse_variable(namespace, 'PCMKick', .false., pcm%kick_like)
566 call messages_print_var_value("PCMKick", pcm%kick_like, namespace=namespace)
567
568 if (pcm%kick_like .and. (.not. pcm%run_pcm)) then
569 message(1) = "PCMKick option can only be activated when PCMCalculation = yes. Octopus will halt."
570 call messages_fatal(1, namespace=namespace)
571 end if
572
573 if (pcm%kick_like .and. (.not. pcm%localf)) then
574 message(1) = "PCMKick option can only be activated when a PCMLocalField = yes. Octopus will halt."
575 call messages_fatal(1, namespace=namespace)
576 end if
577
578 if (pcm%kick_like .and. (.not. pcm%kick_is_present)) then
579 message(1) = "Sorry, you have set PCMKick = yes, but you have not included any kick."
580 call messages_fatal(1, namespace=namespace)
581 end if
582
583 if (pcm%kick_is_present .and. pcm%run_pcm .and. (.not. pcm%localf)) then
584 message(1) = "You have set up a PCM calculation with a kick without local field effects."
585 message(2) = "Please, reconsider if you want the kick to be relevant for the PCM run."
586 call messages_warning(2, namespace=namespace)
587 end if
588
589 !%Variable PCMUpdateIter
590 !%Type integer
591 !%Default 1
592 !%Section Hamiltonian::PCM
593 !%Description
594 !% Defines how often the PCM potential is updated during time propagation.
595 !%End
596 call parse_variable(namespace, 'PCMUpdateIter', 1, pcm%update_iter)
597 call messages_print_var_value("PCMUpdateIter", pcm%update_iter, namespace=namespace)
598
599 !%Variable PCMGamessBenchmark
600 !%Type logical
601 !%Default .false.
602 !%Section Hamiltonian::PCM
603 !%Description
604 !% If PCMGamessBenchmark is set to "yes", the pcm_matrix is also written in a Gamess format.
605 !% for benchamarking purposes.
606 !%End
607 call parse_variable(namespace, 'PCMGamessBenchmark', .false., gamess_benchmark)
608
609 !%Variable PCMRenormCharges
610 !%Type logical
611 !%Default .false.
612 !%Section Hamiltonian::PCM
613 !%Description
614 !% If .true. renormalization of the polarization charges is performed to enforce fulfillment
615 !% of the Gauss law, <math>\sum_i q_i^{e/n} = -[(\epsilon-1)/\epsilon] Q_M^{e/n}</math> where
616 !% <math>q_i^{e/n}</math> are the polarization charges induced by the electrons/nuclei of the molecule
617 !% and <math>Q_M^{e/n}</math> is the nominal electronic/nuclear charge of the system. This can be needed
618 !% to treat molecules in weakly polar solvents.
619 !%End
620 call parse_variable(namespace, 'PCMRenormCharges', .false., pcm%renorm_charges)
621
622 !%Variable PCMQtotTol
623 !%Type float
624 !%Default 0.5
625 !%Section Hamiltonian::PCM
626 !%Description
627 !% If <tt>PCMRenormCharges=.true.</tt> and <math>\delta Q = |[\sum_i q_i| - ((\epsilon-1)/\epsilon)*|Q_M]|>PCMQtotTol</math>
628 !% the polarization charges will be normalized as
629 !% <math>q_i^\prime=q_i + signfunction(e, n, \delta Q) (q_i/q_{tot})*\delta Q</math>
630 !% with <math>q_{tot} = \sum_i q_i</math>. For values of <math>\delta Q > 0.5</math>
631 !% (printed by the code in the file pcm/pcm_info.out) even, if polarization charges are renormalized,
632 !% the calculated results might be inaccurate or erroneous.
633 !%End
634 call parse_variable(namespace, 'PCMQtotTol', m_half, pcm%q_tot_tol)
635
636 if (pcm%renorm_charges) then
637 message(1) = "Info: Polarization charges will be renormalized"
638 message(2) = " if |Q_tot_PCM - Q_M| > PCMQtotTol"
639 call messages_info(2, namespace=namespace)
640 end if
641
642 !%Variable PCMSmearingFactor
643 !%Type float
644 !%Default 1.0
645 !%Section Hamiltonian::PCM
646 !%Description
647 !% Parameter used to control the width (area of each tessera) of the Gaussians used to distribute
648 !% the polarization charges on each tessera (arXiv:1507.05471). If set to zero, the solvent
649 !% reaction potential in real-space is defined by using point charges.
650 !%End
651 call parse_variable(namespace, 'PCMSmearingFactor', m_one, pcm%gaussian_width)
652 call messages_print_var_value("PCMSmearingFactor", pcm%gaussian_width, namespace=namespace)
653
654 if (abs(pcm%gaussian_width) <= m_epsilon) then
655 message(1) = "Info: PCM potential will be defined in terms of polarization point charges"
656 call messages_info(1, namespace=namespace)
657 else
658 message(1) = "Info: PCM potential is regularized to avoid Coulomb singularity"
659 call messages_info(1, namespace=namespace)
660 end if
661
662 call io_mkdir('pcm', namespace)
663
664 !%Variable PCMCavity
665 !%Type string
666 !%Section Hamiltonian::PCM
667 !%Description
668 !% Name of the file containing the geometry of the cavity hosting the solute molecule.
669 !% The data must be in atomic units and the file must contain the following information sequentially:
670 !% T < Number of tesserae
671 !% s_x(1:T) < coordinates x of the tesserae
672 !% s_y(1:T) < coordinates y of the tesserae
673 !% s_z(1:T) < coordinates z of the tesserae
674 !% A(1:T) < areas of the tesserae
675 !% R_sph(1:T) < Radii of the spheres to which the tesserae belong
676 !% normal(1:T,1:3) < Outgoing unitary vectors at the tesserae surfaces
677 !%End
678 call parse_variable(namespace, 'PCMCavity', '', pcm%input_cavity)
679
680 if (pcm%input_cavity == '') then
681
682 !%Variable PCMSpheresOnH
683 !%Type logical
684 !%Default no
685 !%Section Hamiltonian::PCM
686 !%Description
687 !% If true, spheres centered at the Hydrogens atoms are included to build the solute cavity surface.
688 !%End
689 call parse_variable(namespace, 'PCMSpheresOnH', .false., add_spheres_h)
690
691 pcm%n_spheres = 0
692 band = .false.
693 do ia = 1, ions%natoms
694 if ((.not. add_spheres_h) .and. ions%atom(ia)%label == 'H') cycle
695 pcm%n_spheres = pcm%n_spheres + 1 !counting the number of species different from Hydrogen
696 end do
697
698 safe_allocate(pcm%spheres(1:pcm%n_spheres))
699 pcm%spheres(:)%x = m_zero
700 pcm%spheres(:)%y = m_zero
701 pcm%spheres(:)%z = m_zero
702 pcm%spheres(:)%r = m_zero
703
704 pcm%n_spheres = 0
705 do ia = 1, ions%natoms
706 if ((.not. add_spheres_h) .and. ions%atom(ia)%label == 'H') cycle
707 pcm%n_spheres = pcm%n_spheres + 1
708
710 pcm%spheres(pcm%n_spheres)%x = ions%pos(1, ia)
711 pcm%spheres(pcm%n_spheres)%y = ions%pos(2, ia)
712 pcm%spheres(pcm%n_spheres)%z = ions%pos(3, ia)
713
714 vdw_radius = pcm_get_vdw_radius(ions%atom(ia)%species, pcm_vdw_type, namespace)
715 pcm%spheres(pcm%n_spheres)%r = vdw_radius*pcm%scale_r
716 end do
717
718 if (mpi_world%is_root()) then
719 pcm%info_unit = io_open(pcm_dir//'pcm_info.out', pcm%namespace, action='write')
720
721 write(pcm%info_unit, '(A35)') '# Configuration: Molecule + Solvent'
722 write(pcm%info_unit, '(A35)') '# ---------------------------------'
723 write(pcm%info_unit, '(A21,F12.3)') '# Epsilon(Solvent) = ', pcm%epsilon_0
724 write(pcm%info_unit, '(A1)')'#'
725 write(pcm%info_unit, '(A35,I4)') '# Number of interlocking spheres = ', pcm%n_spheres
726 write(pcm%info_unit, '(A1)')'#'
727
728 write(pcm%info_unit, '(A8,3X,A7,8X,A26,20X,A10)') '# SPHERE', 'ELEMENT', 'CENTER (X,Y,Z) (A)', 'RADIUS (A)'
729 write(pcm%info_unit, '(A8,3X,A7,4X,A43,7X,A10)') '# ------', '-------', &
730 '-------------------------------------------', '----------'
731 end if
732
733 pcm%n_spheres = 0
734 do ia = 1, ions%natoms
735 if ((.not. add_spheres_h) .and. ions%atom(ia)%label == 'H') cycle
736 pcm%n_spheres = pcm%n_spheres + 1
737 if (mpi_world%is_root()) then
738 write(pcm%info_unit,'(A1,2X,I3,7X,A2,3X,F14.8,2X,F14.8,2X,F14.8,4X,F14.8)')'#', pcm%n_spheres, &
739 ions%atom(ia)%label, &
740 ions%pos(1, ia)*p_a_b, &
741 ions%pos(2, ia)*p_a_b, &
742 ions%pos(3, ia)*p_a_b, &
743 pcm%spheres(pcm%n_spheres)%r*p_a_b
744 end if
745 end do
746
747 !%Variable PCMTessSubdivider
748 !%Type integer
749 !%Default 1
750 !%Section Hamiltonian::PCM
751 !%Description
752 !% Allows to subdivide further each tessera refining the discretization of the cavity tesselation.
753 !% Can take only two values, 1 or 4. 1 corresponds to 60 tesserae per sphere, while 4 corresponds to 240 tesserae per sphere.
754 !%End
755 call parse_variable(namespace, 'PCMTessSubdivider', 1, subdivider)
756
757 safe_allocate(dum2(1:subdivider*n_tess_sphere*pcm%n_spheres))
758
759 !%Variable PCMTessMinDistance
760 !%Type float
761 !%Default 0.1
762 !%Section Hamiltonian::PCM
763 !%Description
764 !% Minimum distance between tesserae.
765 !% Any two tesserae having smaller distance in the starting tesselation will be merged together.
766 !%End
767 call parse_variable(namespace, 'PCMTessMinDistance', 0.1_real64, min_distance)
768 call messages_print_var_value("PCMTessMinDistance", min_distance, namespace=namespace)
769
771 call cav_gen(subdivider, min_distance, pcm%n_spheres, pcm%spheres, pcm%n_tesserae, dum2, pcm%info_unit)
772
773 safe_allocate(pcm%tess(1:pcm%n_tesserae))
774
775 do ia=1, pcm%n_tesserae
776 pcm%tess(ia)%point = m_zero
777 pcm%tess(ia)%area = m_zero
778 pcm%tess(ia)%r_sphere = m_zero
779 pcm%tess(ia)%normal = m_zero
780 end do
781
782 pcm%tess = dum2(1:pcm%n_tesserae)
783
784 safe_deallocate_a(dum2)
785
786 message(1) = "Info: van der Waals surface has been calculated"
787 call messages_info(1, namespace=namespace)
788
789 else
790
792 iunit = io_open(trim(pcm%input_cavity), pcm%namespace, action='read', status='old')
793 read(iunit,*) pcm%n_tesserae
794
795 if (pcm%n_tesserae > mxts) then
796 write(message(1),'(a,I5,a,I5)') "total number of tesserae", pcm%n_tesserae, ">", mxts
797 call messages_warning(1, namespace=namespace)
798 end if
799
800 safe_allocate(pcm%tess(1:pcm%n_tesserae))
801
802 do ia = 1, pcm%n_tesserae
803 pcm%tess(ia)%point = m_zero
804 pcm%tess(ia)%area = m_zero
805 pcm%tess(ia)%r_sphere = m_zero
806 pcm%tess(ia)%normal = m_zero
807 end do
808
809 do ia = 1, pcm%n_tesserae
810 read(iunit,*) pcm%tess(ia)%point(1)
811 end do
812
813 do ia = 1, pcm%n_tesserae
814 read(iunit,*) pcm%tess(ia)%point(2)
815 end do
816
817 do ia = 1, pcm%n_tesserae
818 read(iunit,*) pcm%tess(ia)%point(3)
819 end do
820
821 do ia = 1, pcm%n_tesserae
822 read(iunit,*) pcm%tess(ia)%area
823 end do
824
825 do ia = 1, pcm%n_tesserae
826 read(iunit,*) pcm%tess(ia)%r_sphere
827 end do
828
829 do ia = 1, pcm%n_tesserae
830 read(iunit,*) pcm%tess(ia)%normal
831 end do
832
833 call io_close(iunit)
834 message(1) = "Info: van der Waals surface has been read from " // trim(pcm%input_cavity)
835 call messages_info(1, namespace=namespace)
836 end if
837
838 if (mpi_world%is_root()) then
839 cav_unit_test = io_open(pcm_dir//'cavity_mol.xyz', pcm%namespace, action='write')
840
841 write (cav_unit_test,'(2X,I4)') pcm%n_tesserae + ions%natoms
842 write (cav_unit_test,'(2X)')
843
844 do ia = 1, pcm%n_tesserae
845 write(cav_unit_test,'(2X,A2,3X,4f15.8,3X,4f15.8,3X,4f15.8)') 'H', pcm%tess(ia)%point*p_a_b
846 end do
847
848 do ia = 1, ions%natoms
849 write(cav_unit_test,'(2X,A2,3X,4f15.8,3X,4f15.8,3X,4f15.8)') ions%atom(ia)%label, &
850 ions%pos(:, ia)*p_a_b
851 end do
852
853 call io_close(cav_unit_test)
854
855 write(pcm%info_unit,'(A1)')'#'
856 if (pcm%localf) then
857 write(pcm%info_unit,'(A1,4X,A4,14X,A4,21X,A4,21X,A4,21X,A4,21X,A7,18X,A7,18X,A8,17X,A5,20X,A8,17X,A5,20X,A8,17X,A5)') &
858 '#','iter', 'E_ee', 'E_en', 'E_nn', 'E_ne', 'E_e_ext', 'E_n_ext', 'E_M-solv', &
859 'Q_pol^e', 'deltaQ^e', 'Q_pol^n', 'deltaQ^n', 'Q_pol^ext'
860 else
861 write(pcm%info_unit,'(A1,4X,A4,14X,A4,21X,A4,21X,A4,21X,A4,21X,A8,17X,A5,20X,A8,17X,A5,20X, A8)') &
862 '#','iter', 'E_ee', 'E_en', 'E_nn', 'E_ne', 'E_M-solv', 'Q_pol^e', 'deltaQ^e', 'Q_pol^n', 'deltaQ^n'
863 end if
864 end if
865 pcm%counter = 0
866
868 if (gamess_benchmark .and. mpi_world%is_root()) then
869 cav_gamess_unit = io_open(pcm_dir//'geom_cavity_gamess.out', pcm%namespace, action='write')
870
871 write(cav_gamess_unit,*) pcm%n_tesserae
872
873 do ia = 1, pcm%n_tesserae
874 write(cav_gamess_unit,*) pcm%tess(ia)%point(1)
875 end do
876
877 do ia = 1, pcm%n_tesserae
878 write(cav_gamess_unit,*) pcm%tess(ia)%point(2)
879 end do
880
881 do ia = 1, pcm%n_tesserae
882 write(cav_gamess_unit,*) pcm%tess(ia)%point(3)
883 end do
884
885 do ia = 1, pcm%n_tesserae
886 write(cav_gamess_unit,*) pcm%tess(ia)%area
887 end do
888
889 do ia = 1, pcm%n_tesserae
890 write(cav_gamess_unit,*) pcm%tess(ia)%r_sphere
891 end do
892
893 do ia = 1, pcm%n_tesserae
894 write(cav_gamess_unit,*) pcm%tess(ia)%normal
895 end do
896
897 call io_close(cav_gamess_unit)
898 end if
899
901 if (gamess_benchmark) then
902 safe_allocate(mat_gamess(1:pcm%n_tesserae, 1:pcm%n_tesserae))
904 end if
905
906 if (.not. is_close(pcm%epsilon_infty, pcm%epsilon_0)) then
907
908 safe_allocate(pcm%matrix_d(1:pcm%n_tesserae, 1:pcm%n_tesserae))
909 pcm%matrix_d = m_zero
910
911 call pcm_matrix(pcm%epsilon_infty, pcm%tess, pcm%n_tesserae, pcm%matrix_d, substrate=substrate%iset_dynamic())
912
913 if (gamess_benchmark .and. mpi_world%is_root()) then
914 pcmmat_gamess_unit = io_open(pcm_dir//'pcm_matrix_gamess_dyn.out', pcm%namespace, action='write')
915
916 do jtess = 1, pcm%n_tesserae
917 do itess = 1, pcm%n_tesserae
918 write(pcmmat_gamess_unit,*) mat_gamess(itess,jtess)
919 end do
920 end do
921
922 call io_close(pcmmat_gamess_unit)
924 end if
925
926 if (pcm%localf) then
927
928 safe_allocate(pcm%matrix_lf_d(1:pcm%n_tesserae, 1:pcm%n_tesserae))
929 pcm%matrix_lf_d = m_zero
930
931 call pcm_matrix(pcm%epsilon_infty, pcm%tess, pcm%n_tesserae, pcm%matrix_lf_d, .true., substrate=substrate%iset_dynamic())
932
933 if (mpi_world%is_root()) then
934 ! only to benchmark
935 pcmmat_unit = io_open(pcm_dir//'pcm_matrix_dynamic_lf.out', pcm%namespace, action='write')
936 do jtess = 1, pcm%n_tesserae
937 do itess = 1, pcm%n_tesserae
938 write(pcmmat_unit,*) pcm%matrix_lf_d(itess,jtess)
939 end do
940 end do
941 call io_close(pcmmat_unit)
942 end if
943
944 end if
945
946 end if
947
948 safe_allocate(pcm%matrix(1:pcm%n_tesserae, 1:pcm%n_tesserae))
949 pcm%matrix = m_zero
950
951 call pcm_matrix(pcm%epsilon_0, pcm%tess, pcm%n_tesserae, pcm%matrix, substrate=substrate%iset_static())
952
953 if (mpi_world%is_root()) then
954 pcmmat_unit = io_open(pcm_dir//'pcm_matrix.out', pcm%namespace, action='write')
955 if (gamess_benchmark) pcmmat_gamess_unit = io_open(pcm_dir//'pcm_matrix_gamess.out', &
956 pcm%namespace, action='write')
957
958 do jtess = 1, pcm%n_tesserae
959 do itess = 1, pcm%n_tesserae
960 write(pcmmat_unit,*) pcm%matrix(itess,jtess)
961 if (gamess_benchmark) write(pcmmat_gamess_unit,*) mat_gamess(itess,jtess)
962 end do
963 end do
964 call io_close(pcmmat_unit)
965 if (gamess_benchmark) call io_close(pcmmat_gamess_unit)
966 end if
967 call mpi_world%barrier()
968
969 if (gamess_benchmark) then
970 safe_deallocate_a(mat_gamess)
971 end if
972
973 if (pcm%localf) then
974
975 safe_allocate(pcm%matrix_lf(1:pcm%n_tesserae, 1:pcm%n_tesserae))
976 pcm%matrix_lf = m_zero
977
978 call pcm_matrix(pcm%epsilon_0, pcm%tess, pcm%n_tesserae, pcm%matrix_lf, .true., substrate=substrate%iset_static())
979
980 if (mpi_world%is_root()) then
981 ! only to benchmark
982 pcmmat_unit = io_open(pcm_dir//'pcm_matrix_static_lf.out', pcm%namespace, action='write')
983 do jtess = 1, pcm%n_tesserae
984 do itess = 1, pcm%n_tesserae
985 write(pcmmat_unit,*) pcm%matrix_lf(itess,jtess)
986 end do
987 end do
988 call io_close(pcmmat_unit)
989 end if
990
991 end if
992
993 message(1) = "Info: PCM response matrices has been evaluated"
994 call messages_info(1, namespace=namespace)
995
996 call layer_pcm_substrate_end(substrate)
997
998 !%Variable PCMCalcMethod
999 !%Type integer
1000 !%Default pcm_direct
1001 !%Section Hamiltonian::PCM
1002 !%Description
1003 !% Defines the method to be used to obtain the PCM potential.
1004 !%Option pcm_direct 1
1005 !% Direct sum of the potential generated by the polarization charges regularized
1006 !% with a Gaussian smearing [A. Delgado, et al., J Chem Phys 143, 144111 (2015)].
1007 !%Option pcm_poisson 2
1008 !% Solving the Poisson equation for the polarization charge density.
1009 !%End
1010 call parse_variable(namespace, 'PCMCalcMethod', pcm_calc_direct, pcm%calc_method)
1011 call messages_print_var_option("PCMCalcMethod", pcm%calc_method, namespace=namespace)
1012
1013
1014 if (pcm%calc_method == pcm_calc_poisson) then
1015
1016 max_area = m_epsilon
1017 do ia = 1, pcm%n_tesserae
1018 if (pcm%tess(ia)%area > max_area) max_area = pcm%tess(ia)%area
1019 end do
1020
1021 !default is as many neighbor to contain 1 gaussian width
1022 default_nn = int(max_area*pcm%gaussian_width/minval(grid%spacing(1:pcm%space%dim)))
1023
1024 changed_default_nn = .false.
1025
1026 do ii = default_nn, 1, -1
1027 pcm%tess_nn = ii
1028 if (pcm_nn_in_mesh(pcm,grid)) then
1029 exit
1030 else
1031 changed_default_nn = .true.
1032 end if
1033 end do
1034 if (changed_default_nn) then
1035 call messages_write('PCM nearest neighbors have been reduced from ')
1036 call messages_write(default_nn)
1037 call messages_write(' to ')
1038 call messages_write(pcm%tess_nn)
1039 call messages_new_line()
1040 call messages_write('in order to fit them into the mesh.')
1041 call messages_new_line()
1042 call messages_write('This may produce unexpected results. ')
1043 call messages_warning(namespace=namespace)
1044 end if
1045 default_nn = pcm%tess_nn
1046
1047 !%Variable PCMChargeSmearNN
1048 !%Type integer
1049 !%Default 2 * max_area * PCMSmearingFactor
1050 !%Section Hamiltonian::PCM
1051 !%Description
1052 !% Defines the number of nearest neighbor mesh-points to be taken around each
1053 !% cavity tessera in order to smear the charge when PCMCalcMethod = pcm_poisson.
1054 !% Setting PCMChargeSmearNN = 1 means first nearest neighbors, PCMChargeSmearNN = 2
1055 !% second nearest neighbors, and so on.
1056 !% The default value is such that the neighbor mesh contains points in a radius
1057 !% equal to the width used for the gaussian smearing.
1058 !%End
1059 call parse_variable(namespace, 'PCMChargeSmearNN', default_nn, pcm%tess_nn)
1060 call messages_print_var_value("PCMChargeSmearNN", pcm%tess_nn, namespace=namespace)
1061
1062 call pcm_poisson_sanity_check(pcm, grid)
1063
1064 end if
1065
1066 if (pcm%run_pcm) call messages_print_with_emphasis(namespace=namespace)
1067
1068 if (pcm%calc_method == pcm_calc_poisson) then
1069 safe_allocate(pcm%rho_n(1:grid%np_part))
1070 safe_allocate(pcm%rho_e(1:grid%np_part))
1071 if (pcm%localf) then
1072 safe_allocate(pcm%rho_ext(1:grid%np_part))
1073 if (pcm%kick_is_present) then
1074 safe_allocate(pcm%rho_kick(1:grid%np_part))
1075 end if
1076 end if
1077 end if
1078
1079
1080 safe_allocate(pcm%v_n(1:pcm%n_tesserae))
1081 safe_allocate(pcm%q_n(1:pcm%n_tesserae))
1082 safe_allocate(pcm%v_n_rs(1:grid%np))
1083 pcm%v_n = m_zero
1084 pcm%q_n = m_zero
1085 pcm%v_n_rs = m_zero
1086
1087 safe_allocate(pcm%v_e(1:pcm%n_tesserae))
1088 safe_allocate(pcm%q_e(1:pcm%n_tesserae))
1089 safe_allocate(pcm%v_e_rs(1:grid%np))
1090 pcm%v_e = m_zero
1091 pcm%q_e = m_zero
1092 pcm%v_e_rs = m_zero
1093
1094 safe_allocate(pcm%q_e_in(1:pcm%n_tesserae))
1095 pcm%q_e_in = m_zero
1096
1097
1098 if (pcm%localf) then
1099 safe_allocate(pcm%v_ext(1:pcm%n_tesserae))
1100 safe_allocate(pcm%q_ext(1:pcm%n_tesserae))
1101 safe_allocate(pcm%v_ext_rs(1:grid%np))
1102 pcm%v_ext = m_zero
1103 pcm%q_ext = m_zero
1104 pcm%v_ext_rs = m_zero
1105
1106 safe_allocate(pcm%q_ext_in(1:pcm%n_tesserae))
1107 pcm%q_ext_in = m_zero
1108
1109 if (pcm%kick_is_present) then
1110 safe_allocate(pcm%v_kick(1:pcm%n_tesserae))
1111 safe_allocate(pcm%q_kick(1:pcm%n_tesserae))
1112 safe_allocate(pcm%v_kick_rs(1:grid%np))
1113 pcm%v_ext = m_zero
1114 pcm%q_ext = m_zero
1115 pcm%v_ext_rs = m_zero
1116 end if
1117
1118 end if
1119
1120 pcm%q_e_nominal = qtot
1121 pcm%q_n_nominal = val_charge
1122 pcm%deltaQ_e = m_zero
1123 pcm%deltaQ_n = m_zero
1124 pcm%qtot_e = m_zero
1125 pcm%qtot_n = m_zero
1126 pcm%qtot_ext = m_zero
1127
1128 pop_sub(pcm_init)
1129 end subroutine pcm_init
1130
1131 ! -----------------------------------------------------------------------------
1132 subroutine pcm_calc_pot_rs(pcm, mesh, psolver, ions, v_h, v_ext, kick, time_present, kick_time)
1133 type(pcm_t), intent(inout) :: pcm
1134 class(mesh_t), intent(in) :: mesh
1135 type(poisson_t), intent(in) :: psolver
1136 type(ions_t), optional, intent(in) :: ions
1137 real(real64), contiguous, optional, intent(in) :: v_h(:)
1138 real(real64), contiguous, optional, intent(in) :: v_ext(:)
1139 real(real64), optional, intent(in) :: kick(:)
1140 logical, optional, intent(in) :: time_present
1141 logical, optional, intent(in) :: kick_time
1142
1143 integer, save :: calc
1144
1145 logical, save :: input_asc_e
1146 logical, save :: input_asc_ext
1147
1148 ! for debuggin - it should be cleaned up
1149 !character*5 :: iteration
1150
1151 logical, save :: not_yet_called = .false.
1152 logical, save :: is_time_for_kick = .false.
1153 logical, save :: after_kick = .false.
1154
1155 logical, save :: td_calc_mode = .false.
1156
1157 integer, save :: asc_vs_t_unit_e
1158
1159 character(len=23), save :: asc_vs_t_unit_format
1160 character(len=16), save :: asc_vs_t_unit_format_tail
1161
1162 integer, save :: ia
1163
1164 push_sub(pcm_calc_pot_rs)
1165
1166 assert(present(v_h) .or. present(ions) .or. present(v_ext) .or. present(kick))
1167
1168 if (present(v_h)) calc = pcm_electrons
1169 if (present(ions)) calc = pcm_nuclei
1170 if (present(v_ext) .and. (.not. present(kick))) calc = pcm_external_potential
1171 if ((.not. present(v_ext)) .and. present(kick)) calc = pcm_kick
1172 if (present(v_ext) .and. present(kick)) calc = pcm_external_plus_kick
1173
1174 if (present(time_present)) then
1175 if (time_present) td_calc_mode = .true.
1176 end if
1177
1178 if (present(kick_time)) then
1179 is_time_for_kick = kick_time
1180 if (kick_time) after_kick = .true.
1181 end if
1182
1183 select case (pcm%initial_asc)
1184 case (1)
1185 input_asc_e = .true.
1186 input_asc_ext = .false.
1187 case (2)
1188 input_asc_e = .false.
1189 input_asc_ext = .true.
1190 case (3)
1191 input_asc_e = .true.
1192 input_asc_ext = .true.
1193 case default
1194 input_asc_e = .false.
1195 input_asc_ext = .false.
1196 end select
1197
1198 if (calc == pcm_nuclei) then
1199 call pcm_v_nuclei_cav(pcm%v_n, ions, pcm%tess, pcm%n_tesserae)
1200 call pcm_charges(pcm%q_n, pcm%qtot_n, pcm%v_n, pcm%matrix, pcm%n_tesserae, &
1201 pcm%q_n_nominal, pcm%epsilon_0, pcm%renorm_charges, pcm%q_tot_tol, pcm%deltaQ_n)
1202 if (pcm%calc_method == pcm_calc_poisson) then
1203 call pcm_charge_density(pcm, pcm%q_n, pcm%qtot_n, mesh, pcm%rho_n)
1204 end if
1205 call pcm_pot_rs(pcm, pcm%v_n_rs, pcm%q_n, pcm%rho_n, mesh, psolver)
1206 end if
1207
1208 if (calc == pcm_electrons) then
1209 call pcm_v_cav_li(pcm%v_e, v_h, pcm, mesh)
1210 if (td_calc_mode .and. .not. is_close(pcm%epsilon_infty, pcm%epsilon_0) .and. pcm%tdlevel /= pcm_td_eq) then
1211
1212 select case (pcm%tdlevel)
1213 case (pcm_td_eom)
1214 select case (pcm%which_eps)
1215 case (pcm_drude_model)
1216 call pcm_charges_propagation(pcm%q_e, pcm%v_e, pcm%dt, pcm%tess, input_asc_e, calc, &
1217 pcm_drude_model, pcm%namespace, this_drl = pcm%drl)
1218 case default
1219 call pcm_charges_propagation(pcm%q_e, pcm%v_e, pcm%dt, pcm%tess, input_asc_e, calc, &
1220 pcm_debye_model, pcm%namespace, this_deb = pcm%deb)
1221 end select
1222 if ((.not. pcm%localf) .and. not_yet_called) call pcm_eom_enough_initial(not_yet_called)
1223
1224 pcm%qtot_e = sum(pcm%q_e)
1225 case (pcm_td_neq)
1226 select case (pcm%iter)
1227 case (1)
1228
1231 call pcm_charges(pcm%q_e, pcm%qtot_e, pcm%v_e, pcm%matrix, pcm%n_tesserae, &
1232 pcm%q_e_nominal, pcm%epsilon_0, pcm%renorm_charges, pcm%q_tot_tol, pcm%deltaQ_e)
1233
1235 call pcm_charges(pcm%q_e_in, pcm%qtot_e_in, pcm%v_e, pcm%matrix_d, pcm%n_tesserae, &
1236 pcm%q_e_nominal, pcm%epsilon_infty, pcm%renorm_charges, pcm%q_tot_tol, pcm%deltaQ_e)
1237
1238 pcm%q_e_in = pcm%q_e - pcm%q_e_in
1239 pcm%qtot_e_in = pcm%qtot_e - pcm%qtot_e_in
1240 case default
1241
1242 call pcm_charges(pcm%q_e, pcm%qtot_e, pcm%v_e, pcm%matrix_d, pcm%n_tesserae, &
1243 pcm%q_e_nominal, pcm%epsilon_infty, pcm%renorm_charges, pcm%q_tot_tol, pcm%deltaQ_e)
1244
1245 pcm%q_e = pcm%q_e + pcm%q_e_in
1246 pcm%qtot_e = pcm%qtot_e + pcm%qtot_e_in
1247 end select
1248 end select
1249 else
1250
1251
1252 call pcm_charges(pcm%q_e, pcm%qtot_e, pcm%v_e, pcm%matrix, pcm%n_tesserae, &
1253 pcm%q_e_nominal, pcm%epsilon_0, pcm%renorm_charges, pcm%q_tot_tol, pcm%deltaQ_e)
1254
1255 end if
1256 if (pcm%calc_method == pcm_calc_poisson) then
1257 call pcm_charge_density(pcm, pcm%q_e, pcm%qtot_e, mesh, pcm%rho_e)
1258 end if
1259 call pcm_pot_rs(pcm, pcm%v_e_rs, pcm%q_e, pcm%rho_e, mesh, psolver)
1260 end if
1261
1262 if ((calc == pcm_external_plus_kick .or. calc == pcm_kick) .and. .not. pcm%kick_like) then
1263 pcm%q_ext = m_zero
1264 pcm%v_ext_rs = m_zero
1265 end if
1266
1267 if (calc == pcm_external_potential .or. calc == pcm_external_plus_kick) then
1268 call pcm_v_cav_li(pcm%v_ext, v_ext, pcm, mesh)
1269 if (td_calc_mode .and. .not. is_close(pcm%epsilon_infty, pcm%epsilon_0) .and. pcm%tdlevel /= pcm_td_eq) then
1270
1271 select case (pcm%tdlevel)
1272 case (pcm_td_eom)
1273 select case (pcm%which_eps)
1274 case (pcm_drude_model)
1275 call pcm_charges_propagation(pcm%q_ext, pcm%v_ext, pcm%dt, pcm%tess, input_asc_ext, calc, &
1276 pcm%which_eps, pcm%namespace, this_drl=pcm%drl)
1277 case default
1278 call pcm_charges_propagation(pcm%q_ext, pcm%v_ext, pcm%dt, pcm%tess, input_asc_ext, calc, &
1279 pcm%which_eps, pcm%namespace, this_deb=pcm%deb)
1280 end select
1281 if ((.not. pcm%kick_is_present) .and. not_yet_called) call pcm_eom_enough_initial(not_yet_called)
1282
1283 pcm%qtot_ext = sum(pcm%q_ext)
1284
1286 pcm%q_ext = pcm%q_ext + pcm%q_ext_in
1287 pcm%qtot_ext = pcm%qtot_ext + pcm%qtot_ext_in
1288 case (pcm_td_neq)
1290 call pcm_charges(pcm%q_ext, pcm%qtot_ext, pcm%v_ext, pcm%matrix_lf_d, pcm%n_tesserae)
1291
1292
1294 pcm%q_ext = pcm%q_ext + pcm%q_ext_in
1295 pcm%qtot_ext = pcm%qtot_ext + pcm%qtot_ext_in
1296 end select
1297 else
1298
1299
1302 call pcm_charges(pcm%q_ext, pcm%qtot_ext, pcm%v_ext, pcm%matrix_lf, pcm%n_tesserae)
1303
1304
1305 pcm%q_ext_in = pcm%q_ext
1306 pcm%qtot_ext_in = pcm%qtot_ext
1307 end if
1308 if (pcm%calc_method == pcm_calc_poisson) then
1309 call pcm_charge_density(pcm, pcm%q_ext, pcm%qtot_ext, mesh, pcm%rho_ext)
1310 end if
1311 call pcm_pot_rs(pcm, pcm%v_ext_rs, pcm%q_ext, pcm%rho_ext, mesh, psolver)
1312
1313 end if
1314
1315 if (calc == pcm_external_plus_kick .or. calc == pcm_kick) then
1316 pcm%q_kick = m_zero
1317 pcm%v_kick_rs = m_zero
1318 if (is_time_for_kick) then
1319 call pcm_v_cav_li(pcm%v_kick, kick, pcm, mesh)
1320 else
1321 pcm%v_kick = m_zero
1322 end if
1323 if (pcm%kick_like) then
1324 if (is_time_for_kick) then
1325
1326 if (.not. is_close(pcm%epsilon_infty, pcm%epsilon_0)) then
1327 call pcm_charges(pcm%q_kick, pcm%qtot_kick, pcm%v_kick, pcm%matrix_lf_d, pcm%n_tesserae)
1328 else
1329 call pcm_charges(pcm%q_kick, pcm%qtot_kick, pcm%v_kick, pcm%matrix_lf, pcm%n_tesserae)
1330 end if
1331 else
1332 pcm%q_kick = m_zero
1333 pcm%qtot_kick = m_zero
1334 if (pcm%calc_method == pcm_calc_poisson) pcm%rho_kick = m_zero
1335 pcm%v_kick_rs = m_zero
1336
1337 pop_sub(pcm_calc_pot_rs)
1338 return
1339 end if
1340 else
1341 if (after_kick) then
1342
1343 select case (pcm%which_eps)
1344 case (pcm_drude_model)
1345 call pcm_charges_propagation(pcm%q_kick, pcm%v_kick, pcm%dt, pcm%tess, input_asc_ext, calc, &
1346 pcm%which_eps, pcm%namespace, this_drl=pcm%drl)
1347 case default
1348 call pcm_charges_propagation(pcm%q_kick, pcm%v_kick, pcm%dt, pcm%tess, input_asc_ext, calc, &
1349 pcm%which_eps, pcm%namespace, this_deb=pcm%deb)
1350 end select
1351 if (not_yet_called) call pcm_eom_enough_initial(not_yet_called)
1352 pcm%qtot_kick = sum(pcm%q_kick)
1353
1354 else
1355 pcm%q_kick = m_zero
1356 pcm%qtot_kick = m_zero
1357 if (pcm%calc_method == pcm_calc_poisson) pcm%rho_kick = m_zero
1358 pcm%v_kick_rs = m_zero
1359
1360 pop_sub(pcm_calc_pot_rs)
1361 return
1362 end if
1363 end if
1364
1365 if (pcm%calc_method == pcm_calc_poisson) then
1366 call pcm_charge_density(pcm, pcm%q_kick, pcm%qtot_kick, mesh, pcm%rho_kick)
1367 end if
1368 call pcm_pot_rs(pcm, pcm%v_kick_rs, pcm%q_kick, pcm%rho_kick, mesh, psolver)
1369 if (.not. pcm%kick_like) then
1370 if (calc == pcm_external_plus_kick) then
1371 pcm%q_ext = pcm%q_ext + pcm%q_kick
1372 pcm%v_ext_rs = pcm%v_ext_rs + pcm%v_kick_rs
1373 else
1374 pcm%q_ext = pcm%q_kick
1375 pcm%v_ext_rs = pcm%v_kick_rs
1376 end if
1377 end if
1378
1379 end if
1380
1381
1382 if (mpi_world%is_root()) then
1383 write (asc_vs_t_unit_format_tail,'(I5,A11)') pcm%n_tesserae,'(1X,F14.8))'
1384 write (asc_vs_t_unit_format,'(A)') '(F14.8,'//trim(adjustl(asc_vs_t_unit_format_tail))
1385
1386 if (pcm%solute .and. pcm%localf .and. td_calc_mode .and. calc == pcm_electrons) then
1387 asc_vs_t_unit_e = io_open(pcm_dir//'ASC_e_vs_t.dat', pcm%namespace, &
1388 action='write', position='append', form='formatted')
1389 write(asc_vs_t_unit_e,trim(adjustl(asc_vs_t_unit_format))) pcm%iter*pcm%dt, &
1390 (pcm%q_e(ia) , ia = 1,pcm%n_tesserae)
1391 call io_close(asc_vs_t_unit_e)
1392 end if
1393 end if
1394
1395 pop_sub(pcm_calc_pot_rs)
1396 end subroutine pcm_calc_pot_rs
1397
1398 ! -----------------------------------------------------------------------------
1401 subroutine pcm_v_cav_li(v_cav, v_mesh, pcm, mesh)
1402 type(pcm_t), intent(in) :: pcm
1403 type(mesh_t), intent(in) :: mesh
1404 real(real64), intent(in) :: v_mesh(:)
1405 real(real64), contiguous, intent(out) :: v_cav(:)
1406
1407 integer :: ia
1408
1409 type(mesh_interpolation_t) :: mesh_interpolation
1410
1411 push_sub(pcm_v_cav_li)
1412
1413 v_cav = m_zero
1414
1415 call mesh_interpolation_init(mesh_interpolation, mesh)
1416
1417 do ia = 1, pcm%n_tesserae
1418 call mesh_interpolation_evaluate(mesh_interpolation, v_mesh, pcm%tess(ia)%point, v_cav(ia))
1419 end do
1420
1421 call mesh_interpolation_end(mesh_interpolation)
1422
1423 pop_sub(pcm_v_cav_li)
1424 end subroutine pcm_v_cav_li
1425
1426 !--------------------------------------------------------------------------------
1427
1430 subroutine pcm_v_nuclei_cav(v_n_cav, ions, tess, n_tess)
1431 real(real64), contiguous, intent(out) :: v_n_cav(:)
1432 type(ions_t), intent(in) :: ions
1433 type(pcm_tessera_t), contiguous, intent(in) :: tess(:)
1434 integer, intent(in) :: n_tess
1435
1436 real(real64) :: dist
1437 integer :: ik, ia
1438
1439 push_sub(pcm_v_nuclei_cav)
1440
1441 v_n_cav = m_zero
1442
1443 do ik = 1, n_tess
1444 do ia = 1, ions%natoms
1445
1446 dist = norm2(ions%pos(1:pcm_dim_space, ia) - tess(ik)%point)
1447
1448 v_n_cav(ik) = v_n_cav(ik) - ions%charge(ia)/dist
1449 end do
1450 end do
1451
1452 pop_sub(pcm_v_nuclei_cav)
1453 end subroutine pcm_v_nuclei_cav
1454
1455 ! -----------------------------------------------------------------------------
1456
1460 subroutine pcm_elect_energy(ions, pcm, E_int_ee, E_int_en, E_int_ne, E_int_nn, E_int_e_ext, E_int_n_ext)
1461 type(ions_t), intent(in) :: ions
1462 type(pcm_t), intent(in) :: pcm
1463 real(real64), intent(out) :: e_int_ee
1464 real(real64), intent(out) :: e_int_en
1465 real(real64), intent(out) :: e_int_ne
1466 real(real64), intent(out) :: e_int_nn
1467 real(real64), optional, intent(out) :: e_int_e_ext
1468 real(real64), optional, intent(out) :: e_int_n_ext
1469
1470 real(real64) :: dist, z_ia
1471 integer :: ik, ia
1472
1474
1475 e_int_ee = m_zero
1476 e_int_en = m_zero
1477 e_int_ne = m_zero
1478 e_int_nn = m_zero
1479
1480 if (pcm%localf .and. ((.not. present(e_int_e_ext)) .or. &
1481 (.not. present(e_int_n_ext)))) then
1482 message(1) = "pcm_elect_energy: There are lacking terms in subroutine call."
1483 call messages_fatal(1, namespace=pcm%namespace)
1484 else if (pcm%localf .and. (present(e_int_e_ext) .and. &
1485 present(e_int_n_ext))) then
1486 e_int_e_ext = m_zero
1487 e_int_n_ext = m_zero
1488 end if
1489
1490 do ik = 1, pcm%n_tesserae
1491
1492 e_int_ee = e_int_ee + pcm%v_e(ik)*pcm%q_e(ik)
1493 e_int_en = e_int_en + pcm%v_e(ik)*pcm%q_n(ik)
1494 if (pcm%localf) then
1495 e_int_e_ext = e_int_e_ext + pcm%v_e(ik)*pcm%q_ext(ik)
1496 end if
1497
1498 do ia = 1, ions%natoms
1499
1500 dist = norm2(ions%pos(1:pcm_dim_space, ia) - pcm%tess(ik)%point)
1501
1502 z_ia = -ions%charge(ia)
1503
1504 e_int_ne = e_int_ne + z_ia*pcm%q_e(ik) / dist
1505 e_int_nn = e_int_nn + z_ia*pcm%q_n(ik) / dist
1506 if (pcm%localf) e_int_n_ext = e_int_n_ext + z_ia*pcm%q_ext(ik) / dist
1507
1508 end do
1509 end do
1510
1511 e_int_ee = m_half*e_int_ee
1512 e_int_en = m_half*e_int_en
1513 e_int_ne = m_half*e_int_ne
1514 e_int_nn = m_half*e_int_nn
1515 ! E_int_e_ext and E_int_n_ext do not need 1/2 factor
1516
1517 ! print results of the iteration in pcm_info file
1518 if (mpi_world%is_root()) then
1519 if (pcm%localf) then
1520 write(pcm%info_unit, &
1521 '(3X,I5,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X)') &
1522 pcm%counter, &
1523 units_from_atomic(units_out%energy, e_int_ee), &
1524 units_from_atomic(units_out%energy, e_int_en), &
1525 units_from_atomic(units_out%energy, e_int_nn), &
1526 units_from_atomic(units_out%energy, e_int_ne), &
1527 units_from_atomic(units_out%energy, e_int_e_ext), &
1528 units_from_atomic(units_out%energy, e_int_n_ext), &
1529 units_from_atomic(units_out%energy, e_int_ee + e_int_en + e_int_nn + e_int_ne + e_int_e_ext + e_int_n_ext), &
1530 pcm%qtot_e, &
1531 pcm%deltaQ_e, &
1532 pcm%qtot_n, &
1533 pcm%deltaQ_n, &
1534 pcm%qtot_ext
1535 else
1536 write(pcm%info_unit, &
1537 '(3X,I5,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8,5X,F20.8)') &
1538 pcm%counter, &
1539 units_from_atomic(units_out%energy, e_int_ee), &
1540 units_from_atomic(units_out%energy, e_int_en), &
1541 units_from_atomic(units_out%energy, e_int_nn), &
1542 units_from_atomic(units_out%energy, e_int_ne), &
1543 units_from_atomic(units_out%energy, e_int_ee + e_int_en + e_int_nn + e_int_ne), &
1544 pcm%qtot_e, &
1545 pcm%deltaQ_e, &
1546 pcm%qtot_n, &
1547 pcm%deltaQ_n
1548 end if
1549 end if
1550
1551 pop_sub(pcm_elect_energy)
1552 end subroutine pcm_elect_energy
1553
1554 ! -----------------------------------------------------------------------------
1555
1559 subroutine pcm_charges(q_pcm, q_pcm_tot, v_cav, pcm_mat, n_tess, qtot_nominal, epsilon, renorm_charges, q_tot_tol, deltaQ)
1560 real(real64), contiguous, intent(out) :: q_pcm(:)
1561 real(real64), intent(out) :: q_pcm_tot
1562 real(real64), contiguous, intent(in) :: v_cav(:)
1563 real(real64), contiguous, intent(in) :: pcm_mat(:,:)
1564 integer, intent(in) :: n_tess
1565 real(real64), optional, intent(in) :: qtot_nominal
1566 real(real64), optional, intent(in) :: epsilon
1567 logical, optional, intent(in) :: renorm_charges
1568 real(real64), optional, intent(in) :: q_tot_tol
1569 real(real64), optional, intent(out) :: deltaq
1570
1571 integer :: ia
1572 real(real64) :: q_pcm_tot_norm
1573 real(real64) :: coeff
1574
1575 push_sub(pcm_charges)
1576 call profiling_in('PCM_CHARGES')
1577
1578 ! q_pcm = pcm_mat * v_cav (beta = 0 overwrites q_pcm)
1579 call lalg_gemv(n_tess, n_tess, m_one, pcm_mat, v_cav, m_zero, q_pcm)
1580 q_pcm_tot = sum(q_pcm(1:n_tess))
1581
1582 if (present(qtot_nominal) .and. present(epsilon) .and. &
1583 present(renorm_charges) .and. present(q_tot_tol) .and. present(deltaq)) then
1584
1585 deltaq = abs(q_pcm_tot) - ((epsilon - m_one)/epsilon) * abs(qtot_nominal)
1586 if ((renorm_charges) .and. (abs(deltaq) > q_tot_tol)) then
1587 q_pcm_tot_norm = m_zero
1588 coeff = sign(m_one, qtot_nominal)*sign(m_one, deltaq)
1589 do ia = 1, n_tess
1590 q_pcm(ia) = q_pcm(ia) + coeff*q_pcm(ia)/q_pcm_tot*abs(deltaq)
1591 q_pcm_tot_norm = q_pcm_tot_norm + q_pcm(ia)
1592 end do
1593 q_pcm_tot = q_pcm_tot_norm
1594 end if
1595 end if
1596
1597 call profiling_out('PCM_CHARGES')
1598 pop_sub(pcm_charges)
1599 end subroutine pcm_charges
1600
1601 ! -----------------------------------------------------------------------------
1603 logical function pcm_nn_in_mesh(pcm, mesh) result(in_mesh)
1604 type(pcm_t), intent(in) :: pcm
1605 class(mesh_t), intent(in) :: mesh
1606
1607 integer :: ia, nm(pcm%space%dim), ipt, i1, i2, i3
1608 real(real64) :: posrel(pcm%space%dim)
1609 integer(int64) :: pt
1610
1611 push_sub(pcm_nn_in_mesh)
1612
1613 in_mesh = .true.
1614 do ia = 1, pcm%n_tesserae
1615
1616 posrel(:) = pcm%tess(ia)%point(1:pcm%space%dim)/mesh%spacing(1:pcm%space%dim)
1617
1618 nm(:) = floor(posrel(:))
1619
1620 ! Get the nearest neighboring points
1621 ipt = 0
1622 do i1 = -pcm%tess_nn + 1 , pcm%tess_nn
1623 do i2 = -pcm%tess_nn + 1 , pcm%tess_nn
1624 do i3 = -pcm%tess_nn + 1 , pcm%tess_nn
1625 ipt = ipt + 1
1626 pt = mesh_global_index_from_coords(mesh, [i1 + nm(1), i2 + nm(2), i3 + nm(3)])
1627
1628 if (pt <= 0 .or. pt > mesh%np_part_global) then
1629 in_mesh = .false.
1630 pop_sub(pcm_nn_in_mesh)
1631 return
1632 end if
1633
1634 end do
1635 end do
1636 end do
1637 end do
1638
1639 pop_sub(pcm_nn_in_mesh)
1640 end function pcm_nn_in_mesh
1641
1642 ! -----------------------------------------------------------------------------
1644 subroutine pcm_poisson_sanity_check(pcm, mesh)
1645 type(pcm_t), intent(in) :: pcm
1646 class(mesh_t), intent(in) :: mesh
1647
1648 push_sub(pcm_poisson_sanity_check)
1649
1650 if (.not. pcm_nn_in_mesh(pcm, mesh)) then
1651 message(1) = 'The simulation box is too small to contain all the requested'
1652 message(2) = 'nearest neighbors for each tessera.'
1653 message(3) = 'Consider using a larger box or reduce PCMChargeSmearNN.'
1654 call messages_warning(3, namespace=pcm%namespace)
1655 end if
1656
1658 end subroutine pcm_poisson_sanity_check
1659
1660 ! -----------------------------------------------------------------------------
1663 subroutine pcm_charge_density(pcm, q_pcm, q_pcm_tot, mesh, rho)
1664 type(pcm_t), intent(inout) :: pcm
1665 real(real64), contiguous, intent(in) :: q_pcm(:)
1666 real(real64), intent(in) :: q_pcm_tot
1667 type(mesh_t), intent(in) :: mesh
1668 real(real64), contiguous, intent(out) :: rho(:)
1669
1670 integer :: ia
1671 real(real64) :: norm, qtot, rr, xx(pcm%space%dim), pp(pcm%space%dim)
1672
1673 ! nearest neighbor variables
1674 integer :: nm(pcm%space%dim)
1675 real(real64) :: posrel(pcm%space%dim)
1676 integer :: npt, ipt
1677 integer :: i1, i2, i3
1678 integer, allocatable :: pt(:)
1679 real(real64), allocatable :: lrho(:) ! local charge density on a tessera NN
1680 logical :: inner_point, boundary_point
1681
1682 !profiling and debug
1683 integer :: ierr
1684
1685 push_sub(pcm_charge_density)
1686 call profiling_in('PCM_CHARGE_DENSITY')
1687
1688 npt = (2*pcm%tess_nn)**pcm%space%dim
1689 safe_allocate(pt(1:npt))
1690 safe_allocate(lrho(1:npt))
1691
1692 pt = 0
1693 rho = m_zero
1694
1695 do ia = 1, pcm%n_tesserae
1696
1697 pp(:) = pcm%tess(ia)%point(1:pcm%space%dim)
1698 posrel(:) = pp(:)/mesh%spacing(1:pcm%space%dim)
1699
1700 nm(:) = floor(posrel(:))
1701
1702 ! Get the nearest neighboring points
1703 ipt = 0
1704 do i1 = -pcm%tess_nn + 1 , pcm%tess_nn
1705 do i2 = -pcm%tess_nn + 1 , pcm%tess_nn
1706 do i3 = -pcm%tess_nn + 1 , pcm%tess_nn
1707 ipt = ipt + 1
1708 pt(ipt) = mesh_local_index_from_coords(mesh, [i1 + nm(1), i2 + nm(2), i3 + nm(3)])
1709 end do
1710 end do
1711 end do
1712
1713
1714 ! Extrapolate the tessera point charge with a gaussian distritibution
1715 ! to the neighboring points
1716 ! \f$ rho(r) = N exp(-|r-sk|^2/(alpha*Ak)) \f$
1717 norm = m_zero
1718 lrho = m_zero
1719 do ipt = 1, npt
1720
1721 ! Check the point is inside the mesh skip otherwise
1722 if (pt(ipt) > 0 .and. pt(ipt) <= mesh%np_part) then
1723
1724 if (mesh%parallel_in_domains) then
1725 boundary_point = pt(ipt) > mesh%np + mesh%pv%np_ghost
1726 inner_point = pt(ipt) > 0 .and. pt(ipt) <= mesh%np
1727
1728 if (boundary_point .or. inner_point) then
1729 xx(:) = mesh%x(:, pt(ipt))
1730 else
1731 cycle
1732 end if
1733
1734 else
1735 xx(:) = mesh%x(:, pt(ipt))
1736 end if
1737
1738 rr = sum((xx(1:pcm%space%dim) - pp(1:pcm%space%dim))**2)
1739 norm = norm + exp(-rr/(pcm%tess(ia)%area*pcm%gaussian_width))
1740 lrho(ipt) = lrho(ipt) + exp(-rr/(pcm%tess(ia)%area*pcm%gaussian_width))
1741
1742 end if
1743 end do
1744
1745 ! reduce the local density scattered among nodes
1746 call mesh%allreduce(lrho, npt)
1747
1748 ! normalize the integral to the tessera point charge q_pcm(ia)
1749 norm = sum(lrho(1:npt)) * mesh%volume_element
1750 if (norm > m_epsilon) then
1751 norm = q_pcm(ia)/norm
1752 else
1753 norm = m_zero
1754 end if
1755 lrho(:) = lrho(:) * norm
1756
1757 ! Add up the local density to the full charge density
1758 do ipt = 1, npt
1759
1760 if (pt(ipt) > 0 .and. pt(ipt) <= mesh%np_part_global) then
1761
1762 if (mesh%parallel_in_domains) then
1763 boundary_point = pt(ipt) > mesh%np + mesh%pv%np_ghost
1764 inner_point = pt(ipt) > 0 .and. pt(ipt) <= mesh%np
1765 if (boundary_point .or. inner_point) rho(pt(ipt)) = rho(pt(ipt)) + lrho(ipt)
1766 else
1767 rho(pt(ipt)) = rho(pt(ipt)) + lrho(ipt)
1768 end if
1769
1770 end if
1771 end do
1772
1773 end do
1774
1775 if (debug%info) then
1776 qtot = dmf_integrate(mesh, rho)
1777 call messages_write(' PCM charge density integrates to q = ')
1778 call messages_write(qtot)
1779 call messages_write(' (qtot = ')
1780 call messages_write(q_pcm_tot)
1781 call messages_write(')')
1782 call messages_info()
1783
1784 ! Keep this here for debug purposes.
1785 call dio_function_output(io_function_fill_how("VTK"), ".", "rho_pcm", pcm%namespace, pcm%space, &
1786 mesh, rho, unit_one, ierr)
1787 end if
1788
1789 safe_deallocate_a(pt)
1790 safe_deallocate_a(lrho)
1791
1792 call profiling_out('PCM_CHARGE_DENSITY')
1793
1794 pop_sub(pcm_charge_density)
1795 end subroutine pcm_charge_density
1796
1797
1798 ! -----------------------------------------------------------------------------
1800 subroutine pcm_pot_rs(pcm, v_pcm, q_pcm, rho, mesh, psolver)
1801 type(pcm_t), intent(inout) :: pcm
1802 real(real64), contiguous, intent(inout) :: v_pcm(:)
1803 real(real64), contiguous, intent(in) :: q_pcm(:)
1804 real(real64), contiguous, intent(inout) :: rho(:)
1805 type(mesh_t), intent(in) :: mesh
1806 type(poisson_t), intent(in) :: psolver
1807
1808 integer :: ierr
1809
1810 push_sub(pcm_pot_rs)
1811 call profiling_in('PCM_POT_RS')
1812
1813 v_pcm = m_zero
1814
1815 select case (pcm%calc_method)
1816 case (pcm_calc_direct)
1817 call pcm_pot_rs_direct(v_pcm, q_pcm, pcm%tess, pcm%n_tesserae, mesh, pcm%gaussian_width)
1818
1819 case (pcm_calc_poisson)
1820 call pcm_pot_rs_poisson(pcm%namespace, v_pcm, psolver, rho)
1821
1822 case default
1823 message(1) = "BAD BAD BAD"
1824 call messages_fatal(1,only_root_writes = .true., namespace=pcm%namespace)
1825
1826 end select
1827
1828 if (debug%info) then
1829 ! Keep this here for debug purposes.
1830 call dio_function_output(io_function_fill_how("VTK"), ".", "v_pcm", pcm%namespace, pcm%space, &
1831 mesh, v_pcm, unit_one, ierr)
1832 end if
1833
1834 call profiling_out('PCM_POT_RS')
1835 pop_sub(pcm_pot_rs)
1836 end subroutine pcm_pot_rs
1837
1838
1839 ! -----------------------------------------------------------------------------
1841 subroutine pcm_pot_rs_poisson(namespace, v_pcm, psolver, rho)
1842 type(namespace_t), intent(in) :: namespace
1843 real(real64), contiguous, intent(inout) :: v_pcm(:)
1844 type(poisson_t), intent(in) :: psolver
1845 real(real64), contiguous, intent(inout) :: rho(:)
1846
1847 push_sub(pcm_pot_rs_poisson)
1848
1849 call dpoisson_solve(psolver, namespace, v_pcm, rho)
1850
1851 pop_sub(pcm_pot_rs_poisson)
1852 end subroutine pcm_pot_rs_poisson
1853
1854
1855 ! -----------------------------------------------------------------------------
1857 subroutine pcm_pot_rs_direct(v_pcm, q_pcm, tess, n_tess, mesh, width_factor)
1858 real(real64), contiguous, intent(out) :: v_pcm(:)
1859 real(real64), contiguous, intent(in) :: q_pcm(:)
1860 real(real64), intent(in) :: width_factor
1861 integer, intent(in) :: n_tess
1862 type(mesh_t), intent(in) :: mesh
1863 type(pcm_tessera_t), contiguous, intent(in) :: tess(:)
1864
1865 real(real64), parameter :: p_1 = 0.119763_real64
1866 real(real64), parameter :: p_2 = 0.205117_real64
1867 real(real64), parameter :: q_1 = 0.137546_real64
1868 real(real64), parameter :: q_2 = 0.434344_real64
1869 real(real64) :: arg
1870 real(real64) :: term
1871 integer :: ip
1872 integer :: ia
1873
1874 push_sub(pcm_pot_rs_direct)
1875
1876 v_pcm = m_zero
1877
1878 if (abs(width_factor) > m_epsilon) then
1879
1880 do ia = 1, n_tess
1881 do ip = 1, mesh%np
1882 ! Computing the distances between tesserae and grid points.
1883 call mesh_r(mesh, ip, term, origin=tess(ia)%point)
1884 arg = term/sqrt(tess(ia)%area*width_factor)
1885 term = (m_one + p_1*arg + p_2*arg**2) / (m_one + q_1*arg + q_2*arg**2 + p_2*arg**3)
1886 v_pcm(ip) = v_pcm(ip) + q_pcm(ia) * term/sqrt(tess(ia)%area*width_factor)
1887 end do
1888 end do
1889
1890 v_pcm = m_two*v_pcm / sqrt(m_pi)
1891
1892 else
1893
1894 do ia = 1, n_tess
1895 do ip = 1, mesh%np
1896 ! Computing the distances between tesserae and grid points.
1897 call mesh_r(mesh, ip, term, origin=tess(ia)%point)
1898 v_pcm(ip) = v_pcm(ip) + q_pcm(ia)/term
1899 end do
1900 end do
1901 end if
1902
1903 pop_sub(pcm_pot_rs_direct)
1904 end subroutine pcm_pot_rs_direct
1905
1906 ! -----------------------------------------------------------------------------
1907
1909 subroutine pcm_matrix(eps, tess, n_tess, pcm_mat, localf, substrate)
1910 real(real64), intent(in) :: eps
1911 type(pcm_tessera_t), intent(in) :: tess(:)
1912 integer, intent(in) :: n_tess
1913 real(real64), intent(out) :: pcm_mat(:,:)
1914 logical, optional, intent(in) :: localf
1915 type(lpcm_substrate_t), optional, intent(in) :: substrate
1916
1917 integer :: i, info
1918 integer, allocatable :: iwork(:)
1919 real(real64), allocatable :: mat_tmp(:,:)
1920
1921 real(real64) :: sgn_lf
1922
1923 push_sub(pcm_matrix)
1924
1926 safe_allocate(s_mat_act(1:n_tess, 1:n_tess))
1927 call s_i_matrix(n_tess, tess)
1928
1930 safe_allocate(sigma(1:n_tess, 1:n_tess))
1931 sigma = s_mat_act/eps
1932
1934 safe_allocate(d_mat_act(1:n_tess, 1:n_tess))
1935 call d_i_matrix(n_tess, tess)
1936
1938 safe_allocate(delta(1:n_tess, 1:n_tess))
1940
1941 if(present(substrate)) then
1942 if (substrate%is_present) call layer_pcm_add_image_term(n_tess, tess, substrate, delta, sigma)
1943 end if
1944
1945 sgn_lf = m_one
1947 if (present(localf)) then
1948 if (localf) sgn_lf = -m_one
1949 end if
1950
1952 pcm_mat = - sgn_lf * d_mat_act
1953
1954 do i = 1, n_tess
1955 pcm_mat(i,i) = pcm_mat(i,i) + m_two*m_pi
1956 end do
1957
1958 safe_deallocate_a(d_mat_act)
1959
1960 safe_allocate(iwork(1:n_tess))
1961
1964 ! FIXME: use interface, or routine in lalg_adv_lapack_inc.F90
1965 call dgesv(n_tess, n_tess, s_mat_act, n_tess, iwork, pcm_mat, n_tess, info)
1966
1967 safe_deallocate_a(iwork)
1968
1969 safe_deallocate_a(s_mat_act)
1970
1973 pcm_mat = -matmul(sigma, pcm_mat)
1974
1975 do i = 1, n_tess
1976 pcm_mat(i,i) = pcm_mat(i,i) + m_two*m_pi
1977 end do
1978
1979 pcm_mat = pcm_mat - sgn_lf * delta
1980
1981 safe_allocate(mat_tmp(1:n_tess,1:n_tess))
1982 mat_tmp = m_zero
1983
1984 safe_allocate(d_mat_act(1:n_tess,1:n_tess))
1985 call d_i_matrix(n_tess, tess)
1986
1987 mat_tmp = transpose(d_mat_act)
1988
1989 mat_tmp = matmul(sigma, mat_tmp)
1990
1991 mat_tmp = mat_tmp + m_two*m_pi*sigma
1992
1993 safe_deallocate_a(d_mat_act)
1994
1995 safe_allocate(s_mat_act(1:n_tess, 1:n_tess))
1996 call s_i_matrix(n_tess, tess)
1997
1998 mat_tmp = mat_tmp + m_two*m_pi*s_mat_act - matmul(delta, s_mat_act)
1999
2000 safe_deallocate_a(s_mat_act)
2001 safe_deallocate_a(sigma)
2002 safe_deallocate_a(delta)
2003
2004 safe_allocate(iwork(1:n_tess))
2005
2008 call dgesv(n_tess, n_tess, mat_tmp, n_tess, iwork, pcm_mat, n_tess, info)
2009
2010 safe_deallocate_a(iwork)
2011 safe_deallocate_a(mat_tmp)
2012
2013 pcm_mat = - sgn_lf * pcm_mat
2014
2015 ! Testing
2016 if (gamess_benchmark) then
2017 do i = 1, n_tess
2018 mat_gamess(i,:) = pcm_mat(i,:)/tess(i)%area
2019 end do
2020 end if
2021
2022 pop_sub(pcm_matrix)
2023 end subroutine pcm_matrix
2024
2025 ! -----------------------------------------------------------------------------
2026
2027 subroutine s_i_matrix(n_tess, tess)
2028 integer, intent(in) :: n_tess
2029 type(pcm_tessera_t), intent(in) :: tess(:)
2030
2031 integer :: ii, jj
2032
2034
2035 do ii = 1, n_tess
2036 do jj = ii, n_tess
2037 s_mat_act(ii,jj) = s_mat_elem_i(tess(ii), tess(jj))
2038 if (ii /= jj) s_mat_act(jj,ii) = s_mat_act(ii,jj) !symmetric matrix
2039 end do
2040 end do
2041
2042 end subroutine s_i_matrix
2043
2044 ! -----------------------------------------------------------------------------
2045
2046 subroutine d_i_matrix(n_tess, tess)
2047 integer, intent(in) :: n_tess
2048 type(pcm_tessera_t), intent(in) :: tess(:)
2049
2050 integer :: ii, jj
2051
2053
2054 do ii = 1, n_tess
2055 do jj = 1, n_tess
2056 d_mat_act(ii,jj) = d_mat_elem_i(tess(ii), tess(jj))
2057 end do
2058 end do
2059
2060 end subroutine d_i_matrix
2061
2062 ! -----------------------------------------------------------------------------
2063
2066 real(real64) function s_mat_elem_I(tessi, tessj)
2067 type(pcm_tessera_t), intent(in) :: tessi
2068 type(pcm_tessera_t), intent(in) :: tessj
2069
2070 real(real64), parameter :: M_SD_DIAG = 1.0694_real64
2071 real(real64), parameter :: M_DIST_MIN = 0.1_real64
2072
2073 real(real64) :: diff(1:PCM_DIM_SPACE)
2074 real(real64) :: dist
2075 real(real64) :: s_diag
2076 real(real64) :: s_off_diag
2077
2078 s_diag = m_zero
2079 s_off_diag = m_zero
2080
2081 diff = tessi%point - tessj%point
2082
2083 dist = norm2(diff)
2084
2085 if (abs(dist) <= m_epsilon) then
2086 s_diag = m_sd_diag*sqrt(m_four*m_pi/tessi%area)
2087 s_mat_elem_i = s_diag
2088 else
2089 if (dist > m_dist_min) s_off_diag = m_one/dist
2090 s_mat_elem_i = s_off_diag
2091 end if
2092
2093 end function s_mat_elem_i
2094
2095 ! -----------------------------------------------------------------------------
2096
2098 real(real64) function d_mat_elem_I(tessi, tessj)
2099 type(pcm_tessera_t), intent(in) :: tessi
2100 type(pcm_tessera_t), intent(in) :: tessj
2101
2102 real(real64), parameter :: M_SD_DIAG = 1.0694_real64
2103 real(real64), parameter :: M_DIST_MIN = 0.04_real64
2104
2105 real(real64) :: diff(1:PCM_DIM_SPACE)
2106 real(real64) :: dist
2107 real(real64) :: d_diag
2108 real(real64) :: d_off_diag
2109
2110 d_diag = m_zero
2111 d_off_diag = m_zero
2112 diff = m_zero
2113
2114 diff = tessi%point - tessj%point
2115
2116 dist = norm2(diff)
2117
2118 if (abs(dist) <= m_epsilon) then
2120 d_diag = m_sd_diag*sqrt(m_four*m_pi*tessi%area)
2121 d_diag = -d_diag/(m_two*tessi%r_sphere)
2122 d_mat_elem_i = d_diag
2123
2124 else
2126 if (dist > m_dist_min) then
2127 d_off_diag = dot_product( diff, tessj%normal(:))
2128 d_off_diag = d_off_diag*tessj%area/dist**3
2129 end if
2130
2131 d_mat_elem_i = d_off_diag
2132
2133 end if
2134
2135 end function d_mat_elem_i
2136
2137 ! -----------------------------------------------------------------------------
2142 subroutine cav_gen(tess_sphere, tess_min_distance, nesf, sfe, nts, cts, unit_pcminfo)
2143 integer, intent(in) :: tess_sphere
2144 real(real64) , intent(in) :: tess_min_distance
2145 type(pcm_sphere_t), contiguous, intent(inout) :: sfe(:)
2146 integer, intent(in) :: nesf
2147 integer, intent(out) :: nts
2148 type(pcm_tessera_t), contiguous, intent(out) :: cts(:)
2149 integer, intent(in) :: unit_pcminfo
2150
2151 integer, parameter :: dim_angles = 24
2152 integer, parameter :: dim_ten = 10
2153 integer, parameter :: dim_vertices = 122
2154 integer, parameter :: max_vertices = 6
2155 integer, parameter :: mxts = 10000
2156
2157 real(real64), save :: thev(1:dim_angles)
2158 real(real64), save :: fiv(1:dim_angles)
2159 real(real64), save :: fir
2160 real(real64) :: cv(1:dim_vertices, 1:pcm_dim_space)
2161 real(real64) :: th
2162 real(real64) :: fi
2163 real(real64) :: cth
2164 real(real64) :: sth
2165
2166 real(real64) :: xctst(tess_sphere*n_tess_sphere)
2167 real(real64) :: yctst(tess_sphere*n_tess_sphere)
2168 real(real64) :: zctst(tess_sphere*n_tess_sphere)
2169 real(real64) :: ast(tess_sphere*n_tess_sphere)
2170 real(real64) :: nctst(pcm_dim_space, tess_sphere*n_tess_sphere)
2171
2172 real(real64) :: pts(1:pcm_dim_space, 1:dim_ten)
2173 real(real64) :: pp(1:pcm_dim_space)
2174 real(real64) :: pp1(1:pcm_dim_space)
2175 real(real64) :: ccc(1:pcm_dim_space, 1:dim_ten)
2176
2177 integer, save :: idum(1:n_tess_sphere*max_vertices)
2178 integer :: jvt1(1:max_vertices,1:n_tess_sphere)
2179 integer :: isfet(1:dim_ten*dim_angles)
2180
2181 integer :: ii
2182 integer :: ia
2183 integer :: ja
2184 integer :: nn
2185 integer :: nsfe
2186 integer :: its
2187 integer :: n1
2188 integer :: n2
2189 integer :: n3
2190 integer :: nv
2191 integer :: i_tes
2192
2193 real(real64) :: xen
2194 real(real64) :: yen
2195 real(real64) :: zen
2196 real(real64) :: ren
2197 real(real64) :: area
2198 real(real64) :: test2
2199 real(real64) :: rij
2200 real(real64) :: dnorm
2201
2202 real(real64) :: xi
2203 real(real64) :: yi
2204 real(real64) :: zi
2205 real(real64) :: xj
2206 real(real64) :: yj
2207 real(real64) :: zj
2208
2209 real(real64) :: vol
2210 real(real64) :: stot
2211 real(real64) :: prod
2212 real(real64) :: dr
2213
2214 logical :: band_iter
2215
2216 push_sub(cav_gen)
2217
2220 data thev/ 0.6523581398_real64 , 1.107148718_real64 , 1.382085796_real64 , &
2221 1.759506858_real64 , 2.034443936_real64 , 2.489234514_real64 , &
2222 0.3261790699_real64 , 0.5535743589_real64, &
2223 0.8559571251_real64 , 0.8559571251_real64 , 1.017221968_real64 , &
2224 1.229116717_real64 , 1.229116717_real64 , 1.433327788_real64 , &
2225 1.570796327_real64 , 1.570796327_real64 , 1.708264866_real64 , &
2226 1.912475937_real64 , 1.912475937_real64 , 2.124370686_real64 , &
2227 2.285635528_real64 , 2.285635528_real64 , 2.588018295_real64 , &
2228 2.815413584_real64 /
2229 data fiv/ 0.6283185307_real64 , m_zero , &
2230 0.6283185307_real64 , m_zero , 0.6283185307_real64, &
2231 m_zero , 0.6283185307_real64 , m_zero, &
2232 0.2520539002_real64 , 1.004583161_real64 , 0.6283185307_real64, &
2233 0.3293628477_real64 , 0.9272742138_real64 , m_zero, &
2234 0.3141592654_real64 , 0.9424777961_real64 , 0.6283185307_real64, &
2235 0.2989556830_real64 , 0.9576813784_real64 , m_zero, &
2236 0.3762646305_real64 , 0.8803724309_real64 , 0.6283188307_real64, &
2237 m_zero /
2238 data fir / 1.256637061_real64 /
2239
2242 data (idum(ii),ii = 1, 280) / &
2243 1, 6, 2, 32, 36, 37, 1, 2, 3, 33, 32, 38, 1, 3, 4, 34, &
2244 33, 39, 1, 4, 5, 35, 34, 40, 1, 5, 6, 36, 35, 41, 7, 2, 6, 51, &
2245 42, 37, 8, 3, 2, 47, 43, 38, 9, 4, 3, 48, 44, 39, 10, 5, 4, &
2246 49, 45, 40, 11, 6, 5, 50, 46, 41, 8, 2, 12, 62, 47, 52, 9, &
2247 3, 13, 63, 48, 53, 10, 4, 14, 64, 49, 54, 11, 5, 15, 65, 50, &
2248 55, 7, 6, 16, 66, 51, 56, 7, 12, 2, 42, 57, 52, 8, 13, 3, &
2249 43, 58, 53, 9, 14, 4, 44, 59, 54, 10, 15, 5, 45, 60, 55, 11, &
2250 16, 6, 46, 61, 56, 8, 12, 18, 68, 62, 77, 9, 13, 19, 69, 63, &
2251 78, 10, 14, 20, 70, 64, 79, 11, 15, 21, 71, 65, 80, 7, 16, &
2252 17, 67, 66, 81, 7, 17, 12, 57, 67, 72, 8, 18, 13, 58, 68, 73, &
2253 9, 19, 14, 59, 69, 74, 10, 20, 15, 60, 70, 75, 11, 21, 16, &
2254 61, 71, 76, 22, 12, 17, 87, 82, 72, 23, 13, 18, 88, 83, 73, &
2255 24, 14, 19, 89, 84, 74, 25, 15, 20, 90, 85, 75, 26, 16, 21, &
2256 91, 86, 76, 22, 18, 12, 82, 92, 77, 23, 19, 13, 83, 93, 78, &
2257 24, 20, 14, 84, 94, 79, 25, 21, 15, 85, 95, 80, 26, 17, 16, &
2258 86, 96, 81, 22, 17, 27, 102, 87, 97, 23, 18, 28, 103, 88, 98, &
2259 24, 19, 29, 104, 89, 99, 25, 20, 30, 105, 90, 100, 26, 21, &
2260 31, 106, 91, 101, 22, 28, 18, 92, 107, 98, 23, 29, 19, 93 /
2261 data (idum(ii),ii = 281,360) / &
2262 108, 99, 24, 30, 20, 94, 109, 100, 25, 31, 21, 95, 110, 101, &
2263 26, 27, 17, 96, 111, 97, 22, 27, 28, 107, 102, 112, 23, 28, &
2264 29, 108, 103, 113, 24, 29, 30, 109, 104, 114, 25, 30, 31, &
2265 110, 105, 115, 26, 31, 27, 111, 106, 116, 122, 28, 27, 117, &
2266 118, 112, 122, 29, 28, 118, 119, 113, 122, 30, 29, 119, 120, &
2267 114, 122, 31, 30, 120, 121, 115, 122, 27, 31, 121, 117, 116 /
2268
2269 if (mpi_world%is_root()) then
2270 if (tess_sphere == 1) then
2271 write(unit_pcminfo,'(A1)') '#'
2272 write(unit_pcminfo,'(A34)') '# Number of tesserae / sphere = 60'
2273 write(unit_pcminfo,'(A1)') '#'
2274 else
2275 write(unit_pcminfo,'(A1)') '#'
2276 write(unit_pcminfo,'(A35)') '# Number of tesserae / sphere = 240'
2277 write(unit_pcminfo,'(A1)') '#'
2278 end if
2279 end if
2280
2283 dr = 0.01_real64
2284 dr = dr*p_a_b
2285
2286 sfe(:)%x = sfe(:)%x*p_a_b
2287 sfe(:)%y = sfe(:)%y*p_a_b
2288 sfe(:)%z = sfe(:)%z*p_a_b
2289 sfe(:)%r = sfe(:)%r*p_a_b
2290
2291 vol = m_zero
2292 stot = m_zero
2293 jvt1 = reshape(idum,(/6,60/))
2294
2306
2307 cv(1,1) = m_zero
2308 cv(1,2) = m_zero
2309 cv(1,3) = m_one
2310
2311 cv(122,1) = m_zero
2312 cv(122,2) = m_zero
2313 cv(122,3) = -m_one
2314
2315 ii = 1
2316 do ia = 1, dim_angles
2317 th = thev(ia)
2318 fi = fiv(ia)
2319 cth = cos(th)
2320 sth = sin(th)
2321 do ja = 1, 5
2322 fi = fi + fir
2323 if (ja == 1) fi = fiv(ia)
2324 ii = ii + 1
2325 cv(ii,1) = sth*cos(fi)
2326 cv(ii,2) = sth*sin(fi)
2327 cv(ii,3) = cth
2328 end do
2329 end do
2330
2332 nn = 0
2333 do nsfe = 1, nesf
2334 xen = sfe(nsfe)%x
2335 yen = sfe(nsfe)%y
2336 zen = sfe(nsfe)%z
2337 ren = sfe(nsfe)%r
2338
2339 xctst(:) = m_zero
2340 yctst(:) = m_zero
2341 zctst(:) = m_zero
2342 ast(:) = m_zero
2343
2344 do its = 1, n_tess_sphere
2345 do i_tes = 1, tess_sphere
2346 if (tess_sphere == 1) then
2347 n1 = jvt1(1,its)
2348 n2 = jvt1(2,its)
2349 n3 = jvt1(3,its)
2350 else
2351 if (i_tes == 1) then
2352 n1 = jvt1(1,its)
2353 n2 = jvt1(5,its)
2354 n3 = jvt1(4,its)
2355 elseif (i_tes == 2) then
2356 n1 = jvt1(4,its)
2357 n2 = jvt1(6,its)
2358 n3 = jvt1(3,its)
2359 elseif (i_tes == 3) then
2360 n1 = jvt1(4,its)
2361 n2 = jvt1(5,its)
2362 n3 = jvt1(6,its)
2363 elseif (i_tes == 4) then
2364 n1 = jvt1(2,its)
2365 n2 = jvt1(6,its)
2366 n3 = jvt1(5,its)
2367 end if
2368 end if
2369
2370 pts(1,1) = cv(n1,1)*ren + xen
2371 pts(2,1) = cv(n1,3)*ren + yen
2372 pts(3,1) = cv(n1,2)*ren + zen
2373
2374 pts(1,2) = cv(n2,1)*ren + xen
2375 pts(2,2) = cv(n2,3)*ren + yen
2376 pts(3,2) = cv(n2,2)*ren + zen
2377
2378 pts(1,3) = cv(n3,1)*ren + xen
2379 pts(2,3) = cv(n3,3)*ren + yen
2380 pts(3,3) = cv(n3,2)*ren + zen
2381
2382 pp(:) = m_zero
2383 pp1(:) = m_zero
2384 nv = 3
2385
2386 call subtessera(sfe, nsfe, nesf, nv, pts ,ccc, pp, pp1, area)
2387
2388 if (abs(area) <= m_epsilon) cycle
2389
2390 xctst(tess_sphere*(its-1) + i_tes) = pp(1)
2391 yctst(tess_sphere*(its-1) + i_tes) = pp(2)
2392 zctst(tess_sphere*(its-1) + i_tes) = pp(3)
2393 nctst(:,tess_sphere*(its-1) + i_tes) = pp1(:)
2394 ast(tess_sphere*(its-1) + i_tes) = area
2395 isfet(tess_sphere*(its-1) + i_tes) = nsfe
2396
2397 end do
2398 end do
2399
2400 do its = 1, n_tess_sphere*tess_sphere
2401
2402 if (abs(ast(its)) <= m_epsilon) cycle
2403 nn = nn + 1
2404
2405 if (nn > mxts) then
2406 write(message(1),'(a,I5,a,I5)') "total number of tesserae", nn, ">",mxts
2407 call messages_warning(1)
2408 end if
2409
2410 cts(nn)%point(1) = xctst(its)
2411 cts(nn)%point(2) = yctst(its)
2412 cts(nn)%point(3) = zctst(its)
2413 cts(nn)%normal(:) = nctst(:,its)
2414 cts(nn)%area = ast(its)
2415 cts(nn)%r_sphere = sfe(isfet(its))%r
2416
2417 end do
2418 end do
2419
2420 nts = nn
2421
2423 test2 = tess_min_distance*tess_min_distance
2424
2425 band_iter = .false.
2426 do while (.not.(band_iter))
2427 band_iter = .true.
2428
2429 loop_ia: do ia = 1, nts-1
2430 if (abs(cts(ia)%area) <= m_epsilon) cycle
2431 xi = cts(ia)%point(1)
2432 yi = cts(ia)%point(2)
2433 zi = cts(ia)%point(3)
2434
2435 loop_ja: do ja = ia+1, nts
2436 if (abs(cts(ja)%area) <= m_epsilon) cycle
2437 xj = cts(ja)%point(1)
2438 yj = cts(ja)%point(2)
2439 zj = cts(ja)%point(3)
2440
2441 rij = (xi - xj)**2 + (yi - yj)**2 + (zi - zj)**2
2442
2443 if (rij > test2) cycle
2444
2445 if (mpi_world%is_root()) then
2446 write(unit_pcminfo,'(A40,I4,A5,I4,A4,F8.4,A13,F8.4,A3)') &
2447 '# Warning: The distance between tesserae', &
2448 ia,' and ', ja,' is ',sqrt(rij),' A, less than', tess_min_distance,' A.'
2449 end if
2450
2452 xi = (xi*cts(ia)%area + xj*cts(ja)%area) / (cts(ia)%area + cts(ja)%area)
2453 yi = (yi*cts(ia)%area + yj*cts(ja)%area) / (cts(ia)%area + cts(ja)%area)
2454 zi = (zi*cts(ia)%area + zj*cts(ja)%area) / (cts(ia)%area + cts(ja)%area)
2455
2456 cts(ia)%point(1) = xi
2457 cts(ia)%point(2) = yi
2458 cts(ia)%point(3) = zi
2459
2461 cts(ia)%normal = (cts(ia)%normal*cts(ia)%area + cts(ja)%normal*cts(ja)%area)
2462 dnorm = norm2(cts(ia)%normal)
2463 cts(ia)%normal = cts(ia)%normal/dnorm
2464
2466 cts(ia)%r_sphere = (cts(ia)%r_sphere*cts(ia)%area + cts(ja)%r_sphere*cts(ja)%area) / &
2467 (cts(ia)%area + cts(ja)%area)
2468
2470 cts(ia)%area = cts(ia)%area + cts(ja)%area
2471
2473 do ii = ja+1, nts
2474 cts(ii-1) = cts(ii)
2475 end do
2476 nts = nts - 1 ! updating number of tesserae
2477 band_iter = .false.
2478 exit loop_ia
2479
2480 end do loop_ja
2481 end do loop_ia
2482 end do
2483
2485 vol = m_zero
2486 do its = 1, nts
2487 prod = dot_product(cts(its)%point, cts(its)%normal)
2488 vol = vol + cts(its)%area * prod / m_three
2489 stot = stot + cts(its)%area
2490 end do
2491
2492 if (mpi_world%is_root()) then
2493 write(unit_pcminfo, '(A2)') '# '
2494 write(unit_pcminfo, '(A29,I4)') '# Total number of tesserae = ' , nts
2495 write(unit_pcminfo, '(A30,F12.6)') '# Cavity surface area (A^2) = ', stot
2496 write(unit_pcminfo, '(A24,F12.6)') '# Cavity volume (A^3) = ' , vol
2497 write(unit_pcminfo, '(A2)') '# '
2498 end if
2499
2501 cts(1:nts)%area = cts(1:nts)%area*p_ang*p_ang
2502 cts(1:nts)%point(1) = cts(1:nts)%point(1)*p_ang
2503 cts(1:nts)%point(2) = cts(1:nts)%point(2)*p_ang
2504 cts(1:nts)%point(3) = cts(1:nts)%point(3)*p_ang
2505 cts(1:nts)%r_sphere = cts(1:nts)%r_sphere*p_ang
2506
2507 sfe(:)%x=sfe(:)%x*p_ang
2508 sfe(:)%y=sfe(:)%y*p_ang
2509 sfe(:)%z=sfe(:)%z*p_ang
2510 sfe(:)%r=sfe(:)%r*p_ang
2511
2512 pop_sub(cav_gen)
2513 end subroutine cav_gen
2514
2515 ! -----------------------------------------------------------------------------
2516
2519 subroutine subtessera(sfe, ns, nesf, nv, pts, ccc, pp, pp1, area)
2520 type(pcm_sphere_t), contiguous, intent(in) :: sfe(:)
2521 integer, intent(in) :: ns
2522 integer, intent(in) :: nesf
2523 integer, intent(inout) :: nv
2524 real(real64), contiguous, intent(inout) :: pts(:,:)
2525 real(real64), contiguous, intent(out) :: ccc(:,:)
2526 real(real64), contiguous, intent(out) :: pp(:)
2527 real(real64), contiguous, intent(out) :: pp1(:)
2528 real(real64), intent(out) :: area
2529
2530 real(real64), parameter :: TOL = -1.0e-10_real64
2531 integer, parameter :: DIM_TEN = 10
2532
2533 integer :: intsph(1:DIM_TEN)
2534 integer :: nsfe1
2535 integer :: na
2536 integer :: icop
2537 integer :: ll
2538 integer :: iv1
2539 integer :: iv2
2540 integer :: ii
2541 integer :: icut
2542 integer :: jj
2543
2544 real(real64) :: p1(1:PCM_DIM_SPACE)
2545 real(real64) :: p2(1:PCM_DIM_SPACE)
2546 real(real64) :: p3(1:PCM_DIM_SPACE)
2547 real(real64) :: p4(1:PCM_DIM_SPACE)
2548 real(real64) :: point(1:PCM_DIM_SPACE)
2549 real(real64) :: pscr(1:PCM_DIM_SPACE,1:DIM_TEN)
2550 real(real64) :: cccp(1:PCM_DIM_SPACE,1:DIM_TEN)
2551 real(real64) :: pointl(1:PCM_DIM_SPACE,1:DIM_TEN)
2552 real(real64) :: diff(1:PCM_DIM_SPACE)
2553
2554 integer :: ind(1:DIM_TEN)
2555 integer :: ltyp(1:DIM_TEN)
2556 integer :: intscr(1:DIM_TEN)
2557
2558 real(real64) :: delr
2559 real(real64) :: delr2
2560 real(real64) :: rc
2561 real(real64) :: rc2
2562 real(real64) :: dnorm
2563 real(real64) :: dist
2564 real(real64) :: de2
2565
2566 push_sub(subtessera)
2567
2568 p1 = m_zero
2569 p2 = m_zero
2570 p3 = m_zero
2571 p4 = m_zero
2572 point = m_zero
2573 pscr = m_zero
2574 cccp = m_zero
2575 pointl = m_zero
2576 diff = m_zero
2577 area = m_zero
2578
2579 do jj = 1, 3
2580 ccc(1,jj) = sfe(ns)%x
2581 ccc(2,jj) = sfe(ns)%y
2582 ccc(3,jj) = sfe(ns)%z
2583 end do
2584
2585 intsph = ns
2586 do nsfe1 = 1, nesf
2587 if (nsfe1 == ns) cycle
2588 do jj = 1, nv
2589 intscr(jj) = intsph(jj)
2590 pscr(:,jj) = pts(:,jj)
2591 cccp(:,jj) = ccc(:,jj)
2592 end do
2593
2594 icop = 0
2595 ind = 0
2596 ltyp = 0
2597
2598 do ii = 1, nv
2599 delr2 = (pts(1,ii) - sfe(nsfe1)%x)**2 + (pts(2,ii) - sfe(nsfe1)%y)**2 + (pts(3,ii) - sfe(nsfe1)%z)**2
2600 delr = sqrt(delr2)
2601 if (delr < sfe(nsfe1)%r) then
2602 ind(ii) = 1
2603 icop = icop + 1
2604 end if
2605 end do
2606
2607 if (icop == nv) then
2608 pop_sub(subtessera)
2609 return
2610 end if
2611
2612 do ll = 1, nv
2613 iv1 = ll
2614 iv2 = ll+1
2615 if (ll == nv) iv2 = 1
2616 if ((ind(iv1) == 1) .and. (ind(iv2) == 1)) then
2617 ltyp(ll) = 0
2618 else if ((ind(iv1) == 0) .and. (ind(iv2) == 1)) then
2619 ltyp(ll) = 1
2620 else if ((ind(iv1) == 1) .and. (ind(iv2) == 0)) then
2621 ltyp(ll) = 2
2622 else if ((ind(iv1) == 0) .and. (ind(iv2) == 0)) then
2623 ltyp(ll) = 4
2624 diff = ccc(:,ll) - pts(:,ll)
2625 rc2 = dot_product(diff, diff)
2626 rc = sqrt(rc2)
2627
2628 do ii = 1, 11
2629 point = pts(:,iv1) + ii * (pts(:,iv2) - pts(:,iv1)) / 11
2630 point = point - ccc(:,ll)
2631 dnorm = norm2(point)
2632 point = point * rc / dnorm + ccc(:,ll)
2633
2634 dist = sqrt((point(1) - sfe(nsfe1)%x)**2 + (point(2) - sfe(nsfe1)%y)**2 + (point(3) - sfe(nsfe1)%z)**2)
2635
2636 if ((dist - sfe(nsfe1)%r) < tol) then
2637 ltyp(ll) = 3
2638 pointl(:, ll) = point
2639 exit
2640 end if
2641
2642 end do
2643 end if
2644 end do
2645
2646 icut = 0
2647 do ll = 1, nv
2648 if ((ltyp(ll) == 1) .or. (ltyp(ll) == 2)) icut = icut + 1
2649 if (ltyp(ll) == 3) icut = icut + 2
2650 end do
2651 icut = icut / 2
2652 if (icut > 1) then
2653 pop_sub(subtessera)
2654 return
2655 end if
2656
2657 na = 1
2658 do ll = 1, nv
2659
2660 if (ltyp(ll) == 0) cycle
2661 iv1 = ll
2662 iv2 = ll + 1
2663 if (ll == nv) iv2 = 1
2664
2665 if (ltyp(ll) == 1) then
2666 pts(:,na) = pscr(:,iv1)
2667 ccc(:,na) = cccp(:,iv1)
2668 intsph(na) = intscr(iv1)
2669 na = na + 1
2670 p1 = pscr(:,iv1)
2671 p2 = pscr(:,iv2)
2672 p3 = cccp(:,iv1)
2673
2674 call inter(sfe, p1, p2, p3, p4, nsfe1, 0)
2675 pts(:,na) = p4
2676
2677 de2 = (sfe(nsfe1)%x - sfe(ns)%x)**2 + ( sfe(nsfe1)%y - sfe(ns)%y)**2 + &
2678 (sfe(nsfe1)%z - sfe(ns)%z)**2
2679
2680 ccc(1,na) = sfe(ns)%x + ( sfe(nsfe1)%x - sfe(ns)%x)* &
2681 (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2682
2683 ccc(2,na) = sfe(ns)%y + ( sfe(nsfe1)%y - sfe(ns)%y)* &
2684 (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2685
2686 ccc(3,na) = sfe(ns)%z + ( sfe(nsfe1)%z - sfe(ns)%z)* &
2687 (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2688
2689 intsph(na) = nsfe1
2690 na = na + 1
2691 end if
2692
2693 if (ltyp(ll) == 2) then
2694 p1 = pscr(:,iv1)
2695 p2 = pscr(:,iv2)
2696 p3 = cccp(:,iv1)
2697
2698 call inter(sfe, p1, p2, p3, p4, nsfe1, 1)
2699 pts(:,na) = p4
2700 ccc(:,na) = cccp(:,iv1)
2701 intsph(na) = intscr(iv1)
2702 na = na + 1
2703 end if
2704
2705 if (ltyp(ll) == 3) then
2706 pts(:,na) = pscr(:,iv1)
2707 ccc(:,na) = cccp(:,iv1)
2708 intsph(na) = intscr(iv1)
2709 na = na + 1
2710 p1 = pscr(:,iv1)
2711 p2 = pointl(:,ll)
2712 p3 = cccp(:,iv1)
2713
2714 call inter(sfe, p1, p2, p3, p4, nsfe1, 0)
2715 pts(:,na) = p4
2716
2717 de2 = (sfe(nsfe1)%x - sfe(ns)%x)**2 + (sfe(nsfe1)%y - sfe(ns)%y)**2 + (sfe(nsfe1)%z - sfe(ns)%z)**2
2718
2719 ccc(1,na) = sfe(ns)%x + (sfe(nsfe1)%x - sfe(ns)%x) * (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2720
2721 ccc(2,na) = sfe(ns)%y + (sfe(nsfe1)%y - sfe(ns)%y) * (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2722
2723 ccc(3,na) = sfe(ns)%z + (sfe(nsfe1)%z - sfe(ns)%z) * (sfe(ns)%r**2 - sfe(nsfe1)%r**2 + de2) / (m_two*de2)
2724
2725 intsph(na) = nsfe1
2726 na = na + 1
2727 p1 = pointl(:,ll)
2728 p2 = pscr(:,iv2)
2729 p3 = cccp(:,iv1)
2730
2731 call inter(sfe, p1, p2, p3, p4, nsfe1, 1)
2732 pts(:,na) = p4
2733 ccc(:,na) = cccp(:,iv1)
2734 intsph(na) = intscr(iv1)
2735 na = na + 1
2736 end if
2737
2738 if (ltyp(ll) == 4) then
2739 pts(:,na) = pscr(:,iv1)
2740 ccc(:,na) = cccp(:,iv1)
2741 intsph(na) = intscr(iv1)
2742 na = na + 1
2743 end if
2744 end do
2745
2746 nv = na - 1
2747 if (nv > 10) then
2748 message(1) = "Too many vertices on the tessera"
2749 call messages_fatal(1)
2750 end if
2751 end do
2752
2753 call gaubon(sfe, nv, ns, pts, ccc, pp, pp1, area, intsph)
2754
2755 pop_sub(subtessera)
2756 end subroutine subtessera
2757
2758 ! -----------------------------------------------------------------------------
2759
2763 subroutine inter(sfe, p1, p2, p3, p4, ns, ia)
2764 type(pcm_sphere_t), intent(in) :: sfe(:)
2765 real(real64), intent(in) :: p1(1:PCM_DIM_SPACE)
2766 real(real64), intent(in) :: p2(1:PCM_DIM_SPACE)
2767 real(real64), intent(in) :: p3(1:PCM_DIM_SPACE)
2768 real(real64), intent(out) :: p4(1:PCM_DIM_SPACE)
2769 integer, intent(in) :: ns
2770 integer, intent(in) :: ia
2771
2772 real(real64), parameter :: TOL = 1.0e-08_real64
2773
2774 integer :: m_iter
2775 real(real64) :: r
2776 real(real64) :: alpha
2777 real(real64) :: delta
2778 real(real64) :: dnorm
2779 real(real64) :: diff
2780 real(real64) :: diff_vec(1:PCM_DIM_SPACE)
2781 logical :: band_iter
2782
2783 push_sub(inter)
2784
2785 diff_vec = p1 - p3
2786 r = norm2(diff_vec)
2787
2788 alpha = m_half
2789 delta = m_zero
2790 m_iter = 1
2791
2792 band_iter = .false.
2793 do while(.not.(band_iter))
2794 if (m_iter > 1000) then
2795 message(1) = "Too many iterations inside subrotuine inter"
2796 call messages_fatal(1)
2797 end if
2798
2799 band_iter = .true.
2800
2801 alpha = alpha + delta
2802
2803 p4 = p1 + alpha*(p2 - p1) - p3
2804 dnorm = norm2(p4)
2805 p4 = p4*r/dnorm + p3
2806 diff = (p4(1) - sfe(ns)%x)**2 + (p4(2) - sfe(ns)%y)**2 + (p4(3) - sfe(ns)%z)**2
2807 diff = sqrt(diff) - sfe(ns)%r
2808
2809 if (abs(diff) < tol) then
2810 pop_sub(inter)
2811 return
2812 end if
2813
2814 if (ia == 0) then
2815 if (diff > m_zero) delta = m_one/(m_two**(m_iter + 1))
2816 if (diff < m_zero) delta = -m_one/(m_two**(m_iter + 1))
2817 m_iter = m_iter + 1
2818 band_iter = .false.
2819 end if
2820
2821 if (ia == 1) then
2822 if (diff > m_zero) delta = -m_one/(m_two**(m_iter + 1))
2823 if (diff < m_zero) delta = m_one/(m_two**(m_iter + 1))
2824 m_iter = m_iter + 1
2825 band_iter = .false.
2826 end if
2827 end do
2828
2829 pop_sub(inter)
2830 end subroutine inter
2831
2832 ! -----------------------------------------------------------------------------
2833
2840 subroutine gaubon(sfe, nv, ns, pts, ccc, pp, pp1, area, intsph)
2841 type(pcm_sphere_t), contiguous, intent(in) :: sfe(:)
2842 real(real64), contiguous, intent(in) :: pts(:,:)
2843 real(real64), contiguous, intent(in) :: ccc(:,:)
2844 real(real64), contiguous, intent(inout) :: pp(:)
2845 real(real64), contiguous, intent(inout) :: pp1(:)
2846 integer, contiguous, intent(in) :: intsph(:)
2847 real(real64), intent(out) :: area
2848 integer, intent(in) :: nv
2849 integer, intent(in) :: ns
2850
2851 real(real64) :: p1(1:PCM_DIM_SPACE), p2(1:PCM_DIM_SPACE), p3(1:PCM_DIM_SPACE)
2852 real(real64) :: u1(1:PCM_DIM_SPACE), u2(1:PCM_DIM_SPACE)
2853 real(real64) :: point_1(1:PCM_DIM_SPACE), point_2(1:PCM_DIM_SPACE)
2854 real(real64) :: tpi, sum1, dnorm, dnorm1, dnorm2
2855 real(real64) :: cosphin, phin, costn, sum2, betan
2856 integer :: nsfe1, ia, nn, n0, n1, n2
2857
2858 push_sub(gaubon)
2859
2860 point_1 = m_zero
2861 point_2 = m_zero
2862 p1 = m_zero
2863 p2 = m_zero
2864 p3 = m_zero
2865 u1 = m_zero
2866 u2 = m_zero
2867
2868 tpi = m_two*m_pi
2869 sum1 = m_zero
2870 do nn = 1, nv
2871 point_1 = pts(:,nn) - ccc(:,nn)
2872 if (nn < nv) then
2873 point_2 = pts(:,nn+1) - ccc(:,nn)
2874 else
2875 point_2 = pts(:,1) - ccc(:,nn)
2876 end if
2877
2878 dnorm1 = norm2(point_1)
2879 dnorm2 = norm2(point_2)
2880 cosphin = dot_product(point_1, point_2) / (dnorm1*dnorm2)
2881
2882 if (cosphin > m_one) cosphin = m_one
2883 if (cosphin < -m_one) cosphin = -m_one
2884
2885 phin = acos(cosphin)
2886 nsfe1 = intsph(nn)
2887
2888 point_1(1) = sfe(nsfe1)%x - sfe(ns)%x
2889 point_1(2) = sfe(nsfe1)%y - sfe(ns)%y
2890 point_1(3) = sfe(nsfe1)%z - sfe(ns)%z
2891
2892 dnorm1 = norm2(point_1)
2893
2894 if (abs(dnorm1) <= m_epsilon) dnorm1 = m_one
2895
2896 point_2(1) = pts(1,nn) - sfe(ns)%x
2897 point_2(2) = pts(2,nn) - sfe(ns)%y
2898 point_2(3) = pts(3,nn) - sfe(ns)%z
2899
2900 dnorm2 = norm2(point_2)
2901
2902 costn = dot_product(point_1, point_2) / (dnorm1 * dnorm2)
2903 sum1 = sum1 + phin * costn
2904 end do
2905
2906 sum2 = m_zero
2908 do nn = 1, nv
2909 p1 = m_zero
2910 p2 = m_zero
2911 p3 = m_zero
2913 n1 = nn
2914 if (nn > 1) n0 = nn - 1
2915 if (nn == 1) n0 = nv
2916 if (nn < nv) n2 = nn + 1
2917 if (nn == nv) n2 = 1
2918
2919 p1 = pts(:,n1) - ccc(:,n0)
2920 p2 = pts(:,n0) - ccc(:,n0)
2921 call vecp(p1, p2, p3, dnorm)
2922 p2 = p3
2923
2924 call vecp(p1, p2, p3, dnorm)
2925 u1 = p3/dnorm
2926
2927 p1 = pts(:,n1) - ccc(:,n1)
2928 p2 = pts(:,n2) - ccc(:,n1)
2929 call vecp(p1, p2, p3, dnorm)
2930 p2 = p3
2931
2932 call vecp(p1, p2, p3, dnorm)
2933 u2 = p3/dnorm
2934
2935 betan = acos(dot_product(u1, u2))
2936 sum2 = sum2 + (m_pi - betan)
2937 end do
2938
2940 area = sfe(ns)%r*sfe(ns)%r*(tpi + sum1 - sum2)
2941
2943 pp = m_zero
2944
2945 do ia = 1, nv
2946 pp(1) = pp(1) + (pts(1,ia) - sfe(ns)%x)
2947 pp(2) = pp(2) + (pts(2,ia) - sfe(ns)%y)
2948 pp(3) = pp(3) + (pts(3,ia) - sfe(ns)%z)
2949 end do
2950
2951 dnorm = norm2(pp)
2952
2953 pp(1) = sfe(ns)%x + pp(1) * sfe(ns)%r / dnorm
2954 pp(2) = sfe(ns)%y + pp(2) * sfe(ns)%r / dnorm
2955 pp(3) = sfe(ns)%z + pp(3) * sfe(ns)%r / dnorm
2956
2958 pp1(1) = (pp(1) - sfe(ns)%x) / sfe(ns)%r
2959 pp1(2) = (pp(2) - sfe(ns)%y) / sfe(ns)%r
2960 pp1(3) = (pp(3) - sfe(ns)%z) / sfe(ns)%r
2961
2963 if (area < m_zero) area = m_zero
2964
2965 pop_sub(gaubon)
2966 end subroutine gaubon
2967
2968 ! -----------------------------------------------------------------------------
2969
2971 subroutine vecp(p1, p2, p3, dnorm)
2972 real(real64), contiguous, intent(in) :: P1(:)
2973 real(real64), contiguous, intent(in) :: P2(:)
2974 real(real64), contiguous, intent(out) :: P3(:)
2975 real(real64), intent(out) :: dnorm
2976
2977 p3 = m_zero
2978 p3(1) = p1(2)*p2(3) - p1(3)*p2(2)
2979 p3(2) = p1(3)*p2(1) - p1(1)*p2(3)
2980 p3(3) = p1(1)*p2(2) - p1(2)*p2(1)
2981
2982 dnorm = norm2(p3)
2983
2984 end subroutine vecp
2985
2986 subroutine pcm_end(pcm)
2987 type(pcm_t), intent(inout) :: pcm
2988
2989 integer :: asc_unit_test, asc_unit_test_sol, asc_unit_test_e, asc_unit_test_n, asc_unit_test_ext
2990 integer :: ia
2991
2992 push_sub(pcm_end)
2993
2994 if (pcm%solute .and. pcm%localf) then
2995 asc_unit_test = io_open(pcm_dir//'ASC.dat', pcm%namespace, action='write')
2996 asc_unit_test_sol = io_open(pcm_dir//'ASC_sol.dat', pcm%namespace, action='write')
2997 asc_unit_test_e = io_open(pcm_dir//'ASC_e.dat', pcm%namespace, action='write')
2998 asc_unit_test_n = io_open(pcm_dir//'ASC_n.dat', pcm%namespace, action='write')
2999 asc_unit_test_ext = io_open(pcm_dir//'ASC_ext.dat', pcm%namespace, action='write')
3000 do ia = 1, pcm%n_tesserae
3001 write(asc_unit_test,*) pcm%tess(ia)%point, pcm%q_e(ia) + pcm%q_n(ia) + pcm%q_ext(ia), ia
3002 write(asc_unit_test_sol,*) pcm%tess(ia)%point, pcm%q_e(ia) + pcm%q_n(ia), ia
3003 write(asc_unit_test_e,*) pcm%tess(ia)%point, pcm%q_e(ia), ia
3004 write(asc_unit_test_n,*) pcm%tess(ia)%point, pcm%q_n(ia), ia
3005 write(asc_unit_test_ext,*) pcm%tess(ia)%point, pcm%q_ext(ia), ia
3006 end do
3007 call io_close(asc_unit_test)
3008 call io_close(asc_unit_test_sol)
3009 call io_close(asc_unit_test_e)
3010 call io_close(asc_unit_test_n)
3011 call io_close(asc_unit_test_ext)
3012
3013 else if (pcm%solute .and. .not. pcm%localf) then
3014 asc_unit_test_sol = io_open(pcm_dir//'ASC_sol.dat', pcm%namespace, action='write')
3015 asc_unit_test_e = io_open(pcm_dir//'ASC_e.dat', pcm%namespace, action='write')
3016 asc_unit_test_n = io_open(pcm_dir//'ASC_n.dat', pcm%namespace, action='write')
3017 do ia = 1, pcm%n_tesserae
3018 write(asc_unit_test_sol,*) pcm%tess(ia)%point, pcm%q_e(ia) + pcm%q_n(ia), ia
3019 write(asc_unit_test_e,*) pcm%tess(ia)%point, pcm%q_e(ia), ia
3020 write(asc_unit_test_n,*) pcm%tess(ia)%point, pcm%q_n(ia), ia
3021 end do
3022 call io_close(asc_unit_test_sol)
3023 call io_close(asc_unit_test_e)
3024 call io_close(asc_unit_test_n)
3025
3026 else if (.not. pcm%solute .and. pcm%localf) then
3027 asc_unit_test_ext = io_open(pcm_dir//'ASC_ext.dat', pcm%namespace, action='write')
3028 do ia = 1, pcm%n_tesserae
3029 write(asc_unit_test_ext,*) pcm%tess(ia)%point, pcm%q_ext(ia), ia
3030 end do
3031 call io_close(asc_unit_test_ext)
3032 end if
3033
3034 safe_deallocate_a(pcm%spheres)
3035 safe_deallocate_a(pcm%tess)
3036 safe_deallocate_a(pcm%matrix)
3037 if (.not. is_close(pcm%epsilon_infty, pcm%epsilon_0)) then
3038 safe_deallocate_a(pcm%matrix_d)
3039 end if
3040 safe_deallocate_a(pcm%q_e)
3041 safe_deallocate_a(pcm%q_e_in)
3042 safe_deallocate_a(pcm%q_n)
3043 safe_deallocate_a(pcm%v_e)
3044 safe_deallocate_a(pcm%v_n)
3045 safe_deallocate_a(pcm%v_e_rs)
3046 safe_deallocate_a(pcm%v_n_rs)
3047 if (pcm%localf) then
3048 safe_deallocate_a(pcm%matrix_lf)
3049 if (.not. is_close(pcm%epsilon_infty, pcm%epsilon_0)) then
3050 safe_deallocate_a(pcm%matrix_lf_d)
3051 end if
3052
3053 safe_deallocate_a(pcm%q_ext)
3054 safe_deallocate_a(pcm%q_ext_in)
3055 safe_deallocate_a(pcm%v_ext)
3056 safe_deallocate_a(pcm%v_ext_rs)
3057 if (pcm%kick_is_present) then
3058 safe_deallocate_a(pcm%q_kick)
3059 safe_deallocate_a(pcm%v_kick)
3060 safe_deallocate_a(pcm%v_kick_rs)
3061 end if
3062 end if
3063
3064 if (pcm%calc_method == pcm_calc_poisson) then
3065 safe_deallocate_a( pcm%rho_n)
3066 safe_deallocate_a( pcm%rho_e)
3067 if (pcm%localf) then
3068 safe_deallocate_a( pcm%rho_ext)
3069 if (pcm%kick_is_present) then
3070 safe_deallocate_a( pcm%rho_kick)
3071 end if
3072 end if
3073 end if
3074
3075 if (pcm%tdlevel == pcm_td_eom) call pcm_eom_end()
3076
3077 if (mpi_world%is_root()) call io_close(pcm%info_unit)
3078
3079 pop_sub(pcm_end)
3080 end subroutine pcm_end
3081
3082 ! -----------------------------------------------------------------------------
3084 logical function pcm_update(this) result(update)
3085 type(pcm_t), intent(inout) :: this
3086
3087 this%iter = this%iter + 1
3088 update = this%iter <= 6 .or. mod(this%iter, this%update_iter) == 0
3089
3090 end function pcm_update
3091
3092 ! -----------------------------------------------------------------------------
3094 real(real64) function pcm_get_vdw_radius(species, pcm_vdw_type, namespace) result(vdw_r)
3095 class(species_t), intent(in) :: species
3096 integer, intent(in) :: pcm_vdw_type
3097 type(namespace_t), intent(in) :: namespace
3098
3099 integer :: ia
3100 integer, parameter :: upto_xe = 54
3101 real(real64), save :: vdw_radii(1:upto_xe)
3102 ! by Stefan Grimme in J. Comput. Chem. 27: 1787-1799, 2006
3103 ! except for C, N and O, reported in J. Chem. Phys. 120, 3893 (2004).
3104 data (vdw_radii(ia), ia=1, upto_xe) / &
3105 !H He
3106 1.001_real64, 1.012_real64, &
3107 !Li Be B C N O F Ne
3108 0.825_real64, 1.408_real64, 1.485_real64, 2.000_real64, 1.583_real64, 1.500_real64, 1.287_real64, 1.243_real64, &
3109 !Na Mg Al Si P S Cl Ar
3110 1.144_real64, 1.364_real64, 1.639_real64, 1.716_real64, 1.705_real64, 1.683_real64, 1.639_real64, 1.595_real64, &
3111 !K Ca
3112 1.485_real64, 1.474_real64, &
3114 1.562_real64, 1.562_real64, &
3115 1.562_real64, 1.562_real64, &
3116 1.562_real64, 1.562_real64, &
3117 1.562_real64, 1.562_real64, &
3118 1.562_real64, 1.562_real64, &
3119 !Ga Ge As Se Br Kr
3120 1.650_real64, 1.727_real64, 1.760_real64, 1.771_real64, 1.749_real64, 1.727_real64, &
3121 !Rb Sr !> Y -- Cd <!
3122 1.628_real64, 1.606_real64, 1.639_real64, 1.639_real64, &
3123 1.639_real64, 1.639_real64, &
3124 1.639_real64, 1.639_real64, &
3125 1.639_real64, 1.639_real64, &
3126 1.639_real64, 1.639_real64, &
3127 !In Sn Sb Te I Xe
3128 2.672_real64, 1.804_real64, 1.881_real64, 1.892_real64, 1.892_real64, 1.881_real64 /
3129
3130 select case (pcm_vdw_type)
3131 case (pcm_vdw_optimized)
3132 if (species%get_z() > upto_xe) then
3133 write(message(1),'(a,a)') "The van der Waals radius is missing for element ", trim(species%get_label())
3134 write(message(2),'(a)') "Use PCMVdWRadii = pcm_vdw_species, for other vdw radii values"
3135 call messages_fatal(2, namespace=namespace)
3136 end if
3137 ia = int(species%get_z())
3138 vdw_r = vdw_radii(ia)*p_ang
3139
3140 case (pcm_vdw_species)
3141 vdw_r = species%get_vdw_radius()
3142 if (vdw_r < m_zero) then
3143 call messages_write('The default vdW radius for species '//trim(species%get_label())//':')
3144 call messages_write(' is not defined. ')
3145 call messages_write(' Add a positive vdW radius value in %Species block. ')
3146 call messages_fatal(namespace=namespace)
3147 end if
3148 end select
3149
3150 end function pcm_get_vdw_radius
3151
3152
3153 ! -----------------------------------------------------------------------------
3155 subroutine pcm_dipole(mu_pcm, q_pcm, tess, n_tess)
3156 real(real64), contiguous, intent(out) :: mu_pcm(:)
3157 real(real64), intent(in) :: q_pcm(:)
3158 integer, intent(in) :: n_tess
3159 type(pcm_tessera_t), contiguous, intent(in) :: tess(:)
3160
3161 integer :: ia
3162
3163 push_sub(pcm_dipole)
3164
3165 mu_pcm = m_zero
3166 do ia = 1, n_tess
3167 mu_pcm = mu_pcm + q_pcm(ia) * tess(ia)%point
3168 end do
3169
3170 pop_sub(pcm_dipole)
3171 end subroutine pcm_dipole
3172
3173 ! -----------------------------------------------------------------------------
3174 ! Driver function to evaluate eps(omega)
3175 subroutine pcm_eps(pcm, eps, omega)
3176 type(pcm_min_t), intent(in) :: pcm
3177 complex(real64), intent(out) :: eps
3178 real(real64), intent(in) :: omega
3179
3180 push_sub(pcm_eps)
3181
3182 if (pcm%tdlevel == pcm_td_eom) then
3183 if (pcm%which_eps == pcm_debye_model) then
3184 call pcm_eps_deb(eps, pcm%deb, omega)
3185 else if (pcm%which_eps == pcm_drude_model) then
3186 call pcm_eps_drl(eps, pcm%drl, omega)
3187 end if
3188 else if (pcm%tdlevel == pcm_td_neq) then
3189 eps = pcm%deb%eps_d
3190 else if (pcm%tdlevel == pcm_td_eq) then
3191 eps = pcm%deb%eps_0
3192 end if
3193
3194 pop_sub(pcm_eps)
3195 end subroutine pcm_eps
3196
3197 ! -----------------------------------------------------------------------------
3198
3199 subroutine pcm_min_input_parsing_for_spectrum(pcm, namespace)
3200 type(pcm_min_t), intent(out) :: pcm
3201 type(namespace_t), intent(in) :: namespace
3202
3204
3205 ! re-parsing PCM keywords
3206 call parse_variable(namespace, 'PCMCalculation', .false., pcm%run_pcm)
3207 call messages_print_with_emphasis(msg='PCM', namespace=namespace)
3208 call parse_variable(namespace, 'PCMLocalField', .false., pcm%localf)
3209 call messages_print_var_value("PCMLocalField", pcm%localf, namespace=namespace)
3210 if (pcm%localf) then
3211 call messages_experimental("PCM local field effects in the optical spectrum", namespace=namespace)
3212 call messages_write('Beware of possible numerical errors in the optical spectrum due to PCM local field effects,')
3213 call messages_new_line()
3214 call messages_write('particularly, when static and high-frequency values of the dielectric functions are large')
3215 call messages_write(' (>~10 in units of the vacuum permittivity \epsilon_0).')
3216 call messages_new_line()
3217 call messages_write('However, PCM local field effects in the optical spectrum work well for polar or non-polar solvents')
3218 call messages_new_line()
3219 call messages_write('in the nonequilibrium or equation-of-motion TD-PCM propagation schemes.')
3220 call messages_warning(namespace=namespace)
3221 end if
3222 call parse_variable(namespace, 'PCMTDLevel' , pcm_td_eq, pcm%tdlevel)
3223 call messages_print_var_value("PCMTDLevel", pcm%tdlevel, namespace=namespace)
3224
3225 ! reading dielectric function model parameters
3226 call parse_variable(namespace, 'PCMStaticEpsilon' , m_one, pcm%deb%eps_0)
3227 call messages_print_var_value("PCMStaticEpsilon", pcm%deb%eps_0, namespace=namespace)
3228 if (pcm%tdlevel == pcm_td_eom) then
3229 call parse_variable(namespace, 'PCMEpsilonModel', pcm_debye_model, pcm%which_eps)
3230 call messages_print_var_value("PCMEpsilonModel", pcm%which_eps, namespace=namespace)
3231 if (pcm%which_eps == pcm_debye_model) then
3232 call parse_variable(namespace, 'PCMDynamicEpsilon', pcm%deb%eps_0, pcm%deb%eps_d)
3233 call messages_print_var_value("PCMDynamicEpsilon", pcm%deb%eps_d, namespace=namespace)
3234 call parse_variable(namespace, 'PCMDebyeRelaxTime', m_zero, pcm%deb%tau)
3235 call messages_print_var_value("PCMDebyeRelaxTime", pcm%deb%tau, namespace=namespace)
3236 else if (pcm%which_eps == pcm_drude_model) then
3237 call parse_variable(namespace, 'PCMDrudeLOmega', sqrt(m_one/(pcm%deb%eps_0-m_one)), pcm%drl%w0)
3238 call messages_print_var_value("PCMDrudeLOmega", pcm%drl%w0, namespace=namespace)
3239 call parse_variable(namespace, 'PCMDrudeLDamping', m_zero, pcm%drl%gm)
3240 call messages_print_var_value("PCMDrudeLDamping", pcm%drl%gm, namespace=namespace)
3241 end if
3242 else if (pcm%tdlevel == pcm_td_neq) then
3243 call parse_variable(namespace, 'PCMDynamicEpsilon', pcm%deb%eps_0, pcm%deb%eps_d)
3244 call messages_print_var_value("PCMDynamicEpsilon", pcm%deb%eps_d, namespace=namespace)
3245 end if
3246
3249
3250 ! -----------------------------------------------------------------------------
3251 ! Debye dielectric function
3252 subroutine pcm_eps_deb(eps, deb, omega)
3253 complex(real64), intent(out) :: eps
3254 type(debye_param_t), intent(in) :: deb
3255 real(real64), intent(in) :: omega
3256
3257 push_sub(pcm_eps_deb)
3258
3259 eps = deb%eps_d + (deb%eps_0 - deb%eps_d)/(m_one + (omega*deb%tau)**2) + &
3260 m_zi*omega*deb%tau*(deb%eps_0 - deb%eps_d)/(m_one + (omega*deb%tau)**2)
3261
3262 pop_sub(pcm_eps_deb)
3263 end subroutine pcm_eps_deb
3264
3265 ! -----------------------------------------------------------------------------
3266 ! Drude-Lorentz dielectric function
3267 subroutine pcm_eps_drl(eps, drl, omega)
3268 complex(real64), intent(out) :: eps
3269 type(drude_param_t), intent(in) :: drl
3270 real(real64), intent(in) :: omega
3272 push_sub(pcm_eps_drl)
3273
3274 eps = m_one + (drl%w0**2 - omega**2)*drl%aa/((drl%w0**2 - omega**2)**2 + (omega*drl%gm)**2) + &
3275 m_zi*omega*drl%gm*drl%aa/((drl%w0**2 - omega**2)**2 + (omega*drl%gm)**2)
3276
3277 pop_sub(pcm_eps_drl)
3278 end subroutine pcm_eps_drl
3279
3280end module pcm_oct_m
3281
3282!! Local Variables:
3283!! mode: f90
3284!! coding: utf-8
3285!! End:
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:158
double acos(double __x) __attribute__((__nothrow__
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 floor(double __x) __attribute__((__nothrow__
type(debug_t), save, public debug
Definition: debug.F90:133
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_four
Definition: global.F90:177
real(real64), parameter, public p_a_b
some physical constants
Definition: global.F90:210
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
character(len= *), parameter, public pcm_dir
Definition: global.F90:261
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public m_one
Definition: global.F90:174
This module implements the underlying real-space grid.
Definition: grid.F90:96
This module implements the index, used for the mesh points.
Definition: index.F90:101
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.
integer(int64) function, public io_function_fill_how(where)
Use this function to quickly plot functions for debugging purposes: call dio_function_output(io_funct...
Definition: io.F90:93
subroutine, public io_close(iunit, grp)
Definition: io.F90:444
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:338
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:379
subroutine, public layer_pcm_substrate_end(substrate)
Definition: layer_pcm.F90:573
subroutine, public layer_pcm_substrate_init(substrate, namespace)
Parses the substrate.
Definition: layer_pcm.F90:287
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
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines various routines, operating on mesh functions.
subroutine, public mesh_interpolation_init(this, mesh)
subroutine, public mesh_interpolation_end(this)
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
integer function, public mesh_local_index_from_coords(mesh, ix)
This function returns the local index of the point for a given vector of integer coordinates.
Definition: mesh.F90:924
integer(int64) function, public mesh_global_index_from_coords(mesh, ix)
This function returns the true global index of the point for a given vector of integer coordinates.
Definition: mesh.F90:905
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
Definition: mesh.F90:324
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:878
character(len=512), private msg
Definition: messages.F90:143
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_new_line()
Definition: messages.F90:1069
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:317
Some general things and nomenclature:
Definition: par_vec.F90:150
integer, parameter, public pcm_external_plus_kick
Definition: pcm_eom.F90:151
integer, parameter, public pcm_electrons
Definition: pcm_eom.F90:151
integer, parameter, public pcm_kick
Definition: pcm_eom.F90:151
integer, parameter, public pcm_nuclei
Definition: pcm_eom.F90:151
type(drude_param_t) drl
Definition: pcm_eom.F90:160
subroutine, public pcm_charges_propagation(q_t, pot_t, this_dt, this_cts_act, input_asc, this_eom, this_eps, namespace, this_deb, this_drl)
Driving subroutine for the Equation of Motion (EOM) propagation of the polarization charges within th...
Definition: pcm_eom.F90:212
type(debye_param_t) deb
Definition: pcm_eom.F90:159
integer which_eps
flag for Debye (PCM_DEBYE_MODEL) and Drude-Lorentz (PCM_DRUDE_MODEL) models
Definition: pcm_eom.F90:166
integer, parameter, public pcm_external_potential
Definition: pcm_eom.F90:151
integer, parameter, public pcm_drude_model
Definition: pcm_eom.F90:147
subroutine, public pcm_eom_enough_initial(not_yet_called)
Definition: pcm_eom.F90:917
integer, parameter, public pcm_debye_model
Definition: pcm_eom.F90:147
subroutine, public pcm_calc_pot_rs(pcm, mesh, psolver, ions, v_h, v_ext, kick, time_present, kick_time)
Definition: pcm.F90:1205
real(real64), dimension(:,:), allocatable s_mat_act
S_I matrix.
Definition: pcm.F90:248
subroutine pcm_eps_deb(eps, deb, omega)
Definition: pcm.F90:3325
logical function, public pcm_update(this)
Update pcm potential.
Definition: pcm.F90:3157
subroutine, public pcm_pot_rs(pcm, v_pcm, q_pcm, rho, mesh, psolver)
Generates the potential 'v_pcm' in real-space.
Definition: pcm.F90:1873
integer, parameter n_tess_sphere
minimum number of tesserae per sphere
Definition: pcm.F90:269
real(real64), dimension(:,:), allocatable sigma
S_E matrix.
Definition: pcm.F90:250
subroutine pcm_eps_drl(eps, drl, omega)
Definition: pcm.F90:3340
logical function pcm_nn_in_mesh(pcm, mesh)
Check wether the nearest neighbor requested are in the mesh or not.
Definition: pcm.F90:1676
integer, parameter, public pcm_calc_direct
Definition: pcm.F90:261
subroutine, public pcm_charge_density(pcm, q_pcm, q_pcm_tot, mesh, rho)
Generates the polarization charge density smearing the charge with a gaussian distribution on the mes...
Definition: pcm.F90:1736
real(real64) function, public pcm_get_vdw_radius(species, pcm_vdw_type, namespace)
get the vdw radius
Definition: pcm.F90:3167
integer, parameter pcm_dim_space
The resulting cavity is discretized by a set of tesserae defined in 3d.
Definition: pcm.F90:164
subroutine, public pcm_dipole(mu_pcm, q_pcm, tess, n_tess)
Computes the dipole moment mu_pcm due to a distribution of charges q_pcm.
Definition: pcm.F90:3228
subroutine pcm_matrix(eps, tess, n_tess, pcm_mat, localf, substrate)
Generates the PCM response matrix. J. Tomassi et al. Chem. Rev. 105, 2999 (2005).
Definition: pcm.F90:1982
subroutine, public pcm_elect_energy(ions, pcm, E_int_ee, E_int_en, E_int_ne, E_int_nn, E_int_e_ext, E_int_n_ext)
Calculates the solute-solvent electrostatic interaction energy .
Definition: pcm.F90:1533
real(real64) function s_mat_elem_i(tessi, tessj)
electrostatic Green function in vacuo:
Definition: pcm.F90:2139
subroutine d_i_matrix(n_tess, tess)
Definition: pcm.F90:2119
integer, parameter, public pcm_td_eom
Definition: pcm.F90:256
subroutine, public pcm_charges(q_pcm, q_pcm_tot, v_cav, pcm_mat, n_tess, qtot_nominal, epsilon, renorm_charges, q_tot_tol, deltaQ)
Calculates the polarization charges at each tessera by using the response matrix 'pcm_mat',...
Definition: pcm.F90:1632
real(real64), dimension(:,:), allocatable d_mat_act
D_I matrix.
Definition: pcm.F90:249
integer, parameter pcm_vdw_species
Definition: pcm.F90:265
subroutine, public pcm_v_cav_li(v_cav, v_mesh, pcm, mesh)
Calculates the Hartree/external/kick potential at the tessera representative points by doing a 3D lin...
Definition: pcm.F90:1474
integer, parameter, public pcm_calc_poisson
Definition: pcm.F90:261
subroutine gaubon(sfe, nv, ns, pts, ccc, pp, pp1, area, intsph)
Use the Gauss-Bonnet theorem to calculate the area of the tessera with vertices 'pts(3,...
Definition: pcm.F90:2913
real(real64), dimension(:,:), allocatable mat_gamess
PCM matrix formatted to be inputed to GAMESS.
Definition: pcm.F90:254
subroutine pcm_poisson_sanity_check(pcm, mesh)
Check that all the required nearest neighbors are prensent in the mesh.
Definition: pcm.F90:1717
subroutine pcm_pot_rs_poisson(namespace, v_pcm, psolver, rho)
Generates the potential 'v_pcm' in real-space solving the poisson equation for rho.
Definition: pcm.F90:1914
real(real64) function d_mat_elem_i(tessi, tessj)
Gradient of the Green function in vacuo .
Definition: pcm.F90:2171
subroutine s_i_matrix(n_tess, tess)
Definition: pcm.F90:2100
subroutine pcm_pot_rs_direct(v_pcm, q_pcm, tess, n_tess, mesh, width_factor)
Generates the potential 'v_pcm' in real-space by direct sum.
Definition: pcm.F90:1930
logical gamess_benchmark
Decide to output pcm_matrix in a GAMESS format.
Definition: pcm.F90:253
subroutine, public pcm_eps(pcm, eps, omega)
Definition: pcm.F90:3248
subroutine, public pcm_v_nuclei_cav(v_n_cav, ions, tess, n_tess)
Calculates the classical electrostatic potential geneated by the nuclei at the tesserae....
Definition: pcm.F90:1503
subroutine, public pcm_end(pcm)
Definition: pcm.F90:3059
integer, parameter pcm_vdw_optimized
Definition: pcm.F90:265
real(real64), dimension(:,:), allocatable delta
D_E matrix in JCP 139, 024105 (2013).
Definition: pcm.F90:251
subroutine, public pcm_init(pcm, namespace, space, ions, grid, qtot, val_charge, external_potentials_present, kick_present)
Initializes the PCM calculation: reads the VdW molecular cavity and generates the PCM response matrix...
Definition: pcm.F90:277
integer, parameter, public pcm_td_neq
Definition: pcm.F90:256
subroutine vecp(p1, p2, p3, dnorm)
calculates the vectorial product p3 = p1 x p2
Definition: pcm.F90:3044
subroutine inter(sfe, p1, p2, p3, p4, ns, ia)
Finds the point 'p4', on the arc 'p1'-'p2' developed from 'p3', which is on the surface of sphere 'ns...
Definition: pcm.F90:2836
integer, parameter, public pcm_td_eq
Definition: pcm.F90:256
subroutine subtessera(sfe, ns, nesf, nv, pts, ccc, pp, pp1, area)
find the uncovered region for each tessera and computes the area, the representative point (pp) and t...
Definition: pcm.F90:2592
subroutine, public pcm_min_input_parsing_for_spectrum(pcm, namespace)
Definition: pcm.F90:3272
subroutine cav_gen(tess_sphere, tess_min_distance, nesf, sfe, nts, cts, unit_pcminfo)
It builds the solute cavity surface and calculates the vertices, representative points and areas of t...
Definition: pcm.F90:2215
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:909
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
Class implementing a box that is a union of spheres. We do this in a specific class instead of using ...
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:148
Holding parameters characterizing a stack of dielectric layers.
Definition: layer_pcm.F90:185
Describes mesh distribution to nodes.
Definition: mesh.F90:165
set of parameters for Debye dielectric model
Definition: pcm_eom.F90:132
set of parameters for Drude-Lorentz dielectric model
Definition: pcm_eom.F90:141
tesselation derived type
Definition: pcm_eom.F90:121
The cavity hosting the solute molecule is built from a set of interlocking spheres with optimized rad...
Definition: pcm.F90:155
int true(void)