26 use,
intrinsic :: iso_fortran_env
92 integer,
parameter :: PCM_DIM_SPACE = 3
96 logical,
public :: run_pcm
97 integer,
public :: tdlevel
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
146 logical,
public :: kick_like
147 integer :: initial_asc
148 real(real64) :: gaussian_width
150 integer,
public :: counter
151 character(len=80) :: input_cavity
152 integer :: update_iter
153 integer,
public :: iter
154 integer :: calc_method
156 real(real64),
public :: dt
178 real(real64),
allocatable ::
sigma(:,:)
179 real(real64),
allocatable ::
delta(:,:)
184 integer,
parameter :: &
189 integer,
parameter,
public :: &
193 integer,
parameter :: &
204 subroutine pcm_init(pcm, namespace, space, ions, grid, qtot, val_charge, external_potentials_present, kick_present)
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
228 logical :: add_spheres_h
229 logical :: changed_default_nn
231 integer :: default_nn
232 real(real64) :: max_area
238 pcm%kick_is_present = kick_present
243 pcm%kick_like = .false.
245 pcm%namespace => namespace
260 call parse_variable(namespace,
'PCMCalculation', .false., pcm%run_pcm)
261 if (pcm%run_pcm)
then
263 if (pcm%space%dim /= pcm_dim_space)
then
264 message(1) =
"PCM is only available for 3d calculations"
267 select type (box => grid%box)
270 message(1) =
"PCM is only available for BoxShape = minimum"
296 select case (pcm_vdw_type)
298 default_value = 1.2_real64
300 default_value =
m_one
311 call parse_variable(namespace,
'PCMRadiusScaling', default_value, pcm%scale_r)
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.')
338 call messages_write(
'To spare you some time, Octopus will proceed as if PCMCalculation = yes.')
360 call parse_variable(namespace,
'PCMDynamicEpsilon', pcm%epsilon_0, pcm%epsilon_infty)
383 call messages_write(
'Sorry, only Debye or Drude-Lorentz dielectric models are available.')
385 call messages_write(
'To spare you some time, Octopus will proceed with the default choice (Debye).')
387 call messages_write(
'You may change PCMEpsilonModel value for a Drude-Lorentz run.')
392 call messages_write(
'Sorry, inertial/dynamic polarization splitting scheme for TD-PCM')
395 call messages_write(
'require both static and dynamic dielectric constants,')
398 call messages_write(
'Octopus will run using TD-PCM version in equilibrium')
418 call parse_variable(namespace,
'PCMEoMInitialCharges', 0, pcm%initial_asc)
421 if (pcm%initial_asc /= 0)
then
425 call messages_write(
'Sorry, initial polarization charges can only be read')
429 call messages_write(
'Octopus will proceed as if PCMEoMInitialCharges = 0.')
436 pcm%deb%eps_0 = pcm%epsilon_0
437 pcm%deb%eps_d = pcm%epsilon_infty
454 (abs(pcm%deb%tau) <=
m_epsilon .or.
is_close(pcm%deb%eps_0, pcm%deb%eps_d)))
then
456 call messages_write(
'but you have not included all required Debye model parameters.')
458 call messages_write(
'You need PCMEpsilonStatic, PCMEpsilonDynamic')
459 call messages_write(
'and PCMDebyeRelaxTime for an EOM TD-PCM run.')
461 call messages_write(
'Octopus will run using TD-PCM version in equilibrium')
469 message(1) =
"PCMEpsilonStatic = 1 is incompatible with a Drude-Lorentz EOM-PCM run."
489 call messages_write(
'but this is incompatible with a Drude-Lorentz EOM-PCM run.')
492 call messages_write(
'Octopus will run using the default value of PCMDrudeLOmega.')
496 message(1) =
"PCMEpsilonStatic = 1 is incompatible with a Drude-Lorentz EOM-PCM run."
513 pcm%drl%aa = (pcm%epsilon_0 -
m_one)*pcm%drl%w0**2
525 call parse_variable(namespace,
'PCMLocalField', .false., pcm%localf)
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."
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.')
548 if (.not. pcm%localf)
then
549 message(1) =
"You have activated a PCM run without polarization effects. Octopus will halt."
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."
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."
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."
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."
596 call parse_variable(namespace,
'PCMUpdateIter', 1, pcm%update_iter)
620 call parse_variable(namespace,
'PCMRenormCharges', .false., pcm%renorm_charges)
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"
654 if (abs(pcm%gaussian_width) <=
m_epsilon)
then
655 message(1) =
"Info: PCM potential will be defined in terms of polarization point charges"
658 message(1) =
"Info: PCM potential is regularized to avoid Coulomb singularity"
680 if (pcm%input_cavity ==
'')
then
689 call parse_variable(namespace,
'PCMSpheresOnH', .false., add_spheres_h)
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
698 safe_allocate(pcm%spheres(1:pcm%n_spheres))
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
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)
715 pcm%spheres(pcm%n_spheres)%r = vdw_radius*pcm%scale_r
719 pcm%info_unit =
io_open(
pcm_dir//
'pcm_info.out', pcm%namespace, action=
'write')
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)')
'#'
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 '-------------------------------------------',
'----------'
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
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
755 call parse_variable(namespace,
'PCMTessSubdivider', 1, subdivider)
757 safe_allocate(dum2(1:subdivider*
n_tess_sphere*pcm%n_spheres))
767 call parse_variable(namespace,
'PCMTessMinDistance', 0.1_real64, min_distance)
771 call cav_gen(subdivider, min_distance, pcm%n_spheres, pcm%spheres, pcm%n_tesserae, dum2, pcm%info_unit)
773 safe_allocate(pcm%tess(1:pcm%n_tesserae))
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
782 pcm%tess = dum2(1:pcm%n_tesserae)
784 safe_deallocate_a(dum2)
786 message(1) =
"Info: van der Waals surface has been calculated"
792 iunit =
io_open(trim(pcm%input_cavity), pcm%namespace, action=
'read', status=
'old')
793 read(iunit,*) pcm%n_tesserae
795 if (pcm%n_tesserae > mxts)
then
796 write(
message(1),
'(a,I5,a,I5)')
"total number of tesserae", pcm%n_tesserae,
">", mxts
800 safe_allocate(pcm%tess(1:pcm%n_tesserae))
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
809 do ia = 1, pcm%n_tesserae
810 read(iunit,*) pcm%tess(ia)%point(1)
813 do ia = 1, pcm%n_tesserae
814 read(iunit,*) pcm%tess(ia)%point(2)
817 do ia = 1, pcm%n_tesserae
818 read(iunit,*) pcm%tess(ia)%point(3)
821 do ia = 1, pcm%n_tesserae
822 read(iunit,*) pcm%tess(ia)%area
825 do ia = 1, pcm%n_tesserae
826 read(iunit,*) pcm%tess(ia)%r_sphere
829 do ia = 1, pcm%n_tesserae
830 read(iunit,*) pcm%tess(ia)%normal
834 message(1) =
"Info: van der Waals surface has been read from " // trim(pcm%input_cavity)
839 cav_unit_test =
io_open(
pcm_dir//
'cavity_mol.xyz', pcm%namespace, action=
'write')
841 write (cav_unit_test,
'(2X,I4)') pcm%n_tesserae + ions%natoms
842 write (cav_unit_test,
'(2X)')
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
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
855 write(pcm%info_unit,
'(A1)')
'#'
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'
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'
869 cav_gamess_unit =
io_open(
pcm_dir//
'geom_cavity_gamess.out', pcm%namespace, action=
'write')
871 write(cav_gamess_unit,*) pcm%n_tesserae
873 do ia = 1, pcm%n_tesserae
874 write(cav_gamess_unit,*) pcm%tess(ia)%point(1)
877 do ia = 1, pcm%n_tesserae
878 write(cav_gamess_unit,*) pcm%tess(ia)%point(2)
881 do ia = 1, pcm%n_tesserae
882 write(cav_gamess_unit,*) pcm%tess(ia)%point(3)
885 do ia = 1, pcm%n_tesserae
886 write(cav_gamess_unit,*) pcm%tess(ia)%area
889 do ia = 1, pcm%n_tesserae
890 write(cav_gamess_unit,*) pcm%tess(ia)%r_sphere
893 do ia = 1, pcm%n_tesserae
894 write(cav_gamess_unit,*) pcm%tess(ia)%normal
902 safe_allocate(
mat_gamess(1:pcm%n_tesserae, 1:pcm%n_tesserae))
906 if (.not.
is_close(pcm%epsilon_infty, pcm%epsilon_0))
then
908 safe_allocate(pcm%matrix_d(1:pcm%n_tesserae, 1:pcm%n_tesserae))
911 call pcm_matrix(pcm%epsilon_infty, pcm%tess, pcm%n_tesserae, pcm%matrix_d, substrate=substrate%iset_dynamic())
914 pcmmat_gamess_unit =
io_open(
pcm_dir//
'pcm_matrix_gamess_dyn.out', pcm%namespace, action=
'write')
916 do jtess = 1, pcm%n_tesserae
917 do itess = 1, pcm%n_tesserae
918 write(pcmmat_gamess_unit,*)
mat_gamess(itess,jtess)
928 safe_allocate(pcm%matrix_lf_d(1:pcm%n_tesserae, 1:pcm%n_tesserae))
931 call pcm_matrix(pcm%epsilon_infty, pcm%tess, pcm%n_tesserae, pcm%matrix_lf_d, .
true., substrate=substrate%iset_dynamic())
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)
948 safe_allocate(pcm%matrix(1:pcm%n_tesserae, 1:pcm%n_tesserae))
951 call pcm_matrix(pcm%epsilon_0, pcm%tess, pcm%n_tesserae, pcm%matrix, substrate=substrate%iset_static())
954 pcmmat_unit =
io_open(
pcm_dir//
'pcm_matrix.out', pcm%namespace, action=
'write')
956 pcm%namespace, action=
'write')
958 do jtess = 1, pcm%n_tesserae
959 do itess = 1, pcm%n_tesserae
960 write(pcmmat_unit,*) pcm%matrix(itess,jtess)
975 safe_allocate(pcm%matrix_lf(1:pcm%n_tesserae, 1:pcm%n_tesserae))
978 call pcm_matrix(pcm%epsilon_0, pcm%tess, pcm%n_tesserae, pcm%matrix_lf, .
true., substrate=substrate%iset_static())
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)
993 message(1) =
"Info: PCM response matrices has been evaluated"
1017 do ia = 1, pcm%n_tesserae
1018 if (pcm%tess(ia)%area > max_area) max_area = pcm%tess(ia)%area
1022 default_nn = int(max_area*pcm%gaussian_width/minval(grid%spacing(1:pcm%space%dim)))
1024 changed_default_nn = .false.
1026 do ii = default_nn, 1, -1
1031 changed_default_nn = .
true.
1034 if (changed_default_nn)
then
1035 call messages_write(
'PCM nearest neighbors have been reduced from ')
1045 default_nn = pcm%tess_nn
1059 call parse_variable(namespace,
'PCMChargeSmearNN', default_nn, pcm%tess_nn)
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))
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))
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))
1094 safe_allocate(pcm%q_e_in(1:pcm%n_tesserae))
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))
1106 safe_allocate(pcm%q_ext_in(1:pcm%n_tesserae))
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))
1120 pcm%q_e_nominal = qtot
1121 pcm%q_n_nominal = val_charge
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
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
1143 integer,
save :: calc
1145 logical,
save :: input_asc_e
1146 logical,
save :: input_asc_ext
1151 logical,
save :: not_yet_called = .false.
1152 logical,
save :: is_time_for_kick = .false.
1153 logical,
save :: after_kick = .false.
1155 logical,
save :: td_calc_mode = .false.
1157 integer,
save :: asc_vs_t_unit_e
1159 character(len=23),
save :: asc_vs_t_unit_format
1160 character(len=16),
save :: asc_vs_t_unit_format_tail
1166 assert(
present(v_h) .or.
present(ions) .or.
present(v_ext) .or.
present(kick))
1171 if ((.not.
present(v_ext)) .and.
present(kick)) calc =
pcm_kick
1174 if (
present(time_present))
then
1175 if (time_present) td_calc_mode = .
true.
1178 if (
present(kick_time))
then
1179 is_time_for_kick = kick_time
1180 if (kick_time) after_kick = .
true.
1183 select case (pcm%initial_asc)
1185 input_asc_e = .
true.
1186 input_asc_ext = .false.
1188 input_asc_e = .false.
1189 input_asc_ext = .
true.
1191 input_asc_e = .
true.
1192 input_asc_ext = .
true.
1194 input_asc_e = .false.
1195 input_asc_ext = .false.
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)
1205 call pcm_pot_rs(pcm, pcm%v_n_rs, pcm%q_n, pcm%rho_n, mesh, psolver)
1210 if (td_calc_mode .and. .not.
is_close(pcm%epsilon_infty, pcm%epsilon_0) .and. pcm%tdlevel /=
pcm_td_eq)
then
1212 select case (pcm%tdlevel)
1214 select case (pcm%which_eps)
1224 pcm%qtot_e = sum(pcm%q_e)
1226 select case (pcm%iter)
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)
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)
1238 pcm%q_e_in = pcm%q_e - pcm%q_e_in
1239 pcm%qtot_e_in = pcm%qtot_e - pcm%qtot_e_in
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)
1245 pcm%q_e = pcm%q_e + pcm%q_e_in
1246 pcm%qtot_e = pcm%qtot_e + pcm%qtot_e_in
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)
1259 call pcm_pot_rs(pcm, pcm%v_e_rs, pcm%q_e, pcm%rho_e, mesh, psolver)
1269 if (td_calc_mode .and. .not.
is_close(pcm%epsilon_infty, pcm%epsilon_0) .and. pcm%tdlevel /=
pcm_td_eq)
then
1271 select case (pcm%tdlevel)
1273 select case (pcm%which_eps)
1276 pcm%which_eps, pcm%namespace, this_drl=pcm%drl)
1279 pcm%which_eps, pcm%namespace, this_deb=pcm%deb)
1283 pcm%qtot_ext = sum(pcm%q_ext)
1286 pcm%q_ext = pcm%q_ext + pcm%q_ext_in
1287 pcm%qtot_ext = pcm%qtot_ext + pcm%qtot_ext_in
1290 call pcm_charges(pcm%q_ext, pcm%qtot_ext, pcm%v_ext, pcm%matrix_lf_d, pcm%n_tesserae)
1294 pcm%q_ext = pcm%q_ext + pcm%q_ext_in
1295 pcm%qtot_ext = pcm%qtot_ext + pcm%qtot_ext_in
1302 call pcm_charges(pcm%q_ext, pcm%qtot_ext, pcm%v_ext, pcm%matrix_lf, pcm%n_tesserae)
1305 pcm%q_ext_in = pcm%q_ext
1306 pcm%qtot_ext_in = pcm%qtot_ext
1311 call pcm_pot_rs(pcm, pcm%v_ext_rs, pcm%q_ext, pcm%rho_ext, mesh, psolver)
1318 if (is_time_for_kick)
then
1323 if (pcm%kick_like)
then
1324 if (is_time_for_kick)
then
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)
1329 call pcm_charges(pcm%q_kick, pcm%qtot_kick, pcm%v_kick, pcm%matrix_lf, pcm%n_tesserae)
1341 if (after_kick)
then
1343 select case (pcm%which_eps)
1346 pcm%which_eps, pcm%namespace, this_drl=pcm%drl)
1349 pcm%which_eps, pcm%namespace, this_deb=pcm%deb)
1352 pcm%qtot_kick = sum(pcm%q_kick)
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
1371 pcm%q_ext = pcm%q_ext + pcm%q_kick
1372 pcm%v_ext_rs = pcm%v_ext_rs + pcm%v_kick_rs
1374 pcm%q_ext = pcm%q_kick
1375 pcm%v_ext_rs = pcm%v_kick_rs
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))
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)
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(:)
1417 do ia = 1, pcm%n_tesserae
1431 real(real64),
contiguous,
intent(out) :: v_n_cav(:)
1432 type(
ions_t),
intent(in) :: ions
1434 integer,
intent(in) :: n_tess
1436 real(real64) :: dist
1444 do ia = 1, ions%natoms
1446 dist = norm2(ions%pos(1:pcm_dim_space, ia) - tess(ik)%point)
1448 v_n_cav(ik) = v_n_cav(ik) - ions%charge(ia)/dist
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
1470 real(real64) :: dist, z_ia
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."
1484 else if (pcm%localf .and. (
present(e_int_e_ext) .and. &
1485 present(e_int_n_ext)))
then
1490 do ik = 1, pcm%n_tesserae
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)
1498 do ia = 1, ions%natoms
1500 dist = norm2(ions%pos(1:pcm_dim_space, ia) - pcm%tess(ik)%point)
1502 z_ia = -ions%charge(ia)
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
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
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)') &
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)') &
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
1572 real(real64) :: q_pcm_tot_norm
1573 real(real64) :: coeff
1580 q_pcm_tot = sum(q_pcm(1:n_tess))
1582 if (
present(qtot_nominal) .and.
present(epsilon) .and. &
1583 present(renorm_charges) .and.
present(q_tot_tol) .and.
present(deltaq))
then
1585 deltaq = abs(q_pcm_tot) - ((epsilon -
m_one)/epsilon) * abs(qtot_nominal)
1586 if ((renorm_charges) .and. (abs(deltaq) > q_tot_tol))
then
1588 coeff = sign(
m_one, qtot_nominal)*sign(
m_one, deltaq)
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)
1593 q_pcm_tot = q_pcm_tot_norm
1604 type(
pcm_t),
intent(in) :: pcm
1605 class(
mesh_t),
intent(in) :: mesh
1607 integer :: ia, nm(pcm%space%dim), ipt, i1, i2, i3
1608 real(real64) :: posrel(pcm%space%dim)
1609 integer(int64) :: pt
1614 do ia = 1, pcm%n_tesserae
1616 posrel(:) = pcm%tess(ia)%point(1:pcm%space%dim)/mesh%spacing(1:pcm%space%dim)
1618 nm(:) =
floor(posrel(:))
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
1628 if (pt <= 0 .or. pt > mesh%np_part_global)
then
1645 type(
pcm_t),
intent(in) :: pcm
1646 class(
mesh_t),
intent(in) :: mesh
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.'
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(:)
1671 real(real64) :: norm, qtot, rr, xx(pcm%space%dim), pp(pcm%space%dim)
1674 integer :: nm(pcm%space%dim)
1675 real(real64) :: posrel(pcm%space%dim)
1677 integer :: i1, i2, i3
1678 integer,
allocatable :: pt(:)
1679 real(real64),
allocatable :: lrho(:)
1680 logical :: inner_point, boundary_point
1688 npt = (2*pcm%tess_nn)**pcm%space%dim
1689 safe_allocate(pt(1:npt))
1690 safe_allocate(lrho(1:npt))
1695 do ia = 1, pcm%n_tesserae
1697 pp(:) = pcm%tess(ia)%point(1:pcm%space%dim)
1698 posrel(:) = pp(:)/mesh%spacing(1:pcm%space%dim)
1700 nm(:) =
floor(posrel(:))
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
1722 if (pt(ipt) > 0 .and. pt(ipt) <= mesh%np_part)
then
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
1728 if (boundary_point .or. inner_point)
then
1729 xx(:) = mesh%x(:, pt(ipt))
1735 xx(:) = mesh%x(:, pt(ipt))
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))
1746 call mesh%allreduce(lrho, npt)
1749 norm = sum(lrho(1:npt)) * mesh%volume_element
1751 norm = q_pcm(ia)/norm
1755 lrho(:) = lrho(:) * norm
1760 if (pt(ipt) > 0 .and. pt(ipt) <= mesh%np_part_global)
then
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)
1767 rho(pt(ipt)) = rho(pt(ipt)) + lrho(ipt)
1775 if (
debug%info)
then
1789 safe_deallocate_a(pt)
1790 safe_deallocate_a(lrho)
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
1815 select case (pcm%calc_method)
1817 call pcm_pot_rs_direct(v_pcm, q_pcm, pcm%tess, pcm%n_tesserae, mesh, pcm%gaussian_width)
1828 if (
debug%info)
then
1843 real(real64),
contiguous,
intent(inout) :: v_pcm(:)
1845 real(real64),
contiguous,
intent(inout) :: rho(:)
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
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
1870 real(real64) :: term
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)
1897 call mesh_r(mesh, ip, term, origin=tess(ia)%point)
1898 v_pcm(ip) = v_pcm(ip) + q_pcm(ia)/term
1909 subroutine pcm_matrix(eps, tess, n_tess, pcm_mat, localf, substrate)
1910 real(real64),
intent(in) :: eps
1912 integer,
intent(in) :: n_tess
1913 real(real64),
intent(out) :: pcm_mat(:,:)
1914 logical,
optional,
intent(in) :: localf
1918 integer,
allocatable :: iwork(:)
1919 real(real64),
allocatable :: mat_tmp(:,:)
1921 real(real64) :: sgn_lf
1926 safe_allocate(
s_mat_act(1:n_tess, 1:n_tess))
1930 safe_allocate(
sigma(1:n_tess, 1:n_tess))
1934 safe_allocate(
d_mat_act(1:n_tess, 1:n_tess))
1938 safe_allocate(
delta(1:n_tess, 1:n_tess))
1941 if(
present(substrate))
then
1947 if (
present(localf))
then
1948 if (localf) sgn_lf = -
m_one
1955 pcm_mat(i,i) = pcm_mat(i,i) +
m_two*
m_pi
1960 safe_allocate(iwork(1:n_tess))
1965 call dgesv(n_tess, n_tess,
s_mat_act, n_tess, iwork, pcm_mat, n_tess, info)
1967 safe_deallocate_a(iwork)
1973 pcm_mat = -matmul(
sigma, pcm_mat)
1976 pcm_mat(i,i) = pcm_mat(i,i) +
m_two*
m_pi
1979 pcm_mat = pcm_mat - sgn_lf *
delta
1981 safe_allocate(mat_tmp(1:n_tess,1:n_tess))
1984 safe_allocate(
d_mat_act(1:n_tess,1:n_tess))
1989 mat_tmp = matmul(
sigma, mat_tmp)
1995 safe_allocate(
s_mat_act(1:n_tess, 1:n_tess))
2001 safe_deallocate_a(
sigma)
2002 safe_deallocate_a(
delta)
2004 safe_allocate(iwork(1:n_tess))
2008 call dgesv(n_tess, n_tess, mat_tmp, n_tess, iwork, pcm_mat, n_tess, info)
2010 safe_deallocate_a(iwork)
2011 safe_deallocate_a(mat_tmp)
2013 pcm_mat = - sgn_lf * pcm_mat
2028 integer,
intent(in) :: n_tess
2047 integer,
intent(in) :: n_tess
2066 real(real64) function s_mat_elem_I(tessi, tessj)
2070 real(real64),
parameter :: M_SD_DIAG = 1.0694_real64
2071 real(real64),
parameter :: M_DIST_MIN = 0.1_real64
2073 real(real64) :: diff(1:PCM_DIM_SPACE)
2074 real(real64) :: dist
2075 real(real64) :: s_diag
2076 real(real64) :: s_off_diag
2081 diff = tessi%point - tessj%point
2087 s_mat_elem_i = s_diag
2089 if (dist > m_dist_min) s_off_diag =
m_one/dist
2090 s_mat_elem_i = s_off_diag
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
2102 real(real64),
parameter :: M_SD_DIAG = 1.0694_real64
2103 real(real64),
parameter :: M_DIST_MIN = 0.04_real64
2105 real(real64) :: diff(1:PCM_DIM_SPACE)
2106 real(real64) :: dist
2107 real(real64) :: d_diag
2108 real(real64) :: d_off_diag
2114 diff = tessi%point - tessj%point
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)
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
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
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
2157 real(real64),
save :: thev(1:dim_angles)
2158 real(real64),
save :: fiv(1:dim_angles)
2159 real(real64),
save :: fir
2179 integer :: isfet(1:dim_ten*dim_angles)
2197 real(real64) :: area
2198 real(real64) :: test2
2200 real(real64) :: dnorm
2210 real(real64) :: stot
2211 real(real64) :: prod
2214 logical :: band_iter
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, &
2238 data fir / 1.256637061_real64 /
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 /
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)')
'#'
2275 write(unit_pcminfo,
'(A1)')
'#'
2276 write(unit_pcminfo,
'(A35)')
'# Number of tesserae / sphere = 240'
2277 write(unit_pcminfo,
'(A1)')
'#'
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
2293 jvt1 = reshape(idum,(/6,60/))
2316 do ia = 1, dim_angles
2323 if (ja == 1) fi = fiv(ia)
2325 cv(ii,1) = sth*
cos(fi)
2326 cv(ii,2) = sth*
sin(fi)
2345 do i_tes = 1, tess_sphere
2346 if (tess_sphere == 1)
then
2351 if (i_tes == 1)
then
2355 elseif (i_tes == 2)
then
2359 elseif (i_tes == 3)
then
2363 elseif (i_tes == 4)
then
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
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
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
2386 call subtessera(sfe, nsfe, nesf, nv, pts ,ccc, pp, pp1, area)
2388 if (abs(area) <= m_epsilon) cycle
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
2402 if (abs(ast(its)) <= m_epsilon) cycle
2406 write(message(1),
'(a,I5,a,I5)')
"total number of tesserae", nn,
">",mxts
2407 call messages_warning(1)
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
2423 test2 = tess_min_distance*tess_min_distance
2426 do while (.not.(band_iter))
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)
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)
2441 rij = (xi - xj)**2 + (yi - yj)**2 + (zi - zj)**2
2443 if (rij > test2) cycle
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.'
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)
2456 cts(ia)%point(1) = xi
2457 cts(ia)%point(2) = yi
2458 cts(ia)%point(3) = zi
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
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)
2470 cts(ia)%area = cts(ia)%area + cts(ja)%area
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
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)')
'# '
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
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
2519 subroutine subtessera(sfe, ns, nesf, nv, pts, ccc, pp, pp1, area)
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
2530 real(real64),
parameter :: TOL = -1.0e-10_real64
2531 integer,
parameter :: DIM_TEN = 10
2533 integer :: intsph(1:DIM_TEN)
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)
2554 integer :: ind(1:DIM_TEN)
2555 integer :: ltyp(1:DIM_TEN)
2556 integer :: intscr(1:DIM_TEN)
2558 real(real64) :: delr
2559 real(real64) :: delr2
2562 real(real64) :: dnorm
2563 real(real64) :: dist
2580 ccc(1,jj) = sfe(ns)%x
2581 ccc(2,jj) = sfe(ns)%y
2582 ccc(3,jj) = sfe(ns)%z
2587 if (nsfe1 == ns) cycle
2589 intscr(jj) = intsph(jj)
2590 pscr(:,jj) = pts(:,jj)
2591 cccp(:,jj) = ccc(:,jj)
2599 delr2 = (pts(1,ii) - sfe(nsfe1)%x)**2 + (pts(2,ii) - sfe(nsfe1)%y)**2 + (pts(3,ii) - sfe(nsfe1)%z)**2
2601 if (delr < sfe(nsfe1)%r)
then
2607 if (icop == nv)
then
2615 if (ll == nv) iv2 = 1
2616 if ((ind(iv1) == 1) .and. (ind(iv2) == 1))
then
2618 else if ((ind(iv1) == 0) .and. (ind(iv2) == 1))
then
2620 else if ((ind(iv1) == 1) .and. (ind(iv2) == 0))
then
2622 else if ((ind(iv1) == 0) .and. (ind(iv2) == 0))
then
2624 diff = ccc(:,ll) - pts(:,ll)
2625 rc2 = dot_product(diff, diff)
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)
2634 dist =
sqrt((point(1) - sfe(nsfe1)%x)**2 + (point(2) - sfe(nsfe1)%y)**2 + (point(3) - sfe(nsfe1)%z)**2)
2636 if ((dist - sfe(nsfe1)%r) < tol)
then
2638 pointl(:, ll) = point
2648 if ((ltyp(ll) == 1) .or. (ltyp(ll) == 2)) icut = icut + 1
2649 if (ltyp(ll) == 3) icut = icut + 2
2660 if (ltyp(ll) == 0) cycle
2663 if (ll == nv) iv2 = 1
2665 if (ltyp(ll) == 1)
then
2666 pts(:,na) = pscr(:,iv1)
2667 ccc(:,na) = cccp(:,iv1)
2668 intsph(na) = intscr(iv1)
2674 call inter(sfe, p1, p2, p3, p4, nsfe1, 0)
2677 de2 = (sfe(nsfe1)%x - sfe(ns)%x)**2 + ( sfe(nsfe1)%y - sfe(ns)%y)**2 + &
2678 (sfe(nsfe1)%z - sfe(ns)%z)**2
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)
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)
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)
2693 if (ltyp(ll) == 2)
then
2698 call inter(sfe, p1, p2, p3, p4, nsfe1, 1)
2700 ccc(:,na) = cccp(:,iv1)
2701 intsph(na) = intscr(iv1)
2705 if (ltyp(ll) == 3)
then
2706 pts(:,na) = pscr(:,iv1)
2707 ccc(:,na) = cccp(:,iv1)
2708 intsph(na) = intscr(iv1)
2714 call inter(sfe, p1, p2, p3, p4, nsfe1, 0)
2717 de2 = (sfe(nsfe1)%x - sfe(ns)%x)**2 + (sfe(nsfe1)%y - sfe(ns)%y)**2 + (sfe(nsfe1)%z - sfe(ns)%z)**2
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)
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)
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)
2731 call inter(sfe, p1, p2, p3, p4, nsfe1, 1)
2733 ccc(:,na) = cccp(:,iv1)
2734 intsph(na) = intscr(iv1)
2738 if (ltyp(ll) == 4)
then
2739 pts(:,na) = pscr(:,iv1)
2740 ccc(:,na) = cccp(:,iv1)
2741 intsph(na) = intscr(iv1)
2748 message(1) =
"Too many vertices on the tessera"
2749 call messages_fatal(1)
2753 call gaubon(sfe, nv, ns, pts, ccc, pp, pp1, area, intsph)
2763 subroutine inter(sfe, p1, p2, p3, p4, ns, ia)
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
2772 real(real64),
parameter :: TOL = 1.0e-08_real64
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
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)
2801 alpha = alpha + delta
2803 p4 = p1 + alpha*(p2 - p1) - p3
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
2809 if (abs(diff) < tol)
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))
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))
2830 end subroutine inter
2840 subroutine gaubon(sfe, nv, ns, pts, ccc, pp, pp1, area, intsph)
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
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
2871 point_1 = pts(:,nn) - ccc(:,nn)
2873 point_2 = pts(:,nn+1) - ccc(:,nn)
2875 point_2 = pts(:,1) - ccc(:,nn)
2878 dnorm1 = norm2(point_1)
2879 dnorm2 = norm2(point_2)
2880 cosphin = dot_product(point_1, point_2) / (dnorm1*dnorm2)
2882 if (cosphin > m_one) cosphin = m_one
2883 if (cosphin < -m_one) cosphin = -m_one
2885 phin =
acos(cosphin)
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
2892 dnorm1 = norm2(point_1)
2894 if (abs(dnorm1) <= m_epsilon) dnorm1 = m_one
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
2900 dnorm2 = norm2(point_2)
2902 costn = dot_product(point_1, point_2) / (dnorm1 * dnorm2)
2903 sum1 = sum1 + phin * costn
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
2919 p1 = pts(:,n1) - ccc(:,n0)
2920 p2 = pts(:,n0) - ccc(:,n0)
2921 call vecp(p1, p2, p3, dnorm)
2924 call vecp(p1, p2, p3, dnorm)
2927 p1 = pts(:,n1) - ccc(:,n1)
2928 p2 = pts(:,n2) - ccc(:,n1)
2929 call vecp(p1, p2, p3, dnorm)
2932 call vecp(p1, p2, p3, dnorm)
2935 betan =
acos(dot_product(u1, u2))
2936 sum2 = sum2 + (m_pi - betan)
2940 area = sfe(ns)%r*sfe(ns)%r*(tpi + sum1 - sum2)
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)
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
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
2963 if (area < m_zero) area = m_zero
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
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)
2987 type(
pcm_t),
intent(inout) :: pcm
2989 integer :: asc_unit_test, asc_unit_test_sol, asc_unit_test_e, asc_unit_test_n, asc_unit_test_ext
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
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)
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
3022 call io_close(asc_unit_test_sol)
3023 call io_close(asc_unit_test_e)
3024 call io_close(asc_unit_test_n)
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
3031 call io_close(asc_unit_test_ext)
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)
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)
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)
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)
3075 if (pcm%tdlevel ==
pcm_td_eom)
call pcm_eom_end()
3077 if (mpi_world%is_root())
call io_close(pcm%info_unit)
3084 logical function pcm_update(this)
result(update)
3085 type(
pcm_t),
intent(inout) :: this
3087 this%iter = this%iter + 1
3088 update = this%iter <= 6 .or. mod(this%iter, this%update_iter) == 0
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
3100 integer,
parameter :: upto_xe = 54
3101 real(real64),
save :: vdw_radii(1:upto_xe)
3104 data (vdw_radii(ia), ia=1, upto_xe) / &
3106 1.001_real64, 1.012_real64, &
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, &
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, &
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, &
3120 1.650_real64, 1.727_real64, 1.760_real64, 1.771_real64, 1.749_real64, 1.727_real64, &
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, &
3128 2.672_real64, 1.804_real64, 1.881_real64, 1.892_real64, 1.892_real64, 1.881_real64 /
3130 select case (pcm_vdw_type)
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)
3137 ia = int(species%get_z())
3138 vdw_r = vdw_radii(ia)*p_ang
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)
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(:)
3167 mu_pcm = mu_pcm + q_pcm(ia) * tess(ia)%point
3175 subroutine pcm_eps(pcm, eps, omega)
3177 complex(real64),
intent(out) :: eps
3178 real(real64),
intent(in) :: omega
3183 if (pcm%which_eps == pcm_debye_model)
then
3185 else if (pcm%which_eps == pcm_drude_model)
then
3201 type(namespace_t),
intent(in) :: namespace
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)
3222 call parse_variable(namespace,
'PCMTDLevel' ,
pcm_td_eq, pcm%tdlevel)
3223 call messages_print_var_value(
"PCMTDLevel", pcm%tdlevel, namespace=namespace)
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)
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)
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)
3253 complex(real64),
intent(out) :: eps
3254 type(debye_param_t),
intent(in) :: deb
3255 real(real64),
intent(in) :: omega
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)
3268 complex(real64),
intent(out) :: eps
3269 type(drude_param_t),
intent(in) :: drl
3270 real(real64),
intent(in) :: omega
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)
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
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
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_four
real(real64), parameter, public p_a_b
some physical constants
real(real64), parameter, public m_pi
some mathematical constants
character(len= *), parameter, public pcm_dir
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
This module implements the index, used for the mesh points.
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...
subroutine, public io_close(iunit, grp)
subroutine, public io_mkdir(fname, namespace, parents)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
subroutine, public layer_pcm_substrate_end(substrate)
subroutine, public layer_pcm_substrate_init(substrate, namespace)
Parses the substrate.
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.
This module is intended to contain "only mathematical" functions and procedures.
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.
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.
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.
pure subroutine, public mesh_r(mesh, ip, rr, origin, coords)
return the distance to the origin for a given grid point
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
type(mpi_grp_t), public mpi_world
Some general things and nomenclature:
integer, parameter, public pcm_external_plus_kick
integer, parameter, public pcm_electrons
integer, parameter, public pcm_kick
integer, parameter, public pcm_nuclei
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...
integer which_eps
flag for Debye (PCM_DEBYE_MODEL) and Drude-Lorentz (PCM_DRUDE_MODEL) models
integer, parameter, public pcm_external_potential
integer, parameter, public pcm_drude_model
subroutine, public pcm_eom_enough_initial(not_yet_called)
integer, parameter, public pcm_debye_model
subroutine, public pcm_calc_pot_rs(pcm, mesh, psolver, ions, v_h, v_ext, kick, time_present, kick_time)
real(real64), dimension(:,:), allocatable s_mat_act
S_I matrix.
subroutine pcm_eps_deb(eps, deb, omega)
logical function, public pcm_update(this)
Update pcm potential.
subroutine, public pcm_pot_rs(pcm, v_pcm, q_pcm, rho, mesh, psolver)
Generates the potential 'v_pcm' in real-space.
integer, parameter n_tess_sphere
minimum number of tesserae per sphere
real(real64), dimension(:,:), allocatable sigma
S_E matrix.
subroutine pcm_eps_drl(eps, drl, omega)
logical function pcm_nn_in_mesh(pcm, mesh)
Check wether the nearest neighbor requested are in the mesh or not.
integer, parameter, public pcm_calc_direct
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...
real(real64) function, public pcm_get_vdw_radius(species, pcm_vdw_type, namespace)
get the vdw radius
integer, parameter pcm_dim_space
The resulting cavity is discretized by a set of tesserae defined in 3d.
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.
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).
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 .
real(real64) function s_mat_elem_i(tessi, tessj)
electrostatic Green function in vacuo:
subroutine d_i_matrix(n_tess, tess)
integer, parameter, public pcm_td_eom
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',...
real(real64), dimension(:,:), allocatable d_mat_act
D_I matrix.
integer, parameter pcm_vdw_species
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...
integer, parameter, public pcm_calc_poisson
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,...
real(real64), dimension(:,:), allocatable mat_gamess
PCM matrix formatted to be inputed to GAMESS.
subroutine pcm_poisson_sanity_check(pcm, mesh)
Check that all the required nearest neighbors are prensent in the mesh.
subroutine pcm_pot_rs_poisson(namespace, v_pcm, psolver, rho)
Generates the potential 'v_pcm' in real-space solving the poisson equation for rho.
real(real64) function d_mat_elem_i(tessi, tessj)
Gradient of the Green function in vacuo .
subroutine s_i_matrix(n_tess, tess)
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.
logical gamess_benchmark
Decide to output pcm_matrix in a GAMESS format.
subroutine, public pcm_eps(pcm, eps, omega)
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....
subroutine, public pcm_end(pcm)
integer, parameter pcm_vdw_optimized
real(real64), dimension(:,:), allocatable delta
D_E matrix in JCP 139, 024105 (2013).
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...
integer, parameter, public pcm_td_neq
subroutine vecp(p1, p2, p3, dnorm)
calculates the vectorial product p3 = p1 x p2
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...
integer, parameter, public pcm_td_eq
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...
subroutine, public pcm_min_input_parsing_for_spectrum(pcm, namespace)
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...
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
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.
Holding parameters characterizing a stack of dielectric layers.
Describes mesh distribution to nodes.
set of parameters for Debye dielectric model
set of parameters for Drude-Lorentz dielectric model
The cavity hosting the solute molecule is built from a set of interlocking spheres with optimized rad...