QMCPACK
HarmonicExternalPotential.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
15 #include "OhmmsData/AttributeSet.h"
16 
17 
18 namespace qmcplusplus
19 {
20 bool HarmonicExternalPotential::put(xmlNodePtr cur)
21 {
22  using std::sqrt;
23 
24  mass = -1.0;
25  energy = -1.0;
26  length = -1.0;
27  center = 0.0;
28 
29  OhmmsAttributeSet attrib;
30  attrib.add(mass, "mass");
31  attrib.add(energy, "frequency");
32  attrib.add(energy, "energy");
33  attrib.add(length, "length");
34  attrib.add(center, "center");
35  attrib.put(cur);
36 
37  if (energy < 0.0)
38  energy = 1.0;
39  if (mass < 0.0 && length < 0.0)
40  length = 1.0;
41  if (mass < 0.0)
42  mass = 1.0 / (energy * length * length);
43  else if (length < 0.0)
44  length = 1.0 / sqrt(mass * energy);
45 
46  return true;
47 }
48 
49 
50 bool HarmonicExternalPotential::get(std::ostream& os) const
51 {
52  os << "External harmonic potential" << std::endl;
53  return true;
54 }
55 
56 
58 {
59  return std::make_unique<HarmonicExternalPotential>(*this);
60 }
61 
62 
64 {
65 #if !defined(REMOVE_TRACEMANAGER)
67  value_ = evaluate_sp(P);
68  else
69  {
70 #endif
71  value_ = 0.0;
72  RealType prefactor = .5 * energy / (length * length);
73  for (int i = 0; i < P.getTotalNum(); ++i)
74  {
75  PosType r = P.R[i] - center;
76  value_ += prefactor * dot(r, r);
77  }
78 #if !defined(REMOVE_TRACEMANAGER)
79  }
80 #endif
81  return value_;
82 }
83 
84 
85 #if !defined(REMOVE_TRACEMANAGER)
87 {
88  Array<TraceReal, 1>& V_samp = *V_sample;
89  value_ = 0.0;
90  RealType prefactor = .5 * energy / (length * length);
91  for (int i = 0; i < P.getTotalNum(); ++i)
92  {
93  PosType r = P.R[i] - center;
94  RealType v1 = prefactor * dot(r, r);
95  V_samp(i) = v1;
96  value_ += v1;
97  }
98  return value_;
99 }
100 #endif
101 
102 } // namespace qmcplusplus
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
size_t getTotalNum() const
Definition: ParticleSet.h:493
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
Array< TraceReal, 1 > * V_sample
single particle trace sample array
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
bool get(std::ostream &os) const override
write about the class
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
ParticlePos R
Position.
Definition: ParticleSet.h:79
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
bool put(xmlNodePtr cur) override
Read the input parameter.
Class to represent a many-body trial wave function.
Return_t value_
current value
Definition: OperatorBase.h:524
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
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
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.