Skip to content

Commit f258b45

Browse files
Kappa minus one (#491)
* improve things * refine potential before kappa transform * project and store kappa minus one * apply product rule * rever product rule change * use other derivative operator * remove unused operator * delete unused zora_kinetic operator * remove old comments * add some documentation * rename kappa to chi --------- Co-authored-by: moritzgubler <[email protected]>
1 parent 03862bb commit f258b45

File tree

5 files changed

+41
-70
lines changed

5 files changed

+41
-70
lines changed

src/qmoperators/one_electron/ZoraKineticOperator.h

-48
This file was deleted.

src/qmoperators/one_electron/ZoraOperator.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ ZoraOperator::ZoraOperator(QMPotential &vz, double c, double proj_prec, bool inv
4747
if (k->hasReal()) {
4848
mrcpp::refine_grid(k->real(), 1);
4949
if (inverse) {
50-
k->real().map([two_cc](double val) { return (two_cc - val) / two_cc; });
50+
k->real().map([two_cc](double val) { return (two_cc - val) / two_cc - 1.0; });
5151
} else {
52-
k->real().map([two_cc](double val) { return two_cc / (two_cc - val); });
52+
k->real().map([two_cc](double val) { return (val) / (two_cc - val); });
5353
}
5454
k->real().crop(proj_prec);
5555
}
5656

57-
RankZeroOperator &kappa = (*this);
58-
kappa = k;
57+
RankZeroOperator &chi = (*this);
58+
chi = k;
5959
if (inverse) {
60-
kappa.name() = "kappa_m1";
60+
chi.name() = "chi_inv";
6161
} else {
62-
kappa.name() = "kappa";
62+
chi.name() = "chi";
6363
}
6464
auto plevel = Printer::getPrintLevel();
65-
print_utils::qmfunction(2, "ZORA operator (" + kappa.name() + ")", *k, timer);
65+
print_utils::qmfunction(2, "ZORA operator (" + chi.name() + ")", *k, timer);
6666
}
6767

6868
} // namespace mrchem

src/qmoperators/one_electron/ZoraOperator.h

