chombo-discharge
CD_MultiIndex.H
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_MultiIndex_H
13 #define CD_MultiIndex_H
14 
15 // Std includes
16 #include <map>
17 
18 // Chombo includes
19 #include <IntVect.H>
20 #include <RealVect.H>
21 
22 // Our includes
23 #include <CD_NamespaceHeader.H>
24 
30 {
31 public:
35  MultiIndex() = delete;
36 
40  MultiIndex(const MultiIndex& a_index) = default;
41 
46  MultiIndex(const int a_order);
47 
51  ~MultiIndex() = default;
52 
56  void
57  define(const int a_order);
58 
62  int
63  factorial() const;
64 
68  IntVect
69  getCurrentIndex() const;
70 
74  int
75  getOrder() const;
76 
80  int
81  getLinearIndex(const IntVect a_MultiIndex) const;
82 
86  IntVect
87  getMultiIndex(const int a_linearIndex) const;
88 
92  MultiIndex&
93  operator=(const MultiIndex& a_other) = default;
94 
98  int
99  operator[](const int a_dir) const;
100 
104  void
105  operator++();
106 
110  void
111  reset();
112 
116  bool
117  ok() const;
118 
123  int
124  norm() const;
125 
129  int
130  getNumIndices() const;
131 
135  Real
136  pow(const RealVect& a_vec);
137 
138 protected:
142  int m_order;
143 
147  IntVect m_curIndex;
148 
152  std::vector<IntVect>::iterator m_iter;
153 
157  std::vector<IntVect> m_indices;
158 
162  std::map<IntVect, int> m_mapToLinearIndex;
163 
167  std::map<int, IntVect> m_mapToMultiIndex;
168 
172  int
173  factorial(const int a_n) const;
174 
178  void
179  makeIndices();
180 
184  void
185  makeMaps();
186 
187 private:
191  int
192  norm(const IntVect a_index) const;
193 };
194 
195 #include <CD_NamespaceFooter.H>
196 
197 #endif
SpaceDim multi-index type for use with higher order Taylor series.
Definition: CD_MultiIndex.H:30
void operator++()
Increment multi-index lexigraphically.
Definition: CD_MultiIndex.cpp:151
void makeMaps()
Fill maps.
Definition: CD_MultiIndex.cpp:194
MultiIndex()=delete
Weak construction is bad.
int factorial() const
Factorial function.
Definition: CD_MultiIndex.cpp:110
int norm() const
Get norm of multi-index.
Definition: CD_MultiIndex.cpp:121
std::vector< IntVect >::iterator m_iter
Pointer to index.
Definition: CD_MultiIndex.H:152
void makeIndices()
Fill m_indices.
Definition: CD_MultiIndex.cpp:157
IntVect m_curIndex
Current idnex.
Definition: CD_MultiIndex.H:147
void reset()
Reset multi-index to point to the first index.
Definition: CD_MultiIndex.cpp:33
IntVect getCurrentIndex() const
Get index.
Definition: CD_MultiIndex.cpp:39
~MultiIndex()=default
Destructor.
int m_order
Maximum order representable by this multi-index.
Definition: CD_MultiIndex.H:142
int operator[](const int a_dir) const
Get one index.
Definition: CD_MultiIndex.cpp:87
IntVect getMultiIndex(const int a_linearIndex) const
Get a multi-index corresponding to the linear index (i.e. column number)
Definition: CD_MultiIndex.cpp:72
MultiIndex(const MultiIndex &a_index)=default
Copy constructor.
std::map< int, IntVect > m_mapToMultiIndex
Map going from linear index to multi-index.
Definition: CD_MultiIndex.H:167
MultiIndex & operator=(const MultiIndex &a_other)=default
Assignment operator.
bool ok() const
Check that multi-index is ok.
Definition: CD_MultiIndex.cpp:93
std::map< IntVect, int > m_mapToLinearIndex
Map for going from lexigraphically ordered multi-index to linear index.
Definition: CD_MultiIndex.H:162
int getLinearIndex(const IntVect a_MultiIndex) const
Get the linear index (i.e. column number) for a given multi-index.
Definition: CD_MultiIndex.cpp:57
int getOrder() const
Get highest order for this index.
Definition: CD_MultiIndex.cpp:45
void define(const int a_order)
Define function.
Definition: CD_MultiIndex.cpp:22
std::vector< IntVect > m_indices
All indices.
Definition: CD_MultiIndex.H:157
Real pow(const RealVect &a_vec)
Power function for multi-indices.
Definition: CD_MultiIndex.cpp:138
int getNumIndices() const
Return number of indices in MultiIndex range.
Definition: CD_MultiIndex.cpp:51