Documentation of CSL
index.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef INDEX_H_INCLUDED
24 #define INDEX_H_INCLUDED
25 
26 #include <string>
27 #include <string_view>
28 #include <vector>
29 #include <map>
31 
32 namespace csl {
33  class Space;
34 }
35 
41 namespace cslIndex{
42 
48  enum Type{
49 
50  Free,
53  };
54 
60  enum TensorType{
61 
62  Generic,
65  };
66 }
67 
68 namespace csl {
69 
75 class Index{
76 
77  public:
78 
79  using ID_type = unsigned int;
80 
81  private:
82 
86  const Space* space = nullptr;
87 
88  ID_type id;
89 
93  char nameOrValue;
94 
98  char type;
99 
100  public:
101 
105  Index();
106 
112  explicit Index(const std::string& t_name,
113  unsigned short t_id = 0);
114 
115  Index(char value);
116 
122  Index(const Index& index) = default;
123 
130  Index(const std::string& t_name,\
131  const Space* t_space,
132  unsigned short t_id = 0);
133 
137  ~Index(){};
138 
139  std::string_view getName() const;
140 
141  std::string getIndexCodeName() const;
142 
143  inline ID_type getID() const {
144  return id;
145  }
146 
151  inline char getValue() const {
152  return nameOrValue;
153  }
154 
158  bool getSign() const {
159  return nameOrValue >= 0;
160  }
161 
166  inline bool getFree() const {
167  return type == 0;
168  }
169 
173  inline cslIndex::Type getType() const {
174  return static_cast<cslIndex::Type>(type);
175  }
176 
180  int getMax() const;
181 
185  inline const Space* getSpace() const {
186  return space;
187  }
188 
189  Index rename() const;
190 
195  Index getFlipped() const;
196 
200  void setName(const std::string& t_name);
201 
202  void setID(ID_type t_id);
203 
208  void setSpace(const Space* t_space);
209 
215  void setValue(char t_value);
216 
220  void setSign(bool t_sign);
221 
222  void flipSign();
223 
228  void setFree(bool t_free);
229 
233  void setType(cslIndex::Type t_type);
234 
244  bool testContraction(const Index& t_index) const;
245 
249  void print() const;
250 
255  std::string printLaTeX() const;
256 
257  void printDefinition(
258  std::ostream &out,
259  int indentSize
260  ) const;
261 
269  Index& operator=(const Index& index) = default;
270 
276  Index& operator=(int t_value);
277 
288  bool compareWithDummy(const Index& t_index) const;
289 
300  bool compareWithoutSign(const Index& t_index) const;
301 
310  bool exactMatch(const Index& t_index) const;
311 
312  Index& operator++();
313 
314  Index operator++(int);
315 
327  bool operator==(const Index& t_index) const;
328 
329 
341  bool operator==(int value) const;
342 
354  bool operator==(size_t value) const;
355 
363  bool operator!=(const Index& t_index) const;
364 
365  bool operator!=(int value) const;
366 
367  bool operator!=(size_t value) const;
368 
376  bool operator|=(const Index& index) const;
377 
385  bool operator&=(const Index& index) const;
386 
394  bool operator<(const Index& index) const;
395 
403  bool operator>(const Index& index) const;
404 
412  bool operator<=(const Index& index) const;
413 
421  bool operator>=(const Index& index) const;
422 
431  friend std::ostream& operator<<(std::ostream& fout, const Index& index);
432 };
433 
434 std::vector<Index> integerToIndices(const std::vector<int>& indices);
435 
445 Index operator!(const Index& index);
446 
455 Index operator+(const Index& index);
456 
465 Index operator-(const Index& index);
466 
473 
474  IMPLEMENTS_STD_VECTOR_NO_OP(Index, index)
475 
476  private:
477 
482  std::vector<Index> index;
483 
484  public:
485 
489  IndexStructure();
490 
496  explicit IndexStructure(int t_nIndices);
497 
503  IndexStructure(const IndexStructure& structure);
504 
505  IndexStructure(IndexStructure&&) = default;
506 
507  IndexStructure& operator=(IndexStructure&&) = default;
508 
515  explicit IndexStructure(const std::initializer_list<Index>& structure);
516 
524  explicit IndexStructure(const std::vector<Index>& structure);
525 
530 
534  std::vector<Index> const &getIndex() const;
535 
536  const std::vector<Index>& getIndexView() const;
537 
541  std::vector<Index>& getIndex();
542 
543 
552  std::vector<Index>::const_iterator find(const Index& t_index) const;
553 
554  std::vector<Index>::iterator find(const Index& t_index);
555 
559  IndexStructure getFreeStructure() const;
560 
565  IndexStructure getSinglePermutation(int i1, int i2) const;
566 
574  IndexStructure getPermutation(const std::vector<int>& permutation) const;
575 
583  void setIndex(const Index& newIndex, int iIndex=0);
584 
585  void reset();
586 
594  IndexStructure& operator=(const IndexStructure& structure) = default;
595 
603  IndexStructure& operator+=(const Index& newIndex);
604 
613  IndexStructure& operator+=(const IndexStructure& structure);
614 
615  IndexStructure operator+(const csl::Index& index) const;
616 
625  IndexStructure operator+(const IndexStructure& structure) const;
626 
627  bool hasCommonIndex(csl::IndexStructure const &other) const;
628 
639  bool exactMatch(const IndexStructure& structure) const;
640 
651  bool compareWithDummy(const IndexStructure& structure) const;
652 
671  bool compareWithDummy(const IndexStructure& structure,
672  std::map<Index,Index>& constraints,
673  bool keepAllCosntraints = false) const;
674 
686  bool operator==(const IndexStructure& structure) const;
687 
695  bool operator!=(const IndexStructure& structure) const;
696 
705  bool operator|=(const IndexStructure& structure) const;
706 
715  bool operator&=(const IndexStructure& structure) const;
716 
725  bool operator<(const IndexStructure& structure) const;
726 
735  bool operator>(const IndexStructure& structure) const;
736 
745  bool operator<=(const IndexStructure& structure) const;
746 
755  bool operator>=(const IndexStructure& structure) const;
756 
764  Index operator[](int i) const;
765 
773  Index& operator[](int i);
774 
783  friend std::ostream& operator<<(std::ostream& fout,
784  const IndexStructure& structure);
785 };
786 
788 // Inline functions
789 
791 inline IndexStructure::IndexStructure(int t_nIndices)
792  : index(std::vector<Index>(t_nIndices,Index())){}
794  index(t_index.index){}
795 inline IndexStructure::IndexStructure(const std::initializer_list<Index>& t_index):
796  IndexStructure(std::vector<Index>(t_index)){}
798 
799 
800 } // End of namespace csl
801 
802 #endif
Definition: index.h:63
TensorType
Type of TensorElement.
Definition: index.h:60
Namespace for csl library.
Definition: abreviation.h:34
char getValue() const
Definition: index.h:151
Index operator!(const Index &index)
operator!, unary operator on Index that change the free property of the Index.
Definition: index.cpp:378
bool operator &=(const Expr &a, const Expr &b)
see Abstract::operator&=()
Index object that is used for indicial objects.
Definition: index.h:75
bool operator<=(const Expr &a, const Expr &b)
see Abstract::operator<=()
Definition: abstract.cpp:1416
Definition: index.h:51
Definition: diagonalization.h:32
Expr operator+(const Expr &a, const Expr &b)
Shortcut function that allows to use arithmetic operator + with Expr (== shared_ptr<Abstract>).
Definition: abstract.cpp:1298
bool getFree() const
Definition: index.h:166
bool operator|=(const Expr &a, const Expr &b)
see Abstract::operator|=()
bool operator>(const Expr &a, const Expr &b)
see Abstract::operator>()
Definition: abstract.cpp:1419
bool operator>=(const Expr &a, const Expr &b)
see Abstract::operator>=()
Definition: abstract.cpp:1413
cslIndex::Type getType() const
Definition: index.h:173
bool getSign() const
Definition: index.h:158
Definition: index.h:64
Definition: index.h:52
~IndexStructure()
Destructor.
Definition: index.h:529
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
bool operator==(const Expr &a, const Expr &b)
see Abstract::operator==()
Definition: abstract.cpp:1398
Definition: index.h:50
Encapsulate types of indices and tensor in a small namespace.
~Index()
Destructor.
Definition: index.h:137
Type
Definition: index.h:48
const Space * getSpace() const
Definition: index.h:185
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
bool operator!=(const Expr &a, const Expr &b)
see Abstract::operator!=()
Definition: abstract.cpp:1404
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
IndexStructure()
Default constructor, empty structure.
Definition: index.h:790