Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
StarsAndBars.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_StarsAndBars_H_
9#define model_StarsAndBars_H_
10
11#include <Eigen/Dense>
13
14namespace model
15{
16 /**************************************************************************/
17 /**************************************************************************/
22 template <int N, int k,int j=0>
24 {
25 static_assert(N>0,"N MUST BE >0.");
26 static_assert(k>0,"k MUST BE >0.");
27 static_assert(j>=0,"j MUST BE >0.");
28 static_assert(j<k,"j MUST BE <k.");
29
30// static constexpr int N=_N; // number of positive integers
31// static constexpr int k=_k; // value of the sum of the N integers
32// static constexpr int j=_j; // value of the sum of the N integers
33 static constexpr int r1=CombinationWithRepetition<N,k-j-1>::value;
34 static constexpr int r2=CombinationWithRepetition<N-1,k-j>::value;
35
36 static Eigen::Matrix<int,r1+r2,N> sAb()
37 {
41 return (Eigen::Matrix<int,r1+r2,N>() << (StarsAndBars<N,k,j+1>::sAb()),
42 (Eigen::Matrix<int,N,r2>() << Eigen::Matrix<int,1,r2>().Constant(j),
43 StarsAndBars<N-1,k-j,0>::sAb().transpose()).finished().transpose()).finished();
44 }
45
46 };
47
48
49 /**************************************************************************/
50 /**************************************************************************/
51 // End recursion in j at j=k
52 template <int N, int k>
53 struct StarsAndBars<N,k,k>
54 {
55 static_assert(N>0,"N MUST BE >0.");
56// static constexpr int N=_N;
57// static constexpr int k=_k;
58// static constexpr int j=_k;
59 static constexpr int r=CombinationWithRepetition<N-1,k-k>::value; // this is = 1, since C(n,0)=1
60
61 static Eigen::Matrix<int,r,N> sAb()
62 {
63 Eigen::Matrix<int,r,N> temp;
65 return temp;
66 }
67 };
68
69 /**************************************************************************/
70 /**************************************************************************/
71 // End recursion in k at k=0, (which implies j=0)
72 template <int N>
73 struct StarsAndBars<N,0,0>
74 {
75 static_assert(N>0,"N MUST BE >0.");
76// static constexpr int N=_N;
77// static constexpr int k=0;
78// static constexpr int j=k;
79 static constexpr int r=CombinationWithRepetition<N,0>::value; // this is = 1, since C(n,0)=1
80
81 static Eigen::Matrix<int,r,N> sAb() // this is an 1xN matrix
82 {
83 return Eigen::Matrix<int,r,N>::Zero();
84 }
85 };
86
87 /**************************************************************************/
88 /**************************************************************************/
89 // End recursion in n at n=1
90 template <int k,int j>
91 struct StarsAndBars<1,k,j>
92 {
93 static_assert(k>0,"k MUST BE >0.");
94// static constexpr int N=1;
95 static constexpr int r=CombinationWithRepetition<1,k-j>::value; // this is = 1, since C(1,k-j)=1
96
97 static Eigen::Matrix<int,r,1> sAb() // this is a 1x1 matrix
98 {
99 return Eigen::Matrix<int,r,1>::Constant(k-j);
100 }
101 };
102
103 /**************************************************************************/
104 /**************************************************************************/
105 // Template Specialization Case <1,k,k>
106 template <int k>
107 struct StarsAndBars<1,k,k>
108 {
109 static_assert(k>0,"k MUST BE >0.");
110// static constexpr int N=1;
111// static constexpr int j=k;
112 static constexpr int r=CombinationWithRepetition<1,0>::value; // this is = 1, since C(1,k-j)=1
113
114 static Eigen::Matrix<int,r,1> sAb() // this is a 1x1 matrix
115 {
116 return Eigen::Matrix<int,r,1>::Constant(0);
117 }
118 };
119
120 /**************************************************************************/
121 /**************************************************************************/
122 // Template Specialization Case <1,0,0>
123 template <>
124 struct StarsAndBars<1,0,0>
125 {
126// static constexpr int N=1;
127// static constexpr int k=0;
128// static constexpr int j=k;
129 static constexpr int r=CombinationWithRepetition<1,0>::value; // this is = 1, since C(1,0)=1
130
131 static Eigen::Matrix<int,r,1> sAb() // this is a 1x1 matrix
132 {
133 return Eigen::Matrix<int,r,1>::Constant(0);
134 }
135
136 };
137}
138#endif
static Eigen::Matrix< int, r, 1 > sAb()
static Eigen::Matrix< int, r, 1 > sAb()
static Eigen::Matrix< int, r, 1 > sAb()
static Eigen::Matrix< int, r, N > sAb()
static Eigen::Matrix< int, r, N > sAb()
static Eigen::Matrix< int, r1+r2, N > sAb()
static constexpr int r1
static constexpr int r2
int j
int k
vertex temp