QMCPACK
StructFact Class Reference

Calculates the structure-factor for a particle set. More...

+ Inheritance diagram for StructFact:
+ Collaboration diagram for StructFact:

Public Types

using ParticleLayout = PtclOnLatticeTraits::ParticleLayout
 
- 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 Member Functions

 StructFact (const ParticleLayout &lattice, const KContainer &k_lists)
 Constructor - copy ParticleSet and init. More...
 
 ~StructFact ()
 desructor More...
 
void updateAllPart (const ParticleSet &P)
 Update Rhok if all particles moved. More...
 
void turnOnStorePerParticle (const ParticleSet &P)
 switch on the storage per particle if StorePerParticle was false, this function allocates memory and precompute data if StorePerParticle was true, this function is no-op More...
 
bool isStorePerParticle () const
 accessor of StorePerParticle More...
 
const KContainergetKLists () const
 accessor of k_lists_ More...
 

Static Public Member Functions

static void mw_updateAllPart (const RefVectorWithLeader< StructFact > &sk_list, const RefVectorWithLeader< ParticleSet > &p_list, SKMultiWalkerMem &mw_mem)
 Update RhoK for all particles for multiple walkers particles. More...
 

Public Attributes

int SuperCellEnum
 enumeration for the methods to handle mixed bconds More...
 
Matrix< RealTyperhok_r
 2-D container for the phase More...
 
Matrix< RealTyperhok_i
 
Matrix< RealTypeeikr_r
 
Matrix< RealTypeeikr_i
 

Private Member Functions

void computeRhok (const ParticleSet &P)
 Compute all rhok elements from the start. More...
 
void resize (int nkpts, int num_species, int num_ptcls)
 resize the internal data More...
 

Private Attributes

const KContainerk_lists_
 K-Vector List. More...
 
bool StorePerParticle
 Whether intermediate data is stored per particle. More...
 
NewTimerupdate_all_timer_
 timer for updateAllPart More...
 

Detailed Description

Calculates the structure-factor for a particle set.

Structure factor per species Rhok[alpha][k] $ \equiv \rho_{k}^{\alpha} = \sum_{i} e^{i{\bf k}\cdot{\bf r_i}}$ Structure factor per particle eikr[i][k]

Definition at line 39 of file StructFact.h.

Member Typedef Documentation

◆ ParticleLayout

Constructor & Destructor Documentation

◆ StructFact()

StructFact ( const ParticleLayout lattice,
const KContainer k_lists 
)

Constructor - copy ParticleSet and init.

k-shells

Parameters
latticelong range box
kccutoff for k

At least in the batched version Structure factor is NOT valid after construction.

Definition at line 29 of file StructFact.cpp.

References qmcplusplus::app_log(), LRCoulombSingleton::isQuasi2D(), qmcplusplus::SUPERCELL_SLAB, and StructFact::SuperCellEnum.

31  k_lists_(k_lists),
32  StorePerParticle(false),
33  update_all_timer_(createGlobalTimer("StructFact::update_all_part", timer_level_fine))
34 {
36  {
37  app_log() << " Setting StructFact::SuperCellEnum=SUPERCELL_SLAB " << std::endl;
39  }
40 }
const KContainer & k_lists_
K-Vector List.
Definition: StructFact.h:100
std::ostream & app_log()
Definition: OutputManager.h:65
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
bool StorePerParticle
Whether intermediate data is stored per particle.
Definition: StructFact.h:105
int SuperCellEnum
enumeration for the methods to handle mixed bconds
Definition: StructFact.h:49
NewTimer & update_all_timer_
timer for updateAllPart
Definition: StructFact.h:107
static bool isQuasi2D()
return true if quasi 2D is selected

◆ ~StructFact()

~StructFact ( )
default

desructor

Member Function Documentation

◆ computeRhok()

void computeRhok ( const ParticleSet P)
private

Compute all rhok elements from the start.

evaluate rok per species, eikr per particle

Definition at line 138 of file StructFact.cpp.

References qmcplusplus::dot(), StructFact::eikr_i, StructFact::eikr_r, eval_e2iphi(), ParticleSet::getGroupID(), ParticleSet::getTotalNum(), ParticleSet::groups(), StructFact::k_lists_, KContainer::kpts_cart, omptarget::min(), KContainer::numk, ParticleSet::R, StructFact::resize(), StructFact::rhok_i, StructFact::rhok_r, qmcplusplus::Units::time::s, qmcplusplus::sincos(), and StructFact::StorePerParticle.

Referenced by StructFact::mw_updateAllPart(), StructFact::turnOnStorePerParticle(), and StructFact::updateAllPart().

