Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Remove useless variables from read_pp.h. #4711

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 73 additions & 159 deletions source/module_cell/pseudo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pseudo.h"
#include "module_base/tool_title.h"

pseudo::pseudo()
{
Expand All @@ -21,37 +22,25 @@ pseudo::~pseudo()
}

//---------------------------------------------------------------------
void pseudo::set_pseudo(const Pseudopot_upf& upf)
void pseudo::set_pseudo()
{
ModuleBase::TITLE("pseudo", "set_pseudo");

// call subroutines
this->set_pseudo_h(upf);
this->set_pseudo_atom(upf);
this->set_pseudo_vl(upf);
this->set_pseudo_h();
this->set_pseudo_atom();
this->set_pseudo_vl();

if (nbeta == 0)
if (nbeta == 0) {
return;
delete[] lll;
lll = new int[nbeta];
assert(lll != 0);

for (int i = 0;i < nbeta;i++)
}

if (lll == nullptr)
{
lll[i] = upf.lll[i];
lll = new int[nbeta];
assert(lll != nullptr);
}

betar.create(upf.beta.nr, upf.beta.nc);

// OUT("betar.nr",upf.beta.nr); // nbeta
// OUT("betar.nc",upf.beta.nc); // mesh

dion.create(nbeta, nbeta);

betar = upf.beta;

dion = upf.dion;

nh = 0;

for (int nb = 0; nb < nbeta;nb++)
Expand All @@ -75,28 +64,9 @@ void pseudo::print_pseudo(std::ofstream& ofs)
}


void pseudo::set_pseudo_h(const Pseudopot_upf &upf)
void pseudo::set_pseudo_h()
{
ModuleBase::TITLE("pseudo","set_pseudo_h");
// set pseudopotential for each atom type
// by using the Unified Pseudopotential Format

this->nv = upf.nv;// UPF file version number
this->psd = upf.psd;
this->pp_type = upf.pp_type;

this->tvanp = upf.tvanp;// if USPP
this->nlcc = upf.nlcc;// Non linear core corrections( bool ?)

this->xc_func = upf.xc_func;

this->zv = upf.zp;
this->etotps = upf.etotps;
this->ecutwfc = upf.ecutwfc;
this->ecutrho = upf.ecutrho;

this->lmax = upf.lmax;
this->mesh = upf.mesh;

// mohan update 2021-02-22
// max number of points in the atomic radial mesh
Expand All @@ -106,82 +76,59 @@ void pseudo::set_pseudo_h(const Pseudopot_upf &upf)
std::cout << "\n set_pseudo_h, too many grid points,";
}

this->nchi = upf.nwfc;
this->nbeta = upf.nbeta;
this->kkbeta = upf.kkbeta;

delete[] els;
this->els = new std::string[nchi];
assert(this->els != 0);

delete[] lchi;
this->lchi = new int[this->nchi];
assert(this->lchi != 0);

delete[] oc;
this->oc = new double[nchi];
assert(this->oc != 0);

for (int i = 0; i < nchi; i++)
{
this->els[i] = upf.els[i];
this->lchi[i] = upf.lchi[i];
this->oc[i] = upf.oc[i];
}

delete[] jjj;
this->jjj = new double[nbeta];
assert(this->jjj != 0);

delete[] nn;
this->nn = new int[nchi];
assert(this->nn != 0);
if (this->els == nullptr)
{
this->els = new std::string[nchi];
assert(this->els != nullptr);
}

delete[] jchi;
this->jchi = new double[nchi];
assert(this->jchi != 0);
if (this->lchi == nullptr)
{
this->lchi = new int[this->nchi];
assert(this->lchi != nullptr);
}

this->has_so = upf.has_so;//added by zhengdy-soc
if (this->oc == nullptr)
{
this->oc = new double[nchi];
assert(this->oc != nullptr);
}

