Skip to content

Commit 41bf762

Browse files
committed
Rename GPESolver::solveEquation to iterateEquation
Remove print statements Make sure the code compiles
1 parent a84e90e commit 41bf762

File tree

8 files changed

+15
-43
lines changed

8 files changed

+15
-43
lines changed

pilot/mrchem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int main(int argc, char **argv) {
125125

126126
PB_solver->setConvergenceThreshold(poisson_prec);
127127
// PB_solver->setStaticSalt();
128-
PB_solver->solveEquation(poisson_prec, ORB);
128+
PB_solver->iterateEquation(poisson_prec, ORB);
129129
double total_energy = PB_solver->getTotalEnergy() / 2;
130130
PB_solver->clear();
131131

src/driver.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,6 @@ void driver::build_fock_operator(const json &json_fock, Molecule &mol, FockBuild
10661066

10671067
auto width_ion = json_fock["reaction_operator"]["ion_width"];
10681068
auto kformulation = json_fock["reaction_operator"]["formulation"];
1069-
auto solver_type = json_fock["reaction_operator"]["solver_type"];
10701069

10711070
Permittivity dielectric_func(*cavity_p, eps_i, eps_o, formulation);
10721071
dielectric_func.printParameters();

src/environment/GPESolver.cpp

+7-35
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ GPESolver::GPESolver(Permittivity e, const Nuclei &N, PoissonOperator_p P, Deriv
7171
, poisson(P) {
7272
setDCavity();
7373
rho_nuc = chemistry::compute_nuclear_density(this->apply_prec, N, 1000);
74-
std::cout << "norm of rho_nuc: " << rho_nuc.norm() << std::endl;
75-
std::cout << "integral of rho_nuc: " << rho_nuc.integrate() << std::endl;
7674
}
7775

7876
GPESolver::~GPESolver() {
@@ -115,10 +113,10 @@ void GPESolver::computeDensities(OrbitalVector &Phi) {
115113
rho_el.rescale(-1.0);
116114
if (this->density_type == "electronic") {
117115
mrcpp::cplxfunc::deep_copy(this->rho_tot, rho_el);
116+
118117
} else if (this->density_type == "nuclear") {
119118
mrcpp::cplxfunc::deep_copy(this->rho_tot, this->rho_nuc);
120-
std::cout << "norm of rho_tot: " << this->rho_tot.norm() << std::endl;
121-
std::cout << "integral of rho_tot: " << this->rho_tot.integrate() << std::endl;
119+
122120
} else {
123121
mrcpp::cplxfunc::add(this->rho_tot, 1.0, rho_el, 1.0, this->rho_nuc, -1.0); // probably change this into a vector
124122
}
@@ -131,8 +129,6 @@ void GPESolver::computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFu
131129
mrcpp::dot(this->apply_prec, out_gamma.real(), d_V, this->d_cavity);
132130
out_gamma.rescale(std::log((epsilon.getEpsIn() / epsilon.getEpsOut())) * (1.0 / (4.0 * mrcpp::pi)));
133131
mrcpp::clear(d_V, true);
134-
std::cout << "norm of gamma: " << out_gamma.norm() << std::endl;
135-
std::cout << "integral of gamma: " << out_gamma.integrate() << std::endl;
136132
}
137133

138134
mrcpp::ComplexFunction GPESolver::solvePoissonEquation(const mrcpp::ComplexFunction &in_gamma) {
@@ -150,9 +146,6 @@ mrcpp::ComplexFunction GPESolver::solvePoissonEquation(const mrcpp::ComplexFunct
150146
mrcpp::cplxfunc::multiply(first_term, this->rho_tot, eps_inv, this->apply_prec);
151147
mrcpp::cplxfunc::add(rho_eff, 1.0, first_term, -1.0, this->rho_tot, -1.0);
152148

153-
std::cout << "norm of rho_eff: " << rho_eff.norm() << std::endl;
154-
std::cout << "integral of rho_eff: " << rho_eff.integrate() << std::endl;
155-
156149
mrcpp::cplxfunc::add(Poisson_func, 1.0, in_gamma, 1.0, rho_eff, -1.0);
157150
mrcpp::apply(this->apply_prec, Vr.real(), *poisson, Poisson_func.real());
158151

@@ -185,15 +178,12 @@ void GPESolver::runMicroIterations(mrcpp::ComplexFunction V_vac) {
185178
auto update = 10.0, norm = 1.0;
186179

187180
auto iter = 1;
188-
std::cout << "convergence threshold: " << this->conv_thrs << std::endl;
189181
for (; iter <= max_iter; iter++) {
190182

191183
Timer t_iter;
192184
mrcpp::ComplexFunction Vr_np1;
193185
// solve the poisson equation
194186
Vr_np1 = solvePoissonEquation(this->gamma_n);
195-
std::cout << "norm of Vr_np1: " << Vr_np1.norm() << std::endl;
196-
std::cout << "integral of Vr_np1: " << Vr_np1.integrate() << std::endl;
197187

198188
norm = Vr_np1.norm();
199189

@@ -207,7 +197,6 @@ void GPESolver::runMicroIterations(mrcpp::ComplexFunction V_vac) {
207197
mrcpp::cplxfunc::add(Vr_np1, 1.0, Vr_n, 1.0, dVr_n, -1.0);
208198
}
209199
update = dVr_n.norm();
210-
std::cout << "total energy at iteration " << iter << ": " << getTotalEnergy() << std::endl;
211200
// set up for next iteration
212201
mrcpp::ComplexFunction V_tot;
213202
mrcpp::cplxfunc::add(V_tot, 1.0, Vr_np1, 1.0, V_vac, -1.0);
@@ -229,9 +218,7 @@ void GPESolver::runMicroIterations(mrcpp::ComplexFunction V_vac) {
229218
updateCurrentGamma(gamma_np1);
230219
printConvergenceRow(iter, norm, update, t_iter.elapsed());
231220

232-
std::cout << "update: " << update << std::endl;
233221
// compute new PB term
234-
std::cout << "update " << update << " convergence threshold " << this->conv_thrs << std::endl;
235222
if (update < this->conv_thrs) break;
236223
}
237224

@@ -268,15 +255,13 @@ void GPESolver::printConvergenceRow(int i, double norm, double update, double ti
268255
println(3, o_txt.str());
269256
}
270257

271-
mrcpp::ComplexFunction &GPESolver::solveEquation(double prec, const OrbitalVector_p &Phi) {
258+
mrcpp::ComplexFunction &GPESolver::iterateEquation(double prec, const OrbitalVector_p &Phi) {
272259
this->apply_prec = prec;
273260
computeDensities(*Phi);
274261
Timer t_vac;
275262
mrcpp::ComplexFunction V_vac;
276263
V_vac.alloc(NUMBER::Real);
277264
mrcpp::apply(this->apply_prec, V_vac.real(), *poisson, this->rho_tot.real());
278-
std::cout << "norm of V_vac: " << V_vac.norm() << std::endl;
279-
std::cout << "integral of V_vac: " << V_vac.integrate() << std::endl;
280265
print_utils::qmfunction(3, "Vacuum potential", V_vac, t_vac);
281266

282267
// set up the zero-th iteration potential and gamma, so the first iteration gamma and potentials can be made
@@ -286,17 +271,13 @@ mrcpp::ComplexFunction &GPESolver::solveEquation(double prec, const OrbitalVecto
286271
mrcpp::ComplexFunction gamma_0;
287272
mrcpp::ComplexFunction V_tot;
288273
computeGamma(V_vac, gamma_0);
289-
std::cout << "norm of gamma_n at zeroth iteration: " << gamma_0.norm() << std::endl;
290-
std::cout << "integral of gamma_n at zeroth iteration: " << gamma_0.integrate() << std::endl;
274+
291275
this->Vr_n = solvePoissonEquation(gamma_0);
292-
std::cout << "total energy at zeroth iteration" << getTotalEnergy() << std::endl;
293-
std::cout << "norm of Vr_n at zeroth iteration: " << this->Vr_n.norm() << std::endl;
294-
std::cout << "integral of Vr_n at zeroth iteration: " << this->Vr_n.integrate() << std::endl;
276+
295277
mrcpp::cplxfunc::add(V_tot, 1.0, V_vac, 1.0, this->Vr_n, -1.0);
296278
computeGamma(V_tot, this->gamma_n);
297279
}
298-
std::cout << "norm of gamma_n at first iteration: " << this->gamma_n.norm() << std::endl;
299-
std::cout << "integral of gamma_n at first iteration: " << this->gamma_n.integrate() << std::endl;
280+
300281
// update the potential/gamma with the previous scf cycle kain update before doing anything with them
301282

302283
if (accelerate_Vr) {
@@ -308,16 +289,7 @@ mrcpp::ComplexFunction &GPESolver::solveEquation(double prec, const OrbitalVecto
308289
mrcpp::cplxfunc::add(V_tot, 1.0, this->Vr_n, 1.0, V_vac, -1.0);
309290
resetComplexFunction(this->gamma_n);
310291
computeGamma(V_tot, this->gamma_n);
311-
// std::cout << "apply prec " << this->apply_prec << std::endl;
312-
// std::cout << "conv thrs " << this->conv_thrs << std::endl;
313-
// std::cout << "difference between them " << this->conv_thrs - this->apply_prec << std::endl;
314-
// if (std::abs(this->conv_thrs - this->apply_prec) <= mrcpp::MachineZero) {
315-
// std::cout << "does this ever work?" << std::endl;
316-
// this->salt_factor = 1.0;
317-
// computePBTerm(V_tot, this->salt_factor);
318-
// } else {
319-
// this->salt_factor = 0.0;
320-
// }
292+
321293
} else {
322294
mrcpp::ComplexFunction temp_gamma_n;
323295
mrcpp::cplxfunc::add(temp_gamma_n, 1.0, this->gamma_n, 1.0, this->dgamma_n, -1.0);

src/environment/GPESolver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class GPESolver {
8080
void updateMOResidual(double const err_t) { this->mo_residual = err_t; }
8181

8282
friend class ReactionPotential;
83-
mrcpp::ComplexFunction &solveEquation(double prec, const std::shared_ptr<mrchem::OrbitalVector> &Phi);
83+
mrcpp::ComplexFunction &iterateEquation(double prec, const std::shared_ptr<mrchem::OrbitalVector> &Phi);
8484
double getTotalEnergy();
8585

8686
void clear();

src/environment/LPBESolver.h

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class LPBESolver final : public PBESolver {
5252
std::string density_type)
5353
: PBESolver(e, kappa, N, P, D, orb_prec, kain_hist, max_iter, acc_pot, dyn_thrs, density_type) {}
5454

55-
~LPBESolver();
56-
5755
friend class ReactionPotential;
5856

5957
protected:

src/environment/PBESolver.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class PBESolver : public GPESolver {
5151
bool dyn_thrs,
5252
std::string density_type);
5353

54-
~PBESolver();
55-
5654
void setStaticSalt(bool do_static) { do_static_salt = do_static; }
5755

5856
friend class ReactionPotential;
@@ -65,6 +63,10 @@ class PBESolver : public GPESolver {
6563

6664
void setKappa(DHScreening k);
6765

66+
// FIXME ComputeGamma should not be computing the PB term.
67+
// THe PB term is actually an approximation for an external density, so
68+
// it should be computed in the computedensities function or in the
69+
// solvePoissonEquation function.
6870
void computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFunction &out_gamma);
6971
void computePBTerm(mrcpp::ComplexFunction &V_tot, double salt_factor);
7072
};

src/qmoperators/two_electron/ReactionPotential.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void ReactionPotential::setup(double prec) {
4949
mrcpp::print::value(3, "Precision", prec, "(rel)", 5);
5050
mrcpp::print::value(3, "Threshold", thrs, "(abs)", 5);
5151
mrcpp::print::separator(3, '-');
52-
auto potential = this->solver->solveEquation(prec, this->Phi);
52+
auto potential = this->solver->iterateEquation(prec, this->Phi);
5353
mrcpp::cplxfunc::deep_copy(*this, potential);
5454
if (plevel == 2) print_utils::qmfunction(2, "Reaction operator", *this, timer);
5555
mrcpp::print::footer(3, timer, 2);

tests/solventeffect/reaction_operator.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ TEST_CASE("ReactionOperator", "[reaction_operator]") {
9292
Reo->setup(prec);
9393
double total_energy = Reo->getTotalEnergy();
9494
Reo->clear();
95+
std::cout << "total_energy = " << total_energy << std::endl;
9596
REQUIRE(total_energy == Approx(-0.191434124263).epsilon(thrs));
9697
}
9798

0 commit comments

Comments
 (0)