QMCPACK
MagnetizationDensity.h
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) 2023 QMCPACK developers.
6 //
7 // File developed by: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
8 //
9 // File created by: Raymond Clay, rclay@sandia.gov, Sandia National Laboratories
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef QMCPLUSPLUS_MAGNETIZATION_DENSITY_H
13 #define QMCPLUSPLUS_MAGNETIZATION_DENSITY_H
14 
15 #include <vector>
16 #include <functional>
17 
21 #include <SpeciesSet.h>
22 #include <StdRandom.h>
24 
25 namespace qmcplusplus
26 {
27 namespace testing
28 {
29 class MagnetizationDensityTests;
30 }
31 /** Magnetization density estimator for non-collinear spin calculations.
32  *
33  * As documented in the manual, the following formula is computed:
34  *\mathbf{m}_c = \int d\mathbf{X} \left|{\Psi(\mathbf{X})}\right|^2 \int_{\Omega_c}d\mathbf{r} \sum_i\delta(\mathbf{r}-\hat{\mathbf{r}}_i)\int_0^{2\pi} \frac{ds'_i}{2\pi} \frac{\Psi(\ldots \mathbf{r}_i s'_i \ldots )}{\Psi(\ldots \mathbf{r}_i s_i \ldots)}\langle s_i | \hat{\sigma} | s'_i \rangle
35  *
36  * The way that the above relates to the underlying data structure data_ is as follows. We grid space up and assign an index
37  * for each of the real space bins (identical to SpinDensityNew). To account for the fact that magnetization is vectorial, we
38  * triple the length of this array. If grid_i is the index of the real space gridpoint i, then the data is layed out like:
39  * [grid_0_x, grid_0_y, grid_0_z, grid_1_x, ..., grid_N_x, grid_N_y, grid_N_z]. This is also the way it is stored in HDF5.
40  *
41  */
43 {
44 public:
53  static constexpr int DIM = QMCTraits::DIM;
54 
57 
58  void startBlock(int steps) override;
59 
61  const RefVector<ParticleSet>& psets,
62  const RefVector<TrialWaveFunction>& wfns,
63  const RefVector<QMCHamiltonian>& hams,
64  RandomBase<FullPrecReal>& rng) override;
65 
66  void collect(const RefVector<OperatorEstBase>& operator_estimators) override;
67  /**
68  * This returns the total size of data object required for this estimator.
69  * Right now, it's 3*number_of_realspace_gridpoints
70  *
71  * @return Size of data.
72  */
73  size_t getFullDataSize();
74  std::unique_ptr<OperatorEstBase> spawnCrowdClone() const override;
75  void registerOperatorEstimator(hdf_archive& file) override;
76 
77  /**
78  * This is a convenience function that handles \int_0^{2\pi} dx f(x).
79  * There are two provided methods for integrating this, so this function picks Simpson's
80  * or Monte Carlo to perform this integration, while keeping awareness of the integration
81  * interval and number of samples.
82  *
83  * @tparam Value type. Real or complex in double or single precision. Return type is same as fgrid type.
84  * @param[in] fgrid f(x), the function to integrate. Assumed to be on a [0-2pi] interval, and if the grid isn't
85  * random, it's assumed to be uniform.
86  * @return Value of integral.
87  */
88  Value integrateMagnetizationDensity(const std::vector<Value>& fgrid) const;
89 
90 private:
91  MagnetizationDensity(const MagnetizationDensity& magdens) = default;
92 
93 
94  /**
95  * Generates the spin integrand \Psi(s')/Psi(s)* \langle s | \vec{\sigma} | s'\rangle for a specific
96  * electron iat. Since this is a vectorial quantity, this function returns sx, sy, and sz in their own
97  * arrays.
98  *
99  * @param[in] pset ParticleSet
100  * @param[in] wfn TrialWaveFunction
101  * @param[in] iat electron index
102  * @param[out] sx x component of spin integrand
103  * @param[out] sy y component of spin integrand
104  * @param[out] sz z component of spin integrand
105  */
107  TrialWaveFunction& wfn,
108  const int iat,
109  std::vector<Value>& sx,
110  std::vector<Value>& sy,
111  std::vector<Value>& sz);
112 
113  /**
114  * Implementation of Simpson's 1/3 rule to integrate a function on a uniform grid.
115  *
116  * @param[in] fgrid f(x), the function to integrate.
117  * @param[in] gridDx, the grid spacing for the uniform grid. Assumed to be consistent with size of fgrid.
118  * @return Value of integral.
119  */
120  Value integrateBySimpsonsRule(const std::vector<Value>& fgrid, Real gridDx) const;
121 
122 
123  /**
124  * Convenience function to generate a grid between 0 and 2pi, consistent with nsamples_ and integration method.
125  * Can be uniform or random, depending on choice of integrator.
126  *
127  * @param[out] sgrid A grid with nsamples_ points between 0 and 2pi. Overwritten.
128  */
129  void generateGrid(std::vector<Real>& sgrid) const;
130 
131  /**
132  * Generate a uniform grid between [start,stop] for numerical quadrature.
133  *
134  * @param[out] sgrid Random number grid between "start" and "stop". Number of points taken from size of sgrid.
135  * @param[in] start start of grid interval
136  * @param[in] stop end of grid interval
137  */
138  void generateUniformGrid(std::vector<Real>& sgrid, const Real start, const Real stop) const;
139 
140  /**
141  * Generate random grid between [start,stop] for MC integration.
142  *
143  * @tparam RAN_GEN Random number generator type.
144  * @param[out] sgrid Random number grid between "start" and "stop". Number of points taken from size of sgrid.
145  * @param[in] rng Random number generator queried to generate random points.
146  * @param[in] start start of grid interval
147  * @param[in] stop end of grid interval
148  */
149 
150  void generateRandomGrid(std::vector<Real>& sgrid, RandomBase<FullPrecReal>& rng, Real start, Real stop) const;
151 
152  /**
153  * For a given spatial position r and spin component s, this returns the bin for accumulating the observable.
154  *
155  *
156  * @param[in] Position in real space. 3D
157  * @param[in] component, the x=0,y=1,z=2 component of the spin.
158  * @return Index of appropriate bin for this position and spin component
159  */
160  size_t computeBin(const Position& r, const unsigned int component) const;
162  //These are the same variables as in SpinDensityNew.
169  size_t npoints_;
171 
173 };
174 } // namespace qmcplusplus
175 #endif /* QMCPLUSPLUS_MAGNETIZATION_DENSITY_H */
a class that defines a supercell in D-dimensional Euclean space.
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
size_t computeBin(const Position &r, const unsigned int component) const
For a given spatial position r and spin component s, this returns the bin for accumulating the observ...
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > ParticleLayout
Definition: Configuration.h:79
void generateSpinIntegrand(ParticleSet &pset, TrialWaveFunction &wfn, const int iat, std::vector< Value > &sx, std::vector< Value > &sy, std::vector< Value > &sz)
Generates the spin integrand (s&#39;)/Psi(s)* s | {} | s&#39; for a specific electron iat.
class to handle hdf file
Definition: hdf_archive.h:51
MagnetizationDensity(MagnetizationDensityInput &&min, const Lattice &lattice)
const char walkers[]
Definition: HDFVersion.h:36
T min(T a, T b)
Value integrateMagnetizationDensity(const std::vector< Value > &fgrid) const
This is a convenience function that handles ^{2} dx f(x).
void collect(const RefVector< OperatorEstBase > &operator_estimators) override
Reduce estimator result data from crowds to rank.
QMCTraits::FullPrecValueType FullPrecValue
void registerOperatorEstimator(hdf_archive &file) override
CrystalLattice< OHMMS_PRECISION, OHMMS_DIM > lattice
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Value integrateBySimpsonsRule(const std::vector< Value > &fgrid, Real gridDx) const
Implementation of Simpson&#39;s 1/3 rule to integrate a function on a uniform grid.
QTFull::ValueType FullPrecValueType
Definition: Configuration.h:67
QTBase::ValueType ValueType
Definition: Configuration.h:60
void generateGrid(std::vector< Real > &sgrid) const
Convenience function to generate a grid between 0 and 2pi, consistent with nsamples_ and integration ...
RealAlias< FullPrecValue > FullPrecReal
A minimally functional wrapper for the since c++11 <random>
An abstract class for gridded estimators.
void generateUniformGrid(std::vector< Real > &sgrid, const Real start, const Real stop) const
Generate a uniform grid between [start,stop] for numerical quadrature.
QTBase::PosType PosType
Definition: Configuration.h:61
std::unique_ptr< OperatorEstBase > spawnCrowdClone() const override
size_t getFullDataSize()
This returns the total size of data object required for this estimator.
std::vector< std::reference_wrapper< T > > RefVector
void accumulate(const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, const RefVector< QMCHamiltonian > &hams, RandomBase< FullPrecReal > &rng) override
Class to represent a many-body trial wave function.
typename RealAlias_impl< T >::value_type RealAlias
If you have a function templated on a value that can be real or complex and you need to get the base ...
DataLocality
data locality with respect to walker buffer
Definition: DataLocality.h:19
void generateRandomGrid(std::vector< Real > &sgrid, RandomBase< FullPrecReal > &rng, Real start, Real stop) const
Generate random grid between [start,stop] for MC integration.
Magnetization density estimator for non-collinear spin calculations.