QMCPACK
ParticleSet.BC.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: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /**@file ParticleSet.BC.cpp
16  * @brief definition of functions controlling Boundary Conditions
17  */
18 #include "Particle/ParticleSet.h"
20 #include "Concurrency/OpenMP.h"
21 #include "LongRange/StructFact.h"
22 
23 namespace qmcplusplus
24 {
25 /** Creating StructureFactor
26  *
27  * Currently testing only 1 component for PBCs.
28  */
30 {
32  throw std::runtime_error("Report bug! structure_factor_ has already been created. Unexpected call sequence.");
33 
34  auto& Lattice = getLattice();
35  auto& LRBox = getLRBox();
37  convert2Cart(R); //make sure that R is in Cartesian coordinates
38 
40  {
41  app_log() << "\n Creating Structure Factor for periodic systems " << LRBox.LR_kc << std::endl;
42  structure_factor_ = std::make_unique<StructFact>(LRBox, simulation_cell_.getKLists());
43  }
44 
45  //set the mass array
46  int beforemass = my_species_.numAttributes();
47  int massind = my_species_.addAttribute("mass");
48  if (beforemass == massind)
49  {
50  app_log() << " ParticleSet::createSK setting mass of " << getName() << " to 1.0" << std::endl;
51  for (int ig = 0; ig < my_species_.getTotalNum(); ++ig)
52  my_species_(massind, ig) = 1.0;
53  }
54  for (int iat = 0; iat < GroupID.size(); iat++)
55  Mass[iat] = my_species_(massind, GroupID[iat]);
56 
57  coordinates_->setAllParticlePos(R);
58 }
59 
61 {
63  structure_factor_->turnOnStorePerParticle(*this);
64  else
65  throw std::runtime_error("ParticleSet::turnOnPerParticleSK trying to turn on per particle storage in "
66  "structure_factor_ but structure_factor_ has not been created.");
67 }
68 
70 {
71  bool isPerParticleOn = false;
73  isPerParticleOn = structure_factor_->isStorePerParticle();
74  return isPerParticleOn;
75 }
76 
77 void ParticleSet::convert(const ParticlePos& pin, ParticlePos& pout)
78 {
79  if (pin.getUnit() == pout.getUnit())
80  {
81  pout = pin;
82  return;
83  }
84  if (pin.getUnit() == PosUnit::Lattice)
85  //convert to CartesianUnit
86  {
88  }
89  else
90  //convert to getLattice()Unit
91  {
93  }
94 }
95 
96 void ParticleSet::convert2Unit(const ParticlePos& pin, ParticlePos& pout)
97 {
98  pout.setUnit(PosUnit::Lattice);
99  if (pin.getUnit() == PosUnit::Lattice)
100  pout = pin;
101  else
103 }
104 
105 void ParticleSet::convert2Cart(const ParticlePos& pin, ParticlePos& pout)
106 {
107  pout.setUnit(PosUnit::Cartesian);
108  if (pin.getUnit() == PosUnit::Cartesian)
109  pout = pin;
110  else
112 }
113 
114 void ParticleSet::convert2Unit(ParticlePos& pinout)
115 {
116  if (pinout.getUnit() == PosUnit::Lattice)
117  return;
118  else
119  {
120  pinout.setUnit(PosUnit::Lattice);
122  }
123 }
124 
125 void ParticleSet::convert2Cart(ParticlePos& pinout)
126 {
127  if (pinout.getUnit() == PosUnit::Cartesian)
128  return;
129  else
130  {
131  pinout.setUnit(PosUnit::Cartesian);
133  }
134 }
135 
136 void ParticleSet::applyBC(const ParticlePos& pin, ParticlePos& pout) { applyBC(pin, pout, 0, pin.size()); }
137 
138 void ParticleSet::applyBC(const ParticlePos& pin, ParticlePos& pout, int first, int last)
139 {
140  if (pin.getUnit() == PosUnit::Cartesian)
141  {
142  if (pout.getUnit() == PosUnit::Cartesian)
144  else if (pout.getUnit() == PosUnit::Lattice)
146  else
147  throw std::runtime_error("Unknown unit conversion");
148  }
149  else if (pin.getUnit() == PosUnit::Lattice)
150  {
151  if (pout.getUnit() == PosUnit::Cartesian)
153  else if (pout.getUnit() == PosUnit::Lattice)
155  else
156  throw std::runtime_error("Unknown unit conversion");
157  }
158  else
159  throw std::runtime_error("Unknown unit conversion");
160 }
161 
162 void ParticleSet::applyBC(ParticlePos& pos)
163 {
164  if (pos.getUnit() == PosUnit::Lattice)
165  {
167  }
168  else
169  {
171  }
172 }
173 
174 void ParticleSet::applyMinimumImage(ParticlePos& pinout) const
175 {
176  if (getLattice().SuperCellEnum == SUPERCELL_OPEN)
177  return;
178  for (int i = 0; i < pinout.size(); ++i)
179  getLattice().applyMinimumImage(pinout[i]);
180 }
181 
182 void ParticleSet::convert2UnitInBox(const ParticlePos& pin, ParticlePos& pout)
183 {
184  pout.setUnit(PosUnit::Lattice);
185  convert2Unit(pin, pout); // convert to crystalline unit
186  put2box(pout);
187 }
188 
189 void ParticleSet::convert2CartInBox(const ParticlePos& pin, ParticlePos& pout)
190 {
191  convert2UnitInBox(pin, pout); // convert to crystalline unit
192  convert2Cart(pout);
193 }
194 } // namespace qmcplusplus
a class that defines a supercell in D-dimensional Euclean space.
int numAttributes() const
return the number of attributes in our list
Definition: SpeciesSet.h:59
const auto & getLRBox() const
Definition: ParticleSet.h:253
int SuperCellEnum
supercell enumeration
void convert2UnitInBox(const ParticlePos &pint, ParticlePos &pout)
const std::string & getName() const
return the name
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void applyMinimumImage(ParticlePos &pinout) const
Dummy template class to be specialized.
const KContainer & getKLists() const
access k_lists_ read only
std::ostream & app_log()
Definition: OutputManager.h:65
size_t TotalNum
total number of particles
Definition: ParticleSet.h:642
Dummy template class to apply boundary conditions.
void applyBC(const ParticlePos &pin, ParticlePos &pout)
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
Definition: SpeciesSet.cpp:45
void convert2Unit(const ParticlePos &pin, ParticlePos &pout)
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
std::unique_ptr< StructFact > structure_factor_
Structure factor.
Definition: ParticleSet.h:617
void turnOnPerParticleSK()
Turn on per particle storage in Structure Factor.
size_type size() const
return the current size
Definition: OhmmsVector.h:162
template functions to support conversion and handling of boundary conditions.
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
void convert2Cart(const ParticlePos &pin, ParticlePos &pout)
ParticlePos R
Position.
Definition: ParticleSet.h:79
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
std::unique_ptr< DynamicCoordinates > coordinates_
internal representation of R. It can be an SoA copy of R
Definition: ParticleSet.h:648
SpeciesSet my_species_
SpeciesSet of particles.
Definition: ParticleSet.h:614
void convert(const ParticlePos &pin, ParticlePos &pout)
void put2box(ParticleAttrib< TinyVector< T, D >> &inout)
inout[i]=inout[i]-floor(inout[i])
ParticleScalar Mass
mass of each particle
Definition: ParticleSet.h:87
bool getPerParticleSKState() const
Get state (on/off) of per particle storage in Structure Factor.
const auto & getLattice() const
Definition: ParticleSet.h:251
void createSK()
create Structure Factor with PBCs
bool explicitly_defined
true, the lattice is defined by the input instead of an artificial default
const SimulationCell & simulation_cell_
reference to global simulation cell
Definition: ParticleSet.h:587
void convert2CartInBox(const ParticlePos &pint, ParticlePos &pout)