1 /* Copyright 2014-2018 The PySCF Developers. All Rights Reserved.
2 
3    Licensed under the Apache License, Version 2.0 (the "License");
4     you may not use this file except in compliance with the License.
5     You may obtain a copy of the License at
6 
7         http://www.apache.org/licenses/LICENSE-2.0
8 
9     Unless required by applicable law or agreed to in writing, software
10     distributed under the License is distributed on an "AS IS" BASIS,
11     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12     See the License for the specific language governing permissions and
13     limitations under the License.
14 
15  *
16  * Author: Qiming Sun <osirpt.sun@gmail.com>
17  */
18 
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include <complex.h>
22 #include <math.h>
23 #include "cint.h"
24 
25 // 2 slots of int param[]
26 #define POS_E1   0
27 #define TENSOR   1
28 
29 #define LMAX            7
30 #define SIMDD           8
31 // 128s42p21d12f8g6h4i3j
32 #define NCTR_CART       128
33 #define NPRIMAX         40
34 #define BLKSIZE         104
35 #define EXPCUTOFF       50  // 1e-22
36 #define NOTZERO(e)      (fabs(e)>1e-18)
37 
38 #ifndef HAVE_NONZERO_EXP
39 #define HAVE_NONZERO_EXP
_nonzero_in(double * exps,int count)40 inline static int _nonzero_in(double *exps, int count) {
41         int n;
42         int val = 0;
43         for (n = 0; n < count; n++) {
44                 if NOTZERO(exps[n]) {
45                         val = 1;
46                         break;
47                 }
48         }
49         return val;
50 }
51 #endif
52 
53 typedef int (*FPtr_exp)(double *ectr, double *coord, double *alpha, double *coeff,
54                         int l, int nprim, int nctr, size_t ngrids, double fac);
55 typedef void (*FPtr_eval)(double *gto, double *ri, double *exps,
56                           double *coord, double *alpha, double *coeff,
57                           double *env, int l, int np, int nc,
58                           size_t nao, size_t ngrids, size_t blksize);
59 
60 void GTOnabla1(double *fx1, double *fy1, double *fz1,
61                double *fx0, double *fy0, double *fz0, int l, double a);
62 void GTOx1(double *fx1, double *fy1, double *fz1,
63            double *fx0, double *fy0, double *fz0, int l, double *ri);
64 int GTOprim_exp(double *eprim, double *coord, double *alpha, double *coeff,
65                 int l, int nprim, int nctr, size_t ngrids, double fac);
66 int GTOcontract_exp0(double *ectr, double *coord, double *alpha, double *coeff,
67                      int l, int nprim, int nctr, size_t ngrids, double fac);
68 int GTOcontract_exp1(double *ectr, double *coord, double *alpha, double *coeff,
69                      int l, int nprim, int nctr, size_t ngrids, double fac);
70 
71 void GTOeval_sph_drv(FPtr_eval feval, FPtr_exp fexp, double fac,
72                      int ngrids, int param[], int *shls_slice, int *ao_loc,
73                      double *ao, double *coord, char *non0table,
74                      int *atm, int natm, int *bas, int nbas, double *env);
75 
76 void GTOeval_cart_drv(FPtr_eval feval, FPtr_exp fexp, double fac,
77                       int ngrids, int param[], int *shls_slice, int *ao_loc,
78                       double *ao, double *coord, char *non0table,
79                       int *atm, int natm, int *bas, int nbas, double *env);
80 
81 void GTOeval_spinor_drv(FPtr_eval feval, FPtr_exp fexp, void (*c2s)(), double fac,
82                         int ngrids, int param[], int *shls_slice, int *ao_loc,
83                         double complex *ao, double *coord, char *non0table,
84                         int *atm, int natm, int *bas, int nbas, double *env);
85 
86 #define GTO_D_I(o, i, l) \
87         GTOnabla1(fx##o, fy##o, fz##o, fx##i, fy##i, fz##i, l, alpha[k])
88 /* r-R_0, R_0 is (0,0,0) */
89 #define GTO_R0I(o, i, l) \
90         GTOx1(fx##o, fy##o, fz##o, fx##i, fy##i, fz##i, l, ri)
91 /* r-R_C, R_C is common origin */
92 #define GTO_RCI(o, i, l) \
93         GTOx1(fx##o, fy##o, fz##o, fx##i, fy##i, fz##i, l, dri)
94 /* origin from center of each basis
95  * x1(fx1, fy1, fz1, fx0, fy0, fz0, l, 0, 0, 0) */
96 #define GTO_R_I(o, i, l) \
97         fx##o = fx##i + SIMDD; \
98         fy##o = fy##i + SIMDD; \
99         fz##o = fz##i + SIMDD
100 
101 #define ALIGN8_UP(buf) (void *)(((uintptr_t)buf + 7) & (-(uintptr_t)8))
102