TBTK
Geometry.h
Go to the documentation of this file.
1 /* Copyright 2016 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_GEOMETRY
24 #define COM_DAFER45_TBTK_GEOMETRY
25 
27 #include "TBTK/Serializable.h"
28 
29 #include <initializer_list>
30 
31 namespace TBTK{
32  class FileReader;
33 
35 class Geometry : public Serializable{
36 public:
38  Geometry(
39  int dimensions,
40  int numSpecifiers,
41  const HoppingAmplitudeSet *hoppingAmplitudeSet
42  );
43 
45  Geometry(const Geometry &geometry);
46 
48  Geometry(Geometry &&geometry);
49 
52  Geometry(
53  const std::string &serialization,
54  Mode mode,
55  const HoppingAmplitudeSet &hoppingAmplitudeSet
56  );
57 
59  virtual ~Geometry();
60 
62  Geometry& operator=(const Geometry &rhs);
63 
65  Geometry& operator=(Geometry &&rhs);
66 
68  void setCoordinates(
69  const Index &index,
70  std::initializer_list<double> coordinates,
71  std::initializer_list<int> specifiers = {}
72  );
73 
75  void setCoordinates(
76  const Index &index,
77  const std::vector<double> &coordinates,
78  const std::vector<int> &specifiers = {}
79  );
80 
82  void setCoordinates(
83  int basisIndex,
84  std::initializer_list<double> coordinates,
85  std::initializer_list<int> specifiers = {}
86  );
87 
89  void setCoordinates(
90  int basisIndex,
91  const std::vector<double> &coordinates,
92  const std::vector<int> &specifiers = {}
93  );
94 
96  int getDimensions() const;
97 
99  int getNumSpecifiers() const;
100 
102  const double* getCoordinates(const Index &index) const;
103 
105  const double* getCoordinates(int index) const;
106 
108  const double* getCoordinates() const;
109 
111  void translate(std::initializer_list<double> translation);
112 
114  int getSpecifier(const Index &index, int specifier) const;
115 
117  int getSpecifier(int index, int specifier) const;
118 
120  const int* getSpecifiers(const Index &index) const;
121 
123  const int* getSpecifiers(int index) const;
124 
126  const int* getSpecifiers() const;
127 
130  double getDistance(const Index &index1, const Index &index2) const;
131 
134  double getDistance(int index1, int index2) const;
135 
137  int getBasisSize() const;
138 
140  std::string serialize(Mode mode) const;
141 private:
143  unsigned int dimensions;
144 
146  unsigned int numSpecifiers;
147 
149  double *coordinates;
150 
152  int *specifiers;
153 
155  const HoppingAmplitudeSet *hoppingAmplitudeSet;
156 
158  friend class FileReader;
159 };
160 
161 inline int Geometry::getDimensions() const{
162  return dimensions;
163 }
164 
165 inline int Geometry::getNumSpecifiers() const{
166  return numSpecifiers;
167 }
168 
169 inline const double* Geometry::getCoordinates(const Index &index) const{
170  return &(coordinates[dimensions*hoppingAmplitudeSet->getBasisIndex(index)]);
171 }
172 
173 inline const double* Geometry::getCoordinates(int index) const{
174  return &(coordinates[dimensions*index]);
175 }
176 
177 inline const double* Geometry::getCoordinates() const{
178  return coordinates;
179 }
180 
181 inline int Geometry::getSpecifier(const Index &index, int specifier) const{
182  return specifiers[numSpecifiers*hoppingAmplitudeSet->getBasisIndex(index) + specifier];
183 }
184 
185 inline int Geometry::getSpecifier(int index, int specifier) const{
186  return specifiers[numSpecifiers*index + specifier];
187 }
188 
189 inline const int* Geometry::getSpecifiers(const Index& index) const{
190  return &(specifiers[numSpecifiers*hoppingAmplitudeSet->getBasisIndex(index)]);
191 }
192 
193 inline const int* Geometry::getSpecifiers(const int index) const{
194  return &(specifiers[numSpecifiers*index]);
195 }
196 
197 inline const int* Geometry::getSpecifiers() const{
198  return specifiers;
199 }
200 
201 inline double Geometry::getDistance(int index1, int index2) const{
202  double distanceSquared = 0.;
203  for(unsigned int n = 0; n < dimensions; n++){
204  double difference = coordinates[index1] - coordinates[index2];
205  distanceSquared += difference*difference;
206  }
207 
208  return sqrt(distanceSquared);
209 }
210 
211 inline int Geometry::getBasisSize() const{
212  return hoppingAmplitudeSet->getBasisSize();
213 }
214 
215 }; //End of namespace TBTK
216 
217 #endif
int getBasisSize() const
Definition: Geometry.h:211
const double * getCoordinates() const
Definition: Geometry.h:177
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
Geometry(int dimensions, int numSpecifiers, const HoppingAmplitudeSet *hoppingAmplitudeSet)
int getBasisSize() const
Definition: HoppingAmplitudeSet.h:310
Definition: Serializable.h:40
std::string serialize(Mode mode) const
void translate(std::initializer_list< double > translation)
const int * getSpecifiers() const
Definition: Geometry.h:197
HoppingAmplitude container.
int getDimensions() const
Definition: Geometry.h:161
virtual ~Geometry()
Definition: FileReader.h:50
void setCoordinates(const Index &index, std::initializer_list< double > coordinates, std::initializer_list< int > specifiers={})
Geometry & operator=(const Geometry &rhs)
int getBasisIndex(const Index &index) const
Definition: HoppingAmplitudeSet.h:302
int getNumSpecifiers() const
Definition: Geometry.h:165
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
double getDistance(const Index &index1, const Index &index2) const
Contains geometric information about a Model.
Definition: Geometry.h:35
Mode
Definition: Serializable.h:44
Abstract base class for serializable objects.
int getSpecifier(const Index &index, int specifier) const
Definition: Geometry.h:181