-
Notifications
You must be signed in to change notification settings - Fork 1
/
pme.F
683 lines (603 loc) · 29.6 KB
/
pme.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \par History
!> JGH (21-Mar-2001) : Complete rewrite
!> \author CJM and APSI
! **************************************************************************************************
MODULE pme
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE atprop_types, ONLY: atprop_type
USE bibliography, ONLY: cite_reference,&
darden1993
USE cell_types, ONLY: cell_type
USE dg_rho0_types, ONLY: dg_rho0_type
USE dg_types, ONLY: dg_get,&
dg_type
USE dgs, ONLY: dg_get_patch,&
dg_get_strucfac,&
dg_sum_patch,&
dg_sum_patch_force_1d,&
dg_sum_patch_force_3d
USE ewald_environment_types, ONLY: ewald_env_get,&
ewald_environment_type
USE ewald_pw_types, ONLY: ewald_pw_get,&
ewald_pw_type
USE kinds, ONLY: dp
USE mathconstants, ONLY: fourpi
USE message_passing, ONLY: mp_comm_type
USE particle_types, ONLY: particle_type
USE pme_tools, ONLY: get_center,&
set_list
USE pw_grid_types, ONLY: pw_grid_type
USE pw_methods, ONLY: pw_integral_a2b,&
pw_transfer
USE pw_poisson_methods, ONLY: pw_poisson_solve
USE pw_poisson_types, ONLY: pw_poisson_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE realspace_grid_types, ONLY: realspace_grid_desc_type,&
realspace_grid_type,&
rs_grid_create,&
rs_grid_release,&
rs_grid_set_box,&
rs_grid_zero,&
transfer_pw2rs,&
transfer_rs2pw
USE shell_potential_types, ONLY: shell_kind_type
USE structure_factor_types, ONLY: structure_factor_type
USE structure_factors, ONLY: structure_factor_allocate,&
structure_factor_deallocate,&
structure_factor_init
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: pme_evaluate
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pme'
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param ewald_env ...
!> \param ewald_pw ...
!> \param box ...
!> \param particle_set ...
!> \param vg_coulomb ...
!> \param fg_coulomb ...
!> \param pv_g ...
!> \param shell_particle_set ...
!> \param core_particle_set ...
!> \param fgshell_coulomb ...
!> \param fgcore_coulomb ...
!> \param use_virial ...
!> \param charges ...
!> \param atprop ...
!> \par History
!> JGH (15-Mar-2001) : New electrostatic calculation and pressure tensor
!> JGH (21-Mar-2001) : Complete rewrite
!> JGH (21-Mar-2001) : Introduced real space density type for future
!> parallelisation
!> \author CJM and APSI
! **************************************************************************************************
SUBROUTINE pme_evaluate(ewald_env, ewald_pw, box, particle_set, vg_coulomb, &
fg_coulomb, pv_g, shell_particle_set, core_particle_set, &
fgshell_coulomb, fgcore_coulomb, use_virial, charges, atprop)
TYPE(ewald_environment_type), POINTER :: ewald_env
TYPE(ewald_pw_type), POINTER :: ewald_pw
TYPE(cell_type), POINTER :: box
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
REAL(KIND=dp), INTENT(OUT) :: vg_coulomb
REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT), &
OPTIONAL :: fg_coulomb, pv_g
TYPE(particle_type), DIMENSION(:), OPTIONAL, &
POINTER :: shell_particle_set, core_particle_set
REAL(KIND=dp), DIMENSION(:, :), INTENT(OUT), &
OPTIONAL :: fgshell_coulomb, fgcore_coulomb
LOGICAL, INTENT(IN) :: use_virial
REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: charges
TYPE(atprop_type), POINTER :: atprop
CHARACTER(LEN=*), PARAMETER :: routineN = 'pme_evaluate'
INTEGER :: handle, i, ipart, j, npart, nshell, p1, &
p2
LOGICAL :: is1_core, is2_core
REAL(KIND=dp) :: alpha, dvols, fat1, ffa
REAL(KIND=dp), DIMENSION(3) :: fat
REAL(KIND=dp), DIMENSION(3, 3) :: f_stress, h_stress
TYPE(dg_rho0_type), POINTER :: dg_rho0
TYPE(dg_type), POINTER :: dg
TYPE(mp_comm_type) :: group
TYPE(pw_c1d_gs_type), DIMENSION(3) :: dphi_g
TYPE(pw_grid_type), POINTER :: grid_b, grid_s
TYPE(pw_poisson_type), POINTER :: poisson_env
TYPE(pw_pool_type), POINTER :: pw_big_pool, pw_small_pool
TYPE(pw_r3d_rs_type) :: phi_r, rhob_r, rhos1, rhos2
TYPE(realspace_grid_desc_type), POINTER :: rs_desc
TYPE(realspace_grid_type), DIMENSION(3) :: drpot
TYPE(realspace_grid_type), POINTER :: rden, rpot
TYPE(structure_factor_type) :: exp_igr
CALL timeset(routineN, handle)
NULLIFY (poisson_env, rden)
CALL cite_reference(Darden1993)
CALL ewald_env_get(ewald_env, alpha=alpha, group=group)
CALL ewald_pw_get(ewald_pw, pw_big_pool=pw_big_pool, &
pw_small_pool=pw_small_pool, rs_desc=rs_desc, &
poisson_env=poisson_env, dg=dg)
grid_b => pw_big_pool%pw_grid
grid_s => pw_small_pool%pw_grid
CALL dg_get(dg, dg_rho0=dg_rho0)
npart = SIZE(particle_set)
CALL structure_factor_init(exp_igr)
IF (PRESENT(shell_particle_set)) THEN
CPASSERT(ASSOCIATED(shell_particle_set))
CPASSERT(ASSOCIATED(core_particle_set))
nshell = SIZE(shell_particle_set)
CALL structure_factor_allocate(grid_s%bounds, npart, exp_igr, &
allocate_centre=.TRUE., allocate_shell_e=.TRUE., &
allocate_shell_centre=.TRUE., nshell=nshell)
ELSE
CALL structure_factor_allocate(grid_s%bounds, npart, exp_igr, &
allocate_centre=.TRUE.)
END IF
CALL pw_small_pool%create_pw(rhos1)
CALL pw_small_pool%create_pw(rhos2)
ALLOCATE (rden)
CALL rs_grid_create(rden, rs_desc)
CALL rs_grid_set_box(grid_b, rs=rden)
CALL rs_grid_zero(rden)
CPASSERT(ASSOCIATED(box))
IF (rden%desc%parallel .AND. rden%desc%distributed) THEN
CALL get_center(particle_set, box, exp_igr%centre, exp_igr%delta, grid_b%npts, 1)
END IF
IF (PRESENT(shell_particle_set) .AND. rden%desc%parallel .AND. rden%desc%distributed) THEN
CALL get_center(shell_particle_set, box, exp_igr%shell_centre, exp_igr%shell_delta, grid_b%npts, 1)
CALL get_center(core_particle_set, box, exp_igr%core_centre, exp_igr%core_delta, grid_b%npts, 1)
END IF
!-------------- DENSITY CALCULATION ----------------
ipart = 0
DO
CALL set_list(particle_set, npart, exp_igr%centre, p1, rden, ipart, exp_igr%core_centre)
CALL set_list(particle_set, npart, exp_igr%centre, p2, rden, ipart, exp_igr%core_centre)
IF (p1 == 0 .AND. p2 == 0) EXIT
is1_core = (particle_set(p1)%shell_index /= 0)
IF (p2 /= 0) THEN
is2_core = (particle_set(p2)%shell_index /= 0)
ELSE
is2_core = .FALSE.
END IF
! calculate function on small boxes (we use double packing in FFT)
IF (is1_core .OR. is2_core) THEN
CALL get_patch(dg, particle_set, exp_igr, box, p1, p2, grid_b, grid_s, &
rhos1, rhos2, is1_core=is1_core, is2_core=is2_core, &
core_particle_set=core_particle_set, charges=charges)
! add boxes to real space grid (big box)
IF (is1_core) THEN
CALL dg_sum_patch(rden, rhos1, exp_igr%core_centre(:, particle_set(p1)%shell_index))
ELSE
CALL dg_sum_patch(rden, rhos1, exp_igr%centre(:, p1))
END IF
IF (p2 /= 0 .AND. is2_core) THEN
CALL dg_sum_patch(rden, rhos2, exp_igr%core_centre(:, particle_set(p2)%shell_index))
ELSE IF (p2 /= 0) THEN
CALL dg_sum_patch(rden, rhos2, exp_igr%centre(:, p2))
END IF
ELSE
CALL get_patch(dg, particle_set, exp_igr, box, p1, p2, grid_b, grid_s, &
rhos1, rhos2, charges=charges)
! add boxes to real space grid (big box)
CALL dg_sum_patch(rden, rhos1, exp_igr%centre(:, p1))
IF (p2 /= 0) CALL dg_sum_patch(rden, rhos2, exp_igr%centre(:, p2))
END IF
END DO
IF (PRESENT(shell_particle_set)) THEN
ipart = 0
DO
CALL set_list(shell_particle_set, nshell, exp_igr%shell_centre, p1, rpot, ipart)
CALL set_list(shell_particle_set, nshell, exp_igr%shell_centre, p2, rpot, ipart)
IF (p1 == 0 .AND. p2 == 0) EXIT
! calculate function on small boxes (we use double packing in FFT)
CALL get_patch(dg, shell_particle_set, exp_igr, box, p1, p2, grid_b, grid_s, &
rhos1, rhos2, is1_shell=.TRUE., is2_shell=.TRUE., charges=charges)
! add boxes to real space grid (big box)
CALL dg_sum_patch(rpot, rhos1, exp_igr%shell_centre(:, p1))
IF (p2 /= 0) CALL dg_sum_patch(rpot, rhos2, exp_igr%shell_centre(:, p2))
END DO
END IF
CALL pw_big_pool%create_pw(rhob_r)
CALL transfer_rs2pw(rden, rhob_r)
!-------------- ELECTROSTATIC CALCULATION -----------
! allocate intermediate arrays
DO i = 1, 3
CALL pw_big_pool%create_pw(dphi_g(i))
END DO
CALL pw_big_pool%create_pw(phi_r)
CALL pw_poisson_solve(poisson_env, rhob_r, vg_coulomb, phi_r, dphi_g, h_stress)
! atomic energies
IF (atprop%energy) THEN
dvols = rhos1%pw_grid%dvol
ALLOCATE (rpot)
CALL rs_grid_create(rpot, rs_desc)
CALL transfer_pw2rs(rpot, phi_r)
ipart = 0
DO
CALL set_list(particle_set, npart, exp_igr%centre, p1, rden, ipart, exp_igr%core_centre)
CALL set_list(particle_set, npart, exp_igr%centre, p2, rden, ipart, exp_igr%core_centre)
IF (p1 == 0 .AND. p2 == 0) EXIT
! integrate box and potential
CALL get_patch(dg, particle_set, exp_igr, box, p1, p2, grid_b, grid_s, &
rhos1, rhos2, charges=charges)
! add boxes to real space grid (big box)
CALL dg_sum_patch_force_1d(rpot, rhos1, exp_igr%centre(:, p1), fat1)
IF (atprop%energy) THEN
atprop%atener(p1) = atprop%atener(p1) + 0.5_dp*fat1*dvols
END IF
IF (p2 /= 0) THEN
CALL dg_sum_patch_force_1d(rpot, rhos2, exp_igr%centre(:, p2), fat1)
IF (atprop%energy) THEN
atprop%atener(p2) = atprop%atener(p2) + 0.5_dp*fat1*dvols
END IF
END IF
END DO
CALL rs_grid_release(rpot)
DEALLOCATE (rpot)
END IF
CALL pw_big_pool%give_back_pw(phi_r)
!---------- END OF ELECTROSTATIC CALCULATION --------
!------------- STRESS TENSOR CALCULATION ------------
IF ((use_virial) .AND. (PRESENT(pv_g))) THEN
DO i = 1, 3
DO j = i, 3
f_stress(i, j) = pw_integral_a2b(dphi_g(i), dphi_g(j))
f_stress(j, i) = f_stress(i, j)
END DO
END DO
ffa = (1.0_dp/fourpi)*(0.5_dp/dg_rho0%zet(1))**2
f_stress = -ffa*f_stress
pv_g = h_stress + f_stress
END IF
!--------END OF STRESS TENSOR CALCULATION -----------
DO i = 1, 3
CALL rs_grid_create(drpot(i), rs_desc)
CALL rs_grid_set_box(grid_b, rs=drpot(i))
CALL pw_transfer(dphi_g(i), rhob_r)
CALL pw_big_pool%give_back_pw(dphi_g(i))
CALL transfer_pw2rs(drpot(i), rhob_r)
END DO
CALL pw_big_pool%give_back_pw(rhob_r)
!----------------- FORCE CALCULATION ----------------
! initialize the forces
IF (PRESENT(fg_coulomb)) THEN
fg_coulomb = 0.0_dp
dvols = rhos1%pw_grid%dvol
ipart = 0
DO
CALL set_list(particle_set, npart, exp_igr%centre, p1, rden, ipart, exp_igr%core_centre)
CALL set_list(particle_set, npart, exp_igr%centre, p2, rden, ipart, exp_igr%core_centre)
IF (p1 == 0 .AND. p2 == 0) EXIT
is1_core = (particle_set(p1)%shell_index /= 0)
IF (p2 /= 0) THEN
is2_core = (particle_set(p2)%shell_index /= 0)
ELSE
is2_core = .FALSE.
END IF
! calculate function on small boxes (we use double packing in FFT)
CALL get_patch_again(dg, particle_set, exp_igr, p1, p2, rhos1, rhos2, &
is1_core=is1_core, is2_core=is2_core, charges=charges)
! sum boxes on real space grids (big box)
IF (is1_core) THEN
CALL dg_sum_patch_force_3d(drpot, rhos1, &
exp_igr%core_centre(:, particle_set(p1)%shell_index), fat)
fgcore_coulomb(1, particle_set(p1)%shell_index) = &
fgcore_coulomb(1, particle_set(p1)%shell_index) - fat(1)*dvols
fgcore_coulomb(2, particle_set(p1)%shell_index) = &
fgcore_coulomb(2, particle_set(p1)%shell_index) - fat(2)*dvols
fgcore_coulomb(3, particle_set(p1)%shell_index) = &
fgcore_coulomb(3, particle_set(p1)%shell_index) - fat(3)*dvols
ELSE
CALL dg_sum_patch_force_3d(drpot, rhos1, exp_igr%centre(:, p1), fat)
fg_coulomb(1, p1) = fg_coulomb(1, p1) - fat(1)*dvols
fg_coulomb(2, p1) = fg_coulomb(2, p1) - fat(2)*dvols
fg_coulomb(3, p1) = fg_coulomb(3, p1) - fat(3)*dvols
END IF
IF (p2 /= 0 .AND. is2_core) THEN
CALL dg_sum_patch_force_3d(drpot, rhos1, &
exp_igr%core_centre(:, particle_set(p2)%shell_index), fat)
fgcore_coulomb(1, particle_set(p2)%shell_index) = &
fgcore_coulomb(1, particle_set(p2)%shell_index) - fat(1)*dvols
fgcore_coulomb(2, particle_set(p2)%shell_index) = &
fgcore_coulomb(2, particle_set(p2)%shell_index) - fat(2)*dvols
fgcore_coulomb(3, particle_set(p2)%shell_index) = &
fgcore_coulomb(3, particle_set(p2)%shell_index) - fat(3)*dvols
ELSEIF (p2 /= 0) THEN
CALL dg_sum_patch_force_3d(drpot, rhos2, exp_igr%centre(:, p2), fat)
fg_coulomb(1, p2) = fg_coulomb(1, p2) - fat(1)*dvols
fg_coulomb(2, p2) = fg_coulomb(2, p2) - fat(2)*dvols
fg_coulomb(3, p2) = fg_coulomb(3, p2) - fat(3)*dvols
END IF
END DO
END IF
IF (PRESENT(fgshell_coulomb)) THEN
fgshell_coulomb = 0.0_dp
dvols = rhos1%pw_grid%dvol
ipart = 0
DO
CALL set_list(shell_particle_set, nshell, exp_igr%shell_centre, p1, rden, ipart)
CALL set_list(shell_particle_set, nshell, exp_igr%shell_centre, p2, rden, ipart)
IF (p1 == 0 .AND. p2 == 0) EXIT
! calculate function on small boxes (we use double packing in FFT)
CALL get_patch_again(dg, shell_particle_set, exp_igr, p1, p2, rhos1, rhos2, &
is1_shell=.TRUE., is2_shell=.TRUE., charges=charges)
! sum boxes on real space grids (big box)
CALL dg_sum_patch_force_3d(drpot, rhos1, exp_igr%shell_centre(:, p1), fat)
fgshell_coulomb(1, p1) = fgshell_coulomb(1, p1) - fat(1)*dvols
fgshell_coulomb(2, p1) = fgshell_coulomb(2, p1) - fat(2)*dvols
fgshell_coulomb(3, p1) = fgshell_coulomb(3, p1) - fat(3)*dvols
IF (p2 /= 0) THEN
CALL dg_sum_patch_force_3d(drpot, rhos2, exp_igr%shell_centre(:, p2), fat)
fgshell_coulomb(1, p2) = fgshell_coulomb(1, p2) - fat(1)*dvols
fgshell_coulomb(2, p2) = fgshell_coulomb(2, p2) - fat(2)*dvols
fgshell_coulomb(3, p2) = fgshell_coulomb(3, p2) - fat(3)*dvols
END IF
END DO
END IF
!--------------END OF FORCE CALCULATION -------------
!------------------CLEANING UP ----------------------
CALL rs_grid_release(rden)
DEALLOCATE (rden)
DO i = 1, 3
CALL rs_grid_release(drpot(i))
END DO
CALL pw_small_pool%give_back_pw(rhos1)
CALL pw_small_pool%give_back_pw(rhos2)
CALL structure_factor_deallocate(exp_igr)
CALL timestop(handle)
END SUBROUTINE pme_evaluate
! **************************************************************************************************
!> \brief Calculates local density in a small box
!> \param dg ...
!> \param particle_set ...
!> \param exp_igr ...
!> \param box ...
!> \param p1 ...
!> \param p2 ...
!> \param grid_b ...
!> \param grid_s ...
!> \param rhos1 ...
!> \param rhos2 ...
!> \param is1_core ...
!> \param is2_core ...
!> \param is1_shell ...
!> \param is2_shell ...
!> \param core_particle_set ...
!> \param charges ...
!> \par History
!> JGH (23-Mar-2001) : Switch to integer from particle list pointers
!> \author JGH (21-Mar-2001)
! **************************************************************************************************
SUBROUTINE get_patch(dg, particle_set, exp_igr, box, p1, p2, &
grid_b, grid_s, rhos1, rhos2, is1_core, is2_core, is1_shell, &
is2_shell, core_particle_set, charges)
TYPE(dg_type), POINTER :: dg
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(structure_factor_type) :: exp_igr
TYPE(cell_type), POINTER :: box
INTEGER, INTENT(IN) :: p1, p2
TYPE(pw_grid_type), INTENT(IN) :: grid_b, grid_s
TYPE(pw_r3d_rs_type), INTENT(INOUT) :: rhos1, rhos2
LOGICAL, OPTIONAL :: is1_core, is2_core, is1_shell, is2_shell
TYPE(particle_type), DIMENSION(:), OPTIONAL, &
POINTER :: core_particle_set
REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: charges
COMPLEX(KIND=dp), DIMENSION(:), POINTER :: ex1, ex2, ey1, ey2, ez1, ez2
INTEGER, DIMENSION(:), POINTER :: center1, center2
LOGICAL :: my_is1_core, my_is1_shell, my_is2_core, &
my_is2_shell, use_charge_array
REAL(KIND=dp) :: q1, q2
REAL(KIND=dp), DIMENSION(3) :: r1, r2
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(dg_rho0_type), POINTER :: dg_rho0
TYPE(pw_r3d_rs_type), POINTER :: rho0
TYPE(shell_kind_type), POINTER :: shell
NULLIFY (shell)
use_charge_array = .FALSE.
IF (PRESENT(charges)) use_charge_array = ASSOCIATED(charges)
my_is1_core = .FALSE.
my_is2_core = .FALSE.
IF (PRESENT(is1_core)) my_is1_core = is1_core
IF (PRESENT(is2_core)) my_is2_core = is2_core
IF (my_is1_core .OR. my_is2_core) THEN
CPASSERT(PRESENT(core_particle_set))
END IF
my_is1_shell = .FALSE.
my_is2_shell = .FALSE.
IF (PRESENT(is1_shell)) my_is1_shell = is1_shell
IF (PRESENT(is2_shell)) my_is2_shell = is2_shell
IF (my_is1_core .AND. my_is1_shell) THEN
CPABORT("Shell-model: cannot be core and shell simultaneously")
END IF
CALL dg_get(dg, dg_rho0=dg_rho0)
rho0 => dg_rho0%density
IF (my_is1_core) THEN
r1 = core_particle_set(particle_set(p1)%shell_index)%r
ELSE
r1 = particle_set(p1)%r
END IF
atomic_kind => particle_set(p1)%atomic_kind
IF (my_is1_core) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q1 = shell%charge_core
ELSE IF (my_is1_shell) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q1 = shell%charge_shell
ELSE
CALL get_atomic_kind(atomic_kind=atomic_kind, qeff=q1)
END IF
IF (use_charge_array) q1 = charges(p1)
IF (my_is1_shell) THEN
center1 => exp_igr%shell_centre(:, p1)
ex1 => exp_igr%shell_ex(:, p1)
ey1 => exp_igr%shell_ey(:, p1)
ez1 => exp_igr%shell_ez(:, p1)
ELSEIF (my_is1_core) THEN
center1 => exp_igr%core_centre(:, particle_set(p1)%shell_index)
ex1 => exp_igr%core_ex(:, particle_set(p1)%shell_index)
ey1 => exp_igr%core_ey(:, particle_set(p1)%shell_index)
ez1 => exp_igr%core_ez(:, particle_set(p1)%shell_index)
ELSE
center1 => exp_igr%centre(:, p1)
ex1 => exp_igr%ex(:, p1)
ey1 => exp_igr%ey(:, p1)
ez1 => exp_igr%ez(:, p1)
END IF
CPASSERT(ASSOCIATED(box))
CALL dg_get_strucfac(box%hmat, r1, grid_s%npts, grid_b%npts, center1, &
exp_igr%lb, ex1, ey1, ez1)
IF (p2 /= 0) THEN
IF (my_is2_core) THEN
r2 = core_particle_set(particle_set(p2)%shell_index)%r
ELSE
r2 = particle_set(p2)%r
END IF
atomic_kind => particle_set(p2)%atomic_kind
IF (my_is2_core) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q2 = shell%charge_core
ELSE IF (my_is2_shell) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q2 = shell%charge_shell
ELSE
CALL get_atomic_kind(atomic_kind=atomic_kind, qeff=q2)
END IF
IF (use_charge_array) q2 = charges(p2)
IF (my_is2_shell) THEN
center2 => exp_igr%shell_centre(:, p2)
ex2 => exp_igr%shell_ex(:, p2)
ey2 => exp_igr%shell_ey(:, p2)
ez2 => exp_igr%shell_ez(:, p2)
ELSEIF (my_is2_core) THEN
center2 => exp_igr%core_centre(:, particle_set(p2)%shell_index)
ex2 => exp_igr%core_ex(:, particle_set(p2)%shell_index)
ey2 => exp_igr%core_ey(:, particle_set(p2)%shell_index)
ez2 => exp_igr%core_ez(:, particle_set(p2)%shell_index)
ELSE
center2 => exp_igr%centre(:, p2)
ex2 => exp_igr%ex(:, p2)
ey2 => exp_igr%ey(:, p2)
ez2 => exp_igr%ez(:, p2)
END IF
CALL dg_get_strucfac(box%hmat, r2, grid_s%npts, grid_b%npts, center2, &
exp_igr%lb, ex2, ey2, ez2)
END IF
IF (p2 == 0) THEN
CALL dg_get_patch(rho0, rhos1, q1, ex1, ey1, ez1)
ELSE
CALL dg_get_patch(rho0, rhos1, rhos2, q1, q2, ex1, ey1, ez1, ex2, ey2, ez2)
END IF
END SUBROUTINE get_patch
! **************************************************************************************************
!> \brief ...
!> \param dg ...
!> \param particle_set ...
!> \param exp_igr ...
!> \param p1 ...
!> \param p2 ...
!> \param rhos1 ...
!> \param rhos2 ...
!> \param is1_core ...
!> \param is2_core ...
!> \param is1_shell ...
!> \param is2_shell ...
!> \param charges ...
! **************************************************************************************************
SUBROUTINE get_patch_again(dg, particle_set, exp_igr, p1, p2, rhos1, rhos2, is1_core, &
is2_core, is1_shell, is2_shell, charges)
TYPE(dg_type), POINTER :: dg
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(structure_factor_type) :: exp_igr
INTEGER, INTENT(IN) :: p1, p2
TYPE(pw_r3d_rs_type), INTENT(INOUT) :: rhos1, rhos2
LOGICAL, OPTIONAL :: is1_core, is2_core, is1_shell, is2_shell
REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: charges
COMPLEX(KIND=dp), DIMENSION(:), POINTER :: ex1, ex2, ey1, ey2, ez1, ez2
LOGICAL :: my_is1_core, my_is1_shell, my_is2_core, &
my_is2_shell, use_charge_array
REAL(KIND=dp) :: q1, q2
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(dg_rho0_type), POINTER :: dg_rho0
TYPE(pw_r3d_rs_type), POINTER :: rho0
TYPE(shell_kind_type), POINTER :: shell
NULLIFY (shell)
use_charge_array = .FALSE.
IF (PRESENT(charges)) use_charge_array = ASSOCIATED(charges)
my_is1_core = .FALSE.
my_is2_core = .FALSE.
IF (PRESENT(is1_core)) my_is1_core = is1_core
IF (PRESENT(is2_core)) my_is2_core = is2_core
my_is1_shell = .FALSE.
my_is2_shell = .FALSE.
IF (PRESENT(is1_shell)) my_is1_shell = is1_shell
IF (PRESENT(is2_shell)) my_is2_shell = is2_shell
CALL dg_get(dg, dg_rho0=dg_rho0)
rho0 => dg_rho0%density
atomic_kind => particle_set(p1)%atomic_kind
IF (my_is1_core) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q1 = shell%charge_core
ELSE IF (my_is1_shell) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q1 = shell%charge_shell
ELSE
CALL get_atomic_kind(atomic_kind=atomic_kind, qeff=q1)
END IF
IF (use_charge_array) q1 = charges(p1)
IF (my_is1_core) THEN
ex1 => exp_igr%core_ex(:, particle_set(p1)%shell_index)
ey1 => exp_igr%core_ey(:, particle_set(p1)%shell_index)
ez1 => exp_igr%core_ez(:, particle_set(p1)%shell_index)
ELSEIF (my_is1_shell) THEN
ex1 => exp_igr%shell_ex(:, p1)
ey1 => exp_igr%shell_ey(:, p1)
ez1 => exp_igr%shell_ez(:, p1)
ELSE
ex1 => exp_igr%ex(:, p1)
ey1 => exp_igr%ey(:, p1)
ez1 => exp_igr%ez(:, p1)
END IF
IF (p2 /= 0) THEN
atomic_kind => particle_set(p2)%atomic_kind
IF (my_is2_core) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q2 = shell%charge_core
ELSE IF (my_is2_shell) THEN
CALL get_atomic_kind(atomic_kind=atomic_kind, shell=shell)
q2 = shell%charge_shell
ELSE
CALL get_atomic_kind(atomic_kind=atomic_kind, qeff=q2)
END IF
IF (use_charge_array) q2 = charges(p2)
IF (my_is2_core) THEN
ex2 => exp_igr%core_ex(:, particle_set(p2)%shell_index)
ey2 => exp_igr%core_ey(:, particle_set(p2)%shell_index)
ez2 => exp_igr%core_ez(:, particle_set(p2)%shell_index)
ELSEIF (my_is2_shell) THEN
ex2 => exp_igr%shell_ex(:, p2)
ey2 => exp_igr%shell_ey(:, p2)
ez2 => exp_igr%shell_ez(:, p2)
ELSE
ex2 => exp_igr%ex(:, p2)
ey2 => exp_igr%ey(:, p2)
ez2 => exp_igr%ez(:, p2)
END IF
END IF
IF (p2 == 0) THEN
CALL dg_get_patch(rho0, rhos1, q1, ex1, ey1, ez1)
ELSE
CALL dg_get_patch(rho0, rhos1, rhos2, q1, q2, &
ex1, ey1, ez1, ex2, ey2, ez2)
END IF
END SUBROUTINE get_patch_again
END MODULE pme