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

Public Types

using Point = ReferencePoints::Point
 
using PSPool = std::map< std::string, const std::unique_ptr< ParticleSet > >
 
- 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 > >
 
- Public Types inherited from PtclOnLatticeTraits
using ParticleLayout = CrystalLattice< OHMMS_PRECISION, OHMMS_DIM >
 
using QTFull = QMCTraits::QTFull
 
using Index_t = int
 
using Scalar_t = QTFull::RealType
 
using Complex_t = QTFull::ComplexType
 
using SingleParticleIndex = ParticleLayout::SingleParticleIndex
 
using SingleParticlePos = ParticleLayout::SingleParticlePos
 
using Tensor_t = ParticleLayout::Tensor_t
 
using ParticleIndex = ParticleAttrib< Index_t >
 
using ParticleScalar = ParticleAttrib< Scalar_t >
 
using ParticlePos = ParticleAttrib< SingleParticlePos >
 
using ParticleTensor = ParticleAttrib< Tensor_t >
 
using ParticleGradient = ParticleAttrib< QTFull::GradType >
 
using ParticleLaplacian = ParticleAttrib< QTFull::ValueType >
 
using SingleParticleValue = QTFull::ValueType
 

Public Member Functions

 EnergyDensityEstimator (const PSPool &PSP, const std::string &defaultKE)
 
 ~EnergyDensityEstimator () override
 
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 put (xmlNodePtr cur) override
 check xml elements More...
 
bool put (xmlNodePtr cur, ParticleSet &P)
 
bool get (std::ostream &os) const override
 write about the class More...
 
std::unique_ptr< OperatorBasemakeClone (ParticleSet &qp, TrialWaveFunction &psi) final
 
void write_description (std::ostream &os)
 
void write_EDValues (void)
 
void write_nonzero_domains (const ParticleSet &P)
 
void write_Collectables (std::string &label, int &cnt, ParticleSet &P)
 
- Public Member Functions inherited from OperatorBase
 OperatorBase ()
 Construct a new Operator Base object Default and unique empty constructor. More...
 
virtual ~OperatorBase ()=default
 
virtual bool dependsOnWaveFunction () const
 return true if this operator depends on a wavefunction More...
 
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 setRandomGenerator (RandomBase< FullPrecRealType > *rng)
 Set the Random Generator object TODO: add docs. More...
 
virtual void add2Hamiltonian (ParticleSet &qp, TrialWaveFunction &psi, QMCHamiltonian &targetH)
 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...
 

Private Types

enum  { W = 0, T, V, nEDValues }
 

Private Member Functions

ParticleSetget_particleset (std::string &psname)
 
void set_ptcl (void)
 
void unset_ptcl (void)
 
void getRequiredTraces (TraceManager &tm) override
 TODO: add docs. More...
 
void contributeScalarQuantities () override
 
void checkoutScalarQuantities (TraceManager &tm) override
 
void collectScalarQuantities () override
 
void deleteScalarQuantities () override
 

Private Attributes

xmlNodePtr input_xml
 
std::string defKE
 
const PSPoolpsetpool
 
ParticleSetPdynamic
 
ParticleSetPstatic
 
int dtable_index
 
int nparticles
 
bool ion_points
 
int nions
 
int ion_buffer_offset
 
Matrix< RealTypeRion
 
ReferencePoints ref
 
Matrix< RealTypeEDValues
 
Matrix< RealTypeEDIonValues
 
int outside_buffer_offset
 
std::vector< bool > particles_outside
 
std::vector< SpaceGrid * > spacegrids
 
ParticlePos R
 
int nsamples
 
std::vector< RealTypeZptcl
 
ParticlePos Rptcl
 
TraceSample< TraceReal > * w_trace
 
TraceSample< TraceReal > * Td_trace
 
CombinedTraceSample< TraceReal > * Vd_trace
 
CombinedTraceSample< TraceReal > * Vs_trace
 

Additional Inherited Members

- Protected Member Functions inherited from OperatorBase
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 25 of file EnergyDensityEstimator.h.

Member Typedef Documentation

◆ Point

Definition at line 28 of file EnergyDensityEstimator.h.

◆ PSPool

using PSPool = std::map<std::string, const std::unique_ptr<ParticleSet> >

Definition at line 29 of file EnergyDensityEstimator.h.

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ EnergyDensityEstimator()

EnergyDensityEstimator ( const PSPool PSP,
const std::string &  defaultKE 
)

