Skip to content

Commit

Permalink
Merge pull request #2920 from camelto2/ecp_local_fix
Browse files Browse the repository at this point in the history
Fix handling of high l-momentum channels in ECP local potential
  • Loading branch information
ye-luo authored Feb 16, 2021
2 parents f0f88d9 + ec7de52 commit 35199b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
8 changes: 2 additions & 6 deletions src/QMCHamiltonians/ECPComponentBuilder.1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ void ECPComponentBuilder::buildLocal(xmlNodePtr cur)
if (grid_local_inp == 0)
{
if (grid_global == 0)
{
APP_ABORT("ECPComponentBuilder::buildLocal Missing grid information. ");
}
myComm->barrier_and_abort("ECPComponentBuilder::buildLocal Missing grid information. ");
grid_local = new LinearGrid<RealType>;
grid_local->set(grid_global->rmin(), grid_global->rmax(), grid_global->size());
}
Expand All @@ -165,9 +163,7 @@ void ECPComponentBuilder::buildLocal(xmlNodePtr cur)
grid_local->set(grid_local_inp->rmin(), grid_local_inp->rmax(), grid_local_inp->size());
}
if (grid_local->GridTag == CUSTOM_1DGRID)
{
APP_ABORT("ECPComponentBuilder::buildLocal Custom grid is used. Need to recast to the linear grid");
}
myComm->barrier_and_abort("ECPComponentBuilder::buildLocal Custom grid is used. Need to recast to the linear grid");
else
{
std::vector<RealType> v;
Expand Down
41 changes: 28 additions & 13 deletions src/QMCHamiltonians/ECPComponentBuilder.2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ void ECPComponentBuilder::buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPt
{
app_log() << " ECPComponentBuilder::buildSemiLocalAndLocal " << std::endl;
if (grid_global == 0)
{
app_error() << " Global grid needs to be defined." << std::endl;
APP_ABORT("ECPComponentBuilder::buildSemiLocalAndLocal");
}
myComm->barrier_and_abort("ECPComponentBuilder::buildSemiLocalAndLocal. Global grid needs to be defined.\n");
// There should only be one semilocal tag
if (semiPtr.size() > 1)
{
app_error() << " We have more than one semilocal sections in the PP xml file." << std::endl;
APP_ABORT("ECPComponentBuilder::buildSemiLocalAndLocal");
std::stringstream err_msg;
err_msg << "ECPComponentBuilder::buildSemiLocalAndLocal. "
<< "We have more than one semilocal sections in the PP xml file";
myComm->barrier_and_abort(err_msg.str());
}
RealType rmax = -1;
//attributes: initailize by defaults
Expand Down Expand Up @@ -78,8 +77,10 @@ void ECPComponentBuilder::buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPt
is_r_times_V = false;
else
{
app_error() << "Unrecognized format \"" << format << "\" in PP file." << std::endl;
APP_ABORT("ECPComponentBuilder::buildSemiLocalAndLocal");
std::stringstream err_msg;
err_msg << "ECPComponentBuilder::buildSemiLocalAndLocal."
<< "Unrecognized format \"" << format << "\" in PP file.\n";
myComm->barrier_and_abort(err_msg.str());
}
// We cannot construct the potentials as we construct them since
// we may not know which one is local yet.
Expand All @@ -103,7 +104,14 @@ void ECPComponentBuilder::buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPt
aAttrib.add(lstr, "l");
aAttrib.add(rc, "cutoff");
aAttrib.put(cur_vps);
rmax = std::max(rmax, rc);
rmax = std::max(rmax, rc);
if (angMon.find(lstr) == angMon.end())
{
std::stringstream err_msg;
err_msg << "ECPComponentBuilder::buildSemiLocalAndLocal. "
<< "Requested angular momentum " << lstr << " not available.\n";
myComm->barrier_and_abort(err_msg.str());
}
int l = angMon[lstr];
angList.push_back(l);
vpsPtr.push_back(cur_vps);
Expand All @@ -117,7 +125,14 @@ void ECPComponentBuilder::buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPt
aAttrib.add(lstr, "l");
aAttrib.add(rc, "cutoff");
aAttrib.put(cur_vps);
rmax = std::max(rmax, rc);
rmax = std::max(rmax, rc);
if (angMon.find(lstr) == angMon.end())
{
std::stringstream err_msg;
err_msg << "ECPComponentBuilder::buildSemiLocalAndLocal. "
<< "Requested angular momentum " << lstr << " not available for SO.\n";
myComm->barrier_and_abort(err_msg.str());
}
int l = angMon[lstr];
angListSO.push_back(l);
vpsoPtr.push_back(cur_vps);
Expand All @@ -140,7 +155,7 @@ void ECPComponentBuilder::buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPt
std::string outstring("");
outstring = ssout.str();

APP_ABORT(outstring.c_str());
myComm->barrier_and_abort(outstring.c_str());
}
int npts = grid_global->size();
Matrix<mRealType> vnn(angList.size(), npts);
Expand Down Expand Up @@ -299,7 +314,7 @@ bool ECPComponentBuilder::parseCasino(const std::string& fname, xmlNodePtr cur)
if (!fin)
{
app_error() << "Could not open file " << fname << std::endl;
APP_ABORT("ECPComponentBuilder::parseCasino");
myComm->barrier_and_abort("ECPComponentBuilder::parseCasino");
}
if (!pp_nonloc)
pp_nonloc = std::make_unique<NonLocalECPComponent>();
Expand Down Expand Up @@ -419,7 +434,7 @@ void ECPComponentBuilder::doBreakUp(const std::vector<int>& angList,
{
app_error() << "The local channel is not specified in the pseudopotential file.\n"
<< "Please add \'l-local=\"n\"\' attribute the semilocal section of the fsatom XML file.\n";
APP_ABORT("ECPComponentBuilder::doBreakUp");
myComm->barrier_and_abort("ECPComponentBuilder::doBreakUp");
// Llocal = Lmax;
}
//find the index of local
Expand Down
20 changes: 12 additions & 8 deletions src/QMCHamiltonians/ECPComponentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ ECPComponentBuilder::ECPComponentBuilder(const std::string& aname, Communicate*
angMon["d"] = 2;
angMon["f"] = 3;
angMon["g"] = 4;
angMon["h"] = 5;
angMon["i"] = 6;
angMon["j"] = 7;
angMon["k"] = 8;
angMon["0"] = 0;
angMon["1"] = 1;
angMon["2"] = 2;
angMon["3"] = 3;
angMon["4"] = 4;
angMon["5"] = 5;
angMon["6"] = 6;
angMon["7"] = 7;
angMon["8"] = 8;
}

bool ECPComponentBuilder::parse(const std::string& fname, xmlNodePtr cur)
Expand Down Expand Up @@ -129,29 +137,25 @@ bool ECPComponentBuilder::read_pp_file(const std::string& fname)
ReadFileBuffer buf(myComm);
bool okay = buf.open_file(fname);
if (!okay)
{
APP_ABORT("ECPComponentBuilder::read_pp_file Missing PP file " + fname + "\n");
}
myComm->barrier_and_abort("ECPComponentBuilder::read_pp_file Missing PP file " + fname + "\n");

okay = buf.read_contents();
if (!okay)
{
APP_ABORT("ECPComponentBuilder::read_pp_file Unable to read PP file " + fname + "\n");
}
myComm->barrier_and_abort("ECPComponentBuilder::read_pp_file Unable to read PP file " + fname + "\n");

xmlDocPtr m_doc = xmlReadMemory(buf.contents(), buf.length, NULL, NULL, 0);

if (m_doc == NULL)
{
xmlFreeDoc(m_doc);
APP_ABORT("ECPComponentBuilder::read_pp_file xml file " + fname + " is invalid");
myComm->barrier_and_abort("ECPComponentBuilder::read_pp_file xml file " + fname + " is invalid");
}
// Check the document is of the right kind
xmlNodePtr cur = xmlDocGetRootElement(m_doc);
if (cur == NULL)
{
xmlFreeDoc(m_doc);
APP_ABORT("Empty document");
myComm->barrier_and_abort("Empty document");
}
bool success = put(cur);
xmlFreeDoc(m_doc);
Expand Down

0 comments on commit 35199b8

Please sign in to comment.