QMCPACK
test_StructFact.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) 2019 and QMCPACK developers.
6 //
7 // File developed by: Yubo "Paul" Yang, yubo.paul.yang@gmail.com, University of Illinois Urbana-Champaign
8 //
9 // File created by: Yubo "Paul" Yang, yubo.paul.yang@gmail.com, University of Illinois Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
13 
14 #include <vector>
15 #include <complex>
16 #include "Configuration.h"
17 #include "ParticleSet.h"
18 #include "LongRange/StructFact.h"
19 
20 namespace qmcplusplus
21 {
22 /** evalaute bare Coulomb in 3D using LRHandlerTemp
23  */
24 TEST_CASE("StructFact", "[lrhandler]")
25 {
27  Lattice.BoxBConds = true;
28  Lattice.LR_dim_cutoff = 30.;
29  Lattice.R.diagonal(5.0);
30  Lattice.reset();
31  CHECK(Approx(Lattice.Volume) == 125);
32  Lattice.SetLRCutoffs(Lattice.Rv);
33  Lattice.printCutoffs(app_log());
34  CHECK(Approx(Lattice.LR_rc) == 2.5);
35  CHECK(Approx(Lattice.LR_kc) == 12);
36 
37  Lattice.LR_dim_cutoff = 125;
38  const SimulationCell simulation_cell(Lattice);
39  ParticleSet ref(simulation_cell); // handler needs ref.getSimulationCell().getKLists()
40 
41  SpeciesSet& tspecies = ref.getSpeciesSet();
42  int upIdx = tspecies.addSpecies("u");
43  int downIdx = tspecies.addSpecies("d");
44 
45  ref.create({3,1});
46  ref.R[0] = {0.0, 1.0, 2.0};
47  ref.R[1] = {1.0, 0.2, 3.0};
48  ref.R[2] = {0.3, 4.0, 1.4};
49  ref.R[3] = {3.2, 4.7, 0.7};
50 
51  REQUIRE(simulation_cell.getKLists().numk == 263786);
52  StructFact sk(ref.getLRBox(), simulation_cell.getKLists());
53  sk.updateAllPart(ref);
54 
55  CHECK(sk.rhok_r.rows() == ref.groups());
56  CHECK(sk.rhok_i.rows() == ref.groups());
57  CHECK(sk.rhok_r.cols() == simulation_cell.getKLists().numk);
58  CHECK(sk.rhok_i.cols() == simulation_cell.getKLists().numk);
59 
60  std::vector<std::complex<double>> rhok_sum_ref{-125.80618630936, 68.199075127271};
61 
62  for (int i = 0; i < ref.groups(); i++)
63  {
64  std::complex<QMCTraits::RealType> rhok_sum, rhok_even_sum;
65  for (int ik = 0; ik < simulation_cell.getKLists().numk; ik++)
66  rhok_sum += std::complex<QMCTraits::RealType>(sk.rhok_r[i][ik], sk.rhok_i[i][ik]);
67 
68  //std::cout << std::setprecision(14) << rhok_sum << std::endl;
69  CHECK(ComplexApprox(rhok_sum).epsilon(5e-5) == rhok_sum_ref[i]);
70  }
71 }
72 
73 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
const auto & getLRBox() const
Definition: ParticleSet.h:253
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
void reset()
Evaluate the reciprocal vectors, volume and metric tensor.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
const KContainer & getKLists() const
access k_lists_ read only
std::ostream & app_log()
Definition: OutputManager.h:65
TEST_CASE("complex_helper", "[type_traits]")
Calculates the structure-factor for a particle set.
Definition: StructFact.h:39
TinyVector< SingleParticlePos, D > Rv
Real-space unit vectors.
int groups() const
return the number of groups
Definition: ParticleSet.h:511
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Scalar_t Volume
Physical properties of a supercell.
TinyVector< int, D > BoxBConds
The boundary condition in each direction.
REQUIRE(std::filesystem::exists(filename))
ParticlePos R
Position.
Definition: ParticleSet.h:79
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
void diagonal(const T &rhs)
Definition: Tensor.h:205
void create(const std::vector< int > &agroup)
create grouped particles
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Custom container for set of attributes for a set of species.
Definition: SpeciesSet.h:33
void updateAllPart(const ParticleSet &P)
Update Rhok if all particles moved.
Definition: StructFact.cpp:57
Tensor_t R
Real-space unit vectors. R(i,j) i=vector and j=x,y,z.
int numk
number of k-points
Definition: KContainer.h:40