Definition at line 26 of file EnergyDensityEstimator.cpp.

References OperatorBase::COLLECTABLE, EnergyDensityEstimator::defKE, EnergyDensityEstimator::ion_points, EnergyDensityEstimator::nions, EnergyDensityEstimator::nsamples, OperatorBase::request_, TraceRequest::request_array(), TraceRequest::request_scalar(), and OperatorBase::update_mode_.

27  : psetpool(PSP), Pdynamic(0), Pstatic(0), w_trace(0), Td_trace(0), Vd_trace(0), Vs_trace(0)
28 {
29  update_mode_.set(COLLECTABLE, 1);
30  defKE = defaultKE;
31  nsamples = 0;
32  ion_points = false;
33  nions = -1;
34  request_.request_scalar("weight");
35  request_.request_array("Kinetic");
36  request_.request_array("LocalPotential");
37 }
TraceRequest request_
whether traces are being collected
Definition: OperatorBase.h:531
CombinedTraceSample< TraceReal > * Vs_trace
void request_array(const std::string &name, bool write=false)
Definition: TraceManager.h:233
CombinedTraceSample< TraceReal > * Vd_trace
void request_scalar(const std::string &name, bool write=false)
Definition: TraceManager.h:224
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521

◆ ~EnergyDensityEstimator()

~EnergyDensityEstimator ( )
override

Definition at line 40 of file EnergyDensityEstimator.cpp.

References qmcplusplus::delete_iter(), and EnergyDensityEstimator::spacegrids.

40 { delete_iter(spacegrids.begin(), spacegrids.end()); }
void delete_iter(IT first, IT last)
delete the pointers in [first,last)

Member Function Documentation

◆ addObservables() [1/2]

void addObservables ( PropertySetType plist)
inline

Definition at line 37 of file EnergyDensityEstimator.h.

37 {}

◆ 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 457 of file EnergyDensityEstimator.cpp.

References PooledData< T >::add(), EnergyDensityEstimator::ion_buffer_offset, EnergyDensityEstimator::ion_points, OperatorBase::my_index_, EnergyDensityEstimator::nEDValues, EnergyDensityEstimator::nions, EnergyDensityEstimator::outside_buffer_offset, PooledData< T >::size(), and EnergyDensityEstimator::spacegrids.

458 {
459  my_index_ = collectables.size();
460  //allocate space for energy density outside of any spacegrid
461  outside_buffer_offset = collectables.size();
462  int nvalues = (int)nEDValues;
463  std::vector<RealType> tmp(nvalues);
464  collectables.add(tmp.begin(), tmp.end());
465  //allocate space for spacegrids
466  for (int i = 0; i < spacegrids.size(); i++)
467  {
468  spacegrids[i]->allocate_buffer_space(collectables);
469  }
470  if (ion_points)
471  {
472  ion_buffer_offset = collectables.size();
473  nvalues = nions * ((int)nEDValues);
474  std::vector<RealType> tmp2(nvalues);
475  collectables.add(tmp2.begin(), tmp2.end());
476  }
477 }
int my_index_
starting index of this object
Definition: OperatorBase.h:535

◆ checkoutScalarQuantities()

void checkoutScalarQuantities ( TraceManager tm)
inlineoverrideprivatevirtual

Reimplemented from OperatorBase.

Definition at line 107 of file EnergyDensityEstimator.h.

107 {}

◆ collectScalarQuantities()

void collectScalarQuantities ( )
inlineoverrideprivatevirtual

Reimplemented from OperatorBase.

Definition at line 108 of file EnergyDensityEstimator.h.

108 {}

◆ contributeScalarQuantities()

void contributeScalarQuantities ( )
inlineoverrideprivatevirtual

Reimplemented from OperatorBase.

Definition at line 106 of file EnergyDensityEstimator.h.

106 {}

◆ deleteScalarQuantities()

void deleteScalarQuantities ( )
inlineoverrideprivatevirtual

Reimplemented from OperatorBase.

Definition at line 109 of file EnergyDensityEstimator.h.

109 {}

◆ evaluate()

EnergyDensityEstimator::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 257 of file EnergyDensityEstimator.cpp.

