QMCPACK
SpeciesSet.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #include "SpeciesSet.h"
17 #include <algorithm>
18 namespace qmcplusplus
19 {
20 void SpeciesSet::create(unsigned m)
21 {
22  if (m > 0)
23  {
24  speciesName.insert(speciesName.end(), m, std::string("none"));
25  for (auto& d : d_attrib)
26  {
27  d.insert(d.end(), m, 0);
28  }
29  TotalNum += m;
30  }
31 }
32 
33 int SpeciesSet::addSpecies(const std::string& aname)
34 {
35  int i = findSpecies(aname); // check if the name is registered
36  if (i == TotalNum)
37  // if not found, add a new species
38  {
39  create(1);
40  speciesName[i] = aname;
41  }
42  return i; // return an index for a species
43 }
44 
45 int SpeciesSet::addAttribute(const std::string& aname)
46 {
47  int i = 0;
48  while (i < attribName.size())
49  {
50  if (attribName[i] == aname)
51  return i;
52  i++;
53  }
54  attribName.push_back(aname);
55  int n = d_attrib.size();
56  d_attrib.push_back(SpeciesAttrib_t(TotalNum));
57  return n;
58 }
59 
60 int SpeciesSet::getAttribute(const std::string& aname) const
61 {
62  for (int i = 0; i < attribName.size(); i++)
63  {
64  if (attribName[i] == aname)
65  return i;
66  }
67  return attribName.size();
68 }
69 
70 bool SpeciesSet::hasAttribute(const std::string& aname) const
71 {
72  return std::find(attribName.begin(), attribName.end(), aname) != attribName.end();
73 }
74 
75 } // namespace qmcplusplus
std::vector< std::string > attribName
attribute name list
Definition: SpeciesSet.h:47
int addSpecies(const std::string &aname)
When a name species does not exist, add a new species.
Definition: SpeciesSet.cpp:33
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool hasAttribute(const std::string &aname) const
Check for attribute presence This replaces code that gets numAttributes then tries to addAttribute fo...
Definition: SpeciesSet.cpp:70
void create(unsigned m)
Definition: SpeciesSet.cpp:20
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
AttribList_t d_attrib
List of species attributes.
Definition: SpeciesSet.h:50
std::vector< std::string > speciesName
Species name list.
Definition: SpeciesSet.h:44
int getAttribute(const std::string &aname) const
When a name species does not exist, return attribute.size()
Definition: SpeciesSet.cpp:60
int findSpecies(const std::string &name) const
if the input species is not found, add a new species
Definition: SpeciesSet.h:114
std::vector< Scalar_t > SpeciesAttrib_t
Definition: SpeciesSet.h:37
unsigned TotalNum
The number of species.
Definition: SpeciesSet.h:41