QMCPACK
ExampleHeComponent Class Reference
+ Inheritance diagram for ExampleHeComponent:
+ Collaboration diagram for ExampleHeComponent:

Public Types

using OptVariablesType = optimize::VariableSet
 
using PtclGrpIndexes = QMCTraits::PtclGrpIndexes
 
- Public Types inherited from WaveFunctionComponent
enum  {
  ORB_PBYP_RATIO, ORB_PBYP_ALL, ORB_PBYP_PARTIAL, ORB_WALKER,
  ORB_ALLWALKER
}
 enum for a update mode More...
 
using Walker_t = ParticleSet::Walker_t
 
using WFBufferType = Walker_t::WFBuffer_t
 
using BufferType = Walker_t::Buffer_t
 
using RealMatrix_t = OrbitalSetTraits< RealType >::ValueMatrix
 
using ValueVector = OrbitalSetTraits< ValueType >::ValueVector
 
using ValueMatrix = OrbitalSetTraits< ValueType >::ValueMatrix
 
using GradMatrix = OrbitalSetTraits< ValueType >::GradMatrix
 
using HessType = OrbitalSetTraits< ValueType >::HessType
 
using HessVector = OrbitalSetTraits< ValueType >::HessVector
 
using LogValue = std::complex< QTFull::RealType >
 
using PsiValue = QTFull::ValueType
 
- Public Types inherited from QMCTraits
enum  { DIM = OHMMS_DIM, DIM_VGL = OHMMS_DIM + 2 }
 
using QTBase = QMCTypes< OHMMS_PRECISION, DIM >
 
using QTFull = QMCTypes< OHMMS_PRECISION_FULL, DIM >
 
using RealType = QTBase::RealType
 
using ComplexType = QTBase::ComplexType
 
using ValueType = QTBase::ValueType
 
using PosType = QTBase::PosType
 
using GradType = QTBase::GradType
 
using TensorType = QTBase::TensorType
 
using IndexType = OHMMS_INDEXTYPE
 define other types More...
 
using FullPrecRealType = QTFull::RealType
 
using FullPrecValueType = QTFull::ValueType
 
using PropertySetType = RecordNamedProperty< FullPrecRealType >
 define PropertyList_t More...
 
using PtclGrpIndexes = std::vector< std::pair< int, int > >
 

Public Member Functions

 ExampleHeComponent (const ParticleSet &ions, ParticleSet &els)
 
std::string getClassName () const override
 return class name More...
 
void extractOptimizableObjectRefs (UniqueOptObjRefs &opt_obj_refs) override
 extract underlying OptimizableObject references More...
 
bool isOptimizable () const override
 if true, this contains optimizable components More...
 
void checkInVariablesExclusive (OptVariablesType &active) override
 check in variational parameters to the global list of parameters used by the optimizer. More...
 
void checkOutVariables (const OptVariablesType &active) override
 check out variational optimizable variables More...
 
void resetParametersExclusive (const OptVariablesType &active) override
 reset the parameters during optimizations. More...
 
