QMCPACK
ParticleAttrib.h
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) 2021 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 /**@file ParticleAttrib.h
14  *
15  * Declaraton of ParticleAttrib<T> derived from Vector
16  */
17 
18 #ifndef OHMMS_NEW_PARTICLEATTRIB_PEPE_H
19 #define OHMMS_NEW_PARTICLEATTRIB_PEPE_H
20 
21 #include "OhmmsPETE/TinyVector.h"
22 #include "OhmmsPETE/OhmmsVector.h"
23 #include "Utilities/OhmmsObject.h"
24 #include "PosUnit.h"
25 
26 namespace qmcplusplus
27 {
28 /** Attaches a unit to a Vector for IO
29  *
30  * Makes Vect
31  */
32 template<class T, typename Alloc = std::allocator<T>>
33 class ParticleAttrib : public Vector<T, Alloc>, public OhmmsObject
34 {
36 
37 public:
38  /// The unit type
40 
41  /** constructor with size n*/
42  explicit inline ParticleAttrib(size_t n = 0) : __my_base(n), InUnit(PosUnit::Cartesian) {}
43 
44  /** constructor with an initialized ref */
45  explicit inline ParticleAttrib(T* ref, size_t n) : __my_base(ref, n), InUnit(PosUnit::Cartesian) {}
46 
47  ParticleAttrib(const ParticleAttrib& rhs) = default;
48 
49  ParticleAttrib(std::initializer_list<T> ts) : __my_base(ts), InUnit(PosUnit::Cartesian){};
50 
51  inline ParticleAttrib& operator=(const ParticleAttrib& rhs) = default;
52 
53  /** assignment operator to enable PETE */
54  template<class RHS>
55  inline ParticleAttrib& operator=(const RHS& rhs)
56  {
57  assign(*this, rhs);
58  return *this;
59  }
60 
61  //@{set/set the unit
62  inline void setUnit(PosUnit i) { InUnit = i; }
63  inline PosUnit getUnit() const { return InUnit; }
64  //@}
65 
66  OhmmsObject* makeClone() const override { return new ParticleAttrib<T, Alloc>(*this); }
67 
68  /** Specialized to write the unit
69  *\return true, if the attribute is relative to a unit
70  *
71  * Ad hoc get function to tell users if this attribute is absolute or relative value.
72  * E.g., is Cartesian unit vs Lattice unit.
73  */
74  bool get(std::ostream& os) const override
75  {
76  os << InUnit;
77  return true;
78  }
79 
80  /** Specialized to read the unit
81  */
82  bool put(std::istream& is) override
83  {
84  is >> InUnit;
85  return true;
86  }
87 
88  /*@warning not fully implemented.*/
89  bool put(xmlNodePtr cur) override { return true; }
90 
91  ///reset member data
92  void reset() override {}
93 };
94 
95 template<class T, unsigned D>
97 {
98  return &(a[0][0]);
99 }
100 
101 template<class T, unsigned D>
103 {
104  return &(a[0][0]) + D * a.size();
105 }
106 
107 } // namespace qmcplusplus
108 
109 #include "ParticleAttrib.cpp"
110 
111 #endif // OHMMS_PARTICLEATTRIB_PEPE_H
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
PosUnit InUnit
The unit type.
ParticleAttrib & operator=(const RHS &rhs)
assignment operator to enable PETE
Attaches a unit to a Vector for IO.
bool put(xmlNodePtr cur) override
read from an xmlNode
bool put(std::istream &is) override
Specialized to read the unit.
An OhmmsElementBase with extra members to keep track the object/type.
Definition: OhmmsObject.h:43
Matrix< T1, C1 > & assign(Matrix< T1, C1 > &lhs, const RHS &rhs)
T * get_last_address(ParticleAttrib< TinyVector< T, D >> &a)
ParticleAttrib(std::initializer_list< T > ts)
OhmmsObject * makeClone() const override
void reset() override
reset member data
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
Declaration of OhmmsObject.
PosUnit
enum class to assist copy and unit conversion operations on position vectors
Definition: PosUnit.h:21
ParticleAttrib & operator=(const ParticleAttrib &rhs)=default
ParticleAttrib(T *ref, size_t n)
constructor with an initialized ref
T * get_first_address(ParticleAttrib< TinyVector< T, D >> &a)
ParticleAttrib(size_t n=0)
constructor with size n