QMCPACK
RadialJastrowBuilder Class Reference

JastrowBuilder using an analytic 1d functor Should be able to eventually handle all one and two body jastrows although spline based ones will come later. More...

+ Inheritance diagram for RadialJastrowBuilder:
+ Collaboration diagram for RadialJastrowBuilder:

Public Types

enum  detail { CPU, CUDA, OMPTARGET }
 
- Public Types inherited from WaveFunctionComponentBuilder
using RealType = WaveFunctionComponent::RealType
 
using ValueType = WaveFunctionComponent::ValueType
 
using PosType = WaveFunctionComponent::PosType
 
using GradType = WaveFunctionComponent::GradType
 
using PSetMap = std::map< std::string, const std::unique_ptr< ParticleSet > >
 
- Public Types inherited from MPIObjectBase
using mpi_comm_type = Communicate::mpi_comm_type
 

Public Member Functions

 RadialJastrowBuilder (Communicate *comm, ParticleSet &target, ParticleSet &source)
 
 RadialJastrowBuilder (Communicate *comm, ParticleSet &target)
 
std::unique_ptr< WaveFunctionComponentbuildComponent (xmlNodePtr cur) override
 process a xml node at cur More...
 
template<>
void initTwoBodyFunctor (BsplineFunctor< RealType > &bfunc, double fac)
 
- Public Member Functions inherited from WaveFunctionComponentBuilder
 WaveFunctionComponentBuilder (Communicate *comm, ParticleSet &p)
 constructor More...
 
virtual ~WaveFunctionComponentBuilder ()=default
 
- Public Member Functions inherited from MPIObjectBase
 MPIObjectBase (Communicate *c)
 constructor with communicator More...
 
int rank () const
 return the rank of the communicator More...
 
int getGroupID () const
 return the group id of the communicator More...
 
CommunicategetCommunicator () const
 return myComm More...
 
CommunicategetCommRef () const
 return a TEMPORARY reference to Communicate More...
 
mpi_comm_type getMPI () const
 return MPI communicator if one wants to use MPI directly More...
 
bool is_manager () const
 return true if the rank == 0 More...
 
const std::string & getName () const
 return the name More...
 
void setName (const std::string &aname)
 

Private Member Functions

template<class RadFuncType , bool SPIN = false, unsigned Implementation = detail::CPU>
std::unique_ptr< WaveFunctionComponentcreateJ1 (xmlNodePtr cur)
 
template<class RadFuncType , unsigned Implementation = detail::CPU>
std::unique_ptr< WaveFunctionComponentcreateJ2 (xmlNodePtr cur)
 
template<class RadFuncType >
void initTwoBodyFunctor (RadFuncType &functor, double fac)
 
template<class RadFuncType >
void computeJ2uk (const std::vector< RadFuncType *> &functors)
 
void guardAgainstOBC ()
 
void guardAgainstPBC ()
 
template<>
std::unique_ptr< WaveFunctionComponentcreateJ2 (xmlNodePtr cur)
 
template<>
std::unique_ptr< WaveFunctionComponentcreateJ1 (xmlNodePtr cur)
 

Private Attributes

std::string NameOpt
 <jastrow name="..."> More...
 
std::string TypeOpt
 <jastrow type="..."> More...
 
std::string Jastfunction
 <jastrow function="..."> More...
 
std::string SpinOpt
 <jastrow spin="..."> More...
 
ParticleSetSourcePtcl
 particle set for source particle More...
 

Additional Inherited Members

- Static Public Attributes inherited from WaveFunctionComponentBuilder
static std::string wfs_tag = "wavefunction"
 reserved tags for the elements associated with the many-body wavefunctions More...
 
static std::string param_tag = "parameter"
 the element name for a parameter More...
 
static std::string dtable_tag = "distancetable"
 the element name for a distancetable More...
 
static std::string jastrow_tag = "jastrow"
 the element name for jatrow More...
 
static std::string detset_tag = "determinantset"
 the element name for a set of Slater determinants, contains 1..* Slater determinants More...
 
static std::string sd_tag = "slaterdeterminant"
 the element name for a Slater determinant, contains 1..* determinants More...
 
static std::string det_tag = "determinant"
 the element name for a determinant, may contain (0..*) orbital or parameter element More...
 
static std::string rn_tag = "determinant_rn"
 the element name for a released node determinant, may contain (0..*) orbital or parameter element More...
 
static std::string spo_tag = "psi"
 the element name for single-particle orbital More...
 
static std::string sposet_tag = "sposet"
 the element name for single-particle orbital set More...
 
static std::string ionorb_tag = "ionwf"
 the element name for an ion wavefunction More...
 
static std::string backflow_tag = "backflow"
 the element name for a backflow transformation More...
 
static std::string multisd_tag = "multideterminant"
 the element name for a multi slater determinant wavefunction More...
 
- Protected Attributes inherited from WaveFunctionComponentBuilder
ParticleSettargetPtcl
 reference to the particle set on which targetPsi is defined More...
 
xmlNodePtr myNode
 xmlNode operated by this object More...
 
- Protected Attributes inherited from MPIObjectBase
CommunicatemyComm
 pointer to Communicate More...
 
std::string ClassName
 class Name More...
 
std::string myName
 name of the object More...
 

Detailed Description

