Skip to content

Commit

Permalink
compatibility for redefined mrcpp alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
gitpeterwind committed Aug 28, 2024
1 parent 2fc0119 commit a8bf937
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/environment/GPESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mrcpp::CompFunction<3> GPESolver::solvePoissonEquation(const mrcpp::CompFunction
mrcpp::CompFunction<3> first_term;
mrcpp::CompFunction<3> Vr_np1;
Vr_np1.func_ptr->isreal = 1;
Vr_np1.alloc(0);
Vr_np1.alloc(1);

auto eps_inv_func = mrcpp::AnalyticFunction<3>([this](const mrcpp::Coord<3> &r) { return 1.0 / this->epsilon.evalf(r); });
Density rho_tot(false);
Expand Down Expand Up @@ -238,7 +238,7 @@ mrcpp::CompFunction<3> &GPESolver::solveEquation(double prec, const Density &rho
Timer t_vac;
mrcpp::CompFunction<3> V_vac;
V_vac.func_ptr->isreal = 1;
V_vac.alloc(0);
V_vac.alloc(1);
mrcpp::apply(this->apply_prec, V_vac.real(), *poisson, rho_tot.real());
rho_tot.free();
print_utils::qmfunction(3, "Vacuum potential", V_vac, t_vac);
Expand All @@ -250,7 +250,7 @@ mrcpp::CompFunction<3> &GPESolver::solveEquation(double prec, const Density &rho
mrcpp::CompFunction<3> gamma_0;
mrcpp::CompFunction<3> V_tot;
gamma_0.func_ptr->isreal = 1;
gamma_0.alloc(0);
gamma_0.alloc(1);

computeGamma(V_vac, gamma_0);
this->Vr_n = solvePoissonEquation(gamma_0, rho_el);
Expand All @@ -273,7 +273,7 @@ auto GPESolver::computeEnergies(const Density &rho_el) -> std::tuple<double, dou
void GPESolver::resetComplexFunction(mrcpp::CompFunction<3> &function) {
function.func_ptr->isreal = 1;
function.func_ptr->iscomplex = 0;
function.alloc(0);
function.alloc(1);
}

void GPESolver::printParameters() const {
Expand Down
2 changes: 1 addition & 1 deletion src/environment/PBESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void PBESolver::computePBTerm(mrcpp::CompFunction<3> &V_tot, const double salt_f
resetComplexFunction(pb_term);
mrcpp::CompFunction<3> sinhV;
sinhV.func_ptr->isreal = 1;
sinhV.alloc(0);
sinhV.alloc(1);
mrcpp::map(this->apply_prec / 100, sinhV.real(), V_tot.real(), sinh_f);

mrcpp::multiply(pb_term, sinhV, this->kappa, this->apply_prec);
Expand Down
2 changes: 1 addition & 1 deletion src/initial_guess/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool initial_guess::cube::project_mo(OrbitalVector &Phi, double prec, const std:
Timer t_i;
if (mrcpp::mpi::my_func(Phi[i])) {
CUBEfunction phi_i = CUBEVector[i];
Phi[i].alloc(0);
Phi[i].alloc(1);
mrcpp::project(prec, Phi[i].real(), phi_i);
std::stringstream o_txt;
o_txt << std::setw(w1 - 1) << i;
Expand Down
2 changes: 1 addition & 1 deletion src/initial_guess/sad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void initial_guess::sad::project_atomic_densities(double prec, Density &rho_tot,

Timer t_tot;
Density rho_loc(false);
rho_loc.alloc();
rho_loc.alloc(1);
rho_loc.real().setZero();

Timer t_loc;
Expand Down
4 changes: 2 additions & 2 deletions src/qmfunctions/Density.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ void Density::loadDensity(const std::string &file) {
if (isreal()) {
std::stringstream fname;
fname << file << "_re";
alloc(0);
alloc(1);
CompD[0]->loadTree(fname.str());
}

// reading complex tree
if (iscomplex()) {
std::stringstream fname;
fname << file << "_cx";
alloc(0);
alloc(1);
CompC[0]->loadTree(fname.str());
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/qmfunctions/density_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void density::compute_local_X(double prec, Density &rho, OrbitalVector &Phi, Orb
double add_prec = prec / N_el; // prec for rho = sum_i rho_i
if (Phi.size() != X.size()) MSG_ERROR("Size mismatch");

if (rho.Ncomp() == 0) rho.alloc(0);
if (rho.Ncomp() == 0) rho.alloc(1);

// Compute local density from own orbitals
for (int i = 0; i < Phi.size(); i++) {
Expand All @@ -179,7 +179,7 @@ void density::compute_local_XY(double prec, Density &rho, OrbitalVector &Phi, Or
if (Phi.size() != X.size()) MSG_ERROR("Size mismatch");
if (Phi.size() != Y.size()) MSG_ERROR("Size mismatch");

if (rho.Ncomp() == 0) rho.alloc(0);
if (rho.Ncomp() == 0) rho.alloc(1);

// Compute local density from own orbitals
rho.real().setZero();
Expand All @@ -205,7 +205,7 @@ void density::compute_local_XY(double prec, Density &rho, OrbitalVector &Phi, Or
}

void density::compute(double prec, Density &rho, mrcpp::GaussExp<3> &dens_exp) {
if (not rho.hasReal()) rho.alloc(NUMBER::Real);
if (not rho.hasReal()) rho.alloc(1);
mrcpp::build_grid(rho.real(), dens_exp);
mrcpp::project(prec, rho.real(), dens_exp);
}
Expand All @@ -228,7 +228,7 @@ void density::allreduce_density(double prec, Density &rho_tot, Density &rho_loc)
if (mrcpp::mpi::numerically_exact) rho_loc.crop(prec);
}

if (not rho_tot.hasReal()) rho_tot.alloc(NUMBER::Real);
if (not rho_tot.hasReal()) rho_tot.alloc(1);

if (rho_tot.isShared()) {
int tag = 2002;
Expand Down
4 changes: 2 additions & 2 deletions src/qmfunctions/orbital_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,15 +1236,15 @@ void orbital::loadOrbital(const std::string &file, Orbital &orb) {
if (orb.isreal()) {
std::stringstream fname;
fname << file << "_real";
orb.alloc(0);
orb.alloc(1);
orb.CompD[0]->loadTree(fname.str());
}

// reading imaginary part
if (orb.iscomplex()) {
std::stringstream fname;
fname << file << "_complex";
orb.alloc(0);
orb.alloc(1);
orb.CompC[0]->loadTree(fname.str());
}
delete mra;
Expand Down
6 changes: 3 additions & 3 deletions src/qmoperators/QMDerivative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ QMOperatorVector QMDerivative::apply(QMOperator_p &O) {
// does not compile? mrcpp::apply(V_out_base, D, V_inp, d);
if (this->isReal()) {
if (V_inp->isreal()) {
V_out->alloc(0);
V_out->alloc(1);
mrcpp::apply(V_out->real(), D, V_inp->real(), d);
}
if (V_inp->iscomplex()) {
V_out->func_ptr->isreal = 0;
V_out->func_ptr->iscomplex = 1;
V_out->alloc(0);
V_out->alloc(1);
mrcpp::apply(V_out->complex(), D, V_inp->complex(), d);
//if (V_inp->conjugate()) V_out->imag().rescale(-1.0);
}
} else {
if (V_inp->iscomplex()) {
V_out->func_ptr->isreal = 0;
V_out->func_ptr->iscomplex = 1;
V_out->alloc(0);
V_out->alloc(1);
mrcpp::apply(V_out->complex(), D, V_inp->complex(), d);
if (!V_inp->conjugate()) V_out->CompC[0]->rescale({0.0, 1.0});
}
Expand Down
2 changes: 1 addition & 1 deletion src/qmoperators/one_electron/DistanceOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DistanceOperator final : public RankZeroOperator {

// Project analytic potential, building grid for 1/r
auto r_pow = std::make_shared<QMPotential>(1);
r_pow->alloc(0);
r_pow->alloc(1);
mrcpp::build_grid(r_pow->real(), nuc_func);
mrcpp::project<3>(proj_prec, r_pow->real(), f);

Expand Down
2 changes: 1 addition & 1 deletion src/qmoperators/one_electron/NuclearOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void NuclearOperator::allreducePotential(double prec, mrcpp::CompFunction<3> &V_
if (mrcpp::mpi::numerically_exact) V_loc.crop(prec);
}

if (not V_tot.hasReal()) V_tot.alloc(0);
if (not V_tot.hasReal()) V_tot.alloc(1);
if (V_tot.isShared()) {
int tag = 3141;
// MPI grand master distributes to shared masters
Expand Down
6 changes: 3 additions & 3 deletions src/qmoperators/two_electron/CoulombPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CoulombPotential::setupGlobalPotential(double prec) {
bool need_to_apply = not(V.isShared()) or mrcpp::mpi::share_master();

Timer timer;
V.alloc(0);
V.alloc(1);
if (need_to_apply) mrcpp::apply(abs_prec, V.real(), P, rho.real());
mrcpp::mpi::share_function(V, 0, 22445, mrcpp::mpi::comm_share);
print_utils::qmfunction(3, "Compute global potential", V, timer);
Expand All @@ -151,7 +151,7 @@ mrcpp::CompFunction<3> CoulombPotential::setupLocalPotential(double prec) {

Timer timer;
mrcpp::CompFunction<3> V(false);
V.alloc(0);
V.alloc(1);
mrcpp::apply(abs_prec, V.real(), P, rho.real());
print_utils::qmfunction(3, "Compute local potential", V, timer);

Expand All @@ -169,7 +169,7 @@ void CoulombPotential::allreducePotential(double prec, mrcpp::CompFunction<3> &V
// Add up local contributions into the grand master
mrcpp::mpi::reduce_function(abs_prec, V_loc, mrcpp::mpi::comm_wrk);

if (not V_tot.hasReal()) V_tot.alloc(0);
if (not V_tot.hasReal()) V_tot.alloc(1);
if (V_tot.isShared()) {
int tag = 3141;
// MPI grand master distributes to shared masters
Expand Down
6 changes: 3 additions & 3 deletions src/qmoperators/two_electron/XCPotentialD1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD1::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Total, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Total);
}
Expand All @@ -66,7 +66,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD1::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Alpha, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Alpha);
}
Expand All @@ -77,7 +77,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD1::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Beta, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Beta);
}
Expand Down
12 changes: 6 additions & 6 deletions src/qmoperators/two_electron/XCPotentialD2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Total, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Total);
}
Expand All @@ -86,7 +86,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Total, 1);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, *orbitals_x, *orbitals_y, DensityType::Total);
}
Expand All @@ -98,7 +98,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Alpha, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Alpha);
}
Expand All @@ -109,7 +109,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Beta, 0);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, DensityType::Beta);
}
Expand All @@ -120,7 +120,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Alpha, 1);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, *orbitals_x, *orbitals_y, DensityType::Alpha);
}
Expand All @@ -131,7 +131,7 @@ mrcpp::FunctionTreeVector<3> XCPotentialD2::setupDensities(double prec, mrcpp::F
Timer timer;
Density &rho = getDensity(DensityType::Beta, 1);
if (rho.Ncomp() == 0) {
rho.alloc(0);
rho.alloc(1);
mrcpp::copy_grid(rho.real(), grid);
density::compute(prec, rho, *orbitals, *orbitals_x, *orbitals_y, DensityType::Beta);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/qmoperators/position_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_CASE("PositionOperator", "[position_operator]") {
r.setup(prec);
SECTION("vector apply") {
OrbitalVector xPhi = r[0](Phi);
ComplexMatrix X = orbital::calc_overlap_matrix(Phi, xPhi);
ComplexMatrix X = mrcpp::calc_overlap_matrix(Phi, xPhi);
for (int i = 0; i < X.rows(); i++) {
for (int j = 0; j < X.cols(); j++) { REQUIRE(std::abs(X(i, j).real() - ref(i, j)) < thrs); }
}
Expand Down

0 comments on commit a8bf937

Please sign in to comment.