+14
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,22 @@ namespace mrchem {
3131

3232
class QMPotential;
3333

34+
/**
35+
* @class ZoraOperator
36+
* @brief Implements chi = kappa - 1 relativistic dampening function. This has to be done in order to
37+
* avoid numerical instabilities in the ZORA operator. Whenever this operator is applied, the + 1 has to be added to chi i
38+
* in order to get the kappa operator. kappa * phi = chi * phi + phi
39+
* This has to be done manually.
40+
*/
3441
class ZoraOperator final : public RankZeroOperator {
3542
public:
43+
/**
44+
* @brief Constructor for the ZoraOperator that contains the chi = kappa - 1 function.
45+
* @param vz The potential used to calculate the kappa function.
46+
* @param c Speed of light.
47+
* @param proj_prec The precision of the MW projection.
48+
* @param inverse If true, the inverse of the chi function is calculated.
49+
*/
3650
ZoraOperator(QMPotential &vz, double c, double proj_prec, bool inverse = false);
3751
};
3852

src/qmoperators/two_electron/FockBuilder.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ void FockBuilder::setup(double prec) {
9696
mrcpp::print::value(3, "Light speed", c, "(au)", 5);
9797
mrcpp::print::separator(3, '-');
9898
auto vz = collectZoraBasePotential();
99-
this->kappa = std::make_shared<ZoraOperator>(*vz, c, prec, false);
100-
this->kappa_inv = std::make_shared<ZoraOperator>(*vz, c, prec, true);
99+
// chi = kappa - 1. See ZoraOperator.h for more information.
100+
this->chi = std::make_shared<ZoraOperator>(*vz, c, prec, false);
101+
this->chi_inv = std::make_shared<ZoraOperator>(*vz, c, prec, true);
101102
this->zora_base = RankZeroOperator(vz);
102-
this->kappa->setup(prec);
103-
this->kappa_inv->setup(prec);
103+
this->chi->setup(prec);
104+
this->chi_inv->setup(prec);
104105
this->zora_base.setup(prec);
105106
mrcpp::print::footer(3, t_zora, 2);
106107
};
@@ -120,8 +121,8 @@ void FockBuilder::clear() {
120121
this->potential().clear();
121122
this->perturbation().clear();
122123
if (isZora()) {
123-
this->kappa->clear();
124-
this->kappa_inv->clear();
124+
this->chi->clear();
125+
this->chi_inv->clear();
125126
this->zora_base.clear();
126127
}
127128
}
@@ -180,7 +181,7 @@ SCFEnergy FockBuilder::trace(OrbitalVector &Phi, const Nuclei &nucs) {
180181

181182
// Kinetic part
182183
if (isZora()) {
183-
E_kin = qmoperator::calc_kinetic_trace(momentum(), *this->kappa, Phi).real();
184+
E_kin = qmoperator::calc_kinetic_trace(momentum(), *this->chi, Phi).real() + qmoperator::calc_kinetic_trace(momentum(), Phi);
184185
} else {
185186
E_kin = qmoperator::calc_kinetic_trace(momentum(), Phi);
186187
}
@@ -205,7 +206,7 @@ ComplexMatrix FockBuilder::operator()(OrbitalVector &bra, OrbitalVector &ket) {
205206

206207
ComplexMatrix T_mat = ComplexMatrix::Zero(bra.size(), ket.size());
207208
if (isZora()) {
208-
T_mat = qmoperator::calc_kinetic_matrix(momentum(), *this->kappa, bra, ket);
209+
T_mat = qmoperator::calc_kinetic_matrix(momentum(), *this->chi, bra, ket) + qmoperator::calc_kinetic_matrix(momentum(), bra, ket);
209210
} else {
210211
T_mat = qmoperator::calc_kinetic_matrix(momentum(), bra, ket);
211212
}
@@ -247,12 +248,12 @@ OrbitalVector FockBuilder::buildHelmholtzArgumentZORA(OrbitalVector &Phi, Orbita
247248
double two_cc = 2.0 * c * c;
248249
MomentumOperator &p = momentum();
249250
RankZeroOperator &V = potential();
250-
RankZeroOperator &kappa = *this->kappa;
251-
RankZeroOperator &kappa_m1 = *this->kappa_inv;
251+
RankZeroOperator &chi = *this->chi;
252+
RankZeroOperator &chi_inv = *this->chi_inv;
252253
RankZeroOperator &V_zora = this->zora_base;
253254

254-
RankZeroOperator operOne = 0.5 * tensor::dot(p(kappa), p);
255-
RankZeroOperator operThree = kappa * V_zora;
255+
RankZeroOperator operOne = 0.5 * tensor::dot(p(chi), p);
256+
RankZeroOperator operThree = chi * V_zora + V_zora;
256257
operOne.setup(prec);
257258
operThree.setup(prec);
258259

@@ -296,7 +297,11 @@ OrbitalVector FockBuilder::buildHelmholtzArgumentZORA(OrbitalVector &Phi, Orbita
296297
operOne.clear();
297298

298299
Timer t_kappa;
299-
auto out = kappa_m1(arg);
300+
mrchem::OrbitalVector out = chi_inv(arg);
301+
for (int i = 0; i < arg.size(); i++) {
302+
if (not mrcpp::mpi::my_orb(out[i])) continue;
303+
out[i].add(1.0, arg[i]);
304+
}
300305
mrcpp::print::time(2, "Applying kappa inverse", t_kappa);
301306
return out;
302307
}

src/qmoperators/two_electron/FockBuilder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class FockBuilder final {
105105
std::shared_ptr<XCOperator> xc{nullptr};
106106
std::shared_ptr<ReactionOperator> Ro{nullptr}; // Reaction field operator
107107
std::shared_ptr<ElectricFieldOperator> ext{nullptr}; // Total external potential
108-
std::shared_ptr<ZoraOperator> kappa{nullptr};
109-
std::shared_ptr<ZoraOperator> kappa_inv{nullptr};
108+
std::shared_ptr<ZoraOperator> chi{nullptr};
109+
std::shared_ptr<ZoraOperator> chi_inv{nullptr};
110110

111111
std::shared_ptr<QMPotential> collectZoraBasePotential();
112112
OrbitalVector buildHelmholtzArgumentZORA(OrbitalVector &Phi, OrbitalVector &Psi, DoubleVector eps, double prec);

0 commit comments

Comments
 (0)