JastrowBuilder using an analytic 1d functor Should be able to eventually handle all one and two body jastrows although spline based ones will come later.

Definition at line 33 of file RadialJastrowBuilder.h.

Member Enumeration Documentation

◆ detail

Constructor & Destructor Documentation

◆ RadialJastrowBuilder() [1/2]

RadialJastrowBuilder ( Communicate comm,
ParticleSet target,
ParticleSet source 
)

Definition at line 57 of file RadialJastrowBuilder.cpp.

References MPIObjectBase::ClassName, RadialJastrowBuilder::Jastfunction, RadialJastrowBuilder::NameOpt, RadialJastrowBuilder::SpinOpt, and RadialJastrowBuilder::TypeOpt.

58  : WaveFunctionComponentBuilder(comm, target), SourcePtcl(&source)
59 {
60  ClassName = "RadialJastrowBuilder";
61  NameOpt = "0";
62  TypeOpt = "unknown";
63  Jastfunction = "unknown";
64  SpinOpt = "no";
65 }
WaveFunctionComponentBuilder(Communicate *comm, ParticleSet &p)
constructor
ParticleSet * SourcePtcl
particle set for source particle
std::string NameOpt
<jastrow name="...">
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
std::string Jastfunction
<jastrow function="...">
std::string SpinOpt
<jastrow spin="...">
std::string TypeOpt
<jastrow type="...">

◆ RadialJastrowBuilder() [2/2]

RadialJastrowBuilder ( Communicate comm,
ParticleSet target 
)

Definition at line 67 of file RadialJastrowBuilder.cpp.

References MPIObjectBase::ClassName, RadialJastrowBuilder::Jastfunction, RadialJastrowBuilder::NameOpt, RadialJastrowBuilder::SpinOpt, and RadialJastrowBuilder::TypeOpt.

69 {
70  ClassName = "RadialJastrowBuilder";
71  NameOpt = "0";
72  TypeOpt = "unknown";
73  Jastfunction = "unknown";
74  SpinOpt = "no";
75 }
WaveFunctionComponentBuilder(Communicate *comm, ParticleSet &p)
constructor
ParticleSet * SourcePtcl
particle set for source particle
std::string NameOpt
<jastrow name="...">
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
std::string Jastfunction
<jastrow function="...">
std::string SpinOpt
<jastrow spin="...">
std::string TypeOpt
<jastrow type="...">

Member Function Documentation

◆ buildComponent()

std::unique_ptr< WaveFunctionComponent > buildComponent ( xmlNodePtr  cur)
overridevirtual

process a xml node at cur

Implements WaveFunctionComponentBuilder.

Definition at line 508 of file RadialJastrowBuilder.cpp.

References OhmmsAttributeSet::add(), SpeciesSet::addAttribute(), APP_ABORT, qmcplusplus::app_error(), qmcplusplus::app_summary(), Communicate::barrier_and_abort(), PlatformSelector< KIND >::candidate_values(), MPIObjectBase::ClassName, qmcplusplus::DC_POS_OFFLOAD, ParticleSet::getCoordinates(), DynamicCoordinates::getKind(), OhmmsElementBase::getName(), ParticleSet::getSpeciesSet(), RadialJastrowBuilder::guardAgainstOBC(), RadialJastrowBuilder::guardAgainstPBC(), qmcplusplus::is_same(), RadialJastrowBuilder::Jastfunction, qmcplusplus::lowerCase(), MPIObjectBase::myComm, RadialJastrowBuilder::NameOpt, qmcplusplus::OMPTARGET, RadialJastrowBuilder::OMPTARGET, OhmmsAttributeSet::put(), PlatformSelector< KIND >::selectPlatform(), RadialJastrowBuilder::SpinOpt, WaveFunctionComponentBuilder::targetPtcl, and RadialJastrowBuilder::TypeOpt.

Referenced by JastrowBuilder::buildOneBody(), JastrowBuilder::buildTwoBody(), qmcplusplus::doSOECPotentialTest(), qmcplusplus::TEST_CASE(), qmcplusplus::test_J1_spline(), and qmcplusplus::testTrialWaveFunction_diamondC_2x1x1().

