forked from cp2k/cp2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxc_xbecke_roussel.F
2597 lines (2502 loc) · 114 KB
/
xc_xbecke_roussel.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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Calculates the exchange energy based on the Becke-Roussel exchange
!> hole. Takes advantage of an analytical representation of the hole
!> in order to avoid solving a non-linear equation by means of Newton-
!> Raphson algorithm
!> \note
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
MODULE xc_xbecke_roussel
USE bibliography, ONLY: BeckeRoussel1989,&
Proynov2007,&
cite_reference
USE input_section_types, ONLY: section_vals_type,&
section_vals_val_get
USE kinds, ONLY: dp
USE mathconstants, ONLY: pi
USE xc_derivative_desc, ONLY: &
deriv_laplace_rho, deriv_laplace_rhoa, deriv_laplace_rhob, deriv_norm_drho, &
deriv_norm_drhoa, deriv_norm_drhob, deriv_rho, deriv_rhoa, deriv_rhob, deriv_tau, &
deriv_tau_a, deriv_tau_b
USE xc_derivative_set_types, ONLY: xc_derivative_set_type,&
xc_dset_get_derivative
USE xc_derivative_types, ONLY: xc_derivative_get,&
xc_derivative_type
USE xc_rho_cflags_types, ONLY: xc_rho_cflags_type
USE xc_rho_set_types, ONLY: xc_rho_set_get,&
xc_rho_set_type
#include "../base/base_uses.f90"
IMPLICIT NONE
PRIVATE
LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_xbecke_roussel'
REAL(dp), PARAMETER, PRIVATE :: br_a1 = 1.5255251812009530_dp, &
br_a2 = 0.4576575543602858_dp, &
br_a3 = 0.4292036732051034_dp, &
br_c0 = 0.7566445420735584_dp, &
br_c1 = -2.6363977871370960_dp, &
br_c2 = 5.4745159964232880_dp, &
br_c3 = -12.657308127108290_dp, &
br_c4 = 4.1250584725121360_dp, &
br_c5 = -30.425133957163840_dp, &
br_b0 = 0.4771976183772063_dp, &
br_b1 = -1.7799813494556270_dp, &
br_b2 = 3.8433841862302150_dp, &
br_b3 = -9.5912050880518490_dp, &
br_b4 = 2.1730180285916720_dp, &
br_b5 = -30.425133851603660_dp, &
br_d0 = 0.00004435009886795587_dp, &
br_d1 = 0.58128653604457910_dp, &
br_d2 = 66.742764515940610_dp, &
br_d3 = 434.26780897229770_dp, &
br_d4 = 824.7765766052239000_dp, &
br_d5 = 1657.9652731582120_dp, &
br_e0 = 0.00003347285060926091_dp, &
br_e1 = 0.47917931023971350_dp, &
br_e2 = 62.392268338574240_dp, &
br_e3 = 463.14816427938120_dp, &
br_e4 = 785.2360350104029000_dp, &
br_e5 = 1657.962968223273000000_dp, &
br_BB = 2.085749716493756_dp
PUBLIC :: xbecke_roussel_lda_info, xbecke_roussel_lsd_info, xbecke_roussel_lda_eval, &
xbecke_roussel_lsd_eval, x_br_lsd_y_lte_0, x_br_lsd_y_gt_0, x_br_lsd_y_lte_0_cutoff, &
x_br_lsd_y_gt_0_cutoff
CONTAINS
! **************************************************************************************************
!> \brief return various information on the functional
!> \param reference string with the reference of the actual functional
!> \param shortform string with the shortform of the functional name
!> \param needs the components needed by this functional are set to
!> true (does not set the unneeded components to false)
!> \param max_deriv controls the number of derivatives
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lda_info(reference, shortform, needs, max_deriv)
CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL :: needs
INTEGER, INTENT(out), OPTIONAL :: max_deriv
CALL cite_reference(BeckeRoussel1989)
CALL cite_reference(Proynov2007)
IF (PRESENT(reference)) THEN
reference = "A.D. Becke, M.R. Roussel, "// &
"Phys. Rev. A, vol. 39, n 8, pp. 3761-3767, (1989) {spin unpolarized}"
END IF
IF (PRESENT(shortform)) THEN
shortform = "Becke-Roussel exchange hole (spin unpolarized)"
END IF
IF (PRESENT(needs)) THEN
needs%rho = .TRUE.
needs%norm_drho = .TRUE.
needs%tau = .TRUE.
needs%laplace_rho = .TRUE.
END IF
IF (PRESENT(max_deriv)) max_deriv = 1
END SUBROUTINE xbecke_roussel_lda_info
! **************************************************************************************************
!> \brief return various information on the functional
!> \param reference string with the reference of the actual functional
!> \param shortform string with the shortform of the functional name
!> \param needs the components needed by this functional are set to
!> true (does not set the unneeded components to false)
!> \param max_deriv ...
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lsd_info(reference, shortform, needs, max_deriv)
CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: reference, shortform
TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL :: needs
INTEGER, INTENT(out), OPTIONAL :: max_deriv
CALL cite_reference(BeckeRoussel1989)
CALL cite_reference(Proynov2007)
IF (PRESENT(reference)) THEN
reference = "A.D. Becke, M.R. Roussel, "// &
"Phys. Rev. A, vol. 39, n 8, pp. 3761-3767, (1989) {spin polarized}"
END IF
IF (PRESENT(shortform)) THEN
shortform = "Becke-Roussel exchange hole (spin polarized)"
END IF
IF (PRESENT(needs)) THEN
needs%rho_spin = .TRUE.
needs%norm_drho_spin = .TRUE.
needs%tau_spin = .TRUE.
needs%laplace_rho_spin = .TRUE.
END IF
IF (PRESENT(max_deriv)) max_deriv = 1
END SUBROUTINE xbecke_roussel_lsd_info
! **************************************************************************************************
!> \brief evaluates the Becke Roussel exchange functional for lda
!> \param rho_set the density where you want to evaluate the functional
!> \param deriv_set place where to store the functional derivatives (they are
!> added to the derivatives)
!> \param grad_deriv degree of the derivative that should be evaluated,
!> if positive all the derivatives up to the given degree are evaluated,
!> if negative only the given degree is calculated
!> \param br_params parameters for the becke roussel functional
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lda_eval(rho_set, deriv_set, grad_deriv, br_params)
TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
INTEGER, INTENT(in) :: grad_deriv
TYPE(section_vals_type), POINTER :: br_params
CHARACTER(len=*), PARAMETER :: routineN = 'xbecke_roussel_lda_eval'
INTEGER :: handle, npoints
INTEGER, DIMENSION(2, 3) :: bo
REAL(dp) :: gamma, R, sx
REAL(kind=dp) :: epsilon_rho
REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), &
POINTER :: dummy, e_0, e_laplace_rho, e_ndrho, &
e_rho, e_tau, laplace_rho, norm_drho, &
rho, tau
TYPE(xc_derivative_type), POINTER :: deriv
CALL timeset(routineN, handle)
CALL xc_rho_set_get(rho_set, rho=rho, norm_drho=norm_drho, &
tau=tau, laplace_rho=laplace_rho, local_bounds=bo, &
rho_cutoff=epsilon_rho)
npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
dummy => rho
e_0 => dummy
e_rho => dummy
e_ndrho => dummy
e_tau => dummy
e_laplace_rho => dummy
IF (grad_deriv >= 0) THEN
deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_0)
END IF
IF (grad_deriv >= 1 .OR. grad_deriv == -1) THEN
deriv => xc_dset_get_derivative(deriv_set, [deriv_rho], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_rho)
deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drho], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_ndrho)
deriv => xc_dset_get_derivative(deriv_set, [deriv_tau], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_tau)
deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rho], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_laplace_rho)
END IF
IF (grad_deriv > 1 .OR. grad_deriv < -1) THEN
CPABORT("derivatives bigger than 1 not implemented")
END IF
CALL section_vals_val_get(br_params, "scale_x", r_val=sx)
CALL section_vals_val_get(br_params, "CUTOFF_RADIUS", r_val=R)
CALL section_vals_val_get(br_params, "GAMMA", r_val=gamma)
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(rho, norm_drho, laplace_rho, tau, e_0, e_rho) &
!$OMP SHARED(e_ndrho, e_tau, e_laplace_rho, grad_deriv) &
!$OMP SHARED(npoints, epsilon_rho) &
!$OMP SHARED(sx, r, gamma)
CALL xbecke_roussel_lda_calc(rho=rho, norm_drho=norm_drho, &
laplace_rho=laplace_rho, tau=tau, e_0=e_0, e_rho=e_rho, e_ndrho=e_ndrho, &
e_tau=e_tau, e_laplace_rho=e_laplace_rho, grad_deriv=grad_deriv, &
npoints=npoints, epsilon_rho=epsilon_rho, &
sx=sx, R=R, gamma=gamma)
!$OMP END PARALLEL
CALL timestop(handle)
END SUBROUTINE xbecke_roussel_lda_eval
! **************************************************************************************************
!> \brief Precalculates which branch of the code has to be taken
!> There are two main branches, one for a truncated potential and a cutoff
!> radius, the other for the full coulomb interaction. In the end, the code
!> for the lsd part will be called and the lda part is obtained via spin
!> scaling relations
!> \param rho grid values
!> \param norm_drho grid values
!> \param laplace_rho grid values
!> \param tau grid values
!> \param e_0 energies and derivatives
!> \param e_rho energies and derivatives
!> \param e_ndrho energies and derivatives
!> \param e_tau energies and derivatives
!> \param e_laplace_rho energies and derivatives
!> \param grad_deriv degree of the derivative that should be evaluated,
!> if positive all the derivatives up to the given degree are evaluated,
!> if negative only the given degree is calculated
!> \param npoints size of the grids
!> \param epsilon_rho cutoffs
!> \param sx scales the exchange potential and energies
!> \param R cutoff Radius for truncated case
!> \param gamma parameter from original publication, usually set to 1
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lda_calc(rho, norm_drho, laplace_rho, tau, e_0, e_rho, &
e_ndrho, e_tau, e_laplace_rho, grad_deriv, npoints, &
epsilon_rho, sx, R, gamma)
INTEGER, INTENT(in) :: npoints, grad_deriv
REAL(kind=dp), DIMENSION(1:npoints), INTENT(inout) :: e_laplace_rho, e_tau, e_ndrho, e_rho, e_0
REAL(kind=dp), DIMENSION(1:npoints), INTENT(in) :: tau, laplace_rho, norm_drho, rho
REAL(kind=dp), INTENT(in) :: epsilon_rho, sx, R, gamma
INTEGER :: ip
REAL(dp) :: e_diff, e_old, my_laplace_rho, my_ndrho, &
my_rho, my_tau, t1, t15, t16, t2, t3, &
t4, t5, t8, t9, yval
! Precalculate y, in order to chose the correct branch afterwards
!$OMP DO
DO ip = 1, npoints
my_rho = 0.5_dp*MAX(rho(ip), 0.0_dp)
IF (my_rho > epsilon_rho) THEN
my_ndrho = 0.5_dp*MAX(norm_drho(ip), EPSILON(0.0_dp)*1.e4_dp)
my_tau = 0.5_dp*MAX(EPSILON(0.0_dp)*1.e4_dp, tau(ip))
my_laplace_rho = 0.5_dp*laplace_rho(ip)
t1 = pi**(0.1e1_dp/0.3e1_dp)
t2 = t1**2
t3 = my_rho**(0.1e1_dp/0.3e1_dp)
t4 = t3**2
t5 = t4*my_rho
t8 = my_ndrho**2
t9 = 0.1e1_dp/my_rho
! *** CP2K defines tau in a different way as compared to Becke !!!
t15 = my_laplace_rho/0.6e1_dp - gamma*(2.0_dp*my_tau - t8*t9/0.4e1_dp)/0.3e1_dp
t16 = 0.1e1_dp/t15
yval = 0.2e1_dp/0.3e1_dp*t2*t5*t16
IF (R == 0.0_dp) THEN
IF (yval <= 0.0_dp) THEN
e_old = e_0(ip)
CALL x_br_lsd_y_lte_0(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, gamma, grad_deriv)
! VERY UGLY HACK e_0 has to multiplied by the factor 2
e_diff = e_0(ip) - e_old
e_0(ip) = e_0(ip) + e_diff
ELSE
e_old = e_0(ip)
CALL x_br_lsd_y_gt_0(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, gamma, grad_deriv)
! VERY UGLY HACK e_0 has to multiplied by the factor 2
e_diff = e_0(ip) - e_old
e_0(ip) = e_0(ip) + e_diff
END IF
ELSE
IF (yval <= 0.0_dp) THEN
e_old = e_0(ip)
CALL x_br_lsd_y_lte_0_cutoff(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, R, gamma, grad_deriv)
! VERY UGLY HACK e_0 has to multiplied by the factor 2
e_diff = e_0(ip) - e_old
e_0(ip) = e_0(ip) + e_diff
ELSE
e_old = e_0(ip)
CALL x_br_lsd_y_gt_0_cutoff(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, R, gamma, grad_deriv)
! VERY UGLY HACK e_0 has to multiplied by the factor 2
e_diff = e_0(ip) - e_old
e_0(ip) = e_0(ip) + e_diff
END IF
END IF
END IF
END DO
!$OMP END DO
END SUBROUTINE xbecke_roussel_lda_calc
! **************************************************************************************************
!> \brief evaluates the Becke Roussel exchange functional for lda
!> \param rho_set the density where you want to evaluate the functional
!> \param deriv_set place where to store the functional derivatives (they are
!> added to the derivatives)
!> \param grad_deriv degree of the derivative that should be evaluated,
!> if positive all the derivatives up to the given degree are evaluated,
!> if negative only the given degree is calculated
!> \param br_params parameters for the becke roussel functional
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lsd_eval(rho_set, deriv_set, grad_deriv, br_params)
TYPE(xc_rho_set_type), INTENT(IN) :: rho_set
TYPE(xc_derivative_set_type), INTENT(IN) :: deriv_set
INTEGER, INTENT(in) :: grad_deriv
TYPE(section_vals_type), POINTER :: br_params
CHARACTER(len=*), PARAMETER :: routineN = 'xbecke_roussel_lsd_eval'
INTEGER :: handle, npoints
INTEGER, DIMENSION(2, 3) :: bo
REAL(dp) :: gamma, R, sx
REAL(kind=dp) :: epsilon_rho
REAL(kind=dp), CONTIGUOUS, DIMENSION(:, :, :), POINTER :: dummy, e_0, e_laplace_rhoa, &
e_laplace_rhob, e_ndrhoa, e_ndrhob, e_rhoa, e_rhob, e_tau_a, e_tau_b, laplace_rhoa, &
laplace_rhob, norm_drhoa, norm_drhob, rhoa, rhob, tau_a, tau_b
TYPE(xc_derivative_type), POINTER :: deriv
CALL timeset(routineN, handle)
CALL xc_rho_set_get(rho_set, rhoa=rhoa, rhob=rhob, norm_drhoa=norm_drhoa, &
norm_drhob=norm_drhob, tau_a=tau_a, tau_b=tau_b, laplace_rhoa=laplace_rhoa, &
laplace_rhob=laplace_rhob, local_bounds=bo, &
rho_cutoff=epsilon_rho)
npoints = (bo(2, 1) - bo(1, 1) + 1)*(bo(2, 2) - bo(1, 2) + 1)*(bo(2, 3) - bo(1, 3) + 1)
dummy => rhoa
e_0 => dummy
e_rhoa => dummy
e_rhob => dummy
e_ndrhoa => dummy
e_ndrhob => dummy
e_tau_a => dummy
e_tau_b => dummy
e_laplace_rhoa => dummy
e_laplace_rhob => dummy
IF (grad_deriv >= 0) THEN
deriv => xc_dset_get_derivative(deriv_set, [INTEGER::], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_0)
END IF
IF (grad_deriv >= 1 .OR. grad_deriv == -1) THEN
deriv => xc_dset_get_derivative(deriv_set, [deriv_rhoa], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_rhoa)
deriv => xc_dset_get_derivative(deriv_set, [deriv_rhob], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_rhob)
deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhoa], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_ndrhoa)
deriv => xc_dset_get_derivative(deriv_set, [deriv_norm_drhob], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_ndrhob)
deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_a], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_tau_a)
deriv => xc_dset_get_derivative(deriv_set, [deriv_tau_b], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_tau_b)
deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhoa], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhoa)
deriv => xc_dset_get_derivative(deriv_set, [deriv_laplace_rhob], &
allocate_deriv=.TRUE.)
CALL xc_derivative_get(deriv, deriv_data=e_laplace_rhob)
END IF
IF (grad_deriv > 1 .OR. grad_deriv < -1) THEN
CPABORT("derivatives bigger than 1 not implemented")
END IF
CALL section_vals_val_get(br_params, "scale_x", r_val=sx)
CALL section_vals_val_get(br_params, "CUTOFF_RADIUS", r_val=R)
CALL section_vals_val_get(br_params, "GAMMA", r_val=gamma)
!$OMP PARALLEL DEFAULT (NONE) &
!$OMP SHARED(rhoa, norm_drhoa, laplace_rhoa, tau_a, e_0) &
!$OMP SHARED(e_rhoa, e_ndrhoa, e_tau_a, e_laplace_rhoa) &
!$OMP SHARED(grad_deriv, npoints, epsilon_rho) &
!$OMP SHARED(sx, r, gamma) &
!$OMP SHARED(rhob, norm_drhob, laplace_rhob, tau_b, e_rhob) &
!$OMP SHARED(e_ndrhob, e_tau_b, e_laplace_rhob)
CALL xbecke_roussel_lsd_calc(rho=rhoa, norm_drho=norm_drhoa, &
laplace_rho=laplace_rhoa, tau=tau_a, e_0=e_0, e_rho=e_rhoa, e_ndrho=e_ndrhoa, &
e_tau=e_tau_a, e_laplace_rho=e_laplace_rhoa, grad_deriv=grad_deriv, &
npoints=npoints, epsilon_rho=epsilon_rho, &
sx=sx, R=R, gamma=gamma)
CALL xbecke_roussel_lsd_calc(rho=rhob, norm_drho=norm_drhob, &
laplace_rho=laplace_rhob, tau=tau_b, e_0=e_0, e_rho=e_rhob, e_ndrho=e_ndrhob, &
e_tau=e_tau_b, e_laplace_rho=e_laplace_rhob, grad_deriv=grad_deriv, &
npoints=npoints, epsilon_rho=epsilon_rho, &
sx=sx, R=R, gamma=gamma)
!$OMP END PARALLEL
CALL timestop(handle)
END SUBROUTINE xbecke_roussel_lsd_eval
! **************************************************************************************************
!> \brief Precalculates which branch of the code has to be taken
!> There are two main branches, one for a truncated potential and a cutoff
!> radius, the other for the full coulomb interaction
!> \param rho grid values
!> \param norm_drho grid values
!> \param laplace_rho grid values
!> \param tau grid values
!> \param e_0 energies and derivatives
!> \param e_rho energies and derivatives
!> \param e_ndrho energies and derivatives
!> \param e_tau energies and derivatives
!> \param e_laplace_rho energies and derivatives
!> \param grad_deriv degree of the derivative that should be evaluated,
!> if positive all the derivatives up to the given degree are evaluated,
!> if negative only the given degree is calculated
!> \param npoints size of the grids
!> \param epsilon_rho cutoffs
!> \param sx scales the exchange potential and energies
!> \param R cutoff Radius for truncated case
!> \param gamma parameter from original publication, usually set to 1
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE xbecke_roussel_lsd_calc(rho, norm_drho, laplace_rho, tau, e_0, e_rho, &
e_ndrho, e_tau, e_laplace_rho, grad_deriv, npoints, &
epsilon_rho, sx, R, gamma)
INTEGER, INTENT(in) :: npoints, grad_deriv
REAL(kind=dp), DIMENSION(1:npoints), INTENT(inout) :: e_laplace_rho, e_tau, e_ndrho, e_rho, e_0
REAL(kind=dp), DIMENSION(1:npoints), INTENT(in) :: tau, laplace_rho, norm_drho, rho
REAL(kind=dp), INTENT(in) :: epsilon_rho, sx, R, gamma
INTEGER :: ip
REAL(dp) :: my_laplace_rho, my_ndrho, my_rho, &
my_tau, t1, t15, t16, t2, t3, t4, t5, &
t8, t9, yval
! Precalculate y, in order to chose the correct branch afterwards
!$OMP DO
DO ip = 1, npoints
my_rho = MAX(rho(ip), 0.0_dp)
IF (my_rho > epsilon_rho) THEN
my_ndrho = MAX(norm_drho(ip), EPSILON(0.0_dp)*1.e4_dp)
my_tau = 1.0_dp*MAX(EPSILON(0.0_dp)*1.e4_dp, tau(ip))
my_laplace_rho = 1.0_dp*laplace_rho(ip)
t1 = pi**(0.1e1_dp/0.3e1_dp)
t2 = t1**2
t3 = my_rho**(0.1e1_dp/0.3e1_dp)
t4 = t3**2
t5 = t4*my_rho
t8 = my_ndrho**2
t9 = 0.1e1_dp/my_rho
! *** CP2K defines tau in a different way as compared to Becke !!!
t15 = my_laplace_rho/0.6e1_dp - gamma*(2.0_dp*my_tau - t8*t9/0.4e1_dp)/0.3e1_dp
t16 = 0.1e1_dp/t15
yval = 0.2e1_dp/0.3e1_dp*t2*t5*t16
IF (R == 0.0_dp) THEN
IF (yval <= 0.0_dp) THEN
CALL x_br_lsd_y_lte_0(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, gamma, grad_deriv)
ELSE
CALL x_br_lsd_y_gt_0(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, gamma, grad_deriv)
END IF
ELSE
IF (yval <= 0.0_dp) THEN
CALL x_br_lsd_y_lte_0_cutoff(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, R, gamma, grad_deriv)
ELSE
CALL x_br_lsd_y_gt_0_cutoff(my_rho, my_ndrho, my_tau, my_laplace_rho, e_0(ip), &
e_rho(ip), e_ndrho(ip), e_tau(ip), e_laplace_rho(ip), &
sx, R, gamma, grad_deriv)
END IF
END IF
END IF
END DO
!$OMP END DO
END SUBROUTINE xbecke_roussel_lsd_calc
! **************************************************************************************************
!> \brief full range evaluation for y <= 0
!> \param rho ...
!> \param ndrho ...
!> \param tau ...
!> \param laplace_rho ...
!> \param e_0 ...
!> \param e_rho ...
!> \param e_ndrho ...
!> \param e_tau ...
!> \param e_laplace_rho ...
!> \param sx ...
!> \param gamma ...
!> \param grad_deriv ...
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE x_br_lsd_y_lte_0(rho, ndrho, tau, laplace_rho, e_0, &
e_rho, e_ndrho, e_tau, e_laplace_rho, &
sx, gamma, grad_deriv)
REAL(dp), INTENT(IN) :: rho, ndrho, tau, laplace_rho
REAL(dp), INTENT(INOUT) :: e_0, e_rho, e_ndrho, e_tau, e_laplace_rho
REAL(dp), INTENT(IN) :: sx, gamma
INTEGER, INTENT(IN) :: grad_deriv
REAL(KIND=dp) :: t1, t100, t101, t102, t108, t111, t113, t114, t117, t118, t120, t121, t122, &
t129, t130, t134, t135, t138, t142, t143, t146, t147, t150, t152, t153, t157, t158, t16, &
t161, t164, t165, t166, t169, t17, t170, t172, t173, t19, t199, t2, t20, t202, t207, &
t208, t209, t21, t217, t218, t22, t220, t227, t229, t23, t234, t246, t249, t252, t255, &
t259, t26, t263, t267, t27, t271, t274, t275, t276, t28, t29, t293, t295, t3, t304, t307, &
t308, t32, t320, t33, t34, t340, t341, t342, t344, t346, t349, t35, t350, t353, t354, &
t357, t358, t36, t361, t362, t365, t366, t367, t37, t379, t38
REAL(KIND=dp) :: t381, t387, t39, t4, t401, t42, t422, t43, t434, t435, t436, t44, t448, &
t45, t450, t47, t471, t48, t5, t51, t52, t53, t54, t55, t56, t57, t61, t62, t63, t64, &
t66, t67, t70, t71, t72, t75, t78, t81, t84, t87, t88, t89, t9, t91, t92, t93, t94, t95, &
t96, t97, yval
IF (grad_deriv >= 0) THEN
t1 = pi**(0.1e1_dp/0.3e1_dp)
t2 = t1**2
t3 = rho**(0.1e1_dp/0.3e1_dp)
t4 = t3**2
t5 = t4*rho
t9 = ndrho**2
t16 = laplace_rho/0.6e1_dp - gamma*(REAL(2*tau, KIND=dp) - t9/rho/0.4e1_dp)/0.3e1_dp
t17 = 0.1e1_dp/t16
yval = 0.2e1_dp/0.3e1_dp*t2*t5*t17
t19 = t3*rho
t20 = 0.3141592654e1_dp**(0.1e1_dp/0.3e1_dp)
t21 = t19*t20
t22 = br_a1*t2
t23 = t5*t17
t26 = 0.2e1_dp/0.3e1_dp*t22*t23 + br_a2
t27 = ATAN(t26)
t28 = -t27 + br_a3
t29 = br_c1*t2
t32 = t1*pi
t33 = br_c2*t32
t34 = rho**2
t35 = t34*rho
t36 = t3*t35
t37 = t16**2
t38 = 0.1e1_dp/t37
t39 = t36*t38
t42 = pi**2
t43 = br_c3*t42
t44 = t34**2
t45 = t44*rho
t47 = 0.1e1_dp/t37/t16
t48 = t45*t47
t51 = t2*t42
t52 = br_c4*t51
t53 = t44*t34
t54 = t4*t53
t55 = t37**2
t56 = 0.1e1_dp/t55
t57 = t54*t56
t61 = t1*t42*pi
t62 = br_c5*t61
t63 = t44**2
t64 = t3*t63
t66 = 0.1e1_dp/t55/t16
t67 = t64*t66
t70 = br_c0 + 0.2e1_dp/0.3e1_dp*t29*t23 + 0.4e1_dp/0.9e1_dp*t33*t39 &
+ 0.8e1_dp/0.27e2_dp*t43*t48 + 0.16e2_dp/0.81e2_dp*t52*t57 + 0.32e2_dp &
/0.243e3_dp*t62*t67
t71 = t28*t70
t72 = br_b1*t2
t75 = br_b2*t32
t78 = br_b3*t42
t81 = br_b4*t51
t84 = br_b5*t61
t87 = br_b0 + 0.2e1_dp/0.3e1_dp*t72*t23 + 0.4e1_dp/0.9e1_dp*t75*t39 &
+ 0.8e1_dp/0.27e2_dp*t78*t48 + 0.16e2_dp/0.81e2_dp*t81*t57 + 0.32e2_dp &
/0.243e3_dp*t84*t67
t88 = 0.1e1_dp/t87
t89 = t71*t88
t91 = EXP(t89/0.3e1_dp)
t92 = t21*t91
t93 = 0.1e1_dp/t28
t94 = 0.1e1_dp/t70
t95 = t93*t94
t96 = EXP(-t89)
t97 = t88*t96
t100 = 0.1e1_dp - t96 - t71*t97/0.2e1_dp
t101 = t87*t100
t102 = t95*t101
e_0 = e_0 + (-t92*t102)*sx
END IF
IF (grad_deriv >= 1 .OR. grad_deriv == -1) THEN
t108 = t4*t17
t111 = 0.1e1_dp/t3
t113 = t38*gamma
t114 = t113*t9
t117 = 0.10e2_dp/0.9e1_dp*t22*t108 + t22*t111*t114/0.18e2_dp
t118 = t26**2
t120 = 0.1e1_dp/(0.1e1_dp + t118)
t121 = t117*t120
t122 = t70*t88
t129 = t3*t34
t130 = t129*t38
t134 = t47*gamma
t135 = t134*t9
t138 = t44*t47
t142 = t56*gamma
t143 = t142*t9
t146 = t4*t45
t147 = t146*t56
t150 = t4*t44
t152 = t66*gamma
t153 = t152*t9
t157 = t3*t44*t35
t158 = t157*t66
t161 = t3*t53
t164 = 0.1e1_dp/t55/t37
t165 = t164*gamma
t166 = t165*t9
t169 = 0.10e2_dp/0.9e1_dp*t29*t108 + t29*t111*t114/0.18e2_dp + 0.40e2_dp &
/0.27e2_dp*t33*t130 + 0.2e1_dp/0.27e2_dp*t33*t19*t135 + &
0.40e2_dp/0.27e2_dp*t43*t138 + 0.2e1_dp/0.27e2_dp*t43*t35*t143 + &
0.320e3_dp/0.243e3_dp*t52*t147 + 0.16e2_dp/0.243e3_dp*t52*t150* &
t153 + 0.800e3_dp/0.729e3_dp*t62*t158 + 0.40e2_dp/0.729e3_dp*t62*t161 &
*t166
t170 = t28*t169
t172 = t87**2
t173 = 0.1e1_dp/t172
t199 = 0.10e2_dp/0.9e1_dp*t72*t108 + t72*t111*t114/0.18e2_dp + 0.40e2_dp &
/0.27e2_dp*t75*t130 + 0.2e1_dp/0.27e2_dp*t75*t19*t135 + &
0.40e2_dp/0.27e2_dp*t78*t138 + 0.2e1_dp/0.27e2_dp*t78*t35*t143 + &
0.320e3_dp/0.243e3_dp*t81*t147 + 0.16e2_dp/0.243e3_dp*t81*t150* &
t153 + 0.800e3_dp/0.729e3_dp*t84*t158 + 0.40e2_dp/0.729e3_dp*t84*t161 &
*t166
t202 = -t121*t122 + t170*t88 - t71*t173*t199
t207 = t28**2
t208 = 0.1e1_dp/t207
t209 = t91*t208
t217 = t21*t91*t93
t218 = t70**2
t220 = 0.1e1_dp/t218*t87
t227 = -t202
t229 = t122*t96
t234 = t173*t96
e_rho = e_rho + (-0.4e1_dp/0.3e1_dp*t3*t20*t91*t102 - t21*t202*t91* &
t102/0.3e1_dp - t21*t209*t94*t87*t100*t117*t120 + t217 &
*t220*t100*t169 - t92*t95*t199*t100 - t92*t95*t87* &
(-t227*t96 + t121*t229/0.2e1_dp - t170*t97/0.2e1_dp + t71*t234 &
*t199/0.2e1_dp - t71*t88*t227*t96/0.2e1_dp))*sx
t246 = t4*t38
t249 = t120*t70
t252 = t22*t246*gamma*ndrho*t249*t88
t255 = t113*ndrho
t259 = t134*ndrho
t263 = t142*ndrho
t267 = t152*ndrho
t271 = t165*ndrho
t274 = -t29*t4*t255/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t33*t129*t259 &
- 0.4e1_dp/0.27e2_dp*t43*t44*t263 - 0.32e2_dp/0.243e3_dp*t52*t146 &
*t267 - 0.80e2_dp/0.729e3_dp*t62*t157*t271
t275 = t28*t274
t276 = t275*t88
t293 = -t72*t4*t255/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t75*t129*t259 &
- 0.4e1_dp/0.27e2_dp*t78*t44*t263 - 0.32e2_dp/0.243e3_dp*t81*t146 &
*t267 - 0.80e2_dp/0.729e3_dp*t84*t157*t271
t295 = t71*t173*t293
t304 = t208*t94*t87
t307 = t100*br_a1*t2
t308 = ndrho*t120
t320 = -t252/0.9e1_dp - t276 + t295
e_ndrho = e_ndrho + (-t21*(t252/0.27e2_dp + t276/0.3e1_dp - t295/0.3e1_dp)*t91 &
*t102 + t34*t20*t91*t304*t307*t113*t308/0.9e1_dp + t217 &
*t220*t100*t274 - t92*t95*t293*t100 - t92*t95*t87 &
*(-t320*t96 - t22*t246*gamma*t308*t229/0.18e2_dp - t275 &
*t97/0.2e1_dp + t71*t234*t293/0.2e1_dp - t71*t88*t320*t96 &
/0.2e1_dp))*sx
t340 = t5*t38
t341 = t22*t340
t342 = gamma*t120
t344 = t341*t342*t122
t346 = t340*gamma
t349 = t36*t47
t350 = t349*gamma
t353 = t45*t56
t354 = t353*gamma
t357 = t54*t66
t358 = t357*gamma
t361 = t64*t164
t362 = t361*gamma
t365 = 0.4e1_dp/0.9e1_dp*t29*t346 + 0.16e2_dp/0.27e2_dp*t33*t350 + &
0.16e2_dp/0.27e2_dp*t43*t354 + 0.128e3_dp/0.243e3_dp*t52*t358 + 0.320e3_dp &
/0.729e3_dp*t62*t362
t366 = t28*t365
t367 = t366*t88
t379 = 0.4e1_dp/0.9e1_dp*t72*t346 + 0.16e2_dp/0.27e2_dp*t75*t350 + &
0.16e2_dp/0.27e2_dp*t78*t354 + 0.128e3_dp/0.243e3_dp*t81*t358 + 0.320e3_dp &
/0.729e3_dp*t84*t362
t381 = t71*t173*t379
t387 = t35*t20
t401 = 0.4e1_dp/0.9e1_dp*t344 - t367 + t381
e_tau = e_tau + (-t21*(-0.4e1_dp/0.27e2_dp*t344 + t367/0.3e1_dp - t381/0.3e1_dp) &
*t91*t102 - 0.4e1_dp/0.9e1_dp*t387*t91*t304*t307*t113* &
t120 + t217*t220*t100*t365 - t92*t95*t379*t100 - t92 &
*t95*t87*(-t401*t96 + 0.2e1_dp/0.9e1_dp*t341*t342*t229 - &
t366*t97/0.2e1_dp + t71*t234*t379/0.2e1_dp - t71*t88*t401 &
*t96/0.2e1_dp))*sx
t422 = t22*t5*t38*t120*t122
t434 = -t29*t340/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t33*t349 - 0.4e1_dp/ &
0.27e2_dp*t43*t353 - 0.32e2_dp/0.243e3_dp*t52*t357 - 0.80e2_dp/0.729e3_dp &
*t62*t361
t435 = t28*t434
t436 = t435*t88
t448 = -t72*t340/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t75*t349 - 0.4e1_dp/ &
0.27e2_dp*t78*t353 - 0.32e2_dp/0.243e3_dp*t81*t357 - 0.80e2_dp/0.729e3_dp &
*t84*t361
t450 = t71*t173*t448
t471 = -t422/0.9e1_dp - t436 + t450
e_laplace_rho = e_laplace_rho + (-t21*(t422/0.27e2_dp + t436/0.3e1_dp - t450/0.3e1_dp)*t91* &
t102 + t387*t209*t94*t101*br_a1*t2*t38*t120/0.9e1_dp &
+ t217*t220*t100*t434 - t92*t95*t448*t100 - t92*t95 &
*t87*(-t471*t96 - t341*t249*t97/0.18e2_dp - t435*t97/0.2e1_dp &
+ t71*t234*t448/0.2e1_dp - t71*t88*t471*t96/0.2e1_dp))*sx
END IF
END SUBROUTINE x_br_lsd_y_lte_0
! **************************************************************************************************
!> \brief Full range evaluation for y > 0
!> \param rho ...
!> \param ndrho ...
!> \param tau ...
!> \param laplace_rho ...
!> \param e_0 ...
!> \param e_rho ...
!> \param e_ndrho ...
!> \param e_tau ...
!> \param e_laplace_rho ...
!> \param sx ...
!> \param gamma ...
!> \param grad_deriv ...
!> \par History
!> 12.2008 created [mguidon]
!> \author mguidon
! **************************************************************************************************
SUBROUTINE x_br_lsd_y_gt_0(rho, ndrho, tau, laplace_rho, e_0, &
e_rho, e_ndrho, e_tau, e_laplace_rho, &
sx, gamma, grad_deriv)
REAL(dp), INTENT(IN) :: rho, ndrho, tau, laplace_rho
REAL(dp), INTENT(INOUT) :: e_0, e_rho, e_ndrho, e_tau, e_laplace_rho
REAL(dp), INTENT(IN) :: sx, gamma
INTEGER, INTENT(IN) :: grad_deriv
REAL(KIND=dp) :: t1, t102, t103, t104, t106, t107, t108, t109, t110, t111, t112, t115, t117, &
t124, t131, t134, t137, t138, t142, t143, t154, t157, t158, t159, t16, t160, t162, t165, &
t167, t168, t17, t176, t180, t181, t184, t185, t188, t19, t190, t191, t195, t196, t199, &
t2, t20, t202, t203, t204, t207, t208, t21, t210, t211, t22, t23, t237, t24, t240, t245, &
t248, t249, t25, t255, t256, t258, t26, t265, t267, t272, t285, t288, t289, t29, t297, &
t298, t3, t30, t301, t305, t309, t31, t313, t317, t32, t320, t321, t33, t338, t34, t341, &
t35, t356, t36, t37, t376, t377, t382, t383, t387, t388, t391
REAL(KIND=dp) :: t392, t395, t396, t399, t4, t400, t403, t404, t41, t416, t419, t42, t43, &
t434, t458, t459, t47, t471, t472, t48, t484, t487, t49, t5, t50, t502, t51, t54, t57, &
t58, t59, t6, t60, t62, t63, t66, t67, t68, t69, t70, t71, t72, t76, t77, t78, t79, t81, &
t82, t85, t86, t87, t9, t90, t93, t96, t99, yval
IF (grad_deriv >= 0) THEN
t1 = pi**(0.1e1_dp/0.3e1_dp)
t2 = t1**2
t3 = rho**(0.1e1_dp/0.3e1_dp)
t4 = t3**2
t5 = t4*rho
t6 = t2*t5
t9 = ndrho**2
t16 = laplace_rho/0.6e1_dp - gamma*(REAL(2*tau, KIND=dp) - t9/rho/0.4e1_dp)/0.3e1_dp
t17 = 0.1e1_dp/t16
yval = 0.2e1_dp/0.3e1_dp*t6*t17
t19 = t3*rho
t20 = 0.3141592654e1_dp**(0.1e1_dp/0.3e1_dp)
t21 = t19*t20
t22 = 0.1e1_dp/br_BB
t23 = 0.1e1_dp/t2
t24 = t22*t23
t25 = 0.1e1_dp/t5
t26 = t25*t16
t29 = br_BB**2
t30 = t1*pi
t31 = t29*t30
t32 = rho**2
t33 = t32*rho
t34 = t3*t33
t35 = t16**2
t36 = 0.1e1_dp/t35
t37 = t34*t36
t41 = SQRT(0.10e1_dp + 0.4e1_dp/0.9e1_dp*t31*t37)
t42 = t41*t22
t43 = t23*t25
t47 = 0.1500000000000000e1_dp*t24*t26 + 0.3e1_dp/0.2e1_dp*t42*t43 &
*t16
t48 = LOG(t47)
t49 = t48 + 0.2e1_dp
t50 = br_d1*t2
t51 = t5*t17
t54 = br_d2*t30
t57 = pi**2
t58 = br_d3*t57
t59 = t32**2
t60 = t59*rho
t62 = 0.1e1_dp/t35/t16
t63 = t60*t62
t66 = t2*t57
t67 = br_d4*t66
t68 = t59*t32
t69 = t4*t68
t70 = t35**2
t71 = 0.1e1_dp/t70
t72 = t69*t71
t76 = t1*t57*pi
t77 = br_d5*t76
t78 = t59**2
t79 = t3*t78
t81 = 0.1e1_dp/t70/t16
t82 = t79*t81
t85 = br_d0 + 0.2e1_dp/0.3e1_dp*t50*t51 + 0.4e1_dp/0.9e1_dp*t54*t37 &
+ 0.8e1_dp/0.27e2_dp*t58*t63 + 0.16e2_dp/0.81e2_dp*t67*t72 + 0.32e2_dp &
/0.243e3_dp*t77*t82
t86 = t49*t85
t87 = br_e1*t2
t90 = br_e2*t30
t93 = br_e3*t57
t96 = br_e4*t66
t99 = br_e5*t76
t102 = br_e0 + 0.2e1_dp/0.3e1_dp*t87*t51 + 0.4e1_dp/0.9e1_dp*t90*t37 &
+ 0.8e1_dp/0.27e2_dp*t93*t63 + 0.16e2_dp/0.81e2_dp*t96*t72 + 0.32e2_dp &
/0.243e3_dp*t99*t82
t103 = 0.1e1_dp/t102
t104 = t86*t103
t106 = EXP(t104/0.3e1_dp)
t107 = t21*t106
t108 = 0.1e1_dp/t49
t109 = 0.1e1_dp/t85
t110 = t108*t109
t111 = EXP(-t104)
t112 = t103*t111
t115 = 0.1e1_dp - t111 - t86*t112/0.2e1_dp
t117 = t110*t102*t115
e_0 = e_0 + (-t107*t117)*sx
END IF
IF (grad_deriv >= 1 .OR. grad_deriv == -1) THEN
t124 = 0.1e1_dp/t4/t32
t131 = 0.1e1_dp/t4/t33*gamma*t9
t134 = 0.1e1_dp/t41
t137 = t3*t32
t138 = t137*t36
t142 = t62*gamma
t143 = t142*t9
t154 = t42*t23
t157 = -0.2500000000e1_dp*t24*t124*t16 - 0.1250000000e0_dp*t24* &
t131 + 0.3e1_dp/0.4e1_dp*t134*t22*t23*t26*(0.40e2_dp/0.27e2_dp* &
t31*t138 + 0.2e1_dp/0.27e2_dp*t31*t19*t143) - 0.5e1_dp/0.2e1_dp* &
t42*t23*t124*t16 - t154*t131/0.8e1_dp
t158 = 0.1e1_dp/t47
t159 = t157*t158
t160 = t85*t103
t162 = t4*t17
t165 = 0.1e1_dp/t3
t167 = t36*gamma
t168 = t167*t9
t176 = t59*t62
t180 = t71*gamma
t181 = t180*t9
t184 = t4*t60
t185 = t184*t71
t188 = t4*t59
t190 = t81*gamma
t191 = t190*t9
t195 = t3*t59*t33
t196 = t195*t81
t199 = t3*t68
t202 = 0.1e1_dp/t70/t35
t203 = t202*gamma
t204 = t203*t9
t207 = 0.10e2_dp/0.9e1_dp*t50*t162 + t50*t165*t168/0.18e2_dp + 0.40e2_dp &
/0.27e2_dp*t54*t138 + 0.2e1_dp/0.27e2_dp*t54*t19*t143 + &
0.40e2_dp/0.27e2_dp*t58*t176 + 0.2e1_dp/0.27e2_dp*t58*t33*t181 + &
0.320e3_dp/0.243e3_dp*t67*t185 + 0.16e2_dp/0.243e3_dp*t67*t188* &
t191 + 0.800e3_dp/0.729e3_dp*t77*t196 + 0.40e2_dp/0.729e3_dp*t77*t199 &
*t204
t208 = t49*t207
t210 = t102**2
t211 = 0.1e1_dp/t210
t237 = 0.10e2_dp/0.9e1_dp*t87*t162 + t87*t165*t168/0.18e2_dp + 0.40e2_dp &
/0.27e2_dp*t90*t138 + 0.2e1_dp/0.27e2_dp*t90*t19*t143 + &
0.40e2_dp/0.27e2_dp*t93*t176 + 0.2e1_dp/0.27e2_dp*t93*t33*t181 + &
0.320e3_dp/0.243e3_dp*t96*t185 + 0.16e2_dp/0.243e3_dp*t96*t188* &
t191 + 0.800e3_dp/0.729e3_dp*t99*t196 + 0.40e2_dp/0.729e3_dp*t99*t199 &
*t204
t240 = t159*t160 + t208*t103 - t86*t211*t237
t245 = t49**2
t248 = t21*t106/t245
t249 = t109*t102
t255 = t21*t106*t108
t256 = t85**2
t258 = 0.1e1_dp/t256*t102
t265 = -t240
t267 = t160*t111
t272 = t211*t111
e_rho = e_rho + (-0.4e1_dp/0.3e1_dp*t3*t20*t106*t117 - t21*t240*t106 &
*t117/0.3e1_dp + t248*t249*t115*t157*t158 + t255*t258* &
t115*t207 - t107*t110*t237*t115 - t107*t110*t102*(-t265 &
*t111 - t159*t267/0.2e1_dp - t208*t112/0.2e1_dp + t86*t272 &
*t237/0.2e1_dp - t86*t103*t265*t111/0.2e1_dp))*sx
t285 = t124*gamma*ndrho
t288 = t134*br_BB
t289 = t288*t2
t297 = 0.2500000000000000e0_dp*t24*t285 - t289*t4*t36*gamma* &
ndrho/0.9e1_dp + t154*t285/0.4e1_dp
t298 = t297*t158
t301 = t167*ndrho
t305 = t142*ndrho
t309 = t180*ndrho
t313 = t190*ndrho
t317 = t203*ndrho
t320 = -t50*t4*t301/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t54*t137*t305 &
- 0.4e1_dp/0.27e2_dp*t58*t59*t309 - 0.32e2_dp/0.243e3_dp*t67*t184 &
*t313 - 0.80e2_dp/0.729e3_dp*t77*t195*t317
t321 = t49*t320
t338 = -t87*t4*t301/0.9e1_dp - 0.4e1_dp/0.27e2_dp*t90*t137*t305 &
- 0.4e1_dp/0.27e2_dp*t93*t59*t309 - 0.32e2_dp/0.243e3_dp*t96*t184 &
*t313 - 0.80e2_dp/0.729e3_dp*t99*t195*t317
t341 = t298*t160 + t321*t103 - t86*t211*t338
t356 = -t341