References qmcplusplus::app_log(), ParticleSet::applyMinimumImage(), ParticleSet::Collectables, CombinedTraceSample< T >::combine(), EnergyDensityEstimator::dtable_index, EnergyDensityEstimator::EDIonValues, EnergyDensityEstimator::EDValues, SpaceGrid::evaluate(), ParticleSet::getDistTableAB(), ParticleSet::getLattice(), ParticleSet::getTotalNum(), OperatorBase::have_required_traces_, qmcplusplus::if(), EnergyDensityEstimator::ion_buffer_offset, EnergyDensityEstimator::ion_points, EnergyDensityEstimator::nEDValues, EnergyDensityEstimator::nions, EnergyDensityEstimator::nparticles, EnergyDensityEstimator::nsamples, omp_get_thread_num(), EnergyDensityEstimator::outside_buffer_offset, EnergyDensityEstimator::particles_outside, EnergyDensityEstimator::Pdynamic, ParticleSet::PropertyList, EnergyDensityEstimator::Pstatic, ParticleSet::R, EnergyDensityEstimator::R, TraceSample< T >::sample, EnergyDensityEstimator::spacegrids, SpaceGrid::sum(), qmcplusplus::SUPERCELL_OPEN, EnergyDensityEstimator::T, EnergyDensityEstimator::Td_trace, EnergyDensityEstimator::V, EnergyDensityEstimator::Vd_trace, EnergyDensityEstimator::Vs_trace, EnergyDensityEstimator::W, and EnergyDensityEstimator::w_trace.

258 {
260  {
261  Pdynamic = &P;
262  //Collect positions from ParticleSets
263  int p = 0;
264  {
265  const ParticlePos& Rs = Pdynamic->R;
266  for (int i = 0; i < Rs.size(); i++)
267  {
268  R[p] = Rs[i];
269  p++;
270  }
271  }
272  if (Pstatic && !ion_points)
273  {
274  const ParticlePos& Rs = Pstatic->R;
275  for (int i = 0; i < Rs.size(); i++)
276  {
277  R[p] = Rs[i];
278  p++;
279  }
280  }
281  if (P.getLattice().SuperCellEnum != SUPERCELL_OPEN)
282  P.applyMinimumImage(R);
283  //Convert information accumulated in ParticleSets into EnergyDensity quantities
284  RealType w = w_trace->sample[0];
285  p = 0;
286  {
287  Vd_trace->combine();
288  const ParticleSet& Ps = *Pdynamic;
289  const auto& Ts = Td_trace->sample;
290  const auto& Vs = Vd_trace->sample;
291  for (int i = 0; i < Ps.getTotalNum(); i++)
292  {
293  EDValues(p, W) = w;
294  EDValues(p, T) = w * Ts[i];
295  EDValues(p, V) = w * Vs[i];
296  p++;
297  }
298  }
299  if (Pstatic)
300  {
301  Vs_trace->combine();
302  const ParticleSet& Ps = *Pstatic;
303  const auto& Vs = Vs_trace->sample;
304  if (!ion_points)
305  for (int i = 0; i < Ps.getTotalNum(); i++)
306  {
307  EDValues(p, W) = w;
308  EDValues(p, T) = 0.0;
309  EDValues(p, V) = w * Vs[i];
310  p++;
311  }
312  else
313  for (int i = 0; i < Ps.getTotalNum(); i++)
314  {
315  EDIonValues(i, W) = w;
316  EDIonValues(i, T) = 0.0;
317  EDIonValues(i, V) = w * Vs[i];
318  }
319  }
320  //Accumulate energy density in spacegrids
321  const auto& dtab(P.getDistTableAB(dtable_index));
322  fill(particles_outside.begin(), particles_outside.end(), true);
323  for (int i = 0; i < spacegrids.size(); i++)
324  {
325  SpaceGrid& sg = *spacegrids[i];
326  sg.evaluate(R, EDValues, P.Collectables, particles_outside, dtab);
327  }
328  //Accumulate energy density of particles outside any spacegrid
329  int bi, v;
330  const int bimax = outside_buffer_offset + (int)nEDValues;
331  for (int p = 0; p < particles_outside.size(); p++)
332  {
333  if (particles_outside[p])
334  {
335  for (bi = outside_buffer_offset, v = 0; bi < bimax; bi++, v++)
336  {
337  P.Collectables[bi] += EDValues(p, v);
338  }
339  }
340  }
341  if (ion_points)
342  {
343  // Accumulate energy density for ions at a point field
344  bi = ion_buffer_offset;
345  for (int i = 0; i < nions; i++)
346  for (v = 0; v < (int)nEDValues; v++, bi++)
347  {
348  P.Collectables[bi] += EDIonValues(i, v);
349  }
350  }
351  nsamples++;
352 #if defined(ENERGYDENSITY_CHECK)
353  int thread = omp_get_thread_num();
355  RealType Eref = P.PropertyList[WP::LOCALENERGY];
356  RealType Vref = P.PropertyList[WP::LOCALPOTENTIAL];
357  RealType Tref = Eref - Vref;
358 #pragma omp critical(edcheck)
359  {
360  RealType Dsum = 0.0;
361  RealType Tsum = 0.0;
362  RealType Vsum = 0.0;
363  RealType Esum = 0.0;
364  for (int p = 0; p < nparticles; p++)
365  {
366  Dsum += EDValues(p, W);
367  Tsum += EDValues(p, T);
368  Vsum += EDValues(p, V);
369  }
370  if (ion_points)
371  for (int i = 0; i < nions; i++)
372  {
373  Dsum += EDIonValues(i, W);
374  Tsum += EDIonValues(i, T);
375  Vsum += EDIonValues(i, V);
376  }
377  Esum = Tsum + Vsum;
378  static int cnt = 0;
379  //app_log()<<"eval ED Dsum"<<cnt<<" "<<Dsum<< std::endl;
380  app_log() << thread << " eval ED " << cnt << " " << Tsum << " " << Vsum << " " << Esum << std::endl;
381  int nvals = (int)nEDValues;
382  RealType edvals[nvals];
383  RealType edtmp[nvals];
384  for (int v = 0; v < nvals; v++)
385  edvals[v] = 0.0;
386  for (int i = 0; i < spacegrids.size(); i++)
387  {
388  SpaceGrid& sg = *spacegrids[i];
389  sg.sum(P.Collectables, edtmp);
390  for (int v = 0; v < nvals; v++)
391  edvals[v] += edtmp[v];
392  }
393  for (int v = 0; v < nvals; v++)
394  edvals[v] += P.Collectables[outside_buffer_offset + v];
395  if (ion_points)
396  {
397  for (int i = 0; i < nions; i++)
398  for (int v = 0; v < nvals; v++)
399  edvals[v] += P.Collectables[ion_buffer_offset + i * nvals + v];
400  }
401  //app_log()<<"eval ES Dsum"<<cnt<<" "<<edvals[W]<< std::endl;
402  app_log() << thread << " eval ES " << cnt << " " << edvals[T] << " " << edvals[V] << " " << edvals[T] + edvals[V]
403  << std::endl;
404  app_log() << thread << " ref E " << cnt << " " << Tref << " " << Vref << " " << Eref << std::endl;
405  cnt++;
406  }
407 #endif
408  //APP_ABORT("EnergyDensityEstimator::evaluate");
409  }
410 
411  return 0.0;
412 }
std::ostream & app_log()
Definition: OutputManager.h:65
if(c->rank()==0)
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
ParticlePos R
Position.
Definition: ParticleSet.h:79
CombinedTraceSample< TraceReal > * Vs_trace
QMCTraits::RealType RealType
Indexes
an enum denoting index of physical properties
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
CombinedTraceSample< TraceReal > * Vd_trace