509 {
510  ReportEngine PRE(ClassName, "put(xmlNodePtr)");
511  std::string useGPU;
512  OhmmsAttributeSet aAttrib;
513  aAttrib.add(NameOpt, "name");
514  aAttrib.add(TypeOpt, "type");
515  aAttrib.add(Jastfunction, "function");
516  aAttrib.add(SpinOpt, "spin", {"no", "yes"});
517  aAttrib.add(useGPU, "gpu", CPUOMPTargetSelector::candidate_values);
518  aAttrib.put(cur);
523 
524  SpeciesSet& species(targetPtcl.getSpeciesSet());
525  int chargeInd = species.addAttribute("charge");
526 
527  if (TypeOpt.find("one") < TypeOpt.size())
528  {
529  // it's a one body jastrow factor
530  if (Jastfunction == "bspline")
531  {
532  if (SpinOpt == "yes")
533  return createJ1<BsplineFunctor<RealType>, true>(cur);
534  else
535  return createJ1<BsplineFunctor<RealType>>(cur);
536  }
537  else if (Jastfunction == "pade")
538  {
539  guardAgainstPBC();
540  if (SpinOpt == "yes")
541  return createJ1<PadeFunctor<RealType>, true>(cur);
542  else
543  return createJ1<PadeFunctor<RealType>>(cur);
544  }
545  else if (Jastfunction == "pade2")
546  {
547  guardAgainstPBC();
548  return createJ1<Pade2ndOrderFunctor<RealType>>(cur);
549  }
550  else if (Jastfunction == "shortrangecusp")
551  {
552  //guardAgainstPBC(); // is this needed?
553  if (SpinOpt == "yes")
554  return createJ1<ShortRangeCuspFunctor<RealType>, true>(cur);
555  else
556  return createJ1<ShortRangeCuspFunctor<RealType>>(cur);
557  }
558  else if (Jastfunction == "user")
559  {
560  if (SpinOpt == "yes")
561  return createJ1<UserFunctor<RealType>, true>(cur);
562  else
563  return createJ1<UserFunctor<RealType>>(cur);
564  }
565  else if (Jastfunction == "rpa")
566  {
567 #if !(OHMMS_DIM == 3)
568  app_error() << "RPA for one-body jastrow is only available for 3D\n";
569 #endif
570  guardAgainstOBC();
571  app_error() << "one body RPA jastrow is not supported at the moment\n";
572  //return createJ1<RPAFunctor>(cur);
573  }
574  else
575  app_error() << "Unknown one jastrow body function: " << Jastfunction << ".\n";
576  }
577  else if (TypeOpt.find("two") < TypeOpt.size())
578  {
579  // it's a two body jastrow factor
580  if (Jastfunction == "bspline")
581  {
582  if (useGPU.empty())
584 
586  {
587  static_assert(std::is_same<JastrowTypeHelper<BsplineFunctor<RealType>, OMPTARGET>::J2Type,
588  TwoBodyJastrow<BsplineFunctor<RealType>>>::value,
589  "check consistent type");
591  {
592  std::ostringstream msg;
593  msg << R"(Offload enabled Jastrow needs the gpu="yes" attribute in the ")" << targetPtcl.getName()
594  << "\" particleset" << std::endl;
595  myComm->barrier_and_abort(msg.str());
596  }
597  app_summary() << " Running OpenMP offload code path." << std::endl;
598  return createJ2<BsplineFunctor<RealType>, detail::OMPTARGET>(cur);
599  }
600  else
601  return createJ2<BsplineFunctor<RealType>>(cur);
602  }
603  else if (Jastfunction == "pade")
604  {
605  guardAgainstPBC();
606  return createJ2<PadeFunctor<RealType>>(cur);
607  }
608  else if (Jastfunction == "user")
609  {
610  return createJ2<UserFunctor<RealType>>(cur);
611  }
612  else if (Jastfunction == "rpa" || Jastfunction == "yukawa")
613  {
614 #if !(OHMMS_DIM == 3)
615  app_error() << "RPA for one-body jastrow is only available for 3D\n";
616 #else
617  guardAgainstOBC();
618  return createJ2<RPAFunctor>(cur);
619 #endif
620  }
621  else
622  app_error() << "Unknown two jastrow body function: " << Jastfunction << ".\n";
623  }
624 
625  APP_ABORT("RadialJastrowBuilder::buildComponent not able to create Jastrow!\n");
626  return nullptr;
627 }
const std::string & getName() const
return the name
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
std::ostream & app_error()
Definition: OutputManager.h:67
bool is_same(const xmlChar *a, const char *b)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
DynamicCoordinateKind getKind() const
std::string NameOpt
<jastrow name="...">
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::string lowerCase(const std::string_view s)
++17
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
static PlatformKind selectPlatform(std::string_view value)
std::string Jastfunction
<jastrow function="...">
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
std::string SpinOpt
<jastrow spin="...">
std::string TypeOpt
<jastrow type="...">
void barrier_and_abort(const std::string &msg) const
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
const std::vector< std::string > candidate_values

◆ computeJ2uk()

void computeJ2uk ( const std::vector< RadFuncType *> &  functors)
private

Definition at line 257 of file RadialJastrowBuilder.cpp.

References DEBUG, ParticleSet::first(), MPIObjectBase::getGroupID(), ParticleSet::getLattice(), ParticleSet::getSimulationCell(), ParticleSet::groups(), MPIObjectBase::is_manager(), OutputManagerClass::isActive(), ParticleSet::last(), RadialJastrowBuilder::NameOpt, outputManager, qmcplusplus::sin(), qmcplusplus::sqrt(), and WaveFunctionComponentBuilder::targetPtcl.

Referenced by RadialJastrowBuilder::createJ2().

