Chombo + EB + MF  3.2
MultiIndexImplem.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _MULTIINDEXIMPLEM_H_
12 #define _MULTIINDEXIMPLEM_H_
13 
14 #include "NamespaceHeader.H"
15 
16 // Generate and return a vector of all multi-indices whose magnitude (the sum
17 // of their entries) equals "a_magnitude"
18 template <int dim> void generateMultiIndices(Vector<IndexTM<int,dim> > & a_indices,
19  const int & a_magnitude)
20 {
21  if (a_magnitude >= 0)
22  {
23  IndexTM<int,dim> monomial;
24 
25  for (int idir = 0; idir < dim; ++ idir)
26  {
27  monomial[idir] = 0;
28  }
29 
30  while (true)
31  {
32  for (int j = 1; j < dim-1; ++j)
33  {
34  int t = a_magnitude;
35  for (int k = j+1; k < dim; ++k)
36  {
37  t -= monomial[k];
38  }
39 
40  if (monomial[j] > t)
41  {
42  monomial[j+1] += 1;
43  monomial[j] = 0;
44  }
45  else
46  {
47  break;
48  }
49  }
50 
51  if (monomial[dim-1] > a_magnitude)
52  {
53  break;
54  }
55 
56  monomial[0] = a_magnitude;
57 
58  for (int j = 1; j < dim; ++j)
59  {
60  monomial[0] -= monomial[j];
61  }
62 
63  a_indices.push_back(monomial);
64 
65  monomial[1] += 1;
66  }
67  }
68 }
69 
70 #include "NamespaceFooter.H"
71 
72 #endif
one dimensional dynamic array
Definition: Vector.H:53
Definition: IndexTM.H:36
void generateMultiIndices(Vector< IndexTM< int, dim > > &a_indices, const int &a_magnitude)
Definition: MultiIndexImplem.H:18
int dim
Definition: EBInterface.H:146