Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
CombinationWithRepetition.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_CombinationWithRepetition_H_
9#define model_CombinationWithRepetition_H_
10
11#include <Eigen/Dense>
12#include <CTM.h>
13
14namespace model
15{
16
17 /**************************************************************************/
18 /**************************************************************************/
25 template <int _N, int _k>
27 {
28 static constexpr int N=_N;
29 static constexpr int k=_k;
30 static_assert(N>0,"N MUST BE >0.");
31 static_assert(k>0,"k MUST BE >0.");
32 static constexpr int value=CTM::binomial(N+k-1,k);
33
34
35 template <typename T>
36 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
37 {
40 Eigen::Matrix<T,value,k> temp;
41// // Use Pascal rule to fill the combinations: bin(N,k) = bin(n-1,k-1) + bin(n-1,k)
42 temp<<(Eigen::Matrix<T,k,CTM::binomial(N+k-2,k-1)>() << Eigen::Matrix<T,1,CTM::binomial(N+k-2,k-1)>().Constant(pool(0)),
43 CombinationWithRepetition<N,k-1>::template combine<T>(pool).transpose()).finished().transpose(),
44 CombinationWithRepetition<N-1,k>::template combine<T>(pool.template segment<N-1>(1));
45
46 return temp;
47
48 }
49
50 };
51
52 /**************************************************************************/
53 /**************************************************************************/
54 // End recursion in n at n=1
55 template <int k>
57 {
58
59 static_assert(k>0,"k MUST BE >0.");
60 static constexpr int N=1;
61 static constexpr int value=CTM::binomial(N+k-1,k);
62
63
64 template <typename T>
65 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
66 {
68 return Eigen::Matrix<T,value,k>::Constant(pool(N-1));
69 }
70
71 };
72
73 /**************************************************************************/
74 /**************************************************************************/
75 // End recursion in k at k=1
76 template <int _N>
78 {
79
80 static constexpr int N=_N;
81 static_assert(N>0,"N MUST BE >0.");
82 static constexpr int k=1;
83 static constexpr int value=CTM::binomial(N+k-1,k);
84
85 template <typename T>
86 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
87 {
89 return pool;
90 }
91
92 };
93
94 /**************************************************************************/
95 /**************************************************************************/
96 // Case N=1, k=1
97 template <>
99 {
100 static constexpr int N=1;
101 static constexpr int k=1;
102 static constexpr int value=CTM::binomial(N+k-1,k);
103
104 template <typename T>
105 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
106 {
108 return pool;
109 }
110
111 };
112
113 /**************************************************************************/
114 /**************************************************************************/
115 // Case k=0
116 template <int _N>
118 {
119 static constexpr int N=_N;
120 static_assert(N>0,"N MUST BE >0.");
121 static constexpr int k=0;
122 static constexpr int value=CTM::binomial(N+k-1,k);
123
124// template <typename T>
125// static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
126// {/*!@param[in] pool a row vector of N values
127// */
128// return pool;
129// }
130
131 };
132
133 /**************************************************************************/
134 /**************************************************************************/
135 // Case N=1, k=0
136 template <>
138 {
139
140 static constexpr int N=1;
141// static_assert(N>0,"N MUST BE >0.");
142 static constexpr int k=0;
143 static constexpr int value=CTM::binomial(N+k-1,k);
144
145 // template <typename T>
146 // static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
147 // {/*!@param[in] pool a row vector of N values
148 // */
149 // return pool;
150 // }
151
152 };
153
154}
155#endif
static constexpr int binomial(int N, int k)
Definition CTM.h:20
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
vertex temp
INEXACT REAL _k