00001 //
00002 // macros.h
00003 //
00004 // Copyright (C) 2001 Edward Valeev
00005 //
00006 // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
00007 // Maintainer: EV
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027
00028 /* True if the integral is nonzero. */
00029 #define INT_NONZERO(x) (((x)< -1.0e-15)||((x)> 1.0e-15))
00030
00031 /* Computes an index to a Cartesian function within a shell given
00032 * am = total angular momentum
00033 * i = the exponent of x (i is used twice in the macro--beware side effects)
00034 * j = the exponent of y
00035 * formula: (am - i + 1)*(am - i)/2 + am - i - j unless i==am, then 0
00036 * The following loop will generate indices in the proper order:
00037 * cartindex = 0;
00038 * for (i=am; i>=0; i--) {
00039 * for (j=am-i; j>=0; j--) {
00040 * do_it_with(cartindex);
00041 * cartindex++;
00042 * }
00043 * }
00044 */
00045 #define INT_CARTINDEX(am,i,j) (((i) == (am))? 0 : (((((am) - (i) + 1)*((am) - (i)))>>1) + (am) - (i) - (j)))
00046
00047 /* This sets up the above loop over cartesian exponents as follows
00048 * FOR_CART(i,j,k,am)
00049 * Stuff using i,j,k.
00050 * END_FOR_CART
00051 */
00052 #define FOR_CART(i,j,k,am) for((i)=(am);(i)>=0;(i)--) {\
00053 for((j)=(am)-(i);(j)>=0;(j)--) \
00054 { (k) = (am) - (i) - (j);
00055 #define END_FOR_CART }}
00056
00057 /* This sets up a loop over all of the generalized contractions
00058 * and all of the cartesian exponents.
00059 * gc is the number of the gen con
00060 * index is the index within the current gen con.
00061 * i,j,k are the angular momentum for x,y,z
00062 * sh is the shell pointer
00063 */
00064 #define FOR_GCCART(gc,index,i,j,k,sh)\
00065 for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\
00066 (index)=0;\
00067 FOR_CART(i,j,k,(sh)->type[gc].am)
00068
00069 #define FOR_GCCART_GS(gc,index,i,j,k,sh)\
00070 for ((gc)=0; (gc)<(sh)->ncontraction(); (gc)++) {\
00071 (index)=0;\
00072 FOR_CART(i,j,k,(sh)->am(gc))
00073
00074 #define END_FOR_GCCART(index)\
00075 (index)++;\
00076 END_FOR_CART\
00077 }
00078
00079 #define END_FOR_GCCART_GS(index)\
00080 (index)++;\
00081 END_FOR_CART\
00082 }
00083
00084 /* These are like the above except no index is kept track of. */
00085 #define FOR_GCCART2(gc,i,j,k,sh)\
00086 for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\
00087 FOR_CART(i,j,k,(sh)->type[gc].am)
00088
00089 #define END_FOR_GCCART2\
00090 END_FOR_CART\
00091 }
00092
00093 /* These are used to loop over shells, given the centers structure
00094 * and the center index, and shell index. */
00095 #define FOR_SHELLS(c,i,j) for((i)=0;(i)<(c)->n;i++) {\
00096 for((j)=0;(j)<(c)->center[(i)].basis.n;j++) {
00097 #define END_FOR_SHELLS }}
00098
00099 /* Computes the number of Cartesian function in a shell given
00100 * am = total angular momentum
00101 * formula: (am*(am+1))/2 + am+1;
00102 */
00103 #define INT_NCART(am) ((am>=0)?((((am)+2)*((am)+1))>>1):0)
00104
00105 /* Like INT_NCART, but only for nonnegative arguments. */
00106 #define INT_NCART_NN(am) ((((am)+2)*((am)+1))>>1)
00107
00108 /* For a given ang. mom., am, with n cartesian functions, compute the
00109 * number of cartesian functions for am+1 or am-1
00110 */
00111 #define INT_NCART_DEC(am,n) ((n)-(am)-1)
00112 #define INT_NCART_INC(am,n) ((n)+(am)+2)
00113
00114 /* Computes the number of pure angular momentum functions in a shell
00115 * given am = total angular momentum
00116 */
00117 #define INT_NPURE(am) (2*(am)+1)
00118
00119 /* Computes the number of functions in a shell given
00120 * pu = pure angular momentum boolean
00121 * am = total angular momentum
00122 */
00123 #define INT_NFUNC(pu,am) ((pu)?INT_NPURE(am):INT_NCART(am))
00124
00125 /* Given a centers pointer and a shell number, this evaluates the
00126 * pointer to that shell. */
00127 #define INT_SH(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]])
00128
00129 /* Given a centers pointer and a shell number, get the angular momentum
00130 * of that shell. */
00131 #define INT_SH_AM(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.am)
00132
00133 /* Given a centers pointer and a shell number, get pure angular momentum
00134 * boolean for that shell. */
00135 #define INT_SH_PU(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.puream)
00136
00137 /* Given a centers pointer, a center number, and a shell number,
00138 * get the angular momentum of that shell. */
00139 #define INT_CE_SH_AM(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.am)
00140
00141 /* Given a centers pointer, a center number, and a shell number,
00142 * get pure angular momentum boolean for that shell. */
00143 #define INT_CE_SH_PU(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.puream)
00144
00145 /* Given a centers pointer and a shell number, compute the number
00146 * of functions in that shell. */
00147 /* #define INT_SH_NFUNC(c,s) INT_NFUNC(INT_SH_PU(c,s),INT_SH_AM(c,s)) */
00148 #define INT_SH_NFUNC(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].nfunc)
00149
00150 /* These macros assist in looping over the unique integrals
00151 * in a shell quartet. The exy variables are booleans giving
00152 * information about the equivalence between shells x and y. The nx
00153 * variables give the number of functions in each shell, x. The
00154 * i,j,k are the current values of the looping indices for shells 1, 2, and 3.
00155 * The macros return the maximum index to be included in a summation
00156 * over indices 1, 2, 3, and 4.
00157 * These macros require canonical integrals. This requirement comes
00158 * from the need that integrals of the shells (1 2|2 1) are not
00159 * used. The integrals (1 2|1 2) must be used with these macros to
00160 * get the right nonredundant integrals.
00161 */
00162 #define INT_MAX1(n1) ((n1)-1)
00163 #define INT_MAX2(e12,i,n2) ((e12)?(i):((n2)-1))
00164 #define INT_MAX3(e13e24,i,n3) ((e13e24)?(i):((n3)-1))
00165 #define INT_MAX4(e13e24,e34,i,j,k,n4) \
00166 ((e34)?(((e13e24)&&((k)==(i)))?(j):(k)) \
00167 :((e13e24)&&((k)==(i)))?(j):(n4)-1)
00168 /* A note on integral symmetries:
00169 * There are 15 ways of having equivalent indices.
00170 * There are 8 of these which are important for determining the
00171 * nonredundant integrals (that is there are only 8 ways of counting
00172 * the number of nonredundant integrals in a shell quartet)
00173 * Integral type Integral Counting Type
00174 * 1 (1 2|3 4) 1
00175 * 2 (1 1|3 4) 2
00176 * 3 (1 2|1 4) ->1
00177 * 4 (1 2|3 1) ->1
00178 * 5 (1 1|1 4) 3
00179 * 6 (1 1|3 1) ->2
00180 * 7 (1 2|1 1) ->5
00181 * 8 (1 1|1 1) 4
00182 * 9 (1 2|2 4) ->1
00183 * 10 (1 2|3 2) ->1
00184 * 11 (1 2|3 3) 5
00185 * 12 (1 1|3 3) 6
00186 * 13 (1 2|1 2) 7
00187 * 14 (1 2|2 1) 8 reduces to 7 thru canonicalization
00188 * 15 (1 2|2 2) ->5
00189 */