258 {
259  const int numPoints = 1000;
260  RealType vol = targetPtcl.getLattice().Volume;
261  int nsp = targetPtcl.groups();
262  FILE* fout = nullptr;
264  {
265  std::array<char, 16> fname;
266  if (std::snprintf(fname.data(), fname.size(), "uk.%s.g%03d.dat", NameOpt.c_str(), getGroupID()) < 0)
267  throw std::runtime_error("Error generating filename");
268  fout = fopen(fname.data(), "w");
269  }
270  for (int iG = 0; iG < targetPtcl.getSimulationCell().getKLists().ksq.size(); iG++)
271  {
272  RealType Gmag = std::sqrt(targetPtcl.getSimulationCell().getKLists().ksq[iG]);
273  RealType sum = 0.0;
274  RealType uk = 0.0;
275  for (int i = 0; i < targetPtcl.groups(); i++)
276  {
277  int Ni = targetPtcl.last(i) - targetPtcl.first(i);
278  RealType aparam = 0.0;
279  for (int j = 0; j < targetPtcl.groups(); j++)
280  {
281  int Nj = targetPtcl.last(j) - targetPtcl.first(j);
282  if (functors[i * nsp + j])
283  {
284  auto& ufunc = *functors[i * nsp + j];
285  RealType radius = ufunc.cutoff_radius;
286  RealType k = Gmag;
287  RealType dr = radius / (RealType)(numPoints - 1);
288  for (int ir = 0; ir < numPoints; ir++)
289  {
290  RealType r = dr * (RealType)ir;
291  RealType u = ufunc.evaluate(r);
292  aparam += (1.0 / 4.0) * k * k * 4.0 * M_PI * r * std::sin(k * r) / k * u * dr;
293  uk += 0.5 * 4.0 * M_PI * r * std::sin(k * r) / k * u * dr * (RealType)Nj / (RealType)(Ni + Nj);
294  }
295  }
296  }
297  //app_log() << "A = " << aparam << std::endl;
298  sum += Ni * aparam / vol;
299  }
300  if (fout)
301  fprintf(fout, "%1.8f %1.12e %1.12e\n", Gmag, uk, sum);
302  }
303  if (fout)
304  fclose(fout);
305 }
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
int getGroupID() const
return the group id of the communicator
Definition: MPIObjectBase.h:38
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
OutputManagerClass outputManager(Verbosity::HIGH)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
int groups() const
return the number of groups
Definition: ParticleSet.h:511
const auto & getSimulationCell() const
Definition: ParticleSet.h:250
std::string NameOpt
<jastrow name="...">
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
QMCTraits::RealType RealType
const auto & getLattice() const
Definition: ParticleSet.h:251
bool is_manager() const
return true if the rank == 0
Definition: MPIObjectBase.h:51
bool isActive(Verbosity level) const

◆ createJ1() [1/2]

std::unique_ptr< WaveFunctionComponent > createJ1 ( xmlNodePtr  cur)
private

Definition at line 317 of file RadialJastrowBuilder.cpp.

References OhmmsAttributeSet::add(), qmcplusplus::app_summary(), Communicate::barrier_and_abort(), PlatformSelector< KIND >::candidate_values(), castXMLCharToChar(), MPIObjectBase::ClassName, qmcplusplus::DC_POS_OFFLOAD, DEBUG, ReportEngine::error(), qmcplusplus::extractCoefficientsID(), SpeciesSet::findSpecies(), ParticleSet::getCoordinates(), MPIObjectBase::getGroupID(), DynamicCoordinates::getKind(), ParticleSet::getLattice(), OhmmsElementBase::getName(), ParticleSet::getSpeciesSet(), SpeciesSet::getTotalNum(), getXMLAttributeValue(), MPIObjectBase::is_manager(), OutputManagerClass::isActive(), RadialJastrowBuilder::Jastfunction, qmcplusplus::lowerCase(), MPIObjectBase::myComm, RadialJastrowBuilder::NameOpt, qmcplusplus::OMPTARGET, outputManager, qmcplusplus::print(), OhmmsAttributeSet::put(), PlatformSelector< KIND >::selectPlatform(), RadialJastrowBuilder::SourcePtcl, qmcplusplus::SUPERCELL_OPEN, and WaveFunctionComponentBuilder::targetPtcl.

