QMCPACK
NESpaceGrid.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: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 // Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //
11 // Some code refactored from: QMCHamiltonian/SpaceGrid.h
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 /** \file
15  * This is the port of QMCHamiltonian/SpaceGrid to the new Estimator design.
16  * Name clashes were undesirable as the legacy implementation needed to remain.
17  * \todo rename to more obvious Spacegrid once QMCHamiltonian/SpaceGrid is removed
18  */
19 #ifndef QMCPLUSPLUS_NESPACEGRID_H
20 #define QMCPLUSPLUS_NESPACEGRID_H
21 
22 #include <Configuration.h>
23 
24 #include "SpaceGridInput.h"
25 #include "OhmmsPETE/Tensor.h"
26 #include "OhmmsPETE/OhmmsMatrix.h"
27 #include "Pools/PooledData.h"
29 #include "Particle/DistanceTable.h"
30 #include "NEReferencePoints.h"
31 
32 namespace qmcplusplus
33 {
34 /** SpaceGrid refactored for use with batched estimator design
35  * NE should be dropped when QMCHamiltonian/SpaceGrid has been deleted.
36  *
37  * This class has more going on than just representing a spacial grid
38  * I'm still working out how much of this just because of the Voronoi code that shouldn't be
39  * part of the same class as the simpler grid and how much is particleset contimination etc.
40  *
41  * For memory considerations it is quite possible this could be at single precision even
42  * if the actual montecarlo is being carried out in double precision. Eventually this should
43  * be determined from input in some way.
44  */
45 namespace testing
46 {
47 template<typename T>
49 }
50 
51 template<typename REAL>
53 {
54 public:
55  using Real = REAL;
56  using Point = typename NEReferencePoints::Point;
62  enum class ReferenceEnergy
63  {
64  vacuum,
65  neutral,
66  noref
67  };
68 
69  /** This constructor is used for electron only grids
70  * \param[in] sgi input object for space grid.
71  * \param[in] reference reference points from which origin and on other reference points referenced in input object are to be found
72  * \param[in] nvalues number of fields the owning class wants for each grid point.
73  * \param[in] is_periodic properly names is what is says
74  */
75  NESpaceGrid(SpaceGridInput& sgi, const Points& points, const int nvalues, const bool is_periodic);
76 
77  /** This is the general constructor
78  * \param[in] sgi input object for space grid.
79  * \param[in] reference reference points from which origin and on other reference points referenced in input object are to be found
80  * \param[in] ndp number of particles that can move
81  * \param[in] nvalues number of fields the owning class wants for each grid point.
82  * \param[in] is_periodic properly names is what is says
83  */
84  NESpaceGrid(SpaceGridInput& sgi, const Points& points, const int ndp, const int nvalues, const bool is_periodic);
85 
86  /** This is the constructor for when PStatic is used.
87  */
89  const Points& points,
90  ParticlePos& static_particle_positions,
91  std::vector<Real>& static_particle_charges,
92  const int ndp,
93  const int nvalues,
94  const bool is_periodic);
95 
96  NESpaceGrid(const NESpaceGrid& sg) = default;
97  NESpaceGrid& operator=(const NESpaceGrid& sg) = default;
98 
99  void write_description(std::ostream& os, const std::string& indent);
100 
101  /** set up Observable helper(s) for this grid
102  * almost unchanged from legacy
103  * \todo uses Observable helper unpleasantly in implementation, remove
104  */
105  void registerGrid(hdf_archive& file, int grid_index);
106 
107  void write(hdf_archive& file) const;
108  /// @}
109 
110  void accumulate(const ParticlePos& R,
111  const Matrix<Real>& values,
112  std::vector<bool>& particles_outside);
113 
114  /** SpaceGridAccumulate not type erased and with its own particular interface.
115  * the composing class needs to provide the following to spave grid.
116  * \param[in] R particle positions
117  * \param[in] values matrix indexed particle, value
118  * \param[in/out] buf buffer to accumulating grid to
119  * \param[out] particles_outside mask vector of particles falling outside the grid box
120  * \param[in] dtab particle A to Particle B distance table
121  *
122  * right now cartesian grids are all accumulated as if they were "periodic" which honestly does not
123  * seem to be well defined with repsect to these grids. But for the particle cell itself it doesn't make
124  * sense that it be periodic unless it is exactly comenserate with the particle cell (at least IMHO)
125  */
126  void accumulate(const ParticlePos& R,
127  const Matrix<Real>& values,
128  std::vector<bool>& particles_outside,
129  const DistanceTableAB& dtab);
130 
131  bool check_grid(void);
132  int nDomains(void) const { return ndomains_; }
133 
134  void sum(const BufferType& buf, Real* vals);
135 
136  void static collect(NESpaceGrid& reduction_grid, RefVector<NESpaceGrid> grid_for_each_crowd);
137 
138  auto& getDataVector() { return data_; }
139 private:
140  /** copy AxisGrid data to SoA layout for evaluation
141  */
142  void copyToSoA();
143 
144 
145  void zero();
146 
147  /** return actual origin point based on input
148  */
149  static Point deriveOrigin(const SpaceGridInput& input, const Points& points);
150 
151  /** dispatch to correct initialize for coord type
152  */
153  bool initializeCoordSystem();
154 
155  /** Initialize NESpaceGrid for rectilinear grid
156  * \param[in] input SpaceGridInput object
157  * \param[in] points ReferencePoints object for grid
158  * Causes side effects updating
159  * origin_ fixed up origin for grid
160  * axes_ axes with scaling applied to it.
161  * axinv_ the inverse of the axes with scaling applied
162  */
163  bool initializeRectilinear(const SpaceGridInput& input, const Points& points);
164 
165  /** Initialize NESpaceGrid for cylindrical grid
166  * \param[in] input SpaceGridInput object
167  * \param[in] points ReferencePoints object for grid
168  * Causes side effects updating
169  * origin_ fixed up origin for grid
170  * axes_ axes with scaling applied to it.
171  * axinv_ the inverse of the axes with scaling applied
172  */
173  bool initializeCylindrical(const SpaceGridInput& input, const Points& points);
174 
175  /** Initialize NESpaceGrid for cylindrical grid
176  * \param[in] input SpaceGridInput object
177  * \param[in] points ReferencePoints object for grid
178  * Causes side effects updating
179  * origin_ fixed up origin for grid
180  * axes_ axes with scaling applied to it.
181  * axinv_ the inverse of the axes with scaling applied
182  */
183  bool initializeSpherical(const SpaceGridInput& input, const Points& points);
184 
185  // /** Initialize NESpaceGrid for voronoi grid
186  // * \param[in] input SpaceGridInput object
187  // * \param[in] points ReferencePoints object for grid
188  // * \param[in] rs_static Initial static particle positions
189  // * Causes side effects updating
190  // * origin_ fixed up origin for grid
191  // * axes_ axes with scaling applied to it.
192  // * axinv_ the inverse of the axes with scaling applied
193  // */
194  // bool initializeVoronoi(const SpaceGridInput& input, const Points& points, ParticlePos& r_static);
195 
196  /** Another function to cut scopes to sort of manageable size.
197  * does nothing but create many side effects
198  */
199  void someMoreAxisGridStuff();
200 
201  /** create axes and axinv tensors
202  * \param[in] input space grid input
203  * \param[out] axes
204  * \param[out] axinv
205  */
206  static void processAxis(const SpaceGridInput& input, const Points& points, AxTensor& axes, AxTensor& axinv);
207 
208  // should be handled in SpaceGridInput now.
209  //static bool checkAxisGridValues(const SpaceGridInput& input_, const AxTensor& axes);
210 
211  /** refrence points for the space grid
212  * this reference it to the EstimatorManagers EDE's spacegrid_inputs_
213  */
217  /** refrence points for the space grid
218  * this reference is to the EstimatorManagers EDE's reference points
219  */
220  const Points& points_;
221 
222  // _NO_
225 
226  /** in legacy used to be the starting index into the collectibles buffer.
227  * Maintained to use more legacy code without modificaiton in the short term.
228  * In the long term its possible the entire way the grid data is structured in memory should be redesigned.
229  */
230  const int buffer_offset_{0};
231  int ndomains_{1};
233  /** @ingroup Calculated by NESpaceGrid
234  * These are calculated by NESpaceGrid before accumulation and possibly belong in SpaceGridInput
235  * as derived inputs. i.e. they are immutable and only based on the input.
236  * Alternately they would be appropriate to calculate at construction time.
237  * @{ */
240  //really only used for cartesian-like grids
244 
245  /// @}
246 
249  std::string axlabel_[OHMMS_DIM];
250  std::array<std::vector<int>, 3> gmap_;
256  std::vector<Real> data_;
257  std::shared_ptr<ObservableHelper> observable_helper_;
258 
259  struct IRPair
260  {
262  int i;
263  };
264  std::vector<IRPair> nearcell_;
265 
266 public:
267  template<typename T>
269 };
270 
271 extern template class NESpaceGrid<float>;
272 extern template class NESpaceGrid<double>;
273 
274 
275 } // namespace qmcplusplus
276 
277 #endif
NESpaceGrid & operator=(const NESpaceGrid &sg)=default
bool initializeSpherical(const SpaceGridInput &input, const Points &points)
Initialize NESpaceGrid for cylindrical grid.
static Point deriveOrigin(const SpaceGridInput &input, const Points &points)
return actual origin point based on input
ReferenceEnergy reference_energy_
Definition: NESpaceGrid.h:255
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const Points & points_
refrence points for the space grid this reference is to the EstimatorManagers EDE&#39;s reference points ...
Definition: NESpaceGrid.h:220
typename NEReferencePoints::Point Point
Definition: NESpaceGrid.h:56
std::map< std::string, Point > Points
typename NEReferencePoints::Points Points
Definition: NESpaceGrid.h:57
class to handle hdf file
Definition: hdf_archive.h:51
TinyVector< Real, OHMMS_DIM > Point
Attaches a unit to a Vector for IO.
Real umin_[OHMMS_DIM]
Definition: NESpaceGrid.h:252
#define OHMMS_DIM
Definition: config.h:64
ForceBase::Real Real
Definition: ForceBase.cpp:26
void copyToSoA()
copy AxisGrid data to SoA layout for evaluation
void accumulate(const ParticlePos &R, const Matrix< Real > &values, std::vector< bool > &particles_outside)
const int buffer_offset_
in legacy used to be the starting index into the collectibles buffer.
Definition: NESpaceGrid.h:230
Declaration of ObservableHelper and other helper class for observables.
Real umax_[OHMMS_DIM]
Definition: NESpaceGrid.h:253
int nDomains(void) const
Definition: NESpaceGrid.h:132
PooledData< Real > BufferType
Definition: NESpaceGrid.h:58
static void processAxis(const SpaceGridInput &input, const Points &points, AxTensor &axes, AxTensor &axinv)
create axes and axinv tensors
Definition: NESpaceGrid.cpp:91
AB type of DistanceTable containing storage.
void write_description(std::ostream &os, const std::string &indent)
Tensor< Real, OHMMS_DIM > AxTensor
Definition: NESpaceGrid.h:61
Matrix< Real > domain_centers_
Definition: NESpaceGrid.h:239
std::shared_ptr< ObservableHelper > observable_helper_
Definition: NESpaceGrid.h:257
std::vector< IRPair > nearcell_
Definition: NESpaceGrid.h:264
bool initializeCylindrical(const SpaceGridInput &input, const Points &points)
Initialize NESpaceGrid for cylindrical grid.
bool initializeRectilinear(const SpaceGridInput &input, const Points &points)
Initialize NESpaceGrid for rectilinear grid.
Matrix< Real > domain_uwidths_
Definition: NESpaceGrid.h:248
bool initializeCoordSystem()
dispatch to correct initialize for coord type
Definition: NESpaceGrid.cpp:71
Real odu_[OHMMS_DIM]
Definition: NESpaceGrid.h:251
std::vector< std::reference_wrapper< T > > RefVector
void registerGrid(hdf_archive &file, int grid_index)
set up Observable helper(s) for this grid almost unchanged from legacy
Particle traits to use UniformGridLayout for the ParticleLayout.
Definition: Configuration.h:77
ParticleAttrib< SingleParticlePos > ParticlePos
Definition: Configuration.h:92
std::array< std::vector< int >, 3 > gmap_
Definition: NESpaceGrid.h:250
POLT::ParticlePos ParticlePos
Definition: NESpaceGrid.h:60
static void collect(NESpaceGrid &reduction_grid, RefVector< NESpaceGrid > grid_for_each_crowd)
SpaceGridInput & input_
refrence points for the space grid this reference it to the EstimatorManagers EDE&#39;s spacegrid_inputs_...
Definition: NESpaceGrid.h:214
void write(hdf_archive &file) const
Matrix< Real > domain_volumes_
These are calculated by NESpaceGrid before accumulation and possibly belong in SpaceGridInput as der...
Definition: NESpaceGrid.h:238
void sum(const BufferType &buf, Real *vals)
void someMoreAxisGridStuff()
Initialize NESpaceGrid for voronoi grid.
std::string axlabel_[OHMMS_DIM]
Definition: NESpaceGrid.h:249
Define a serialized buffer to store anonymous data.
NESpaceGrid(SpaceGridInput &sgi, const Points &points, const int nvalues, const bool is_periodic)
This constructor is used for electron only grids.
std::vector< Real > data_
Definition: NESpaceGrid.h:256