139 {
140  const size_t num_ptcls = P.getTotalNum();
141  const size_t num_species = P.groups();
142  const size_t nk = k_lists_.numk;
143  resize(nk, num_species, num_ptcls);
144 
145  rhok_r = 0.0;
146  rhok_i = 0.0;
147  if (StorePerParticle)
148  {
149  // save per particle and species value
150  for (int i = 0; i < num_ptcls; ++i)
151  {
152  const auto& pos = P.R[i];
153  auto* restrict eikr_r_ptr = eikr_r[i];
154  auto* restrict eikr_i_ptr = eikr_i[i];
155  auto* restrict rhok_r_ptr = rhok_r[P.getGroupID(i)];
156  auto* restrict rhok_i_ptr = rhok_i[P.getGroupID(i)];
157 #pragma omp simd
158  for (int ki = 0; ki < nk; ki++)
159  {
160  qmcplusplus::sincos(dot(k_lists_.kpts_cart[ki], pos), &eikr_i_ptr[ki], &eikr_r_ptr[ki]);
161  rhok_r_ptr[ki] += eikr_r_ptr[ki];
162  rhok_i_ptr[ki] += eikr_i_ptr[ki];
163  }
164  }
165  }
166  else
167  {
168  // save per species value
169  for (int i = 0; i < num_ptcls; ++i)
170  {
171  const auto& pos = P.R[i];
172  auto* restrict rhok_r_ptr = rhok_r[P.getGroupID(i)];
173  auto* restrict rhok_i_ptr = rhok_i[P.getGroupID(i)];
174 #if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
175 #pragma omp simd
176  for (int ki = 0; ki < nk; ki++)
177  {
178  RealType s, c;
179  qmcplusplus::sincos(dot(k_lists_.kpts_cart[ki], pos), &s, &c);
180  rhok_r_ptr[ki] += c;
181  rhok_i_ptr[ki] += s;
182  }
183 #else
184  // make the compute over nk by blocks
185  constexpr size_t kblock_size = 512;
186  const size_t num_kblocks = (nk + kblock_size) / kblock_size;
187  RealType phiV[kblock_size], eikr_r_temp[kblock_size], eikr_i_temp[kblock_size];
188 
189  for (int ib = 0; ib < num_kblocks; ib++)
190  {
191  const size_t offset = ib * kblock_size;
192  const size_t this_block_size = std::min(kblock_size, nk - offset);
193  for (int ki = 0; ki < this_block_size; ki++)
194  phiV[ki] = dot(k_lists_.kpts_cart[ki + offset], pos);
195  eval_e2iphi(this_block_size, phiV, eikr_r_temp, eikr_i_temp);
196  for (int ki = 0; ki < this_block_size; ki++)
197  {
198  rhok_r_ptr[ki + offset] += eikr_r_temp[ki];
199  rhok_i_ptr[ki + offset] += eikr_i_temp[ki];
200  }
201  }
202 #endif
203  }
204  }
205 }
std::vector< PosType > kpts_cart
K-vector in Cartesian coordinates.
Definition: KContainer.h:53
Matrix< RealType > rhok_r
2-D container for the phase
Definition: StructFact.h:51
Matrix< RealType > eikr_i
Definition: StructFact.h:52
const KContainer & k_lists_
K-Vector List.
Definition: StructFact.h:100
Matrix< RealType > rhok_i
Definition: StructFact.h:51
T min(T a, T b)
bool StorePerParticle
Whether intermediate data is stored per particle.
Definition: StructFact.h:105
QMCTraits::RealType RealType
Matrix< RealType > eikr_r
Definition: StructFact.h:52
void sincos(T a, T *restrict s, T *restrict c)
sincos function wrapper
Definition: math.hpp:62
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void eval_e2iphi(int n, const T *restrict phi, T *restrict phase_r, T *restrict phase_i)
Definition: e2iphi.h:61
void resize(int nkpts, int num_species, int num_ptcls)
resize the internal data
Definition: StructFact.cpp:45
int numk
number of k-points
Definition: KContainer.h:40

◆ getKLists()

const KContainer& getKLists ( ) const
inline

accessor of k_lists_

Definition at line 87 of file StructFact.h.

References StructFact::k_lists_.

87 { return k_lists_; }
const KContainer & k_lists_
K-Vector List.
Definition: StructFact.h:100

◆ isStorePerParticle()

bool isStorePerParticle ( ) const
inline

accessor of StorePerParticle

Definition at line 84 of file StructFact.h.

References StructFact::StorePerParticle.

84 { return StorePerParticle; }
bool StorePerParticle
Whether intermediate data is stored per particle.
Definition: StructFact.h:105

◆ mw_updateAllPart()