318 {
319  ReportEngine PRE(ClassName, "createJ1(xmlNodePtr)");
320  using Real = typename RadFuncType::real_type;
321  using TH = JastrowTypeHelper<RadFuncType, Implementation>;
322  using J1Type = typename std::conditional<SPIN, typename TH::J1SpinType, typename TH::J1Type>::type;
323 
324  std::string input_name(getXMLAttributeValue(cur, "name"));
325  std::string jname = input_name.empty() ? Jastfunction : input_name;
326 
327  std::string useGPU;
328  OhmmsAttributeSet attr;
329  attr.add(useGPU, "gpu", CPUOMPTargetSelector::candidate_values);
330  attr.put(cur);
331 
332  if (useGPU.empty())
334 
335  bool use_offload = false;
337  {
339  {
340  std::ostringstream msg;
341  msg << R"(Offload enabled Jastrow needs the gpu="yes" attribute in the ")" << SourcePtcl->getName()
342  << "\" particleset" << std::endl;
343  myComm->barrier_and_abort(msg.str());
344  }
345  app_summary() << " Running OpenMP offload code path." << std::endl;
346  use_offload = true;
347  }
348 
349  auto J1 = std::make_unique<J1Type>(jname, *SourcePtcl, targetPtcl, use_offload);
350 
351  xmlNodePtr kids = cur->xmlChildrenNode;
352 
353  // Find the number of the source species
354  SpeciesSet& sSet = SourcePtcl->getSpeciesSet();
355  SpeciesSet& tSet = targetPtcl.getSpeciesSet();
356  bool success = false;
357  while (kids != NULL)
358  {
359  std::string kidsname(lowerCase(castXMLCharToChar(kids->name)));
360  if (kidsname == "correlation")
361  {
362  std::string speciesA;
363  std::string speciesB;
364  RealType cusp(0);
365  OhmmsAttributeSet rAttrib;
366  rAttrib.add(speciesA, "elementType");
367  rAttrib.add(speciesA, "speciesA");
368  rAttrib.add(speciesB, "speciesB");
369  rAttrib.add(cusp, "cusp");
370  rAttrib.put(kids);
371 
372  const auto coef_id = extractCoefficientsID(kids);
373  auto functor = std::make_unique<RadFuncType>(coef_id.empty() ? jname + "_" + speciesA + speciesB : coef_id);
374  functor->setPeriodic(SourcePtcl->getLattice().SuperCellEnum != SUPERCELL_OPEN);
375  functor->cutoff_radius = targetPtcl.getLattice().WignerSeitzRadius;
376  functor->setCusp(cusp);
377  const int ig = sSet.findSpecies(speciesA);
378  const int jg = speciesB.size() ? tSet.findSpecies(speciesB) : -1;
379  if (ig == sSet.getTotalNum())
380  {
381  PRE.error("species " + speciesA + " requested for Jastrow " + jname + " does not exist in ParticleSet " +
382  SourcePtcl->getName(),
383  true);
384  }
385  if (jg == tSet.getTotalNum())
386  {
387  PRE.error("species " + speciesB + " requested for Jastrow " + jname + " does not exist in ParticleSet " +
389  true);
390  }
391  app_summary() << " Radial function for element: " << speciesA << " - "
392  << (speciesB.empty() ? targetPtcl.getName() : speciesB) << std::endl;
393  functor->put(kids);
394  app_summary() << std::endl;
396  {
397  std::array<char, 128> fname;
398  int fname_len{0};
399  if (speciesB.size())
400  fname_len = std::snprintf(fname.data(), fname.size(), "%s.%s.%s%s.g%03d.dat", jname.c_str(), NameOpt.c_str(),
401  speciesA.c_str(), speciesB.c_str(), getGroupID());
402  else
403  fname_len = std::snprintf(fname.data(), fname.size(), "%s.%s.%s.g%03d.dat", jname.c_str(), NameOpt.c_str(),
404  speciesA.c_str(), getGroupID());
405  if (fname_len < 0)
406  throw std::runtime_error("Error generating filename");
407  std::ofstream os(std::string(fname.data(), fname_len));
408  if constexpr (std::is_same_v<RadFuncType, PadeFunctor<RealType>> ||
409  std::is_same_v<RadFuncType, Pade2ndOrderFunctor<RealType>>)
410  {
411  double plotextent = 10.0;
412  print(*functor.get(), os, plotextent);
413  }
414  else
415  {
416  print(*functor.get(), os);
417  }
418  }
419  J1->addFunc(ig, std::move(functor), jg);
420  success = true;
421  }
422  kids = kids->next;
423  }
424 
425  // sanity check before returning the constructed J1
426  J1->checkSanity();
427 
428  if (success)
429  return J1;
430  else
431  {
432  PRE.error("BsplineJastrowBuilder failed to add an One-Body Jastrow.");
433  return std::unique_ptr<WaveFunctionComponent>();
434  }
435 }
const std::string & getName() const
return the name
void print(OptimizableFunctorBase &func, std::ostream &os, double extent)
evaluates a functor (value and derivative) and dumps the quantities to output
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
int getGroupID() const
return the group id of the communicator
Definition: MPIObjectBase.h:38
ParticleSet * SourcePtcl
particle set for source particle
ForceBase::Real Real
Definition: ForceBase.cpp:26
OutputManagerClass outputManager(Verbosity::HIGH)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
DynamicCoordinateKind getKind() const
std::string NameOpt
<jastrow name="...">
Communicate * myComm
pointer to Communicate
Definition: MPIObjectBase.h:62
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::string lowerCase(const std::string_view s)
++17
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
Definition: libxmldefs.h:62
static PlatformKind selectPlatform(std::string_view value)
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
std::string Jastfunction
<jastrow function="...">
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
const DynamicCoordinates & getCoordinates() const
Definition: ParticleSet.h:246
QMCTraits::RealType RealType
OHMMS_PRECISION real_type
const auto & getLattice() const
Definition: ParticleSet.h:251
bool is_manager() const
return true if the rank == 0
Definition: MPIObjectBase.h:51
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
void barrier_and_abort(const std::string &msg) const
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
bool isActive(Verbosity level) const
const std::vector< std::string > candidate_values

◆ createJ1() [2/2]

std::unique_ptr<WaveFunctionComponent> createJ1 ( xmlNodePtr  cur)
private

Definition at line 439 of file RadialJastrowBuilder.cpp.

References OhmmsAttributeSet::add(), ParameterSet::add(), qmcplusplus::app_log(), qmcplusplus::Units::charge::e, qmcplusplus::pow(), ParameterSet::put(), OhmmsAttributeSet::put(), LinearGrid< T, CT >::set(), and ShortRangePartAdapter< T >::setRmax().

