1#ifndef FOCK_VECTOR_DEFINED
2#define FOCK_VECTOR_DEFINED
19template <
typename F =
double>
63 const std::vector<std::string> &indices)
74 template <
typename TensorsIterator,
typename IndicesIterator>
76 TensorsIterator tensorsEnd,
77 IndicesIterator indicesBegin,
78 IndicesIterator indicesEnd)
140 get(i)->sum(+1.0, *a.
get(i), indices, 1.0, indices);
153 get(i)->sum(-1.0, *a.
get(i), indices, 1.0, indices);
165 get(i)->sum(s, *
get(i), indices, 0.0, indices);
180 std::vector<int> transposedLens(
get(i)->lens,
get(i)->lens + 2 * order);
181 std::rotate(transposedLens.begin(),
182 transposedLens.begin() + order,
183 transposedLens.begin() + 2 * order);
186 transposedLens.size(),
187 transposedLens.data(),
190 (std::string(
get(i)->get_name()) +
"*").c_str()));
193 CTF::Univar_Function<F> fConj(sisi4s::conj<F>);
194 result.
get(i)->sum(1.0,
210 CTF::Scalar<F> result;
213 const char *ketIndices(ket.
get_indices(i).c_str());
215 result[
""] += (*
get(i))[indices] * (*ket.
get(i))[ketIndices];
217 return result.get_val();
228 CTF::Scalar<F> result;
231 CTF::Bivar_Function<F> fDot(&sisi4s::dot<F>);
233 result.contract(1.0, *
get(i), indices, *a.
get(i), indices, 1.0,
"", fDot);
235 return result.get_val();
255 size_t get_index(
const size_t component,
const size_t componentIndex)
const {
256 size_t base(component > 0 ?
index_ends[component - 1] : 0);
257 return base + componentIndex;
267 size_t &componentIndex)
const {
277 componentIndex = index - base;
285 size_t elementsCount(0);
286 std::vector<std::pair<size_t, F>> elements;
288 size_t componentValuesCount;
291 get(i)->read_local(
reinterpret_cast<int64_t *
>(&componentValuesCount),
295 elements.resize(elementsCount + componentValuesCount);
296 for (
size_t k(0); k < componentValuesCount; ++k) {
299 elements[elementsCount + k].second = componentValues[k];
301 elementsCount += componentValuesCount;
303 free(componentValues);
312 void write(
const std::vector<std::pair<size_t, F>> &elements) {
317 for (
size_t k(0); k < elements.size(); ++k) {
319 size_t componentIndex;
320 fromIndex(elements[k].first, component, componentIndex);
322 tensorIndices[component].push_back(componentIndex);
323 tensorValues[component].push_back(elements[k].second);
328 tensorIndices[i].reserve(tensorIndices[i].size() + 1);
329 tensorValues[i].reserve(tensorIndices[i].size() + 1);
330 get(i)->write(tensorIndices[i].size(),
331 reinterpret_cast<int64_t *
>(tensorIndices[i].data()),
332 tensorValues[i].data());
352 size_t tensorIndexSize(1);
353 for (
int d(0); d <
get(i)->order; ++d) {
354 tensorIndexSize *=
get(i)->lens[d];
366 for (
size_t i(0); i < components.size(); ++i) {
379 size_t indexLens(a.
get(i)->order());
380 for (
size_t j(0); j < indexLens; j++) {
381 size_t indexPos(
get(i).find(a.getIndicies(i)[j]));
382 if (indexPos == std::string::npos) {
383 throw EXCEPTION(
"Indices of fock vectors do not match");
385 if (a.
get(i)->lens[j] !=
get(i)->lens[indexPos]) {
386 throw EXCEPTION(
"Shapes of component tensors does not match");
395 throw EXCEPTION(
"Number of component tensors does no match");
514 return stream <<
" )";
517template <
typename F,
int N,
int StartDimension = 0>
527 throw new EXCEPTION(
"FockVectorNdCanonical implemented only up to 6");
529 const std::string pindices(
"abcdefgABCDEFG");
530 const std::string hindices(
"ijklomnIJKLOMN");
531 for (
unsigned int i(StartDimension); i <= N / 2; i++) {
535 std::vector<int> syms(i, NS);
536 std::vector<int> dimso(i, No);
537 std::vector<int> dimsv(i, Nv);
538 std::vector<int> dims(dimsv);
539 dims.insert(dims.end(), dimso.begin(), dimso.end());
541 this->component_indices.push_back(pindices.substr(0, i)
542 + hindices.substr(0, i));
543 this->component_tensors.push_back(
558 this->component_tensors = a.component_tensors;
559 this->component_indices = a.component_indices;
560 this->index_ends.resize(a.component_tensors.size());
598 this->index_ends.resize(1);
599 this->component_tensors.resize(1);
605 this->component_indices = a.component_indices;
606 this->component_tensors = a.component_tensors;
607 this->index_ends.resize(1);
620 this->index_ends.resize(1);
621 this->component_tensors.resize(1);
640 this->index_ends.resize(2);
641 this->component_tensors.resize(2);
647 this->component_indices = a.component_indices;
648 this->component_tensors = a.component_tensors;
649 this->index_ends.resize(2);
662 this->index_ends.resize(2);
663 this->component_tensors.resize(2);
670 this->index_ends.resize(2);
671 this->component_tensors.resize(2);
687 this->component_tensors.resize(3);
688 this->component_indices.resize(3);
691 this->component_indices[2] =
"abcijk";
692 this->index_ends.resize(3);
695 int No(this->component_tensors[0]->lens[1]);
696 int Nv(this->component_tensors[0]->lens[0]);
697 int vvvooo[6] = {Nv, Nv, Nv, No, No, No};
698 int syms[6] = {NS, NS, NS, NS, NS, NS};
699 this->component_tensors[2] =
701 (*this->
get(2))[
"abcijk"] = 0.0;
707 this->component_tensors.resize(3);
708 this->component_indices.resize(3);
709 this->component_indices[0] = a.component_indices[0];
710 this->component_indices[1] = a.component_indices[1];
711 this->component_indices[2] =
"abcijk";
712 this->index_ends.resize(3);
714 this->component_tensors[0] = a.component_tensors[0];
715 this->component_tensors[1] = a.component_tensors[1];
717 int No(this->component_tensors[0]->lens[1]);
718 int Nv(this->component_tensors[0]->lens[0]);
719 int vvvooo[6] = {Nv, Nv, Nv, No, No, No};
720 int syms[6] = {NS, NS, NS, NS, NS, NS};
721 this->component_tensors[2] =
723 (*this->
get(2))[
"abcijk"] = 0.0;
729 this->component_tensors.resize(3);
730 this->component_indices.resize(3);
731 this->component_indices[0] = a.component_indices[0];
732 this->component_indices[1] = a.component_indices[1];
733 this->component_indices[2] =
"abcijk";
734 this->index_ends.resize(3);
736 this->component_tensors[0] = a.component_tensors[0];
737 this->component_tensors[1] = a.component_tensors[1];
739 int No(this->component_tensors[0]->lens[1]);
740 int Nv(this->component_tensors[0]->lens[0]);
741 int vvvooo[6] = {Nv, Nv, Nv, No, No, No};
742 int syms[6] = {NS, NS, NS, NS, NS, NS};
743 this->component_tensors[2] =
745 (*this->
get(2))[
"abcijk"] = 0.0;
754 this->component_tensors.resize(3);
755 this->component_indices.resize(3);
758 this->component_indices[2] =
"abcijk";
759 this->index_ends.resize(3);
762 int No(this->component_tensors[0]->lens[1]);
763 int Nv(this->component_tensors[0]->lens[0]);
764 int vvvooo[6] = {Nv, Nv, Nv, No, No, No};
765 int syms[6] = {NS, NS, NS, NS, NS, NS};
766 this->component_tensors[2] =
768 (*this->
get(2))[
"abcijk"] = 0.0;
#define EXCEPTION(message)
Definition Exception.hpp:8
std::ostream & operator<<(std::ostream &s, const FcidumpReader::FcidumpHeader &h)
Definition FcidumpWriter.cxx:25
#define NEW(TYPE,...)
Definition SharedPointer.hpp:10
#define PTR(TYPE)
Definition SharedPointer.hpp:8
Definition FockVector.hpp:518
FockVectorNdCanonical(const FockVector< F > &a)
Copy constructor copying the tensors owned by a.
Definition FockVector.hpp:568
FockVectorNdCanonical(const unsigned int No, const unsigned int Nv)
Build a canonical vector from No and Nv.
Definition FockVector.hpp:525
FockVectorNdCanonical(FockVector< F > &&a)
Move constructor taking possession of the tensors owned by a.
Definition FockVector.hpp:557
FockVectorNdCanonical()
Empty constructor.
Definition FockVector.hpp:552
Represents the direct sum of Tensors and provides the vector space operations of addition,...
Definition FockVector.hpp:26
F braket(const FockVector< F > &ket) const
Returns the matrix product of this bra-FockVector with the given dual ket-FockVector ket.
Definition FockVector.hpp:208
FockVector()
Default constructor for an empty Fock vector without elements.
Definition FockVector.hpp:36
std::vector< std::pair< size_t, F > > readLocal() const
Reads out all locally stored values together with their respective indices. The indices are between 0...
Definition FockVector.hpp:284
std::vector< std::shared_ptr< Tensor< F > > > component_tensors
Definition FockVector.hpp:30
FockVector(const std::vector< std::shared_ptr< Tensor< F > > > &tensors, const std::vector< std::string > &indices)
Move constructor taking possession of the tensors given.
Definition FockVector.hpp:62
F FieldType
Definition FockVector.hpp:28
FockVector< F > conjugateTranspose() const
Creates and returns the conjugate transpose of this FockVector. The first and the second half of the ...
Definition FockVector.hpp:176
void checkDualCompatibility(const FockVector< F > &a) const
Check if two FockVectors are transpose of each other by swapping the first and the second half of the...
Definition FockVector.hpp:376
FockVector(FockVector< F > &&a)
Move constructor taking possession of the tensors owned by a.
Definition FockVector.hpp:41
FockVector< F > & operator+=(const FockVector< F > &a)
Add-to assignment operator adding each component of a to the respective component of this FockVector.
Definition FockVector.hpp:136
void build_index_translation()
Definition FockVector.hpp:348
void checkCompatibilityTo(const FockVector< F > &a) const
Definition FockVector.hpp:392
FockVector< F > & operator-=(const FockVector< F > &a)
Subtract-from assignment operator subtracting each component of a from the respective component of th...
Definition FockVector.hpp:149
std::vector< std::string > component_indices
Definition FockVector.hpp:31
FockVector< F > & operator=(const FockVector< F > &&a)
Move assignment operator taking possession of the tensors owned by a.
Definition FockVector.hpp:115
F dot(const FockVector< F > &a) const
Returns the inner product of this ket-FockVector with the given ket-FockVector a. The elements of thi...
Definition FockVector.hpp:226
size_t get_dimension() const
Get the total number of degrees of freedom represented by this FockVector, i.e. the total number of f...
Definition FockVector.hpp:249
size_t get_index(const size_t component, const size_t componentIndex) const
Definition FockVector.hpp:255
FockVector(const FockVector< F > &a)
Copy constructor copying the tensors owned by a.
Definition FockVector.hpp:51
void fromIndex(const size_t index, size_t &component, size_t &componentIndex) const
Definition FockVector.hpp:265
std::string & get_indices(const size_t i)
Retrieves the i-th component indices as modifiable string.
Definition FockVector.hpp:109
std::vector< size_t > index_ends
The end of the FockVector index range for each component. This vector is used for translating compone...
Definition FockVector.hpp:342
const std::string & get_indices(const size_t i) const
Retrieves the i-th component indices.
Definition FockVector.hpp:102
std::shared_ptr< Tensor< F > > & get(const size_t i)
Retrieves the i-th component tensor.
Definition FockVector.hpp:97
FockVector< F > & operator=(const FockVector< F > &a)
Copy assignment operator copying the tensors owned by a.
Definition FockVector.hpp:125
void copy_components(const std::vector< std::shared_ptr< Tensor< F > > > &components)
Sets this FockVector's component tensors by copying the given component tensors. Called by copy const...
Definition FockVector.hpp:364
const std::shared_ptr< Tensor< F > > & get(const size_t i) const
Retrieves the i-th component tensor. Note that the Tensor is not const since rearrangement may be req...
Definition FockVector.hpp:90
size_t get_components_count() const
Get the number of component tensors of this FockVector.
Definition FockVector.hpp:241
void write(const std::vector< std::pair< size_t, F > > &elements)
Writes the given values together with their respective indices. The indices are between 0 and get_dim...
Definition FockVector.hpp:312
FockVector(TensorsIterator tensorsBegin, TensorsIterator tensorsEnd, IndicesIterator indicesBegin, IndicesIterator indicesEnd)
Move constructor taking possession of the tensors given by the iterators.
Definition FockVector.hpp:75
FockVector< F > & operator*=(const F s)
Multiply-by assignment operator scalar multiplying each component each component of this FockVector b...
Definition FockVector.hpp:162
Definition FockVector.hpp:631
SDFockVector< F > & operator=(const SDFockVector< F > &a)
Definition FockVector.hpp:653
SDFockVector()
Definition FockVector.hpp:635
SDFockVector(const SDTFockVector< F > &a)
Definition FockVector.hpp:668
SDFockVector(const SFockVector< F > &a)
Definition FockVector.hpp:660
SDFockVector(const SDFockVector< F > &a)
Definition FockVector.hpp:638
SDFockVector(SDFockVector< F > &&a)
Definition FockVector.hpp:646
Definition FockVector.hpp:678
SDTFockVector< F > & operator=(SDFockVector< F > &&a)
Definition FockVector.hpp:728
SDTFockVector()
Definition FockVector.hpp:682
SDTFockVector(const SDFockVector< F > &a)
Definition FockVector.hpp:685
SDTFockVector(const SDFockVector< F > &&a)
Definition FockVector.hpp:706
SDTFockVector< F > & operator=(const SDFockVector< F > &a)
Definition FockVector.hpp:752
Definition FockVector.hpp:589
SFockVector(const SFockVector< F > &a)
Definition FockVector.hpp:596
SFockVector()
Definition FockVector.hpp:593
SFockVector< F > & operator=(const SFockVector< F > &a)
Definition FockVector.hpp:611
SFockVector(SFockVector< F > &&a)
Definition FockVector.hpp:604
SFockVector(const SDFockVector< F > &a)
Definition FockVector.hpp:618
static CTF::World * world
Definition Sisi4s.hpp:17
Definition Algorithm.hpp:10
CTF::Tensor< F > Tensor
Definition Tensor.hpp:9
FockVector< F > operator+(const FockVector< F > &a, const FockVector< F > &b)
Returns the sum of two FockVectors a and b, where neither a nor b are modified.
Definition FockVector.hpp:406
std::string operator*(const std::string &s, const sisi4s::Permutation< N > &pi)
Definition CcsdPerturbativeTriples.cxx:24
FockVector< F > operator-(const FockVector< F > &a, const FockVector< F > &b)
Returns the difference between two FockVectors a and b, where neither a nor b are modified.
Definition FockVector.hpp:435