void mw_updateAllPart ( const RefVectorWithLeader< StructFact > &  sk_list,
const RefVectorWithLeader< ParticleSet > &  p_list,
SKMultiWalkerMem mw_mem 
)
static

Update RhoK for all particles for multiple walkers particles.

In batched context until this is called StructFact is invalid and will cause a crash if any Hamiltonian using StructFact indirectly through ParticleSet is evaluated.

Definition at line 63 of file StructFact.cpp.

References StructFact::computeRhok(), qmcplusplus::syclBLAS::copy_n(), qmcplusplus::DC_POS_OFFLOAD, QMCTraits::DIM, RefVectorWithLeader< T >::getLeader(), RealSpacePositionsOMPTarget::getMultiWalkerRSoADevicePtrs(), omptarget::min(), SKMultiWalkerMem::nw_rhok, StructFact::rhok_i, StructFact::rhok_r, qmcplusplus::Units::time::s, and qmcplusplus::sincos().

Referenced by ParticleSet::mw_donePbyP().

66 {
67  auto& sk_leader = sk_list.getLeader();
68  auto& p_leader = p_list.getLeader();
69  ScopedTimer local(sk_leader.update_all_timer_);
70  if (p_leader.getCoordinates().getKind() != DynamicCoordinateKind::DC_POS_OFFLOAD || sk_leader.StorePerParticle)
71  for (int iw = 0; iw < sk_list.size(); iw++)
72  sk_list[iw].computeRhok(p_list[iw]);
73  else
74  {
75  const size_t nw = p_list.size();
76  const size_t num_species = p_leader.groups();
77  const auto& kpts_cart = sk_leader.k_lists_.get_kpts_cart_soa();
78  const size_t nk = sk_leader.k_lists_.numk;
79  const size_t nk_padded = kpts_cart.capacity();
80 
81  auto& coordinates_leader = static_cast<const RealSpacePositionsOMPTarget&>(p_leader.getCoordinates());
82  auto& mw_rsoa_dev_ptrs = coordinates_leader.getMultiWalkerRSoADevicePtrs();
83  const size_t np_padded = p_leader.getCoordinates().getAllParticlePos().capacity();
84 
85  constexpr size_t cplx_stride = 2;
86  mw_mem.nw_rhok.resize(nw * num_species * cplx_stride, nk_padded);
87 
88  // make the compute over nk by blocks
89  constexpr size_t kblock_size = 512;
90  const size_t num_kblocks = (nk + kblock_size) / kblock_size;
91 
92  auto* mw_rsoa_ptr = mw_rsoa_dev_ptrs.data();
93  auto* kpts_cart_ptr = kpts_cart.data();
94  auto* mw_rhok_ptr = mw_mem.nw_rhok.data();
95  auto* group_offsets = p_leader.get_group_offsets().data();
96 
97  PRAGMA_OFFLOAD("omp target teams distribute collapse(2) map(always, from : mw_rhok_ptr[:mw_mem.nw_rhok.size()])")
98  for (int iw = 0; iw < nw; iw++)
99  for (int ib = 0; ib < num_kblocks; ib++)
100  {
101  const size_t offset = ib * kblock_size;
102  const size_t this_block_size = omptarget::min(kblock_size, nk - offset);
103  const auto* rsoa_ptr = mw_rsoa_ptr[iw];
104 
105  PRAGMA_OFFLOAD("omp parallel for")
106  for (int ik = 0; ik < this_block_size; ik++)
107  for (int is = 0; is < num_species; is++)
108  {
109  RealType rhok_r(0), rhok_i(0);
110 
111  for (int ip = group_offsets[is]; ip < group_offsets[is + 1]; ip++)
112  {
113  RealType s, c, phase(0);
114  for (int idim = 0; idim < DIM; idim++)
115  phase += kpts_cart_ptr[ik + offset + nk_padded * idim] * rsoa_ptr[ip + idim * np_padded];
116  omptarget::sincos(phase, &s, &c);
117  rhok_r += c;
118  rhok_i += s;
119  }
120 
121  mw_rhok_ptr[(iw * num_species + is) * cplx_stride * nk_padded + offset + ik] = rhok_r;
122  mw_rhok_ptr[(iw * num_species + is) * cplx_stride * nk_padded + nk_padded + offset + ik] = rhok_i;
123  }
124  }
125 
126  for (int iw = 0; iw < nw; iw++)
127  for (int is = 0; is < num_species; is++)
128  {
129  std::copy_n(mw_mem.nw_rhok[(iw * num_species + is) * cplx_stride], nk, sk_list[iw].rhok_r[is]);
130  std::copy_n(mw_mem.nw_rhok[(iw * num_species + is) * cplx_stride + 1], nk, sk_list[iw].rhok_i[is]);
131  }
132  }
133 }
Matrix< RealType > rhok_r
2-D container for the phase
Definition: StructFact.h:51
Matrix< RealType > rhok_i
Definition: StructFact.h:51
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
T min(T a, T b)
for(int i=0;i< size_test;++i) CHECK(Approx(gauss_random_vals[offset_for_rs+i])
void computeRhok(const ParticleSet &P)
Compute all rhok elements from the start.
Definition: StructFact.cpp:138
QMCTraits::RealType RealType
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
Definition: syclBLAS.cpp:548
void sincos(T a, T *restrict s, T *restrict c)
sincos function wrapper
Definition: math.hpp:62

◆ resize()

void resize ( int  nkpts,
int  num_species,
int  num_ptcls 
)
private

resize the internal data

Parameters
nkpts
num_speciesnumber of species
num_ptclsnumber of particles

Definition at line 45 of file StructFact.cpp.

References StructFact::eikr_i, StructFact::eikr_r, Matrix< T, Alloc >::resize(), StructFact::rhok_i, StructFact::rhok_r, and StructFact::StorePerParticle.

Referenced by StructFact::computeRhok().

46 {
47  rhok_r.resize(num_species, nkpts);
48  rhok_i.resize(num_species, nkpts);
49  if (StorePerParticle)
50  {
51  eikr_r.resize(num_ptcls, nkpts);
52  eikr_i.resize(num_ptcls, nkpts);
53  }
54 }
Matrix< RealType > rhok_r
2-D container for the phase
Definition: StructFact.h:51
Matrix< RealType > eikr_i
Definition: StructFact.h:52
Matrix< RealType > rhok_i
Definition: StructFact.h:51
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
bool StorePerParticle
Whether intermediate data is stored per particle.
Definition: StructFact.h:105
Matrix< RealType > eikr_r
Definition: StructFact.h:52

◆ turnOnStorePerParticle()

void turnOnStorePerParticle ( const ParticleSet P)

switch on the storage per particle if StorePerParticle was false, this function allocates memory and precompute data if StorePerParticle was true, this function is no-op

Definition at line 207 of file StructFact.cpp.

References StructFact::computeRhok(), and StructFact::StorePerParticle.

208 {
209  if (!StorePerParticle)
210  {
211  StorePerParticle = true;
212  computeRhok(P);
213  }
214 }
void computeRhok(const ParticleSet &P)
Compute all rhok elements from the start.
Definition: StructFact.cpp:138
bool StorePerParticle
Whether intermediate data is stored per particle.
Definition: StructFact.h:105

◆ updateAllPart()

void updateAllPart ( const ParticleSet P)

Update Rhok if all particles moved.

Definition at line 57 of file StructFact.cpp.

References StructFact::computeRhok(), and StructFact::update_all_timer_.

Referenced by qmcplusplus::TEST_CASE().

58 {
60  computeRhok(P);
61 }
ScopeGuard< NewTimer > ScopedTimer
Definition: NewTimer.h:257
void computeRhok(const ParticleSet &P)
Compute all rhok elements from the start.
Definition: StructFact.cpp:138
NewTimer & update_all_timer_
timer for updateAllPart
Definition: StructFact.h:107

Member Data Documentation

◆ eikr_i

Matrix<RealType> eikr_i

Definition at line 52 of file StructFact.h.

Referenced by StructFact::computeRhok(), and StructFact::resize().

◆ eikr_r

Matrix<RealType> eikr_r

Definition at line 52 of file StructFact.h.

Referenced by StructFact::computeRhok(), and StructFact::resize().

◆ k_lists_

const KContainer& k_lists_
private

K-Vector List.

Definition at line 100 of file StructFact.h.

Referenced by StructFact::computeRhok(), and StructFact::getKLists().

◆ rhok_i

◆ rhok_r

◆ StorePerParticle

bool StorePerParticle
private

Whether intermediate data is stored per particle.

default false storing data per particle needs significant amount of memory but some calculation may request it. storing data per particle specie is more cost-effective

Definition at line 105 of file StructFact.h.

Referenced by StructFact::computeRhok(), StructFact::isStorePerParticle(), StructFact::resize(), and StructFact::turnOnStorePerParticle().

◆ SuperCellEnum

int SuperCellEnum

enumeration for the methods to handle mixed bconds

Allow overwriting lattice::SuperCellEnum to use D-dim k-point sets with mixed BC

Definition at line 49 of file StructFact.h.

Referenced by StructFact::StructFact().

◆ update_all_timer_

NewTimer& update_all_timer_
private

timer for updateAllPart

Definition at line 107 of file StructFact.h.

Referenced by StructFact::updateAllPart().


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