21 #ifndef _libint2_src_bin_libint_multipole_h_ 22 #define _libint2_src_bin_libint_multipole_h_ 30 #include <smart_ptr.h> 31 #include <polyconstr.h> 33 #include <global_macros.h> 34 #include <util_types.h> 40 template <
unsigned NDIM = 3>
43 static_assert(NDIM == 1 || NDIM == 3,
"CartesianMultipoleQuanta<NDIM>: only NDIM=1 or NDIM=3 are supported");
46 for(
auto d=0u; d!=NDIM; ++d) n_[d] = 0u;
49 std::copy(other.n_, other.n_ + NDIM, n_);
52 valid_ = other.valid_;
53 std::copy(other.n_, other.n_ + NDIM, n_);
58 for(
auto d=0u; d!=NDIM; ++d) n_[d] += other.n_[d];
63 for(
auto d=0u; d!=NDIM; ++d) n_[d] -= other.n_[d];
74 void inc(
unsigned int xyz,
unsigned int c = 1u) {
80 void dec(
unsigned int xyz,
unsigned int c = 1u) {
89 unsigned int norm()
const {
90 return std::accumulate(n_, n_+NDIM, 0u);
95 bool valid()
const {
return valid_; }
97 LIBINT2_UINT_LEAST64
key()
const {
99 unsigned nxy = n_[1] + n_[2];
100 unsigned l = nxy + n_[0];
101 LIBINT2_UINT_LEAST64
key = nxy*(nxy+1)/2 + n_[2];
102 const auto result =
key + key_l_offset.at(l);
107 const auto result = n_[0];
116 for(
auto xyz=0u; xyz<NDIM; ++xyz) result[xyz] =
'0' + n_[xyz];
118 return std::string(result);
124 const constexpr
static unsigned max_qn = LIBINT_CARTGAUSS_MAX_AM;
132 const static unsigned max_key = NDIM == 3 ? (1 + max_qn)*(2 + max_qn)*(3 + max_qn)/6 : (1+max_qn);
135 void print(std::ostream& os = std::cout)
const;
143 unsigned int n_[NDIM];
157 template <
unsigned NDIM>
158 CartesianMultipoleQuanta<NDIM> operator-(
const CartesianMultipoleQuanta<NDIM>& A,
const CartesianMultipoleQuanta<NDIM>& B) {
159 CartesianMultipoleQuanta<NDIM> Diff(A);
160 for(
unsigned int xyz=0; xyz<3; ++xyz)
161 Diff.dec(xyz,B[xyz]);
165 template <
unsigned NDIM>
166 bool operator==(
const CartesianMultipoleQuanta<NDIM>& A,
const CartesianMultipoleQuanta<NDIM>& B) {
167 for(
unsigned d=0; d!=NDIM; ++d)
187 enum Sign {plus, minus};
188 const constexpr
static unsigned max_qn = LIBINT_CARTGAUSS_MAX_AM;
201 phase_(sign == Sign::plus && m < 0 ? -1 : 1) {
202 if (l < 0) valid_ =
false;
203 if (m_ > l_) valid_ =
false;
205 if (sign_ == Sign::minus && m_ == 0) valid_ =
false;
208 int l()
const { assert(valid_);
return static_cast<int>(l_); }
209 int m()
const { assert(valid_);
return static_cast<int>(m_); }
210 Sign sign()
const { assert(valid_);
return sign_; }
211 bool valid()
const {
return valid_; }
212 int phase()
const { assert(valid_);
return phase_; }
214 bool is_precomputed()
const { assert(valid_);
return sign_ == Sign::plus && l_ == 0 && m_ == 0; }
217 const static unsigned max_key = (1 + max_qn) * (1 + max_qn);
220 LIBINT2_UINT_LEAST64
key()
const {
222 const auto result = l_*l_ + (sign_ == Sign::plus ? (l_ + m_) : (l_ - m_));
223 assert(result < max_key);
240 inline SphericalMultipoleQuanta::Sign
flip(
const SphericalMultipoleQuanta::Sign& s) {
241 return s == SphericalMultipoleQuanta::Sign::minus ? SphericalMultipoleQuanta::Sign::plus : SphericalMultipoleQuanta::Sign::minus;
void print(std::ostream &os=std::cout) const
Print out the content.
Represents quantum numbers of cartesian multipole operator.
Definition: multipole.h:41
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
Objects of Hashable<T> class provide hashing function key() which computes keys of type KeyType.
Definition: hashable.h:73
SphericalMultipoleQuanta(int l, int m)
constructs if , otherwise constructs
Definition: multipole.h:193
Represents quantum numbers of real spherical multipole operator defined in Eqs.
Definition: multipole.h:185
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<unsigned>::key()
Definition: multipole.h:220
SphericalMultipoleQuanta(int l, int m, Sign sign)
constructs
Definition: multipole.h:196
bool zero() const
norm() == 0
Definition: multipole.h:93
static const unsigned max_key
The range of keys is [0,max_key).
Definition: multipole.h:132
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<unsigned>::key()
Definition: multipole.h:97
void inc(unsigned int xyz, unsigned int c=1u)
Add c quanta along xyz.
Definition: multipole.h:74
bool valid() const
Return false if this object is invalid.
Definition: multipole.h:95
unsigned int operator[](unsigned int xyz) const
returns the number of quanta along xyz
Definition: multipole.h:69
void invalidate()
make this object invalid
Definition: multipole.h:140
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:92
unsigned int norm() const
Returns the sum of quantum numbers.
Definition: multipole.h:89
bool is_precomputed() const
Definition: multipole.h:214
SphericalMultipoleQuanta::Sign flip(const SphericalMultipoleQuanta::Sign &s)
plus <-> minus
Definition: multipole.h:240
SphericalMultipoleQuanta()
constructs an object in default (unusable) state
Definition: multipole.h:191
std::string label() const
Return a compact label.
Definition: multipole.h:114
void dec(unsigned int xyz, unsigned int c=1u)
Subtract c quanta along xyz. If impossible, invalidate the object, but do not change its quanta!
Definition: multipole.h:80