49 return {{
PS_newpos,
"ParticleSet:" + obj_name +
"::computeNewPosDT"},
50 {
PS_donePbyP,
"ParticleSet:" + obj_name +
"::donePbyP"},
51 {
PS_accept,
"ParticleSet:" + obj_name +
"::acceptMove"},
53 {
PS_update,
"ParticleSet:" + obj_name +
"::update"},
54 {
PS_dt_move,
"ParticleSet:" + obj_name +
"::dt_move"},
55 {
PS_mw_copy,
"ParticleSet:" + obj_name +
"::mw_copy"}};
59 : quantum_domain(classical),
60 Properties(0, 0, 1,
WP::MAXPROPERTIES),
61 simulation_cell_(simulation_cell),
65 active_spin_val_(0.0),
77 : Properties(p.Properties),
78 simulation_cell_(p.simulation_cell_),
82 active_spin_val_(0.0),
83 my_species_(p.getSpeciesSet()),
86 ParentName(p.parentName()),
87 group_offsets_(p.group_offsets_),
88 coordinates_(p.coordinates_->makeClone())
128 group_offsets.resize(agroup.size() + 1);
129 group_offsets[0] = 0;
130 for (
int is = 0; is < agroup.size(); is++)
131 group_offsets[is + 1] = group_offsets[is] + agroup[is];
132 group_offsets.updateTo();
133 const size_t nsum = group_offsets[agroup.size()];
137 for (
int i = 0; i < agroup.size(); i++)
138 for (
int j = 0; j < agroup[i]; j++, loc++)
147 throw std::runtime_error(
"ParticleSet::setQuantumDomain\n input quantum domain is not valid for particles");
156 if (nspecies == 0 &&
getName() !=
"empty")
158 throw std::runtime_error(
"ParticleSet::resetGroups() Failed. No species exisits");
164 app_log() <<
" Missing charge attribute of the SpeciesSet " <<
myName <<
" particleset" << std::endl;
165 app_log() <<
" Assume neutral particles Z=0.0 " << std::endl;
166 for (
int ig = 0; ig < nspecies; ig++)
169 for (
int iat = 0; iat <
Z.
size(); iat++)
175 for (
int ig = 0; ig < nspecies; ig++)
180 for (
int ig = 1; ig < nspecies; ig++)
183 app_log() <<
" All the species have the same mass " << m0 << std::endl;
185 app_log() <<
" Distinctive masses for each species " << std::endl;
186 for (
int iat = 0; iat <
Mass.
size(); iat++)
190 for (
int ig = 0; ig < nspecies; ++ig)
194 assert(
GroupID[iat] < nspecies);
201 int srcChargeIndx = srcSpSet.addAttribute(
"charge");
202 int srcMemberIndx = srcSpSet.addAttribute(
"membersize");
203 int ChargeIndex = spSet.addAttribute(
"charge");
204 int MemberIndx = spSet.addAttribute(
"membersize");
207 int NumSpecies = spSet.TotalNum;
208 int NumSrcSpecies = srcSpSet.TotalNum;
210 std::vector<int> Zat, Zspec, NofSpecies, NofSrcSpecies, CurElec;
212 Zspec.resize(NumSrcSpecies);
213 NofSpecies.resize(NumSpecies);
214 CurElec.resize(NumSpecies);
215 NofSrcSpecies.resize(NumSrcSpecies);
216 for (
int spec = 0; spec < NumSrcSpecies; spec++)
218 Zspec[spec] = (int)round(srcSpSet(srcChargeIndx, spec));
219 NofSrcSpecies[spec] = (int)round(srcSpSet(srcMemberIndx, spec));
221 for (
int spec = 0; spec < NumSpecies; spec++)
223 NofSpecies[spec] = (int)round(spSet(MemberIndx, spec));
224 CurElec[spec] =
first(spec);
227 for (
int iat = 0; iat < Nsrc; iat++)
228 totQ += Zat[iat] = Zspec[src.
GroupID[iat]];
229 app_log() <<
" Total ion charge = " << totQ << std::endl;
231 app_log() <<
" Total system charge = " << totQ << std::endl;
236 int spLeft = NumSpecies;
237 std::vector<PosType> gaussRand(Nptcl);
239 for (
int iat = 0; iat < Nsrc; iat++)
244 while (z > 0 && spLeft)
246 int sp = spToken++ % NumSpecies;
251 int elec = CurElec[sp]++;
252 app_log() <<
" Assigning " << (sp ?
"down" :
"up ") <<
" electron " << elec <<
" to ion " << iat
253 <<
" with charge " << z << std::endl;
254 double radius = 0.5 *
std::sqrt((
double)Zat[iat]);
255 R[elec] = src.
R[iat] + radius * gaussRand[elec];
263 for (
int sp = 0; sp < NumSpecies; sp++)
265 for (
int ie = 0; ie < NofSpecies[sp]; ie++)
267 int iat = ion++ % Nsrc;
268 double radius =
std::sqrt((
double)Zat[iat]);
269 int elec = CurElec[sp]++;
270 R[elec] = src.
R[iat] + radius * gaussRand[elec];
277 os <<
" ParticleSet '" <<
getName() <<
"' contains " <<
TotalNum <<
" particles : ";
278 if (
auto& group_offsets(*
group_offsets_); group_offsets.size() > 0)
279 for (
int i = 0; i < group_offsets.size() - 1; i++)
281 os << std::endl << std::endl;
285 for (
int i = 0; i < numToPrint; i++)
291 os <<
" (... and " << (
TotalNum - numToPrint) <<
" more particle positions ...)" << std::endl;
310 throw std::runtime_error(
"ParticleSet::addTable needs proper names for both source and target particle sets.");
316 std::ostringstream description;
324 app_debug() <<
" ... ParticleSet::addTable Create Table #" << tid <<
" " <<
DistTables[tid]->getName()
330 app_debug() <<
" ... ParticleSet::addTable Reuse Table #" << tid <<
" " <<
DistTables[tid]->getName() << std::endl;
368 pset.coordinates_->setAllParticlePos(
pset.R);
370 auto& dts = p_leader.DistTables;
371 for (
int i = 0; i < dts.size(); ++i)
374 dts[i]->mw_evaluate(dt_list, p_list);
377 if (!skipSK && p_leader.structure_factor_)
378 for (
int iw = 0; iw < p_list.size(); iw++)
396 template<CoordsType CT>
406 const std::vector<SingleParticlePos>& displs)
408 std::vector<SingleParticlePos> new_positions;
409 new_positions.reserve(displs.size());
411 for (
int iw = 0; iw < p_list.size(); iw++)
413 p_list[iw].active_ptcl_ = iat;
414 p_list[iw].active_pos_ = p_list[iw].R[iat] + displs[iw];
423 const std::vector<Scalar_t>& sdispls)
425 for (
int iw = 0; iw < p_list.size(); iw++)
434 bool is_valid =
true;
463 DistTables[i]->move(*
this, newpos, iat, maybe_accept);
468 const std::vector<SingleParticlePos>& new_positions,
477 p_leader.
coordinates_->mw_copyActivePos(coords_list, iat, new_positions);
482 const int dist_tables_size = p_leader.
DistTables.size();
483 for (
int i = 0; i < dist_tables_size; ++i)
486 p_leader.
DistTables[i]->mw_move(dt_list, p_list, new_positions, iat, maybe_accept);
490 PRAGMA_OFFLOAD(
"omp taskwait")
501 for (
int iat = 0; iat < deltaR.size(); ++iat)
514 for (
int iat = 0; iat < deltaR.size(); ++iat)
515 R[iat] = awalker.
R[iat] + dt * deltaR[iat];
527 const ParticlePos& deltaR,
528 const std::vector<RealType>& dt)
534 for (
int iat = 0; iat < deltaR.size(); ++iat)
547 for (
int iat = 0; iat < deltaR.size(); ++iat)
548 R[iat] = awalker.
R[iat] + dt[iat] * deltaR[iat];
567 const ParticlePos& drift,
568 const ParticlePos& deltaR,
575 for (
int iat = 0; iat < deltaR.size(); ++iat)
588 for (
int iat = 0; iat < deltaR.size(); ++iat)
589 R[iat] = awalker.
R[iat] + dt * deltaR[iat] + drift[iat];
601 const ParticlePos& drift,
602 const ParticlePos& deltaR,
603 const std::vector<RealType>& dt)
609 for (
int iat = 0; iat < deltaR.size(); ++iat)
622 for (
int iat = 0; iat < deltaR.size(); ++iat)
623 R[iat] = awalker.
R[iat] + dt[iat] * deltaR[iat] + drift[iat];
644 throw std::runtime_error(
"Bug detected by acceptMove! Request electron is not active!");
688 throw std::runtime_error(
"Bug detected by rejectMove! Request electron is not active!");
702 template<CoordsType CT>
705 const std::vector<bool>& isAccepted,
716 const std::vector<bool>& isAccepted,
725 std::vector<SingleParticlePos> new_positions;
726 new_positions.reserve(p_list.size());
728 new_positions.push_back(
pset.active_pos_);
729 p_leader.
coordinates_->mw_acceptParticlePos(coords_list, iat, new_positions, isAccepted);
732 for (
int i = 0; i < dts.size(); ++i)
735 dts[i]->mw_updatePartial(dt_list, iat, isAccepted);
738 for (
int iw = 0; iw < p_list.size(); iw++)
742 p_list[iw].R[iat] = p_list[iw].active_pos_;
743 p_list[iw].active_ptcl_ = -1;
744 assert(p_list[iw].
R[iat] == p_list[iw].
coordinates_->getAllParticlePos()[iat]);
753 throw std::runtime_error(
"BUG calling mw_accept_rejectMove in non-forward mode");
759 const std::vector<bool>& isAccepted)
761 for (
int iw = 0; iw < p_list.size(); iw++)
765 p_list[iw].spins[iat] = p_list[iw].active_spin_val_;
775 for (
size_t i = 0; i <
DistTables.size(); ++i)
787 pset.coordinates_->donePbyP();
788 pset.active_ptcl_ = -1;
798 for (
int i = 0; i < dts.size(); ++i)
801 dts[i]->mw_finalizePbyP(dt_list, p_list);
809 for (
size_t i = 0; i <
DistTables.size(); ++i)
819 #if !defined(SOA_MEMORY_OPTIMIZED) 836 const std::vector<bool>& recompute,
844 pset.spins = awalker.spins;
845 pset.coordinates_->setAllParticlePos(
pset.R);
847 for (
int iw = 0; iw < p_list.size(); ++iw)
849 loadWalkerConfig(p_list[iw],
walkers[iw]);
853 auto& dts = p_leader.DistTables;
854 for (
int i = 0; i < dts.size(); ++i)
857 dts[i]->mw_recompute(dt_list, p_list, recompute);
866 #if !defined(SOA_MEMORY_OPTIMIZED) 874 for (
int iw = 0; iw < psets.size(); ++iw)
950 collection.
addResource(std::make_unique<SKMultiWalkerMem>());
957 for (
int i = 0; i < ps_leader.DistTables.size(); i++)
958 ps_leader.DistTables[i]->acquireResource(collection,
extractDTRefList(p_list, i));
960 if (ps_leader.structure_factor_)
968 for (
int i = 0; i < ps_leader.DistTables.size(); i++)
969 ps_leader.DistTables[i]->releaseResource(collection,
extractDTRefList(p_list, i));
971 if (ps_leader.structure_factor_)
978 dt_list.reserve(p_list.size());
980 dt_list.push_back(*p.DistTables[
id]);
988 coords_list.reserve(p_list.size());
990 coords_list.push_back(*p.coordinates_);
997 sk_list.reserve(p_list.size());
999 sk_list.push_back(*p.structure_factor_);
1012 const std::vector<bool>& isAccepted,
1016 const std::vector<bool>& isAccepted,
multi walker shared memory buffer
a class that defines a supercell in D-dimensional Euclean space.
int numAttributes() const
return the number of attributes in our list
DynamicCoordinateKind
enumerator for DynamicCoordinates kinds
bool isValid(const TinyVector< T, D > &u) const
return true if all the open direction of reduced coordinates u are in the range [0,1)
ResourceHandle< SKMultiWalkerMem > mw_structure_factor_data_handle_
multi walker structure factor data
void acceptMoveForwardMode(Index_t iat)
actual implemenation for accepting a proposed move in forward mode
quantum_domains quantum_domain
quantum_domain of the particles, default = classical
const std::string & getName() const
return the name
static void mw_makeMove(const RefVectorWithLeader< ParticleSet > &p_list, int iat, const MCCoords< CT > &displs)
batched version of makeMove
size_t addResource(std::unique_ptr< Resource > &&res, bool noprint=false)
void takebackResource(ResourceHandle< RS > &res_handle)
Index_t active_ptcl_
the index of the active particle during particle-by-particle moves
helper functions for EinsplineSetBuilder
const DistanceTableAA & getDistTableAA(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAA
static void mw_accept_rejectSpinMove(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< bool > &isAccepted)
batched version of acceptMove and reject Move fused, but only for spins
ParticleScalar spins
internal spin variables for dynamical spin calculations
std::string myName
the name of the node, corresponds to the xml tag
std::vector< TimerIDName_t< T > > TimerNameList_t
std::unique_ptr< DynamicCoordinates > createDynamicCoordinates(const DynamicCoordinateKind kind)
create DynamicCoordinates based on kind
PosUnit InUnit
The unit type.
size_t getTotalNum() const
size_t TotalNum
total number of particles
static void mw_makeSpinMove(const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< Scalar_t > &sdispls)
batched version makeMove for spin variable only
static void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< ParticleSet > &p_list)
release external resource Note: use RAII ResourceCollectionTeamLock whenever possible ...
static RefVectorWithLeader< StructFact > extractSKRefList(const RefVectorWithLeader< ParticleSet > &p_list)
bool same_mass_
true if the particles have the same mass
std::vector< std::vector< FullPrecRealType > > PropertyHistory
Property history vector.
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
int first(int igroup) const
return the first index of a group i
void update(bool skipSK=false)
update the internal data
ParticleLaplacian L
laplacians of the particles
static RefVectorWithLeader< DistanceTable > extractDTRefList(const RefVectorWithLeader< ParticleSet > &p_list, int id)
static void mw_saveWalker(const RefVectorWithLeader< ParticleSet > &psets, const RefVector< Walker_t > &walkers)
batched version of saveWalker
static void mw_accept_rejectMove(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< bool > &isAccepted, bool forward_mode=true)
batched version of acceptMove and rejectMove fused, templated on CoordsType
int addAttribute(const std::string &aname)
for a new attribute, allocate the data, !More often used to get the index of a species ...
SingleParticlePos myTwist
Scalar_t active_spin_val_
the proposed spin of active_ptcl_ during particle-by-particle moves
std::map< std::string, int > myDistTableMap
map to handle distance tables
ParticleIndex GroupID
Species ID.
void rejectMoveForwardMode(Index_t iat)
reject a proposed move in forward mode
PropertySetType PropertyList
name-value map of Walker Properties
int getTotalNum() const
return the number of species
static const TimerNameList_t< PSetTimers > generatePSetTimerNames(std::string &obj_name)
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.
const DistanceTableAB & getDistTableAB(int table_ID) const
get a distance table by table_ID and dyanmic_cast to DistanceTableAB
std::unique_ptr< StructFact > structure_factor_
Structure factor.
std::vector< std::string > Names
ParticleSet(const SimulationCell &simulation_cell, const DynamicCoordinateKind kind=DynamicCoordinateKind::DC_POS)
default constructor
int addTable(const ParticleSet &psrc, DTModes modes=DTModes::ALL_OFF)
add a distance table
Specialized paritlce class for atomistic simulations.
size_type size() const
return the current size
const Lattice & getLattice() const
int add(const std::string &aname)
void makeGaussRandom(std::vector< TinyVector< T, D >> &a)
AB type of DistanceTable containing storage.
void rejectMove(Index_t iat)
reject a proposed move in regular mode
void resize(size_t numPtcl)
resize internal storage
ParticleGradient G
gradients of the particles
bool makeMoveAndCheckWithSpin(Index_t iat, const SingleParticlePos &displ, const Scalar_t &sdispl)
makeMoveAndCheck, but now includes an update to the spin variable
static void mw_computeNewPosDistTables(const RefVectorWithLeader< ParticleSet > &p_list, Index_t iat, const std::vector< SingleParticlePos > &new_positions, bool maybe_accept=true)
compute temporal DistTables and SK for a new particle position for each walker in a batch ...
void saveWalker(Walker_t &awalker)
save this to awalker
std::vector< int > PHindex
int groupsize(int igroup) const
return the size of a group
void accept_rejectMove(Index_t iat, bool accepted, bool forward_mode=true)
accept or reject a proposed move Two operation modes: The using and updating distance tables via Part...
void reset() override
dummy. For satisfying OhmmsElementBase.
int addPropertyHistory(int leng)
void makeMoveWithSpin(Index_t iat, const SingleParticlePos &displ, const Scalar_t &sdispl)
makeMove, but now includes an update to the spin variable
SingleParticlePos toUnit(const TinyVector< T1, D > &r) const
Convert a cartesian vector to a unit vector.
std::vector< std::string > distTableDescriptions
Descriptions from distance table creation. Same order as DistTables.
OMPallocator is an allocator with fused device and dualspace allocator functionality.
bool is_spinor_
true is a dynamic spin calculation
ParticleScalar Z
charge of each particle
AA type of DistanceTable containing storage.
void loadWalker(Walker_t &awalker, bool pbyp)
load a Walker_t to the current ParticleSet
void computeNewPosDistTables(Index_t iat, const SingleParticlePos &newpos, bool maybe_accept=true)
compute temporal DistTables and SK for a new particle position
Buffer_t Collectables
observables in addition to those registered in Properties/PropertyList
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
void create(const std::vector< int > &agroup)
create grouped particles
static void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< ParticleSet > &p_list)
acquire external resource and assocaite it with the list of ParticleSet Note: use RAII ResourceCollec...
std::vector< std::string > speciesName
Species name list.
std::unique_ptr< DynamicCoordinates > coordinates_
internal representation of R. It can be an SoA copy of R
std::vector< std::reference_wrapper< T > > RefVector
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
std::shared_ptr< Vector< int, OMPallocator< int > > > group_offsets_
array to handle a group of distinct particles per species
std::unique_ptr< DistanceTable > createDistanceTable(ParticleSet &s, std::ostream &description)
whether full table needs to be ready at anytime or not during PbyP Optimization can be implemented du...
SpeciesSet my_species_
SpeciesSet of particles.
void print(std::ostream &os, const size_t maxParticlesToPrint=0) const
print particle coordinates to a std::ostream
~ParticleSet() override
default destructor
bool quantumDomainValid() const
check whether quantum domain is valid for particles
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
ParticleScalar Mass
mass of each particle
static RefVectorWithLeader< DynamicCoordinates > extractCoordsRefList(const RefVectorWithLeader< ParticleSet > &p_list)
SingleParticlePos active_pos_
the proposed position of active_ptcl_ during particle-by-particle moves
Indexes
an enum denoting index of physical properties
static void mw_update(const RefVectorWithLeader< ParticleSet > &p_list, bool skipSK=false)
batched version of update
static void mw_donePbyP(const RefVectorWithLeader< ParticleSet > &p_list, bool skipSK=false)
batched version of donePbyP
bool put(std::istream &) override
dummy. For satisfying OhmmsElementBase.
bool makeMoveAllParticlesWithDrift(const Walker_t &awalker, const ParticlePos &drift, const ParticlePos &deltaR, RealType dt)
move all the particles including the drift
bool makeMoveAndCheck(Index_t iat, const SingleParticlePos &displ)
move the iat-th particle to active_pos_
bool outOfBound(const TinyVector< T, D > &u) const
return true if any direction of reduced coordinates u goes larger than 0.5
void setQuantumDomain(quantum_domains qdomain)
specify quantum_domain of particles
TimerManager< NewTimer > & getGlobalTimerManager()
ResourceHandle< RS > lendResource()
void randomizeFromSource(ParticleSet &src)
Initialize particles around another ParticleSet Used to initialize an electron ParticleSet by an ion ...
bool explicitly_defined
true, the lattice is defined by the input instead of an artificial default
Custom container for set of attributes for a set of species.
void evaluate(Matrix< T, Alloc > &lhs, const Op &op, const Expression< RHS > &rhs)
static void mw_loadWalker(const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< Walker_t > &walkers, const std::vector< bool > &recompute, bool pbyp)
batched version of loadWalker
std::vector< std::unique_ptr< DistanceTable > > DistTables
distance tables that need to be updated by moving this ParticleSet
bool get(std::ostream &os) const override
dummy. For satisfying OhmmsElementBase.
void acceptMove(Index_t iat)
accept the move and update the particle attribute by the proposed move in regular mode ...
Declare a global Random Number Generator.
bool makeMoveAllParticles(const Walker_t &awalker, const ParticlePos &deltaR, RealType dt)
move all the particles of a walker
A container class to represent a walker.
const SimulationCell & simulation_cell_
reference to global simulation cell
void donePbyP(bool skipSK=false)
update structure factor and unmark active_ptcl_
void makeVirtualMoves(const SingleParticlePos &newpos)
Handles virtual moves for all the particles to a single newpos.
ParticleLaplacian L
^2_i d for the i-th particle
ParticlePos R
The configuration vector (3N-dimensional vector to store the positions of all the particles for a sin...