20 #ifndef _libint2_src_bin_libint_bfset_h_ 21 #define _libint2_src_bin_libint_bfset_h_ 28 #include <libint2/stdarray.h> 29 #include <smart_ptr.h> 30 #include <polyconstr.h> 32 #include <contractable.h> 33 #include <global_macros.h> 34 #include <util_types.h> 45 virtual unsigned int num_bf()
const =0;
46 virtual const std::string label()
const =0;
67 virtual void inc(
unsigned int xyz,
unsigned int c = 1u) =0;
69 virtual void dec(
unsigned int xyz,
unsigned int c = 1u) =0;
71 virtual unsigned int norm()
const =0;
73 bool zero()
const {
return norm() == 0; }
75 bool valid()
const {
return valid_; }
89 F
unit(
unsigned int X) { F tmp; tmp.inc(X,1);
return tmp; }
95 template <
unsigned NDIM = 3>
100 for(
auto d=0u; d!=NDIM; ++d) d_[d] = 0u;
103 std::copy(other.d_, other.d_ + NDIM, d_);
106 valid_ = other.valid_;
107 std::copy(other.d_, other.d_ + NDIM, d_);
112 for(
auto d=0u; d!=NDIM; ++d) d_[d] += other.d_[d];
117 for(
auto d=0u; d!=NDIM; ++d) d_[d] -= other.d_[d];
121 static_assert(NDIM == 3u || NDIM == 1u,
"OriginDerivative with NDIM=1,3 are implemented");
125 unsigned int d(
unsigned int xyz)
const {
134 void inc(
unsigned int xyz,
unsigned int c = 1u) {
140 void dec(
unsigned int xyz,
unsigned int c = 1u) {
150 return std::accumulate(d_, d_+NDIM, 0u);
153 bool zero()
const {
return norm() == 0; }
155 bool valid()
const {
return valid_; }
157 LIBINT2_UINT_LEAST64
key()
const {
159 unsigned nxy = d_[1] + d_[2];
160 unsigned l = nxy + d_[0];
161 LIBINT2_UINT_LEAST64 key = nxy*(nxy+1)/2 + d_[2];
162 return key + key_l_offset.at(l);
172 for(
auto xyz=0u; xyz<NDIM; ++xyz) result[xyz] =
'0' + d_[xyz];
174 return std::string(result);
180 const static unsigned max_deriv = 4;
190 const static unsigned max_key = NDIM == 3 ? (1 + max_deriv)*(2 + max_deriv)*(3 + max_deriv)/6 : (1+max_deriv);
193 void print(std::ostream& os = std::cout)
const;
201 unsigned int d_[NDIM];
209 template <
unsigned NDIM>
212 for(
unsigned int xyz=0; xyz<3; ++xyz)
213 Diff.
dec(xyz,B.
d(xyz));
217 template <
unsigned NDIM>
219 for(
unsigned d=0; d!=NDIM; ++d)
220 if (A.
d(d) != B.
d(d))
250 CGShell(
unsigned int qn,
bool pure_sh =
false);
259 const std::string label()
const;
261 unsigned int num_bf()
const {
return (qn_[0]+1)*(qn_[0]+2)/2; };
263 unsigned int qn(
unsigned int xyz=0)
const {
return qn_[0]; }
266 return this->qn(xyz);
270 bool operator==(
const CGShell&)
const;
279 void inc(
unsigned int xyz,
unsigned int c = 1u);
281 void dec(
unsigned int xyz,
unsigned int c = 1u);
283 unsigned int norm()
const;
285 LIBINT2_UINT_LEAST64
key()
const {
286 if (is_unit())
return max_key-1;
287 const LIBINT2_UINT_LEAST64 result =
288 ((deriv().key() * 2 +
289 (contracted() ? 1 : 0)
294 assert(result < max_key-1);
297 const static LIBINT2_UINT_LEAST64 max_qn = LIBINT_CARTGAUSS_MAX_AM;
308 void print(std::ostream& os = std::cout)
const;
312 bool is_unit()
const {
return unit_; }
328 friend CGF operator+(
const CGF& A,
const CGF& B);
329 friend CGF operator-(
const CGF& A,
const CGF& B);
340 CGF(
unsigned int qn[3],
bool pure_sh =
false);
345 CGF& operator=(
const CGF&);
351 const std::string label()
const;
353 unsigned int num_bf()
const {
return 1; };
355 unsigned int qn(
unsigned int axis)
const;
356 unsigned int operator[](
unsigned int axis)
const {
367 bool operator==(
const CGF&)
const;
370 void inc(
unsigned int xyz,
unsigned int c = 1u);
372 void dec(
unsigned int xyz,
unsigned int c = 1u);
374 unsigned int norm()
const;
376 LIBINT2_UINT_LEAST64
key()
const {
377 if (is_unit())
return max_key-1;
378 unsigned nxy = qn_[1] + qn_[2];
379 unsigned l = nxy + qn_[0];
380 LIBINT2_UINT_LEAST64 key = nxy*(nxy+1)/2 + qn_[2];
381 const LIBINT2_UINT_LEAST64 result =
382 ( ( deriv().key() * 2 +
383 (contracted() ? 1 : 0)
385 key + key_l_offset.at(l)
387 + (pure_sh() ? 1 : 0);
388 if (result >= max_key-1) {
389 this->print(std::cout);
390 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
391 assert(result < max_key-1);
398 const static LIBINT2_UINT_LEAST64 max_num_qn = ((1 + (CGShell::max_qn+1)) * (2 + (CGShell::max_qn+1)) * (3 + (CGShell::max_qn+1)) /6);
407 void print(std::ostream& os = std::cout)
const;
411 bool is_unit()
const {
return unit_; }
418 CGF operator+(
const CGF& A,
const CGF& B);
419 CGF operator-(
const CGF& A,
const CGF& B);
422 template <CartesianAxis Axis>
434 static constexpr CartesianAxis axis = Axis;
441 CGF1d() : unit_(false) { qn_[0] = 0; }
442 CGF1d(
unsigned int qn) : unit_(
false) { qn_[0] = qn; }
443 CGF1d(
unsigned int qn[1]) : unit_(
false) { qn_[0] = qn[0]; }
445 deriv_(source.deriv_), unit_(source.unit_)
447 qn_[0] = source.qn_[0];
452 const CGF1d& sptr_cast =
dynamic_cast<const CGF1d&
>(sptr);
453 qn_[0] = sptr_cast.qn_[0];
454 deriv_ = sptr_cast.deriv_;
455 unit_ = sptr_cast.unit_;
463 qn_[0] = source.qn_[0];
464 deriv_ = source.deriv_;
465 unit_ = source.unit_;
467 if (!source.
valid()) invalidate();
475 Sum.deriv_ += B.deriv_;
482 Diff.deriv_ -= B.deriv_;
492 std::ostringstream oss;
494 if (deriv_.
zero() ==
false) oss <<
"_" << deriv_.
label();
498 assert(this->contracted() ==
false);
505 unsigned int num_bf()
const {
return 1; };
507 unsigned int qn(
unsigned int dir = 0)
const {
511 unsigned int operator[](
unsigned int dir)
const {
512 return this->qn(dir);
517 return ( qn_[0] == a.qn_[0] &&
518 this->contracted() == a.contracted() &&
519 deriv_ == a.deriv_ &&
524 void inc(
unsigned int dir,
unsigned int c = 1u) {
525 assert(is_unit() ==
false);
531 void dec(
unsigned int dir,
unsigned int c = 1u) {
532 if (is_unit()) { invalidate();
return; }
543 unsigned int norm()
const {
return qn_[0]; }
545 LIBINT2_UINT_LEAST64
key()
const {
546 if (is_unit())
return max_key-1;
547 const LIBINT2_UINT_LEAST64 result =
548 ( deriv().key() * 2ul +
549 (this->contracted() ? 1ul : 0ul)
552 if (result >= max_key-1) {
553 this->print(std::cout);
554 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
555 assert(result < max_key-1);
562 const static LIBINT2_UINT_LEAST64 max_num_qn = CGShell::max_qn+1;
570 void print(std::ostream& os = std::cout)
const {
571 os <<
"CGF1d<" <<
to_string(Axis) <<
">: " << label() << std::endl;
581 bool is_unit()
const {
return unit_; }
613 template <CartesianAxis Axis>
623 static constexpr CartesianAxis axis = Axis;
631 CGShell1d(
unsigned int qn) : unit_(
false) { qn_[0] = qn; }
632 CGShell1d(
unsigned int qn[1]) : unit_(
false) { qn_[0] = qn[0]; }
634 deriv_(source.deriv_), unit_(source.unit_)
636 qn_[0] = source.qn_[0];
644 qn_[0] = source.qn_[0];
645 deriv_ = source.deriv_;
646 unit_ = source.unit_;
648 if (!source.
valid()) invalidate();
658 std::ostringstream oss;
660 axis_label[0] = std::toupper(axis_label[0]);
661 oss << axis_label << qn_[0];
662 if (deriv_.
zero() ==
false) oss <<
"_" << deriv_.
label();
666 assert(this->contracted() ==
false);
673 unsigned int num_bf()
const {
return qn_[0]+1; };
675 unsigned int qn(
unsigned int dir=0)
const {
682 return ( qn_[0] == a.qn_[0] &&
683 this->contracted() == a.contracted() &&
684 deriv_ == a.deriv_ &&
689 void inc(
unsigned int dir,
unsigned int c = 1u) {
693 void dec(
unsigned int dir,
unsigned int c = 1u) {
697 unsigned int norm()
const {
return qn_[0]; }
699 LIBINT2_UINT_LEAST64
key()
const {
700 if (is_unit())
return max_key-1;
701 const LIBINT2_UINT_LEAST64 result =
702 ( deriv().key() * 2ul +
703 (this->contracted() ? 1ul : 0ul)
706 if (result >= max_key-1) {
707 this->print(std::cout);
708 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
709 assert(result < max_key-1);
716 const static LIBINT2_UINT_LEAST64 max_num_qn = CGShell::max_qn+1;
724 void print(std::ostream& os = std::cout)
const {
725 os <<
"CGShell1d<" <<
to_string(Axis) <<
">: " << label() << std::endl;
735 bool is_unit()
const {
return unit_; }
773 const std::string label()
const;
775 unsigned int num_bf()
const {
return 2*qn_[0]+1; };
777 unsigned int qn(
unsigned int m=0)
const {
return qn_[0]; }
780 bool operator==(
const SHGShell&)
const;
783 void inc(
unsigned int xyz,
unsigned int c = 1u);
785 void dec(
unsigned int xyz,
unsigned int c = 1u);
787 unsigned int norm()
const;
789 unsigned key()
const {
return (deriv().
key() * 2 + (contracted() ? 1 : 0)) * (max_qn+1) + qn_[0]; }
790 const static unsigned max_qn = LIBINT_CARTGAUSS_MAX_AM;
797 void print(std::ostream& os = std::cout)
const;
823 SHGF(
unsigned int qn[3]);
834 const std::string label()
const;
836 unsigned int num_bf()
const {
return 1; };
838 unsigned int qn(
unsigned int xyz)
const;
841 bool operator==(
const SHGF&)
const;
844 void inc(
unsigned int xyz,
unsigned int c = 1u);
846 void dec(
unsigned int xyz,
unsigned int c = 1u);
848 unsigned int norm()
const;
851 unsigned nxy = qn_[1] + qn_[2];
852 unsigned l = nxy + qn_[0];
853 unsigned key = nxy*(nxy+1)/2 + qn_[2];
854 return ( deriv().key() * 2 + (contracted() ? 1 : 0)) * max_num_qn + key + key_l_offset.at(l);
859 const static unsigned max_num_qn = ((1 + (SHGShell::max_qn+1)) * (2 + (SHGShell::max_qn+1)) * (3 + (SHGShell::max_qn+1)) /6);
863 void print(std::ostream& os = std::cout)
const;
867 static unsigned key_l_offset[SHGShell::max_key+2];
882 static const bool result =
false;
886 static const bool result =
true;
888 template <CartesianAxis Axis>
890 static const bool result =
false;
892 template <CartesianAxis Axis>
894 static const bool result =
true;
899 static const bool result =
false;
903 static const bool result =
true;
bool zero() const
norm() == 0
Definition: bfset.h:73
unsigned int operator[](unsigned int xyz) const
returns the number of quanta along xyz
Definition: bfset.h:130
use this as a base to add to Derived a "contracted()" attribute
Definition: contractable.h:26
Cartesian components of 3D CGF = 1D CGF.
Definition: bfset.h:425
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:879
Set of basis functions with incrementable/decrementable quantum numbers.
Definition: bfset.h:61
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:673
ConstructablePolymorphically is a base for all objects which can be constructed using a SafePtr to a ...
Definition: polyconstr.h:30
3D Cartesian Gaussian Shell
Definition: bfset.h:231
static CGF1d unit()
returns the unit shell (exponent=0, am=0, indicated by unit_=true)
Definition: bfset.h:575
void dec(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: bfset.h:531
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
Objects of Hashable<T> class provide hashing function key() which computes keys of type KeyType...
Definition: hashable.h:72
a "shell" of 1D CGFs with quantum number L is a set of 1D CGFs with quantum numbers 0 ...
Definition: bfset.h:614
static const unsigned max_key
The range of keys is [0,max_key).
Definition: bfset.h:190
unsigned int qn(unsigned int dir=0) const
Returns the quantum number (what used to be "angular momentum")
Definition: bfset.h:507
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:157
CGF1d & operator=(const CGF1d &source)
assignment
Definition: bfset.h:461
unsigned int norm() const
Returns the norm of the quantum numbers.
Definition: bfset.h:149
unsigned int qn(unsigned int dir=0) const
Returns the quantum number (what used to be "angular momentum")
Definition: bfset.h:675
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:545
void dec(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: bfset.h:693
unsigned int num_bf() const
Returns the number of basis functions in the set.
Definition: bfset.h:261
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:376
CGF iter_type
As far as SetIterator is concerned, CGShell is a set of CGFs.
Definition: bfset.h:245
SHGF iter_type
As far as SetIterator is concerned, SHGShell is a set of SHGFs.
Definition: bfset.h:759
bool pure_sh() const
contains only solid harmonics with the same quantum number as this shell? (this may permit simplified...
Definition: bfset.h:362
CGF1d iter_type
As far as SetIterator is concerned, CGF1d is a set of one CGF1d.
Definition: bfset.h:437
Solid-Harmonic Gaussian Shell.
Definition: bfset.h:748
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: bfset.h:543
CGF1d()
Default constructor makes an qn=0 Gaussian.
Definition: bfset.h:441
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:836
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:353
bool operator==(const CGShell1d &a) const
Comparison operator.
Definition: bfset.h:681
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:71
unsigned int qn(unsigned int m=0) const
Returns the angular momentum.
Definition: bfset.h:777
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:505
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:285
void inc(unsigned int xyz, unsigned int c=1u)
Add c quanta along xyz.
Definition: bfset.h:134
bool valid() const
Return false if this object is invalid.
Definition: bfset.h:75
CGF1d< Axis > iter_type
CGShell1d is a set CGF1d's.
Definition: bfset.h:626
unsigned int num_bf() const
Returns the number of basis functions in the set.
Definition: bfset.h:775
bool operator==(const CGF1d &a) const
Comparison operator.
Definition: bfset.h:516
F unit(unsigned int X)
BF with unit quantum along X. F must behave like IncableBFSet.
Definition: bfset.h:89
const std::string label() const
Return a compact label.
Definition: bfset.h:490
void inc(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: bfset.h:524
unsigned int d(unsigned int xyz) const
returns the number of quanta along xyz
Definition: bfset.h:125
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: bfset.h:697
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:91
const std::string label() const
Return a compact label.
Definition: bfset.h:170
Array idential to C++0X arrays.
Definition: stdarray_bits.h:14
SHGF iter_type
As far as SetIterator is concerned, SHGF is a set of one SHGF.
Definition: bfset.h:816
void inc(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: bfset.h:689
unsigned int operator[](unsigned int xyz) const
returns the angular momentum
Definition: bfset.h:265
Set of basis functions.
Definition: bfset.h:41
unsigned key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:789
unsigned key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:850
CGShell1d()
Default constructor makes a qn=0 shell.
Definition: bfset.h:630
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: bfset.h:570
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: bfset.h:140
Solid-Harmonic Gaussian Function.
Definition: bfset.h:805
void invalidate()
make this object invalid
Definition: bfset.h:81
bool zero() const
norm() == 0
Definition: bfset.h:153
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: bfset.h:724
void pure_sh(bool p)
Definition: bfset.h:276
const std::string label() const
Return a compact label.
Definition: bfset.h:656
CGShell1d & operator=(const CGShell1d &source)
assignment
Definition: bfset.h:642
static CGShell1d unit()
returns the unit shell (exponent=0, am=0, indicated by unit_=true)
Definition: bfset.h:729
3D Cartesian Gaussian Function
Definition: bfset.h:320
Represents cartesian derivatives of atom-centered basis functions.
Definition: bfset.h:96
bool valid() const
Return false if this object is invalid.
Definition: bfset.h:155
CGF iter_type
As far as SetIterator is concerned, CGF is a set of one CGF.
Definition: bfset.h:333
void pure_sh(bool p)
Definition: bfset.h:364
unsigned int qn(unsigned int xyz=0) const
Returns the angular momentum.
Definition: bfset.h:263
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:699
bool pure_sh() const
contains only solid harmonics with the same quantum number as this shell? (this may permit simplified...
Definition: bfset.h:274
void invalidate()
make this object invalid
Definition: bfset.h:198