440 {
441  using Real = RealType;
443  using RadFunctorType = CubicSplineSingle<Real, SplineEngineType>;
444  using GridType = LinearGrid<Real>;
445  using HandlerType = LRHandlerBase;
446  using J1Type = J1OrbitalSoA<RadFunctorType>;
447 
448  std::string input_name;
449  std::string rpafunc = "RPA";
451  a.add(input_name, "name");
452  a.add(rpafunc, "function");
453  a.put(cur);
454  ParameterSet params;
455  RealType Rs(-1.0);
456  RealType Kc(-1.0);
457  params.add(Rs, "rs");
458  params.add(Kc, "kc");
459  params.put(cur);
460 
461  std::string jname = input_name.empty() ? Jastfunction : input_name;
462 
463  HandlerType* myHandler = nullptr;
464  if (Rs < 0)
465  {
466  Rs = std::pow(3.0 / 4.0 / M_PI * targetPtcl.getLattice().Volume / static_cast<RealType>(targetPtcl.getTotalNum()),
467  1.0 / 3.0);
468  }
469  if (Kc < 0)
470  {
471  Kc = 1e-6;
472  }
473  if (rpafunc == "RPA")
474  {
475  myHandler = new LRRPAHandlerTemp<EPRPABreakup<RealType>, LPQHIBasis>(targetPtcl, Kc);
476  app_log() << " using e-p RPA" << std::endl;
477  }
478  else if (rpafunc == "dRPA")
479  {
480  myHandler = new LRRPAHandlerTemp<derivEPRPABreakup<RealType>, LPQHIBasis>(targetPtcl, Kc);
481  app_log() << " using e-p derivRPA" << std::endl;
482  }
483  myHandler->Breakup(targetPtcl, Rs);
484 
485  Real Rcut = myHandler->get_rc() - 0.1;
486  GridType* myGrid = new GridType;
487  int npts = static_cast<int>(Rcut / 0.01) + 1;
488  myGrid->set(0, Rcut, npts);
489 
490  //create the numerical functor
491  auto nfunc = std::make_unique<RadFunctorType>();
492  ShortRangePartAdapter<Real>* SRA = new ShortRangePartAdapter<Real>(myHandler);
493  SRA->setRmax(Rcut);
494  nfunc->initialize(SRA, myGrid);
495 
496  auto J1 = std::make_unique<J1Type>(jname, *SourcePtcl, targetPtcl, false);
497 
498  SpeciesSet& sSet = SourcePtcl->getSpeciesSet();
499  for (int ig = 0; ig < sSet.getTotalNum(); ig++)
500  {
501  J1->addFunc(ig, std::move(nfunc));
502  }
503 
504  return J1;
505 }
void set(T ri, T rf, int n) override
Set the grid given the parameters.
LRCoulombSingleton::GridType GridType
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
ParticleSet * SourcePtcl
particle set for source particle
ForceBase::Real Real
Definition: ForceBase.cpp:26
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
class to handle a set of parameters
Definition: ParameterSet.h:27
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
Linear Grid inherets from Grid.
Definition: Grid.h:73
std::string Jastfunction
<jastrow function="...">
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
QMCTraits::RealType RealType
GridType
The different types of grids that we currently allow.
Definition: Grid.h:29
const auto & getLattice() const
Definition: ParticleSet.h:251
LRCoulombSingleton::RadFunctorType RadFunctorType
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42

◆ createJ2() [1/2]

std::unique_ptr< WaveFunctionComponent > createJ2 ( xmlNodePtr  cur)
private

Definition at line 133 of file RadialJastrowBuilder.cpp.

References OhmmsAttributeSet::add(), app_debug, qmcplusplus::app_summary(), MPIObjectBase::ClassName, RadialJastrowBuilder::computeJ2uk(), DEBUG, ReportEngine::error(), qmcplusplus::extractCoefficientsID(), ParticleSet::first(), MPIObjectBase::getGroupID(), ParticleSet::getLattice(), OhmmsElementBase::getName(), ParticleSet::getSpeciesSet(), getXMLAttributeValue(), RadialJastrowBuilder::initTwoBodyFunctor(), MPIObjectBase::is_manager(), OutputManagerClass::isActive(), RadialJastrowBuilder::Jastfunction, ParticleSet::last(), RadialJastrowBuilder::NameOpt, outputManager, qmcplusplus::print(), OhmmsAttributeSet::put(), qmcplusplus::SUPERCELL_OPEN, WaveFunctionComponentBuilder::targetPtcl, and ReportEngine::warning().

