24 #ifndef COM_DAFER45_TBTK_ARRAY_STATE
25 #define COM_DAFER45_TBTK_ARRAY_STATE
27 #include "TBTK/AbstractState.h"
28 #include "TBTK/DefaultOperator.h"
36 class ArrayState :
public AbstractState{
40 std::initializer_list<unsigned int> resolution
44 virtual ~ArrayState();
47 virtual ArrayState* clone()
const;
50 virtual std::complex<double> getOverlap(
const AbstractState &bra)
const;
53 virtual std::complex<double> getMatrixElement(
54 const AbstractState &bra,
55 const AbstractOperator &o = DefaultOperator()
60 std::complex<double> amplitude,
61 std::initializer_list<unsigned int> element
66 std::complex<double> amplitude,
67 const std::vector<unsigned int> &element
72 std::complex<double> amplitude,
77 const std::complex<double>& getAmplitude(
78 std::initializer_list<unsigned int> element
82 const std::complex<double>& getAmplitude(
83 const std::vector<unsigned int> &element
87 const std::complex<double>& getAmplitude(
92 const std::vector<unsigned int>& getResolution()
const;
97 Storage(std::initializer_list<unsigned int> resolution);
111 std::complex<double> value,
112 std::initializer_list<unsigned int> element
117 std::complex<double> value,
118 const std::vector<unsigned int> &element
123 std::complex<double> value,
128 const std::complex<double>& getElement(
129 std::initializer_list<unsigned int> element
133 const std::complex<double>& getElement(
134 const std::vector<unsigned int> &element
138 const std::complex<double>& getElement(
143 const std::vector<unsigned int>& getResolution()
const;
146 unsigned int referenceCounter;
149 std::complex<double> *data;
152 std::vector<unsigned int> resolution;
158 inline void ArrayState::Storage::grab(){
162 inline bool ArrayState::Storage::release(){
164 if(referenceCounter == 0)
170 inline void ArrayState::setAmplitude(
171 std::complex<double> amplitude,
172 std::initializer_list<unsigned int> element
174 storage->setElement(amplitude, element);
177 inline void ArrayState::setAmplitude(
178 std::complex<double> amplitude,
179 const std::vector<unsigned int> &element
181 storage->setElement(amplitude, element);
184 inline void ArrayState::setAmplitude(
185 std::complex<double> amplitude,
188 storage->setElement(amplitude, element);
191 inline const std::complex<double>& ArrayState::getAmplitude(
192 std::initializer_list<unsigned int> element
194 return storage->getElement(element);
197 inline const std::complex<double>& ArrayState::getAmplitude(
198 const std::vector<unsigned int> &element
200 return storage->getElement(element);
203 inline const std::complex<double>& ArrayState::getAmplitude(
206 return storage->getElement(element);
209 inline const std::vector<unsigned int>& ArrayState::getResolution()
const{
210 return storage->getResolution();
213 inline void ArrayState::Storage::setElement(
214 std::complex<double> value,
215 std::initializer_list<unsigned int> element
217 unsigned int x = *(element.begin() + 0);
218 unsigned int y = *(element.begin() + 1);
219 unsigned int z = *(element.begin() + 2);
220 data[resolution[2]*(resolution[1]*x + y) + z] = value;
223 inline void ArrayState::Storage::setElement(
224 std::complex<double> value,
225 const std::vector<unsigned int> &element
227 unsigned int x = element.at(0);
228 unsigned int y = element.at(1);
229 unsigned int z = element.at(2);
230 data[resolution[2]*(resolution[1]*x + y) + z] = value;
233 inline void ArrayState::Storage::setElement(
234 std::complex<double> value,
237 unsigned int x = element.at(0);
238 unsigned int y = element.at(1);
239 unsigned int z = element.at(2);
240 data[resolution[2]*(resolution[1]*x + y) + z] = value;
243 inline const std::complex<double>& ArrayState::Storage::getElement(
244 std::initializer_list<unsigned int> element
246 unsigned int x = *(element.begin() + 0);
247 unsigned int y = *(element.begin() + 1);
248 unsigned int z = *(element.begin() + 2);
249 return data[resolution[2]*(resolution[1]*x + y) + z];
252 inline const std::complex<double>& ArrayState::Storage::getElement(
253 const std::vector<unsigned int> &element
255 unsigned int x = element.at(0);
256 unsigned int y = element.at(1);
257 unsigned int z = element.at(2);
258 return data[resolution[2]*(resolution[1]*x + y) + z];
261 inline const std::complex<double>& ArrayState::Storage::getElement(
264 unsigned int x = element.at(0);
265 unsigned int y = element.at(1);
266 unsigned int z = element.at(2);
267 return data[resolution[2]*(resolution[1]*x + y) + z];
270 inline const std::vector<unsigned int>& ArrayState::Storage::getResolution()
const{