# macros.h

    00001 /*
    00002  * macros.h
    00003  *
    00004  * Copyright (C) 1996 Limit Point Systems, Inc.
    00005  *
    00006  * Author: Curtis Janssen <cljanss@ca.sandia.gov>
    00007  * Maintainer: LPS
    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-10)||((x)> 1.0e-10))
    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) - (i*(i+1))/2 + i+1 - j - 1
    00036  * The following loop will generate indices in the proper order:
    00037  *  cartindex = 0;
    00038  *  for (i=0; i<=am; i++) {
    00039  *    for (k=0; k<=am-i; k++) {
    00040  *      j = am - i - k;
    00041  *      do_it_with(cartindex); // cartindex == INT_CARTINDEX(am,i,j)
    00042  *      cartindex++;
    00043  *      }
    00044  *    }
    00045  */
    00046 #define INT_CARTINDEX(am,i,j) (((((((am)+1)<<1)-(i))*((i)+1))>>1)-(j)-1)
    00047
    00048 /* This sets up the above loop over cartesian exponents as follows
    00049  * FOR_CART(i,j,k,am)
    00050  *   Stuff using i,j,k.
    00051  *   END_FOR_CART
    00052  */
    00053 #define FOR_CART(i,j,k,am) for((i)=0;(i)<=(am);(i)++) {\
    00054                            for((k)=0;(k)<=(am)-(i);(k)++) \
    00055                            { (j) = (am) - (i) - (k);
    00056 #define END_FOR_CART }}
    00057
    00058 /* This sets up a loop over all of the generalized contractions
    00059  * and all of the cartesian exponents.
    00060  * gc is the number of the gen con
    00061  * index is the index within the current gen con.
    00062  * i,j,k are the angular momentum for x,y,z
    00063  * sh is the shell pointer
    00064  */
    00065 #define FOR_GCCART(gc,index,i,j,k,sh)\
    00066     for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\
    00067     (index)=0;\
    00068     FOR_CART(i,j,k,(sh)->type[gc].am)
    00069
    00070 #define FOR_GCCART_GS(gc,index,i,j,k,sh)\
    00071     for ((gc)=0; (gc)<(sh)->ncontraction(); (gc)++) {\
    00072     (index)=0;\
    00073     FOR_CART(i,j,k,(sh)->am(gc))
    00074
    00075 #define END_FOR_GCCART(index)\
    00076     (index)++;\
    00077     END_FOR_CART\
    00078     }
    00079
    00080 #define END_FOR_GCCART_GS(index)\
    00081     (index)++;\
    00082     END_FOR_CART\
    00083     }
    00084
    00085 /* These are like the above except no index is kept track of. */
    00086 #define FOR_GCCART2(gc,i,j,k,sh)\
    00087     for ((gc)=0; (gc)<(sh)->ncon; (gc)++) {\
    00088     FOR_CART(i,j,k,(sh)->type[gc].am)
    00089
    00090 #define END_FOR_GCCART2\
    00091     END_FOR_CART\
    00092     }
    00093
    00094 /* These are used to loop over shells, given the centers structure
    00095  * and the center index, and shell index. */
    00096 #define FOR_SHELLS(c,i,j) for((i)=0;(i)<(c)->n;i++) {\
    00097                           for((j)=0;(j)<(c)->center[(i)].basis.n;j++) {
    00098 #define END_FOR_SHELLS }}
    00099
    00100 /* Computes the number of Cartesian function in a shell given
    00101  * am = total angular momentum
    00102  * formula: (am*(am+1))/2 + am+1;
    00103  */
    00104 #define INT_NCART(am) ((am>=0)?((((am)+2)*((am)+1))>>1):0)
    00105
    00106 /* Like INT_NCART, but only for nonnegative arguments. */
    00107 #define INT_NCART_NN(am) ((((am)+2)*((am)+1))>>1)
    00108
    00109 /* For a given ang. mom., am, with n cartesian functions, compute the
    00110  * number of cartesian functions for am+1 or am-1
    00111  */
    00112 #define INT_NCART_DEC(am,n) ((n)-(am)-1)
    00113 #define INT_NCART_INC(am,n) ((n)+(am)+2)
    00114
    00115 /* Computes the number of pure angular momentum functions in a shell
    00116  * given am = total angular momentum
    00117  */
    00118 #define INT_NPURE(am) (2*(am)+1)
    00119
    00120 /* Computes the number of functions in a shell given
    00121  * pu = pure angular momentum boolean
    00122  * am = total angular momentum
    00123  */
    00124 #define INT_NFUNC(pu,am) ((pu)?INT_NPURE(am):INT_NCART(am))
    00125
    00126 /* Given a centers pointer and a shell number, this evaluates the
    00127  * pointer to that shell. */
    00128 #define INT_SH(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]])
    00129
    00130 /* Given a centers pointer and a shell number, get the angular momentum
    00131  * of that shell. */
    00132 #define INT_SH_AM(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.am)
    00133
    00134 /* Given a centers pointer and a shell number, get pure angular momentum
    00135  * boolean for that shell. */
    00136 #define INT_SH_PU(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].type.puream)
    00137
    00138 /* Given a centers pointer, a center number, and a shell number,
    00139  * get the angular momentum of that shell. */
    00140 #define INT_CE_SH_AM(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.am)
    00141
    00142 /* Given a centers pointer, a center number, and a shell number,
    00143  * get pure angular momentum boolean for that shell. */
    00144 #define INT_CE_SH_PU(c,a,s) ((c)->center[(a)].basis.shell[(s)].type.puream)
    00145
    00146 /* Given a centers pointer and a shell number, compute the number
    00147  * of functions in that shell. */
    00148 /* #define INT_SH_NFUNC(c,s) INT_NFUNC(INT_SH_PU(c,s),INT_SH_AM(c,s)) */
    00149 #define INT_SH_NFUNC(c,s) ((c)->center[(c)->center_num[s]].basis.shell[(c)->shell_num[s]].nfunc)
    00150
    00151 /* These macros assist in looping over the unique integrals
    00152  * in a shell quartet.  The exy variables are booleans giving
    00153  * information about the equivalence between shells x and y.  The nx
    00154  * variables give the number of functions in each shell, x. The
    00155  * i,j,k are the current values of the looping indices for shells 1, 2, and 3.
    00156  * The macros return the maximum index to be included in a summation
    00157  * over indices 1, 2, 3, and 4.
    00158  * These macros require canonical integrals.  This requirement comes
    00159  * from the need that integrals of the shells (1 2|2 1) are not
    00160  * used.  The integrals (1 2|1 2) must be used with these macros to
    00161  * get the right nonredundant integrals.
    00162  */
    00163 #define INT_MAX1(n1) ((n1)-1)
    00164 #define INT_MAX2(e12,i,n2) ((e12)?(i):((n2)-1))
    00165 #define INT_MAX3(e13e24,i,n3) ((e13e24)?(i):((n3)-1))
    00166 #define INT_MAX4(e13e24,e34,i,j,k,n4) \
    00167   ((e34)?(((e13e24)&&((k)==(i)))?(j):(k)) \
    00168         :((e13e24)&&((k)==(i)))?(j):(n4)-1)
    00169 /* A note on integral symmetries:
    00170  *  There are 15 ways of having equivalent indices.
    00171  *  There are 8 of these which are important for determining the
    00172  *  nonredundant integrals (that is there are only 8 ways of counting
    00173  *  the number of nonredundant integrals in a shell quartet)
    00174  * Integral type   Integral    Counting Type
    00175  *     1           (1 2|3 4)      1
    00176  *     2           (1 1|3 4)      2
    00177  *     3           (1 2|1 4)       ->1
    00178  *     4           (1 2|3 1)       ->1
    00179  *     5           (1 1|1 4)      3
    00180  *     6           (1 1|3 1)       ->2
    00181  *     7           (1 2|1 1)       ->5
    00182  *     8           (1 1|1 1)      4
    00183  *     9           (1 2|2 4)       ->1
    00184  *    10           (1 2|3 2)       ->1
    00185  *    11           (1 2|3 3)      5
    00186  *    12           (1 1|3 3)      6
    00187  *    13           (1 2|1 2)      7
    00188  *    14           (1 2|2 1)      8    reduces to 7 thru canonicalization
    00189  *    15           (1 2|2 2)       ->5
    00190  */