134 {
135  ReportEngine PRE(ClassName, "createJ2(xmlNodePtr)");
136  using Real = typename RadFuncType::real_type;
138 
139  std::string input_name(getXMLAttributeValue(cur, "name"));
140  std::string j2name = input_name.empty() ? "J2_" + Jastfunction : input_name;
141  const size_t ndim = targetPtcl.getLattice().ndim;
142  SpeciesSet& species(targetPtcl.getSpeciesSet());
143  auto J2 = std::make_unique<J2Type>(j2name, targetPtcl, Implementation == RadialJastrowBuilder::detail::OMPTARGET);
144 
145  std::string init_mode("0");
146  {
147  OhmmsAttributeSet hAttrib;
148  hAttrib.add(init_mode, "init");
149  hAttrib.put(cur);
150  }
151 
152  cur = cur->xmlChildrenNode;
153  while (cur != NULL)
154  {
155  std::string cname((const char*)cur->name);
156  if (cname == "correlation")
157  {
158  OhmmsAttributeSet rAttrib;
159  RealType cusp = -1e10;
160  std::string spA(species.speciesName[0]);
161  std::string spB(species.speciesName[0]);
162  std::string pairType("0");
163  rAttrib.add(spA, "speciesA");
164  rAttrib.add(spB, "speciesB");
165  rAttrib.add(pairType, "pairType");
166  rAttrib.add(cusp, "cusp");
167 
168  rAttrib.put(cur);
169  if (pairType[0] == '0')
170  {
171  pairType = spA + spB;
172  }
173  else
174  {
175  PRE.warning("pairType is deprecated. Use speciesA/speciesB");
176  //overwrite the species
177  spA = pairType[0];
178  spB = pairType[1];
179  }
180 
181  int ia = species.findSpecies(spA);
182  int ib = species.findSpecies(spB);
183  int chargeInd = species.addAttribute("charge");
184  int massInd = species.addAttribute("mass");
185  std::string illegal_species;
186  if (ia == species.size())
187  illegal_species = spA;
188  if (ib == species.size())
189  {
190  if (illegal_species.size())
191  illegal_species += " and ";
192  illegal_species += spB;
193  }
194  if (illegal_species.size())
195  PRE.error("species " + illegal_species + " requested for Jastrow " + j2name +
196  " does not exist in ParticleSet " + targetPtcl.getName(),
197  true);
198  if (ia == ib && (targetPtcl.last(ia) - targetPtcl.first(ia) == 1))
199  PRE.error("Failed to add " + spA + spB + " correlation for only 1 " + spA +
200  " particle. Please remove it from two-body Jastrow.",
201  true);
202  if (cusp < -1e6)
203  { // see eq. (9) in https://arxiv.org/abs/2003.06506
204  RealType qq = species(chargeInd, ia) * species(chargeInd, ib);
205  RealType red_mass = species(massInd, ia) * species(massInd, ib) / (species(massInd, ia) + species(massInd, ib));
206  RealType dim_factor = (ia == ib) ? 1.0 / (ndim + 1) : 1.0 / (ndim - 1);
207  if (ndim == 1)
208  dim_factor = 1.0 / (ndim + 1);
209  cusp = -2 * qq * red_mass * dim_factor;
210  }
211  app_summary() << " Radial function for species: " << spA << " - " << spB << std::endl;
212  app_debug() << " RadialJastrowBuilder adds a functor with cusp = " << cusp << std::endl;
213 
214  const auto coef_id = extractCoefficientsID(cur);
215  auto functor = std::make_unique<RadFuncType>(coef_id.empty() ? j2name + "_" + spA + spB : coef_id);
216  functor->setCusp(cusp);
217  functor->setPeriodic(targetPtcl.getLattice().SuperCellEnum != SUPERCELL_OPEN);
218  functor->cutoff_radius = targetPtcl.getLattice().WignerSeitzRadius;
219  bool functor_initialized = functor->put(cur);
220  if (!functor_initialized && init_mode == "rpa")
221  {
222  initTwoBodyFunctor(*functor, -cusp / 0.5);
223  }
224 
225  app_summary() << std::endl;
226 
228  {
229  std::array<char, 32> fname;
230  if (std::snprintf(fname.data(), fname.size(), "J2.%s.%s.g%03d.dat", NameOpt.c_str(), pairType.c_str(),
231  getGroupID()) < 0)
232  throw std::runtime_error("Error generating filename");
233  std::ofstream os(fname.data());
234  print(*functor, os);
235  }
236 
237  J2->addFunc(ia, ib, std::move(functor));
238  }
239  cur = cur->next;
240  }
241 
242  // compute Chiesa Correction based on the current J2 parameters
243  J2->ChiesaKEcorrection();
244 
245  // Ye: actually don't know what uk.dat is used for
246  if (targetPtcl.getLattice().SuperCellEnum)
247  computeJ2uk(J2->getPairFunctions());
248 
249  // sanity check before returning the constructed J2
250  J2->checkSanity();
251 
252  return J2;
253 }
const std::string & getName() const
return the name
#define app_debug
Definition: OutputManager.h:75
void print(OptimizableFunctorBase &func, std::ostream &os, double extent)
evaluates a functor (value and derivative) and dumps the quantities to output
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
int getGroupID() const
return the group id of the communicator
Definition: MPIObjectBase.h:38
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
ForceBase::Real Real
Definition: ForceBase.cpp:26
OutputManagerClass outputManager(Verbosity::HIGH)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
std::string NameOpt
<jastrow name="...">
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::string ClassName
class Name
Definition: MPIObjectBase.h:65
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
std::string Jastfunction
<jastrow function="...">
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void computeJ2uk(const std::vector< RadFuncType *> &functors)
QMCTraits::RealType RealType
OHMMS_PRECISION real_type
TwoBodyJastrow< RadFuncType > J2Type
const auto & getLattice() const
Definition: ParticleSet.h:251
bool is_manager() const
return true if the rank == 0
Definition: MPIObjectBase.h:51
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
void initTwoBodyFunctor(RadFuncType &functor, double fac)
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
bool isActive(Verbosity level) const

◆ createJ2() [2/2]

std::unique_ptr<WaveFunctionComponent> createJ2 ( xmlNodePtr  cur)
private

Definition at line 309 of file RadialJastrowBuilder.cpp.

