QMCPACK
ForceBase.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: John R. Gergely, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
12 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: John R. Gergely, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 #include "ForceBase.h"
18 #include "Particle/ParticleSet.h"
19 #include "Message/Communicate.h"
23 
24 namespace qmcplusplus
25 {
27 
29  : first_force_index_(-1),
30  n_nuc_(ions.getTotalNum()),
31  n_el_(elns.getTotalNum()),
32  tries_(0),
33  first_time_(true),
34  add_ion_ion_(true),
35  ions_(ions)
36 {
37  ReportEngine PRE("ForceBase", "ForceBase");
38  pair_name_ = elns.getName() + "-" + ions.getName();
40  forces_ = 0.0;
42  forces_ion_ion_ = 0.0;
43 }
44 
46 
48 {
49  if (first_force_index_ < 0)
50  first_force_index_ = plist.size();
51  for (int iat = 0; iat < n_nuc_; iat++)
52  {
53  for (int x = 0; x < OHMMS_DIM; x++)
54  {
55  std::ostringstream obsName;
56  obsName << prefix_ << "_" << iat << "_" << x;
57  plist.add(obsName.str());
58  }
59  }
60 }
61 
63 {
64  if (first_force_index_ < 0)
65  first_force_index_ = plist.size();
66  for (int i = 0; i < OHMMS_DIM; i++)
67  for (int j = i; j < OHMMS_DIM; j++)
68  {
69  std::ostringstream obsName;
70  obsName << prefix_ << "_" << i << "_" << j;
71  plist.add(obsName.str());
72  }
73 }
74 
75 void ForceBase::registerObservablesF(std::vector<ObservableHelper>& h5list, hdf_archive& file) const
76 {
77  std::vector<int> ndim(2);
78  ndim[0] = n_nuc_;
79  ndim[1] = OHMMS_DIM;
80 
81  h5list.emplace_back(hdf_path{prefix_});
82  auto& h5o = h5list.back();
83  h5o.set_dimensions(ndim, first_force_index_);
84 }
85 
87 {
88  int index = first_force_index_;
89  for (int iat = 0; iat < n_nuc_; iat++)
90  {
91  for (int x = 0; x < OHMMS_DIM; x++)
92  {
93  plist[index] = forces_[iat][x];
94  index++;
95  }
96  }
97 }
98 
100 {
101  int index = first_force_index_;
102  for (int iat = 0; iat < OHMMS_DIM; iat++)
103  {
104  for (int jat = iat; jat < OHMMS_DIM; jat++)
105  {
106  plist[index] = stress_(iat, jat);
107  index++;
108  }
109  }
110 }
111 
112 
114 {
115  int index = first_force_index_ + offset;
116  for (int iat = 0; iat < n_nuc_; iat++)
117  {
118  for (int x = 0; x < OHMMS_DIM; x++)
119  {
120  plist[index] = forces_[iat][x];
121  index++;
122  }
123  }
124 }
125 
127 {
128  int index = first_force_index_ + offset;
129  for (int iat = 0; iat < OHMMS_DIM; iat++)
130  {
131  for (int jat = iat; jat < OHMMS_DIM; jat++)
132  {
133  plist[index] = stress_(iat, jat);
134  index++;
135  }
136  }
137 }
138 
139 void ForceBase::setForces(const ParticleSet::ParticlePos& forces) { forces_ = forces; }
140 
141 void ForceBase::setForces(Real val) { forces_ = val; }
142 
143 void ForceBase::setForcesIonIon(const ParticleSet::ParticlePos& forces_ion_ion) { forces_ion_ion_ = forces_ion_ion; }
144 
145 void ForceBase::initVarReduction(Real rcut, int m, int numFuncs)
146 {
147  m_ = m;
148  rcut_ = rcut;
149  std::vector<Real> h(numFuncs);
150  Matrix<Real> S(numFuncs, numFuncs);
151  ck_.resize(numFuncs, 0.0);
152  Real R2jp1 = rcut_ * rcut_;
153  Real R2m = 1.0;
154  for (int i = 0; i < m_; i++)
155  R2m *= rcut_;
156  for (int j = 1; j <= numFuncs; j++)
157  {
158  h[j - 1] = R2jp1 / Real(j + 1);
159  Real R2k = rcut_;
160  for (int k = 1; k <= numFuncs; k++)
161  {
162  S(k - 1, j - 1) = R2m * R2k * R2jp1 / (Real)(m_ + k + j + 1);
163  S(k - 1, j - 1) = std::pow(rcut_, (m_ + k + j + 1)) / (m_ + k + j + 1.0);
164  R2k *= rcut_;
165  }
166  R2jp1 *= rcut_;
167  }
168  invert_matrix(S, false);
169  for (int i = 0; i < numFuncs; i++)
170  {
171  for (int j = 0; j < numFuncs; j++)
172  ck_[i] += S(i, j) * h[j];
173  }
174  FILE* fout = fopen("g_r.dat", "w");
175  for (double r = 0.0; r < rcut_; r += 0.001)
176  fprintf(fout, "%1.10f %1.10e\n", r, g(r));
177  fclose(fout);
178  app_log() << "Initialized variance reduction coefs.\n";
179 }
180 
181 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
MatrixA::value_type invert_matrix(MatrixA &M, bool getdet=true)
invert a matrix
void setForcesIonIon(const ParticleSet::ParticlePos &forces_ion_ion)
Definition: ForceBase.cpp:143
const std::string & getName() const
return the name
void setObservablesStress(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:99
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< Real > ck_
Definition: ForceBase.h:103
void setForces(const ParticleSet::ParticlePos &forces)
Definition: ForceBase.cpp:139
ParticleSet::ParticlePos forces_
Definition: ForceBase.h:87
std::ostream & app_log()
Definition: OutputManager.h:65
void addObservablesF(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:47
class to handle hdf file
Definition: hdf_archive.h:51
Vectorized record engine for scalar properties.
ForceBase(ParticleSet &ions, ParticleSet &elns)
Definition: ForceBase.cpp:28
Attaches a unit to a Vector for IO.
std::string prefix_
Definition: ForceBase.h:96
#define OHMMS_DIM
Definition: config.h:64
ForceBase::Real Real
Definition: ForceBase.cpp:26
void registerObservablesF(std::vector< ObservableHelper > &h5list, hdf_archive &file) const
Definition: ForceBase.cpp:75
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)
void initVarReduction(Real rcut, int m, int numFuncs)
Definition: ForceBase.cpp:145
void addObservablesStress(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:62
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void setParticleSetStress(QMCTraits::PropertySetType &plist, int offset)
Definition: ForceBase.cpp:126
int add(const std::string &aname)
Final class and should not be derived.
declaration of ProgressReportEngine
void setParticleSetF(QMCTraits::PropertySetType &plist, int offset)
Definition: ForceBase.cpp:113
std::string pair_name_
Definition: ForceBase.h:97
QMCTraits::RealType Real
cheat, need to use virtual inheriance to clean up
Definition: ForceBase.h:29
Define determinant operators.
void setObservablesF(QMCTraits::PropertySetType &plist)
Definition: ForceBase.cpp:86
Real g(Real r)
Definition: ForceBase.h:31
SymTensor< Real, OHMMS_DIM > stress_
Definition: ForceBase.h:94
ParticleSet::ParticlePos forces_ion_ion_
Definition: ForceBase.h:88