◆ get()

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

write about the class

Implements OperatorBase.

Definition at line 241 of file EnergyDensityEstimator.cpp.

References APP_ABORT.

242 {
243  os << "EDM replace this " << std::endl;
244  APP_ABORT("EnergyDensityEstimator::get");
245  return true;
246 }
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27

◆ get_particleset()

ParticleSet * get_particleset ( std::string &  psname)
private

Definition at line 193 of file EnergyDensityEstimator.cpp.

References APP_ABORT, qmcplusplus::app_log(), and EnergyDensityEstimator::psetpool.

Referenced by EnergyDensityEstimator::put().

194 {
195  auto pit(psetpool.find(psname));
196  if (pit == psetpool.end())
197  {
198  app_log() << " ParticleSet " << psname << " does not exist" << std::endl;
199  APP_ABORT("EnergyDensityEstimator::put");
200  }
201  return pit->second.get();
202 }
std::ostream & app_log()
Definition: OutputManager.h:65
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27

◆ getClassName()

std::string getClassName ( ) const
inlineoverridevirtual

return class name

Implements OperatorBase.

Definition at line 34 of file EnergyDensityEstimator.h.

34 { return "EnergyDensityEstimator"; }

◆ getRequiredTraces()

void getRequiredTraces ( TraceManager tm)
overrideprivatevirtual

TODO: add docs.

Parameters
tm

Reimplemented from OperatorBase.