LogValue evaluateLog (const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
 evaluate the value of the WaveFunctionComponent from scratch More...
 
void acceptMove (ParticleSet &P, int iat, bool safe_to_delay=false) override
 a move for iat-th particle is accepted. More...
 
void restore (int iat) override
 If a move for iat-th particle is rejected, restore to the content. More...
 
PsiValue ratio (ParticleSet &P, int iat) override
 evaluate the ratio of the new to old WaveFunctionComponent value More...
 
GradType evalGrad (ParticleSet &P, int iat) override
 return the current gradient for the iat-th particle More...
 
PsiValue ratioGrad (ParticleSet &P, int iat, GradType &grad_iat) override
 evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient More...
 
void evaluateDerivatives (ParticleSet &P, const OptVariablesType &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
 Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimizable parameters. More...
 
void registerData (ParticleSet &P, WFBufferType &buf) override
 For particle-by-particle move. More...
 
LogValue updateBuffer (ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
 For particle-by-particle move. More...
 
void copyFromBuffer (ParticleSet &P, WFBufferType &buf) override
 For particle-by-particle move. More...
 
std::unique_ptr< WaveFunctionComponentmakeClone (ParticleSet &tpq) const override
 make clone More...
 
bool put (xmlNodePtr cur)
 
- Public Member Functions inherited from WaveFunctionComponent
const LogValueget_log_value () const
 
 WaveFunctionComponent (const std::string &obj_name="")
 default constructor More...
 
virtual ~WaveFunctionComponent ()
 default destructor More...
 
virtual void checkSanity () const
 Validate the internal consistency of the object. More...
 
const std::string & getName () const
 return object name More...
 
PsiValue getValue () const
 assembles the full value More...
 
virtual bool isFermionic () const
 true, if this component is fermionic More...
 
virtual bool isMultiDet () const
 true, if this component is multi-determinant More...
 
virtual void registerTWFFastDerivWrapper (const ParticleSet &P, TWFFastDerivWrapper &twf) const
 Register the component with the TWFFastDerivWrapper wrapper. More...
 
virtual void mw_evaluateLog (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list) const
 evaluate from scratch the same type WaveFunctionComponent of multiple walkers More...
 
virtual void recompute (const ParticleSet &P)
 recompute the value of the WaveFunctionComponents which require critical accuracy. More...
 
virtual void mw_recompute (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< bool > &recompute) const
 
virtual void evaluateHessian (ParticleSet &P, HessVector &grad_grad_psi_all)
 
virtual void prepareGroup (ParticleSet &P, int ig)
 Prepare internal data for updating WFC correspond to a particle group It should be called before moving particles of a given group. More...
 
virtual void mw_prepareGroup (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int ig) const
 
virtual GradType evalGradWithSpin (ParticleSet &P, int iat, ComplexType &spingrad)
 return the current spin gradient for the iat-th particle Default implementation assumes that WaveFunctionComponent does not explicitly depend on Spin. More...
 
template<CoordsType CT>
void mw_evalGrad (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const int iat, TWFGrads< CT > &grads_now) const
 compute the current gradients for the iat-th particle of multiple walkers More...
 
virtual void mw_evalGrad (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< GradType > &grad_now) const
 compute the current gradients for the iat-th particle of multiple walkers More...
 
virtual GradType evalGradSource (ParticleSet &P, ParticleSet &source, int iat)
 return the logarithmic gradient for the iat-th particle of the source particleset More...
 
virtual GradType evalGradSource (ParticleSet &P, ParticleSet &source, int iat, TinyVector< ParticleSet::ParticleGradient, OHMMS_DIM > &grad_grad, TinyVector< ParticleSet::ParticleLaplacian, OHMMS_DIM > &lapl_grad)
 Adds the gradient w.r.t. More...
 
virtual PsiValue ratioGradWithSpin (ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad_iat)
 evaluate the ratio of the new to old WaveFunctionComponent value and the new spin gradient Default implementation assumes that WaveFunctionComponent does not explicitly depend on Spin. More...
 
template<CoordsType CT>
void mw_ratioGrad (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, TWFGrads< CT > &grad_new) const
 
virtual void mw_ratioGrad (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, std::vector< GradType > &grad_new) const
 compute the ratio of the new to old WaveFunctionComponent value and the new gradient of multiple walkers More...
 
virtual void mw_accept_rejectMove (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< bool > &isAccepted, bool safe_to_delay=false) const
 moves of the iat-th particle on some walkers in a batch is accepted. More...
 
virtual void completeUpdates ()
 complete all the delayed or asynchronous operations before leaving the p-by-p move region. More...
 
virtual void mw_completeUpdates (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
 complete all the delayed or asynchronous operations for all the walkers in a batch before leaving the p-by-p move region. More...
 
virtual void mw_calcRatio (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios) const
 compute the ratio of the new to old WaveFunctionComponent value of multiple walkers More...
 
virtual LogValue evaluateGL (const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, bool fromscratch)
 compute gradients and laplacian of the TWF with respect to each particle. More...
 
virtual void mw_evaluateGL (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list, bool fromscratch) const
 evaluate gradients and laplacian of the same type WaveFunctionComponent of multiple walkers More...
 
virtual void createResource (ResourceCollection &collection) const
 initialize a shared resource and hand it to a collection More...
 
virtual void acquireResource (ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
 acquire a shared resource from a collection More...
 
virtual void releaseResource (ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
 return a shared resource to a collection More...
 
virtual RealType KECorrection ()
 Return the Chiesa kinetic energy correction. More...
 
virtual void evaluateDerivativesWF (ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi)
 Compute the derivatives of the log of the wavefunction with respect to optimizable parameters. More...
 
virtual void evaluateGradDerivatives (const ParticleSet::ParticleGradient &G_in, std::vector< ValueType > &dgradlogpsi)
 Calculates the derivatives of $ \nabla \textnormal{log} \psi_f $ with respect to the optimizable parameters, and the dot product of this is then performed with the passed-in G_in gradient vector. More...
 
virtual void finalizeOptimization ()
 
virtual void evaluateRatiosAlltoOne (ParticleSet &P, std::vector< ValueType > &ratios)
 evaluate the ratios of one virtual move with respect to all the particles More...
 
virtual void evaluateRatios (const VirtualParticleSet &VP, std::vector< ValueType > &ratios)
 evaluate ratios to evaluate the non-local PP More...
 
virtual void evaluateSpinorRatios (const VirtualParticleSet &VP, const std::pair< ValueVector, ValueVector > &spinor_multiplier, std::vector< ValueType > &ratios)
 Used by SOECPComponent for faster SOC evaluation. More...
 
virtual void mw_evaluateRatios (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, std::vector< std::vector< ValueType >> &ratios) const
 evaluate ratios to evaluate the non-local PP multiple walkers More...
 
virtual void evaluateDerivRatios (const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratios)
 evaluate ratios to evaluate the non-local PP More...
 
virtual void mw_evalGradWithSpin (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< GradType > &grad_now, std::vector< ComplexType > &spingrad_now) const
 compute the current gradients and spin gradients for the iat-th particle of multiple walkers More...
 
virtual void mw_ratioGradWithSpin (const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, std::vector< GradType > &grad_new, std::vector< ComplexType > &spingrad_new) const
 compute the ratio of the new to old WaveFunctionComponent value and the new gradient/spingradient of multiple walkers More...
 

Public Attributes

bool opt_B
 
RealType B
 
std::string ID_B
 
RealType A
 
RealType Z
 
- Public Attributes inherited from WaveFunctionComponent
int UpdateMode
 current update mode More...
 
opt_variables_type myVars
 list of variables this WaveFunctionComponent handles More...
 
size_t Bytes_in_WFBuffer
 Bytes in WFBuffer. More...
 

Private Attributes

const ParticleSetions_
 
const int my_table_ee_idx_
 
const int my_table_ei_idx_
 
OptVariablesType my_vars_
 

Additional Inherited Members

- Protected Attributes inherited from WaveFunctionComponent
const std::string my_name_
 Name of the object It is required to be different for objects of the same derived type like multiple J1. More...
 
LogValue log_value_
 Current $\log\phi $. More...
 
- Private Member Functions inherited from OptimizableObject
 OptimizableObject (const std::string &name)
 
const std::string & getName () const
 
bool isOptimized () const
 
virtual void reportStatus (std::ostream &os)
 print the state, e.g., optimizables More...
 
void setOptimization (bool state)
 
virtual void writeVariationalParameters (hdf_archive &hout)
 Write the variational parameters for this object to the VP HDF file. More...
 
virtual void readVariationalParameters (hdf_archive &hin)
 Read the variational parameters for this object from the VP HDF file. More...
 

Detailed Description

Definition at line 26 of file ExampleHeComponent.h.

Member Typedef Documentation

◆ OptVariablesType

Definition at line 35 of file ExampleHeComponent.h.

◆ PtclGrpIndexes

Definition at line 36 of file ExampleHeComponent.h.

Constructor & Destructor Documentation

◆ ExampleHeComponent()

ExampleHeComponent ( const ParticleSet ions,
ParticleSet els 
)
inline

Definition at line 29 of file ExampleHeComponent.h.

30  : OptimizableObject("example"),
31  ions_(ions),
For distance tables of virtual particle (VP) sets constructed based on this table, whether full table is needed on host The corresponding DT of VP need to set MW_EVALUATE_RESULT_NO_TRANSFER_TO_HOST accordingly.
OptimizableObject(const std::string &name)
whether temporary data set on the host is updated or not when a move is proposed. ...

Member Function Documentation

◆ acceptMove()

void acceptMove ( ParticleSet P,
int  iat,
bool  safe_to_delay = false 
)
inlineoverridevirtual

a move for iat-th particle is accepted.

Update the current content.

Parameters
Ptarget ParticleSet
iatindex of the particle whose new position was proposed
safe_to_delayif true, delayed accept is safe.

Implements WaveFunctionComponent.

Definition at line 49 of file ExampleHeComponent.h.

49 {}

◆ checkInVariablesExclusive()

void checkInVariablesExclusive ( OptVariablesType active)
inlineoverridevirtual

check in variational parameters to the global list of parameters used by the optimizer.

Parameters
activea super set of optimizable variables

The existing checkInVariables implementation in WFC/SPO/.. are inclusive and it calls checkInVariables of its members class A: public SPOSet {} class B: public WFC { A objA; checkInVariables() { objA.checkInVariables(); } };

With OptimizableObject, class A: public OptimizableObject {} class B: public OptimizableObject { A objA; checkInVariablesExclusive() { // should not call objA.checkInVariablesExclusive() if objA has been extracted; } }; A vector of OptimizableObject, will be created by calling extractOptimizableObjects(). All the checkInVariablesExclusive() will be called through this vector and thus checkInVariablesExclusive implementation should only handle non-OptimizableObject members.

Implements OptimizableObject.

Definition at line 41 of file ExampleHeComponent.h.

References VariableSet::insertFrom(), and ExampleHeComponent::my_vars_.

Referenced by qmcplusplus::TEST_CASE().

41 { active.insertFrom(my_vars_); }

◆ checkOutVariables()

void checkOutVariables ( const OptVariablesType active)
inlineoverridevirtual

check out variational optimizable variables

Parameters
activea super set of optimizable variables

Reimplemented from WaveFunctionComponent.

Definition at line 42 of file ExampleHeComponent.h.

References VariableSet::getIndex(), and ExampleHeComponent::my_vars_.

Referenced by qmcplusplus::TEST_CASE().

42 { my_vars_.getIndex(active); }
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter

◆ copyFromBuffer()

void copyFromBuffer ( ParticleSet P,
WFBufferType buf 
)
inlineoverridevirtual

For particle-by-particle move.

Copy data or attach memory from a walker buffer to the objects of this class. The log value, P.G and P.L contribution from the objects of this class are also added.

Parameters
Pparticle set
bufAnonymous storage

Implements WaveFunctionComponent.

Definition at line 69 of file ExampleHeComponent.h.

69 {}

◆ evalGrad()

ExampleHeComponent::GradType evalGrad ( ParticleSet P,
int  iat 
)
overridevirtual

return the current gradient for the iat-th particle

Parameters
Pquantum particle set
iatparticle index
Returns
the gradient of the iat-th particle

Reimplemented from WaveFunctionComponent.

Definition at line 140 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, ExampleHeComponent::B, DistanceTableAA::getDistances(), DistanceTableAB::getDistances(), ParticleSet::getDistTableAA(), ParticleSet::getDistTableAB(), ExampleHeComponent::my_table_ee_idx_, ExampleHeComponent::my_table_ei_idx_, and ExampleHeComponent::Z.

Referenced by qmcplusplus::TEST_CASE().

141 {
142  const auto& ei_table = P.getDistTableAB(my_table_ei_idx_);
143  const auto& ei_dists = ei_table.getDistances();
144  const auto& ei_displs = ei_table.getDisplacements();
145 
146  double r = ei_dists[iat][0];
147  auto rhat = ei_displs[iat][0] / r;
148 
149  const auto& ee_table = P.getDistTableAA(my_table_ee_idx_);
150  const auto& ee_dists = ee_table.getDistances();
151  const auto& ee_displs = ee_table.getDisplacements();
152 
153  // only the lower triangle of e-e Distances and Displacements can be used.
154  double r12 = ee_dists[1][0];
155  auto rhat12 = (iat == 0 ? -ee_displs[1][0] : ee_displs[1][0]) / r12;
156 
157  double du = A / ((B * r12 + 1) * (B * r12 + 1));
158 
159  return Z * rhat + rhat12 * du;
160 }

◆ evaluateDerivatives()

void evaluateDerivatives ( ParticleSet P,
const OptVariablesType optvars,
Vector< ValueType > &  dlogpsi,
Vector< ValueType > &  dhpsioverpsi 
)
overridevirtual

Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimizable parameters.

Parameters
Pparticle set
optvarsoptimizable parameters
dlogpsiarray of derivatives of the log of the wavefunction. Add the contribution from this component.
dhpsioverpsiarray of Hamiltonian derivatives. Add the kinetic energy derivatives contribution from this component. $ -\frac{1}{2}{\partial}_\alpha \tilde L - G \cdot {\partial}_\alpha \tilde G $. $ \tilde L $ and $ \tilde G $ are from this WaveFunctionComponent. $ G $ is from TrialWaveFunction. The 1/m factor is applied in TrialWaveFunction. This is a bug when the particle set doesn't hold equal mass particles.

Implements WaveFunctionComponent.

Definition at line 228 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, ExampleHeComponent::B, DistanceTableAA::getDistances(), DistanceTableAB::getDistances(), ParticleSet::getDistTableAA(), ParticleSet::getDistTableAB(), ExampleHeComponent::my_table_ee_idx_, ExampleHeComponent::my_table_ei_idx_, qmcplusplus::pow(), and ExampleHeComponent::Z.

Referenced by qmcplusplus::TEST_CASE().

232 {
233  using RealGradType = TinyVector<RealType, 3>;
234 
235  double tmpB = std::real(optvars[0]);
236 
237  const auto& ee_table = P.getDistTableAA(my_table_ee_idx_);
238  const auto& ee_dists = ee_table.getDistances();
239  const auto& ee_displs = ee_table.getDisplacements();
240  const auto& ee_temp_r = ee_table.getTempDists();
241  const auto& ee_temp_dr = ee_table.getTempDispls();
242 
243  double r12 = ee_dists[1][0];
244  auto rhat12 = ee_displs[1][0] / r12;
245 
246  const auto& ei_table = P.getDistTableAB(my_table_ei_idx_);
247  const auto& ei_dists = ei_table.getDistances();
248  const auto& ei_displs = ei_table.getDisplacements();
249  const auto& ei_temp_r = ei_table.getTempDists();
250  const auto& ei_temp_dr = ei_table.getTempDispls();
251 
252  double r1 = ei_dists[0][0];
253  double r2 = ei_dists[1][0];
254 
255  auto rhat1 = ei_displs[0][0] / r1;
256  auto rhat2 = ei_displs[1][0] / r2;
257 
258  dlogpsi[0] = A * r12 * r12 / ((tmpB * r12 + 1) * (tmpB * r12 + 1)) - A / (tmpB * tmpB);
259 
260  double df = -Z;
261  double du = A / ((B * r12 + 1) * (B * r12 + 1));
262  RealGradType G1 = -df * rhat1 - rhat12 * du;
263  RealGradType G2 = -df * rhat2 + rhat12 * du;
264 
265  double dudb = -2 * A * r12 / std::pow(B * r12 + 1, 3);
266  RealGradType dG1 = rhat12 * dudb;
267  RealGradType dG2 = -1 * rhat12 * dudb;
268 
269  double dlap = -6 * A / std::pow((tmpB * r12 + 1), 4);
270  dhpsioverpsi[0] =
271  dlap + (G1[0] * dG1[0] + G1[1] * dG1[1] + G1[2] * dG1[2]) + (G2[0] * dG2[0] + G2[1] * dG2[1] + G2[2] * dG2[2]);
272 }
QMCTraits::RealType real
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)

◆ evaluateLog()

evaluate the value of the WaveFunctionComponent from scratch

Parameters
[in]Pactive ParticleSet
[out]GGradients, $\nabla\ln\Psi$
[out]LLaplacians, $\nabla^2\ln\Psi$
Returns
the log value

Mainly for walker-by-walker move. The initial stage of particle-by-particle move also uses this. causes complete state update in WFC's

Implements WaveFunctionComponent.

Definition at line 65 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, ExampleHeComponent::B, DistanceTableAA::getDistances(), DistanceTableAB::getDistances(), ParticleSet::getDistTableAA(), ParticleSet::getDistTableAB(), qmcplusplus::log(), WaveFunctionComponent::log_value_, ExampleHeComponent::my_table_ee_idx_, ExampleHeComponent::my_table_ei_idx_, norm(), qmcplusplus::sqrt(), and ExampleHeComponent::Z.

Referenced by qmcplusplus::TEST_CASE(), and ExampleHeComponent::updateBuffer().

68 {
69  const auto& ee_table = P.getDistTableAA(my_table_ee_idx_);
70  const auto& ee_dists = ee_table.getDistances();
71  const auto& ee_displs = ee_table.getDisplacements();
72  // Only the lower triangle is up-to-date after particle-by-particle moves
73  double r12 = ee_dists[1][0];
74  auto rhat12 = ee_displs[1][0] / r12;
75 
76  const auto& ei_table = P.getDistTableAB(my_table_ei_idx_);
77  const auto& ei_dists = ei_table.getDistances();
78  const auto& ei_displs = ei_table.getDisplacements();
79 
80  // First index is electron, second index is ion
81  double r1 = ei_dists[0][0];
82  double r2 = ei_dists[1][0];
83 
84  auto rhat1 = ei_displs[0][0] / r1;
85  auto rhat2 = ei_displs[1][0] / r2;
86 
87  // Normalization for STO is not strictly necessary in this example, but it
88  // makes the values directly comparable to existing code
89  double norm = 0.5 / std::sqrt(M_PI);
90 
91  double du = A / ((B * r12 + 1) * (B * r12 + 1));
92 
93  double df1 = -Z;
94  G[0] = -df1 * rhat1 - du * rhat12;
95  // Previous line copies all three components and is the same as
96  //G[0][0] = -df1*rhat1[0];
97  //G[0][1] = -df1*rhat1[1];
98  //G[0][2] = -df1*rhat1[2];
99 
100  double df2 = -Z;
101  G[1] = -df2 * rhat2 + du * rhat12;
102 
103  double del_u = 2 * A / (r12 * (B * r12 + 1) * (B * r12 + 1) * (B * r12 + 1));
104 
105  L[0] = -2 * Z / r1 - del_u;
106  L[1] = -2 * Z / r2 - del_u;
107 
108  double u = A * r12 / (B * r12 + 1) - A / B;
109 
110  log_value_ = -Z * (r1 + r2) + std::log(norm * norm) - u;
111  return log_value_;
112 }
double norm(const zVec &c)
Definition: VectorOps.h:118
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)

◆ extractOptimizableObjectRefs()

void extractOptimizableObjectRefs ( UniqueOptObjRefs opt_obj_refs)
inlineoverridevirtual

extract underlying OptimizableObject references

Parameters
opt_obj_refsaggregated list of optimizable object references

Reimplemented from WaveFunctionComponent.

Definition at line 39 of file ExampleHeComponent.h.

References UniqueOptObjRefs::push_back().

39 { opt_obj_refs.push_back(*this); }

◆ getClassName()

std::string getClassName ( ) const
inlineoverridevirtual

return class name

Implements WaveFunctionComponent.

Definition at line 38 of file ExampleHeComponent.h.

38 { return "ExampleHeComponent"; }

◆ isOptimizable()

bool isOptimizable ( ) const
inlineoverridevirtual

if true, this contains optimizable components

Reimplemented from WaveFunctionComponent.

Definition at line 40 of file ExampleHeComponent.h.

40 { return true; }

◆ makeClone()

std::unique_ptr< WaveFunctionComponent > makeClone ( ParticleSet tqp) const
overridevirtual

make clone

Parameters
tqptarget Quantum ParticleSet
deepcopyif true, make a decopy

If not true, return a proxy class

Reimplemented from WaveFunctionComponent.

Definition at line 207 of file ExampleHeComponent.cpp.

208 {
209  return std::make_unique<ExampleHeComponent>(*this);
210 }

◆ put()

bool put ( xmlNodePtr  cur)

Definition at line 21 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, OhmmsAttributeSet::add(), ExampleHeComponent::B, VariableSet::clear(), ExampleHeComponent::ID_B, VariableSet::insert(), ExampleHeComponent::my_vars_, ExampleHeComponent::opt_B, optimize::OTHER_P, OhmmsAttributeSet::put(), putContent(), and ExampleHeComponent::Z.

22 {
23  cur = cur->xmlChildrenNode;
24  while (cur != NULL)
25  {
26  std::string cname((const char*)(cur->name));
27 
28  if (cname == "var")
29  {
30  std::string id_in;
31  std::string p_name;
32  OhmmsAttributeSet rAttrib;
33  rAttrib.add(id_in, "id");
34  rAttrib.add(p_name, "name");
35  rAttrib.put(cur);
36 
37 
38  if (p_name == "B")
39  {
40  ID_B = id_in;
41  putContent(B, cur);
42  opt_B = true;
43  }
44  }
45  cur = cur->next;
46  }
47 
48  my_vars_.clear();
49 
50  if (opt_B)
52 
53 
54  // Electron-nucleus cusp
55  Z = 2.0;
56 
57  // Electron-electron cusp
58  A = -0.5;
59  //A = 0.0;
60 
61 
62  return true;
63 }
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
void clear()
clear the variable set
Definition: VariableSet.cpp:28
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
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

◆ ratio()

ExampleHeComponent::PsiValue ratio ( ParticleSet P,
int  iat 
)
overridevirtual

evaluate the ratio of the new to old WaveFunctionComponent value

Parameters
Pthe active ParticleSet
iatthe index of a particle
Returns
$ \psi( \{ {\bf R}^{'} \} )/ \psi( \{ {\bf R}\})$

Specialized for particle-by-particle move

Implements WaveFunctionComponent.

Definition at line 114 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, ExampleHeComponent::B, qmcplusplus::exp(), DistanceTableAA::getDistances(), DistanceTableAB::getDistances(), ParticleSet::getDistTableAA(), ParticleSet::getDistTableAB(), ExampleHeComponent::my_table_ee_idx_, ExampleHeComponent::my_table_ei_idx_, and ExampleHeComponent::Z.

Referenced by qmcplusplus::TEST_CASE().

115 {
116  const auto& ee_table = P.getDistTableAA(my_table_ee_idx_);
117  const auto& ee_dists = ee_table.getDistances();
118  const auto& ee_temp_r = ee_table.getTempDists();
119 
120  // only the lower triangle of e-e Distances and Displacements can be used.
121  double r12_old = ee_dists[1][0];
122  double r12_new = ee_temp_r[iat == 0 ? 1 : 0];
123 
124  const auto& ei_table = P.getDistTableAB(my_table_ei_idx_);
125  const auto& ei_dists = ei_table.getDistances();
126  const auto& ei_temp_r = ei_table.getTempDists();
127 
128  double r_old = ei_dists[iat][0];
129  double r_new = ei_temp_r[0];
130 
131  double u_old = A * r12_old / (B * r12_old + 1);
132  double u_new = A * r12_new / (B * r12_new + 1);
133 
134  double log_v_old = -Z * (r_old)-u_old;
135  double log_v_new = -Z * (r_new)-u_new;
136 
137  return std::exp(static_cast<PsiValue>(log_v_new - log_v_old));
138 }
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)

◆ ratioGrad()

ExampleHeComponent::PsiValue ratioGrad ( ParticleSet P,
int  iat,
GradType grad_iat 
)
overridevirtual

evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient

Parameters
Pthe active ParticleSet
iatthe index of a particle
grad_iatGradient for the active particle

Reimplemented from WaveFunctionComponent.

Definition at line 162 of file ExampleHeComponent.cpp.

References ExampleHeComponent::A, ExampleHeComponent::B, qmcplusplus::exp(), DistanceTableAA::getDistances(), DistanceTableAB::getDistances(), ParticleSet::getDistTableAA(), ParticleSet::getDistTableAB(), ExampleHeComponent::my_table_ee_idx_, ExampleHeComponent::my_table_ei_idx_, and ExampleHeComponent::Z.

Referenced by qmcplusplus::TEST_CASE().

163 {
164  const auto& ee_table = P.getDistTableAA(my_table_ee_idx_);
165  const auto& ee_dists = ee_table.getDistances();
166  const auto& ee_displs = ee_table.getDisplacements();
167  const auto& ee_temp_r = ee_table.getTempDists();
168  const auto& ee_temp_dr = ee_table.getTempDispls();
169 
170  const int jat = (iat == 0 ? 1 : 0);
171  // only the lower triangle of e-e Distances and Displacements can be used.
172  double r12_old = ee_dists[1][0];
173  double r12_new = ee_temp_r[jat];
174 
175  auto rhat12 = ee_temp_dr[jat] / r12_new;
176 
177  const auto& ei_table = P.getDistTableAB(my_table_ei_idx_);
178  const auto& ei_dists = ei_table.getDistances();
179  const auto& ei_displs = ei_table.getDisplacements();
180  const auto& ei_temp_r = ei_table.getTempDists();
181  const auto& ei_temp_dr = ei_table.getTempDispls();
182 
183  double r_old = ei_dists[iat][0];
184  double r_new = ei_temp_r[0];
185 
186  auto rhat = ei_temp_dr[0] / r_new;
187 
188  double du = A / ((B * r12_new + 1) * (B * r12_new + 1));
189  double df = -Z;
190  grad_iat = -df * rhat + du * rhat12;
191 
192  double u_old = A * r12_old / (B * r12_old + 1);
193  double u_new = A * r12_new / (B * r12_new + 1);
194 
195  double log_v_old = -Z * (r_old)-u_old;
196  double log_v_new = -Z * (r_new)-u_new;
197 
198  return std::exp(static_cast<PsiValue>(log_v_new - log_v_old));
199 }
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)

◆ registerData()

void registerData ( ParticleSet P,
WFBufferType buf 
)
inlineoverridevirtual

For particle-by-particle move.

Requests space in the buffer based on the data type sizes of the objects in this class.

Parameters
Pparticle set
bufAnonymous storage

Implements WaveFunctionComponent.

Definition at line 65 of file ExampleHeComponent.h.

65 {}

◆ resetParametersExclusive()

void resetParametersExclusive ( const OptVariablesType active)
overridevirtual

reset the parameters during optimizations.

Exclusive, see checkInVariablesExclusive

Implements OptimizableObject.

Definition at line 212 of file ExampleHeComponent.cpp.

References ExampleHeComponent::B, ExampleHeComponent::my_vars_, ExampleHeComponent::opt_B, VariableSet::size(), and VariableSet::where().

Referenced by qmcplusplus::TEST_CASE().

213 {
214  if (my_vars_.size())
215  {
216  int ia = my_vars_.where(0);
217  if (ia > -1)
218  {
219  int i = 0;
220  if (opt_B)
221  {
222  B = std::real(my_vars_[i++] = active[ia++]);
223  }
224  }
225  }
226 }
QMCTraits::RealType real
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
size_type size() const
return the size
Definition: VariableSet.h:88

◆ restore()

void restore ( int  iat)
inlineoverridevirtual

If a move for iat-th particle is rejected, restore to the content.

Parameters
iatindex of the particle whose new position was proposed

Ye: hopefully we can gradually move away from restore

Implements WaveFunctionComponent.

Definition at line 51 of file ExampleHeComponent.h.

51 {}

◆ updateBuffer()

ExampleHeComponent::LogValue updateBuffer ( ParticleSet P,
WFBufferType buf,
bool  fromscratch = false 
)
overridevirtual

For particle-by-particle move.

Put the objects of this class in the walker buffer or forward the memory cursor.

Parameters
Pparticle set
bufAnonymous storage
fromscratchrequest recomputing the precision critical pieces of wavefunction from scratch
Returns
log value of the wavefunction.

Implements WaveFunctionComponent.

Definition at line 202 of file ExampleHeComponent.cpp.

References ExampleHeComponent::evaluateLog(), ParticleSet::G, and ParticleSet::L.

203 {
204  return evaluateLog(P, P.G, P.L);
205 }
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch

Member Data Documentation

◆ A

◆ B

◆ ID_B

std::string ID_B

Definition at line 77 of file ExampleHeComponent.h.

Referenced by ExampleHeComponent::put().

◆ ions_

const ParticleSet& ions_
private

Definition at line 83 of file ExampleHeComponent.h.

◆ my_table_ee_idx_

◆ my_table_ei_idx_

◆ my_vars_

◆ opt_B

bool opt_B

◆ Z


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