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

Public Member Functions

 MomentumEstimator (ParticleSet &elns, TrialWaveFunction &psi)
 
bool dependsOnWaveFunction () const override
 return true if this operator depends on a wavefunction More...
 
std::string getClassName () const override
 return class name More...
 
void resetTargetParticleSet (ParticleSet &P) override
 Reset the data with the target ParticleSet. More...
 
Return_t evaluate (ParticleSet &P) override
 Evaluate the local energy contribution of this component. More...
 
void addObservables (PropertySetType &plist)
 
void addObservables (PropertySetType &plist, BufferType &olist) override
 named values to the property list Default implementaton uses addValue(plist_) More...
 
void registerCollectables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
 
void setObservables (PropertySetType &plist) override
 Set the values evaluated by this object to plist Default implementation is to assign Value which is updated by evaluate function using my_index_. More...
 
void setParticlePropertyList (PropertySetType &plist, int offset) override
 
bool putSpecial (xmlNodePtr cur, ParticleSet &elns, bool rootNode)
 
bool put (xmlNodePtr cur) override
 Read the input parameter. More...
 
bool get (std::ostream &os) const override
 write about the class More...
 
std::unique_ptr< OperatorBasemakeClone (ParticleSet &qp, TrialWaveFunction &psi) final
 
void setRandomGenerator (RandomBase< FullPrecRealType > *rng) override
 Set the Random Generator object TODO: add docs. More...
 
void resize (const std::vector< PosType > &kin, const int Min)
 
- Public Member Functions inherited from OperatorBase
 OperatorBase ()
 Construct a new Operator Base object Default and unique empty constructor. More...
 
virtual ~OperatorBase ()=default
 
std::bitset< 8 > & getUpdateMode () noexcept
 get update_mode_ reference More...
 
Return_t getValue () const noexcept
 get a copy of value_ More...
 
std::string getName () const noexcept
 getter a copy of my_name_, rvalue small string optimization More...
 
void setName (const std::string name) noexcept
 Set my_name member, uses small string optimization (pass by value) More...
 
TraceRequestgetRequest () noexcept
 Get request_ member. More...
 
virtual void registerObservables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
 add to observable descriptor for hdf5 The default implementation is to register a scalar for this->value_ More...
 
virtual void setHistories (Walker_t &ThisWalker)
 
virtual Return_t evaluateDeterministic (ParticleSet &P)
 Evaluate the local energy contribution of this component, deterministically based on current state. More...
 
