From dc39dbaba7c7edf31a5d69f9a75becb2ad2f2fda Mon Sep 17 00:00:00 2001 From: Paul Kent Date: Tue, 28 Sep 2021 21:55:32 -0400 Subject: [PATCH 1/6] Try public in cmake --- src/QMCTools/ppconvert/src/CMakeLists.txt | 6 +++--- src/QMCTools/ppconvert/src/common/CMakeLists.txt | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/QMCTools/ppconvert/src/CMakeLists.txt b/src/QMCTools/ppconvert/src/CMakeLists.txt index d0a5f06d92..feb4e2d2c8 100644 --- a/src/QMCTools/ppconvert/src/CMakeLists.txt +++ b/src/QMCTools/ppconvert/src/CMakeLists.txt @@ -4,8 +4,8 @@ add_subdirectory(common) target_sources( ppconvert - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/CubicSpline.cc" "${CMAKE_CURRENT_SOURCE_DIR}/ParseCommand.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/XMLWriterClass2.cc" "${CMAKE_CURRENT_SOURCE_DIR}/NLPPClass.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/ParserClass.cc") + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/CubicSpline.cc" "${CMAKE_CURRENT_SOURCE_DIR}/ParseCommand.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/XMLWriterClass2.cc" "${CMAKE_CURRENT_SOURCE_DIR}/NLPPClass.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/ParserClass.cc") target_link_libraries(ppconvert common platform_LA) diff --git a/src/QMCTools/ppconvert/src/common/CMakeLists.txt b/src/QMCTools/ppconvert/src/common/CMakeLists.txt index 9f9248aba4..ac46a85225 100644 --- a/src/QMCTools/ppconvert/src/common/CMakeLists.txt +++ b/src/QMCTools/ppconvert/src/common/CMakeLists.txt @@ -2,7 +2,7 @@ add_library(common EXCLUDE_FROM_ALL "") target_sources( common - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/GKIntegration.cc + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/GKIntegration.cc ${CMAKE_CURRENT_SOURCE_DIR}/CoulombPot.cc ${CMAKE_CURRENT_SOURCE_DIR}/NLPP.cc ${CMAKE_CURRENT_SOURCE_DIR}/DFTAtom.cc @@ -19,6 +19,3 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/PotentialBase.cc ${CMAKE_CURRENT_SOURCE_DIR}/IOASCII.cc ${CMAKE_CURRENT_SOURCE_DIR}/Functionals.cc) - -target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/blitz - ${CMAKE_CURRENT_SOURCE_DIR}/blitz/array) From 3ba75e9abdfcac37de6370199e03a70201f86c61 Mon Sep 17 00:00:00 2001 From: Paul Kent Date: Tue, 28 Sep 2021 22:04:05 -0400 Subject: [PATCH 2/6] Test label --- src/QMCTools/ppconvert/test/Oxygen/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/QMCTools/ppconvert/test/Oxygen/CMakeLists.txt b/src/QMCTools/ppconvert/test/Oxygen/CMakeLists.txt index 1dd7d86ee8..9dd6b78b21 100644 --- a/src/QMCTools/ppconvert/test/Oxygen/CMakeLists.txt +++ b/src/QMCTools/ppconvert/test/Oxygen/CMakeLists.txt @@ -7,8 +7,7 @@ add_test( NAME ${THISTESTNAME} COMMAND bash ${CMAKE_CURRENT_BINARY_DIR}/O_test.sh $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -# Add label when asan clean -#SET_TESTS_PROPERTIES(${THISTESTNAME} PROPERTIES LABELS "deterministic") +SET_TESTS_PROPERTIES(${THISTESTNAME} PROPERTIES LABELS "deterministic") find_program(HAVE_NUMDIFF numdiff) if(HAVE_NUMDIFF) @@ -17,7 +16,6 @@ if(HAVE_NUMDIFF) COMMAND numdiff -a 0.001 ${CMAKE_CURRENT_BINARY_DIR}/O.BFD.xml ${PROJECT_SOURCE_DIR}/../../tests/solids/monoO_1x1x1_pp/O.BFD.xml WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(ppconvert_o_diff PROPERTIES DEPENDS ppconvert_runs) - # Add label when asan clean - # LABELS "deterministic") + set_tests_properties(ppconvert_o_diff PROPERTIES DEPENDS ppconvert_runs + LABELS "deterministic") endif(HAVE_NUMDIFF) From 216d9dd7594628dfe1bf11c0ce08877c3a7191d6 Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Thu, 30 Sep 2021 10:47:27 -0400 Subject: [PATCH 3/6] Address leaks in XMLWriterClass Use std::shared_ptr to allow for deep copy constructors --- src/QMCTools/ppconvert/src/XMLWriterClass2.cc | 139 ++++++++---------- src/QMCTools/ppconvert/src/XMLWriterClass2.h | 11 +- 2 files changed, 67 insertions(+), 83 deletions(-) diff --git a/src/QMCTools/ppconvert/src/XMLWriterClass2.cc b/src/QMCTools/ppconvert/src/XMLWriterClass2.cc index 06aefd60ce..e7d82c322c 100644 --- a/src/QMCTools/ppconvert/src/XMLWriterClass2.cc +++ b/src/QMCTools/ppconvert/src/XMLWriterClass2.cc @@ -9,9 +9,6 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - - #include "XMLWriterClass2.h" @@ -21,19 +18,18 @@ XMLAttribute::XMLAttribute(std::string name, std::string content) { - Name = name; + Name = name; Content = content; } -XMLAttribute::XMLAttribute (const XMLAttribute &attr) -{ - Name = attr.Name; - Content = attr.Content; +XMLAttribute::XMLAttribute(const XMLAttribute& attr) +{ + Name = attr.Name; + Content = attr.Content; } -void -XMLAttribute::Write(std::string &out) +void XMLAttribute::Write(std::string& out) { std::stringstream str; str << Name << "=\"" << Content << "\""; @@ -41,7 +37,7 @@ XMLAttribute::Write(std::string &out) } -XMLElement::XMLElement(const XMLElement &elem) +XMLElement::XMLElement(const XMLElement& elem) { Attributes = elem.Attributes; Children = elem.Children; @@ -50,27 +46,27 @@ XMLElement::XMLElement(const XMLElement &elem) Level = elem.Level; } -void -XMLElement::Indent(std::ostream &out) +void XMLElement::Indent(std::ostream& out) { - for (int i=0; iWrite(str); - if (lineCount + str.size() + 2*Level > 73) { + if (lineCount + str.size() + 2 * Level > 73) + { out << "\n"; - Indent (out); + Indent(out); out << " "; lineCount = 1; } @@ -78,155 +74,142 @@ XMLElement::Write(std::ostream &out) out << str; } int numLines = 0; - for (int i=0; i\n"; - else { + else + { out << ">"; if (numLines > 0 || Children.size() > 0) out << "\n"; out << Content; - for (int i=0; iWrite(out); - if (numLines > 0 || Children.size()>0) + if (numLines > 0 || Children.size() > 0) Indent(out); out << "\n"; } } - -void -XMLElement::AddContent(std::vector &data) + +void XMLElement::AddContent(std::vector& data) { std::stringstream str; str.setf(std::ios_base::scientific, std::ios_base::floatfield); str << std::setprecision(14); - for (int i=0; i\n"; + + Out << "\n"; return true; } -bool -XMLWriterClass::EndDocument() +bool XMLWriterClass::EndDocument() { - if (Elements.size() <=0) + if (Elements.size() <= 0) return false; Elements[0]->Write(Out); return true; } -bool -XMLWriterClass::StartElement(std::string name) +bool XMLWriterClass::StartElement(std::string name) { int level = Elements.size(); - - XMLElement* elem = new XMLElement(name, level); + + auto elem = std::make_shared(name, level); if (level > 0) - Elements.back()->AddElement (elem); + Elements.back()->AddElement(elem); Elements.push_back(elem); return true; } -bool -XMLWriterClass::EndElement() +bool XMLWriterClass::EndElement() { if (Elements.size() > 1) Elements.pop_back(); return true; } -bool -XMLWriterClass::FullEndElement() +bool XMLWriterClass::FullEndElement() { Elements.pop_back(); return true; } -bool -XMLWriterClass::WriteAttribute (std::string name, std::string content) +bool XMLWriterClass::WriteAttribute(std::string name, std::string content) { - XMLAttribute *attr = new XMLAttribute (name, content); - Elements.back()->AddAttribute (attr); + auto attr = std::make_shared(name, content); + Elements.back()->AddAttribute(attr); return true; } -bool -XMLWriterClass::WriteAttribute (std::string name, double val, bool scientific) +bool XMLWriterClass::WriteAttribute(std::string name, double val, bool scientific) { std::stringstream content; - if (scientific) { + if (scientific) + { content.setf(std::ios_base::scientific, std::ios_base::floatfield); content << std::setprecision(14); } content << val; - XMLAttribute *attr = new XMLAttribute (name, content.str()); - Elements.back()->AddAttribute (attr); + auto attr = std::make_shared(name, content.str()); + Elements.back()->AddAttribute(attr); return true; } -bool -XMLWriterClass::WriteAttribute (std::string name, int val) +bool XMLWriterClass::WriteAttribute(std::string name, int val) { std::stringstream content; content << val; - XMLAttribute *attr = new XMLAttribute (name, content.str()); - Elements.back()->AddAttribute (attr); + auto attr = std::make_shared(name, content.str()); + Elements.back()->AddAttribute(attr); return true; } -bool -XMLWriterClass::WriteData(std::vector data) +bool XMLWriterClass::WriteData(std::vector data) { - Elements.back()->AddContent (data); + Elements.back()->AddContent(data); return true; } -bool -XMLWriterClass::WriteData(std::string data) +bool XMLWriterClass::WriteData(std::string data) { - Elements.back()->AddContent (data); + Elements.back()->AddContent(data); return true; } -bool -XMLWriterClass::WriteElement (std::string name, std::vector data) +bool XMLWriterClass::WriteElement(std::string name, std::vector data) { int level = Elements.size(); - XMLElement *elem = new XMLElement (name, level); - elem->AddContent (data); + auto elem = std::make_shared(name, level); + elem->AddContent(data); if (level > 0) - Elements.back()->AddElement (elem); + Elements.back()->AddElement(elem); return true; } - diff --git a/src/QMCTools/ppconvert/src/XMLWriterClass2.h b/src/QMCTools/ppconvert/src/XMLWriterClass2.h index 23f66ea757..5a7311f3db 100644 --- a/src/QMCTools/ppconvert/src/XMLWriterClass2.h +++ b/src/QMCTools/ppconvert/src/XMLWriterClass2.h @@ -19,6 +19,7 @@ #include #include #include +#include // std::shared_ptr class XMLAttribute @@ -38,8 +39,8 @@ class XMLAttribute class XMLElement { - std::vector Attributes; - std::vector Children; + std::vector> Attributes; + std::vector> Children; std::string Name, Content; int Level; void Indent(std::ostream& out); @@ -49,9 +50,9 @@ class XMLElement inline int GetLevel() { return Level; } - void AddElement(XMLElement* elem) { Children.push_back(elem); } + void AddElement(std::shared_ptr& elem) { Children.push_back(elem); } - void AddAttribute(XMLAttribute* attr) { Attributes.push_back(attr); } + void AddAttribute(std::shared_ptr& attr) { Attributes.push_back(attr); } void AddContent(std::string content) { Content += content; } @@ -70,7 +71,7 @@ class XMLElement class XMLWriterClass { private: - std::vector Elements; + std::vector> Elements; void Write(); std::ofstream Out; From 9b2e2fba4883be0427ac38e70a71eafa583f8cf6 Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Thu, 30 Sep 2021 11:47:07 -0400 Subject: [PATCH 4/6] Fix leaks associated with Grid raw pointer Use std::shared_ptr to enable copy constructors --- src/QMCTools/ppconvert/src/NLPPClass.cc | 2565 +++++++++-------- src/QMCTools/ppconvert/src/common/AtomBase.h | 8 +- .../ppconvert/src/common/CubicSplineCommon.h | 18 +- src/QMCTools/ppconvert/src/common/DFTAtom.cc | 170 +- src/QMCTools/ppconvert/src/common/DFTAtom.h | 2 +- .../ppconvert/src/common/GeneralPot.cc | 48 +- .../ppconvert/src/common/GeneralPot.h | 4 +- src/QMCTools/ppconvert/src/common/Grid.h | 20 +- src/QMCTools/ppconvert/src/common/NLPP.cc | 391 ++- src/QMCTools/ppconvert/src/common/NLPP.h | 4 +- .../ppconvert/src/common/PotentialBase.h | 1 + src/QMCTools/ppconvert/src/common/RadialWF.cc | 426 ++- src/QMCTools/ppconvert/src/common/RadialWF.h | 4 +- .../ppconvert/src/common/SplinePot.cc | 45 +- 14 files changed, 1896 insertions(+), 1810 deletions(-) diff --git a/src/QMCTools/ppconvert/src/NLPPClass.cc b/src/QMCTools/ppconvert/src/NLPPClass.cc index 467fb5b6ba..1504f22856 100644 --- a/src/QMCTools/ppconvert/src/NLPPClass.cc +++ b/src/QMCTools/ppconvert/src/NLPPClass.cc @@ -11,9 +11,6 @@ ////////////////////////////////////////////////////////////////////////////////////// - - - #include "NLPPClass.h" #include "XMLWriterClass2.h" #include "ParserClass.h" @@ -23,17 +20,15 @@ #include #include -void -ChannelPotentialClass::WriteChannelLog (XMLWriterClass &writer, - bool writeVl) +void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl) { std::string channels[] = {"s", "p", "d", "f", "g", "h", "i", "j"}; // Use a logarithmic grid: // r(i) = a*(exp(b*i) - 1) const int numPoints = 2001; - double end = Vl.grid.End(); - double step = 0.00625; - double scale = end/(expm1(step*(numPoints-1))); + double end = Vl.grid.End(); + double step = 0.00625; + double scale = end / (expm1(step * (numPoints - 1))); if (writeVl) writer.StartElement("vps"); else @@ -41,7 +36,8 @@ ChannelPotentialClass::WriteChannelLog (XMLWriterClass &writer, writer.WriteAttribute("principal-n", n_principal); writer.WriteAttribute("l", channels[l]); writer.WriteAttribute("spin", -1); - if (writeVl) { + if (writeVl) + { writer.WriteAttribute("cutoff", Cutoff); writer.WriteAttribute("occupation", Occupation); } @@ -54,14 +50,17 @@ ChannelPotentialClass::WriteChannelLog (XMLWriterClass &writer, writer.WriteAttribute("npts", numPoints); writer.EndElement(); // "grid" std::vector data; - for (int i=0; i data; - for (int i=0; i vl(numPoints); - for (int ir=0; ir ul(numPoints); - for (int ir=0; ir input/default value)\n0 0\n"); - fprintf (fout, "Number of grid points\n%d\n", - numPoints); - fprintf (fout, "R(i) in atomic units\n"); - for (int i=0; i input/default value)\n0 0\n"); + fprintf(fout, "Number of grid points\n%d\n", numPoints); + fprintf(fout, "R(i) in atomic units\n"); + for (int i = 0; i < numPoints; i++) + { + double r = (double)i / (double)(numPoints - 1) * rMax; + fprintf(fout, " %22.16e\n", r); } - for (int l=0; l& data, int indent) +void PseudoClass::Write4Block(FILE* fout, std::vector& data, int indent) { int N = data.size(); - for (int i=0; i\n"); - fprintf (fout, "Generated using ppconvert\n"); + fprintf(fout, "\n"); + fprintf(fout, "Generated using ppconvert\n"); // Get date - time_t now = time(NULL); - struct tm <ime = *(localtime (&now)); + time_t now = time(NULL); + struct tm& ltime = *(localtime(&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((mon<10) ? "0" : "") << mon << "/"; - date << ((day<10) ? "0" : "") << day << "/"; - date << ((year<10) ? "0" : "") << year; - fprintf (fout, "Author: Kenneth P. Esler Generation date: %s\n", - date.str().c_str()); + date << ((mon < 10) ? "0" : "") << mon << "/"; + date << ((day < 10) ? "0" : "") << day << "/"; + date << ((year < 10) ? "0" : "") << year; + fprintf(fout, "Author: Kenneth P. Esler Generation date: %s\n", date.str().c_str()); - fprintf (fout, "\n"); + fprintf(fout, "\n"); // Write PP_HEADER section - fprintf (fout, "\n"); - fprintf (fout, " 0 Version Number\n"); - fprintf (fout, " %2s Element\n", - ZToSymbolMap[AtomicNumber].c_str()); - fprintf (fout, " NC Norm - Conserving pseudopotential\n"); - fprintf (fout, " F Nonlinear Core Correction\n"); + fprintf(fout, "\n"); + fprintf(fout, " 0 Version Number\n"); + fprintf(fout, " %2s Element\n", ZToSymbolMap[AtomicNumber].c_str()); + fprintf(fout, " NC Norm - Conserving pseudopotential\n"); + fprintf(fout, " F Nonlinear Core Correction\n"); std::string F_EX, F_CORR, F_XC_GRAD, F_CORR_GRAD; - F_EX = "SLA"; - F_CORR = "PW"; - F_XC_GRAD = "PBE"; + F_EX = "SLA"; + F_CORR = "PW"; + F_XC_GRAD = "PBE"; F_CORR_GRAD = "PBE"; - fprintf (fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", - F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), F_CORR_GRAD.c_str()); - fprintf (fout, " %1.10f Z valence\n", - PseudoCharge); - fprintf (fout, " %1.10f Total energy\n", TotalEnergy); - fprintf (fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", - 0.0, 0.0); - fprintf (fout, " %ld Max angular momentum component\n", - ChannelPotentials.size()-1); - fprintf (fout, " %4d Number of points in mesh\n", - N); - fprintf (fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), ChannelPotentials.size()-1); - fprintf (fout, " WaveFunctions nl l occ \n"); - for (int l=0; l\n"); + fprintf(fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), + F_CORR_GRAD.c_str()); + fprintf(fout, " %1.10f Z valence\n", PseudoCharge); + fprintf(fout, " %1.10f Total energy\n", TotalEnergy); + fprintf(fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", 0.0, 0.0); + fprintf(fout, " %ld Max angular momentum component\n", ChannelPotentials.size() - 1); + fprintf(fout, " %4d Number of points in mesh\n", N); + fprintf(fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), + ChannelPotentials.size() - 1); + fprintf(fout, " WaveFunctions nl l occ \n"); + for (int l = 0; l < ChannelPotentials.size(); l++) + fprintf(fout, " %d%s %d %1.4f\n", ChannelPotentials[l].n_principal, ChannelMap[l].c_str(), + ChannelPotentials[l].l, ChannelPotentials[l].Occupation); + + fprintf(fout, "\n"); // Write PP_MESH section - fprintf (fout, "\n"); - fprintf (fout, " \n"); - Write4Block (fout, PotentialGrid.Points()); - fprintf (fout, " \n"); - fprintf (fout, " \n"); + fprintf(fout, "\n"); + fprintf(fout, " \n"); + Write4Block(fout, PotentialGrid.Points()); + fprintf(fout, " \n"); + fprintf(fout, " \n"); std::vector dr(N); - for (int i=1; i<(N-1); i++) - dr[i] = 0.5*(PotentialGrid[i+1]-PotentialGrid[i-1]); - dr[0] = 2.0*dr[ 1 ]-dr[ 2 ]; - dr[N-1] = 2.0*dr[N-2]-dr[N-3]; + for (int i = 1; i < (N - 1); i++) + dr[i] = 0.5 * (PotentialGrid[i + 1] - PotentialGrid[i - 1]); + dr[0] = 2.0 * dr[1] - dr[2]; + dr[N - 1] = 2.0 * dr[N - 2] - dr[N - 3]; - Write4Block (fout, dr); - fprintf (fout, " \n"); - fprintf (fout, "\n"); + Write4Block(fout, dr); + fprintf(fout, " \n"); + fprintf(fout, "\n"); // Write PP_LOCAL section - fprintf (fout, "\n"); + fprintf(fout, "\n"); std::vector vloc(N); - for (int i=0; i\n"); + Write4Block(fout, vloc); + fprintf(fout, "\n"); // Write the nonlocal section - fprintf (fout, "\n"); + fprintf(fout, "\n"); int betaNum = 1; - for (int l=0; l beta(N); - for (int i=0; i\n"); - fprintf (fout, " %d %d Beta L\n", betaNum, l); - fprintf (fout, " %d \n", N); - Write4Block (fout, beta, 4); - fprintf (fout, " \n"); + beta[0] = 2.0 * ChannelPotentials[l].ul(0.0) * + (ChannelPotentials[l].Vlr(1.0e-7) - ChannelPotentials[LocalChannel].Vlr(1.0e-7)) / 1.0e-7; + // beta[0] = 2.0*ChannelPotentials[l].ul(0.0)* + // (ChannelPotentials[l].Vl(1.0e-7)-ChannelPotentials[LocalChannel].Vl(1.0e-7)); + fprintf(fout, " \n"); + fprintf(fout, " %d %d Beta L\n", betaNum, l); + fprintf(fout, " %d \n", N); + Write4Block(fout, beta, 4); + fprintf(fout, " \n"); betaNum++; } // Write D_ij matrix - fprintf (fout, " \n"); - fprintf (fout, " %ld Number of nonzero Dij\n", - ChannelPotentials.size()-1); + fprintf(fout, " \n"); + fprintf(fout, " %ld Number of nonzero Dij\n", ChannelPotentials.size() - 1); betaNum = 1; // Compute D_ij matrix. In our case, with single projectors, D_ij // is diagonal. The elements are // D_ll = 1.0/ // We will numerically integrate with Simpson's rule - for (int l=0; l\n"); - fprintf (fout, "\n"); + fprintf(fout, " \n"); + fprintf(fout, "\n"); // Write PP_PSWFC section - fprintf (fout, "\n"); - for (int l=0; l\n"); + for (int l = 0; l < ChannelPotentials.size(); l++) + { + ChannelPotentialClass& pot = ChannelPotentials[l]; + fprintf(fout, "%d%s %d %6.4f Wavefunction\n", pot.n_principal, ChannelMap[l].c_str(), l, + pot.Occupation); std::vector u(N); - for (int i=0; i\n"); + fprintf(fout, "\n"); // Write PP_RHOATOM section - fprintf (fout, "\n"); + fprintf(fout, "\n"); std::vector rho_at(N); - for (int i=0; i\n"); + fprintf(fout, "\n"); // Close the file - fclose (fout); + fclose(fout); } -void -PseudoClass::WriteFHI (std::string fileName) +void PseudoClass::WriteFHI(std::string fileName) { - const double amesh = 1.013084867359809; + const double amesh = 1.013084867359809; const int numPoints = 1118; - FILE *fout = fopen (fileName.c_str(), "w"); - assert (fout != NULL); + FILE* fout = fopen(fileName.c_str(), "w"); + assert(fout != NULL); // Write ABINIT header - fprintf (fout, "Written by ppconvert: %s psuedopotential\n", - ZToSymbolMap[AtomicNumber].c_str()); - time_t now = time(NULL); - struct tm <ime = *(localtime (&now)); + fprintf(fout, "Written by ppconvert: %s psuedopotential\n", ZToSymbolMap[AtomicNumber].c_str()); + time_t now = time(NULL); + struct tm& ltime = *(localtime(&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((year<10) ? "0" : "") << year; - date << ((mon<10) ? "0" : "") << mon; - date << ((day<10) ? "0" : "") << day; - - fprintf (fout, "%9.5f %9.5f %s" - " zatom, zion, pspdat\n", (double)AtomicNumber, - PseudoCharge, date.str().c_str()); - - fprintf (fout, " 6 7 %ld %d %d 0.0000 " - "pspcod,pspxc,lmax,lloc,mmax,r2well\n", - ChannelPotentials.size()-1, LocalChannel, numPoints); - fprintf (fout, " 0.00000 0.00000 0.00000 " - "rchrg,fchrg,qchrg\n"); - fprintf (fout, "5 --- reserved for future features\n" - "6 --- reserved for future features\n" - "7 --- Here follows the cpi file in the fhi98pp format -\n"); + date << ((year < 10) ? "0" : "") << year; + date << ((mon < 10) ? "0" : "") << mon; + date << ((day < 10) ? "0" : "") << day; + + fprintf(fout, + "%9.5f %9.5f %s" + " zatom, zion, pspdat\n", + (double)AtomicNumber, PseudoCharge, date.str().c_str()); + + fprintf(fout, + " 6 7 %ld %d %d 0.0000 " + "pspcod,pspxc,lmax,lloc,mmax,r2well\n", + ChannelPotentials.size() - 1, LocalChannel, numPoints); + fprintf(fout, + " 0.00000 0.00000 0.00000 " + "rchrg,fchrg,qchrg\n"); + fprintf(fout, + "5 --- reserved for future features\n" + "6 --- reserved for future features\n" + "7 --- Here follows the cpi file in the fhi98pp format -\n"); // Write FHI file proper - fprintf (fout, "%d %ld\n", (int)round(PseudoCharge), - ChannelPotentials.size()); - for (int i=0; i<10; i++) - fprintf (fout, "0.0 0.0 0.0\n"); - - for (int l=0; l= ChannelPotentials[l].Vl.grid.End()) - Vl = -1.0*PseudoCharge/r; + Vl = -1.0 * PseudoCharge / r; else - Vl = ChannelPotentials[l].Vl(r); // /r; + Vl = ChannelPotentials[l].Vl(r); // /r; double Vlold = Vl; - Vl = ChannelPotentials[l].Vlr(r)/r; + Vl = ChannelPotentials[l].Vlr(r) / r; if (i == 0) - Vl = ChannelPotentials[l].Vl(0.0); + Vl = ChannelPotentials[l].Vl(0.0); // fprintf (stderr, "r = %1.10f Interp diff = %1.8e\n", r, Vl-Vlold); - fprintf (fout, "%23.16e ", Vl); - if ((i%3)==2) - fprintf (fout, "\n"); + fprintf(fout, "%23.16e ", Vl); + if ((i % 3) == 2) + fprintf(fout, "\n"); } } // Now write out radial wave functions - for (int l=0; l= rend) { - int i=ChannelPotentials[l].ul.grid.NumPoints(); - while (fabs(ChannelPotentials[l].ul(i)) == 0.0) i--; - double r2 = ChannelPotentials[l].ul.grid[i]; - double r1 = ChannelPotentials[l].ul.grid[i-10]; - double u2 = ChannelPotentials[l].ul(i); - double u1 = ChannelPotentials[l].ul(i-10); - double alpha = log(u1/u2)/(r2-r1); - // rend = min (rend, 60.0); - // double uend = ChannelPotentials[l].ul(rend); - // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); - //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; - // ul = uend * exp(-alpha*(r-rend)); - ul = u2 * exp(-alpha*(r - r2)); - } - else - ul= ChannelPotentials[l].ul(r); - fprintf (fout, "%23.16e ", ul); - if ((i%3)==2) - fprintf (fout, "\n"); + for (int l = 0; l < ChannelPotentials.size(); l++) + { + fprintf(fout, "%d = l for CASINO wave function\n", l); + for (int i = 0; i < mmax; i++) + { + double x = (double)i / (double)(mmax - 1); + x += 0.01; + double r = 100.0 * x * x * x * x * x - 1.0e-8; + double ul; + double rend = ChannelPotentials[l].ul.grid.End(); + if (r >= rend) + { + int i = ChannelPotentials[l].ul.grid.NumPoints(); + while (fabs(ChannelPotentials[l].ul(i)) == 0.0) + i--; + double r2 = ChannelPotentials[l].ul.grid[i]; + double r1 = ChannelPotentials[l].ul.grid[i - 10]; + double u2 = ChannelPotentials[l].ul(i); + double u1 = ChannelPotentials[l].ul(i - 10); + double alpha = log(u1 / u2) / (r2 - r1); + // rend = min (rend, 60.0); + // double uend = ChannelPotentials[l].ul(rend); + // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); + //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; + // ul = uend * exp(-alpha*(r-rend)); + ul = u2 * exp(-alpha * (r - r2)); } + else + ul = ChannelPotentials[l].ul(r); + fprintf(fout, "%23.16e ", ul); + if ((i % 3) == 2) + fprintf(fout, "\n"); + } } - fclose (fout); + fclose(fout); } -void -PseudoClass::WriteASCII() +void PseudoClass::WriteASCII() { - FILE *fout = fopen ("pp.dat", "w"); - for (int i=1; i gridPoints, Vlocal, Vlocalr; - FILE *fout = fopen ("Vlocal.dat", "w"); - for (double r=1.0e-8; r<150.0; r+=0.01) { - gridPoints.push_back (r); - double Vloc = (c0/r)*(expm1(-exp0*r*r)) + - c1*r*exp(-exp1*r*r) + - c2*exp(-exp2*r*r); - double Vlocr = (c0)*(expm1(-exp0*r*r)) + - c1*r*r*exp(-exp1*r*r) + - c2*r*exp(-exp2*r*r); + FILE* fout = fopen("Vlocal.dat", "w"); + for (double r = 1.0e-8; r < 150.0; r += 0.01) + { + gridPoints.push_back(r); + double Vloc = (c0 / r) * (expm1(-exp0 * r * r)) + c1 * r * exp(-exp1 * r * r) + c2 * exp(-exp2 * r * r); + double Vlocr = (c0) * (expm1(-exp0 * r * r)) + c1 * r * r * exp(-exp1 * r * r) + c2 * r * exp(-exp2 * r * r); Vlocal.push_back(Vloc); Vlocalr.push_back(Vlocr); - fprintf (fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); + fprintf(fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); } - fclose (fout); + fclose(fout); int local = numProjectors; - if (LocalChannel<0) LocalChannel = local; - PotentialGrid.Init (gridPoints); + if (LocalChannel < 0) + LocalChannel = local; + PotentialGrid.Init(gridPoints); ChannelPotentials[local].Vl.Init(PotentialGrid, Vlocal); ChannelPotentials[local].Vlr.Init(PotentialGrid, Vlocalr); ChannelPotentials[local].l = local; // Now read nonlocal component - assert (parser.FindToken ("Non-local component:")); - assert (parser.FindToken ("Proj.")); - for (int l=0; l Vl(gridPoints.size()), Vlr(gridPoints.size()); - for (int i=0; i 1.0e-10) { + assert(parser.ReadDouble(chrg)); + if (fabs(chrg - PseudoCharge) > 1.0e-10) + { std::cerr << "PseudoCharge = " << PseudoCharge << std::endl; std::cerr << "chrg = " << chrg << std::endl; } // Read number of channels and resize int numChannels; - assert (parser.ReadInt(numChannels)); + assert(parser.ReadInt(numChannels)); ChannelPotentials.resize(numChannels); // Skip the next 10 lines - for (int i=0; i<11; i++) - assert (parser.FindToken("\n")); + for (int i = 0; i < 11; i++) + assert(parser.FindToken("\n")); // Read the number of grid points - for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), - Vlr(numPoints); - for (int m=0; m points(numPoints), ul(numPoints), Vl(numPoints), Vlr(numPoints); + for (int m = 0; m < numPoints; m++) + { int mtest; - assert (parser.ReadInt(mtest)); - assert (mtest == (m+1)); - assert (parser.ReadDouble(points[m])); - assert (parser.ReadDouble(ul[m])); - assert (parser.ReadDouble(Vl[m])); - Vlr[m] = Vl[m]*points[m]; + assert(parser.ReadInt(mtest)); + assert(mtest == (m + 1)); + assert(parser.ReadDouble(points[m])); + assert(parser.ReadDouble(ul[m])); + assert(parser.ReadDouble(Vl[m])); + Vlr[m] = Vl[m] * points[m]; } - PotentialGrid.Init (points); - ChannelPotentials[l].Vl.Init (PotentialGrid, Vl); - ChannelPotentials[l].Vlr.Init (PotentialGrid, Vlr); - ChannelPotentials[l].ul.Init (PotentialGrid, ul); - ChannelPotentials[l].l = l; - ChannelPotentials[l].n_principal = -1; - ChannelPotentials[l].Cutoff = 0.0; + PotentialGrid.Init(points); + ChannelPotentials[l].Vl.Init(PotentialGrid, Vl); + ChannelPotentials[l].Vlr.Init(PotentialGrid, Vlr); + ChannelPotentials[l].ul.Init(PotentialGrid, ul); + ChannelPotentials[l].l = l; + ChannelPotentials[l].n_principal = -1; + ChannelPotentials[l].Cutoff = 0.0; ChannelPotentials[l].HasProjector = true; } // Now, figure out what rcut should be double rmax = PotentialGrid.End(); - int n = PotentialGrid.NumPoints()-1; - bool diff = false; - while ((n>0) && !diff) { + int n = PotentialGrid.NumPoints() - 1; + bool diff = false; + while ((n > 0) && !diff) + { double r = PotentialGrid[n]; - rmax = r; - for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2 = l1 + 1; l2 < numChannels; l2++) + { + double Vl2 = ChannelPotentials[l2].Vl(r); + if (fabs(Vl1 - Vl2) > 1.0e-5) + diff = true; } } n--; } - for (int l=0; l beta, u, V; KBprojector() {} - KBprojector(int l_, std::vector beta_) : - l(l_), beta(beta_) {} + KBprojector(int l_, std::vector beta_) : l(l_), beta(beta_) {} }; -bool -PseudoClass::ReadUPF_PP (std::string fileName) +bool PseudoClass::ReadUPF_PP(std::string fileName) { MemParserClass parser; - if (!parser.OpenFile (fileName)) { + if (!parser.OpenFile(fileName)) + { std::cerr << "Could not open file \"" << fileName << "\". Exitting.\n"; exit(-1); } std::string temp; - assert(parser.FindToken("")); assert(parser.NextLine()); + assert(parser.FindToken("")); + assert(parser.NextLine()); // Skip version number assert(parser.NextLine()); std::string element, ppType, coreCorrection; - assert(parser.ReadWord(element)); assert(parser.NextLine()); + assert(parser.ReadWord(element)); + assert(parser.NextLine()); assert(SymbolToZMap.find(element) != SymbolToZMap.end()); AtomicNumber = SymbolToZMap[element]; // cerr << "Element = \"" << element << "\"\n"; assert(parser.ReadWord(ppType)); - if (ppType != "NC") { - std::cerr << "Psuedopotential type \"" << ppType - << "\" is not norm-conserving.\n"; + if (ppType != "NC") + { + std::cerr << "Psuedopotential type \"" << ppType << "\" is not norm-conserving.\n"; abort(); } - assert (parser.NextLine()); - assert (parser.ReadWord(coreCorrection)); assert(parser.NextLine()); - if (coreCorrection != "F" && coreCorrection != "f" && - coreCorrection != "false" && coreCorrection != "False" && - coreCorrection != ".F." && coreCorrection != ".f" && - coreCorrection != "FALSE") { + assert(parser.NextLine()); + assert(parser.ReadWord(coreCorrection)); + assert(parser.NextLine()); + if (coreCorrection != "F" && coreCorrection != "f" && coreCorrection != "false" && coreCorrection != "False" && + coreCorrection != ".F." && coreCorrection != ".f" && coreCorrection != "FALSE") + { std::cerr << "It appears that a nonlinear core correction was used. Cannot convert PP.\n"; abort(); } @@ -1230,42 +1309,45 @@ PseudoClass::ReadUPF_PP (std::string fileName) assert(parser.NextLine()); int numPoints; - assert(parser.ReadInt(numPoints)); assert(parser.NextLine()); + assert(parser.ReadInt(numPoints)); + assert(parser.NextLine()); int numWF, numProj; - assert (parser.ReadInt(numWF)); assert(parser.ReadInt(numProj)); - int numChannels = numProj+1; + assert(parser.ReadInt(numWF)); + assert(parser.ReadInt(numProj)); + int numChannels = numProj + 1; ChannelPotentials.resize(numChannels); assert(parser.FindToken("Wavefunctions")); -// for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector r(numPoints), dr(numPoints); - for (int i=0; i")); PotentialGrid.Init(r); assert(parser.FindToken("")); - for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector Vlocal(numPoints); - for (int i=0; i lmap; + std::map lmap; std::vector projectors; - for (int proj=0; proj")); + for (int proj = 0; proj < numProj; proj++) + { + assert(parser.FindToken("")); int Beta; - assert (parser.ReadInt(Beta)); - assert(Beta == (proj+1)); + assert(parser.ReadInt(Beta)); + assert(Beta == (proj + 1)); int l; - assert (parser.ReadInt(l)); parser.NextLine(); + assert(parser.ReadInt(l)); + parser.NextLine(); lmap[l] = proj; // fprintf (stderr, "Found a projector for l=%d\n", l); int npt; - assert (parser.ReadInt(npt)); + assert(parser.ReadInt(npt)); std::vector beta(numPoints); - for (int ir=0; ir")); + assert(parser.FindToken("")); projectors.push_back(KBprojector(l, beta)); } assert(parser.FindToken("")); - int llocal=0; - while (lmap.find(llocal) != lmap.end()) llocal++; + int llocal = 0; + while (lmap.find(llocal) != lmap.end()) + llocal++; LocalChannel = llocal; // fprintf (stderr, "First channel without a projector=%d\n", llocal); ChannelPotentials[llocal].Vl.Init(PotentialGrid, Vlocal); std::vector Vlocal_r(numPoints); - for (int ir=0; ir wf(numPoints); - for (int ir=0; ir Vl(numPoints), Vlr(numPoints); - for (int ir=0; ir Vl(numPoints), Vlr(numPoints); + for (int ir = 0; ir < numPoints; ir++) + { + Vl[ir] = Vlocal[ir]; + if (wf[ir] != 0.0) + Vl[ir] += proj.beta[ir] / (2.0 * wf[ir]); + Vlr[ir] = r[ir] * Vl[ir]; + } + Vl[0] = 2.0 * Vl[1] - Vl[2]; + Vlr[0] = r[0] * Vl[0]; + + // for (int ir=0; ir0) && !diff) { + int n = PotentialGrid.NumPoints() - 1; + bool diff = false; + while ((n > 0) && !diff) + { double r = PotentialGrid[n]; - rmax = r; - for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2 = l1 + 1; l2 < numChannels; l2++) + { + double Vl2 = ChannelPotentials[l2].Vl(r); + if (fabs(Vl1 - Vl2) > 1.0e-5) + diff = true; } } n--; } - fprintf (stderr, "rmax = %1.5f numChannels = %d\n", rmax, numChannels); - for (int l=0; l 1.0e-10) { -// cerr << "PseudoCharge = " << PseudoCharge << endl; -// cerr << "chrg = " << chrg << endl; -// } - -// // Read number of channels and resize -// int numChannels; -// assert (parser.ReadInt(numChannels)); -// ChannelPotentials.resize(numChannels); - -// // Skip the next 10 lines -// for (int i=0; i<11; i++) -// assert (parser.FindToken("\n")); - -// // Read the number of grid points -// for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), -// Vlr(numPoints); -// for (int m=0; m0) && !diff) { -// double r = PotentialGrid[n]; -// rmax = r; -// for (int l1=0; l1 1.0e-5) -// diff = true; -// } -// } -// n--; -// } -// for (int l=0; l 1.0e-10) { + // cerr << "PseudoCharge = " << PseudoCharge << endl; + // cerr << "chrg = " << chrg << endl; + // } + + // // Read number of channels and resize + // int numChannels; + // assert (parser.ReadInt(numChannels)); + // ChannelPotentials.resize(numChannels); + + // // Skip the next 10 lines + // for (int i=0; i<11; i++) + // assert (parser.FindToken("\n")); + + // // Read the number of grid points + // for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), + // Vlr(numPoints); + // for (int m=0; m0) && !diff) { + // double r = PotentialGrid[n]; + // rmax = r; + // for (int l1=0; l1 1.0e-5) + // diff = true; + // } + // } + // n--; + // } + // for (int l=0; l rPoints; - if (WriteLogGrid) { + if (WriteLogGrid) + { const int numPoints = 2001; - double end = 150.0; - double step = 0.00625; - double scale = end/(expm1(step*(numPoints-1))); - for (int i=1; i coefs(ngpot), exponents(ngpot); std::vector powers(ngpot); // The local channel is given first - for (int i=0; i 1) { - while (ir > 0 && !done) { + bool done = false; + int ir = rPoints.size() - 1; + if (ChannelPotentials.size() > 1) + { + while (ir > 0 && !done) + { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - for (int l=0; l 1.0e-5) - done = true; + for (int l = 0; l < ChannelPotentials.size(); l++) + if (ChannelPotentials[l].l != LocalChannel) + if (fabs(ChannelPotentials[l].Vl(ir) - vlocal) > 1.0e-5) + done = true; ir--; } } - else { - while (ir > 0 && !done) { + else + { + while (ir > 0 && !done) + { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - double r = rPoints[ir]; - done = fabs (vlocal + PseudoCharge/r) > 1.0e-5; + double r = rPoints[ir]; + done = fabs(vlocal + PseudoCharge / r) > 1.0e-5; ir--; } } - for (int l=0; l= '0' && s[pos] <= '9') sint.push_back(s[pos++]); - s.erase(0,pos); - n = atoi (sint.c_str()); + s.erase(0, pos); + n = atoi(sint.c_str()); return true; } -bool -ReadDouble (std::string &s, double &x) +bool ReadDouble(std::string& s, double& x) { - int pos=0; + int pos = 0; std::string sd; - while ((s[pos] >= '0' && s[pos] <= '9') || s[pos]=='.') + while ((s[pos] >= '0' && s[pos] <= '9') || s[pos] == '.') sd.push_back(s[pos++]); - s.erase(0,pos); + s.erase(0, pos); x = strtod(sd.c_str(), (char**)NULL); return true; } @@ -1617,161 +1718,169 @@ Config::Config(std::string s) ChannelRevMap['d'] = 2; ChannelRevMap['f'] = 3; ChannelRevMap['g'] = 4; - while (s.size() > 0) { + while (s.size() > 0) + { int n, l; double occ; - ReadInt (s, n); + ReadInt(s, n); l = ChannelRevMap[s[0]]; - s.erase(0,1); - assert (s[0] == '('); - s.erase(0,1); - ReadDouble (s, occ); - assert (s[0] == ')'); - s.erase(0,1); - States.push_back (State(n,l,occ)); + s.erase(0, 1); + assert(s[0] == '('); + s.erase(0, 1); + ReadDouble(s, occ); + assert(s[0] == ')'); + s.erase(0, 1); + States.push_back(State(n, l, occ)); } } - -bool -PseudoClass::ReadCASINO_PP (std::string fileName) +bool PseudoClass::ReadCASINO_PP(std::string fileName) { MemParserClass parser; - parser.OpenFile (fileName); - - assert (parser.FindToken("pseudo-charge")); - assert (parser.ReadInt (AtomicNumber)); - assert (parser.ReadDouble (PseudoCharge)); - assert (parser.FindToken("(rydberg/hartree/ev)")); - assert (parser.FindToken("\n")); - assert (parser.ReadWord(EnergyUnit)); + parser.OpenFile(fileName); + + assert(parser.FindToken("pseudo-charge")); + assert(parser.ReadInt(AtomicNumber)); + assert(parser.ReadDouble(PseudoCharge)); + assert(parser.FindToken("(rydberg/hartree/ev)")); + assert(parser.FindToken("\n")); + assert(parser.ReadWord(EnergyUnit)); std::cerr << "EnergyUnit = " << EnergyUnit << std::endl; - assert (parser.FindToken("(0=s,1=p,2=d..)")); - assert (parser.ReadInt (LocalChannel)); - assert (parser.FindToken("grid points")); + assert(parser.FindToken("(0=s,1=p,2=d..)")); + assert(parser.ReadInt(LocalChannel)); + assert(parser.FindToken("grid points")); int numGridPoints; - assert (parser.ReadInt(numGridPoints)); - std::vector gridPoints(numGridPoints), Vl(numGridPoints), - Vlr(numGridPoints); - assert (parser.FindToken ("in")); - assert (parser.ReadWord(LengthUnit)); + assert(parser.ReadInt(numGridPoints)); + std::vector gridPoints(numGridPoints), Vl(numGridPoints), Vlr(numGridPoints); + assert(parser.FindToken("in")); + assert(parser.ReadWord(LengthUnit)); std::cerr << "LengthUnit = " << LengthUnit << std::endl; - assert (parser.FindToken("\n")); + assert(parser.FindToken("\n")); // assert (parser.FindToken("atomic units")); - for (int i=0; i ul(numPoints); - for (int i=0; i argList; // input formats - argList.push_back(ParamClass("fhi_pot", true)); + argList.push_back(ParamClass("fhi_pot", true)); argList.push_back(ParamClass("casino_pot", true)); - argList.push_back(ParamClass("bfd_pot", true)); + argList.push_back(ParamClass("bfd_pot", true)); argList.push_back(ParamClass("gamess_pot", true)); argList.push_back(ParamClass("upf_pot", true)); // Projector parameters - argList.push_back(ParamClass("casino_us", true)); - argList.push_back(ParamClass("casino_up", true)); - argList.push_back(ParamClass("casino_ud", true)); - argList.push_back(ParamClass("casino_uf", true)); - argList.push_back(ParamClass("s_ref", true)); - argList.push_back(ParamClass("p_ref", true)); - argList.push_back(ParamClass("d_ref", true)); - argList.push_back(ParamClass("f_ref", true)); - argList.push_back(ParamClass("g_ref", true)); - argList.push_back(ParamClass("xml", true)); - argList.push_back(ParamClass("tm", true)); - argList.push_back(ParamClass("upf", true)); - argList.push_back(ParamClass("fhi", true)); - argList.push_back(ParamClass("fpmd", true)); + argList.push_back(ParamClass("casino_us", true)); + argList.push_back(ParamClass("casino_up", true)); + argList.push_back(ParamClass("casino_ud", true)); + argList.push_back(ParamClass("casino_uf", true)); + argList.push_back(ParamClass("s_ref", true)); + argList.push_back(ParamClass("p_ref", true)); + argList.push_back(ParamClass("d_ref", true)); + argList.push_back(ParamClass("f_ref", true)); + argList.push_back(ParamClass("g_ref", true)); + argList.push_back(ParamClass("xml", true)); + argList.push_back(ParamClass("tm", true)); + argList.push_back(ParamClass("upf", true)); + argList.push_back(ParamClass("fhi", true)); + argList.push_back(ParamClass("fpmd", true)); argList.push_back(ParamClass("casino", true)); argList.push_back(ParamClass("log_grid", false)); argList.push_back(ParamClass("local_channel", true)); @@ -1884,37 +1993,38 @@ int main(int argc, char **argv) CommandLineParserClass parser(argList); bool success = parser.Parse(argc, argv); - if (!success || parser.NumFiles()!=0) { + if (!success || parser.NumFiles() != 0) + { std::cerr << "Usage: ppconvert options\n" - << " Options include: \n" - << " Input formats: \n" - << " --casino_pot fname \n" - << " --fhi_pot fname \n" - << " --upf_pot fname \n" - << " --bfd_pot fname \n" - << " --gamess_pot fname \n" - << " Output formats: \n" - << " --xml fname.xml \n" - << " --tm fname.tm \n" - << " --upf fname.upf \n" - << " --fhi fname.fhi \n" - << " --fpmd fname.xml \n" - << " --casino fname.xml \n" - << " Reference states:\n" - << " --casino_us fname \n" - << " --casino_up fname \n" - << " --casino_ud fname \n" - << " --casino_uf fname \n" - << " --casino_ug fname \n" - << " --s_ref state \n" - << " --p_ref state \n" - << " --d_ref state \n" - << " --f_ref state \n" - << " --g_ref state \n" - << " Other options: \n" - << " --log_grid \n" - << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" - << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; + << " Options include: \n" + << " Input formats: \n" + << " --casino_pot fname \n" + << " --fhi_pot fname \n" + << " --upf_pot fname \n" + << " --bfd_pot fname \n" + << " --gamess_pot fname \n" + << " Output formats: \n" + << " --xml fname.xml \n" + << " --tm fname.tm \n" + << " --upf fname.upf \n" + << " --fhi fname.fhi \n" + << " --fpmd fname.xml \n" + << " --casino fname.xml \n" + << " Reference states:\n" + << " --casino_us fname \n" + << " --casino_up fname \n" + << " --casino_ud fname \n" + << " --casino_uf fname \n" + << " --casino_ug fname \n" + << " --s_ref state \n" + << " --p_ref state \n" + << " --d_ref state \n" + << " --f_ref state \n" + << " --g_ref state \n" + << " Other options: \n" + << " --log_grid \n" + << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" + << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; exit(1); } @@ -1934,76 +2044,88 @@ int main(int argc, char **argv) if (parser.Found("casino_pot")) nlpp.ReadCASINO_PP(parser.GetArg("casino_pot")); - else if (parser.Found ("bfd_pot")) - nlpp.ReadBFD_PP (parser.GetArg ("bfd_pot")); - else if (parser.Found ("fhi_pot")) - nlpp.ReadFHI_PP (parser.GetArg ("fhi_pot")); - else if (parser.Found ("upf_pot")) - nlpp.ReadUPF_PP (parser.GetArg ("upf_pot")); - else if (parser.Found ("gamess_pot")) - nlpp.ReadGAMESS_PP (parser.GetArg("gamess_pot")); - else { + else if (parser.Found("bfd_pot")) + nlpp.ReadBFD_PP(parser.GetArg("bfd_pot")); + else if (parser.Found("fhi_pot")) + nlpp.ReadFHI_PP(parser.GetArg("fhi_pot")); + else if (parser.Found("upf_pot")) + nlpp.ReadUPF_PP(parser.GetArg("upf_pot")); + else if (parser.Found("gamess_pot")) + nlpp.ReadGAMESS_PP(parser.GetArg("gamess_pot")); + else + { std::cerr << "Need to specify a potential file with --casino_pot " - << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; + << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; exit(1); } // Now check how the projectors are specified - if (!nlpp.HaveProjectors()) { + if (!nlpp.HaveProjectors()) + { int numChannels = nlpp.GetNumChannels(); - if (numChannels > 0) { - if (parser.Found ("s_ref")) - nlpp.CalcProjector (parser.GetArg("s_ref"), 0); + if (numChannels > 0) + { + if (parser.Found("s_ref")) + nlpp.CalcProjector(parser.GetArg("s_ref"), 0); else if (parser.Found("casino_us")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); - else { - std::cerr << "Please specify the s-channel projector with either " - << " --s_ref or --casino_us.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); + else + { + std::cerr << "Please specify the s-channel projector with either " + << " --s_ref or --casino_us.\n"; + // exit(-1); } } - if (numChannels > 1) { - if (parser.Found ("p_ref")) - nlpp.CalcProjector (parser.GetArg("p_ref"), 1); + if (numChannels > 1) + { + if (parser.Found("p_ref")) + nlpp.CalcProjector(parser.GetArg("p_ref"), 1); else if (parser.Found("casino_up")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); - else { - std::cerr << "Please specify the p-channel projector with either " - << " --p_ref or --casino_up.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); + else + { + std::cerr << "Please specify the p-channel projector with either " + << " --p_ref or --casino_up.\n"; + // exit(-1); } } - if (numChannels > 2) { - if (parser.Found ("d_ref")) - nlpp.CalcProjector (parser.GetArg("d_ref"), 2); - else if(parser.Found("casino_ud")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); - else { - std::cerr << "Please specify the d-channel projector with either " - << " --d_ref or --casino_ud.\n"; - // exit(-1); + if (numChannels > 2) + { + if (parser.Found("d_ref")) + nlpp.CalcProjector(parser.GetArg("d_ref"), 2); + else if (parser.Found("casino_ud")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); + else + { + std::cerr << "Please specify the d-channel projector with either " + << " --d_ref or --casino_ud.\n"; + // exit(-1); } } - if (numChannels > 3) { - if (parser.Found ("f_ref")) - nlpp.CalcProjector (parser.GetArg("f_ref"), 3); - else if(parser.Found("casino_uf")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); - else { - std::cerr << "Please specify the f-channel projector with either " - << " --f_ref or --casino_uf.\n"; - // exit(-1); + if (numChannels > 3) + { + if (parser.Found("f_ref")) + nlpp.CalcProjector(parser.GetArg("f_ref"), 3); + else if (parser.Found("casino_uf")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); + else + { + std::cerr << "Please specify the f-channel projector with either " + << " --f_ref or --casino_uf.\n"; + // exit(-1); } } - if (numChannels > 4) { - if (parser.Found ("g_ref")) - nlpp.CalcProjector (parser.GetArg("g_ref"), 4); - else if(parser.Found("casino_ug")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); - else { - std::cerr << "Please specify the g-channel projector with either " - << " --g_ref or --casino_ug.\n"; - // exit(-1); + if (numChannels > 4) + { + if (parser.Found("g_ref")) + nlpp.CalcProjector(parser.GetArg("g_ref"), 4); + else if (parser.Found("casino_ug")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); + else + { + std::cerr << "Please specify the g-channel projector with either " + << " --g_ref or --casino_ug.\n"; + // exit(-1); } } } @@ -2013,30 +2135,27 @@ int main(int argc, char **argv) nlpp.WriteXML(parser.GetArg("xml")); if (parser.Found("tm")) nlpp.WriteABINIT(parser.GetArg("tm")); - if (parser.Found ("upf")) - nlpp.WriteUPF (parser.GetArg("upf")); - if (parser.Found ("fhi")) - nlpp.WriteFHI (parser.GetArg("fhi")); - if (parser.Found ("fpmd")) - nlpp.WriteFPMD (parser.GetArg("fpmd")); - if (parser.Found ("casino")) - nlpp.WriteCASINO (parser.GetArg("casino")); - -// nlpp.WriteXML(xmlFile); -// nlpp.WriteABINIT(); + if (parser.Found("upf")) + nlpp.WriteUPF(parser.GetArg("upf")); + if (parser.Found("fhi")) + nlpp.WriteFHI(parser.GetArg("fhi")); + if (parser.Found("fpmd")) + nlpp.WriteFPMD(parser.GetArg("fpmd")); + if (parser.Found("casino")) + nlpp.WriteCASINO(parser.GetArg("casino")); + + // nlpp.WriteXML(xmlFile); + // nlpp.WriteABINIT(); nlpp.WriteASCII(); -// nlpp.ReadCASINO_PP ("b_pp.data.HF"); -// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); -// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); -// nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); -// nlpp.WriteXML("test.xml"); + // nlpp.ReadCASINO_PP ("b_pp.data.HF"); + // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); + // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); + // nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); + // nlpp.WriteXML("test.xml"); } - - - #include "common/IO.h" //Array vector2Array(std::vector &vec) @@ -2048,53 +2167,54 @@ int main(int argc, char **argv) //} - -bool -PseudoClass::GetNextState (std::string &state, int &n, int &l, double &occ) +bool PseudoClass::GetNextState(std::string& state, int& n, int& l, double& occ) { if (state.length() <= 0) return false; - if ((state[0]<'1') || (state[0] > '9')) { + if ((state[0] < '1') || (state[0] > '9')) + { std::cerr << "Error parsing reference state.\n"; abort(); } - n = state[0] - '0'; - std::string channel = state.substr (1,1); - if ((channel != "s") && (channel != "p") && - (channel != "d") && (channel != "f") && (channel != "g")) { + n = state[0] - '0'; + std::string channel = state.substr(1, 1); + if ((channel != "s") && (channel != "p") && (channel != "d") && (channel != "f") && (channel != "g")) + { std::cerr << "Unrecognized angular momentum channel in reference state.\n"; abort(); } l = ChannelRevMap[channel]; // cerr << "n=" << n << " l=" << l << endl; - if (state[2] != '(') { + if (state[2] != '(') + { std::cerr << "Error parsing occupancy in reference state.\n"; abort(); } - state.erase(0,3); + state.erase(0, 3); std::string occString; - while ((state.length() > 0) && (state[0] != ')')) { - occString.append (state.substr(0,1)); - state.erase(0,1); + while ((state.length() > 0) && (state[0] != ')')) + { + occString.append(state.substr(0, 1)); + state.erase(0, 1); } - char *endptr; - const char *occStr = occString.c_str(); - occ = strtod (occStr, &endptr); - if (state[0] != ')') { + char* endptr; + const char* occStr = occString.c_str(); + occ = strtod(occStr, &endptr); + if (state[0] != ')') + { std::cerr << "Expected a ')' in parsing reference state.\n"; abort(); } - state.erase(0,1); + state.erase(0, 1); return true; } #include "common/DFTAtom.h" -void -PseudoClass::CalcProjector(std::string refstate, int lchannel) +void PseudoClass::CalcProjector(std::string refstate, int lchannel) { DFTAtom atom; std::string saveState = refstate; @@ -2105,87 +2225,70 @@ PseudoClass::CalcProjector(std::string refstate, int lchannel) int n, l; double occ; int lindex = -1; - int index = 0; - while (GetNextState(refstate, n, l, occ)) { - nList.push_back (n); - lList.push_back (l); - occList.push_back (occ); + int index = 0; + while (GetNextState(refstate, n, l, occ)) + { + nList.push_back(n); + lList.push_back(l); + occList.push_back(occ); if (l == lchannel && lindex == -1) lindex = index; index++; } - if (lindex == -1) { - nList.push_back(lchannel+1); + if (lindex == -1) + { + nList.push_back(lchannel + 1); lList.push_back(lchannel); occList.push_back(0.0); - lindex = nList.size()-1; + lindex = nList.size() - 1; } atom.RadialWFs.resize(nList.size()); - for (int i=0; i optimalGrid = std::make_shared(PseudoCharge, PotentialGrid.End()); + atom.SetGrid(optimalGrid); // Set the potential - atom.SetBarePot (this); + atom.SetBarePot(this); // Solve atom atom.NewMix = DensityMix; std::cerr << "Solving atom for reference state " << saveState << ":\n"; atom.Solve(); // Now, initialize the channel u functions - std::vector ul(PotentialGrid.NumPoints()), - rhoAtom(PotentialGrid.NumPoints()); - for (int i=0; i ul(PotentialGrid.NumPoints()), rhoAtom(PotentialGrid.NumPoints()); + for (int i = 0; i < ul.size(); i++) + { + double r = PotentialGrid[i]; + ul[i] = sqrt(4.0 * M_PI) * atom.RadialWFs(lindex).u(r); rhoAtom[i] = atom.rho(r); } - ChannelPotentials[lchannel].ul.Init (PotentialGrid, ul); + ChannelPotentials[lchannel].ul.Init(PotentialGrid, ul); ChannelPotentials[lchannel].HasProjector = true; - ChannelPotentials[lchannel].Occupation = occList[lindex]; + ChannelPotentials[lchannel].Occupation = occList[lindex]; RhoAtom.Init(PotentialGrid, rhoAtom); } -double -PseudoClass::V(double r) -{ return ChannelPotentials[LocalChannel].Vl(r); } +double PseudoClass::V(double r) { return ChannelPotentials[LocalChannel].Vl(r); } -double -PseudoClass::dVdr(double r) -{ return ChannelPotentials[LocalChannel].Vl.Deriv(r); } +double PseudoClass::dVdr(double r) { return ChannelPotentials[LocalChannel].Vl.Deriv(r); } -double -PseudoClass::d2Vdr2(double r) -{ return ChannelPotentials[LocalChannel].Vl.Deriv2(r); } +double PseudoClass::d2Vdr2(double r) { return ChannelPotentials[LocalChannel].Vl.Deriv2(r); } -double -PseudoClass::V(int l, double r) -{ - return ChannelPotentials[l].Vl(r); -} +double PseudoClass::V(int l, double r) { return ChannelPotentials[l].Vl(r); } -double -PseudoClass::dVdr(int l, double r) -{ return ChannelPotentials[l].Vl.Deriv(r); } +double PseudoClass::dVdr(int l, double r) { return ChannelPotentials[l].Vl.Deriv(r); } -double -PseudoClass::d2Vdr2(int l, double r) -{ return ChannelPotentials[l].Vl.Deriv2(r); } +double PseudoClass::d2Vdr2(int l, double r) { return ChannelPotentials[l].Vl.Deriv2(r); } -void -PseudoClass::Write(IOSectionClass &out) -{ -} +void PseudoClass::Write(IOSectionClass& out) {} -void -PseudoClass::Read(IOSectionClass &in) -{ -} +void PseudoClass::Read(IOSectionClass& in) {} diff --git a/src/QMCTools/ppconvert/src/common/AtomBase.h b/src/QMCTools/ppconvert/src/common/AtomBase.h index 91a5aa2558..3774ef9d04 100644 --- a/src/QMCTools/ppconvert/src/common/AtomBase.h +++ b/src/QMCTools/ppconvert/src/common/AtomBase.h @@ -18,6 +18,8 @@ #include "RadialWF.h" +#include // std::shared_ptr + typedef enum { DFTType, @@ -28,7 +30,7 @@ typedef enum class Atom { protected: - Grid* grid; + std::shared_ptr grid; public: Array RadialWFs; @@ -38,8 +40,8 @@ class Atom virtual void Solve() = 0; virtual void Write(IOSectionClass& out) = 0; virtual void Read(IOSectionClass& in) = 0; - virtual void SetGrid(Grid* newGrid) = 0; - inline Grid* GetGrid() { return grid; } + virtual void SetGrid(std::shared_ptr& newGrid) = 0; + inline Grid* GetGrid() { return grid.get(); } inline double NumElecs(); virtual void SetBarePot(Potential* pot) = 0; }; diff --git a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h index 1dc4c4c008..f140b75064 100644 --- a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h +++ b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h @@ -39,7 +39,7 @@ class CubicSplineCommon public: int NumParams; - Grid* grid; + std::shared_ptr grid; /// The values of the derivative of the represented function on the /// boundary. If each value is greater that 1e30, we compute /// boundary conditions assuming that the second derivative is zero at @@ -61,7 +61,7 @@ class CubicSplineCommon /// Initialize the cubic spline. See notes about start and end /// deriv above. - inline void Init(Grid* NewGrid, Array NewYs, double startderiv, double endderiv) + inline void Init(std::shared_ptr& NewGrid, Array NewYs, double startderiv, double endderiv) { StartDeriv = startderiv; EndDeriv = endderiv; @@ -82,17 +82,17 @@ class CubicSplineCommon /// Simplified form which assumes that the second derivative at both /// boundaries are zero. - inline void Init(Grid* NewGrid, Array NewYs) { Init(NewGrid, NewYs, 5.0e30, 5.0e30); } + inline void Init(std::shared_ptr& NewGrid, Array NewYs) { Init(NewGrid, NewYs, 5.0e30, 5.0e30); } /// Simplified constructor. - inline CubicSplineCommon(Grid* NewGrid, Array NewYs) + inline CubicSplineCommon(std::shared_ptr& NewGrid, Array NewYs) { StartDeriv = EndDeriv = 5.0e30; Init(NewGrid, NewYs, 5.0e30, 5.0e30); } /// Full constructor. - inline CubicSplineCommon(Grid* NewGrid, Array NewYs, double startderiv, double endderiv) + inline CubicSplineCommon(std::shared_ptr& NewGrid, Array NewYs, double startderiv, double endderiv) { Init(NewGrid, NewYs, startderiv, endderiv); Update(); @@ -139,11 +139,11 @@ class CubicSplineCommon /// Trivial constructor CubicSplineCommon() { - UpToDate = 0; - NumParams = 0; + UpToDate = 0; + NumParams = 0; StartDeriv = 0; - EndDeriv = 0; - grid = NULL; + EndDeriv = 0; + grid = NULL; } }; diff --git a/src/QMCTools/ppconvert/src/common/DFTAtom.cc b/src/QMCTools/ppconvert/src/common/DFTAtom.cc index 7a449adca2..abf81ae2b5 100644 --- a/src/QMCTools/ppconvert/src/common/DFTAtom.cc +++ b/src/QMCTools/ppconvert/src/common/DFTAtom.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -17,10 +17,7 @@ #include "RungeKutta.h" #include "Functionals.h" -AtomType DFTAtom::Type() -{ - return (DFTType); -} +AtomType DFTAtom::Type() { return (DFTType); } void DFTAtom::UpdateVHXC() { @@ -28,20 +25,22 @@ void DFTAtom::UpdateVHXC() UpdateHartree(); UpdateExCorr(); - for (int i=0; i < grid->NumPoints; i++) + for (int i = 0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); } /// Radial WFs must be normalized before calling this function void DFTAtom::UpdateChargeDensity() { - for (int i=0; iNumPoints; i++) { + for (int i = 0; i < grid->NumPoints; i++) + { ChargeDensity(i) = 0.0; - double r = (*grid)(i); - double rinv2 = 1.0/(r*r); - for (int j=0; jNumPoints; - + HartreeDeriv1 H1(*this); HartreeDeriv2 H2(*this); - RungeKutta integrator1(H1); - RungeKutta integrator2(H2); - temp(0) = 0.0; temp2(0) = 0.0; - integrator1.Integrate(*grid, 0, N-1, temp); - integrator2.Integrate(*grid, 0, N-1, temp2); - - for (int i=0; i integrator1(H1); + RungeKutta integrator2(H2); + temp(0) = 0.0; + temp2(0) = 0.0; + integrator1.Integrate(*grid, 0, N - 1, temp); + integrator2.Integrate(*grid, 0, N - 1, temp2); + + for (int i = 0; i < N; i++) + { + double r = (*grid)(i); + Hartree(i) = 4.0 * M_PI * (temp(i) / r + (temp2(N - 1) - temp2(i))); } } void DFTAtom::UpdateExCorr() { int N = grid->NumPoints; - for (int i=0; i& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; temp.resize(N); temp2.resize(N); temp = 0.0; V.HXC.Init(grid, temp); - ChargeDensity.Init(grid,temp); + ChargeDensity.Init(grid, temp); Hartree.Init(grid, temp); - ExCorr.Init(grid,temp); - for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -138,7 +142,7 @@ void DFTAtom::SetBarePot(Potential *newPot) // for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -168,7 +172,7 @@ void DFTAtom::SetBarePot(Potential *newPot) // UpdateExCorr(); // for (int i=0; i < grid->NumPoints; i++) // V.HXC(i) = Hartree(i) + ExCorr(i); -// +// // double maxDiff = 0.0; // for (int i=0; iNumPoints; + int N = grid->NumPoints; // Just rename temp and temp2 for clarity - Array &oldCharge = temp; - Array &newCharge = temp2; + Array& oldCharge = temp; + Array& newCharge = temp2; // First, zero out screening - for (int i=0; i oldEnergies(RadialWFs.size()); + Array oldEnergies(RadialWFs.size()); // Now solve radial equations - for (int i=0; iNumPoints; i++) + for (int i = 0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); done = true; - for (int i=0; i 1.0e-8) - done = false; + if (fabs(oldEnergies(i) - RadialWFs(i).Energy) > 1.0e-8) + done = false; oldEnergies(i) = RadialWFs(i).Energy; } - for (int i=0; iWrite(out); out.CloseSection(); - for (int i=0; iWrite(out); out.CloseSection(); - out.WriteVar ("NewMix", NewMix); + out.WriteVar("NewMix", NewMix); } -void DFTAtom::Read(IOSectionClass &in) +void DFTAtom::Read(IOSectionClass& in) { assert(in.OpenSection("Grid")); grid = ReadGrid(in); @@ -274,22 +280,22 @@ void DFTAtom::Read(IOSectionClass &in) int numRadialWFs = in.CountSections("RadialWF"); RadialWFs.resize(numRadialWFs); SetGrid(grid); - in.ReadVar ("ChargeDensity", ChargeDensity.Data()); - in.ReadVar ("Hartree", Hartree.Data()); - in.ReadVar ("ExCorr", ExCorr.Data()); - for (int i=0; i& newGrid) override; void SetBarePot(Potential* pot) override; inline double rho(double r) { return ChargeDensity(r); } diff --git a/src/QMCTools/ppconvert/src/common/GeneralPot.cc b/src/QMCTools/ppconvert/src/common/GeneralPot.cc index 221c317f1b..0ac7cbe76e 100644 --- a/src/QMCTools/ppconvert/src/common/GeneralPot.cc +++ b/src/QMCTools/ppconvert/src/common/GeneralPot.cc @@ -8,27 +8,25 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// #include "GeneralPot.h" -void -GeneralPot::Read(IOSectionClass &in) +void GeneralPot::Read(IOSectionClass& in) { - assert (in.OpenSection("Grid")); - PotGrid = ReadGrid (in); + assert(in.OpenSection("Grid")); + PotGrid = ReadGrid(in); in.CloseSection(); - Array vdata; - assert (in.ReadVar("V", vdata)); - assert (in.ReadVar("Z", Z)); - PotSpline.Init (PotGrid, vdata); + Array vdata; + assert(in.ReadVar("V", vdata)); + assert(in.ReadVar("Z", Z)); + PotSpline.Init(PotGrid, vdata); } -void -GeneralPot::Write(IOSectionClass &out) +void GeneralPot::Write(IOSectionClass& out) { out.NewSection("Grid"); PotGrid->Write(out); @@ -38,41 +36,29 @@ GeneralPot::Write(IOSectionClass &out) out.WriteVar("Type", "General"); } -double -GeneralPot::V(double r) +double GeneralPot::V(double r) { if (r < PotGrid->End) return PotSpline(r); else - return (-Z/r); + return (-Z / r); } -double -GeneralPot::dVdr (double r) +double GeneralPot::dVdr(double r) { if (r < PotGrid->End) return PotSpline.Deriv(r); else - return Z/(r*r); + return Z / (r * r); } -double -GeneralPot::d2Vdr2 (double r) +double GeneralPot::d2Vdr2(double r) { if (r < PotGrid->End) return PotSpline.Deriv2(r); else - return -2.0*Z/(r*r*r); + return -2.0 * Z / (r * r * r); } -GeneralPot::GeneralPot() : PotGrid(NULL) -{ - -} - -GeneralPot::~GeneralPot() -{ - if (PotGrid != NULL) - delete PotGrid; -} +GeneralPot::GeneralPot() : PotGrid(NULL) {} diff --git a/src/QMCTools/ppconvert/src/common/GeneralPot.h b/src/QMCTools/ppconvert/src/common/GeneralPot.h index 35e5ae6787..5e1f269642 100644 --- a/src/QMCTools/ppconvert/src/common/GeneralPot.h +++ b/src/QMCTools/ppconvert/src/common/GeneralPot.h @@ -22,7 +22,7 @@ class GeneralPot : public Potential { protected: - Grid* PotGrid; + std::shared_ptr PotGrid; CubicSplineCommon PotSpline; double Z; @@ -34,7 +34,7 @@ class GeneralPot : public Potential void Write(IOSectionClass& out) override; void Read(IOSectionClass& in) override; GeneralPot(); - ~GeneralPot(); + ~GeneralPot() = default; }; #endif diff --git a/src/QMCTools/ppconvert/src/common/Grid.h b/src/QMCTools/ppconvert/src/common/Grid.h index 25ee4f736e..ac8e90fee6 100644 --- a/src/QMCTools/ppconvert/src/common/Grid.h +++ b/src/QMCTools/ppconvert/src/common/Grid.h @@ -65,7 +65,7 @@ class Grid virtual int ReverseMap(double r) = 0; virtual void Write(IOSectionClass& out) = 0; virtual void Read(IOSectionClass& inSection) = 0; - virtual ~Grid(){} + virtual ~Grid() {} }; @@ -630,31 +630,31 @@ class ClusterGrid : public Grid }; -inline Grid* ReadGrid(IOSectionClass& inSection) +inline std::shared_ptr ReadGrid(IOSectionClass& inSection) { std::string Type; assert(inSection.ReadVar("Type", Type)); - Grid* newGrid; + std::shared_ptr newGrid; if (Type == "Linear") - newGrid = new LinearGrid; + newGrid = std::make_shared(); else if (Type == "General") - newGrid = new GeneralGrid; + newGrid = std::make_shared(); else if (Type == "Optimal") - newGrid = new OptimalGrid; + newGrid = std::make_shared(); else if (Type == "Optimal2") - newGrid = new OptimalGrid2; + newGrid = std::make_shared(); else if (Type == "Log") - newGrid = new LogGrid; + newGrid = std::make_shared(); else if (Type == "Cluster") - newGrid = new ClusterGrid; + newGrid = std::make_shared(); else { std::cerr << "Unrecognized Grid type " << Type << "\n"; exit(1); } newGrid->Read(inSection); - return (newGrid); + return newGrid; } diff --git a/src/QMCTools/ppconvert/src/common/NLPP.cc b/src/QMCTools/ppconvert/src/common/NLPP.cc index 162d6c6ca9..7f54d858a8 100644 --- a/src/QMCTools/ppconvert/src/common/NLPP.cc +++ b/src/QMCTools/ppconvert/src/common/NLPP.cc @@ -8,38 +8,30 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - #include "NLPP.h" #include "GKIntegration.h" #include "MatrixOps.h" -bool -NLPPClass::IsNonlocal() -{ - return true; -} +bool NLPPClass::IsNonlocal() { return true; } -void -ChannelPotential::Read(IOSectionClass &in, Grid *grid) +void ChannelPotential::Read(IOSectionClass& in, std::shared_ptr& grid) { - assert (in.ReadVar("l", l)); - assert (in.ReadVar("n_principal", n_principal)); - assert (in.ReadVar("Cutoff", rc)); + assert(in.ReadVar("l", l)); + assert(in.ReadVar("n_principal", n_principal)); + assert(in.ReadVar("Cutoff", rc)); R0 = 1.75 * rc; - assert (in.ReadVar("Occupation", Occupation)); - assert (in.ReadVar("Eigenvalue", Eigenvalue)); - Array V_data, u_data; - assert (in.ReadVar("Vl", V_data)); - assert (in.ReadVar("ul", u_data)); - V.Init (grid, V_data); - u.Init (grid, u_data); + assert(in.ReadVar("Occupation", Occupation)); + assert(in.ReadVar("Eigenvalue", Eigenvalue)); + Array V_data, u_data; + assert(in.ReadVar("Vl", V_data)); + assert(in.ReadVar("ul", u_data)); + V.Init(grid, V_data); + u.Init(grid, u_data); } -void -ChannelPotential::Write(IOSectionClass &out) +void ChannelPotential::Write(IOSectionClass& out) { out.WriteVar("l", l); out.WriteVar("n_principal", n_principal); @@ -50,148 +42,153 @@ ChannelPotential::Write(IOSectionClass &out) out.WriteVar("ul", u.Data()); } -void -NLPPClass::Read(IOSectionClass &in) +void NLPPClass::Read(IOSectionClass& in) { assert(in.ReadVar("AtomicNumber", AtomicNumber)); assert(in.ReadVar("LocalChannel", lLocal)); assert(in.ReadVar("ValenceCharge", Zion)); assert(in.ReadVar("Symbol", Symbol)); - + int numChannels = in.CountSections("lChannel"); Vl.resize(numChannels); -// vector > vl(numChannels), ul(numChannels); -// vector rc(numChannels); - assert (in.OpenSection("PotentialGrid")); - PotentialGrid = ReadGrid (in); + // vector > vl(numChannels), ul(numChannels); + // vector rc(numChannels); + assert(in.OpenSection("PotentialGrid")); + PotentialGrid = ReadGrid(in); in.CloseSection(); // "PotentialGrid" - for (int i=0; i numChannels) { + assert(in.ReadVar("l", l)); + if (l > numChannels) + { std::cerr << "Skipped channels in NLPPClass read.\n"; abort(); } Vl[l].Read(in, PotentialGrid); - in.CloseSection (); // "lChannel" + in.CloseSection(); // "lChannel" } - for (int l=0; l deltav(PotentialGrid->NumPoints); - deltav = Vl[l].V.Data()- Vl[lLocal].V.Data(); - Vl[l].DeltaV.Init (PotentialGrid, deltav); + for (int l = 0; l < numChannels; l++) + { + Array deltav(PotentialGrid->NumPoints); + deltav = Vl[l].V.Data() - Vl[lLocal].V.Data(); + Vl[l].DeltaV.Init(PotentialGrid, deltav); } } -void -NLPPClass::Write(IOSectionClass &out) +void NLPPClass::Write(IOSectionClass& out) { - out.WriteVar ("Type", "NLPP"); - out.WriteVar ("LocalChannel", lLocal); - out.WriteVar ("AtomicNumber", AtomicNumber); - out.WriteVar ("Symbol", Symbol); - out.WriteVar ("ValenceCharge", Zion); + out.WriteVar("Type", "NLPP"); + out.WriteVar("LocalChannel", lLocal); + out.WriteVar("AtomicNumber", AtomicNumber); + out.WriteVar("Symbol", Symbol); + out.WriteVar("ValenceCharge", Zion); out.NewSection("PotentialGrid"); PotentialGrid->Write(out); - out.CloseSection(); // "PotentialGrid" - for (int i=0; i::quiet_NaN(); // sqrt(-1.0); } @@ -213,86 +210,91 @@ ChannelPotential::A(double q, double qp) // DeltaV and u splines. It then applies the methods of King-Smith et // al to filter out the high Fourier components, so that the // projector can be applied without error in real-space. -void -ChannelPotential::SetupProjector (double G_max, double G_FFT) +void ChannelPotential::SetupProjector(double G_max, double G_FFT) { - Grid &grid = *u.grid; + Grid& grid = *u.grid; // First, compute zeta_r, normalization, and E_KB Job = NORM; GKIntegration integrator(*this); - double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); - ProjectorNorm = 1.0/sqrt(norm); - Job = EKB; - E_KB = norm/integrator.Integrate(0.0, grid.End, 1.0e-12); - std::cerr << "l = " << l << " Norm is " << norm - << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; - + double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); + ProjectorNorm = 1.0 / sqrt(norm); + Job = EKB; + E_KB = norm / integrator.Integrate(0.0, grid.End, 1.0e-12); + std::cerr << "l = " << l << " Norm is " << norm << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; + // Compute zeta(r) - Array zeta(grid.NumPoints); - zeta(0) = ProjectorNorm * DeltaV(0)*u(1.0e-8)*1.0e8; - for (int i=1; i zeta(grid.NumPoints); + zeta(0) = ProjectorNorm * DeltaV(0) * u(1.0e-8) * 1.0e8; + for (int i = 1; i < grid.NumPoints; i++) + zeta(i) = ProjectorNorm * DeltaV(i) * u(i) / grid(i); + zeta_r.Init(u.grid, zeta); // Compute zeta(q) Job = ZETA_Q; - qGrid.Init (0.0, G_FFT, 1000); + qGrid.Init(0.0, G_FFT, 1000); zeta.resize(qGrid.NumPoints); - for (int i=0; i qGridSharedPtr(&qGrid); + zeta_q.Init(qGridSharedPtr, zeta); double gamma = G_FFT - G_max; // Zero out zeta_q above gamma; - Array chi_q_data(qGrid.NumPoints); - for (int i=0; i chi_q_data(qGrid.NumPoints); + for (int i = 0; i < qGrid.NumPoints; i++) chi_q_data(i) = (qGrid(i) >= gamma) ? 0.0 : zeta_q(i); - chi_q.Init (&qGrid, chi_q_data); + + chi_q.Init(qGridSharedPtr, chi_q_data); // Now for the magic: We adjust chi_q between G_max and gamma so // that the real-space oscillations outside R0 are damped out // See King-Smith et al, PRB 44 13063 // Find index of gamma int gammaIndex = qGrid.ReverseMap(gamma); - int G_maxIndex = qGrid.ReverseMap(G_max)+1; - double delta = qGrid(1)-qGrid(0); - int nb = gammaIndex - G_maxIndex; - Array b(nb), x(nb); + int G_maxIndex = qGrid.ReverseMap(G_max) + 1; + double delta = qGrid(1) - qGrid(0); + int nb = gammaIndex - G_maxIndex; + Array b(nb), x(nb); // First, create the b vector b = 0.0; - for (int i=0; i M(nb, nb); - for (int i=0; i M(nb, nb); + for (int i = 0; i < nb; i++) + { + double q = qGrid(G_maxIndex + i); + for (int j = 0; j < nb; j++) + { + double qp = qGrid(G_maxIndex + j); + M(i, j) = delta * A(q, qp); } - M(i,i) -= 0.5*M_PI*q*q; + M(i, i) -= 0.5 * M_PI * q * q; } -// if (l==2) { -// FILE *fout = fopen ("M.dat", "w"); -// for (int i=0; i perm({nb}, int{0}); @@ -300,36 +302,35 @@ ChannelPotential::SetupProjector (double G_max, double G_FFT) assert(size(LU) == size(M)); // check it is invertible x = lup::solve(LU, perm, b); - for (int i=0; i chi_r_data(grid.NumPoints); - for (int i=1; i chi_r_data(grid.NumPoints); + for (int i = 1; i < grid.NumPoints; i++) + { + rCurrent = grid(i); chi_r_data(i) = integrator.Integrate(0.0, gamma, 1.0e-10); } - chi_r.Init (&grid, chi_r_data); + chi_r.Init(u.grid, chi_r_data); // Finally, check to see if chi_r is small outside R0 - Job = CHECK_CHI_R; + Job = CHECK_CHI_R; double norm2 = integrator.Integrate(0.0, grid.End, 1.0e-8); - double error = integrator.Integrate( R0, grid.End, 1.0e-8); + double error = integrator.Integrate(R0, grid.End, 1.0e-8); if (error > 1.0e-16) - std::cerr << "Fractional error in real-space projection = " - << (error / norm2) << std::endl; + std::cerr << "Fractional error in real-space projection = " << (error / norm2) << std::endl; } -double -NLPPClass::V(int l, double r) +double NLPPClass::V(int l, double r) { if (l < Vl.size()) return Vl[l].V(r); @@ -337,8 +338,7 @@ NLPPClass::V(int l, double r) return Vl[lLocal].V(r); } -double -NLPPClass::dVdr(int l, double r) +double NLPPClass::dVdr(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv(r); @@ -346,8 +346,7 @@ NLPPClass::dVdr(int l, double r) return Vl[lLocal].V.Deriv(r); } -double -NLPPClass::d2Vdr2(int l, double r) +double NLPPClass::d2Vdr2(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv2(r); @@ -355,20 +354,8 @@ NLPPClass::d2Vdr2(int l, double r) return Vl[lLocal].V.Deriv2(r); } -double -NLPPClass::V(double r) -{ - return Vl[lLocal].V(r); -} +double NLPPClass::V(double r) { return Vl[lLocal].V(r); } -double -NLPPClass::dVdr(double r) -{ - return Vl[lLocal].V.Deriv(r); -} +double NLPPClass::dVdr(double r) { return Vl[lLocal].V.Deriv(r); } -double -NLPPClass::d2Vdr2(double r) -{ - return Vl[lLocal].V.Deriv2(r); -} +double NLPPClass::d2Vdr2(double r) { return Vl[lLocal].V.Deriv2(r); } diff --git a/src/QMCTools/ppconvert/src/common/NLPP.h b/src/QMCTools/ppconvert/src/common/NLPP.h index 11f30e3314..7d8b338c66 100644 --- a/src/QMCTools/ppconvert/src/common/NLPP.h +++ b/src/QMCTools/ppconvert/src/common/NLPP.h @@ -63,7 +63,7 @@ class ChannelPotential inline double operator()(double x); void SetupProjector(double G_max, double G_FFT); - void Read(IOSectionClass& in, Grid* grid); + void Read(IOSectionClass& in, std::shared_ptr& grid); void Write(IOSectionClass& out); }; @@ -77,7 +77,7 @@ class NLPPClass : public Potential double Zion; int AtomicNumber; std::string Symbol; - Grid* PotentialGrid; + std::shared_ptr PotentialGrid; public: // General accessor functions diff --git a/src/QMCTools/ppconvert/src/common/PotentialBase.h b/src/QMCTools/ppconvert/src/common/PotentialBase.h index cff2c497f2..492cc2ff49 100644 --- a/src/QMCTools/ppconvert/src/common/PotentialBase.h +++ b/src/QMCTools/ppconvert/src/common/PotentialBase.h @@ -22,6 +22,7 @@ using namespace IO; class Potential { public: + virtual ~Potential() = default; // Optional member functions -- if you're not a pseudoHamiltonian, // you do not need to define these virtual bool IsPH(); diff --git a/src/QMCTools/ppconvert/src/common/RadialWF.cc b/src/QMCTools/ppconvert/src/common/RadialWF.cc index 9f6887f68a..a2d87a1999 100644 --- a/src/QMCTools/ppconvert/src/common/RadialWF.cc +++ b/src/QMCTools/ppconvert/src/common/RadialWF.cc @@ -8,91 +8,91 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// #include "RadialWF.h" #include "RungeKutta.h" -int -RadialWF::TurningIndex() +int RadialWF::TurningIndex() { // Start in classically forbidden region and search inward toward // origin looking for classically allowed region - Grid &grid = *u.grid; - int index = grid.NumPoints-1; - bool done = false; - - while (!done && (index >=0)) - { - double r = grid(index); - double A = pot->A(r); - double B = pot->B(r); - double V = pot->V(l,r); - double dAdr = pot->dAdr(r); - double E = Energy; - double sl = (double) l; - - double Deriv2 = dAdr/r + sl*(sl+1.0)*B/(r*r) + 2.0*(V-E); - - if (Deriv2 < 0.0) - done = true; - else - index--; - } + Grid& grid = *u.grid; + int index = grid.NumPoints - 1; + bool done = false; + + while (!done && (index >= 0)) + { + double r = grid(index); + double A = pot->A(r); + double B = pot->B(r); + double V = pot->V(l, r); + double dAdr = pot->dAdr(r); + double E = Energy; + double sl = (double)l; + + double Deriv2 = dAdr / r + sl * (sl + 1.0) * B / (r * r) + 2.0 * (V - E); + + if (Deriv2 < 0.0) + done = true; + else + index--; + } // If we didn't fine a turning point, select the middle grid point; if (index == -1) - index = grid.ReverseMap(0.5*grid(grid.NumPoints-1)); + index = grid.ReverseMap(0.5 * grid(grid.NumPoints - 1)); return (index); } -void -RadialWF::OriginBC(double r0, double &u0, double &du0) +void RadialWF::OriginBC(double r0, double& u0, double& du0) { - if (pot->NeedsRel()) { // Use relativistic equations - const double alpha = 1.0/137.036; - double Z = -pot->V(l,r0)*r0; - double a2Z2 = alpha*alpha*(double)Z*(double)Z; - - double sl = (double) l; - double gamma = - (sl+1.0)*sqrt((sl+1.0)*(sl+1.0)-a2Z2) / - (2.0*sl + 1.0); - if (l!=0) - gamma += sl*sqrt(sl*sl-a2Z2)/(2.0*sl+1.0); - - u0 = pow(r0, gamma); - du0 = gamma * pow(r0,gamma-1.0); + if (pot->NeedsRel()) + { // Use relativistic equations + const double alpha = 1.0 / 137.036; + double Z = -pot->V(l, r0) * r0; + double a2Z2 = alpha * alpha * (double)Z * (double)Z; + + double sl = (double)l; + double gamma = (sl + 1.0) * sqrt((sl + 1.0) * (sl + 1.0) - a2Z2) / (2.0 * sl + 1.0); + if (l != 0) + gamma += sl * sqrt(sl * sl - a2Z2) / (2.0 * sl + 1.0); + + u0 = pow(r0, gamma); + du0 = gamma * pow(r0, gamma - 1.0); } - else { // Use pseudoHamiltonian equations + else + { // Use pseudoHamiltonian equations if (l == 0) + { + double E = Energy; + double A = pot->A(r0); + double B = pot->B(r0); + double V = pot->V(l, r0); + if (V > Energy) + { + double kappa = sqrt(2.0 * (V - E) / A); + u0 = sinh(kappa * r0); + du0 = kappa * cosh(kappa * r0); + } + else { - double E = Energy; - double A = pot->A(r0); - double B = pot->B(r0); - double V = pot->V(l,r0); - if (V > Energy) - { - double kappa = sqrt(2.0 * (V-E)/A); - u0 = sinh(kappa * r0); - du0 = kappa * cosh (kappa * r0); - } - else - { - double k = sqrt(2.0 * (E-V)/A); - u0 = sin(k * r0); - du0 = k * cos(k * r0); - } + double k = sqrt(2.0 * (E - V) / A); + u0 = sin(k * r0); + du0 = k * cos(k * r0); } - else { // l != 0 - u0 = 1.0; - du0 = (double)(l+1)/r0; } - } + else + { // l != 0 + u0 = 1.0; + du0 = (double)(l + 1) / r0; + } + } // Flip sign for odd number of nodes - if (((n-l-1) % 2) == 1) { + if (((n - l - 1) % 2) == 1) + { u0 *= -1.0; du0 *= -1.0; } @@ -105,7 +105,7 @@ RadialWF::OriginBC(double r0, double &u0, double &du0) // Grid &grid = *u.grid; // Array Temp(grid.NumPoints); // // Set up initial conditions: -// double r0 = grid(0); +// double r0 = grid(0); // OriginBC(r0, Temp(0)[0], Temp(0)[1]); // // Now do integration @@ -117,12 +117,12 @@ RadialWF::OriginBC(double r0, double &u0, double &du0) // else if (pot->NeedsRel()) { // NonPHDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // else { // RegularDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // // Copy results of integration into RadialWF @@ -134,152 +134,159 @@ RadialWF::OriginBC(double r0, double &u0, double &du0) //} -double -RadialWF::IntegrateInOut (int &tindex) +double RadialWF::IntegrateInOut(int& tindex) { - Grid &grid = *u.grid; + Grid& grid = *u.grid; // Find classical turning point tindex = TurningIndex(); //cerr << "TurningIndex = " << tindex << endl; //cerr << "Turning Point = " << (*u.grid)(tindex) << endl; // Compute starting value and derivative at origin double r0 = grid(0); - OriginBC (r0, uduVec(0)[0], uduVec(0)[1]); + OriginBC(r0, uduVec(0)[0], uduVec(0)[1]); // Do integration from the origin to the turning point - if (pot->IsPH()) { + if (pot->IsPH()) + { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, 0, tindex, uduVec); } - else if (pot->NeedsRel()) { + else if (pot->NeedsRel()) + { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); } - else { + else + { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); + } - for (int j=0; j<=tindex; j++) { - u(j) = uduVec(j)[0]; + for (int j = 0; j <= tindex; j++) + { + u(j) = uduVec(j)[0]; dudr(j) = uduVec(j)[1]; } // Now initilize value and derivative at rmax - int endPoint = grid.NumPoints-1; - double rend = grid(endPoint); + int endPoint = grid.NumPoints - 1; + double rend = grid(endPoint); InfinityBC(rend, uduVec(endPoint)[0], uduVec(endPoint)[1]); - + // Do integration from the right to the turning point - if (pot->IsPH()) { + if (pot->IsPH()) + { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else if (pot->NeedsRel()) { + else if (pot->NeedsRel()) + { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else { + else + { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, endPoint, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, endPoint, tindex, uduVec); + } - if ((u(tindex)*uduVec(tindex)[0]) < 0.0) - for (int i=tindex; i<=endPoint; i++) + if ((u(tindex) * uduVec(tindex)[0]) < 0.0) + for (int i = tindex; i <= endPoint; i++) uduVec(i) *= -1.0; - double cuspValue = uduVec(tindex)[1]/uduVec(tindex)[0] - - dudr(tindex)/u(tindex); + double cuspValue = uduVec(tindex)[1] / uduVec(tindex)[0] - dudr(tindex) / u(tindex); // Copy values in, normalizing to make R continuous double factor = u(tindex) / uduVec(tindex)[0]; - for (int i=tindex+1; iV(l,rend); - double dVdrend = pot->dVdr(l,rend); - double E = Energy; + double Vend = pot->V(l, rend); + double dVdrend = pot->dVdr(l, rend); + double E = Energy; double k; uend = 1.0; - if (Vend > E) { - k = sqrt(l*(l+1.0)/(rend*rend) + (Vend-E)); - duend = -uend * (k + 0.5*rend/k*(dVdrend-2.0*l*(l+1.0)/(rend*rend*rend))); + if (Vend > E) + { + k = sqrt(l * (l + 1.0) / (rend * rend) + (Vend - E)); + duend = -uend * (k + 0.5 * rend / k * (dVdrend - 2.0 * l * (l + 1.0) / (rend * rend * rend))); } else duend = -1.0; -// cerr << "duend = " << duend << endl; -// cerr << "rend = " << rend << endl; -// cerr << "k = " << k << endl; -// cerr << "Vend = " << Vend << endl; -// cerr << "dVend = " << dVdrend << endl; + // cerr << "duend = " << duend << endl; + // cerr << "rend = " << rend << endl; + // cerr << "k = " << k << endl; + // cerr << "Vend = " << Vend << endl; + // cerr << "dVend = " << dVdrend << endl; } - -void -RadialWF::Solve(double tolerance) +void RadialWF::Solve(double tolerance) { int tindex; IntegrateInOut(tindex); int NumNodes = CountNodes(); double Ehigh, Elow, Etrial; - Ehigh = 0.0; - Grid &grid = *u.grid; - int TotalNodes = n-l-1; - -// char fname[100]; -// snprintf (fname, 100, "WFn%dl%d.h5", n, l); -// IOSectionClass out; -// out.NewFile(fname); -// out.WriteVar ("x", u.grid->Points()); -// Array tmp(1,u.grid->NumPoints); -// tmp(0,Range::all()) = u.Data(); -// out.WriteVar ("u", tmp); -// VarClass *varPtr = out.GetVarPtr("u"); - - if (pot->NeedsRel()){ + Ehigh = 0.0; + Grid& grid = *u.grid; + int TotalNodes = n - l - 1; + + // char fname[100]; + // snprintf (fname, 100, "WFn%dl%d.h5", n, l); + // IOSectionClass out; + // out.NewFile(fname); + // out.WriteVar ("x", u.grid->Points()); + // Array tmp(1,u.grid->NumPoints); + // tmp(0,Range::all()) = u.Data(); + // out.WriteVar ("u", tmp); + // VarClass *varPtr = out.GetVarPtr("u"); + + if (pot->NeedsRel()) + { double N = n; - double Z = -pot->V(l,grid(0))*grid(0); - Elow = -1.5*Z*Z/(N*N); - } - else { + double Z = -pot->V(l, grid(0)) * grid(0); + Elow = -1.5 * Z * Z / (N * N); + } + else + { // Eigenenergy can't be lower than lowest potential -- otherwise // we'd have no turning point. - Elow = pot->V(l,grid(0)); - for (int i=1; iV(l, grid(0)); + for (int i = 1; i < grid.NumPoints; i++) + { double r = grid(i); // cerr << "r = " << r << " V(l,r) = " << pot->V(l,r) << endl; - if (pot->V(l,r) < Elow) - Elow = pot->V(l,r); + if (pot->V(l, r) < Elow) + Elow = pot->V(l, r); } } double Eold; Eold = Etrial = Energy; - bool done = false; - while (!done) { + bool done = false; + while (!done) + { // cerr << "Ehigh = " << Ehigh << " Elow = " << Elow << endl; double CuspValue = IntegrateInOut(tindex); - //cerr << "Cusp value = " << CuspValue << "\n"; + //cerr << "Cusp value = " << CuspValue << "\n"; NumNodes = CountNodes(); if (NumNodes > TotalNodes) Ehigh = Etrial; @@ -291,27 +298,28 @@ RadialWF::Solve(double tolerance) Ehigh = Etrial; else if (std::isnan(CuspValue)) Elow = Etrial; - + Normalize(); // varPtr->Append(u.Data()); - double A = pot->A(grid(tindex)); - double C = 0.5 * A * CuspValue; - double u0 = u(tindex); - double Etest = Eold - 4.0*M_PI*C*u0*u0; + double A = pot->A(grid(tindex)); + double C = 0.5 * A * CuspValue; + double u0 = u(tindex); + double Etest = Eold - 4.0 * M_PI * C * u0 * u0; if ((Etest > Elow) && (Etest < Ehigh) && (NumNodes == TotalNodes)) Etrial = Etest; - else + else Etrial = 0.5 * (Ehigh + Elow); - + Energy = Etrial; - - if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) { + + if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) + { Energy = Eold; - done = true; + done = true; } else { - if(std::isnan(Etrial)) + if (std::isnan(Etrial)) { std::cerr << "NaN detected!" << std::endl; std::cerr << "NumNodes = " << NumNodes << " TotalNodes = " << TotalNodes << std::endl; @@ -319,48 +327,48 @@ RadialWF::Solve(double tolerance) exit(1); } } - Eold = Etrial; + Eold = Etrial; } IntegrateInOut(tindex); Normalize(); NumNodes = CountNodes(); - if (NumNodes != TotalNodes) { - std::cerr << "Node number error! We have " << NumNodes - << " nodes and want " << TotalNodes << ".\n"; -// IOSectionClass out; -// out.NewFile ("BadWF.h5"); -// out.WriteVar ("u", u.Data()); -// out.CloseFile(); + if (NumNodes != TotalNodes) + { + std::cerr << "Node number error! We have " << NumNodes << " nodes and want " << TotalNodes << ".\n"; + // IOSectionClass out; + // out.NewFile ("BadWF.h5"); + // out.WriteVar ("u", u.Data()); + // out.CloseFile(); std::cerr << "Energy = " << Energy << std::endl; } //out.CloseFile(); } -void -RadialWF::Normalize() +void RadialWF::Normalize() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); - // The false means "don't scale" - integrator.Integrate(*u.grid, 0, u.grid->NumPoints-1, normVec, false); - - double norm = sqrt(1.0/(4.0*M_PI*normVec(u.grid->NumPoints-1))); - for (int i=0; iNumPoints; i++) { + RungeKutta integrator(normDeriv); + // The false means "don't scale" + integrator.Integrate(*u.grid, 0, u.grid->NumPoints - 1, normVec, false); + + double norm = sqrt(1.0 / (4.0 * M_PI * normVec(u.grid->NumPoints - 1))); + for (int i = 0; i < u.grid->NumPoints; i++) + { u(i) *= norm; dudr(i) *= norm; } } -int -RadialWF::CountNodes() +int RadialWF::CountNodes() { - int nodes=0; + int nodes = 0; double sign = u(0); - for (int i=1; iNumPoints; i++) - if ((sign*u(i)) < 0.0) { + for (int i = 1; i < u.grid->NumPoints; i++) + if ((sign * u(i)) < 0.0) + { nodes++; sign *= -1.0; // cerr << "Node at i=" << i << " r=" << (*u.grid)(i) << endl; @@ -368,79 +376,67 @@ RadialWF::CountNodes() return (nodes); } -void -RadialWF::SetGrid(Grid *newgrid) +void RadialWF::SetGrid(std::shared_ptr& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; uduVec.resize(N); normVec.resize(N); - uduVec = 0.0; + uduVec = 0.0; normVec = 0.0; - u.Init (grid, normVec); + u.Init(grid, normVec); dudr.Init(grid, normVec); } -void -RadialWF::SetPotential(Potential *newPot) -{ - pot = newPot; -} +void RadialWF::SetPotential(Potential* newPot) { pot = newPot; } -Potential* -RadialWF::GetPotential() -{ - return pot; -} +Potential* RadialWF::GetPotential() { return pot; } -double -RadialWF::PartialNorm() +double RadialWF::PartialNorm() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); + RungeKutta integrator(normDeriv); int N = u.grid->NumPoints; - integrator.Integrate(*u.grid, 0, N-1, normVec); - double uend = u(N-1); - double partNorm = normVec(N-1)/(uend*uend); + integrator.Integrate(*u.grid, 0, N - 1, normVec); + double uend = u(N - 1); + double partNorm = normVec(N - 1) / (uend * uend); return (partNorm); } -double -RadialWF::LogDerivative() +double RadialWF::LogDerivative() { double rend = (*u.grid).End; - return (dudr(rend)/u(rend)); + return (dudr(rend) / u(rend)); } // This will write all the information except the potential and the // grid. We assume that those are store somewhere else -void -RadialWF::Write(IOSectionClass &out) +void RadialWF::Write(IOSectionClass& out) { - out.WriteVar ("u", u.Data()); - out.WriteVar ("dudr", dudr.Data()); - out.WriteVar ("n", n); - out.WriteVar ("l", l); - out.WriteVar ("CoreNodes", CoreNodes); - out.WriteVar ("Occupancy", Occupancy); - out.WriteVar ("Weight", Weight); - out.WriteVar ("Energy", Energy); + out.WriteVar("u", u.Data()); + out.WriteVar("dudr", dudr.Data()); + out.WriteVar("n", n); + out.WriteVar("l", l); + out.WriteVar("CoreNodes", CoreNodes); + out.WriteVar("Occupancy", Occupancy); + out.WriteVar("Weight", Weight); + out.WriteVar("Energy", Energy); // out.WriteVar ("PartialNorm", PartialNorm); - out.WriteVar ("Label", Label); + out.WriteVar("Label", Label); } // This function assumes the grid has already been set. -void -RadialWF::Read (IOSectionClass &in) +void RadialWF::Read(IOSectionClass& in) { bool succ; - if (u.grid == NULL) { + if (u.grid == NULL) + { std::cerr << "Grid not set prior to calling RadialWF::Read.\n"; exit(1); } - in.ReadVar ("u", u.Data()); - in.ReadVar ("dudr", dudr.Data()); + in.ReadVar("u", u.Data()); + in.ReadVar("dudr", dudr.Data()); assert(in.ReadVar("n", n)); assert(in.ReadVar("l", l)); assert(in.ReadVar("Occupancy", Occupancy)); diff --git a/src/QMCTools/ppconvert/src/common/RadialWF.h b/src/QMCTools/ppconvert/src/common/RadialWF.h index 8de0789cb4..a6dc0562e3 100644 --- a/src/QMCTools/ppconvert/src/common/RadialWF.h +++ b/src/QMCTools/ppconvert/src/common/RadialWF.h @@ -33,7 +33,7 @@ class RadialWF Potential* pot; public: - Grid* grid; + std::shared_ptr grid; CubicSplineCommon u, dudr; int n, l, CoreNodes; double Energy, Occupancy, Weight; @@ -49,7 +49,7 @@ class RadialWF double LogDerivative(); void Solve(double tolerance = 1.0e-8); void Normalize(); - void SetGrid(Grid* newgrid); + void SetGrid(std::shared_ptr& newgrid); void SetPotential(Potential* newPot); Potential* GetPotential(); void Write(IOSectionClass& out); diff --git a/src/QMCTools/ppconvert/src/common/SplinePot.cc b/src/QMCTools/ppconvert/src/common/SplinePot.cc index 089ed6809f..a6f89a96df 100644 --- a/src/QMCTools/ppconvert/src/common/SplinePot.cc +++ b/src/QMCTools/ppconvert/src/common/SplinePot.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -19,9 +19,10 @@ double SplinePot::V(double r) { if (r <= Spline.grid->End) return Spline(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->V(r)); - else { + else + { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -33,9 +34,10 @@ double SplinePot::dVdr(double r) { if (r <= Spline.grid->End) return Spline.Deriv(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->dVdr(r)); - else { + else + { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -47,9 +49,10 @@ double SplinePot::d2Vdr2(double r) { if (r <= Spline.grid->End) return Spline.Deriv2(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->d2Vdr2(r)); - else { + else + { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -57,32 +60,34 @@ double SplinePot::d2Vdr2(double r) } } -void SplinePot::Read(IOSectionClass &in) +void SplinePot::Read(IOSectionClass& in) { assert(in.OpenSection("Grid")); - Grid *grid = ReadGrid(in); - in.CloseSection(); // "Grid" - Array data; + auto grid = ReadGrid(in); + in.CloseSection(); // "Grid" + Array data; assert(in.ReadVar("SplineData", data)); - Spline.Init (grid, data); - if(in.OpenSection("Vouter")) { + Spline.Init(grid, data); + if (in.OpenSection("Vouter")) + { Vouter = ReadPotential(in); in.CloseSection(); } else Vouter = NULL; - } +} -void SplinePot::Write(IOSectionClass &out) +void SplinePot::Write(IOSectionClass& out) { - out.WriteVar ("Type", "Spline"); + out.WriteVar("Type", "Spline"); out.NewSection("Grid"); Spline.grid->Write(out); out.CloseSection(); - out.WriteVar ("SplineData", Spline.Data()); - if (Vouter != NULL) { - out.NewSection ("Vouter"); + out.WriteVar("SplineData", Spline.Data()); + if (Vouter != NULL) + { + out.NewSection("Vouter"); Vouter->Write(out); out.CloseSection(); } From b5571ec807e10822468b5c386e484af3d699ce32 Mon Sep 17 00:00:00 2001 From: William F Godoy Date: Thu, 30 Sep 2021 13:46:49 -0400 Subject: [PATCH 5/6] Revert clang-format related changes --- src/QMCTools/ppconvert/src/NLPPClass.cc | 2565 ++++++++--------- src/QMCTools/ppconvert/src/XMLWriterClass2.cc | 129 +- .../ppconvert/src/common/CubicSplineCommon.h | 8 +- src/QMCTools/ppconvert/src/common/DFTAtom.cc | 168 +- .../ppconvert/src/common/GeneralPot.cc | 42 +- src/QMCTools/ppconvert/src/common/Grid.h | 2 +- src/QMCTools/ppconvert/src/common/NLPP.cc | 390 +-- src/QMCTools/ppconvert/src/common/RadialWF.cc | 426 +-- .../ppconvert/src/common/SplinePot.cc | 43 +- 9 files changed, 1851 insertions(+), 1922 deletions(-) diff --git a/src/QMCTools/ppconvert/src/NLPPClass.cc b/src/QMCTools/ppconvert/src/NLPPClass.cc index 1504f22856..4dec3f5c4e 100644 --- a/src/QMCTools/ppconvert/src/NLPPClass.cc +++ b/src/QMCTools/ppconvert/src/NLPPClass.cc @@ -11,6 +11,9 @@ ////////////////////////////////////////////////////////////////////////////////////// + + + #include "NLPPClass.h" #include "XMLWriterClass2.h" #include "ParserClass.h" @@ -20,15 +23,17 @@ #include #include -void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl) +void +ChannelPotentialClass::WriteChannelLog (XMLWriterClass &writer, + bool writeVl) { std::string channels[] = {"s", "p", "d", "f", "g", "h", "i", "j"}; // Use a logarithmic grid: // r(i) = a*(exp(b*i) - 1) const int numPoints = 2001; - double end = Vl.grid.End(); - double step = 0.00625; - double scale = end / (expm1(step * (numPoints - 1))); + double end = Vl.grid.End(); + double step = 0.00625; + double scale = end/(expm1(step*(numPoints-1))); if (writeVl) writer.StartElement("vps"); else @@ -36,8 +41,7 @@ void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl writer.WriteAttribute("principal-n", n_principal); writer.WriteAttribute("l", channels[l]); writer.WriteAttribute("spin", -1); - if (writeVl) - { + if (writeVl) { writer.WriteAttribute("cutoff", Cutoff); writer.WriteAttribute("occupation", Occupation); } @@ -50,17 +54,14 @@ void ChannelPotentialClass::WriteChannelLog(XMLWriterClass& writer, bool writeVl writer.WriteAttribute("npts", numPoints); writer.EndElement(); // "grid" std::vector data; - for (int i = 0; i < numPoints; i++) - { - double r = scale * (expm1(step * i)); - if (writeVl) - { - double rmin = std::min(r, Vl.grid.End()); + for (int i=0; i data; - for (int i = 0; i < numPoints; i++) - { - double r = dr * (double)i; - if (writeVl) - { - r = std::min(r, ul.grid.End()); + for (int i=0; i vl(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - double r = (double)ir * dr; - vl[ir] = (ir == 0) ? pot.Vl(0.0) : pot.Vlr(r) / r; + for (int ir=0; ir ul(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - double r = (ir == 0) ? 1.0e-8 : (double)ir * dr; - ul[ir] = pot.ul(r) / r; + for (int ir=0; ir input/default value)\n0 0\n"); - fprintf(fout, "Number of grid points\n%d\n", numPoints); - fprintf(fout, "R(i) in atomic units\n"); - for (int i = 0; i < numPoints; i++) - { - double r = (double)i / (double)(numPoints - 1) * rMax; - fprintf(fout, " %22.16e\n", r); + fprintf (fout, "Pseudopotential in real space for %s\n", + ZToSymbolMap[AtomicNumber].c_str()); + fprintf (fout, "Atomic number and pseudo-charge\n%d %1.2f\n", + AtomicNumber, PseudoCharge); + fprintf (fout, "Energy units (rydberg/hartree/ev):\nrydberg\n"); + fprintf (fout, "Angular momentum of local component (0=s,1=p,2=d..)\n%d\n", + LocalChannel); + fprintf (fout, "NLRULE override (1) VMC/DMC (2) config gen " + "(0 ==> input/default value)\n0 0\n"); + fprintf (fout, "Number of grid points\n%d\n", + numPoints); + fprintf (fout, "R(i) in atomic units\n"); + for (int i=0; i& data, int indent) +void +PseudoClass::Write4Block (FILE *fout, std::vector& data, int indent) { int N = data.size(); - for (int i = 0; i < N / 4; i++) - { - for (int j = 0; j < indent; j++) - fprintf(fout, " "); - fprintf(fout, "%17.11e %1.17e %1.17e %1.17e\n", data[4 * i + 0], data[4 * i + 1], data[4 * i + 2], data[4 * i + 3]); + for (int i=0; i\n"); - fprintf(fout, "Generated using ppconvert\n"); + fprintf (fout, "\n"); + fprintf (fout, "Generated using ppconvert\n"); // Get date - time_t now = time(NULL); - struct tm& ltime = *(localtime(&now)); + time_t now = time(NULL); + struct tm <ime = *(localtime (&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((mon < 10) ? "0" : "") << mon << "/"; - date << ((day < 10) ? "0" : "") << day << "/"; - date << ((year < 10) ? "0" : "") << year; - fprintf(fout, "Author: Kenneth P. Esler Generation date: %s\n", date.str().c_str()); + date << ((mon<10) ? "0" : "") << mon << "/"; + date << ((day<10) ? "0" : "") << day << "/"; + date << ((year<10) ? "0" : "") << year; + fprintf (fout, "Author: Kenneth P. Esler Generation date: %s\n", + date.str().c_str()); - fprintf(fout, "\n"); + fprintf (fout, "\n"); // Write PP_HEADER section - fprintf(fout, "\n"); - fprintf(fout, " 0 Version Number\n"); - fprintf(fout, " %2s Element\n", ZToSymbolMap[AtomicNumber].c_str()); - fprintf(fout, " NC Norm - Conserving pseudopotential\n"); - fprintf(fout, " F Nonlinear Core Correction\n"); + fprintf (fout, "\n"); + fprintf (fout, " 0 Version Number\n"); + fprintf (fout, " %2s Element\n", + ZToSymbolMap[AtomicNumber].c_str()); + fprintf (fout, " NC Norm - Conserving pseudopotential\n"); + fprintf (fout, " F Nonlinear Core Correction\n"); std::string F_EX, F_CORR, F_XC_GRAD, F_CORR_GRAD; - F_EX = "SLA"; - F_CORR = "PW"; - F_XC_GRAD = "PBE"; + F_EX = "SLA"; + F_CORR = "PW"; + F_XC_GRAD = "PBE"; F_CORR_GRAD = "PBE"; - fprintf(fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), - F_CORR_GRAD.c_str()); - fprintf(fout, " %1.10f Z valence\n", PseudoCharge); - fprintf(fout, " %1.10f Total energy\n", TotalEnergy); - fprintf(fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", 0.0, 0.0); - fprintf(fout, " %ld Max angular momentum component\n", ChannelPotentials.size() - 1); - fprintf(fout, " %4d Number of points in mesh\n", N); - fprintf(fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), - ChannelPotentials.size() - 1); - fprintf(fout, " WaveFunctions nl l occ \n"); - for (int l = 0; l < ChannelPotentials.size(); l++) - fprintf(fout, " %d%s %d %1.4f\n", ChannelPotentials[l].n_principal, ChannelMap[l].c_str(), - ChannelPotentials[l].l, ChannelPotentials[l].Occupation); - - fprintf(fout, "\n"); + fprintf (fout, " %4s %4s %4s %4s Exchange-Corelation functional\n", + F_EX.c_str(), F_CORR.c_str(), F_XC_GRAD.c_str(), F_CORR_GRAD.c_str()); + fprintf (fout, " %1.10f Z valence\n", + PseudoCharge); + fprintf (fout, " %1.10f Total energy\n", TotalEnergy); + fprintf (fout, " %3.6f %3.6f Suggested cutoff for wfc and rho\n", + 0.0, 0.0); + fprintf (fout, " %ld Max angular momentum component\n", + ChannelPotentials.size()-1); + fprintf (fout, " %4d Number of points in mesh\n", + N); + fprintf (fout, " %ld %ld Number of Wavefunctions, Number of Projectors\n", ChannelPotentials.size(), ChannelPotentials.size()-1); + fprintf (fout, " WaveFunctions nl l occ \n"); + for (int l=0; l\n"); // Write PP_MESH section - fprintf(fout, "\n"); - fprintf(fout, " \n"); - Write4Block(fout, PotentialGrid.Points()); - fprintf(fout, " \n"); - fprintf(fout, " \n"); + fprintf (fout, "\n"); + fprintf (fout, " \n"); + Write4Block (fout, PotentialGrid.Points()); + fprintf (fout, " \n"); + fprintf (fout, " \n"); std::vector dr(N); - for (int i = 1; i < (N - 1); i++) - dr[i] = 0.5 * (PotentialGrid[i + 1] - PotentialGrid[i - 1]); - dr[0] = 2.0 * dr[1] - dr[2]; - dr[N - 1] = 2.0 * dr[N - 2] - dr[N - 3]; + for (int i=1; i<(N-1); i++) + dr[i] = 0.5*(PotentialGrid[i+1]-PotentialGrid[i-1]); + dr[0] = 2.0*dr[ 1 ]-dr[ 2 ]; + dr[N-1] = 2.0*dr[N-2]-dr[N-3]; - Write4Block(fout, dr); - fprintf(fout, " \n"); - fprintf(fout, "\n"); + Write4Block (fout, dr); + fprintf (fout, " \n"); + fprintf (fout, "\n"); // Write PP_LOCAL section - fprintf(fout, "\n"); + fprintf (fout, "\n"); std::vector vloc(N); - for (int i = 0; i < N; i++) - vloc[i] = 2.0 * ChannelPotentials[LocalChannel].Vl(i); // /PotentialGrid[i]; + for (int i=0; i\n"); + Write4Block (fout, vloc); + fprintf (fout, "\n"); // Write the nonlocal section - fprintf(fout, "\n"); + fprintf (fout, "\n"); int betaNum = 1; - for (int l = 0; l < ChannelPotentials.size(); l++) - if (l != LocalChannel) - { + for (int l=0; l beta(N); - for (int i = 0; i < N; i++) - { - double Vloc = ChannelPotentials[LocalChannel].Vlr(i); - double Vl = ChannelPotentials[l].Vlr(i); - double ul = ChannelPotentials[l].ul(i); - double r = PotentialGrid[i]; - beta[i] = 2.0 * ul * (Vl - Vloc) / r; - //beta[i] = 2.0*ul*(Vl - Vloc); - //beta[i] = 2.0*r*ul*(Vl - Vloc); + for (int i=0; i\n"); - fprintf(fout, " %d %d Beta L\n", betaNum, l); - fprintf(fout, " %d \n", N); - Write4Block(fout, beta, 4); - fprintf(fout, " \n"); + beta[0] = 2.0*ChannelPotentials[l].ul(0.0)* + (ChannelPotentials[l].Vlr(1.0e-7)-ChannelPotentials[LocalChannel].Vlr(1.0e-7))/1.0e-7; +// beta[0] = 2.0*ChannelPotentials[l].ul(0.0)* +// (ChannelPotentials[l].Vl(1.0e-7)-ChannelPotentials[LocalChannel].Vl(1.0e-7)); + fprintf (fout, " \n"); + fprintf (fout, " %d %d Beta L\n", betaNum, l); + fprintf (fout, " %d \n", N); + Write4Block (fout, beta, 4); + fprintf (fout, " \n"); betaNum++; } // Write D_ij matrix - fprintf(fout, " \n"); - fprintf(fout, " %ld Number of nonzero Dij\n", ChannelPotentials.size() - 1); + fprintf (fout, " \n"); + fprintf (fout, " %ld Number of nonzero Dij\n", + ChannelPotentials.size()-1); betaNum = 1; // Compute D_ij matrix. In our case, with single projectors, D_ij // is diagonal. The elements are // D_ll = 1.0/ // We will numerically integrate with Simpson's rule - for (int l = 0; l < ChannelPotentials.size(); l++) - if (l != LocalChannel) - { - const int M = 100000; + for (int l=0; l\n"); - fprintf(fout, "\n"); + fprintf (fout, " \n"); + fprintf (fout, "\n"); // Write PP_PSWFC section - fprintf(fout, "\n"); - for (int l = 0; l < ChannelPotentials.size(); l++) - { - ChannelPotentialClass& pot = ChannelPotentials[l]; - fprintf(fout, "%d%s %d %6.4f Wavefunction\n", pot.n_principal, ChannelMap[l].c_str(), l, - pot.Occupation); + fprintf (fout, "\n"); + for (int l=0; l u(N); - for (int i = 0; i < N; i++) + for (int i=0; i\n"); + fprintf (fout, "\n"); // Write PP_RHOATOM section - fprintf(fout, "\n"); + fprintf (fout, "\n"); std::vector rho_at(N); - for (int i = 0; i < N; i++) - { + for (int i=0; i\n"); + fprintf (fout, "\n"); // Close the file - fclose(fout); + fclose (fout); } -void PseudoClass::WriteFHI(std::string fileName) +void +PseudoClass::WriteFHI (std::string fileName) { - const double amesh = 1.013084867359809; + const double amesh = 1.013084867359809; const int numPoints = 1118; - FILE* fout = fopen(fileName.c_str(), "w"); - assert(fout != NULL); + FILE *fout = fopen (fileName.c_str(), "w"); + assert (fout != NULL); // Write ABINIT header - fprintf(fout, "Written by ppconvert: %s psuedopotential\n", ZToSymbolMap[AtomicNumber].c_str()); - time_t now = time(NULL); - struct tm& ltime = *(localtime(&now)); + fprintf (fout, "Written by ppconvert: %s psuedopotential\n", + ZToSymbolMap[AtomicNumber].c_str()); + time_t now = time(NULL); + struct tm <ime = *(localtime (&now)); std::stringstream date; int year = ltime.tm_year % 100; int mon = ltime.tm_mon + 1; int day = ltime.tm_mday; - date << ((year < 10) ? "0" : "") << year; - date << ((mon < 10) ? "0" : "") << mon; - date << ((day < 10) ? "0" : "") << day; - - fprintf(fout, - "%9.5f %9.5f %s" - " zatom, zion, pspdat\n", - (double)AtomicNumber, PseudoCharge, date.str().c_str()); - - fprintf(fout, - " 6 7 %ld %d %d 0.0000 " - "pspcod,pspxc,lmax,lloc,mmax,r2well\n", - ChannelPotentials.size() - 1, LocalChannel, numPoints); - fprintf(fout, - " 0.00000 0.00000 0.00000 " - "rchrg,fchrg,qchrg\n"); - fprintf(fout, - "5 --- reserved for future features\n" - "6 --- reserved for future features\n" - "7 --- Here follows the cpi file in the fhi98pp format -\n"); + date << ((year<10) ? "0" : "") << year; + date << ((mon<10) ? "0" : "") << mon; + date << ((day<10) ? "0" : "") << day; + + fprintf (fout, "%9.5f %9.5f %s" + " zatom, zion, pspdat\n", (double)AtomicNumber, + PseudoCharge, date.str().c_str()); + + fprintf (fout, " 6 7 %ld %d %d 0.0000 " + "pspcod,pspxc,lmax,lloc,mmax,r2well\n", + ChannelPotentials.size()-1, LocalChannel, numPoints); + fprintf (fout, " 0.00000 0.00000 0.00000 " + "rchrg,fchrg,qchrg\n"); + fprintf (fout, "5 --- reserved for future features\n" + "6 --- reserved for future features\n" + "7 --- Here follows the cpi file in the fhi98pp format -\n"); // Write FHI file proper - fprintf(fout, "%d %ld\n", (int)round(PseudoCharge), ChannelPotentials.size()); - for (int i = 0; i < 10; i++) - fprintf(fout, "0.0 0.0 0.0\n"); - - for (int l = 0; l < ChannelPotentials.size(); l++) - { - fprintf(fout, "%d %1.18f\n", numPoints, amesh); - double r = 5.848035476425733e-05; + fprintf (fout, "%d %ld\n", (int)round(PseudoCharge), + ChannelPotentials.size()); + for (int i=0; i<10; i++) + fprintf (fout, "0.0 0.0 0.0\n"); + + for (int l=0; l= ChannelPotentials[l].Vl.grid.End()) - Vl = -1.0 * PseudoCharge / r; + Vl = -1.0*PseudoCharge/r; else - Vl = ChannelPotentials[l].Vl(r); // /r; + Vl = ChannelPotentials[l].Vl(r); // /r; double Vlold = Vl; - Vl = ChannelPotentials[l].Vlr(r) / r; + Vl = ChannelPotentials[l].Vlr(r)/r; if (i == 0) - Vl = ChannelPotentials[l].Vl(0.0); + Vl = ChannelPotentials[l].Vl(0.0); // fprintf (stderr, "r = %1.10f Interp diff = %1.8e\n", r, Vl-Vlold); - fprintf(fout, "%23.16e ", Vl); - if ((i % 3) == 2) - fprintf(fout, "\n"); + fprintf (fout, "%23.16e ", Vl); + if ((i%3)==2) + fprintf (fout, "\n"); } } // Now write out radial wave functions - for (int l = 0; l < ChannelPotentials.size(); l++) - { - fprintf(fout, "%d = l for CASINO wave function\n", l); - for (int i = 0; i < mmax; i++) - { - double x = (double)i / (double)(mmax - 1); - x += 0.01; - double r = 100.0 * x * x * x * x * x - 1.0e-8; - double ul; - double rend = ChannelPotentials[l].ul.grid.End(); - if (r >= rend) - { - int i = ChannelPotentials[l].ul.grid.NumPoints(); - while (fabs(ChannelPotentials[l].ul(i)) == 0.0) - i--; - double r2 = ChannelPotentials[l].ul.grid[i]; - double r1 = ChannelPotentials[l].ul.grid[i - 10]; - double u2 = ChannelPotentials[l].ul(i); - double u1 = ChannelPotentials[l].ul(i - 10); - double alpha = log(u1 / u2) / (r2 - r1); - // rend = min (rend, 60.0); - // double uend = ChannelPotentials[l].ul(rend); - // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); - //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; - // ul = uend * exp(-alpha*(r-rend)); - ul = u2 * exp(-alpha * (r - r2)); + for (int l=0; l= rend) { + int i=ChannelPotentials[l].ul.grid.NumPoints(); + while (fabs(ChannelPotentials[l].ul(i)) == 0.0) i--; + double r2 = ChannelPotentials[l].ul.grid[i]; + double r1 = ChannelPotentials[l].ul.grid[i-10]; + double u2 = ChannelPotentials[l].ul(i); + double u1 = ChannelPotentials[l].ul(i-10); + double alpha = log(u1/u2)/(r2-r1); + // rend = min (rend, 60.0); + // double uend = ChannelPotentials[l].ul(rend); + // double alpha = log (ChannelPotentials[l].ul(rend-1.0)/uend); + //cerr << "alpha = " << alpha << " rend = " << r2 << " u2 = " << u2 << endl; + // ul = uend * exp(-alpha*(r-rend)); + ul = u2 * exp(-alpha*(r - r2)); + } + else + ul= ChannelPotentials[l].ul(r); + fprintf (fout, "%23.16e ", ul); + if ((i%3)==2) + fprintf (fout, "\n"); } - else - ul = ChannelPotentials[l].ul(r); - fprintf(fout, "%23.16e ", ul); - if ((i % 3) == 2) - fprintf(fout, "\n"); - } } - fclose(fout); + fclose (fout); } -void PseudoClass::WriteASCII() +void +PseudoClass::WriteASCII() { - FILE* fout = fopen("pp.dat", "w"); - for (int i = 1; i < PotentialGrid.NumPoints(); i++) - { - double r = PotentialGrid[i]; - fprintf(fout, "%24.16e ", r); - for (int l = 0; l < ChannelPotentials.size(); l++) - fprintf(fout, "%24.16e ", ChannelPotentials[l].Vl(r)); // /r); - fprintf(fout, "\n"); + FILE *fout = fopen ("pp.dat", "w"); + for (int i=1; i gridPoints, Vlocal, Vlocalr; - FILE* fout = fopen("Vlocal.dat", "w"); - for (double r = 1.0e-8; r < 150.0; r += 0.01) - { - gridPoints.push_back(r); - double Vloc = (c0 / r) * (expm1(-exp0 * r * r)) + c1 * r * exp(-exp1 * r * r) + c2 * exp(-exp2 * r * r); - double Vlocr = (c0) * (expm1(-exp0 * r * r)) + c1 * r * r * exp(-exp1 * r * r) + c2 * r * exp(-exp2 * r * r); + FILE *fout = fopen ("Vlocal.dat", "w"); + for (double r=1.0e-8; r<150.0; r+=0.01) { + gridPoints.push_back (r); + double Vloc = (c0/r)*(expm1(-exp0*r*r)) + + c1*r*exp(-exp1*r*r) + + c2*exp(-exp2*r*r); + double Vlocr = (c0)*(expm1(-exp0*r*r)) + + c1*r*r*exp(-exp1*r*r) + + c2*r*exp(-exp2*r*r); Vlocal.push_back(Vloc); Vlocalr.push_back(Vlocr); - fprintf(fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); + fprintf (fout, "%1.16e %1.16e %1.16e\n", r, Vloc, Vlocr); } - fclose(fout); + fclose (fout); int local = numProjectors; - if (LocalChannel < 0) - LocalChannel = local; - PotentialGrid.Init(gridPoints); + if (LocalChannel<0) LocalChannel = local; + PotentialGrid.Init (gridPoints); ChannelPotentials[local].Vl.Init(PotentialGrid, Vlocal); ChannelPotentials[local].Vlr.Init(PotentialGrid, Vlocalr); ChannelPotentials[local].l = local; // Now read nonlocal component - assert(parser.FindToken("Non-local component:")); - assert(parser.FindToken("Proj.")); - for (int l = 0; l < numProjectors; l++) - { + assert (parser.FindToken ("Non-local component:")); + assert (parser.FindToken ("Proj.")); + for (int l=0; l Vl(gridPoints.size()), Vlr(gridPoints.size()); - for (int i = 0; i < gridPoints.size(); i++) - { + for (int i=0; i 1.0e-10) - { + assert (parser.ReadDouble(chrg)); + if(fabs(chrg-PseudoCharge) > 1.0e-10) { std::cerr << "PseudoCharge = " << PseudoCharge << std::endl; std::cerr << "chrg = " << chrg << std::endl; } // Read number of channels and resize int numChannels; - assert(parser.ReadInt(numChannels)); + assert (parser.ReadInt(numChannels)); ChannelPotentials.resize(numChannels); // Skip the next 10 lines - for (int i = 0; i < 11; i++) - assert(parser.FindToken("\n")); + for (int i=0; i<11; i++) + assert (parser.FindToken("\n")); // Read the number of grid points - for (int l = 0; l < numChannels; l++) - { + for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), Vlr(numPoints); - for (int m = 0; m < numPoints; m++) - { + assert (parser.ReadInt(numPoints)); + assert (parser.ReadDouble(a_ratio)); + std::vector points(numPoints), ul(numPoints), Vl(numPoints), + Vlr(numPoints); + for (int m=0; m 0) && !diff) - { + int n = PotentialGrid.NumPoints()-1; + bool diff = false; + while ((n>0) && !diff) { double r = PotentialGrid[n]; - rmax = r; - for (int l1 = 0; l1 < numChannels; l1++) - { + rmax = r; + for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2=l1+1; l2 1.0e-5) + diff = true; } } n--; } - for (int l = 0; l < ChannelPotentials.size(); l++) + for (int l=0; l beta, u, V; KBprojector() {} - KBprojector(int l_, std::vector beta_) : l(l_), beta(beta_) {} + KBprojector(int l_, std::vector beta_) : + l(l_), beta(beta_) {} }; -bool PseudoClass::ReadUPF_PP(std::string fileName) +bool +PseudoClass::ReadUPF_PP (std::string fileName) { MemParserClass parser; - if (!parser.OpenFile(fileName)) - { + if (!parser.OpenFile (fileName)) { std::cerr << "Could not open file \"" << fileName << "\". Exitting.\n"; exit(-1); } std::string temp; - assert(parser.FindToken("")); - assert(parser.NextLine()); + assert(parser.FindToken("")); assert(parser.NextLine()); // Skip version number assert(parser.NextLine()); std::string element, ppType, coreCorrection; - assert(parser.ReadWord(element)); - assert(parser.NextLine()); + assert(parser.ReadWord(element)); assert(parser.NextLine()); assert(SymbolToZMap.find(element) != SymbolToZMap.end()); AtomicNumber = SymbolToZMap[element]; // cerr << "Element = \"" << element << "\"\n"; assert(parser.ReadWord(ppType)); - if (ppType != "NC") - { - std::cerr << "Psuedopotential type \"" << ppType << "\" is not norm-conserving.\n"; + if (ppType != "NC") { + std::cerr << "Psuedopotential type \"" << ppType + << "\" is not norm-conserving.\n"; abort(); } - assert(parser.NextLine()); - assert(parser.ReadWord(coreCorrection)); - assert(parser.NextLine()); - if (coreCorrection != "F" && coreCorrection != "f" && coreCorrection != "false" && coreCorrection != "False" && - coreCorrection != ".F." && coreCorrection != ".f" && coreCorrection != "FALSE") - { + assert (parser.NextLine()); + assert (parser.ReadWord(coreCorrection)); assert(parser.NextLine()); + if (coreCorrection != "F" && coreCorrection != "f" && + coreCorrection != "false" && coreCorrection != "False" && + coreCorrection != ".F." && coreCorrection != ".f" && + coreCorrection != "FALSE") { std::cerr << "It appears that a nonlinear core correction was used. Cannot convert PP.\n"; abort(); } @@ -1309,45 +1230,42 @@ bool PseudoClass::ReadUPF_PP(std::string fileName) assert(parser.NextLine()); int numPoints; - assert(parser.ReadInt(numPoints)); - assert(parser.NextLine()); + assert(parser.ReadInt(numPoints)); assert(parser.NextLine()); int numWF, numProj; - assert(parser.ReadInt(numWF)); - assert(parser.ReadInt(numProj)); - int numChannels = numProj + 1; + assert (parser.ReadInt(numWF)); assert(parser.ReadInt(numProj)); + int numChannels = numProj+1; ChannelPotentials.resize(numChannels); assert(parser.FindToken("Wavefunctions")); - // for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector r(numPoints), dr(numPoints); - for (int i = 0; i < numPoints; i++) + for (int i=0; i")); PotentialGrid.Init(r); assert(parser.FindToken("")); - for (int i = 0; i < numPoints; i++) + for (int i=0; i")); assert(parser.FindToken("")); assert(parser.FindToken("")); std::vector Vlocal(numPoints); - for (int i = 0; i < numPoints; i++) - { + for (int i=0; i lmap; + std::map lmap; std::vector projectors; - for (int proj = 0; proj < numProj; proj++) - { - assert(parser.FindToken("")); + for (int proj=0; proj")); int Beta; - assert(parser.ReadInt(Beta)); - assert(Beta == (proj + 1)); + assert (parser.ReadInt(Beta)); + assert(Beta == (proj+1)); int l; - assert(parser.ReadInt(l)); - parser.NextLine(); + assert (parser.ReadInt(l)); parser.NextLine(); lmap[l] = proj; // fprintf (stderr, "Found a projector for l=%d\n", l); int npt; - assert(parser.ReadInt(npt)); + assert (parser.ReadInt(npt)); std::vector beta(numPoints); - for (int ir = 0; ir < numPoints; ir++) + for (int ir=0; ir")); + assert (parser.FindToken("")); projectors.push_back(KBprojector(l, beta)); } assert(parser.FindToken("")); - int llocal = 0; - while (lmap.find(llocal) != lmap.end()) - llocal++; + int llocal=0; + while (lmap.find(llocal) != lmap.end()) llocal++; LocalChannel = llocal; // fprintf (stderr, "First channel without a projector=%d\n", llocal); ChannelPotentials[llocal].Vl.Init(PotentialGrid, Vlocal); std::vector Vlocal_r(numPoints); - for (int ir = 0; ir < numPoints; ir++) - Vlocal_r[ir] = r[ir] * Vlocal[ir]; + for (int ir=0; ir wf(numPoints); - for (int ir = 0; ir < numPoints; ir++) - assert(parser.ReadDouble(wf[ir])); + for (int ir=0; ir Vl(numPoints), Vlr(numPoints); - for (int ir = 0; ir < numPoints; ir++) - { - Vl[ir] = Vlocal[ir]; - if (wf[ir] != 0.0) - Vl[ir] += proj.beta[ir] / (2.0 * wf[ir]); - Vlr[ir] = r[ir] * Vl[ir]; - } - Vl[0] = 2.0 * Vl[1] - Vl[2]; - Vlr[0] = r[0] * Vl[0]; - - // for (int ir=0; ir Vl(numPoints), Vlr(numPoints); + for (int ir=0; ir 0) && !diff) - { + int n = PotentialGrid.NumPoints()-1; + bool diff = false; + while ((n>0) && !diff) { double r = PotentialGrid[n]; - rmax = r; - for (int l1 = 0; l1 < numChannels; l1++) - { + rmax = r; + for (int l1=0; l1 1.0e-5) - diff = true; + for (int l2=l1+1; l2 1.0e-5) + diff = true; } } n--; } - fprintf(stderr, "rmax = %1.5f numChannels = %d\n", rmax, numChannels); - for (int l = 0; l < ChannelPotentials.size(); l++) + fprintf (stderr, "rmax = %1.5f numChannels = %d\n", rmax, numChannels); + for (int l=0; l 1.0e-10) { - // cerr << "PseudoCharge = " << PseudoCharge << endl; - // cerr << "chrg = " << chrg << endl; - // } - - // // Read number of channels and resize - // int numChannels; - // assert (parser.ReadInt(numChannels)); - // ChannelPotentials.resize(numChannels); - - // // Skip the next 10 lines - // for (int i=0; i<11; i++) - // assert (parser.FindToken("\n")); - - // // Read the number of grid points - // for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), - // Vlr(numPoints); - // for (int m=0; m0) && !diff) { - // double r = PotentialGrid[n]; - // rmax = r; - // for (int l1=0; l1 1.0e-5) - // diff = true; - // } - // } - // n--; - // } - // for (int l=0; l 1.0e-10) { +// cerr << "PseudoCharge = " << PseudoCharge << endl; +// cerr << "chrg = " << chrg << endl; +// } + +// // Read number of channels and resize +// int numChannels; +// assert (parser.ReadInt(numChannels)); +// ChannelPotentials.resize(numChannels); + +// // Skip the next 10 lines +// for (int i=0; i<11; i++) +// assert (parser.FindToken("\n")); + +// // Read the number of grid points +// for (int l=0; l points(numPoints), ul(numPoints), Vl(numPoints), +// Vlr(numPoints); +// for (int m=0; m0) && !diff) { +// double r = PotentialGrid[n]; +// rmax = r; +// for (int l1=0; l1 1.0e-5) +// diff = true; +// } +// } +// n--; +// } +// for (int l=0; l rPoints; - if (WriteLogGrid) - { + if (WriteLogGrid) { const int numPoints = 2001; - double end = 150.0; - double step = 0.00625; - double scale = end / (expm1(step * (numPoints - 1))); - for (int i = 1; i < numPoints; i++) - rPoints.push_back(scale * (expm1(step * i))); + double end = 150.0; + double step = 0.00625; + double scale = end/(expm1(step*(numPoints-1))); + for (int i=1; i coefs(ngpot), exponents(ngpot); std::vector powers(ngpot); // The local channel is given first - for (int i = 0; i < ngpot; i++) - { - assert(parser.ReadDouble(coefs[i])); - assert(parser.ReadInt(powers[i])); - assert(parser.ReadDouble(exponents[i])); - assert(parser.FindToken("\n")); + for (int i=0; i 1) - { - while (ir > 0 && !done) - { + bool done=false; + int ir = rPoints.size()-1; + if (ChannelPotentials.size() > 1) { + while (ir > 0 && !done) { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - for (int l = 0; l < ChannelPotentials.size(); l++) - if (ChannelPotentials[l].l != LocalChannel) - if (fabs(ChannelPotentials[l].Vl(ir) - vlocal) > 1.0e-5) - done = true; + for (int l=0; l 1.0e-5) + done = true; ir--; } } - else - { - while (ir > 0 && !done) - { + else { + while (ir > 0 && !done) { double vlocal = ChannelPotentials[LocalChannel].Vl(ir); - double r = rPoints[ir]; - done = fabs(vlocal + PseudoCharge / r) > 1.0e-5; + double r = rPoints[ir]; + done = fabs (vlocal + PseudoCharge/r) > 1.0e-5; ir--; } } - for (int l = 0; l < ChannelPotentials.size(); l++) + for (int l=0; l= '0' && s[pos] <= '9') sint.push_back(s[pos++]); - s.erase(0, pos); - n = atoi(sint.c_str()); + s.erase(0,pos); + n = atoi (sint.c_str()); return true; } -bool ReadDouble(std::string& s, double& x) +bool +ReadDouble (std::string &s, double &x) { - int pos = 0; + int pos=0; std::string sd; - while ((s[pos] >= '0' && s[pos] <= '9') || s[pos] == '.') + while ((s[pos] >= '0' && s[pos] <= '9') || s[pos]=='.') sd.push_back(s[pos++]); - s.erase(0, pos); + s.erase(0,pos); x = strtod(sd.c_str(), (char**)NULL); return true; } @@ -1718,169 +1617,161 @@ Config::Config(std::string s) ChannelRevMap['d'] = 2; ChannelRevMap['f'] = 3; ChannelRevMap['g'] = 4; - while (s.size() > 0) - { + while (s.size() > 0) { int n, l; double occ; - ReadInt(s, n); + ReadInt (s, n); l = ChannelRevMap[s[0]]; - s.erase(0, 1); - assert(s[0] == '('); - s.erase(0, 1); - ReadDouble(s, occ); - assert(s[0] == ')'); - s.erase(0, 1); - States.push_back(State(n, l, occ)); + s.erase(0,1); + assert (s[0] == '('); + s.erase(0,1); + ReadDouble (s, occ); + assert (s[0] == ')'); + s.erase(0,1); + States.push_back (State(n,l,occ)); } } -bool PseudoClass::ReadCASINO_PP(std::string fileName) + +bool +PseudoClass::ReadCASINO_PP (std::string fileName) { MemParserClass parser; - parser.OpenFile(fileName); - - assert(parser.FindToken("pseudo-charge")); - assert(parser.ReadInt(AtomicNumber)); - assert(parser.ReadDouble(PseudoCharge)); - assert(parser.FindToken("(rydberg/hartree/ev)")); - assert(parser.FindToken("\n")); - assert(parser.ReadWord(EnergyUnit)); + parser.OpenFile (fileName); + + assert (parser.FindToken("pseudo-charge")); + assert (parser.ReadInt (AtomicNumber)); + assert (parser.ReadDouble (PseudoCharge)); + assert (parser.FindToken("(rydberg/hartree/ev)")); + assert (parser.FindToken("\n")); + assert (parser.ReadWord(EnergyUnit)); std::cerr << "EnergyUnit = " << EnergyUnit << std::endl; - assert(parser.FindToken("(0=s,1=p,2=d..)")); - assert(parser.ReadInt(LocalChannel)); - assert(parser.FindToken("grid points")); + assert (parser.FindToken("(0=s,1=p,2=d..)")); + assert (parser.ReadInt (LocalChannel)); + assert (parser.FindToken("grid points")); int numGridPoints; - assert(parser.ReadInt(numGridPoints)); - std::vector gridPoints(numGridPoints), Vl(numGridPoints), Vlr(numGridPoints); - assert(parser.FindToken("in")); - assert(parser.ReadWord(LengthUnit)); + assert (parser.ReadInt(numGridPoints)); + std::vector gridPoints(numGridPoints), Vl(numGridPoints), + Vlr(numGridPoints); + assert (parser.FindToken ("in")); + assert (parser.ReadWord(LengthUnit)); std::cerr << "LengthUnit = " << LengthUnit << std::endl; - assert(parser.FindToken("\n")); + assert (parser.FindToken("\n")); // assert (parser.FindToken("atomic units")); - for (int i = 0; i < numGridPoints; i++) - { - assert(parser.ReadDouble(gridPoints[i])); - gridPoints[i] *= UnitToBohrMap[LengthUnit]; + for (int i=0; i ul(numPoints); - for (int i = 0; i < numPoints; i++) - assert(parser.ReadDouble(ul[i])); + for (int i=0; i argList; // input formats - argList.push_back(ParamClass("fhi_pot", true)); + argList.push_back(ParamClass("fhi_pot", true)); argList.push_back(ParamClass("casino_pot", true)); - argList.push_back(ParamClass("bfd_pot", true)); + argList.push_back(ParamClass("bfd_pot", true)); argList.push_back(ParamClass("gamess_pot", true)); argList.push_back(ParamClass("upf_pot", true)); // Projector parameters - argList.push_back(ParamClass("casino_us", true)); - argList.push_back(ParamClass("casino_up", true)); - argList.push_back(ParamClass("casino_ud", true)); - argList.push_back(ParamClass("casino_uf", true)); - argList.push_back(ParamClass("s_ref", true)); - argList.push_back(ParamClass("p_ref", true)); - argList.push_back(ParamClass("d_ref", true)); - argList.push_back(ParamClass("f_ref", true)); - argList.push_back(ParamClass("g_ref", true)); - argList.push_back(ParamClass("xml", true)); - argList.push_back(ParamClass("tm", true)); - argList.push_back(ParamClass("upf", true)); - argList.push_back(ParamClass("fhi", true)); - argList.push_back(ParamClass("fpmd", true)); + argList.push_back(ParamClass("casino_us", true)); + argList.push_back(ParamClass("casino_up", true)); + argList.push_back(ParamClass("casino_ud", true)); + argList.push_back(ParamClass("casino_uf", true)); + argList.push_back(ParamClass("s_ref", true)); + argList.push_back(ParamClass("p_ref", true)); + argList.push_back(ParamClass("d_ref", true)); + argList.push_back(ParamClass("f_ref", true)); + argList.push_back(ParamClass("g_ref", true)); + argList.push_back(ParamClass("xml", true)); + argList.push_back(ParamClass("tm", true)); + argList.push_back(ParamClass("upf", true)); + argList.push_back(ParamClass("fhi", true)); + argList.push_back(ParamClass("fpmd", true)); argList.push_back(ParamClass("casino", true)); argList.push_back(ParamClass("log_grid", false)); argList.push_back(ParamClass("local_channel", true)); @@ -1993,38 +1884,37 @@ int main(int argc, char** argv) CommandLineParserClass parser(argList); bool success = parser.Parse(argc, argv); - if (!success || parser.NumFiles() != 0) - { + if (!success || parser.NumFiles()!=0) { std::cerr << "Usage: ppconvert options\n" - << " Options include: \n" - << " Input formats: \n" - << " --casino_pot fname \n" - << " --fhi_pot fname \n" - << " --upf_pot fname \n" - << " --bfd_pot fname \n" - << " --gamess_pot fname \n" - << " Output formats: \n" - << " --xml fname.xml \n" - << " --tm fname.tm \n" - << " --upf fname.upf \n" - << " --fhi fname.fhi \n" - << " --fpmd fname.xml \n" - << " --casino fname.xml \n" - << " Reference states:\n" - << " --casino_us fname \n" - << " --casino_up fname \n" - << " --casino_ud fname \n" - << " --casino_uf fname \n" - << " --casino_ug fname \n" - << " --s_ref state \n" - << " --p_ref state \n" - << " --d_ref state \n" - << " --f_ref state \n" - << " --g_ref state \n" - << " Other options: \n" - << " --log_grid \n" - << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" - << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; + << " Options include: \n" + << " Input formats: \n" + << " --casino_pot fname \n" + << " --fhi_pot fname \n" + << " --upf_pot fname \n" + << " --bfd_pot fname \n" + << " --gamess_pot fname \n" + << " Output formats: \n" + << " --xml fname.xml \n" + << " --tm fname.tm \n" + << " --upf fname.upf \n" + << " --fhi fname.fhi \n" + << " --fpmd fname.xml \n" + << " --casino fname.xml \n" + << " Reference states:\n" + << " --casino_us fname \n" + << " --casino_up fname \n" + << " --casino_ud fname \n" + << " --casino_uf fname \n" + << " --casino_ug fname \n" + << " --s_ref state \n" + << " --p_ref state \n" + << " --d_ref state \n" + << " --f_ref state \n" + << " --g_ref state \n" + << " Other options: \n" + << " --log_grid \n" + << " --local_channel l (l=0(s),1(p),2(d),3(f),..., default largest possible) \n" + << " --density_mix beta (0 <= beta < 1.0, default 0.75) \n"; exit(1); } @@ -2044,88 +1934,76 @@ int main(int argc, char** argv) if (parser.Found("casino_pot")) nlpp.ReadCASINO_PP(parser.GetArg("casino_pot")); - else if (parser.Found("bfd_pot")) - nlpp.ReadBFD_PP(parser.GetArg("bfd_pot")); - else if (parser.Found("fhi_pot")) - nlpp.ReadFHI_PP(parser.GetArg("fhi_pot")); - else if (parser.Found("upf_pot")) - nlpp.ReadUPF_PP(parser.GetArg("upf_pot")); - else if (parser.Found("gamess_pot")) - nlpp.ReadGAMESS_PP(parser.GetArg("gamess_pot")); - else - { + else if (parser.Found ("bfd_pot")) + nlpp.ReadBFD_PP (parser.GetArg ("bfd_pot")); + else if (parser.Found ("fhi_pot")) + nlpp.ReadFHI_PP (parser.GetArg ("fhi_pot")); + else if (parser.Found ("upf_pot")) + nlpp.ReadUPF_PP (parser.GetArg ("upf_pot")); + else if (parser.Found ("gamess_pot")) + nlpp.ReadGAMESS_PP (parser.GetArg("gamess_pot")); + else { std::cerr << "Need to specify a potential file with --casino_pot " - << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; + << "or --bfd_pot or --fhi_pot or --upf_pot or --gamess_pot.\n"; exit(1); } // Now check how the projectors are specified - if (!nlpp.HaveProjectors()) - { + if (!nlpp.HaveProjectors()) { int numChannels = nlpp.GetNumChannels(); - if (numChannels > 0) - { - if (parser.Found("s_ref")) - nlpp.CalcProjector(parser.GetArg("s_ref"), 0); + if (numChannels > 0) { + if (parser.Found ("s_ref")) + nlpp.CalcProjector (parser.GetArg("s_ref"), 0); else if (parser.Found("casino_us")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); - else - { - std::cerr << "Please specify the s-channel projector with either " - << " --s_ref or --casino_us.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_us"), 0); + else { + std::cerr << "Please specify the s-channel projector with either " + << " --s_ref or --casino_us.\n"; + // exit(-1); } } - if (numChannels > 1) - { - if (parser.Found("p_ref")) - nlpp.CalcProjector(parser.GetArg("p_ref"), 1); + if (numChannels > 1) { + if (parser.Found ("p_ref")) + nlpp.CalcProjector (parser.GetArg("p_ref"), 1); else if (parser.Found("casino_up")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); - else - { - std::cerr << "Please specify the p-channel projector with either " - << " --p_ref or --casino_up.\n"; - // exit(-1); + nlpp.ReadCASINO_WF(parser.GetArg("casino_up"), 1); + else { + std::cerr << "Please specify the p-channel projector with either " + << " --p_ref or --casino_up.\n"; + // exit(-1); } } - if (numChannels > 2) - { - if (parser.Found("d_ref")) - nlpp.CalcProjector(parser.GetArg("d_ref"), 2); - else if (parser.Found("casino_ud")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); - else - { - std::cerr << "Please specify the d-channel projector with either " - << " --d_ref or --casino_ud.\n"; - // exit(-1); + if (numChannels > 2) { + if (parser.Found ("d_ref")) + nlpp.CalcProjector (parser.GetArg("d_ref"), 2); + else if(parser.Found("casino_ud")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ud"), 2); + else { + std::cerr << "Please specify the d-channel projector with either " + << " --d_ref or --casino_ud.\n"; + // exit(-1); } } - if (numChannels > 3) - { - if (parser.Found("f_ref")) - nlpp.CalcProjector(parser.GetArg("f_ref"), 3); - else if (parser.Found("casino_uf")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); - else - { - std::cerr << "Please specify the f-channel projector with either " - << " --f_ref or --casino_uf.\n"; - // exit(-1); + if (numChannels > 3) { + if (parser.Found ("f_ref")) + nlpp.CalcProjector (parser.GetArg("f_ref"), 3); + else if(parser.Found("casino_uf")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_uf"), 3); + else { + std::cerr << "Please specify the f-channel projector with either " + << " --f_ref or --casino_uf.\n"; + // exit(-1); } } - if (numChannels > 4) - { - if (parser.Found("g_ref")) - nlpp.CalcProjector(parser.GetArg("g_ref"), 4); - else if (parser.Found("casino_ug")) - nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); - else - { - std::cerr << "Please specify the g-channel projector with either " - << " --g_ref or --casino_ug.\n"; - // exit(-1); + if (numChannels > 4) { + if (parser.Found ("g_ref")) + nlpp.CalcProjector (parser.GetArg("g_ref"), 4); + else if(parser.Found("casino_ug")) + nlpp.ReadCASINO_WF(parser.GetArg("casino_ug"), 4); + else { + std::cerr << "Please specify the g-channel projector with either " + << " --g_ref or --casino_ug.\n"; + // exit(-1); } } } @@ -2135,27 +2013,30 @@ int main(int argc, char** argv) nlpp.WriteXML(parser.GetArg("xml")); if (parser.Found("tm")) nlpp.WriteABINIT(parser.GetArg("tm")); - if (parser.Found("upf")) - nlpp.WriteUPF(parser.GetArg("upf")); - if (parser.Found("fhi")) - nlpp.WriteFHI(parser.GetArg("fhi")); - if (parser.Found("fpmd")) - nlpp.WriteFPMD(parser.GetArg("fpmd")); - if (parser.Found("casino")) - nlpp.WriteCASINO(parser.GetArg("casino")); - - // nlpp.WriteXML(xmlFile); - // nlpp.WriteABINIT(); + if (parser.Found ("upf")) + nlpp.WriteUPF (parser.GetArg("upf")); + if (parser.Found ("fhi")) + nlpp.WriteFHI (parser.GetArg("fhi")); + if (parser.Found ("fpmd")) + nlpp.WriteFPMD (parser.GetArg("fpmd")); + if (parser.Found ("casino")) + nlpp.WriteCASINO (parser.GetArg("casino")); + +// nlpp.WriteXML(xmlFile); +// nlpp.WriteABINIT(); nlpp.WriteASCII(); - // nlpp.ReadCASINO_PP ("b_pp.data.HF"); - // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); - // nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); - // nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); - // nlpp.WriteXML("test.xml"); +// nlpp.ReadCASINO_PP ("b_pp.data.HF"); +// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 0); +// nlpp.ReadCASINO_WF ("awfn.data_s2p1_2P", 1); +// nlpp.ReadCASINO_WF ("awfn.data_s2d1_2D", 2); +// nlpp.WriteXML("test.xml"); } + + + #include "common/IO.h" //Array vector2Array(std::vector &vec) @@ -2167,54 +2048,53 @@ int main(int argc, char** argv) //} -bool PseudoClass::GetNextState(std::string& state, int& n, int& l, double& occ) + +bool +PseudoClass::GetNextState (std::string &state, int &n, int &l, double &occ) { if (state.length() <= 0) return false; - if ((state[0] < '1') || (state[0] > '9')) - { + if ((state[0]<'1') || (state[0] > '9')) { std::cerr << "Error parsing reference state.\n"; abort(); } - n = state[0] - '0'; - std::string channel = state.substr(1, 1); - if ((channel != "s") && (channel != "p") && (channel != "d") && (channel != "f") && (channel != "g")) - { + n = state[0] - '0'; + std::string channel = state.substr (1,1); + if ((channel != "s") && (channel != "p") && + (channel != "d") && (channel != "f") && (channel != "g")) { std::cerr << "Unrecognized angular momentum channel in reference state.\n"; abort(); } l = ChannelRevMap[channel]; // cerr << "n=" << n << " l=" << l << endl; - if (state[2] != '(') - { + if (state[2] != '(') { std::cerr << "Error parsing occupancy in reference state.\n"; abort(); } - state.erase(0, 3); + state.erase(0,3); std::string occString; - while ((state.length() > 0) && (state[0] != ')')) - { - occString.append(state.substr(0, 1)); - state.erase(0, 1); + while ((state.length() > 0) && (state[0] != ')')) { + occString.append (state.substr(0,1)); + state.erase(0,1); } - char* endptr; - const char* occStr = occString.c_str(); - occ = strtod(occStr, &endptr); - if (state[0] != ')') - { + char *endptr; + const char *occStr = occString.c_str(); + occ = strtod (occStr, &endptr); + if (state[0] != ')') { std::cerr << "Expected a ')' in parsing reference state.\n"; abort(); } - state.erase(0, 1); + state.erase(0,1); return true; } #include "common/DFTAtom.h" -void PseudoClass::CalcProjector(std::string refstate, int lchannel) +void +PseudoClass::CalcProjector(std::string refstate, int lchannel) { DFTAtom atom; std::string saveState = refstate; @@ -2225,70 +2105,87 @@ void PseudoClass::CalcProjector(std::string refstate, int lchannel) int n, l; double occ; int lindex = -1; - int index = 0; - while (GetNextState(refstate, n, l, occ)) - { - nList.push_back(n); - lList.push_back(l); - occList.push_back(occ); + int index = 0; + while (GetNextState(refstate, n, l, occ)) { + nList.push_back (n); + lList.push_back (l); + occList.push_back (occ); if (l == lchannel && lindex == -1) lindex = index; index++; } - if (lindex == -1) - { - nList.push_back(lchannel + 1); + if (lindex == -1) { + nList.push_back(lchannel+1); lList.push_back(lchannel); occList.push_back(0.0); - lindex = nList.size() - 1; + lindex = nList.size()-1; } atom.RadialWFs.resize(nList.size()); - for (int i = 0; i < atom.RadialWFs.size(); i++) - { + for (int i=0; i optimalGrid = std::make_shared(PseudoCharge, PotentialGrid.End()); - atom.SetGrid(optimalGrid); + std::shared_ptr grid = std::make_shared(PseudoCharge, PotentialGrid.End()); + atom.SetGrid (grid); // Set the potential - atom.SetBarePot(this); + atom.SetBarePot (this); // Solve atom atom.NewMix = DensityMix; std::cerr << "Solving atom for reference state " << saveState << ":\n"; atom.Solve(); // Now, initialize the channel u functions - std::vector ul(PotentialGrid.NumPoints()), rhoAtom(PotentialGrid.NumPoints()); - for (int i = 0; i < ul.size(); i++) - { - double r = PotentialGrid[i]; - ul[i] = sqrt(4.0 * M_PI) * atom.RadialWFs(lindex).u(r); + std::vector ul(PotentialGrid.NumPoints()), + rhoAtom(PotentialGrid.NumPoints()); + for (int i=0; iWrite(str); - if (lineCount + str.size() + 2 * Level > 73) - { + if (lineCount + str.size() + 2*Level > 73) { out << "\n"; - Indent(out); + Indent (out); out << " "; lineCount = 1; } @@ -74,142 +78,155 @@ void XMLElement::Write(std::ostream& out) out << str; } int numLines = 0; - for (int i = 0; i < Content.size(); i++) + for (int i=0; i\n"; - else - { + else { out << ">"; if (numLines > 0 || Children.size() > 0) out << "\n"; out << Content; - for (int i = 0; i < Children.size(); i++) + for (int i=0; iWrite(out); - if (numLines > 0 || Children.size() > 0) + if (numLines > 0 || Children.size()>0) Indent(out); out << "\n"; } } + - -void XMLElement::AddContent(std::vector& data) +void +XMLElement::AddContent(std::vector &data) { std::stringstream str; str.setf(std::ios_base::scientific, std::ios_base::floatfield); str << std::setprecision(14); - for (int i = 0; i < data.size(); i++) - { - if ((i % 3 == 0)) + for (int i=0; i\n"; + + Out << "\n"; return true; } -bool XMLWriterClass::EndDocument() +bool +XMLWriterClass::EndDocument() { - if (Elements.size() <= 0) + if (Elements.size() <=0) return false; Elements[0]->Write(Out); return true; } -bool XMLWriterClass::StartElement(std::string name) +bool +XMLWriterClass::StartElement(std::string name) { int level = Elements.size(); - + auto elem = std::make_shared(name, level); if (level > 0) - Elements.back()->AddElement(elem); + Elements.back()->AddElement (elem); Elements.push_back(elem); return true; } -bool XMLWriterClass::EndElement() +bool +XMLWriterClass::EndElement() { if (Elements.size() > 1) Elements.pop_back(); return true; } -bool XMLWriterClass::FullEndElement() +bool +XMLWriterClass::FullEndElement() { Elements.pop_back(); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, std::string content) +bool +XMLWriterClass::WriteAttribute (std::string name, std::string content) { auto attr = std::make_shared(name, content); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, double val, bool scientific) +bool +XMLWriterClass::WriteAttribute (std::string name, double val, bool scientific) { std::stringstream content; - if (scientific) - { + if (scientific) { content.setf(std::ios_base::scientific, std::ios_base::floatfield); content << std::setprecision(14); } content << val; auto attr = std::make_shared(name, content.str()); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteAttribute(std::string name, int val) +bool +XMLWriterClass::WriteAttribute (std::string name, int val) { std::stringstream content; content << val; auto attr = std::make_shared(name, content.str()); - Elements.back()->AddAttribute(attr); + Elements.back()->AddAttribute (attr); return true; } -bool XMLWriterClass::WriteData(std::vector data) +bool +XMLWriterClass::WriteData(std::vector data) { - Elements.back()->AddContent(data); + Elements.back()->AddContent (data); return true; } -bool XMLWriterClass::WriteData(std::string data) +bool +XMLWriterClass::WriteData(std::string data) { - Elements.back()->AddContent(data); + Elements.back()->AddContent (data); return true; } -bool XMLWriterClass::WriteElement(std::string name, std::vector data) +bool +XMLWriterClass::WriteElement (std::string name, std::vector data) { int level = Elements.size(); auto elem = std::make_shared(name, level); - elem->AddContent(data); + elem->AddContent (data); if (level > 0) - Elements.back()->AddElement(elem); + Elements.back()->AddElement (elem); return true; } + diff --git a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h index f140b75064..b878ab61a3 100644 --- a/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h +++ b/src/QMCTools/ppconvert/src/common/CubicSplineCommon.h @@ -139,11 +139,11 @@ class CubicSplineCommon /// Trivial constructor CubicSplineCommon() { - UpToDate = 0; - NumParams = 0; + UpToDate = 0; + NumParams = 0; StartDeriv = 0; - EndDeriv = 0; - grid = NULL; + EndDeriv = 0; + grid = NULL; } }; diff --git a/src/QMCTools/ppconvert/src/common/DFTAtom.cc b/src/QMCTools/ppconvert/src/common/DFTAtom.cc index abf81ae2b5..4f364170fd 100644 --- a/src/QMCTools/ppconvert/src/common/DFTAtom.cc +++ b/src/QMCTools/ppconvert/src/common/DFTAtom.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -17,7 +17,10 @@ #include "RungeKutta.h" #include "Functionals.h" -AtomType DFTAtom::Type() { return (DFTType); } +AtomType DFTAtom::Type() +{ + return (DFTType); +} void DFTAtom::UpdateVHXC() { @@ -25,22 +28,20 @@ void DFTAtom::UpdateVHXC() UpdateHartree(); UpdateExCorr(); - for (int i = 0; i < grid->NumPoints; i++) + for (int i=0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); } /// Radial WFs must be normalized before calling this function void DFTAtom::UpdateChargeDensity() { - for (int i = 0; i < grid->NumPoints; i++) - { + for (int i=0; iNumPoints; i++) { ChargeDensity(i) = 0.0; - double r = (*grid)(i); - double rinv2 = 1.0 / (r * r); - for (int j = 0; j < RadialWFs.size(); j++) - { + double r = (*grid)(i); + double rinv2 = 1.0/(r*r); + for (int j=0; jNumPoints; - + HartreeDeriv1 H1(*this); HartreeDeriv2 H2(*this); - RungeKutta integrator1(H1); - RungeKutta integrator2(H2); - temp(0) = 0.0; - temp2(0) = 0.0; - integrator1.Integrate(*grid, 0, N - 1, temp); - integrator2.Integrate(*grid, 0, N - 1, temp2); - - for (int i = 0; i < N; i++) - { - double r = (*grid)(i); - Hartree(i) = 4.0 * M_PI * (temp(i) / r + (temp2(N - 1) - temp2(i))); + RungeKutta integrator1(H1); + RungeKutta integrator2(H2); + temp(0) = 0.0; temp2(0) = 0.0; + integrator1.Integrate(*grid, 0, N-1, temp); + integrator2.Integrate(*grid, 0, N-1, temp2); + + for (int i=0; iNumPoints; - for (int i = 0; i < N; i++) - { + for (int i=0; i& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; temp.resize(N); temp2.resize(N); temp = 0.0; V.HXC.Init(grid, temp); - ChargeDensity.Init(grid, temp); + ChargeDensity.Init(grid,temp); Hartree.Init(grid, temp); - ExCorr.Init(grid, temp); - for (int i = 0; i < RadialWFs.size(); i++) + ExCorr.Init(grid,temp); + for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -142,7 +138,7 @@ void DFTAtom::SetBarePot(Potential* newPot) // for (int i=0; iNumPoints; +// int N = grid->NumPoints; // // Just rename temp and temp2 for clarity // Array &oldCharge = temp; // Array &newCharge = temp2; @@ -172,7 +168,7 @@ void DFTAtom::SetBarePot(Potential* newPot) // UpdateExCorr(); // for (int i=0; i < grid->NumPoints; i++) // V.HXC(i) = Hartree(i) + ExCorr(i); -// +// // double maxDiff = 0.0; // for (int i=0; iNumPoints; + int N = grid->NumPoints; // Just rename temp and temp2 for clarity - Array& oldCharge = temp; - Array& newCharge = temp2; + Array &oldCharge = temp; + Array &newCharge = temp2; // First, zero out screening - for (int i = 0; i < N; i++) + for (int i=0; i oldEnergies(RadialWFs.size()); + Array oldEnergies(RadialWFs.size()); // Now solve radial equations - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; iNumPoints; i++) + for (int i=0; i < grid->NumPoints; i++) V.HXC(i) = Hartree(i) + ExCorr(i); done = true; - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; i 1.0e-8) - done = false; + if (fabs(oldEnergies(i)-RadialWFs(i).Energy) > 1.0e-8) + done = false; oldEnergies(i) = RadialWFs(i).Energy; } - for (int i = 0; i < RadialWFs.size(); i++) - fprintf(stderr, "Energy(%d) = %1.16f\n", i, RadialWFs(i).Energy); + for (int i=0; iWrite(out); out.CloseSection(); - for (int i = 0; i < RadialWFs.size(); i++) - { + for (int i=0; iWrite(out); out.CloseSection(); - out.WriteVar("NewMix", NewMix); + out.WriteVar ("NewMix", NewMix); } -void DFTAtom::Read(IOSectionClass& in) +void DFTAtom::Read(IOSectionClass &in) { assert(in.OpenSection("Grid")); grid = ReadGrid(in); @@ -280,22 +274,22 @@ void DFTAtom::Read(IOSectionClass& in) int numRadialWFs = in.CountSections("RadialWF"); RadialWFs.resize(numRadialWFs); SetGrid(grid); - in.ReadVar("ChargeDensity", ChargeDensity.Data()); - in.ReadVar("Hartree", Hartree.Data()); - in.ReadVar("ExCorr", ExCorr.Data()); - for (int i = 0; i < V.HXC.size(); i++) - V.HXC(i) = Hartree(i) + ExCorr(i); + in.ReadVar ("ChargeDensity", ChargeDensity.Data()); + in.ReadVar ("Hartree", Hartree.Data()); + in.ReadVar ("ExCorr", ExCorr.Data()); + for (int i=0; i vdata; - assert(in.ReadVar("V", vdata)); - assert(in.ReadVar("Z", Z)); - PotSpline.Init(PotGrid, vdata); + Array vdata; + assert (in.ReadVar("V", vdata)); + assert (in.ReadVar("Z", Z)); + PotSpline.Init (PotGrid, vdata); } -void GeneralPot::Write(IOSectionClass& out) +void +GeneralPot::Write(IOSectionClass &out) { out.NewSection("Grid"); PotGrid->Write(out); @@ -36,29 +38,35 @@ void GeneralPot::Write(IOSectionClass& out) out.WriteVar("Type", "General"); } -double GeneralPot::V(double r) +double +GeneralPot::V(double r) { if (r < PotGrid->End) return PotSpline(r); else - return (-Z / r); + return (-Z/r); } -double GeneralPot::dVdr(double r) +double +GeneralPot::dVdr (double r) { if (r < PotGrid->End) return PotSpline.Deriv(r); else - return Z / (r * r); + return Z/(r*r); } -double GeneralPot::d2Vdr2(double r) +double +GeneralPot::d2Vdr2 (double r) { if (r < PotGrid->End) return PotSpline.Deriv2(r); else - return -2.0 * Z / (r * r * r); + return -2.0*Z/(r*r*r); } -GeneralPot::GeneralPot() : PotGrid(NULL) {} +GeneralPot::GeneralPot() : PotGrid(NULL) +{ + +} diff --git a/src/QMCTools/ppconvert/src/common/Grid.h b/src/QMCTools/ppconvert/src/common/Grid.h index ac8e90fee6..cc5e3d120f 100644 --- a/src/QMCTools/ppconvert/src/common/Grid.h +++ b/src/QMCTools/ppconvert/src/common/Grid.h @@ -65,7 +65,7 @@ class Grid virtual int ReverseMap(double r) = 0; virtual void Write(IOSectionClass& out) = 0; virtual void Read(IOSectionClass& inSection) = 0; - virtual ~Grid() {} + virtual ~Grid(){} }; diff --git a/src/QMCTools/ppconvert/src/common/NLPP.cc b/src/QMCTools/ppconvert/src/common/NLPP.cc index 7f54d858a8..39bab55b46 100644 --- a/src/QMCTools/ppconvert/src/common/NLPP.cc +++ b/src/QMCTools/ppconvert/src/common/NLPP.cc @@ -8,30 +8,38 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// + + #include "NLPP.h" #include "GKIntegration.h" #include "MatrixOps.h" -bool NLPPClass::IsNonlocal() { return true; } +bool +NLPPClass::IsNonlocal() +{ + return true; +} -void ChannelPotential::Read(IOSectionClass& in, std::shared_ptr& grid) +void +ChannelPotential::Read(IOSectionClass &in, std::shared_ptr& grid) { - assert(in.ReadVar("l", l)); - assert(in.ReadVar("n_principal", n_principal)); - assert(in.ReadVar("Cutoff", rc)); + assert (in.ReadVar("l", l)); + assert (in.ReadVar("n_principal", n_principal)); + assert (in.ReadVar("Cutoff", rc)); R0 = 1.75 * rc; - assert(in.ReadVar("Occupation", Occupation)); - assert(in.ReadVar("Eigenvalue", Eigenvalue)); - Array V_data, u_data; - assert(in.ReadVar("Vl", V_data)); - assert(in.ReadVar("ul", u_data)); - V.Init(grid, V_data); - u.Init(grid, u_data); + assert (in.ReadVar("Occupation", Occupation)); + assert (in.ReadVar("Eigenvalue", Eigenvalue)); + Array V_data, u_data; + assert (in.ReadVar("Vl", V_data)); + assert (in.ReadVar("ul", u_data)); + V.Init (grid, V_data); + u.Init (grid, u_data); } -void ChannelPotential::Write(IOSectionClass& out) +void +ChannelPotential::Write(IOSectionClass &out) { out.WriteVar("l", l); out.WriteVar("n_principal", n_principal); @@ -42,153 +50,148 @@ void ChannelPotential::Write(IOSectionClass& out) out.WriteVar("ul", u.Data()); } -void NLPPClass::Read(IOSectionClass& in) +void +NLPPClass::Read(IOSectionClass &in) { assert(in.ReadVar("AtomicNumber", AtomicNumber)); assert(in.ReadVar("LocalChannel", lLocal)); assert(in.ReadVar("ValenceCharge", Zion)); assert(in.ReadVar("Symbol", Symbol)); - + int numChannels = in.CountSections("lChannel"); Vl.resize(numChannels); - // vector > vl(numChannels), ul(numChannels); - // vector rc(numChannels); - assert(in.OpenSection("PotentialGrid")); - PotentialGrid = ReadGrid(in); +// vector > vl(numChannels), ul(numChannels); +// vector rc(numChannels); + assert (in.OpenSection("PotentialGrid")); + PotentialGrid = ReadGrid (in); in.CloseSection(); // "PotentialGrid" - for (int i = 0; i < numChannels; i++) - { - assert(in.OpenSection("lChannel", i)); + for (int i=0; i numChannels) - { + assert (in.ReadVar("l", l)); + if (l > numChannels) { std::cerr << "Skipped channels in NLPPClass read.\n"; abort(); } Vl[l].Read(in, PotentialGrid); - in.CloseSection(); // "lChannel" + in.CloseSection (); // "lChannel" } - for (int l = 0; l < numChannels; l++) - { - Array deltav(PotentialGrid->NumPoints); - deltav = Vl[l].V.Data() - Vl[lLocal].V.Data(); - Vl[l].DeltaV.Init(PotentialGrid, deltav); + for (int l=0; l deltav(PotentialGrid->NumPoints); + deltav = Vl[l].V.Data()- Vl[lLocal].V.Data(); + Vl[l].DeltaV.Init (PotentialGrid, deltav); } } -void NLPPClass::Write(IOSectionClass& out) +void +NLPPClass::Write(IOSectionClass &out) { - out.WriteVar("Type", "NLPP"); - out.WriteVar("LocalChannel", lLocal); - out.WriteVar("AtomicNumber", AtomicNumber); - out.WriteVar("Symbol", Symbol); - out.WriteVar("ValenceCharge", Zion); + out.WriteVar ("Type", "NLPP"); + out.WriteVar ("LocalChannel", lLocal); + out.WriteVar ("AtomicNumber", AtomicNumber); + out.WriteVar ("Symbol", Symbol); + out.WriteVar ("ValenceCharge", Zion); out.NewSection("PotentialGrid"); PotentialGrid->Write(out); - out.CloseSection(); // "PotentialGrid" - for (int i = 0; i < Vl.size(); i++) - { + out.CloseSection(); // "PotentialGrid" + for (int i=0; i::quiet_NaN(); // sqrt(-1.0); } @@ -210,91 +213,87 @@ double ChannelPotential::A(double q, double qp) // DeltaV and u splines. It then applies the methods of King-Smith et // al to filter out the high Fourier components, so that the // projector can be applied without error in real-space. -void ChannelPotential::SetupProjector(double G_max, double G_FFT) +void +ChannelPotential::SetupProjector (double G_max, double G_FFT) { - Grid& grid = *u.grid; + Grid &grid = *u.grid; // First, compute zeta_r, normalization, and E_KB Job = NORM; GKIntegration integrator(*this); - double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); - ProjectorNorm = 1.0 / sqrt(norm); - Job = EKB; - E_KB = norm / integrator.Integrate(0.0, grid.End, 1.0e-12); - std::cerr << "l = " << l << " Norm is " << norm << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; - + double norm = integrator.Integrate(0.0, grid.End, 1.0e-12); + ProjectorNorm = 1.0/sqrt(norm); + Job = EKB; + E_KB = norm/integrator.Integrate(0.0, grid.End, 1.0e-12); + std::cerr << "l = " << l << " Norm is " << norm + << " E_KB is " << E_KB << " R0 = " << R0 << std::endl; + // Compute zeta(r) - Array zeta(grid.NumPoints); - zeta(0) = ProjectorNorm * DeltaV(0) * u(1.0e-8) * 1.0e8; - for (int i = 1; i < grid.NumPoints; i++) - zeta(i) = ProjectorNorm * DeltaV(i) * u(i) / grid(i); - zeta_r.Init(u.grid, zeta); + Array zeta(grid.NumPoints); + zeta(0) = ProjectorNorm * DeltaV(0)*u(1.0e-8)*1.0e8; + for (int i=1; i qGridSharedPtr(&qGrid); - zeta_q.Init(qGridSharedPtr, zeta); + zeta_q.Init (qGridSharedPtr, zeta); double gamma = G_FFT - G_max; // Zero out zeta_q above gamma; - Array chi_q_data(qGrid.NumPoints); - for (int i = 0; i < qGrid.NumPoints; i++) + Array chi_q_data(qGrid.NumPoints); + for (int i=0; i= gamma) ? 0.0 : zeta_q(i); - - chi_q.Init(qGridSharedPtr, chi_q_data); + chi_q.Init (qGridSharedPtr, chi_q_data); // Now for the magic: We adjust chi_q between G_max and gamma so // that the real-space oscillations outside R0 are damped out // See King-Smith et al, PRB 44 13063 // Find index of gamma int gammaIndex = qGrid.ReverseMap(gamma); - int G_maxIndex = qGrid.ReverseMap(G_max) + 1; - double delta = qGrid(1) - qGrid(0); - int nb = gammaIndex - G_maxIndex; - Array b(nb), x(nb); + int G_maxIndex = qGrid.ReverseMap(G_max)+1; + double delta = qGrid(1)-qGrid(0); + int nb = gammaIndex - G_maxIndex; + Array b(nb), x(nb); // First, create the b vector b = 0.0; - for (int i = 0; i < nb; i++) - { - double q = qGrid(G_maxIndex + i); - for (int j = 0; j < G_maxIndex; j++) - { - double qp = qGrid(j); - b(i) -= delta * A(q, qp) * zeta_q(j); + for (int i=0; i M(nb, nb); - for (int i = 0; i < nb; i++) - { - double q = qGrid(G_maxIndex + i); - for (int j = 0; j < nb; j++) - { - double qp = qGrid(G_maxIndex + j); - M(i, j) = delta * A(q, qp); + Array M(nb, nb); + for (int i=0; i perm({nb}, int{0}); @@ -302,35 +301,36 @@ void ChannelPotential::SetupProjector(double G_max, double G_FFT) assert(size(LU) == size(M)); // check it is invertible x = lup::solve(LU, perm, b); - for (int i = 0; i < nb; i++) - chi_q(G_maxIndex + i) = x(i); - chi_q(G_maxIndex + nb) = 0.0; - - // FILE *fout = fopen("chicheck.dat","w"); - // for (double q=0.0; q chi_r_data(grid.NumPoints); - for (int i = 1; i < grid.NumPoints; i++) - { - rCurrent = grid(i); + Array chi_r_data(grid.NumPoints); + for (int i=1; i 1.0e-16) - std::cerr << "Fractional error in real-space projection = " << (error / norm2) << std::endl; + std::cerr << "Fractional error in real-space projection = " + << (error / norm2) << std::endl; } -double NLPPClass::V(int l, double r) +double +NLPPClass::V(int l, double r) { if (l < Vl.size()) return Vl[l].V(r); @@ -338,7 +338,8 @@ double NLPPClass::V(int l, double r) return Vl[lLocal].V(r); } -double NLPPClass::dVdr(int l, double r) +double +NLPPClass::dVdr(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv(r); @@ -346,7 +347,8 @@ double NLPPClass::dVdr(int l, double r) return Vl[lLocal].V.Deriv(r); } -double NLPPClass::d2Vdr2(int l, double r) +double +NLPPClass::d2Vdr2(int l, double r) { if (l < Vl.size()) return Vl[l].V.Deriv2(r); @@ -354,8 +356,20 @@ double NLPPClass::d2Vdr2(int l, double r) return Vl[lLocal].V.Deriv2(r); } -double NLPPClass::V(double r) { return Vl[lLocal].V(r); } +double +NLPPClass::V(double r) +{ + return Vl[lLocal].V(r); +} -double NLPPClass::dVdr(double r) { return Vl[lLocal].V.Deriv(r); } +double +NLPPClass::dVdr(double r) +{ + return Vl[lLocal].V.Deriv(r); +} -double NLPPClass::d2Vdr2(double r) { return Vl[lLocal].V.Deriv2(r); } +double +NLPPClass::d2Vdr2(double r) +{ + return Vl[lLocal].V.Deriv2(r); +} diff --git a/src/QMCTools/ppconvert/src/common/RadialWF.cc b/src/QMCTools/ppconvert/src/common/RadialWF.cc index a2d87a1999..dbe505de53 100644 --- a/src/QMCTools/ppconvert/src/common/RadialWF.cc +++ b/src/QMCTools/ppconvert/src/common/RadialWF.cc @@ -8,91 +8,91 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// #include "RadialWF.h" #include "RungeKutta.h" -int RadialWF::TurningIndex() +int +RadialWF::TurningIndex() { // Start in classically forbidden region and search inward toward // origin looking for classically allowed region - Grid& grid = *u.grid; - int index = grid.NumPoints - 1; - bool done = false; - - while (!done && (index >= 0)) - { - double r = grid(index); - double A = pot->A(r); - double B = pot->B(r); - double V = pot->V(l, r); - double dAdr = pot->dAdr(r); - double E = Energy; - double sl = (double)l; - - double Deriv2 = dAdr / r + sl * (sl + 1.0) * B / (r * r) + 2.0 * (V - E); - - if (Deriv2 < 0.0) - done = true; - else - index--; - } + Grid &grid = *u.grid; + int index = grid.NumPoints-1; + bool done = false; + + while (!done && (index >=0)) + { + double r = grid(index); + double A = pot->A(r); + double B = pot->B(r); + double V = pot->V(l,r); + double dAdr = pot->dAdr(r); + double E = Energy; + double sl = (double) l; + + double Deriv2 = dAdr/r + sl*(sl+1.0)*B/(r*r) + 2.0*(V-E); + + if (Deriv2 < 0.0) + done = true; + else + index--; + } // If we didn't fine a turning point, select the middle grid point; if (index == -1) - index = grid.ReverseMap(0.5 * grid(grid.NumPoints - 1)); + index = grid.ReverseMap(0.5*grid(grid.NumPoints-1)); return (index); } -void RadialWF::OriginBC(double r0, double& u0, double& du0) +void +RadialWF::OriginBC(double r0, double &u0, double &du0) { - if (pot->NeedsRel()) - { // Use relativistic equations - const double alpha = 1.0 / 137.036; - double Z = -pot->V(l, r0) * r0; - double a2Z2 = alpha * alpha * (double)Z * (double)Z; - - double sl = (double)l; - double gamma = (sl + 1.0) * sqrt((sl + 1.0) * (sl + 1.0) - a2Z2) / (2.0 * sl + 1.0); - if (l != 0) - gamma += sl * sqrt(sl * sl - a2Z2) / (2.0 * sl + 1.0); - - u0 = pow(r0, gamma); - du0 = gamma * pow(r0, gamma - 1.0); + if (pot->NeedsRel()) { // Use relativistic equations + const double alpha = 1.0/137.036; + double Z = -pot->V(l,r0)*r0; + double a2Z2 = alpha*alpha*(double)Z*(double)Z; + + double sl = (double) l; + double gamma = + (sl+1.0)*sqrt((sl+1.0)*(sl+1.0)-a2Z2) / + (2.0*sl + 1.0); + if (l!=0) + gamma += sl*sqrt(sl*sl-a2Z2)/(2.0*sl+1.0); + + u0 = pow(r0, gamma); + du0 = gamma * pow(r0,gamma-1.0); } - else - { // Use pseudoHamiltonian equations + else { // Use pseudoHamiltonian equations if (l == 0) - { - double E = Energy; - double A = pot->A(r0); - double B = pot->B(r0); - double V = pot->V(l, r0); - if (V > Energy) - { - double kappa = sqrt(2.0 * (V - E) / A); - u0 = sinh(kappa * r0); - du0 = kappa * cosh(kappa * r0); - } - else { - double k = sqrt(2.0 * (E - V) / A); - u0 = sin(k * r0); - du0 = k * cos(k * r0); + double E = Energy; + double A = pot->A(r0); + double B = pot->B(r0); + double V = pot->V(l,r0); + if (V > Energy) + { + double kappa = sqrt(2.0 * (V-E)/A); + u0 = sinh(kappa * r0); + du0 = kappa * cosh (kappa * r0); + } + else + { + double k = sqrt(2.0 * (E-V)/A); + u0 = sin(k * r0); + du0 = k * cos(k * r0); + } } + else { // l != 0 + u0 = 1.0; + du0 = (double)(l+1)/r0; } - else - { // l != 0 - u0 = 1.0; - du0 = (double)(l + 1) / r0; - } - } + } // Flip sign for odd number of nodes - if (((n - l - 1) % 2) == 1) - { + if (((n-l-1) % 2) == 1) { u0 *= -1.0; du0 *= -1.0; } @@ -105,7 +105,7 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) // Grid &grid = *u.grid; // Array Temp(grid.NumPoints); // // Set up initial conditions: -// double r0 = grid(0); +// double r0 = grid(0); // OriginBC(r0, Temp(0)[0], Temp(0)[1]); // // Now do integration @@ -117,12 +117,12 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) // else if (pot->NeedsRel()) { // NonPHDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // else { // RegularDerivs derivs(*this); // RungeKutta integrator(derivs); -// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); +// integrator.Integrate(grid, 0, grid.NumPoints-1, Temp); // } // // Copy results of integration into RadialWF @@ -134,159 +134,152 @@ void RadialWF::OriginBC(double r0, double& u0, double& du0) //} -double RadialWF::IntegrateInOut(int& tindex) +double +RadialWF::IntegrateInOut (int &tindex) { - Grid& grid = *u.grid; + Grid &grid = *u.grid; // Find classical turning point tindex = TurningIndex(); //cerr << "TurningIndex = " << tindex << endl; //cerr << "Turning Point = " << (*u.grid)(tindex) << endl; // Compute starting value and derivative at origin double r0 = grid(0); - OriginBC(r0, uduVec(0)[0], uduVec(0)[1]); + OriginBC (r0, uduVec(0)[0], uduVec(0)[1]); // Do integration from the origin to the turning point - if (pot->IsPH()) - { + if (pot->IsPH()) { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, 0, tindex, uduVec); } - else if (pot->NeedsRel()) - { + else if (pot->NeedsRel()) { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); } - else - { + else { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, 0, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, 0, tindex, uduVec); + } - for (int j = 0; j <= tindex; j++) - { - u(j) = uduVec(j)[0]; + for (int j=0; j<=tindex; j++) { + u(j) = uduVec(j)[0]; dudr(j) = uduVec(j)[1]; } // Now initilize value and derivative at rmax - int endPoint = grid.NumPoints - 1; - double rend = grid(endPoint); + int endPoint = grid.NumPoints-1; + double rend = grid(endPoint); InfinityBC(rend, uduVec(endPoint)[0], uduVec(endPoint)[1]); - + // Do integration from the right to the turning point - if (pot->IsPH()) - { + if (pot->IsPH()) { PHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else if (pot->NeedsRel()) - { + else if (pot->NeedsRel()) { NonPHDerivs derivs(*this); - RungeKutta integrator(derivs); + RungeKutta integrator(derivs); integrator.Integrate(grid, endPoint, tindex, uduVec); } - else - { + else { RegularDerivs derivs(*this); - RungeKutta integrator(derivs); - integrator.Integrate(grid, endPoint, tindex, uduVec); - } + RungeKutta integrator(derivs); + integrator.Integrate(grid, endPoint, tindex, uduVec); + } - if ((u(tindex) * uduVec(tindex)[0]) < 0.0) - for (int i = tindex; i <= endPoint; i++) + if ((u(tindex)*uduVec(tindex)[0]) < 0.0) + for (int i=tindex; i<=endPoint; i++) uduVec(i) *= -1.0; - double cuspValue = uduVec(tindex)[1] / uduVec(tindex)[0] - dudr(tindex) / u(tindex); + double cuspValue = uduVec(tindex)[1]/uduVec(tindex)[0] - + dudr(tindex)/u(tindex); // Copy values in, normalizing to make R continuous double factor = u(tindex) / uduVec(tindex)[0]; - for (int i = tindex + 1; i < grid.NumPoints; i++) - { - u(i) = factor * uduVec(i)[0]; - dudr(i) = factor * uduVec(i)[1]; + for (int i=tindex+1; iV(l, rend); - double dVdrend = pot->dVdr(l, rend); - double E = Energy; + double Vend = pot->V(l,rend); + double dVdrend = pot->dVdr(l,rend); + double E = Energy; double k; uend = 1.0; - if (Vend > E) - { - k = sqrt(l * (l + 1.0) / (rend * rend) + (Vend - E)); - duend = -uend * (k + 0.5 * rend / k * (dVdrend - 2.0 * l * (l + 1.0) / (rend * rend * rend))); + if (Vend > E) { + k = sqrt(l*(l+1.0)/(rend*rend) + (Vend-E)); + duend = -uend * (k + 0.5*rend/k*(dVdrend-2.0*l*(l+1.0)/(rend*rend*rend))); } else duend = -1.0; - // cerr << "duend = " << duend << endl; - // cerr << "rend = " << rend << endl; - // cerr << "k = " << k << endl; - // cerr << "Vend = " << Vend << endl; - // cerr << "dVend = " << dVdrend << endl; +// cerr << "duend = " << duend << endl; +// cerr << "rend = " << rend << endl; +// cerr << "k = " << k << endl; +// cerr << "Vend = " << Vend << endl; +// cerr << "dVend = " << dVdrend << endl; } -void RadialWF::Solve(double tolerance) + +void +RadialWF::Solve(double tolerance) { int tindex; IntegrateInOut(tindex); int NumNodes = CountNodes(); double Ehigh, Elow, Etrial; - Ehigh = 0.0; - Grid& grid = *u.grid; - int TotalNodes = n - l - 1; - - // char fname[100]; - // snprintf (fname, 100, "WFn%dl%d.h5", n, l); - // IOSectionClass out; - // out.NewFile(fname); - // out.WriteVar ("x", u.grid->Points()); - // Array tmp(1,u.grid->NumPoints); - // tmp(0,Range::all()) = u.Data(); - // out.WriteVar ("u", tmp); - // VarClass *varPtr = out.GetVarPtr("u"); - - if (pot->NeedsRel()) - { + Ehigh = 0.0; + Grid &grid = *u.grid; + int TotalNodes = n-l-1; + +// char fname[100]; +// snprintf (fname, 100, "WFn%dl%d.h5", n, l); +// IOSectionClass out; +// out.NewFile(fname); +// out.WriteVar ("x", u.grid->Points()); +// Array tmp(1,u.grid->NumPoints); +// tmp(0,Range::all()) = u.Data(); +// out.WriteVar ("u", tmp); +// VarClass *varPtr = out.GetVarPtr("u"); + + if (pot->NeedsRel()){ double N = n; - double Z = -pot->V(l, grid(0)) * grid(0); - Elow = -1.5 * Z * Z / (N * N); - } - else - { + double Z = -pot->V(l,grid(0))*grid(0); + Elow = -1.5*Z*Z/(N*N); + } + else { // Eigenenergy can't be lower than lowest potential -- otherwise // we'd have no turning point. - Elow = pot->V(l, grid(0)); - for (int i = 1; i < grid.NumPoints; i++) - { + Elow = pot->V(l,grid(0)); + for (int i=1; i TotalNodes) Ehigh = Etrial; @@ -298,28 +291,27 @@ void RadialWF::Solve(double tolerance) Ehigh = Etrial; else if (std::isnan(CuspValue)) Elow = Etrial; - + Normalize(); // varPtr->Append(u.Data()); - double A = pot->A(grid(tindex)); - double C = 0.5 * A * CuspValue; - double u0 = u(tindex); - double Etest = Eold - 4.0 * M_PI * C * u0 * u0; + double A = pot->A(grid(tindex)); + double C = 0.5 * A * CuspValue; + double u0 = u(tindex); + double Etest = Eold - 4.0*M_PI*C*u0*u0; if ((Etest > Elow) && (Etest < Ehigh) && (NumNodes == TotalNodes)) Etrial = Etest; - else + else Etrial = 0.5 * (Ehigh + Elow); - + Energy = Etrial; - - if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) - { + + if ((NumNodes == TotalNodes) && (fabs(Etrial - Eold) < tolerance)) { Energy = Eold; - done = true; + done = true; } else { - if (std::isnan(Etrial)) + if(std::isnan(Etrial)) { std::cerr << "NaN detected!" << std::endl; std::cerr << "NumNodes = " << NumNodes << " TotalNodes = " << TotalNodes << std::endl; @@ -327,48 +319,48 @@ void RadialWF::Solve(double tolerance) exit(1); } } - Eold = Etrial; + Eold = Etrial; } IntegrateInOut(tindex); Normalize(); NumNodes = CountNodes(); - if (NumNodes != TotalNodes) - { - std::cerr << "Node number error! We have " << NumNodes << " nodes and want " << TotalNodes << ".\n"; - // IOSectionClass out; - // out.NewFile ("BadWF.h5"); - // out.WriteVar ("u", u.Data()); - // out.CloseFile(); + if (NumNodes != TotalNodes) { + std::cerr << "Node number error! We have " << NumNodes + << " nodes and want " << TotalNodes << ".\n"; +// IOSectionClass out; +// out.NewFile ("BadWF.h5"); +// out.WriteVar ("u", u.Data()); +// out.CloseFile(); std::cerr << "Energy = " << Energy << std::endl; } //out.CloseFile(); } -void RadialWF::Normalize() +void +RadialWF::Normalize() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); - // The false means "don't scale" - integrator.Integrate(*u.grid, 0, u.grid->NumPoints - 1, normVec, false); - - double norm = sqrt(1.0 / (4.0 * M_PI * normVec(u.grid->NumPoints - 1))); - for (int i = 0; i < u.grid->NumPoints; i++) - { + RungeKutta integrator(normDeriv); + // The false means "don't scale" + integrator.Integrate(*u.grid, 0, u.grid->NumPoints-1, normVec, false); + + double norm = sqrt(1.0/(4.0*M_PI*normVec(u.grid->NumPoints-1))); + for (int i=0; iNumPoints; i++) { u(i) *= norm; dudr(i) *= norm; } } -int RadialWF::CountNodes() +int +RadialWF::CountNodes() { - int nodes = 0; + int nodes=0; double sign = u(0); - for (int i = 1; i < u.grid->NumPoints; i++) - if ((sign * u(i)) < 0.0) - { + for (int i=1; iNumPoints; i++) + if ((sign*u(i)) < 0.0) { nodes++; sign *= -1.0; // cerr << "Node at i=" << i << " r=" << (*u.grid)(i) << endl; @@ -376,67 +368,79 @@ int RadialWF::CountNodes() return (nodes); } -void RadialWF::SetGrid(std::shared_ptr& newgrid) +void +RadialWF::SetGrid(std::shared_ptr& newgrid) { - grid = newgrid; + grid = newgrid; int N = grid->NumPoints; uduVec.resize(N); normVec.resize(N); - uduVec = 0.0; + uduVec = 0.0; normVec = 0.0; - u.Init(grid, normVec); + u.Init (grid, normVec); dudr.Init(grid, normVec); } -void RadialWF::SetPotential(Potential* newPot) { pot = newPot; } +void +RadialWF::SetPotential(Potential *newPot) +{ + pot = newPot; +} -Potential* RadialWF::GetPotential() { return pot; } +Potential* +RadialWF::GetPotential() +{ + return pot; +} -double RadialWF::PartialNorm() +double +RadialWF::PartialNorm() { normVec(0) = 0.0; NormalizeDeriv normDeriv(*this); - RungeKutta integrator(normDeriv); + RungeKutta integrator(normDeriv); int N = u.grid->NumPoints; - integrator.Integrate(*u.grid, 0, N - 1, normVec); - double uend = u(N - 1); - double partNorm = normVec(N - 1) / (uend * uend); + integrator.Integrate(*u.grid, 0, N-1, normVec); + double uend = u(N-1); + double partNorm = normVec(N-1)/(uend*uend); return (partNorm); } -double RadialWF::LogDerivative() +double +RadialWF::LogDerivative() { double rend = (*u.grid).End; - return (dudr(rend) / u(rend)); + return (dudr(rend)/u(rend)); } // This will write all the information except the potential and the // grid. We assume that those are store somewhere else -void RadialWF::Write(IOSectionClass& out) +void +RadialWF::Write(IOSectionClass &out) { - out.WriteVar("u", u.Data()); - out.WriteVar("dudr", dudr.Data()); - out.WriteVar("n", n); - out.WriteVar("l", l); - out.WriteVar("CoreNodes", CoreNodes); - out.WriteVar("Occupancy", Occupancy); - out.WriteVar("Weight", Weight); - out.WriteVar("Energy", Energy); + out.WriteVar ("u", u.Data()); + out.WriteVar ("dudr", dudr.Data()); + out.WriteVar ("n", n); + out.WriteVar ("l", l); + out.WriteVar ("CoreNodes", CoreNodes); + out.WriteVar ("Occupancy", Occupancy); + out.WriteVar ("Weight", Weight); + out.WriteVar ("Energy", Energy); // out.WriteVar ("PartialNorm", PartialNorm); - out.WriteVar("Label", Label); + out.WriteVar ("Label", Label); } // This function assumes the grid has already been set. -void RadialWF::Read(IOSectionClass& in) +void +RadialWF::Read (IOSectionClass &in) { bool succ; - if (u.grid == NULL) - { + if (u.grid == NULL) { std::cerr << "Grid not set prior to calling RadialWF::Read.\n"; exit(1); } - in.ReadVar("u", u.Data()); - in.ReadVar("dudr", dudr.Data()); + in.ReadVar ("u", u.Data()); + in.ReadVar ("dudr", dudr.Data()); assert(in.ReadVar("n", n)); assert(in.ReadVar("l", l)); assert(in.ReadVar("Occupancy", Occupancy)); diff --git a/src/QMCTools/ppconvert/src/common/SplinePot.cc b/src/QMCTools/ppconvert/src/common/SplinePot.cc index a6f89a96df..8f1d0f6994 100644 --- a/src/QMCTools/ppconvert/src/common/SplinePot.cc +++ b/src/QMCTools/ppconvert/src/common/SplinePot.cc @@ -8,8 +8,8 @@ // // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory ////////////////////////////////////////////////////////////////////////////////////// - - + + // http://pathintegrals.info // ///////////////////////////////////////////////////////////// @@ -19,10 +19,9 @@ double SplinePot::V(double r) { if (r <= Spline.grid->End) return Spline(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->V(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -34,10 +33,9 @@ double SplinePot::dVdr(double r) { if (r <= Spline.grid->End) return Spline.Deriv(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->dVdr(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -49,10 +47,9 @@ double SplinePot::d2Vdr2(double r) { if (r <= Spline.grid->End) return Spline.Deriv2(r); - else if (Vouter != NULL) + else if (Vouter != NULL) return (Vouter->d2Vdr2(r)); - else - { + else { #ifdef BZ_DEBUG cerr << "r outside grid in SplinePot: " << r << endl; #endif @@ -60,34 +57,32 @@ double SplinePot::d2Vdr2(double r) } } -void SplinePot::Read(IOSectionClass& in) +void SplinePot::Read(IOSectionClass &in) { assert(in.OpenSection("Grid")); auto grid = ReadGrid(in); - in.CloseSection(); // "Grid" - Array data; + in.CloseSection(); // "Grid" + Array data; assert(in.ReadVar("SplineData", data)); - Spline.Init(grid, data); - if (in.OpenSection("Vouter")) - { + Spline.Init (grid, data); + if(in.OpenSection("Vouter")) { Vouter = ReadPotential(in); in.CloseSection(); } else Vouter = NULL; -} + } -void SplinePot::Write(IOSectionClass& out) +void SplinePot::Write(IOSectionClass &out) { - out.WriteVar("Type", "Spline"); + out.WriteVar ("Type", "Spline"); out.NewSection("Grid"); Spline.grid->Write(out); out.CloseSection(); - out.WriteVar("SplineData", Spline.Data()); - if (Vouter != NULL) - { - out.NewSection("Vouter"); + out.WriteVar ("SplineData", Spline.Data()); + if (Vouter != NULL) { + out.NewSection ("Vouter"); Vouter->Write(out); out.CloseSection(); } From d48bd761815ee6225ad93eca132fecc9f8542039 Mon Sep 17 00:00:00 2001 From: Ye Luo Date: Fri, 1 Oct 2021 14:37:06 -0500 Subject: [PATCH 6/6] Update README.md about CUDA_ARCH --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3077a52966..7db23041c8 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ make -j 8 and use float and double for CUDA base and full precision. ENABLE_CUDA ON/OFF(default). Enable CUDA code path for NVIDIA GPU acceleration. Production quality for AFQMC. Pre-production quality for real-space. - Use CUDA_ARCH, default sm_70, to set the actual GPU architecture. + Use CMAKE_CUDA_ARCHITECTURES, default 70, to set the actual GPU architecture. ENABLE_OFFLOAD ON/OFF(default). Experimental feature. Enable OpenMP target offload for GPU acceleration. ENABLE_TIMERS ON(default)/OFF. Enable fine-grained timers. Timers are on by default but at level coarse to avoid potential slowdown in tiny systems.