if (this->has_so)
{
for(int i=0;i < nchi;i++)
{
this->nn[i] = upf.nn[i];
this->jchi[i] = upf.jchi[i];
}
for(int i=0;i < upf.nbeta;i++)
if (jjj == nullptr) {
this->jjj = new double[nbeta];
assert(this->jjj != nullptr);
assert(!this->has_so);
for (int i=0; i<nbeta; i++)
{
this->jjj[i] = upf.jjj [i];
this->jjj[i] = 0;
}
}
else
{

if (nn == nullptr) {
this->nn = new int[nchi];
assert(this->nn != nullptr);
assert(!this->has_so);
for (int i=0; i<nchi; i++)
{
this->nn[i] = 0;
this->jchi[i] = 0;
}
for (int i=0; i<upf.nbeta; i++)
}

if (jchi == nullptr) {
this->jchi = new double[nchi];
assert(this->jchi != nullptr);
assert(!this->has_so);
for (int i=0; i<nchi; i++)
{
this->jjj[i] = 0;
this->jchi[i] = 0;
}
}

// uspp
if (tvanp)
{
this->nqlc = upf.nqlc;
this->qfuncl.create(nqlc, nbeta * (nbeta + 1) / 2, mesh);
this->qfuncl = upf.qfuncl;
this->qqq.create(nbeta, nbeta);
this->qqq = upf.qqq;
}
}

return;
} // end subroutine set_pseudo_upf


void pseudo::set_pseudo_atom(const Pseudopot_upf &upf)
void pseudo::set_pseudo_atom()
{
ModuleBase::TITLE("pseudo","set_pseudo_atom");

Expand All @@ -199,59 +146,32 @@ void pseudo::set_pseudo_atom(const Pseudopot_upf &upf)
ModuleBase::WARNING_QUIT("pseudo_atom::set_pseudo_atom","PAO rcut<=0.0");
}

chi.create(nchi, mesh);

delete[] r;
r = new double[mesh];
assert(r != 0);
ModuleBase::GlobalFunc::ZEROS(r, mesh);

delete[] rab;
rab = new double[mesh];
assert(rab != 0);
ModuleBase::GlobalFunc::ZEROS(rab, mesh);

delete[] rho_at;
rho_at = new double[mesh];
assert(rho_at != 0);
ModuleBase::GlobalFunc::ZEROS(rho_at,mesh);

delete[] rho_atc;
rho_atc = new double[mesh];
assert(rho_atc != 0);
// chi.create(nchi, mesh);