virtual void mw_evaluate (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 Evaluate the contribution of this component of multiple walkers. More...
 
virtual void mw_evaluatePerParticle (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual void mw_evaluateWithParameterDerivatives (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< ParticleSet > &p_list, const opt_variables_type &optvars, const RecordArray< ValueType > &dlogpsi, RecordArray< ValueType > &dhpsioverpsi) const
 TODO: add docs. More...
 
virtual Return_t rejectedMove (ParticleSet &P)
 TODO: add docs. More...
 
virtual Return_t evaluateWithToperator (ParticleSet &P)
 Evaluate the local energy contribution of this component with Toperators updated if requested. More...
 
virtual void mw_evaluateWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 Evaluate the contribution of this component of multiple walkers. More...
 
virtual void mw_evaluatePerParticleWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual Return_t evaluateValueAndDerivatives (ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi)
 Evaluate value and derivatives wrt the optimizables. More...
 
virtual Return_t evaluateWithIonDerivs (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual Return_t evaluateWithIonDerivsDeterministic (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual void evaluateOneBodyOpMatrix (ParticleSet &P, const TWFFastDerivWrapper &psi, std::vector< ValueMatrix > &B)
 Evaluate "B" matrix for observable. More...
 
virtual void evaluateOneBodyOpMatrixForceDeriv (ParticleSet &P, ParticleSet &source, const TWFFastDerivWrapper &psi, const int iat, std::vector< std::vector< ValueMatrix >> &Bforce)
 Evaluate "dB/dR" matrices for observable. More...
 
virtual void updateSource (ParticleSet &s)
 Update data associated with a particleset. More...
 
virtual Return_t getEnsembleAverage ()
 Return an average value by collective operation. 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< OperatorBase > &o_list) const
 Acquire a shared resource from a collection. More...
 
virtual void releaseResource (ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const
 Return a shared resource to a collection. More...
 
virtual void add2Hamiltonian (ParticleSet &qp, TrialWaveFunction &psi, QMCHamiltonian &targetH)
 TODO: add docs. More...
 
virtual void getRequiredTraces (TraceManager &tm)
 TODO: add docs. More...
 
virtual void informOfPerParticleListener ()
 
bool isClassical () const noexcept
 
bool isQuantum () const noexcept
 
bool isClassicalClassical () const noexcept
 
bool isQuantumClassical () const noexcept
 
bool isQuantumQuantum () const noexcept
 
bool getMode (const int i) const noexcept
 Return the mode i. More...
 
bool isNonLocal () const noexcept
 TODO: add docs. More...
 
bool hasListener () const noexcept
 
void contributeTraceQuantities ()
 Make trace quantities available. More...
 
void checkoutTraceQuantities (TraceManager &tm)
 Checkout trace arrays Derived classes must guard individual checkouts using request info. More...
 
void collectScalarTraces ()
 Collect scalar trace data. More...
 
void deleteTraceQuantities ()
 delete trace arrays More...
 

Public Attributes

int M
 number of samples More...
 
TrialWaveFunctionrefPsi
 reference to the trial wavefunction for ratio evaluations More...
 
const ParticleSet::ParticleLayoutlattice_
 lattice vector More...
 
RealType norm_nofK
 normalization factor for n(k) More...
 
std::unique_ptr< RandomBase< FullPrecRealType > > myRNG
 random generator More...
 
std::vector< PosTypevPos
 sample positions More...
 
std::vector< ValueTypepsi_ratios
 wavefunction ratios More...
 
Matrix< ValueTypepsi_ratios_all
 wavefunction ratios all samples More...
 
Vector< RealTypekdotp
 nofK internal More...
 
VectorSoaContainer< RealType, 2 > phases
 phases More...
 
std::vector< VectorSoaContainer< RealType, 2 > > phases_vPos
 phases of vPos More...
 
std::vector< PosTypekPoints
 list of k-points in Cartesian Coordinates More...
 
std::vector< int > kWeights
 weight of k-points (make use of symmetry) More...
 
aligned_vector< RealTypenofK
 nofK More...
 
bool hdf5_out
 print to hdf5 or scalar.dat More...
 
PosType twist
 

Additional Inherited Members

- Public Types inherited from OperatorBase
enum  EnergyDomains { KINETIC = 0, POTENTIAL, NO_ENERGY_DOMAIN }
 enum to denote energy domain of operators More...
 
enum  QuantumDomains {
  NO_QUANTUM_DOMAIN = 0, CLASSICAL, QUANTUM, CLASSICAL_CLASSICAL,
  QUANTUM_CLASSICAL, QUANTUM_QUANTUM
}
 
enum  {
  PRIMARY = 0, OPTIMIZABLE = 1, RATIOUPDATE = 2, PHYSICAL = 3,
  COLLECTABLE = 4, NONLOCAL = 5
}
 enum for update_mode More...
 
using Return_t = FullPrecRealType
 type of return value of evaluate More...
 
using ValueMatrix = SPOSet::ValueMatrix
 For fast derivative evaluation. More...
 
using GradMatrix = SPOSet::GradMatrix
 
using BufferType = ParticleSet::Buffer_t
 typedef for the serialized buffer More...
 
using Walker_t = ParticleSet::Walker_t
 typedef for the walker More...
 
using ParticleScalar = ParticleSet::Scalar_t
 typedef for the ParticleScalar More...
 
using SPOMap = SPOSet::SPOMap
 typedef for SPOMap More...
 
- 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 > >
 
- Protected Member Functions inherited from OperatorBase
virtual void contributeScalarQuantities ()
 
virtual void checkoutScalarQuantities (TraceManager &tm)
 
virtual void collectScalarQuantities ()
 
virtual void deleteScalarQuantities ()
 
virtual void contributeParticleQuantities ()
 
virtual void checkoutParticleQuantities (TraceManager &tm)
 
virtual void deleteParticleQuantities ()
 
virtual void setComputeForces (bool compute)
 
void setEnergyDomain (EnergyDomains edomain)
 Set the Energy Domain. More...
 
void setQuantumDomain (QuantumDomains qdomain)
 set quantum domain More...
 
void oneBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for one-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for two-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P1, const ParticleSet &P2)
 set quantum domain for two-body operator More...
 
void addValue (PropertySetType &plist)
 named values to the property list More...
 
- Protected Attributes inherited from OperatorBase
std::bitset< 8 > update_mode_
 set the current update mode More...
 
Return_t value_
 current value More...
 
std::string name_
 name of this object More...
 
TraceRequest request_
 whether traces are being collected More...
 
int my_index_
 starting index of this object More...
 
Return_t new_value_
 a new value for a proposed move More...
 
Walker_tt_walker_
 reference to the current walker More...
 
bool streaming_particles_
 
bool have_required_traces_
 

Detailed Description

Definition at line 20 of file MomentumEstimator.h.

Constructor & Destructor Documentation

◆ MomentumEstimator()

Definition at line 31 of file MomentumEstimator.cpp.

References OperatorBase::COLLECTABLE, ParticleSet::getTotalNum(), ParticleSet::getTwist(), MomentumEstimator::psi_ratios, MomentumEstimator::twist, and OperatorBase::update_mode_.

32  : M(40), refPsi(psi), lattice_(elns.getLattice()), norm_nofK(1), hdf5_out(false)
33 {
34  update_mode_.set(COLLECTABLE, 1);
35  psi_ratios.resize(elns.getTotalNum());
36  twist = elns.getTwist();
37 }
TrialWaveFunction & refPsi
reference to the trial wavefunction for ratio evaluations
bool hdf5_out
print to hdf5 or scalar.dat
RealType norm_nofK
normalization factor for n(k)
const ParticleSet::ParticleLayout & lattice_
lattice vector
std::vector< ValueType > psi_ratios
wavefunction ratios
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521

Member Function Documentation

◆ addObservables() [1/2]

void addObservables ( PropertySetType plist)
inline

Definition at line 30 of file MomentumEstimator.h.

30 {}

◆ addObservables() [2/2]

void addObservables ( PropertySetType plist,
BufferType collectables 
)
overridevirtual

named values to the property list Default implementaton uses addValue(plist_)

Parameters
plistRecordNameProperty
collectablesObservables that are accumulated by evaluate

Reimplemented from OperatorBase.

Definition at line 117 of file MomentumEstimator.cpp.

References PooledData< T >::add(), RecordNamedProperty< T >::add(), MomentumEstimator::hdf5_out, OperatorBase::my_index_, MomentumEstimator::nofK, PooledData< T >::size(), and RecordNamedProperty< T >::size().

118 {
119  if (hdf5_out)
120  {
121  my_index_ = collectables.size();
122  collectables.add(nofK.begin(), nofK.end());
123  }
124  else
125  {
126  my_index_ = plist.size();
127  for (int i = 0; i < nofK.size(); i++)
128  {
129  std::stringstream sstr;
130  sstr << "nofk_" << i;
131  int id = plist.add(sstr.str());
132  }
133  }
134 }
bool hdf5_out
print to hdf5 or scalar.dat
int my_index_
starting index of this object
Definition: OperatorBase.h:535
aligned_vector< RealType > nofK
nofK

◆ dependsOnWaveFunction()

bool dependsOnWaveFunction ( ) const
inlineoverridevirtual

return true if this operator depends on a wavefunction

Reimplemented from OperatorBase.

Definition at line 24 of file MomentumEstimator.h.

24 { return true; }

◆ evaluate()

MomentumEstimator::Return_t evaluate ( ParticleSet P)
overridevirtual

Evaluate the local energy contribution of this component.

Parameters
Pinput configuration containing N particles
Returns
the value of the Hamiltonian component

Implements OperatorBase.

Definition at line 41 of file MomentumEstimator.cpp.

References ParticleSet::Collectables, Vector< T, Alloc >::data(), VectorSoaContainer< T, D, Alloc >::data(), qmcplusplus::dot(), eval_e2iphi(), TrialWaveFunction::evaluateRatiosAlltoOne(), OMPstd::fill_n(), ParticleSet::getTotalNum(), MomentumEstimator::hdf5_out, MomentumEstimator::kdotp, MomentumEstimator::kPoints, MomentumEstimator::lattice_, MomentumEstimator::M, ParticleSet::makeVirtualMoves(), OperatorBase::my_index_, MomentumEstimator::myRNG, MomentumEstimator::nofK, MomentumEstimator::norm_nofK, OHMMS_DIM, MomentumEstimator::phases, MomentumEstimator::phases_vPos, MomentumEstimator::psi_ratios, MomentumEstimator::psi_ratios_all, ParticleSet::R, MomentumEstimator::refPsi, qmcplusplus::Units::time::s, OperatorBase::t_walker_, CrystalLattice< T, D >::toCart(), MomentumEstimator::vPos, and Walker< t_traits, p_traits >::Weight.

42 {
43  const int np = P.getTotalNum();
44  const int nk = kPoints.size();
45  for (int s = 0; s < M; ++s)
46  {
47  PosType newpos;
48  for (int i = 0; i < OHMMS_DIM; ++i)
49  newpos[i] = (*myRNG)();
50  //make it cartesian
51  vPos[s] = lattice_.toCart(newpos);
52  P.makeVirtualMoves(vPos[s]);
54  for (int i = 0; i < np; ++i)
55  psi_ratios_all[s][i] = psi_ratios[i];
56 
57  for (int ik = 0; ik < nk; ++ik)
58  kdotp[ik] = -dot(kPoints[ik], vPos[s]);
59  eval_e2iphi(nk, kdotp.data(), phases_vPos[s].data(0), phases_vPos[s].data(1));
60  }
61 
62  std::fill_n(nofK.begin(), nk, RealType(0));
63  for (int i = 0; i < np; ++i)
64  {
65  for (int ik = 0; ik < nk; ++ik)
66  kdotp[ik] = dot(kPoints[ik], P.R[i]);
67  eval_e2iphi(nk, kdotp.data(), phases.data(0), phases.data(1));
68  for (int s = 0; s < M; ++s)
69  {
70  const ComplexType one_ratio(psi_ratios_all[s][i]);
71  const RealType ratio_c = one_ratio.real();
72  const RealType ratio_s = one_ratio.imag();
73  const RealType* restrict phases_c = phases.data(0);
74  const RealType* restrict phases_s = phases.data(1);
75  const RealType* restrict phases_vPos_c = phases_vPos[s].data(0);
76  const RealType* restrict phases_vPos_s = phases_vPos[s].data(1);
77  RealType* restrict nofK_here = nofK.data();
78 #pragma omp simd aligned(nofK_here, phases_c, phases_s, phases_vPos_c, phases_vPos_s : QMC_SIMD_ALIGNMENT)
79  for (int ik = 0; ik < nk; ++ik)
80  nofK_here[ik] += (phases_c[ik] * phases_vPos_c[ik] - phases_s[ik] * phases_vPos_s[ik]) * ratio_c -
81  (phases_s[ik] * phases_vPos_c[ik] + phases_c[ik] * phases_vPos_s[ik]) * ratio_s;
82  }
83  }
84  if (hdf5_out)
85  {
87  int j = my_index_;
88  for (int ik = 0; ik < nofK.size(); ++ik, ++j)
89  P.Collectables[j] += w * nofK[ik];
90  }
91  else
92  {
93  for (int ik = 0; ik < nofK.size(); ++ik)
94  nofK[ik] *= norm_nofK;
95  }
96 
97  return 0.0;
98 }
std::vector< PosType > vPos
sample positions
TrialWaveFunction & refPsi
reference to the trial wavefunction for ratio evaluations
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios)
Matrix< ValueType > psi_ratios_all
wavefunction ratios all samples
bool hdf5_out
print to hdf5 or scalar.dat
QTBase::RealType RealType
Definition: Configuration.h:58
RealType norm_nofK
normalization factor for n(k)
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21
int my_index_
starting index of this object
Definition: OperatorBase.h:535
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
#define OHMMS_DIM
Definition: config.h:64
QMCTraits::PosType PosType
std::unique_ptr< RandomBase< FullPrecRealType > > myRNG
random generator
VectorSoaContainer< RealType, 2 > phases
phases
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
QMCTraits::RealType RealType
aligned_vector< RealType > nofK
nofK
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
SingleParticlePos toCart(const TinyVector< T1, D > &c) const
Convert a unit vector to a cartesian vector.
const ParticleSet::ParticleLayout & lattice_
lattice vector
std::vector< VectorSoaContainer< RealType, 2 > > phases_vPos
phases of vPos
std::vector< ValueType > psi_ratios
wavefunction ratios
Vector< RealType > kdotp
nofK internal
void eval_e2iphi(int n, const T *restrict phi, T *restrict phase_r, T *restrict phase_i)
Definition: e2iphi.h:61
std::vector< PosType > kPoints
list of k-points in Cartesian Coordinates

◆ get()

bool get ( std::ostream &  os) const
overridevirtual

write about the class

Implements OperatorBase.

Definition at line 424 of file MomentumEstimator.cpp.

424 { return true; }

◆ getClassName()

std::string getClassName ( ) const
inlineoverridevirtual

return class name

Implements OperatorBase.

Definition at line 25 of file MomentumEstimator.h.

25 { return "MomentumEstimator"; }

◆ makeClone()

std::unique_ptr< OperatorBase > makeClone ( ParticleSet qp,
TrialWaveFunction psi 
)
finalvirtual

Implements OperatorBase.

Definition at line 426 of file MomentumEstimator.cpp.

References MomentumEstimator::hdf5_out, MomentumEstimator::kPoints, MomentumEstimator::M, OperatorBase::my_index_, and MomentumEstimator::norm_nofK.

427 {
428  std::unique_ptr<MomentumEstimator> myclone = std::make_unique<MomentumEstimator>(qp, psi);
429  myclone->resize(kPoints, M);
430  myclone->my_index_ = my_index_;
431  myclone->norm_nofK = norm_nofK;
432  myclone->hdf5_out = hdf5_out;
433  return myclone;
434 }
bool hdf5_out
print to hdf5 or scalar.dat
RealType norm_nofK
normalization factor for n(k)
int my_index_
starting index of this object
Definition: OperatorBase.h:535
std::vector< PosType > kPoints
list of k-points in Cartesian Coordinates

◆ put()

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

Read the input parameter.

Parameters
curxml node for a OperatorBase object

Implements OperatorBase.

Definition at line 36 of file MomentumEstimator.h.

36 { return false; };

◆ putSpecial()

bool putSpecial ( xmlNodePtr  cur,
ParticleSet elns,
bool  rootNode 
)

dims of a grid for generating k points (obtained below)

Definition at line 153 of file MomentumEstimator.cpp.

References OhmmsAttributeSet::add(), qmcplusplus::app_log(), qmcplusplus::dot(), ParticleSet::getLattice(), ParticleSet::getTotalNum(), MomentumEstimator::hdf5_out, CrystalLattice< T, D >::k_cart(), MomentumEstimator::kdotp, MomentumEstimator::kPoints, MomentumEstimator::lattice_, MomentumEstimator::M, MomentumEstimator::nofK, MomentumEstimator::norm_nofK, OHMMS_DIM, MomentumEstimator::phases, MomentumEstimator::phases_vPos, pi, qmcplusplus::pow(), MomentumEstimator::psi_ratios, MomentumEstimator::psi_ratios_all, OhmmsAttributeSet::put(), MomentumEstimator::resize(), Matrix< T, Alloc >::resize(), VectorSoaContainer< T, D, Alloc >::resize(), Vector< T, Alloc >::resize(), qmcplusplus::sqrt(), MomentumEstimator::twist, and MomentumEstimator::vPos.

154 {
155  OhmmsAttributeSet pAttrib;
156  std::string hdf5_flag = "yes";
157  ///dims of a grid for generating k points (obtained below)
158  int kgrid = 0;
159  //maximum k-value in the k-grid in cartesian coordinates
160  RealType kmax = 0.0;
161  //maximum k-values in the k-grid along the reciprocal cell axis
162  RealType kmax0 = 0.0;
163  RealType kmax1 = 0.0;
164  RealType kmax2 = 0.0;
165  pAttrib.add(hdf5_flag, "hdf5");
166  //pAttrib.add(kgrid,"grid");
167  pAttrib.add(kmax, "kmax");
168  pAttrib.add(kmax0, "kmax0");
169  pAttrib.add(kmax1, "kmax1");
170  pAttrib.add(kmax2, "kmax2");
171  pAttrib.add(M, "samples"); // default value is 40 (in the constructor)
172  pAttrib.put(cur);
173  hdf5_out = (hdf5_flag == "yes");
174  // minimal length as 2 x WS radius.
175  RealType min_Length = elns.getLattice().WignerSeitzRadius_G * 4.0 * M_PI;
176  PosType vec_length;
177  //length of reciprocal lattice vector
178  for (int i = 0; i < OHMMS_DIM; i++)
179  vec_length[i] = 2.0 * M_PI * std::sqrt(dot(elns.getLattice().Gv[i], elns.getLattice().Gv[i]));
180 #if OHMMS_DIM == 3
181  PosType kmaxs(0);
182  kmaxs[0] = kmax0;
183  kmaxs[1] = kmax1;
184  kmaxs[2] = kmax2;
185  RealType sum_kmaxs = kmaxs[0] + kmaxs[1] + kmaxs[2];
186  RealType sphere_kmax;
187  bool sphere = kmax > 0.0 ? true : false;
188  bool directional = sum_kmaxs > 0.0 ? true : false;
189  if (!sphere && !directional)
190  {
191  // default: kmax = 2 x k_F of polarized non-interacting electron system
192  kmax = 2.0 * std::pow(6.0 * M_PI * M_PI * elns.getTotalNum() / elns.getLattice().Volume, 1.0 / 3);
193  sphere = true;
194  }
195  sphere_kmax = kmax;
196  for (int i = 0; i < OHMMS_DIM; i++)
197  {
198  if (kmaxs[i] > kmax)
199  kmax = kmaxs[i];
200  }
201  kgrid = int(kmax / min_Length) + 1;
202  RealType kgrid_squared[OHMMS_DIM];
203  for (int i = 0; i < OHMMS_DIM; i++)
204  kgrid_squared[i] = kmaxs[i] * kmaxs[i] / vec_length[i] / vec_length[i];
205  RealType kmax_squared = sphere_kmax * sphere_kmax;
206  std::vector<int> kcount0;
207  std::vector<int> kcount1;
208  std::vector<int> kcount2;
209  kcount0.resize(2 * kgrid + 1, 0);
210  kcount1.resize(2 * kgrid + 1, 0);
211  kcount2.resize(2 * kgrid + 1, 0);
212  for (int i = -kgrid; i < (kgrid + 1); i++)
213  {
214  for (int j = -kgrid; j < (kgrid + 1); j++)
215  {
216  for (int k = -kgrid; k < (kgrid + 1); k++)
217  {
218  PosType ikpt, kpt;
219  ikpt[0] = i + twist[0];
220  ikpt[1] = j + twist[1];
221  ikpt[2] = k + twist[2];
222  //convert to Cartesian: note that 2Pi is multiplied
223  kpt = lattice_.k_cart(ikpt);
224  bool not_recorded = true;
225  // This collects the k-points within the parallelepiped (if enabled)
226  if (directional && ikpt[0] * ikpt[0] <= kgrid_squared[0] && ikpt[1] * ikpt[1] <= kgrid_squared[1] &&
227  ikpt[2] * ikpt[2] <= kgrid_squared[2])
228  {
229  kPoints.push_back(kpt);
230  kcount0[kgrid + i] = 1;
231  kcount1[kgrid + j] = 1;
232  kcount2[kgrid + k] = 1;
233  not_recorded = false;
234  }
235  // This collects the k-points within a sphere (if enabled and the k-point has not been recorded yet)
236  if (sphere && not_recorded &&
237  kpt[0] * kpt[0] + kpt[1] * kpt[1] + kpt[2] * kpt[2] <=
238  kmax_squared) //if (std::sqrt(kx*kx+ky*ky+kz*kz)<=sphere_kmax)
239  {
240  kPoints.push_back(kpt);
241  }
242  }
243  }
244  }
245  if (sphere && !directional)
246  {
247  app_log() << " Using all k-space points with (kx^2+ky^2+kz^2)^0.5 < " << sphere_kmax
248  << " for Momentum Distribution." << std::endl;
249  app_log() << " Total number of k-points for Momentum Distribution is " << kPoints.size() << std::endl;
250  }
251  else if (directional && !sphere)
252  {
253  int sums[3];
254  sums[0] = 0;
255  sums[1] = 0;
256  sums[2] = 0;
257  for (int i = 0; i < 2 * kgrid + 1; i++)
258  {
259  sums[0] += kcount0[i];
260  sums[1] += kcount1[i];
261  sums[2] += kcount2[i];
262  }
263  app_log() << " Using all k-space points within cut-offs " << kmax0 << ", " << kmax1 << ", " << kmax2
264  << " for Momentum Distribution." << std::endl;
265  app_log() << " Total number of k-points for Momentum Distribution: " << kPoints.size() << std::endl;
266  app_log() << " Number of grid points in kmax0 direction: " << sums[0] << std::endl;
267  app_log() << " Number of grid points in kmax1 direction: " << sums[1] << std::endl;
268  app_log() << " Number of grid points in kmax2 direction: " << sums[2] << std::endl;
269  }
270  else
271  {
272  int sums[3];
273  sums[0] = 0;
274  sums[1] = 0;
275  sums[2] = 0;
276  for (int i = 0; i < 2 * kgrid + 1; i++)
277  {
278  sums[0] += kcount0[i];
279  sums[1] += kcount1[i];
280  sums[2] += kcount2[i];
281  }
282  app_log() << " Using all k-space points with (kx^2+ky^2+kz^2)^0.5 < " << sphere_kmax << ", and" << std::endl;
283  app_log() << " within the cut-offs " << kmax0 << ", " << kmax1 << ", " << kmax2 << " for Momentum Distribution."
284  << std::endl;
285  app_log() << " Total number of k-points for Momentum Distribution is " << kPoints.size() << std::endl;
286  app_log() << " The number of k-points within the cut-off region: " << sums[0] * sums[1] * sums[2] << std::endl;
287  app_log() << " Number of grid points in kmax0 direction: " << sums[0] << std::endl;
288  app_log() << " Number of grid points in kmax1 direction: " << sums[1] << std::endl;
289  app_log() << " Number of grid points in kmax2 direction: " << sums[2] << std::endl;
290  }
291  app_log() << " Number of samples: " << M << std::endl;
292  app_log() << " My twist is: " << twist[0] << " " << twist[1] << " " << twist[2] << std::endl;
293 #endif
294 #if OHMMS_DIM == 2
295  PosType kmaxs(0);
296  kmaxs[0] = kmax0;
297  kmaxs[1] = kmax1;
298  RealType sum_kmaxs = kmaxs[0] + kmaxs[1];
299  RealType disk_kmax;
300  bool disk = kmax > 0.0 ? true : false;
301  bool directional = sum_kmaxs > 0.0 ? true : false;
302  if (!disk && !directional)
303  {
304  // default: kmax = 2 x k_F of polarized non-interacting electron system
305  kmax = 2.0 * std::pow(4.0 * pi * elns.getTotalNum() / elns.getLattice().Volume, 0.5);
306  disk = true;
307  }
308  disk_kmax = kmax;
309  for (int i = 0; i < OHMMS_DIM; i++)
310  {
311  if (kmaxs[i] > kmax)
312  kmax = kmaxs[i];
313  }
314  kgrid = int(kmax / min_Length) + 1;
315  RealType kgrid_squared[OHMMS_DIM];
316  for (int i = 0; i < OHMMS_DIM; i++)
317  kgrid_squared[i] = kmaxs[i] * kmaxs[i] / vec_length[i] / vec_length[i];
318  RealType kmax_squared = disk_kmax * disk_kmax;
319  std::vector<int> kcount0;
320  std::vector<int> kcount1;
321  kcount0.resize(2 * kgrid + 1, 0);
322  kcount1.resize(2 * kgrid + 1, 0);
323  for (int i = -kgrid; i < (kgrid + 1); i++)
324  {
325  for (int j = -kgrid; j < (kgrid + 1); j++)
326  {
327  PosType ikpt, kpt;
328  ikpt[0] = i - twist[0];
329  ikpt[1] = j - twist[1];
330  //convert to Cartesian: note that 2Pi is multiplied
331  kpt = lattice_.k_cart(ikpt);
332  bool not_recorded = true;
333  if (directional && ikpt[0] * ikpt[0] <= kgrid_squared[0] && ikpt[1] * ikpt[1] <= kgrid_squared[1])
334  {
335  kPoints.push_back(kpt);
336  kcount0[kgrid + i] = 1;
337  kcount1[kgrid + j] = 1;
338  not_recorded = false;
339  }
340  if (disk && not_recorded &&
341  kpt[0] * kpt[0] + kpt[1] * kpt[1] <= kmax_squared) //if (std::sqrt(kx*kx+ky*ky)<=disk_kmax)
342  {
343  kPoints.push_back(kpt);
344  }
345  }
346  }
347  if (disk && !directional)
348  {
349  app_log() << " Using all k-space points with (kx^2+ky^2)^0.5 < " << disk_kmax << " for Momentum Distribution."
350  << std::endl;
351  app_log() << " Total number of k-points for Momentum Distribution is " << kPoints.size() << std::endl;
352  }
353  else if (directional && !disk)
354  {
355  int sums[2];
356  sums[0] = 0;
357  sums[1] = 0;
358  for (int i = 0; i < 2 * kgrid + 1; i++)
359  {
360  sums[0] += kcount0[i];
361  sums[1] += kcount1[i];
362  }
363  app_log() << " Using all k-space points within cut-offs " << kmax0 << ", " << kmax1
364  << " for Momentum Distribution." << std::endl;
365  app_log() << " Total number of k-points for Momentum Distribution: " << kPoints.size() << std::endl;
366  app_log() << " Number of grid points in kmax0 direction: " << sums[0] << std::endl;
367  app_log() << " Number of grid points in kmax1 direction: " << sums[1] << std::endl;
368  }
369  else
370  {
371  int sums[2];
372  sums[0] = 0;
373  sums[1] = 0;
374  for (int i = 0; i < 2 * kgrid + 1; i++)
375  {
376  sums[0] += kcount0[i];
377  sums[1] += kcount1[i];
378  }
379  app_log() << " Using all k-space points with (kx^2+ky^2)^0.5 < " << disk_kmax << ", and" << std::endl;
380  app_log() << " within the cut-offs " << kmax0 << ", " << kmax1 << " for Momentum Distribution." << std::endl;
381  app_log() << " Total number of k-points for Momentum Distribution is " << kPoints.size() << std::endl;
382  app_log() << " The number of k-points within the cut-off region: " << sums[0] * sums[1] << std::endl;
383  app_log() << " Number of grid points in kmax0 direction: " << sums[0] << std::endl;
384  app_log() << " Number of grid points in kmax1 direction: " << sums[1] << std::endl;
385  }
386  app_log() << " Number of samples: " << M << std::endl;
387  app_log() << " My twist is: " << twist[0] << " " << twist[1] << " " << twist[2] << std::endl;
388 #endif
389  if (rootNode)
390  {
391  std::stringstream sstr;
392  sstr << "Kpoints";
393  for (int i(0); i < OHMMS_DIM; i++)
394  sstr << "_" << round(100.0 * twist[i]);
395  sstr << ".dat";
396  std::ofstream fout(sstr.str().c_str());
397  fout.setf(std::ios::scientific, std::ios::floatfield);
398  fout << "# mag_k ";
399  for (int i(0); i < OHMMS_DIM; i++)
400  fout << "k_" << i << " ";
401  fout << std::endl;
402  for (int i = 0; i < kPoints.size(); i++)
403  {
404  float khere(std::sqrt(dot(kPoints[i], kPoints[i])));
405  fout << khere;
406  for (int j(0); j < OHMMS_DIM; j++)
407  fout << " " << kPoints[i][j];
408  fout << std::endl;
409  }
410  fout.close();
411  }
412  nofK.resize(kPoints.size());
413  kdotp.resize(kPoints.size());
414  vPos.resize(M);
415  phases.resize(kPoints.size());
416  phases_vPos.resize(M);
417  for (int im = 0; im < M; im++)
418  phases_vPos[im].resize(kPoints.size());
420  norm_nofK = 1.0 / RealType(M);
421  return true;
422 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
std::vector< PosType > vPos
sample positions
void resize(const std::vector< PosType > &kin, const int Min)
Matrix< ValueType > psi_ratios_all
wavefunction ratios all samples
bool hdf5_out
print to hdf5 or scalar.dat
QTBase::RealType RealType
Definition: Configuration.h:58
RealType norm_nofK
normalization factor for n(k)
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
const double pi
Definition: Standard.h:56
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
#define OHMMS_DIM
Definition: config.h:64
QMCTraits::PosType PosType
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)
SingleParticlePos k_cart(const SingleParticlePos &kin) const
conversion of a reciprocal-vector
VectorSoaContainer< RealType, 2 > phases
phases
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
QMCTraits::RealType RealType
aligned_vector< RealType > nofK
nofK
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
const ParticleSet::ParticleLayout & lattice_
lattice vector
std::vector< VectorSoaContainer< RealType, 2 > > phases_vPos
phases of vPos
void resize(size_type n)
resize myData
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
std::vector< ValueType > psi_ratios
wavefunction ratios
Vector< RealType > kdotp
nofK internal
std::vector< PosType > kPoints
list of k-points in Cartesian Coordinates

◆ registerCollectables()

void registerCollectables ( std::vector< ObservableHelper > &  h5desc,
hdf_archive file 
) const
overridevirtual

Reimplemented from OperatorBase.

Definition at line 100 of file MomentumEstimator.cpp.

References MomentumEstimator::hdf5_out, MomentumEstimator::kPoints, MomentumEstimator::kWeights, OperatorBase::my_index_, and MomentumEstimator::nofK.

101 {
102  if (hdf5_out)
103  {
104  //descriptor for the data, 1-D data
105  std::vector<int> ng(1);
106  //add nofk
107  ng[0] = nofK.size();
108  h5desc.emplace_back(hdf_path{"nofk"});
109  auto& h5o = h5desc.back();
110  h5o.set_dimensions(ng, my_index_);
111  h5o.addProperty(const_cast<std::vector<PosType>&>(kPoints), "kpoints", file);
112  h5o.addProperty(const_cast<std::vector<int>&>(kWeights), "kweights", file);
113  }
114 }
bool hdf5_out
print to hdf5 or scalar.dat
int my_index_
starting index of this object
Definition: OperatorBase.h:535
aligned_vector< RealType > nofK
nofK
std::vector< int > kWeights
weight of k-points (make use of symmetry)
std::vector< PosType > kPoints
list of k-points in Cartesian Coordinates

◆ resetTargetParticleSet()

void resetTargetParticleSet ( ParticleSet P)
overridevirtual

Reset the data with the target ParticleSet.

Parameters
Pnew target ParticleSet

Implements OperatorBase.

Definition at line 39 of file MomentumEstimator.cpp.

39 {}

◆ resize()

void resize ( const std::vector< PosType > &  kin,
const int  Min 
)

Definition at line 436 of file MomentumEstimator.cpp.

References MomentumEstimator::kdotp, MomentumEstimator::kPoints, MomentumEstimator::M, MomentumEstimator::nofK, MomentumEstimator::phases, MomentumEstimator::phases_vPos, MomentumEstimator::psi_ratios, MomentumEstimator::psi_ratios_all, Matrix< T, Alloc >::resize(), VectorSoaContainer< T, D, Alloc >::resize(), Vector< T, Alloc >::resize(), and MomentumEstimator::vPos.

Referenced by MomentumEstimator::putSpecial().

437 {
438  //copy kpoints
439  kPoints = kin;
440  nofK.resize(kin.size());
441  kdotp.resize(kPoints.size());
442  phases.resize(kPoints.size());
443  //M
444  M = Min;
445  vPos.resize(M);
447  phases_vPos.resize(M);
448  for (int im = 0; im < M; im++)
449  phases_vPos[im].resize(kPoints.size());
450 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
std::vector< PosType > vPos
sample positions
void resize(const std::vector< PosType > &kin, const int Min)
Matrix< ValueType > psi_ratios_all
wavefunction ratios all samples
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
VectorSoaContainer< RealType, 2 > phases
phases
aligned_vector< RealType > nofK
nofK
std::vector< VectorSoaContainer< RealType, 2 > > phases_vPos
phases of vPos
void resize(size_type n)
resize myData
std::vector< ValueType > psi_ratios
wavefunction ratios
Vector< RealType > kdotp
nofK internal
std::vector< PosType > kPoints
list of k-points in Cartesian Coordinates

◆ setObservables()

void setObservables ( PropertySetType plist)
overridevirtual

Set the values evaluated by this object to plist Default implementation is to assign Value which is updated by evaluate function using my_index_.

Parameters
plistRecordNameProperty

Reimplemented from OperatorBase.

Definition at line 137 of file MomentumEstimator.cpp.

References RecordNamedProperty< T >::begin(), copy(), MomentumEstimator::hdf5_out, OperatorBase::my_index_, and MomentumEstimator::nofK.

138 {
139  if (!hdf5_out)
140  {
141  copy(nofK.begin(), nofK.end(), plist.begin() + my_index_);
142  }
143 }
bool hdf5_out
print to hdf5 or scalar.dat
int my_index_
starting index of this object
Definition: OperatorBase.h:535
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
aligned_vector< RealType > nofK
nofK

◆ setParticlePropertyList()

void setParticlePropertyList ( PropertySetType plist,
int  offset 
)
overridevirtual

Reimplemented from OperatorBase.

Definition at line 145 of file MomentumEstimator.cpp.

References RecordNamedProperty< T >::begin(), copy(), MomentumEstimator::hdf5_out, OperatorBase::my_index_, and MomentumEstimator::nofK.

146 {
147  if (!hdf5_out)
148  {
149  copy(nofK.begin(), nofK.end(), plist.begin() + my_index_ + offset);
150  }
151 }
bool hdf5_out
print to hdf5 or scalar.dat
int my_index_
starting index of this object
Definition: OperatorBase.h:535
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
aligned_vector< RealType > nofK
nofK

◆ setRandomGenerator()

void setRandomGenerator ( RandomBase< FullPrecRealType > *  rng)
overridevirtual

Set the Random Generator object TODO: add docs.

Parameters
rng

Reimplemented from OperatorBase.

Definition at line 452 of file MomentumEstimator.cpp.

References RandomBase< T >::makeClone(), and MomentumEstimator::myRNG.

453 {
454  //simply copy it
455  myRNG = rng->makeClone();
456 }
std::unique_ptr< RandomBase< FullPrecRealType > > myRNG
random generator
virtual std::unique_ptr< RandomBase< T > > makeClone() const =0

Member Data Documentation

◆ hdf5_out

◆ kdotp

◆ kPoints

◆ kWeights

std::vector<int> kWeights

weight of k-points (make use of symmetry)

Definition at line 67 of file MomentumEstimator.h.

Referenced by MomentumEstimator::registerCollectables().

◆ lattice_

const ParticleSet::ParticleLayout& lattice_

lattice vector

Definition at line 47 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate(), and MomentumEstimator::putSpecial().

◆ M

◆ myRNG

std::unique_ptr<RandomBase<FullPrecRealType> > myRNG

random generator

Definition at line 51 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate(), and MomentumEstimator::setRandomGenerator().

◆ nofK

◆ norm_nofK

RealType norm_nofK

normalization factor for n(k)

Definition at line 49 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate(), MomentumEstimator::makeClone(), and MomentumEstimator::putSpecial().

◆ phases

◆ phases_vPos

std::vector<VectorSoaContainer<RealType, 2> > phases_vPos

◆ psi_ratios

◆ psi_ratios_all

Matrix<ValueType> psi_ratios_all

wavefunction ratios all samples

Definition at line 57 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate(), MomentumEstimator::putSpecial(), and MomentumEstimator::resize().

◆ refPsi

reference to the trial wavefunction for ratio evaluations

Definition at line 45 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate().

◆ twist

◆ vPos

std::vector<PosType> vPos

sample positions

Definition at line 53 of file MomentumEstimator.h.

Referenced by MomentumEstimator::evaluate(), MomentumEstimator::putSpecial(), and MomentumEstimator::resize().


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