14 #include <type_traits> 40 template<
class RadFuncType,
unsigned Implementation = RadialJastrowBuilder::detail::CPU>
83 app_error() <<
"but open boundary conditions are requested. Please choose other forms of Jastrow\n";
93 app_error() <<
"periodic boundary conditions, please choose other forms of Jastrow\n";
97 template<
class RadFuncType>
108 app_log() <<
" Initializing Two-Body with RPA Jastrow " << std::endl;
109 std::vector<RealType> rpaValues;
111 if (rpaValues.empty())
113 rpaValues.resize(npts);
118 for (
int i = 0; i < npts; i++)
120 rpaValues[i] = rpa.
evaluate(r, 1.0 / r);
124 RealType last = rpaValues[npts - 1];
126 for (
int i = 0; i < npts; i++)
127 bfunc.
Parameters[i] = fac * (rpaValues[i] - last);
132 template<
class RadFuncType,
unsigned Implementation>
140 std::string j2name = input_name.empty() ?
"J2_" +
Jastfunction : input_name;
143 auto J2 = std::make_unique<J2Type>(j2name,
targetPtcl, Implementation == RadialJastrowBuilder::detail::OMPTARGET);
145 std::string init_mode(
"0");
148 hAttrib.
add(init_mode,
"init");
152 cur = cur->xmlChildrenNode;
155 std::string cname((
const char*)cur->name);
156 if (cname ==
"correlation")
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");
169 if (pairType[0] ==
'0')
171 pairType = spA + spB;
175 PRE.
warning(
"pairType is deprecated. Use speciesA/speciesB");
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())
190 if (illegal_species.size())
191 illegal_species +=
" and ";
192 illegal_species += spB;
194 if (illegal_species.size())
195 PRE.
error(
"species " + illegal_species +
" requested for Jastrow " + j2name +
199 PRE.
error(
"Failed to add " + spA + spB +
" correlation for only 1 " + spA +
200 " particle. Please remove it from two-body Jastrow.",
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);
208 dim_factor = 1.0 / (ndim + 1);
209 cusp = -2 * qq * red_mass * dim_factor;
211 app_summary() <<
" Radial function for species: " << spA <<
" - " << spB << std::endl;
212 app_debug() <<
" RadialJastrowBuilder adds a functor with cusp = " << cusp << std::endl;
215 auto functor = std::make_unique<RadFuncType>(coef_id.empty() ? j2name +
"_" + spA + spB : coef_id);
216 functor->setCusp(cusp);
219 bool functor_initialized = functor->put(cur);
220 if (!functor_initialized && init_mode ==
"rpa")
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(),
232 throw std::runtime_error(
"Error generating filename");
233 std::ofstream os(fname.data());
237 J2->addFunc(ia, ib, std::move(functor));
243 J2->ChiesaKEcorrection();
256 template<
class RadFuncType>
259 const int numPoints = 1000;
262 FILE* fout =
nullptr;
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");
282 if (functors[i * nsp + j])
284 auto& ufunc = *functors[i * nsp + j];
285 RealType radius = ufunc.cutoff_radius;
288 for (
int ir = 0; ir < numPoints; ir++)
292 aparam += (1.0 / 4.0) * k * k * 4.0 * M_PI * r *
std::sin(k * r) / k * u * dr;
298 sum += Ni * aparam / vol;
301 fprintf(fout,
"%1.8f %1.12e %1.12e\n", Gmag, uk, sum);
309 std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ2<RPAFunctor>(xmlNodePtr cur)
311 auto rpajastrow = std::make_unique<RPAJastrow>(targetPtcl);
312 rpajastrow->put(cur);
316 template<
class RadFuncType,
bool SPIN,
unsigned Implementation>
322 using J1Type =
typename std::conditional<SPIN, typename TH::J1SpinType, typename TH::J1Type>::type;
325 std::string jname = input_name.empty() ?
Jastfunction : input_name;
335 bool use_offload =
false;
340 std::ostringstream msg;
341 msg << R
"(Offload enabled Jastrow needs the gpu="yes" attribute in the ")" << SourcePtcl->getName() 342 << "\" particleset" << std::endl;
345 app_summary() <<
" Running OpenMP offload code path." << std::endl;
351 xmlNodePtr kids = cur->xmlChildrenNode;
356 bool success =
false;
360 if (kidsname ==
"correlation")
362 std::string speciesA;
363 std::string speciesB;
366 rAttrib.
add(speciesA,
"elementType");
367 rAttrib.
add(speciesA,
"speciesA");
368 rAttrib.
add(speciesB,
"speciesB");
369 rAttrib.
add(cusp,
"cusp");
373 auto functor = std::make_unique<RadFuncType>(coef_id.empty() ? jname +
"_" + speciesA + speciesB : coef_id);
376 functor->setCusp(cusp);
378 const int jg = speciesB.size() ? tSet.
findSpecies(speciesB) : -1;
381 PRE.
error(
"species " + speciesA +
" requested for Jastrow " + jname +
" does not exist in ParticleSet " +
387 PRE.
error(
"species " + speciesB +
" requested for Jastrow " + jname +
" does not exist in ParticleSet " +
391 app_summary() <<
" Radial function for element: " << speciesA <<
" - " 397 std::array<char, 128> fname;
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());
403 fname_len = std::snprintf(fname.data(), fname.size(),
"%s.%s.%s.g%03d.dat", jname.c_str(),
NameOpt.c_str(),
406 throw std::runtime_error(
"Error generating filename");
407 std::ofstream os(std::string(fname.data(), fname_len));
411 double plotextent = 10.0;
412 print(*functor.get(), os, plotextent);
416 print(*functor.get(), os);
419 J1->addFunc(ig, std::move(functor), jg);
432 PRE.
error(
"BsplineJastrowBuilder failed to add an One-Body Jastrow.");
433 return std::unique_ptr<WaveFunctionComponent>();
439 std::unique_ptr<WaveFunctionComponent> RadialJastrowBuilder::createJ1<RPAFunctor>(xmlNodePtr cur)
448 std::string input_name;
449 std::string rpafunc =
"RPA";
451 a.
add(input_name,
"name");
452 a.
add(rpafunc,
"function");
457 params.
add(Rs,
"rs");
458 params.
add(Kc,
"kc");
461 std::string jname = input_name.empty() ? Jastfunction : input_name;
463 HandlerType* myHandler =
nullptr;
466 Rs =
std::pow(3.0 / 4.0 / M_PI * targetPtcl.getLattice().Volume /
static_cast<RealType>(targetPtcl.getTotalNum()),
473 if (rpafunc ==
"RPA")
476 app_log() <<
" using e-p RPA" << std::endl;
478 else if (rpafunc ==
"dRPA")
481 app_log() <<
" using e-p derivRPA" << std::endl;
483 myHandler->Breakup(targetPtcl, Rs);
485 Real Rcut = myHandler->get_rc() - 0.1;
487 int npts =
static_cast<int>(Rcut / 0.01) + 1;
488 myGrid->
set(0, Rcut, npts);
491 auto nfunc = std::make_unique<RadFunctorType>();
494 nfunc->initialize(SRA, myGrid);
496 auto J1 = std::make_unique<J1Type>(jname, *SourcePtcl, targetPtcl,
false);
498 SpeciesSet& sSet = SourcePtcl->getSpeciesSet();
499 for (
int ig = 0; ig < sSet.getTotalNum(); ig++)
501 J1->addFunc(ig, std::move(nfunc));
533 return createJ1<BsplineFunctor<RealType>,
true>(cur);
535 return createJ1<BsplineFunctor<RealType>>(cur);
541 return createJ1<PadeFunctor<RealType>,
true>(cur);
543 return createJ1<PadeFunctor<RealType>>(cur);
548 return createJ1<Pade2ndOrderFunctor<RealType>>(cur);
554 return createJ1<ShortRangeCuspFunctor<RealType>,
true>(cur);
556 return createJ1<ShortRangeCuspFunctor<RealType>>(cur);
561 return createJ1<UserFunctor<RealType>,
true>(cur);
563 return createJ1<UserFunctor<RealType>>(cur);
567 #if !(OHMMS_DIM == 3) 568 app_error() <<
"RPA for one-body jastrow is only available for 3D\n";
571 app_error() <<
"one body RPA jastrow is not supported at the moment\n";
589 "check consistent type");
592 std::ostringstream msg;
593 msg << R
"(Offload enabled Jastrow needs the gpu="yes" attribute in the ")" << targetPtcl.getName() 594 << "\" particleset" << std::endl;
597 app_summary() <<
" Running OpenMP offload code path." << std::endl;
601 return createJ2<BsplineFunctor<RealType>>(cur);
606 return createJ2<PadeFunctor<RealType>>(cur);
610 return createJ2<UserFunctor<RealType>>(cur);
614 #if !(OHMMS_DIM == 3) 615 app_error() <<
"RPA for one-body jastrow is only available for 3D\n";
618 return createJ2<RPAFunctor>(cur);
625 APP_ABORT(
"RadialJastrowBuilder::buildComponent not able to create Jastrow!\n");
std::unique_ptr< WaveFunctionComponent > createJ1(xmlNodePtr cur)
const std::string & getName() const
return the name
One-Dimensional linear-grid.
void set(T ri, T rf, int n) override
Set the grid given the parameters.
LRCoulombSingleton::GridType GridType
helper functions for EinsplineSetBuilder
An abstract class for wave function builders.
BsplineFunctor class for the Jastrows REAL is the real type used by offload target, it is the correct type for the mw data pointers and is also used to coerce/implicitly convert the Real type inherited OptimizableFunctorBase into that buffer if offload is off this happens too but is just an implementation quirk.
Declaration of OutputManager class.
void Breakup(ParticleSet &ref, mRealType rs_ext) override
void print(OptimizableFunctorBase &func, std::ostream &os, double extent)
evaluates a functor (value and derivative) and dumps the quantities to output
void warning(const std::string &msg)
std::ostream & app_summary()
bool put(xmlNodePtr cur)
assign attributes to the set
MakeReturn< UnaryNode< FnSin, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sin(const Vector< T1, C1 > &l)
std::unique_ptr< WaveFunctionComponent > buildComponent(xmlNodePtr cur) override
process a xml node at cur
Functor designed to encode short-ranged structure near a nuclear cusp.
std::ostream & app_error()
JastrowBuilder using an analytic 1d functor Should be able to eventually handle all one and two body ...
int getGroupID() const
return the group id of the communicator
void setRmax(real_type rm)
int first(int igroup) const
return the first index of a group i
bool is_same(const xmlChar *a, const char *b)
std::vector< Real > Parameters
ParticleSet * SourcePtcl
particle set for source particle
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
bool put(std::istream &is) override
read from std::istream
OutputManagerClass outputManager(Verbosity::HIGH)
ParticleSet & targetPtcl
reference to the particle set on which targetPsi is defined
int getTotalNum() const
return the number of species
Wrapping information on parallelism.
int groups() const
return the number of groups
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)
const auto & getSimulationCell() const
Specialization for one-body Jastrow function using multiple functors.
Specialized paritlce class for atomistic simulations.
DynamicCoordinateKind getKind() const
std::string NameOpt
<jastrow name="...">
class to handle a set of parameters
A derivative of LRBasis class to provide the functionality of the LPQHI basis.
Final class and should not be derived.
Communicate * myComm
pointer to Communicate
class to handle a set of attributes of an xmlNode
std::string lowerCase(const std::string_view s)
++17
Functors which implement Pade functions.
Specialization for one-body Jastrow function using multiple functors.
std::string ClassName
class Name
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
int last(int igroup) const
return the last index of a group i
static PlatformKind selectPlatform(std::string_view value)
RadialJastrowBuilder(Communicate *comm, ParticleSet &target, ParticleSet &source)
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...
WaveFunctionComponent::RealType RealType
Implements a Pade Function .
real_type cutoff_radius
maximum cutoff
Specialization for two-body Jastrow function using multiple functors.
std::string Jastfunction
<jastrow function="...">
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
mRealType evaluate(mRealType r, mRealType rinv) const override
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>
void computeJ2uk(const std::vector< RadFuncType *> &functors)
const DynamicCoordinates & getCoordinates() const
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
std::unique_ptr< WaveFunctionComponent > createJ2(xmlNodePtr cur)
OHMMS_PRECISION real_type
std::string SpinOpt
<jastrow spin="...">
std::string TypeOpt
<jastrow type="...">
void error(const std::string &msg, bool fatal=false)
const auto & getLattice() const
bool is_manager() const
return true if the rank == 0
base class for LRHandlerTemp<FUNC,BASIS> and DummyLRHanlder<typename Func>
Custom container for set of attributes for a set of species.
int findSpecies(const std::string &name) const
if the input species is not found, add a new species
void barrier_and_abort(const std::string &msg) const
std::string extractCoefficientsID(xmlNodePtr cur)
return the id of the first coefficients. If not found, return an emtpy string
Define LRHandlerBase and DummyLRHandler<typename Func>
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
bool isActive(Verbosity level) const
Define a LRHandler with two template parameters.
void reset() override
reset coefs from Parameters
const std::vector< std::string > candidate_values