for (int i = 0;i < nchi;i++)
{
for (int j = 0; j < mesh; j++)
{
chi(i, j) = upf.chi(i, j);
}
if (r == nullptr) {
r = new double[mesh];
assert(r != nullptr);
ModuleBase::GlobalFunc::ZEROS(r, mesh);
}

for (int i = 0;i < mesh;i++)
{
r [i] = upf.r [i];
rab[i] = upf.rab[i];
rho_at [i] = upf.rho_at [i];
if (rab == nullptr) {
rab = new double[mesh];
assert(rab != nullptr);
ModuleBase::GlobalFunc::ZEROS(rab, mesh);
}

// nlcc: non-linear core corrections
// rho_atc: core atomic charge
if (nlcc)
{
for (int i = 0;i < mesh;i++)
{
rho_atc[i] = upf.rho_atc[i];
}
if (rho_at == nullptr) {
rho_at = new double[mesh];
assert(rho_at != nullptr);
ModuleBase::GlobalFunc::ZEROS(rho_at, mesh);
}
else
{
for (int i = 0;i < upf.mesh;i++)
{
rho_atc[i] = 0.0;
}
} // end if

if (rho_atc == nullptr) {
rho_atc = new double[mesh];
assert(rho_atc != nullptr);
assert(!nlcc);
ModuleBase::GlobalFunc::ZEROS(rho_atc, mesh);
}

bool br = false;

Expand Down Expand Up @@ -282,24 +202,18 @@ void pseudo::set_pseudo_atom(const Pseudopot_upf &upf)



void pseudo::set_pseudo_vl(const Pseudopot_upf &upf)
void pseudo::set_pseudo_vl()
{
ModuleBase::TITLE("pseudo","set_pseudo_vl");

assert(mesh>0);//mohan add 2021-05-01

delete[] vloc_at;
vloc_at = new double[mesh];
assert(vloc_at != 0);

if (upf.coulomb_potential)
return;

for (int i = 0;i < mesh;i++)
{
vloc_at[i] = upf.vloc[i];
if (vloc_at == nullptr) {
vloc_at = new double[mesh];
assert(vloc_at != nullptr);
}


return;
}

Expand Down
12 changes: 6 additions & 6 deletions source/module_cell/pseudo.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef PSEUDO_H
#define PSEUDO_H

#include "../module_io/output.h"
#include "read_pp.h"
#include "module_base/global_function.h"
#include "module_io/output.h"

//-----------------------------------------
// read in pseudopotentials
Expand Down Expand Up @@ -75,10 +75,10 @@ class pseudo
ModuleBase::realArray qfuncl; // qfuncl(2*lmax+1,nbeta*(nbeta+1)/2,mesh) Q_{mu,nu}(|r|) function for |r|> r_L
ModuleBase::matrix qqq; // qqq(nbeta,nbeta) q_{mu,nu}

void set_pseudo_h(const Pseudopot_upf& upf);
void set_pseudo_atom(const Pseudopot_upf& upf);
void set_pseudo_vl(const Pseudopot_upf& upf);
void set_pseudo(const Pseudopot_upf& upf);
void set_pseudo_h();
void set_pseudo_atom();
void set_pseudo_vl();
void set_pseudo();

void print_pseudo_h(std::ofstream& ofs);
void print_pseudo_atom(std::ofstream& ofs);
Expand Down
11 changes: 6 additions & 5 deletions source/module_cell/read_cell_pseudopots.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "module_base/parallel_common.h"
#include "module_io/input.h"
#include "unitcell.h"
#include "read_pp.h"

#include <cstring> // Peize Lin fix bug about strcmp 2016-08-02

Expand Down Expand Up @@ -28,17 +29,17 @@ void UnitCell::read_cell_pseudopots(const std::string& pp_dir, std::ofstream& lo
if (GlobalV::MY_RANK == 0)
{
pp_address = pp_dir + this->pseudo_fn[i];
error = upf.init_pseudo_reader(pp_address, this->pseudo_type[i]); // xiaohui add 2013-06-23
error = upf.init_pseudo_reader(pp_address, this->pseudo_type[i], this->atoms[i].ncpp); // xiaohui add 2013-06-23

if (error == 0) // mohan add 2021-04-16
{
if (this->atoms[i].flag_empty_element) // Peize Lin add for bsse 2021.04.07
{
upf.set_empty_element();
upf.set_empty_element(this->atoms[i].ncpp);
}
upf.set_upf_q(); // liuyu add 2023-09-21
upf.set_upf_q(this->atoms[i].ncpp); // liuyu add 2023-09-21
// average pseudopotential if needed
error_ap = upf.average_p(GlobalV::soc_lambda); // added by zhengdy 2020-10-20
error_ap = upf.average_p(GlobalV::soc_lambda, this->atoms[i].ncpp); // added by zhengdy 2020-10-20
}
this->atoms[i].coulomb_potential = upf.coulomb_potential;
}
Expand Down Expand Up @@ -80,7 +81,7 @@ void UnitCell::read_cell_pseudopots(const std::string& pp_dir, std::ofstream& lo

if (GlobalV::MY_RANK == 0)
{
atoms[i].ncpp.set_pseudo(upf);
atoms[i].ncpp.set_pseudo(); // need to refactor, sunliang 20240716

log << "\n Read in pseudopotential file is " << pseudo_fn[i] << std::endl;
ModuleBase::GlobalFunc::OUT(log, "pseudopotential type", atoms[i].ncpp.pp_type);
Expand Down
Loading
Loading