21 #ifndef _libint2_src_bin_libint_bfset_h_ 22 #define _libint2_src_bin_libint_bfset_h_ 30 #include <smart_ptr.h> 31 #include <polyconstr.h> 33 #include <contractable.h> 34 #include <global_macros.h> 35 #include <util_types.h> 46 virtual unsigned int num_bf()
const =0;
47 virtual std::string label()
const =0;
68 virtual void inc(
unsigned int xyz,
unsigned int c = 1u) =0;
70 virtual void dec(
unsigned int xyz,
unsigned int c = 1u) =0;
72 virtual unsigned int norm()
const =0;
76 bool valid()
const {
return valid_; }
90 F
unit(
unsigned int X) { F tmp; tmp.inc(X,1);
return tmp; }
96 template <
unsigned NDIM = 3>
99 static_assert(NDIM == 1 || NDIM == 3,
"OriginDerivative<NDIM>: only NDIM=1 or NDIM=3 are supported");
102 for(
auto d=0u;
d!=NDIM; ++
d) d_[
d] = 0u;
105 std::copy(other.d_, other.d_ + NDIM, d_);
108 valid_ = other.valid_;
109 std::copy(other.d_, other.d_ + NDIM, d_);
114 for(
auto d=0u;
d!=NDIM; ++
d) d_[
d] += other.d_[
d];
119 for(
auto d=0u;
d!=NDIM; ++
d) d_[
d] -= other.d_[
d];
123 static_assert(NDIM == 3u || NDIM == 1u,
"OriginDerivative with NDIM=1,3 are implemented");
127 unsigned int d(
unsigned int xyz)
const {
136 void inc(
unsigned int xyz,
unsigned int c = 1u) {
142 void dec(
unsigned int xyz,
unsigned int c = 1u) {
152 return std::accumulate(d_, d_+NDIM, 0u);
157 bool valid()
const {
return valid_; }
159 LIBINT2_UINT_LEAST64
key()
const {
161 unsigned nxy = d_[1] + d_[2];
162 unsigned l = nxy + d_[0];
163 LIBINT2_UINT_LEAST64
key = nxy*(nxy+1)/2 + d_[2];
164 const auto result =
key + key_l_offset.at(l);
169 const auto result = d_[0];
178 for(
auto xyz=0u; xyz<NDIM; ++xyz) result[xyz] =
'0' + d_[xyz];
180 return std::string(result);
186 const static unsigned max_deriv = 4;
196 const static unsigned max_key = NDIM == 3 ? (1 + max_deriv)*(2 + max_deriv)*(3 + max_deriv)/6 : (1+max_deriv);
199 void print(std::ostream& os = std::cout)
const;
207 unsigned int d_[NDIM];
221 template <
unsigned NDIM>
222 OriginDerivative<NDIM> operator-(
const OriginDerivative<NDIM>& A,
const OriginDerivative<NDIM>& B) {
223 OriginDerivative<NDIM> Diff(A);
224 for(
unsigned int xyz=0; xyz<3; ++xyz)
225 Diff.dec(xyz,B.d(xyz));
229 template <
unsigned NDIM>
230 bool operator==(
const OriginDerivative<NDIM>& A,
const OriginDerivative<NDIM>& B) {
231 for(
unsigned d=0; d!=NDIM; ++d)
232 if (A.d(d) != B.d(d))
271 std::string
label()
const;
273 unsigned int num_bf()
const {
return (qn_[0]+1)*(qn_[0]+2)/2; };
275 unsigned int qn(
unsigned int xyz=0)
const {
return qn_[0]; }
278 return this->
qn(xyz);
291 void inc(
unsigned int xyz,
unsigned int c = 1u);
293 void dec(
unsigned int xyz,
unsigned int c = 1u);
295 unsigned int norm()
const;
297 LIBINT2_UINT_LEAST64
key()
const {
298 if (is_unit())
return max_key-1;
299 const LIBINT2_UINT_LEAST64 result =
300 ((deriv().
key() * 2 +
301 (contracted() ? 1 : 0)
309 const static LIBINT2_UINT_LEAST64 max_qn = LIBINT_CARTGAUSS_MAX_AM;
320 void print(std::ostream& os = std::cout)
const;
324 bool is_unit()
const {
return unit_; }
328 CGShell operator+(
const CGShell& A,
const CGShell& B);
329 CGShell operator-(
const CGShell& A,
const CGShell& B);
340 friend CGF operator+(
const CGF& A,
const CGF& B);
341 friend CGF operator-(
const CGF& A,
const CGF& B);
363 std::string
label()
const;
365 unsigned int num_bf()
const {
return 1; };
367 unsigned int qn(
unsigned int axis)
const;
368 unsigned int operator[](
unsigned int axis)
const {
382 void inc(
unsigned int xyz,
unsigned int c = 1u);
384 void dec(
unsigned int xyz,
unsigned int c = 1u);
386 unsigned int norm()
const;
388 LIBINT2_UINT_LEAST64
key()
const {
389 if (is_unit())
return max_key-1;
390 unsigned nxy = qn_[1] + qn_[2];
391 unsigned l = nxy + qn_[0];
392 LIBINT2_UINT_LEAST64
key = nxy*(nxy+1)/2 + qn_[2];
393 const LIBINT2_UINT_LEAST64 result =
394 ( ( deriv().
key() * 2 +
395 (contracted() ? 1 : 0)
397 key + key_l_offset.at(l)
400 if (result >= max_key-1) {
401 this->
print(std::cout);
402 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
403 assert(result < max_key-1);
410 const static LIBINT2_UINT_LEAST64
max_num_qn = ((1 + (CGShell::max_qn+1)) * (2 + (CGShell::max_qn+1)) * (3 + (CGShell::max_qn+1)) /6);
419 void print(std::ostream& os = std::cout)
const;
423 bool is_unit()
const {
return unit_; }
430 CGF operator+(
const CGF& A,
const CGF& B);
431 CGF operator-(
const CGF& A,
const CGF& B);
434 template <CartesianAxis Axis>
439 public Hashable<LIBINT2_UINT_LEAST64, ComputeKey>,
447 static constexpr
auto axis = Axis;
454 CGF1d() : unit_(false) { qn_[0] = 0; }
455 CGF1d(
unsigned int qn) : unit_(false) { qn_[0] =
qn; }
456 CGF1d(
unsigned int qn[1]) : unit_(false) { qn_[0] =
qn[0]; }
458 deriv_(source.deriv_), unit_(source.unit_)
460 qn_[0] = source.qn_[0];
462 explicit CGF1d(
const ConstructablePolymorphically& sptr) :
463 Contractable<
CGF1d>(dynamic_cast<const
CGF1d&>(sptr))
465 const CGF1d& sptr_cast = dynamic_cast<const CGF1d&>(sptr);
466 qn_[0] = sptr_cast.qn_[0];
467 deriv_ = sptr_cast.deriv_;
468 unit_ = sptr_cast.unit_;
476 qn_[0] = source.qn_[0];
477 deriv_ = source.deriv_;
478 unit_ = source.unit_;
488 Sum.deriv_ += B.deriv_;
495 Diff.deriv_ -= B.deriv_;
499 const OriginDerivative<1u>& deriv()
const {
return deriv_; }
500 OriginDerivative<1u>& deriv() {
return deriv_; }
505 std::ostringstream oss;
507 if (deriv_.
zero() ==
false) oss <<
"_" << deriv_.
label();
511 assert(this->contracted() ==
false);
518 unsigned int num_bf()
const {
return 1; };
520 unsigned int qn(
unsigned int dir = 0)
const {
524 unsigned int operator[](
unsigned int dir)
const {
525 return this->
qn(dir);
530 return ( qn_[0] == a.qn_[0] &&
531 this->contracted() == a.contracted() &&
532 deriv_ == a.deriv_ &&
537 void inc(
unsigned int dir,
unsigned int c = 1u) {
538 assert(is_unit() ==
false);
544 void dec(
unsigned int dir,
unsigned int c = 1u) {
556 unsigned int norm()
const {
return qn_[0]; }
558 LIBINT2_UINT_LEAST64
key()
const {
559 if (is_unit())
return max_key-1;
560 const LIBINT2_UINT_LEAST64 result =
561 ( deriv().
key() * 2ul +
562 (this->contracted() ? 1ul : 0ul)
565 if (result >= max_key-1) {
566 this->
print(std::cout);
567 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
568 assert(result < max_key-1);
575 const static LIBINT2_UINT_LEAST64
max_num_qn = CGShell::max_qn+1;
583 void print(std::ostream& os = std::cout)
const {
584 os <<
"CGF1d<" <<
to_string(Axis) <<
">: " <<
label() << std::endl;
594 bool is_unit()
const {
return unit_; }
626 template <CartesianAxis Axis>
636 static constexpr
auto axis = Axis;
645 CGShell1d(
unsigned int qn[1]) : unit_(false) { qn_[0] =
qn[0]; }
647 deriv_(source.deriv_), unit_(source.unit_)
649 qn_[0] = source.qn_[0];
657 qn_[0] = source.qn_[0];
658 deriv_ = source.deriv_;
659 unit_ = source.unit_;
666 OriginDerivative<1u>& deriv() {
return deriv_; }
671 std::ostringstream oss;
673 axis_label[0] = std::toupper(axis_label[0]);
674 oss << axis_label << qn_[0];
675 if (deriv_.
zero() ==
false) oss <<
"_" << deriv_.
label();
679 assert(this->contracted() ==
false);
686 unsigned int num_bf()
const {
return qn_[0]+1; };
688 unsigned int qn(
unsigned int dir=0)
const {
695 return ( qn_[0] == a.qn_[0] &&
696 this->contracted() == a.contracted() &&
697 deriv_ == a.deriv_ &&
702 void inc(
unsigned int dir,
unsigned int c = 1u) {
706 void dec(
unsigned int dir,
unsigned int c = 1u) {
710 unsigned int norm()
const {
return qn_[0]; }
712 LIBINT2_UINT_LEAST64
key()
const {
713 if (is_unit())
return max_key-1;
714 const LIBINT2_UINT_LEAST64 result =
715 ( deriv().
key() * 2ul +
716 (this->contracted() ? 1ul : 0ul)
719 if (result >= max_key-1) {
720 this->
print(std::cout);
721 std::cout <<
"result,max_key-1 = " << result <<
"," << max_key-1 << std::endl;
722 assert(result < max_key-1);
729 const static LIBINT2_UINT_LEAST64
max_num_qn = CGShell::max_qn+1;
737 void print(std::ostream& os = std::cout)
const {
738 os <<
"CGShell1d<" <<
to_string(Axis) <<
">: " <<
label() << std::endl;
748 bool is_unit()
const {
return unit_; }
786 std::string
label()
const;
788 unsigned int num_bf()
const {
return 2*qn_[0]+1; };
790 unsigned int qn(
unsigned int m=0)
const {
return qn_[0]; }
796 void inc(
unsigned int xyz,
unsigned int c = 1u);
798 void dec(
unsigned int xyz,
unsigned int c = 1u);
800 unsigned int norm()
const;
802 unsigned key()
const {
return (deriv().
key() * 2 + (contracted() ? 1 : 0)) * (max_qn+1) + qn_[0]; }
803 const static unsigned max_qn = LIBINT_CARTGAUSS_MAX_AM;
810 void print(std::ostream& os = std::cout)
const;
814 SHGShell operator+(
const SHGShell& A,
const SHGShell& B);
815 SHGShell operator-(
const SHGShell& A,
const SHGShell& B);
847 std::string
label()
const;
849 unsigned int num_bf()
const {
return 1; };
851 unsigned int qn(
unsigned int xyz)
const;
857 void inc(
unsigned int xyz,
unsigned int c = 1u);
859 void dec(
unsigned int xyz,
unsigned int c = 1u);
861 unsigned int norm()
const;
864 unsigned nxy = qn_[1] + qn_[2];
865 unsigned l = nxy + qn_[0];
866 unsigned key = nxy*(nxy+1)/2 + qn_[2];
867 return ( deriv().
key() * 2 + (contracted() ? 1 : 0)) *
max_num_qn +
key + key_l_offset.at(l);
872 const static unsigned max_num_qn = ((1 + (SHGShell::max_qn+1)) * (2 + (SHGShell::max_qn+1)) * (3 + (SHGShell::max_qn+1)) /6);
876 void print(std::ostream& os = std::cout)
const;
880 static unsigned key_l_offset[SHGShell::max_key+2];
895 static const bool result =
false;
899 static const bool result =
true;
901 template <CartesianAxis Axis>
903 static const bool result =
false;
905 template <CartesianAxis Axis>
907 static const bool result =
true;
912 static const bool result =
false;
916 static const bool result =
true;
bool operator==(const CGShell1d &a) const
Comparison operator.
Definition: bfset.h:694
std::string label() const
Return a compact label.
Definition: bfset.h:176
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: bfset.h:583
std::string label() const
Return a compact label.
Definition: bfset.h:503
use this as a base to add to Derived a "contracted()" attribute
Definition: contractable.h:27
Cartesian components of 3D CGF = 1D CGF.
Definition: bfset.h:438
void dec(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: gauss.cc:295
unsigned key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:863
TrivialBFSet<T> defines static member result, which is true if T is a basis function set consisting o...
Definition: bfset.h:892
Set of basis functions with incrementable/decrementable quantum numbers.
Definition: bfset.h:62
unsigned int qn(unsigned int dir=0) const
Returns the quantum number (what used to be "angular momentum")
Definition: bfset.h:520
ConstructablePolymorphically is a base for all objects which can be constructed using a SafePtr to a ...
Definition: polyconstr.h:31
3D Cartesian Gaussian Shell
Definition: bfset.h:243
static CGF1d unit()
returns the unit shell (exponent=0, am=0, indicated by unit_=true)
Definition: bfset.h:588
void dec(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: bfset.h:544
std::string label() const
Return a compact label.
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
a "shell" of 1D CGFs with quantum number L is a set of 1D CGFs with quantum numbers 0 .
Definition: bfset.h:627
static const unsigned max_key
The range of keys is [0,max_key).
Definition: bfset.h:196
unsigned int operator[](unsigned int xyz) const
returns the number of quanta along xyz
Definition: bfset.h:132
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:849
virtual void inc(unsigned int xyz, unsigned int c=1u)=0
Add c quanta along xyz.
CGF1d & operator=(const CGF1d &source)
assignment
Definition: bfset.h:474
CGShell()
Default constructor creates an s-type shell.
Definition: gauss.cc:238
unsigned int norm() const
Returns the norm of the quantum numbers.
Definition: bfset.h:151
unsigned int num_bf() const
Returns the number of basis functions in the set.
Definition: bfset.h:273
void dec(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: gauss.cc:175
void dec(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::dec().
Definition: bfset.h:706
CGF iter_type
As far as SetIterator is concerned, CGShell is a set of CGFs.
Definition: bfset.h:257
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: bfset.h:710
SHGF iter_type
As far as SetIterator is concerned, SHGShell is a set of SHGFs.
Definition: bfset.h:772
unsigned int qn(unsigned int xyz) const
Returns the angular momentum.
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:686
CGF1d iter_type
As far as SetIterator is concerned, CGF1d is a set of one CGF1d.
Definition: bfset.h:450
std::string label() const
Return a compact label.
Definition: gauss.cc:262
SHGF & operator=(const SHGF &)
assignment
Solid-Harmonic Gaussian Shell.
Definition: bfset.h:761
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: bfset.h:556
CGF()
How to return key.
Definition: gauss.cc:81
virtual unsigned int norm() const =0
Returns the norm of the quantum numbers.
bool operator==(const SHGShell &) const
Comparison operator.
CGF1d()
Default constructor makes an qn=0 Gaussian.
Definition: bfset.h:454
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: gauss.cc:196
unsigned int d(unsigned int xyz) const
returns the number of quanta along xyz
Definition: bfset.h:127
bool zero() const
norm() == 0
Definition: bfset.h:74
bool pure_sh() const
contains only solid harmonics with the same quantum number as this shell? (this may permit simplified...
Definition: bfset.h:374
bool operator==(const SHGF &) const
Comparison operator.
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:365
unsigned int num_bf() const
Returns the number of basis functions in the set (always 1)
Definition: bfset.h:518
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:159
void inc(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: gauss.cc:188
unsigned int qn(unsigned int m=0) const
Returns the angular momentum.
Definition: bfset.h:790
std::string to_string(const T &x)
Converts x to its string representation.
Definition: entity.h:74
static CGF unit()
returns the unit shell (exponent=0, am=0, indicated by unit_=true)
Definition: gauss.cc:228
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:712
unsigned int norm() const
Implements IncableBFSet::norm()
void inc(unsigned int xyz, unsigned int c=1u)
Add c quanta along xyz.
Definition: bfset.h:136
void dec(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::dec().
CGF1d< Axis > iter_type
CGShell1d is a set CGF1d's.
Definition: bfset.h:639
std::string label() const
Return a compact label.
Definition: bfset.h:669
void inc(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::inc().
bool valid() const
Return false if this object is invalid.
Definition: bfset.h:157
static const unsigned max_num_qn
The range of keys is [0,max_key).
Definition: bfset.h:872
static const LIBINT2_UINT_LEAST64 max_key
The range of keys is [0,max_key] deriv_key_range = OriginDerivative<3u>::max_key contracted = 2 (yes ...
Definition: bfset.h:317
F unit(unsigned int X)
BF with unit quantum along X. F must behave like IncableBFSet.
Definition: bfset.h:90
bool operator==(const CGShell &) const
Comparison operator.
Definition: gauss.cc:285
void inc(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: bfset.h:537
void dec(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::dec().
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: gauss.cc:322
void inc(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: gauss.cc:308
unsigned int num_bf() const
Returns the number of basis functions in the set.
Definition: bfset.h:788
CGF & operator=(const CGF &)
assignment
Definition: gauss.cc:162
bool zero() const
norm() == 0
Definition: bfset.h:155
SHGShell()
Default constructor creates an s-type shell.
void print(std::ostream &os=std::cout) const
Print out the content.
bool exists(const IncableBFSet &A)
Return true if A is valid.
Definition: bfset.h:92
void inc(unsigned int xyz, unsigned int c=1u)
Implementation of IncableBFSet::inc().
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:558
static const LIBINT2_UINT_LEAST64 max_num_qn
The range of keys is [0,max_key).
Definition: bfset.h:410
std::string label() const
Return a compact label.
Definition: gauss.cc:119
void print(std::ostream &os=std::cout) const
Print out the content.
unsigned int qn(unsigned int axis) const
Returns the quantum number along axis.
Definition: gauss.cc:143
unsigned int qn(unsigned int xyz=0) const
Returns the angular momentum.
Definition: bfset.h:275
SHGF iter_type
As far as SetIterator is concerned, SHGF is a set of one SHGF.
Definition: bfset.h:829
void inc(unsigned int dir, unsigned int c=1u)
Implementation of IncableBFSet::inc().
Definition: bfset.h:702
bool operator==(const CGF1d &a) const
Comparison operator.
Definition: bfset.h:529
Set of basis functions.
Definition: bfset.h:42
unsigned int norm() const
Implements IncableBFSet::norm()
Definition: gauss.cc:316
static const LIBINT2_UINT_LEAST64 max_num_qn
The range of keys is [0,max_key).
Definition: bfset.h:729
static CGShell unit()
returns the unit shell (exponent=0, am=0, indicated by pure_sh=true)
Definition: gauss.cc:345
CGShell1d()
Default constructor makes a qn=0 shell.
Definition: bfset.h:643
unsigned int norm() const
Implements IncableBFSet::norm()
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:142
Solid-Harmonic Gaussian Function.
Definition: bfset.h:818
unsigned int qn(unsigned int dir=0) const
Returns the quantum number (what used to be "angular momentum")
Definition: bfset.h:688
void invalidate()
make this object invalid
Definition: bfset.h:82
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: gauss.cc:202
unsigned key() const
Implements Hashable<unsigned>::key()
Definition: bfset.h:802
void pure_sh(bool p)
Definition: bfset.h:288
virtual void dec(unsigned int xyz, unsigned int c=1u)=0
Subtract c quanta along xyz. If impossible, invalidate the object, but do not change its quanta!
CGShell1d & operator=(const CGShell1d &source)
assignment
Definition: bfset.h:655
static CGShell1d unit()
returns the unit shell (exponent=0, am=0, indicated by unit_=true)
Definition: bfset.h:742
static const LIBINT2_UINT_LEAST64 max_num_qn
The range of keys is [0,max_key).
Definition: bfset.h:575
3D Cartesian Gaussian Function
Definition: bfset.h:332
Represents cartesian derivatives of atom-centered basis functions.
Definition: bfset.h:97
CGF iter_type
As far as SetIterator is concerned, CGF is a set of one CGF.
Definition: bfset.h:345
void pure_sh(bool p)
Definition: bfset.h:376
bool pure_sh() const
contains only solid harmonics with the same quantum number as this shell? (this may permit simplified...
Definition: bfset.h:286
void print(std::ostream &os=std::cout) const
Print out the content.
Definition: bfset.h:737
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:297
std::string label() const
Return a compact label.
void print(std::ostream &os=std::cout) const
Print out the content.
unsigned int operator[](unsigned int xyz) const
returns the angular momentum
Definition: bfset.h:277
bool operator==(const CGF &) const
Comparison operator.
Definition: gauss.cc:150
void invalidate()
make this object invalid
Definition: bfset.h:204
LIBINT2_UINT_LEAST64 key() const
Implements Hashable<LIBINT2_UINT_LEAST64>::key()
Definition: bfset.h:388
bool valid() const
Return false if this object is invalid.
Definition: bfset.h:76