Definition at line 205 of file EnergyDensityEstimator.cpp.

References TraceManager::get_real_combined_trace(), TraceManager::get_real_trace(), OperatorBase::have_required_traces_, omp_get_thread_num(), EnergyDensityEstimator::Pdynamic, EnergyDensityEstimator::Pstatic, EnergyDensityEstimator::Td_trace, EnergyDensityEstimator::Vd_trace, EnergyDensityEstimator::Vs_trace, and EnergyDensityEstimator::w_trace.

206 {
207  bool write = omp_get_thread_num() == 0;
208  w_trace = tm.get_real_trace("weight");
209  Td_trace = tm.get_real_trace(*Pdynamic, "Kinetic");
210  Vd_trace = tm.get_real_combined_trace(*Pdynamic, "LocalPotential");
211  if (Pstatic)
212  Vs_trace = tm.get_real_combined_trace(*Pstatic, "LocalPotential");
213  have_required_traces_ = true;
214 }
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25
CombinedTraceSample< TraceReal > * Vs_trace
CombinedTraceSample< TraceReal > * Vd_trace

◆ makeClone()

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

Implements OperatorBase.

Definition at line 529 of file EnergyDensityEstimator.cpp.

References qmcplusplus::app_log(), EnergyDensityEstimator::defKE, EnergyDensityEstimator::input_xml, omp_get_thread_num(), and EnergyDensityEstimator::psetpool.

530 {
531  bool write = omp_get_thread_num() == 0;
532  if (write)
533  app_log() << "EnergyDensityEstimator::makeClone" << std::endl;
534 
535  std::unique_ptr<EnergyDensityEstimator> edclone = std::make_unique<EnergyDensityEstimator>(psetpool, defKE);
536  edclone->put(input_xml, qp);
537  //int thread = omp_get_thread_num();
538  //app_log()<<thread<<"make edclone"<< std::endl;
539  //edclone->Pdynamic = Pdynamic->get_clone(thread);
540  //edclone->Pstatic = Pstatic->get_clone(thread);
541  return edclone;
542 }
std::ostream & app_log()
Definition: OutputManager.h:65
omp_int_t omp_get_thread_num()
Definition: OpenMP.h:25

◆ put() [1/2]

bool put ( xmlNodePtr  cur)
overridevirtual

check xml elements

Implements OperatorBase.

Definition at line 52 of file EnergyDensityEstimator.cpp.

References OhmmsAttributeSet::add(), ParticleSet::addTable(), APP_ABORT, qmcplusplus::app_log(), QMCTraits::DIM, EnergyDensityEstimator::dtable_index, EnergyDensityEstimator::EDIonValues, EnergyDensityEstimator::EDValues, EnergyDensityEstimator::get_particleset(), ParticleSet::getLattice(), ParticleSet::getTotalNum(), ParticleSet::hasSK(), qmcplusplus::if(), EnergyDensityEstimator::input_xml, EnergyDensityEstimator::ion_points, OperatorBase::name_, EnergyDensityEstimator::nEDValues, EnergyDensityEstimator::nions, EnergyDensityEstimator::nparticles, EnergyDensityEstimator::particles_outside, EnergyDensityEstimator::Pdynamic, ReferencePoints::points, EnergyDensityEstimator::Pstatic, SpaceGrid::put(), ReferencePoints::put(), OhmmsAttributeSet::put(), ParticleSet::R, EnergyDensityEstimator::R, EnergyDensityEstimator::ref, Matrix< T, Alloc >::resize(), Vector< T, Alloc >::resize(), EnergyDensityEstimator::Rion, EnergyDensityEstimator::Rptcl, EnergyDensityEstimator::set_ptcl(), EnergyDensityEstimator::spacegrids, qmcplusplus::SUPERCELL_OPEN, ParticleSet::turnOnPerParticleSK(), EnergyDensityEstimator::unset_ptcl(), and EnergyDensityEstimator::Zptcl.

Referenced by EnergyDensityEstimator::put().