310 {
311  auto rpajastrow = std::make_unique<RPAJastrow>(targetPtcl);
312  rpajastrow->put(cur);
313  return rpajastrow;
314 }
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined

◆ guardAgainstOBC()

void guardAgainstOBC ( )
private

Definition at line 78 of file RadialJastrowBuilder.cpp.

References qmcplusplus::app_error(), ParticleSet::getLattice(), RadialJastrowBuilder::Jastfunction, qmcplusplus::SUPERCELL_OPEN, and WaveFunctionComponentBuilder::targetPtcl.

Referenced by RadialJastrowBuilder::buildComponent().

79 {
80  if (targetPtcl.getLattice().SuperCellEnum == SUPERCELL_OPEN)
81  {
82  app_error() << Jastfunction << " relies on the total density for its form\n";
83  app_error() << "but open boundary conditions are requested. Please choose other forms of Jastrow\n";
84  }
85 }
std::ostream & app_error()
Definition: OutputManager.h:67
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
std::string Jastfunction
<jastrow function="...">
const auto & getLattice() const
Definition: ParticleSet.h:251

◆ guardAgainstPBC()

void guardAgainstPBC ( )
private

Definition at line 88 of file RadialJastrowBuilder.cpp.

References qmcplusplus::app_error(), ParticleSet::getLattice(), RadialJastrowBuilder::Jastfunction, qmcplusplus::SUPERCELL_OPEN, and WaveFunctionComponentBuilder::targetPtcl.

Referenced by RadialJastrowBuilder::buildComponent().

89 {
90  if (targetPtcl.getLattice().SuperCellEnum != SUPERCELL_OPEN)
91  {
92  app_error() << Jastfunction << " does not support a cutoff, but is requested with\n";
93  app_error() << "periodic boundary conditions, please choose other forms of Jastrow\n";
94  }
95 }
std::ostream & app_error()
Definition: OutputManager.h:67
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
std::string Jastfunction
<jastrow function="...">
const auto & getLattice() const
Definition: ParticleSet.h:251

◆ initTwoBodyFunctor() [1/2]

void initTwoBodyFunctor ( RadFuncType &  functor,
double  fac 
)
private

Definition at line 98 of file RadialJastrowBuilder.cpp.

Referenced by RadialJastrowBuilder::createJ2().

99 {}

◆ initTwoBodyFunctor() [2/2]

void initTwoBodyFunctor ( BsplineFunctor< RealType > &  bfunc,
double  fac 
)

Definition at line 102 of file RadialJastrowBuilder.cpp.

References qmcplusplus::app_log(), LRRPAHandlerTemp< Func, BreakupBasis >::Breakup(), OptimizableFunctorBase::cutoff_radius, LRRPAHandlerTemp< Func, BreakupBasis >::evaluate(), ParticleSet::getLattice(), BsplineFunctor< REAL >::NumParams, BsplineFunctor< REAL >::Parameters, BsplineFunctor< REAL >::reset(), qmcplusplus::SUPERCELL_OPEN, and WaveFunctionComponentBuilder::targetPtcl.

103 {
104  if (targetPtcl.getLattice().SuperCellEnum == SUPERCELL_OPEN) // for open systems, do nothing
105  {
106  return;
107  }
108  app_log() << " Initializing Two-Body with RPA Jastrow " << std::endl;
109  std::vector<RealType> rpaValues;
110  int npts = bfunc.NumParams;
111  if (rpaValues.empty())
112  {
113  rpaValues.resize(npts);
114  LRRPAHandlerTemp<RPABreakup<RealType>, LPQHIBasis> rpa(targetPtcl, -1.0);
115  rpa.Breakup(targetPtcl, -1.0);
116  RealType dr = bfunc.cutoff_radius / static_cast<RealType>(npts);
117  RealType r = 0;
118  for (int i = 0; i < npts; i++)
119  {
120  rpaValues[i] = rpa.evaluate(r, 1.0 / r); //y[i]=fac*rpa.evaluate(r,1.0/r);
121  r += dr;
122  }
123  }
124  RealType last = rpaValues[npts - 1];
125 
126  for (int i = 0; i < npts; i++)
127  bfunc.Parameters[i] = fac * (rpaValues[i] - last);
128  bfunc.reset();
129 }
std::ostream & app_log()
Definition: OutputManager.h:65
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
QMCTraits::RealType RealType
const auto & getLattice() const
Definition: ParticleSet.h:251

Member Data Documentation

◆ Jastfunction

◆ NameOpt

◆ SourcePtcl

ParticleSet* SourcePtcl
private

particle set for source particle

Definition at line 60 of file RadialJastrowBuilder.h.

Referenced by RadialJastrowBuilder::createJ1().

◆ SpinOpt

std::string SpinOpt
private

<jastrow spin="...">

Definition at line 58 of file RadialJastrowBuilder.h.

Referenced by RadialJastrowBuilder::buildComponent(), and RadialJastrowBuilder::RadialJastrowBuilder().

◆ TypeOpt

std::string TypeOpt
private

<jastrow type="...">

Definition at line 54 of file RadialJastrowBuilder.h.

Referenced by RadialJastrowBuilder::buildComponent(), and RadialJastrowBuilder::RadialJastrowBuilder().


The documentation for this class was generated from the following files: