16 #ifndef QMCPLUSPLUS_SHORTRANGECUSPFUNCTOR_H 17 #define QMCPLUSPLUS_SHORTRANGECUSPFUNCTOR_H 74 std::vector<real_type>
B;
94 ID_A(
"string_not_set"),
95 ID_R0(
"string_not_set"),
96 ID_B(
"string_not_set")
133 for (
int i = 0; i <
B.size(); i++)
135 sig_sum +=
B[i] * sn / (1.0 + sn);
168 for (
int i = 0; i <
B.size(); i++)
174 sig_sum_0 +=
B[i] * sn / d;
175 sig_sum_1 +=
B[i] * (sn * sn + sn -
n * snm1) / d2;
176 sig_sum_2 +=
B[i] * snm2 * (d * noverd2 * noverd2 * (sn - 1.0) + noverd2 * (1.0 + 2.0 *
s) - soverd *
s);
188 dudr =
A * ex + exoverR0 * sig_sum_1;
191 d2udr2 = -
A * exoverR0 + exoverR02 * sig_sum_2;
194 return -1.0 * ex * (
A *
R0 + sig_sum_0);
200 ReportEngine PRE(
"ShortRangeCuspFunctor",
"evaluate(r, dudr, d2udr2, d3udr3)");
201 PRE.
error(
"evaluate(r, dudr, d2udr2, d3udr3) not implemented for ShortRangeCuspFunctor",
true);
209 const T* restrict _distArray,
210 T* restrict distArrayCompressed)
const 213 for (
int idx = iStart; idx < iEnd; idx++)
229 const int dist_stride,
233 for (
int ip = 0; ip < num_pairs; ip++)
236 for (
int j = 0; j < n_src; j++)
238 const int ig = grp_ids[j];
239 auto& functor(*functors[ig]);
241 mw_vals[ip] += functor.evaluate(mw_dist[ip * dist_stride + j]);
251 T* restrict valArray,
252 T* restrict gradArray,
253 T* restrict laplArray,
254 T* restrict distArrayCompressed,
255 int* restrict distIndices)
const 257 for (
int idx = iStart; idx < iEnd; idx++)
259 valArray[idx] =
evaluate(distArray[idx], gradArray[idx], laplArray[idx]);
260 gradArray[idx] /= distArray[idx];
262 if (iat >= iStart && iat < iEnd)
263 valArray[iat] = gradArray[iat] = laplArray[iat] = T(0);
304 derivs[i][0] = -ex *
R0;
306 derivs[i][2] = -exoverR0;
321 for (
int j = 0; j <
B.size(); j++)
327 sig_sum_0 +=
B[j] * sn * (noverd2 - soverd);
328 sig_sum_1 +=
B[j] * snm1 * (d * noverd2 * noverd2 * (1.0 - sn) - 2.0 * noverd2 *
s + soverd * (
s - 1.0));
329 sig_sum_2 +=
B[j] * snm2 *
330 (
s * (3.0 *
s - 1.0) * noverd2 -
s * (
s - 2.0) * soverd +
331 (
n +
n * sn * (sn - 4.0) + (3.0 *
s + 1.0) * (sn * sn - 1.0)) * noverd2 * noverd2);
341 const real_type cusp_part_2 = -
A * exoverR02 * (
s - 1.0);
344 derivs[i][0] = cusp_part_0 + exoverR0 * sig_sum_0;
345 derivs[i][1] = cusp_part_1 + exoverR02 * sig_sum_1;
346 derivs[i][2] = cusp_part_2 + exoverR03 * sig_sum_2;
360 for (
int j = 0; j <
B.size(); j++)
369 derivs[i][0] = -ex * sn / d;
372 derivs[i][1] = exoverR0 * (sn * sn + sn -
n * snm1) / d2;
375 derivs[i][2] = exoverR02 * snm2 * (d * noverd2 * noverd2 * (sn - 1.0) + noverd2 * (1.0 + 2.0 *
s) - soverd *
s);
408 derivs[i] = -ex *
R0;
419 for (
int j = 0; j <
B.size(); j++)
425 sig_sum +=
B[j] * sn * (noverd2 - soverd);
434 derivs[i] = cusp_part + exoverR0 * sig_sum;
444 for (
int j = 0; j <
B.size(); j++)
446 derivs[i] = -ex * sn / (1.0 + sn);
460 std::string& id_to_set,
464 std::string id(
"string_not_set");
465 std::string name(
"string_not_set");
466 std::string
optimize(
"string_not_set");
468 rAttrib.
add(
id,
"id");
469 rAttrib.
add(name,
"name");
477 if (
id !=
"string_not_set")
484 if (
id ==
"string_not_set")
485 PRE.
error(
"\"id\" must be set if we are going to optimize variable " + name,
true);
493 else if (
optimize !=
"string_not_set")
495 PRE.
error(
"Unrecognized value for \"optimize\". Should be either yes or no",
true);
500 bool put(xmlNodePtr cur)
override 503 ReportEngine PRE(
"ShortRangeCuspFunctor",
"put(xmlNodePtr)");
511 rAttrib.
add(radius,
"rcut");
512 rAttrib.
add(radius,
"cutoff");
513 rAttrib.
add(cusp_in,
"cusp");
525 xmlNodePtr childPtr = cur->xmlChildrenNode;
526 while (childPtr != NULL)
529 if (xmlIsBlankNode(childPtr))
531 childPtr = childPtr->next;
541 std::string v_name(
"string_not_set");
543 att.
add(v_name,
"name");
549 else if (v_name ==
"R0")
551 else if (v_name ==
"string_not_set")
552 PRE.
error(
"variable name not set",
true);
554 PRE.
error(
"unrecognized variable name: " + v_name,
true);
558 else if (cname ==
"coefficients")
561 std::string id(
"string_not_set");
562 std::string type(
"string_not_set");
563 std::string
optimize(
"string_not_set");
566 att.
add(type,
"type");
572 PRE.
error(
"ShortRangeCuspFunctor expected coefficients parameter array type to be \"Array\"",
true);
578 if (
id !=
"string_not_set")
585 if (
id ==
"string_not_set")
586 PRE.
error(
"\"id\" must be set if we are going to optimize B coefficients",
true);
588 for (
int i = 0; i <
B.size(); i++)
590 std::stringstream sstr;
591 sstr <<
ID_B <<
"_" << i;
599 else if (
optimize !=
"string_not_set")
601 PRE.
error(
"Unrecognized value for \"optimize\". Should be either yes or no",
true);
608 PRE.
error(
"\"" + cname +
609 "\" is not a recognized value for \"cname\". Allowed values are \"var\" and \"coefficients\"",
614 childPtr = childPtr->next;
618 app_summary() <<
" ---------------------------------------------------------" << std::endl;
619 app_summary() <<
" cusp variable A: " <<
A << std::endl;
621 app_summary() <<
" sigmoidal expansion coefficients B:";
622 for (
int i = 0; i <
B.size(); i++)
658 for (
int j = 0;
Opt_B && j <
B.size(); j++)
real_type f(real_type r) override
compute U(r) at a particular distance or return zero if beyond the cutoff
static void mw_evaluateV(const int num_groups, const ShortRangeCuspFunctor *const functors[], const int n_src, const int *grp_ids, const int num_pairs, const int *ref_at, const T *mw_dist, const int dist_stride, T *mw_vals, Vector< char, OffloadPinnedAllocator< char >> &transfer_buffer)
evaluate sum of the pair potentials FIXME
bool evaluateDerivatives(real_type r, std::vector< TinyVector< real_type, 3 >> &derivs) override
compute derivatives of U(r), dU/dr, and d^2U/dr^2 with respect to the variational parameters ...
helper functions for EinsplineSetBuilder
void set_variable_from_xml(ReportEngine &PRE, xmlNodePtr cur, U &variable_to_set, std::string &id_to_set, bool &opt_to_set)
set up a variational parameter using the supplied xml node
bool Opt_R0
true, if R0 is optimizable
std::ostream & app_summary()
bool put(xmlNodePtr cur)
assign attributes to the set
void reset() override
Implement the reset function, which was pure virtual in OptimizableFunctorBase, even though we don't ...
real_type evaluate(real_type r, real_type &dudr, real_type &d2udr2) const
compute U(r), dU/dr, and d^2U/dr^2 at a particular value of r
Define a base class for one-dimensional functions with optimizable variables.
real_type df(real_type r) override
compute dU/dr at a particular distance or return zero if beyond the cutoff
real_type A
variable that controls the cusp
bool put(xmlNodePtr cur) override
read in information about the functor from an xml node
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Final class and should not be derived.
class to handle a set of attributes of an xmlNode
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
declaration of ProgressReportEngine
std::string lowerCase(const std::string_view s)
++17
class to handle a set of variables that can be modified during optimizations
bool evaluateDerivatives(real_type r, std::vector< real_type > &derivs) override
compute derivatives of U(r) with respect to the variational parameters
int where(int i) const
return the locator of the i-th Index
char * castXMLCharToChar(xmlChar *c)
assign a value from a node. Use specialization for classes.
OHMMS_PRECISION real_type
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
OMPallocator is an allocator with fused device and dualspace allocator functionality.
bool Opt_A
true, if A is optimizable
real_type evaluate(real_type r) const
compute U(r) at a particular value of r
void resetParametersExclusive(const opt_variables_type &active) override
reset the parameters during optimizations.
size_type size() const
return the size
real_type cutoff_radius
maximum cutoff
bool Opt_B
true, if B variables are optimizable
Base class for any functor with optimizable parameters.
ShortRangeCuspFunctor(const std::string &my_name)
default constructor
bool putContent(T &a, xmlNodePtr cur)
replaces a's value with the first "element" in the "string" returned by XMLNodeString{cur}.
void checkInVariablesExclusive(opt_variables_type &active) override
check in variational parameters to the global list of parameters used by the optimizer.
std::string ID_R0
id of R0
void setCusp(real_type cusp) override
sets the cusp condition and disables optimization of the cusp-determining parameter ...
void error(const std::string &msg, bool fatal=false)
OptimizableFunctorBase * makeClone() const override
clone the functor
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
std::vector< real_type > B
variables that add detail through an expansion in sigmoidal functions
real_type evaluateV(const int iat, const int iStart, const int iEnd, const T *restrict _distArray, T *restrict distArrayCompressed) const
compute U(r) at multiple distances and sum the results
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
real_type evaluate(real_type r, real_type &dudr, real_type &d2udr2, real_type &d3udr3) const
compute U(r), dU/dr, d^2U/dr^2, and d^3U/dr^3
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
void evaluateVGL(const int iat, const int iStart, const int iEnd, const T *distArray, T *restrict valArray, T *restrict gradArray, T *restrict laplArray, T *restrict distArrayCompressed, int *restrict distIndices) const
compute U(r), dU/dr, and d^2U/dr^2 at multiple values of r
opt_variables_type myVars
set of variables to be optimized
real_type R0
the soft cutoff distance that controls how short ranged the functor is