(git:e7e05ae)
semi_empirical_int_debug.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Debug the derivatives of the the rotational matrices
10 !>
11 !> \param sepi ...
12 !> \param sepj ...
13 !> \param rjiv ...
14 !> \param ij_matrix ...
15 !> \param do_invert ...
16 !> \date 04.2008 [tlaino]
17 !> \author Teodoro Laino [tlaino] - University of Zurich
18 ! **************************************************************************************************
19 SUBROUTINE check_rotmat_der(sepi, sepj, rjiv, ij_matrix, do_invert)
20 
21  USE kinds, ONLY: dp
25  rotmat_type, &
26  semi_empirical_type, &
27  se_int_control_type
28 #include "./base/base_uses.f90"
29  IMPLICIT NONE
30  TYPE(semi_empirical_type), POINTER :: sepi, sepj
31  REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: rjiv
32  TYPE(rotmat_type), POINTER :: ij_matrix
33  LOGICAL, INTENT(IN) :: do_invert
34 
35  CHARACTER(len=*), PARAMETER :: modulen = 'semi_empirical_int_debug', &
36  routinen = 'check_rotmat_der', routinep = modulen//':'//routinen
37 
38  LOGICAL :: check_value
39  REAL(kind=dp) :: dx, r, r0(3), x(3)
40  TYPE(rotmat_type), POINTER :: matrix, matrix_m, matrix_n, &
41  matrix_p
42  INTEGER :: imap(3), i, j, k, l
43 
44  NULLIFY (matrix_m, matrix_p, matrix_n, matrix)
45  CALL rotmat_create(matrix_p)
46  CALL rotmat_create(matrix_m)
47  CALL rotmat_create(matrix_n)
48  dx = 1.0e-6_dp
49  imap(1) = 1
50  imap(2) = 2
51  imap(3) = 3
52  IF (do_invert) THEN
53  imap(1) = 3
54  imap(2) = 2
55  imap(3) = 1
56  END IF
57  ! Check derivatives: analytical VS numerical
58  WRITE (*, *) "DEBUG::"//routinep
59  DO j = 1, 3
60  x = 0.0_dp
61  x(imap(j)) = dx
62  DO i = 1, 2
63  IF (i == 1) matrix => matrix_p
64  IF (i == 2) matrix => matrix_m
65  r0 = rjiv + (-1.0_dp)**(i - 1)*x
66  r = sqrt(dot_product(r0, r0))
67  CALL rotmat(sepi, sepj, r0, r, matrix, do_derivatives=.false., debug_invert=do_invert)
68  END DO
69  ! SP
70  matrix_n%sp_d(j, :, :) = (matrix_p%sp - matrix_m%sp)/(2.0_dp*dx)
71  DO i = 1, 3
72  DO k = 1, 3
73  IF (.NOT. check_value(matrix_n%sp_d(j, k, i), ij_matrix%sp_d(j, k, i), dx, 0.1_dp)) THEN
74  WRITE (*, *) "ERROR for SP rotation matrix derivative SP(j,k,i), j,k,i::", j, k, i
75  cpabort("")
76  END IF
77  END DO
78  END DO
79  ! PP
80  matrix_n%pp_d(j, :, :, :) = (matrix_p%pp - matrix_m%pp)/(2.0_dp*dx)
81  DO i = 1, 3
82  DO k = 1, 3
83  DO l = 1, 6
84  IF (.NOT. check_value(matrix_n%pp_d(j, l, k, i), ij_matrix%pp_d(j, l, k, i), dx, 0.1_dp)) THEN
85  WRITE (*, *) "ERROR for PP rotation matrix derivative PP(j,l,k,i), j,l,k,i::", j, l, k, i
86  cpabort("")
87  END IF
88  END DO
89  END DO
90  END DO
91  ! d-orbitals debug
92  IF (sepi%dorb .OR. sepj%dorb) THEN
93  ! SD
94  matrix_n%sd_d(j, :, :) = (matrix_p%sd - matrix_m%sd)/(2.0_dp*dx)
95  DO i = 1, 5
96  DO k = 1, 5
97  IF (.NOT. check_value(matrix_n%sd_d(j, k, i), ij_matrix%sd_d(j, k, i), dx, 0.1_dp)) THEN
98  WRITE (*, *) "ERROR for SD rotation matrix derivative SD(j,k,i), j,k,i::", j, k, i
99  cpabort("")
100  END IF
101  END DO
102  END DO
103  ! DP
104  matrix_n%pd_d(j, :, :, :) = (matrix_p%pd - matrix_m%pd)/(2.0_dp*dx)
105  DO i = 1, 3
106  DO k = 1, 5
107  DO l = 1, 15
108  IF (.NOT. check_value(matrix_n%pd_d(j, l, k, i), ij_matrix%pd_d(j, l, k, i), dx, 0.1_dp)) THEN
109  WRITE (*, *) "ERROR for DP rotation matrix derivative DP(j,l,k,i), j,l,k,i::", j, l, k, i
110  cpabort("")
111  END IF
112  END DO
113  END DO
114  END DO
115  ! DD
116  matrix_n%dd_d(j, :, :, :) = (matrix_p%dd - matrix_m%dd)/(2.0_dp*dx)
117  DO i = 1, 5
118  DO k = 1, 5
119  DO l = 1, 15
120  IF (.NOT. check_value(matrix_n%dd_d(j, l, k, i), ij_matrix%dd_d(j, l, k, i), dx, 0.1_dp)) THEN
121  WRITE (*, *) "ERROR for DD rotation matrix derivative DD(j,l,k,i), j,l,k,i::", j, l, k, i
122  cpabort("")
123  END IF
124  END DO
125  END DO
126  END DO
127  END IF
128  END DO
129  CALL rotmat_release(matrix_p)
130  CALL rotmat_release(matrix_m)
131  CALL rotmat_release(matrix_n)
132 END SUBROUTINE check_rotmat_der
133 
134 ! **************************************************************************************************
135 !> \brief Check Numerical Vs Analytical
136 !> \param sepi ...
137 !> \param sepj ...
138 !> \param rijv ...
139 !> \param se_int_control ...
140 !> \param se_taper ...
141 !> \param invert ...
142 !> \param ii ...
143 !> \param kk ...
144 !> \param v_d ...
145 !> \par History
146 !> 04.2008 created [tlaino]
147 !> \author Teodoro Laino - Zurich University
148 !> \note
149 !> Debug routine
150 ! **************************************************************************************************
151 SUBROUTINE rot_2el_2c_first_debug(sepi, sepj, rijv, se_int_control, se_taper, invert, ii, kk, v_d)
152 
153  USE kinds, ONLY: dp
157  USE semi_empirical_types, ONLY: semi_empirical_type, &
158  rotmat_type, &
159  rotmat_create, &
160  rotmat_release, &
161  se_int_control_type, &
162  se_taper_type
164 #include "./base/base_uses.f90"
165  IMPLICIT NONE
166  TYPE(semi_empirical_type), POINTER :: sepi, sepj
167  REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: rijv
168  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
169  LOGICAL, INTENT(IN) :: invert
170  TYPE(se_taper_type), POINTER :: se_taper
171  INTEGER, INTENT(IN) :: ii, kk
172  REAL(KIND=dp), DIMENSION(3, 45, 45), &
173  INTENT(IN) :: v_d
174 
175  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
176  routinen = 'rot_2el_2c_first', routinep = modulen//':'//routinen
177 
178  REAL(KIND=dp), DIMENSION(491) :: rep
179  LOGICAL, DIMENSION(45, 45) :: logv
180  REAL(KIND=dp), DIMENSION(45, 45) :: v_n, v_p, v_m
181 
182  LOGICAL :: check_value
183  REAL(KIND=dp) :: dx, r, r0(3), x(3)
184  TYPE(rotmat_type), POINTER :: matrix
185  INTEGER :: imap(3), i, j, k, limkl
186 
187  NULLIFY (matrix)
188  dx = 1.0e-6_dp
189  imap(1) = 1
190  imap(2) = 2
191  imap(3) = 3
192  IF (invert) THEN
193  imap(1) = 3
194  imap(2) = 2
195  imap(3) = 1
196  END IF
197  limkl = indexb(kk, kk)
198  ! Check derivatives: analytical VS numerical
199  WRITE (*, *) "DEBUG::"//routinep
200  DO j = 1, 3
201  x = 0.0_dp
202  x(imap(j)) = dx
203  DO i = 1, 2
204  r0 = rijv + (-1.0_dp)**(i - 1)*x
205  r = sqrt(dot_product(r0, r0))
206 
207  CALL rotmat_create(matrix)
208  CALL rotmat(sepi, sepj, r0, r, matrix, do_derivatives=.false., debug_invert=invert)
209 
210  ! Compute integrals in diatomic frame
211  CALL terep_num(sepi, sepj, r, rep, se_taper=se_taper, se_int_control=se_int_control)
212 
213  IF (i == 1) THEN
214  CALL rot_2el_2c_first(sepi, sepj, r0, se_int_control, se_taper, invert, ii, kk, rep, logv, matrix, &
215  v_p, lgrad=.false.)
216  END IF
217  IF (i == 2) THEN
218  CALL rot_2el_2c_first(sepi, sepj, r0, se_int_control, se_taper, invert, ii, kk, rep, logv, matrix, &
219  v_m, lgrad=.false.)
220  END IF
221  CALL rotmat_release(matrix)
222  END DO
223  ! Check numerical VS analytical
224  DO i = 1, 45
225  DO k = 1, limkl
226  ! Compute the numerical derivative
227  v_n(i, k) = (v_p(i, k) - v_m(i, k))/(2.0_dp*dx)
228  IF (.NOT. check_value(v_d(j, i, k), v_n(i, k), dx, 0.1_dp)) THEN
229  WRITE (*, *) "ERROR for rot_2el_2c_first derivative V_D(j,i,k), j,i,k::", j, i, k
230  cpabort("")
231  END IF
232  END DO
233  END DO
234  END DO
235 END SUBROUTINE rot_2el_2c_first_debug
236 
237 ! **************************************************************************************************
238 !> \brief Check Numerical Vs Analytical ssss
239 !> \param sepi ...
240 !> \param sepj ...
241 !> \param r ...
242 !> \param dssss ...
243 !> \param itype ...
244 !> \param se_int_control ...
245 !> \param se_taper ...
246 !> \par History
247 !> 04.2008 created [tlaino]
248 !> \author Teodoro Laino - Zurich University
249 !> \note
250 !> Debug routine
251 ! **************************************************************************************************
252 SUBROUTINE check_dssss_nucint_ana(sepi, sepj, r, dssss, itype, se_int_control, se_taper)
253 
254  USE kinds, ONLY: dp
256  USE semi_empirical_types, ONLY: semi_empirical_type, &
257  se_int_control_type, &
258  se_taper_type
259 #include "./base/base_uses.f90"
260  IMPLICIT NONE
261  TYPE(semi_empirical_type), POINTER :: sepi, sepj
262  REAL(dp), INTENT(IN) :: r
263  REAL(dp), INTENT(IN) :: dssss
264  INTEGER, INTENT(IN) :: itype
265  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
266  TYPE(se_taper_type), POINTER :: se_taper
267 
268  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
269  routinen = 'check_dssss_nucint_ana', routinep = modulen//':'//routinen
270 
271  REAL(dp) :: delta, nssss, od, rn, ssssm, ssssp
272  LOGICAL :: check_value
273 
274  delta = 1.0e-8_dp
275  od = 0.5_dp/delta
276  rn = r + delta
277  CALL ssss_nucint_num(sepi, sepj, rn, ssssp, itype, se_taper, se_int_control)
278  rn = r - delta
279  CALL ssss_nucint_num(sepi, sepj, rn, ssssm, itype, se_taper, se_int_control)
280  nssss = od*(ssssp - ssssm)
281  ! check
282  WRITE (*, *) "DEBUG::"//routinep
283  IF (.NOT. check_value(nssss, dssss, delta, 0.1_dp)) THEN
284  WRITE (*, *) "ERROR for SSSS derivative SSSS"
285  cpabort("")
286  END IF
287 END SUBROUTINE check_dssss_nucint_ana
288 
289 ! **************************************************************************************************
290 !> \brief Check Numerical Vs Analytical core
291 !> \param sepi ...
292 !> \param sepj ...
293 !> \param r ...
294 !> \param dcore ...
295 !> \param itype ...
296 !> \param se_int_control ...
297 !> \param se_taper ...
298 !> \par History
299 !> 04.2008 created [tlaino]
300 !> \author Teodoro Laino - Zurich University
301 !> \note
302 !> Debug routine
303 ! **************************************************************************************************
304 SUBROUTINE check_dcore_nucint_ana(sepi, sepj, r, dcore, itype, se_int_control, se_taper)
305 
306  USE kinds, ONLY: dp
308  USE semi_empirical_types, ONLY: semi_empirical_type, &
309  se_int_control_type, &
310  se_taper_type
311 #include "./base/base_uses.f90"
312  IMPLICIT NONE
313  TYPE(semi_empirical_type), POINTER :: sepi, sepj
314  REAL(dp), INTENT(IN) :: r
315  REAL(dp), DIMENSION(10, 2), INTENT(IN) :: dcore
316  INTEGER, INTENT(IN) :: itype
317  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
318  TYPE(se_taper_type), POINTER :: se_taper
319 
320  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
321  routinen = 'check_dcore_nucint_ana', routinep = modulen//':'//routinen
322 
323  INTEGER :: i, j
324  REAL(dp) :: delta, od, rn
325  REAL(dp), DIMENSION(10, 2) :: corem, corep, ncore
326  LOGICAL :: check_value
327 
328  delta = 1.0e-8_dp
329  od = 0.5_dp/delta
330  rn = r + delta
331  CALL core_nucint_num(sepi, sepj, rn, corep, itype, se_taper, se_int_control)
332  rn = r - delta
333  CALL core_nucint_num(sepi, sepj, rn, corem, itype, se_taper, se_int_control)
334  ncore = od*(corep - corem)
335  ! check
336  WRITE (*, *) "DEBUG::"//routinep
337  DO i = 1, 2
338  DO j = 1, 10
339  IF (.NOT. check_value(ncore(j, i), dcore(j, i), delta, 0.1_dp)) THEN
340  WRITE (*, *) "ERROR for CORE derivative CORE(j,i), j,i::", j, i
341  cpabort("")
342  END IF
343  END DO
344  END DO
345 END SUBROUTINE check_dcore_nucint_ana
346 
347 ! **************************************************************************************************
348 !> \brief Low level comparison function between numberical and analytical values
349 !> \param num ...
350 !> \param ana ...
351 !> \param minval ...
352 !> \param thrs ...
353 !> \return ...
354 !> \par History
355 !> 04.2008 created [tlaino]
356 !> \author Teodoro Laino - Zurich University
357 !> \note
358 !> Debug routine
359 ! **************************************************************************************************
360 FUNCTION check_value(num, ana, minval, thrs) RESULT(passed)
361  USE kinds, ONLY: dp
362  IMPLICIT NONE
363  REAL(kind=dp) :: num, ana, thrs, minval
364  LOGICAL :: passed
365 
366  passed = .true.
367 
368  IF ((abs(num) < minval) .AND. (abs(ana) > minval)) THEN
369  WRITE (*, *) "WARNING ---> ", num, ana, thrs
370  ELSE IF ((abs(num) > minval) .AND. (abs(ana) < minval)) THEN
371  WRITE (*, *) "WARNING ---> ", num, ana, thrs
372  ELSE IF ((abs(num) < minval) .AND. (abs(ana) < minval)) THEN
373  ! skip..
374  RETURN
375  END IF
376  IF (abs((num - ana)/num*100._dp) > thrs) THEN
377  WRITE (*, *) abs(num - ana)/num*100._dp, thrs
378  passed = .false.
379  END IF
380  IF (.NOT. passed) THEN
381  WRITE (*, *) "ANALYTICAL ::", ana
382  WRITE (*, *) "NUMERICAL ::", num
383  END IF
384 END FUNCTION check_value
385 
386 ! **************************************************************************************************
387 !> \brief Check Numerical Vs Analytical
388 !> \param sepi ...
389 !> \param sepj ...
390 !> \param rijv ...
391 !> \param itype ...
392 !> \param se_int_control ...
393 !> \param se_taper ...
394 !> \param e1b ...
395 !> \param e2a ...
396 !> \param de1b ...
397 !> \param de2a ...
398 !> \par History
399 !> 04.2008 created [tlaino]
400 !> \author Teodoro Laino - Zurich University
401 !> \note
402 !> Debug routine
403 ! **************************************************************************************************
404 SUBROUTINE check_drotnuc_ana(sepi, sepj, rijv, itype, se_int_control, se_taper, e1b, e2a, de1b, de2a)
405 
406  USE kinds, ONLY: dp
407  USE semi_empirical_int_num, ONLY: rotnuc_num, &
409  USE semi_empirical_types, ONLY: semi_empirical_type, &
410  se_int_control_type, &
411  se_taper_type
412 #include "./base/base_uses.f90"
413  IMPLICIT NONE
414  TYPE(semi_empirical_type), POINTER :: sepi, sepj
415  REAL(dp), DIMENSION(3), INTENT(IN) :: rijv
416  INTEGER, INTENT(IN) :: itype
417  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
418  TYPE(se_taper_type), POINTER :: se_taper
419  REAL(dp), DIMENSION(45), INTENT(IN), &
420  OPTIONAL :: e1b, e2a
421  REAL(dp), DIMENSION(3, 45), &
422  INTENT(IN), OPTIONAL :: de1b, de2a
423 
424  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
425  routinen = 'check_drotnuc_ana', routinep = modulen//':'//routinen
426 
427  INTEGER :: i, j
428  LOGICAL :: l_de1b, l_de2a, l_e1b, l_e2a, &
429  lgrad, check_value
430  REAL(dp) :: delta
431  REAL(KIND=dp), DIMENSION(45) :: e1b2, e2a2
432  REAL(KIND=dp), DIMENSION(3, 45) :: de1b2, de2a2
433 
434  l_e1b = PRESENT(e1b)
435  l_e2a = PRESENT(e2a)
436  l_de1b = PRESENT(de1b)
437  l_de2a = PRESENT(de2a)
438  lgrad = l_de1b .OR. l_de2a
439  delta = 1.0e-5_dp
440  ! Check value of integrals
441  WRITE (*, *) "DEBUG::"//routinep
442  CALL rotnuc_num(sepi, sepj, rijv, e1b2, e2a2, itype, se_int_control, se_taper=se_taper)
443  IF (l_e1b) THEN
444  DO j = 1, 45
445  IF (.NOT. check_value(e1b2(j), e1b(j), delta, 0.1_dp)) THEN
446  WRITE (*, *) "ERROR for E1B value E1B(j), j::", j
447  cpabort("")
448  END IF
449  END DO
450  END IF
451  IF (l_e2a) THEN
452  DO j = 1, 45
453  IF (.NOT. check_value(e2a2(j), e2a(j), delta, 0.1_dp)) THEN
454  WRITE (*, *) "ERROR for E2A value E2A(j), j::", j
455  cpabort("")
456  END IF
457  END DO
458  END IF
459 
460  ! Check derivatives
461  IF (lgrad) THEN
462  CALL drotnuc_num(sepi, sepj, rijv, de1b2, de2a2, itype, delta=delta, &
463  se_int_control=se_int_control, se_taper=se_taper)
464  IF (l_de1b) THEN
465  DO i = 1, 3
466  DO j = 1, 45
467  ! Additional check on the value of the integral before checking derivatives
468  IF (abs(e1b2(j)) > delta) THEN
469  IF (.NOT. check_value(de1b2(i, j), de1b(i, j), delta, 0.1_dp)) THEN
470  WRITE (*, *) "ERROR for derivative of E1B. DE1B(i,j), i,j::", i, j
471  cpabort("")
472  END IF
473  END IF
474  END DO
475  END DO
476  END IF
477  IF (l_de2a) THEN
478  DO i = 1, 3
479  DO j = 1, 45
480  ! Additional check on the value of the integral before checking derivatives
481  IF (abs(e2a2(j)) > delta) THEN
482  IF (.NOT. check_value(de2a2(i, j), de2a(i, j), delta, 0.1_dp)) THEN
483  WRITE (*, *) "ERROR for derivative of E2A. DE2A(i,j), i,j::", i, j
484  cpabort("")
485  END IF
486  END IF
487  END DO
488  END DO
489  END IF
490  END IF
491 END SUBROUTINE check_drotnuc_ana
492 
493 ! **************************************************************************************************
494 !> \brief Check Numerical Vs Analytical CORE-CORE
495 !> \param sepi ...
496 !> \param sepj ...
497 !> \param rijv ...
498 !> \param itype ...
499 !> \param se_int_control ...
500 !> \param se_taper ...
501 !> \param enuc ...
502 !> \param denuc ...
503 !> \par History
504 !> 04.2007 created [tlaino]
505 !> \author Teodoro Laino - Zurich University
506 !> \note
507 !> Debug routine
508 ! **************************************************************************************************
509 SUBROUTINE check_dcorecore_ana(sepi, sepj, rijv, itype, se_int_control, se_taper, enuc, denuc)
510 
511  USE kinds, ONLY: dp
514  USE semi_empirical_types, ONLY: semi_empirical_type, &
515  se_int_control_type, &
516  se_taper_type
517 #include "./base/base_uses.f90"
518  IMPLICIT NONE
519  TYPE(semi_empirical_type), POINTER :: sepi, sepj
520  REAL(dp), DIMENSION(3), INTENT(IN) :: rijv
521  INTEGER, INTENT(IN) :: itype
522  REAL(dp), INTENT(IN), OPTIONAL :: enuc
523  REAL(dp), DIMENSION(3), INTENT(IN), &
524  OPTIONAL :: denuc
525  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
526  TYPE(se_taper_type), POINTER :: se_taper
527 
528  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
529  routinen = 'check_dcorecore_ana', routinep = modulen//':'//routinen
530 
531  LOGICAL :: check_value
532  INTEGER :: j
533  REAL(dp) :: enuc_num, delta
534  REAL(dp), DIMENSION(3) :: denuc_num
535 
536  WRITE (*, *) "DEBUG::"//routinep
537  delta = 1.0e-7_dp
538  ! check
539  IF (PRESENT(enuc)) THEN
540  CALL corecore_num(sepi, sepj, rijv, enuc_num, itype, se_int_control, se_taper)
541  IF (.NOT. check_value(enuc, enuc_num, delta, 0.001_dp)) THEN
542  WRITE (*, *) "ERROR for CORE-CORE energy value (numerical different from analytical)!!"
543  cpabort("")
544  END IF
545  END IF
546  IF (PRESENT(denuc)) THEN
547  CALL dcorecore_num(sepi, sepj, rijv, denuc_num, itype, delta, se_int_control, se_taper)
548  DO j = 1, 3
549  IF (.NOT. check_value(denuc(j), denuc_num(j), delta, 0.001_dp)) THEN
550  WRITE (*, *) "ERROR for CORE-CORE energy derivative value (numerical different from analytical). DENUC(j), j::", j
551  cpabort("")
552  END IF
553  END DO
554  END IF
555 END SUBROUTINE check_dcorecore_ana
556 
557 ! **************************************************************************************************
558 !> \brief Check Numerical Vs Analytical DTEREP_ANA
559 !> \param sepi ...
560 !> \param sepj ...
561 !> \param r ...
562 !> \param ri ...
563 !> \param dri ...
564 !> \param se_int_control ...
565 !> \param se_taper ...
566 !> \param lgrad ...
567 !> \par History
568 !> 04.2007 created [tlaino]
569 !> \author Teodoro Laino - Zurich University
570 !> \note
571 !> Debug routine
572 ! **************************************************************************************************
573 SUBROUTINE check_dterep_ana(sepi, sepj, r, ri, dri, se_int_control, se_taper, lgrad)
574 
575  USE kinds, ONLY: dp
577  USE semi_empirical_types, ONLY: semi_empirical_type, &
578  se_int_control_type, &
579  se_taper_type
580 #include "./base/base_uses.f90"
581  IMPLICIT NONE
582  TYPE(semi_empirical_type), POINTER :: sepi, sepj
583  REAL(dp), INTENT(IN) :: r
584  REAL(dp), DIMENSION(491), INTENT(IN) :: ri, dri
585  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
586  LOGICAL, INTENT(IN) :: lgrad
587  TYPE(se_taper_type), POINTER :: se_taper
588 
589  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
590  routinen = 'check_dterep_ana', routinep = modulen//':'//routinen
591 
592  LOGICAL :: check_value
593  INTEGER :: j, i
594  REAL(dp) :: delta, od, rn
595  REAL(dp), DIMENSION(491) :: nri, ri0, rim, rip
596 
597  delta = 1.0e-8_dp
598  od = 0.5_dp/delta
599  rn = r
600  CALL terep_num(sepi, sepj, rn, ri0, se_taper, se_int_control)
601  IF (lgrad) THEN
602  rn = r + delta
603  CALL terep_num(sepi, sepj, rn, rip, se_taper, se_int_control)
604  rn = r - delta
605  CALL terep_num(sepi, sepj, rn, rim, se_taper, se_int_control)
606  nri = od*(rip - rim)
607  END IF
608  ! check
609  WRITE (*, *) "DEBUG::"//routinep
610  DO j = 1, 491
611  IF (abs(ri(j) - ri0(j)) > epsilon(0.0_dp)) THEN
612  WRITE (*, *) "Error in value of the integral RI", j, ri(j), ri0(j)
613  cpabort("")
614  END IF
615  IF (lgrad) THEN
616  IF (.NOT. check_value(dri(j), nri(j), delta*100.0_dp, 0.1_dp)) THEN
617  WRITE (*, *) "ERROR for derivative of RI integral, RI(j), j::", j
618  WRITE (*, *) "FULL SET OF INTEGRALS: INDX ANAL NUM DIFF"
619  DO i = 1, 491
620  WRITE (*, '(I5,3F15.9)') i, dri(i), nri(i), nri(i) - dri(i)
621  END DO
622  cpabort("")
623  END IF
624  END IF
625  END DO
626 END SUBROUTINE check_dterep_ana
627 
628 ! **************************************************************************************************
629 !> \brief Check Numerical Vs Analytical ROTINT_ANA
630 !> \param sepi ...
631 !> \param sepj ...
632 !> \param rijv ...
633 !> \param w ...
634 !> \param dw ...
635 !> \param se_int_control ...
636 !> \param se_taper ...
637 !> \par History
638 !> 04.2008 created [tlaino]
639 !> \author Teodoro Laino - Zurich University
640 !> \note
641 !> Debug routine
642 ! **************************************************************************************************
643 SUBROUTINE check_rotint_ana(sepi, sepj, rijv, w, dw, se_int_control, se_taper)
644 
645  USE kinds, ONLY: dp
646  USE semi_empirical_int_num, ONLY: rotint_num, &
648  USE semi_empirical_types, ONLY: semi_empirical_type, &
649  se_int_control_type, &
650  se_taper_type
651 #include "./base/base_uses.f90"
652  IMPLICIT NONE
653  TYPE(semi_empirical_type), POINTER :: sepi, sepj
654  REAL(dp), DIMENSION(3), INTENT(IN) :: rijv
655  REAL(dp), DIMENSION(2025), INTENT(IN), &
656  OPTIONAL :: w
657  REAL(dp), DIMENSION(3, 2025), &
658  INTENT(IN), OPTIONAL :: dw
659  TYPE(se_int_control_type), INTENT(IN) :: se_int_control
660  TYPE(se_taper_type), POINTER :: se_taper
661 
662  CHARACTER(len=*), PARAMETER :: moduleN = 'semi_empirical_int_debug', &
663  routinen = 'rotint_ana', routinep = modulen//':'//routinen
664 
665  REAL(dp), DIMENSION(2025) :: w2
666  REAL(dp), DIMENSION(3, 2025) :: dw2
667  LOGICAL :: check_value
668  INTEGER :: j, i
669  REAL(KIND=dp) :: delta
670 
671  delta = 1.0e-6_dp
672  WRITE (*, *) "DEBUG::"//routinep
673  IF (PRESENT(w)) THEN
674  w2 = 0.0_dp
675  CALL rotint_num(sepi, sepj, rijv, w2, se_int_control, se_taper=se_taper)
676  DO j = 1, 2025
677  IF (.NOT. check_value(w(j), w2(j), delta, 0.1_dp)) THEN
678  WRITE (*, *) "ERROR for integral value W(j), j::", j
679  cpabort("")
680  END IF
681  END DO
682  END IF
683  IF (PRESENT(dw)) THEN
684  ! Numerical derivatives are obviosly a big problem..
685  ! First of all let's decide if the value we get for delta is compatible
686  ! with a reasonable value of the integral.. (compatible if the value of the
687  ! integral is greater than 1.0E-6)
688  CALL drotint_num(sepi, sepj, rijv, dw2, delta=delta, se_int_control=se_int_control, se_taper=se_taper)
689  CALL rotint_num(sepi, sepj, rijv, w2, se_int_control=se_int_control, se_taper=se_taper)
690  DO i = 1, 3
691  DO j = 1, 2025
692  IF ((abs(w2(j)) > delta) .AND. (abs(dw2(i, j)) > delta*10)) THEN
693  IF (.NOT. check_value(dw(i, j), dw2(i, j), delta, 0.1_dp)) THEN
694  WRITE (*, *) "ERROR for derivative of the integral value W(j). DW(i,j) i,j::", i, j
695  cpabort("")
696  END IF
697  END IF
698  END DO
699  END DO
700  END IF
701 END SUBROUTINE check_rotint_ana
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Arrays of parameters used in the semi-empirical calculations \References Everywhere in this module TC...
integer, dimension(9, 9), public indexb
Integrals for semi-empiric methods.
subroutine, public rotnuc_num(sepi, sepj, rijv, e1b, e2a, itype, se_int_control, se_taper)
Computes the two-particle interactions.
subroutine, public rotint_num(sepi, sepj, rijv, w, se_int_control, se_taper)
Computes the two particle interactions in the lab frame.
subroutine, public drotint_num(sepi, sepj, r, dw, delta, se_int_control, se_taper)
Numerical Derivatives for rotint.
subroutine, public core_nucint_num(sepi, sepj, rij, core, itype, se_taper, se_int_control)
Calculates the nuclear attraction integrals CORE (main driver)
subroutine, public ssss_nucint_num(sepi, sepj, rij, ssss, itype, se_taper, se_int_control)
Calculates the SSSS integrals (main driver)
subroutine, public drotnuc_num(sepi, sepj, r, de1b, de2a, itype, delta, se_int_control, se_taper)
Numerical Derivatives for rotnuc.
subroutine, public dcorecore_num(sepi, sepj, r, denuc, itype, delta, se_int_control, se_taper)
Numerical Derivatives for corecore.
subroutine, public corecore_num(sepi, sepj, rijv, enuc, itype, se_int_control, se_taper)
Computes the core-core interactions.
subroutine, public terep_num(sepi, sepj, rij, rep, se_taper, se_int_control)
Calculates the derivative pf two-electron repulsion integrals and the nuclear attraction integrals w....
Utilities for Integrals for semi-empiric methods.
recursive subroutine, public rotmat(sepi, sepj, rjiv, r, ij_matrix, do_derivatives, do_invert, debug_invert)
Computes the general rotation matrices for the integrals between I and J (J>=I)
recursive subroutine, public rot_2el_2c_first(sepi, sepj, rijv, se_int_control, se_taper, invert, ii, kk, rep, logv, ij_matrix, v, lgrad, rep_d, v_d, logv_d, drij)
First Step of the rotation of the two-electron two-center integrals in SPD basis.
Definition of the semi empirical parameter types.
subroutine, public rotmat_release(rotmat)
Releases rotmat type.
subroutine, public rotmat_create(rotmat)
Creates rotmat type.
subroutine check_rotmat_der(sepi, sepj, rjiv, ij_matrix, do_invert)
Debug the derivatives of the the rotational matrices.
subroutine rot_2el_2c_first_debug(sepi, sepj, rijv, se_int_control, se_taper, invert, ii, kk, v_d)
Check Numerical Vs Analytical.
subroutine check_dssss_nucint_ana(sepi, sepj, r, dssss, itype, se_int_control, se_taper)
Check Numerical Vs Analytical ssss.
logical function check_value(num, ana, minval, thrs)
Low level comparison function between numberical and analytical values.
subroutine check_dcorecore_ana(sepi, sepj, rijv, itype, se_int_control, se_taper, enuc, denuc)
Check Numerical Vs Analytical CORE-CORE.
subroutine check_rotint_ana(sepi, sepj, rijv, w, dw, se_int_control, se_taper)
Check Numerical Vs Analytical ROTINT_ANA.
subroutine check_drotnuc_ana(sepi, sepj, rijv, itype, se_int_control, se_taper, e1b, e2a, de1b, de2a)
Check Numerical Vs Analytical.
subroutine check_dcore_nucint_ana(sepi, sepj, r, dcore, itype, se_int_control, se_taper)
Check Numerical Vs Analytical core.
subroutine check_dterep_ana(sepi, sepj, r, ri, dri, se_int_control, se_taper, lgrad)
Check Numerical Vs Analytical DTEREP_ANA.