53 {
54  input_xml = cur;
55  //initialize simple xml attributes
56  name_ = "EnergyDensity";
57  std::string dyn, stat = "";
58  ion_points = false;
59  OhmmsAttributeSet attrib;
60  attrib.add(name_, "name");
61  attrib.add(dyn, "dynamic");
62  attrib.add(stat, "static");
63  attrib.add(ion_points, "ion_points");
64  attrib.put(cur);
65  //collect particle sets
66  if (!Pdynamic)
68  if (Pdynamic->hasSK())
71  std::vector<ParticleSet*> Pref;
72  if (stat == "")
73  {
74  Pstatic = 0;
75  dtable_index = -1;
76  }
77  else
78  {
79  Pstatic = get_particleset(stat);
80  if (Pstatic->hasSK())
83  Pref.resize(1);
84  Pref[0] = Pstatic;
85  if (!ion_points)
87  else
89  }
90  //size arrays
93  if (ion_points)
94  {
96  Rion.resize(nions, DIM);
97  for (int i = 0; i < nions; i++)
98  for (int d = 0; d < DIM; d++)
99  Rion(i, d) = Pstatic->R[i][d];
100  }
102  fill(particles_outside.begin(), particles_outside.end(), true);
103  //read xml element contents
104  xmlNodePtr element;
105  bool stop = false;
106  //initialize reference points
107  app_log() << "Initializing reference points" << std::endl;
108  bool has_ref = false;
109  element = cur->children;
110  while (element != NULL)
111  {
112  std::string name((const char*)element->name);
113  if (name == "reference_points")
114  {
115  if (has_ref)
116  {
117  APP_ABORT("EnergyDensityEstimator::put: EDE can only have one instance of reference_points.");
118  }
119  else
120  {
121  bool ref_succeeded = ref.put(element, *Pdynamic, Pref);
122  stop = stop || !ref_succeeded;
123  has_ref = true;
124  }
125  }
126  element = element->next;
127  }
128  if (!has_ref)
129  {
130  bool ref_succeeded = ref.put(*Pdynamic, Pref);
131  stop = stop || !ref_succeeded;
132  }
133  //initialize grids or other cell partitions
134  bool periodic = Pdynamic->getLattice().SuperCellEnum != SUPERCELL_OPEN;
135  bool grid_succeeded;
136  element = cur->children;
137  int nvalues = (int)nEDValues;
138  while (element != NULL)
139  {
140  std::string name = (const char*)element->name;
141  if (name == "spacegrid")
142  {
143  SpaceGrid* sg = new SpaceGrid(nvalues);
144  spacegrids.push_back(sg);
145  if (Pstatic)
146  {
147  set_ptcl();
148  grid_succeeded = sg->put(element, ref.points, Rptcl, Zptcl, Pdynamic->getTotalNum(), periodic, false);
149  unset_ptcl();
150  }
151  else
152  grid_succeeded = sg->put(element, ref.points, periodic, false);
153  stop = stop || !grid_succeeded;
154  }
155  element = element->next;
156  }
157  if (stop == true)
158  {
159  APP_ABORT("EnergyDensityEstimator::put");
160  }
161  return true;
162 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
if(c->rank()==0)
bool put(xmlNodePtr cur, ParticleSet &P, std::vector< ParticleSet *> &Pref)
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
ParticleSet * get_particleset(std::string &psname)
void turnOnPerParticleSK()
Turn on per particle storage in Structure Factor.
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
std::string name_
name of this object
Definition: OperatorBase.h:527
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::map< std::string, Point > points
ParticlePos R
Position.
Definition: ParticleSet.h:79
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
const auto & getLattice() const
Definition: ParticleSet.h:251
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

◆ put() [2/2]

bool put ( xmlNodePtr  cur,
ParticleSet P 
)

Definition at line 43 of file EnergyDensityEstimator.cpp.

References EnergyDensityEstimator::Pdynamic, and EnergyDensityEstimator::put().

44 {
45  Pdynamic = &Pdyn;
46  return put(cur);
47 }
bool put(xmlNodePtr cur) override
check xml elements

◆ registerCollectables()

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

Reimplemented from OperatorBase.

Definition at line 480 of file EnergyDensityEstimator.cpp.

References ObservableHelper::addProperty(), EnergyDensityEstimator::ion_buffer_offset, EnergyDensityEstimator::ion_points, OperatorBase::name_, EnergyDensityEstimator::nEDValues, EnergyDensityEstimator::nions, EnergyDensityEstimator::nparticles, EnergyDensityEstimator::nsamples, qmcplusplus::oh, EnergyDensityEstimator::outside_buffer_offset, EnergyDensityEstimator::ref, SpaceGrid::registerCollectables(), EnergyDensityEstimator::Rion, ReferencePoints::save(), and EnergyDensityEstimator::spacegrids.

481 {
482  hdf_path hdf_name{name_};
483  h5desc.emplace_back(hdf_name / "variables");
484  auto& oh = h5desc.back();
485  oh.addProperty(const_cast<int&>(nparticles), "nparticles", file);
486  int nspacegrids = spacegrids.size();
487  oh.addProperty(const_cast<int&>(nspacegrids), "nspacegrids", file);
488  oh.addProperty(const_cast<int&>(nsamples), "nsamples", file);
489  if (ion_points)
490  {
491  oh.addProperty(const_cast<int&>(nions), "nions", file);
492  oh.addProperty(const_cast<Matrix<RealType>&>(Rion), "ion_positions", file);
493  }
494 
495  ref.save(h5desc, file);
496  h5desc.emplace_back(hdf_name / "outside");
497  auto& ohOutside = h5desc.back();
498  std::vector<int> ng(1);
499  ng[0] = (int)nEDValues;
500  ohOutside.set_dimensions(ng, outside_buffer_offset);
501  for (int i = 0; i < spacegrids.size(); i++)
502  {
503  SpaceGrid& sg = *spacegrids[i];
504  sg.registerCollectables(h5desc, file, i);
505  }
506  if (ion_points)
507  {
508  std::vector<int> ng2(2);
509  ng2[0] = nions;
510  ng2[1] = (int)nEDValues;
511 
512  h5desc.emplace_back(hdf_name / "ions");
513  auto& ohIons = h5desc.back();
514  ohIons.set_dimensions(ng2, ion_buffer_offset);
515  }
516 }
void addProperty(T &p, const std::string &pname, hdf_archive &file)
add named property to describe the collectable this helper class handles
std::string name_
name of this object
Definition: OperatorBase.h:527
ObservableHelper oh
void save(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const

◆ resetTargetParticleSet()

void resetTargetParticleSet ( ParticleSet P)
overridevirtual

Reset the data with the target ParticleSet.

Parameters
Pnew target ParticleSet

Implements OperatorBase.

Definition at line 249 of file EnergyDensityEstimator.cpp.

250 {
251  //remains empty
252 }

◆ set_ptcl()

void set_ptcl ( void  )
private

Definition at line 165 of file EnergyDensityEstimator.cpp.

References SpeciesSet::addAttribute(), ParticleSet::applyMinimumImage(), ParticleSet::getLattice(), ParticleSet::getSpeciesSet(), ParticleSet::getTotalNum(), ParticleSet::GroupID, qmcplusplus::if(), EnergyDensityEstimator::Pstatic, ParticleSet::R, Vector< T, Alloc >::resize(), EnergyDensityEstimator::Rptcl, Vector< T, Alloc >::size(), qmcplusplus::SUPERCELL_OPEN, and EnergyDensityEstimator::Zptcl.

Referenced by EnergyDensityEstimator::put().

166 {
167  ParticleSet& P = *Pstatic;
168  SpeciesSet& species(P.getSpeciesSet());
169  int ChargeAttribIndx = species.addAttribute("charge");
170  int nspecies = species.TotalNum;
171  int nps = P.getTotalNum();
172  std::vector<RealType> Zspec;
173  Zspec.resize(nspecies);
174  Zptcl.resize(nps);
175  for (int spec = 0; spec < nspecies; spec++)
176  Zspec[spec] = species(ChargeAttribIndx, spec);
177  for (int i = 0; i < nps; i++)
178  Zptcl[i] = Zspec[P.GroupID[i]];
179  Rptcl.resize(P.R.size());
180  for (int i = 0; i < P.R.size(); i++)
181  Rptcl[i] = P.R[i];
182  if (P.getLattice().SuperCellEnum != SUPERCELL_OPEN)
183  P.applyMinimumImage(Rptcl);
184 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
if(c->rank()==0)
size_t TotalNum
total number of particles
Definition: ParticleSet.h:642

◆ 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 518 of file EnergyDensityEstimator.cpp.

519 {
520  //remains empty
521 }

◆ setParticlePropertyList()

void setParticlePropertyList ( PropertySetType plist,
int  offset 
)
overridevirtual

Reimplemented from OperatorBase.

Definition at line 523 of file EnergyDensityEstimator.cpp.

524 {
525  //remains empty
526 }

◆ unset_ptcl()

void unset_ptcl ( void  )
private

◆ write_Collectables()

void write_Collectables ( std::string &  label,
int &  cnt,
ParticleSet P 
)

Definition at line 415 of file EnergyDensityEstimator.cpp.

References qmcplusplus::app_log(), ParticleSet::Collectables, EnergyDensityEstimator::outside_buffer_offset, and EnergyDensityEstimator::spacegrids.

416 {
417  //for(int v=0;v<nEDValues;v++){
418  int ii = spacegrids[0]->buffer_offset;
419  int io = outside_buffer_offset;
420  double Ti = P.Collectables[ii + 1] / P.Collectables[ii] * 12.0;
421  double To = P.Collectables[io + 1] / P.Collectables[io] * 12.0;
422  app_log() << "EDcoll " << label << cnt << " " << Ti << " " << To << std::endl;
423  //}
424 }
std::ostream & app_log()
Definition: OutputManager.h:65

◆ write_description()

void write_description ( std::ostream &  os)

Definition at line 217 of file EnergyDensityEstimator.cpp.

References EnergyDensityEstimator::nparticles, EnergyDensityEstimator::ref, EnergyDensityEstimator::spacegrids, and ReferencePoints::write_description().

218 {
219  os << "EnergyDensityEstimator::write_description" << std::endl;
220  os << std::endl;
221  os << " EnergyDensityEstimator details" << std::endl;
222  os << std::endl;
223  std::string indent = " ";
224  os << indent + "nparticles = " << nparticles << std::endl;
225  os << indent + "nspacegrids = " << spacegrids.size() << std::endl;
226  os << std::endl;
227  ref.write_description(os, indent);
228  os << std::endl;
229  for (int i = 0; i < spacegrids.size(); i++)
230  {
231  spacegrids[i]->write_description(os, indent);
232  }
233  os << std::endl;
234  os << " end EnergyDensityEstimator details" << std::endl;
235  os << std::endl;
236  os << "end EnergyDensityEstimator::write_description" << std::endl;
237  return;
238 }
void write_description(std::ostream &os, std::string &indent)

◆ write_EDValues()

void write_EDValues ( void  )

Definition at line 427 of file EnergyDensityEstimator.cpp.

References qmcplusplus::app_log(), EnergyDensityEstimator::EDValues, and EnergyDensityEstimator::nparticles.

428 {
429  app_log() << "EDValues" << std::endl;
430  for (int p = 0; p < nparticles; p++)
431  fprintf(stdout, " %d %e %e %e\n", p, EDValues(p, 0), EDValues(p, 1), EDValues(p, 2));
432 }
std::ostream & app_log()
Definition: OutputManager.h:65

◆ write_nonzero_domains()

void write_nonzero_domains ( const ParticleSet P)

Definition at line 434 of file EnergyDensityEstimator.cpp.

References qmcplusplus::abs(), qmcplusplus::app_log(), ParticleSet::Collectables, qmcplusplus::Units::charge::e, qmcplusplus::n, EnergyDensityEstimator::nEDValues, EnergyDensityEstimator::outside_buffer_offset, and EnergyDensityEstimator::spacegrids.

435 {
436  app_log() << "Nonzero domains" << std::endl;
437  int nd = 1;
438  for (int i = 0; i < spacegrids.size(); i++)
439  nd += spacegrids[i]->nDomains();
440  for (int i = 0; i < nd; i++)
441  {
442  bool nonzero = false;
443  int n = outside_buffer_offset + i * nEDValues;
444  for (int v = 0; v < nEDValues; v++)
445  {
446  nonzero = nonzero || std::abs(P.Collectables[n + v]) > 1e-8;
447  }
448  if (nonzero)
449  {
450  // fprintf(stdout," %d %e %e %e %e %e %e\n",i,P.Collectables[n],
451  fprintf(stdout, " %d %e %e %e \n", i, P.Collectables[n], P.Collectables[n + 1], P.Collectables[n + 2]);
452  }
453  }
454 }
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_log()
Definition: OutputManager.h:65

Member Data Documentation

◆ defKE

std::string defKE
private

◆ dtable_index

int dtable_index
private

◆ EDIonValues

Matrix<RealType> EDIonValues
private

◆ EDValues

◆ input_xml

xmlNodePtr input_xml
private

◆ ion_buffer_offset

◆ ion_points

◆ nions

◆ nparticles

◆ nsamples

◆ outside_buffer_offset

◆ particles_outside

std::vector<bool> particles_outside
private

◆ Pdynamic

◆ psetpool

const PSPool& psetpool
private

◆ Pstatic

◆ R

◆ ref

◆ Rion

◆ Rptcl

◆ spacegrids

◆ Td_trace

◆ Vd_trace

◆ Vs_trace

◆ w_trace

◆ Zptcl


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