Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
PermutationWithoutRepetition.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_PERMUTATIONWITHOUTREPETITION_H_
9#define model_PERMUTATIONWITHOUTREPETITION_H_
10
11//#include <Factorial.h>
12//#include <Pow.h>
13#include <CTM.h>
14
15namespace model
16{
17
18
19
20 /**************************************************************************/
21 /**************************************************************************/
22 template <int k>
24 {
25 // enum{value=Factorial<N>::value / Factorial<(k>=0 && k<=N && N>=0)?(N-k):0>::value * (k>=0 && k<=N && N>=0)};
26 static constexpr int value(int N)
27 {
28 return CTM::factorial(N) / CTM::factorial((k>=0 && k<=N && N>=0)?(N-k):0) * (k>=0 && k<=N && N>=0);
29 }
30
31 template <typename T,int M>
32 static Eigen::Matrix<T,1,M-1> reducePool(const Eigen::Matrix<T,1,M>& pool,const int& p)
33 {
34 Eigen::Matrix<T,1,M-1> temp;
35 int n=0;
36 for (int i=0;i<M;++i)
37 {
38 if(i!=p)
39 {
40 temp(n)=pool(i);
41 n++;
42 }
43 }
44 return temp;
45 }
46
47 template<typename T,int N>
48 static Eigen::Matrix<T,k,value(N)> permute(const Eigen::Matrix<T,N,1>& pool)
49 {
50 return permute(pool.transpose().eval());
51 }
52
53
54 template<typename T,int N>
55 static Eigen::Matrix<T,k,value(N)> permute(const Eigen::Matrix<T,1,N>& pool)
56 {
57 assert(N>=k);
58
59
60 Eigen::Matrix<T,k,value(N)> temp1;
62 for(size_t p=0;p<N;++p)
63 {
64 temp1.template block< 1,c>(0,p*c)=Eigen::Matrix<T,1,c>::Constant(pool(p));
65 temp1.template block<k-1,c>(1,p*c)=PermutationWithoutRepetition<k-1>::permute(reducePool(pool,p));
66 }
67
68 return temp1;
69 }
70
71
72 template<typename T,int N>
73 static Eigen::Matrix<T,k,value(N)*CTM::pow(2,k)> permuteWithPlusMinusSign(const Eigen::Matrix<T,N,1>& pool)
74 {
75 return permuteWithPlusMinusSign(pool.transpose().eval());
76 }
77
78 template<typename T,int N>
79 static Eigen::Matrix<T,k,value(N)*CTM::pow(2,k)> permuteWithPlusMinusSign(const Eigen::Matrix<T,1,N>& pool)
80 {
81 assert(N>=k);
82
83
84 Eigen::Matrix<T,k,value(N)*CTM::pow(2,k)> temp1;
86 for(size_t p=0;p<N;++p)
87 {
88 temp1.template block< 1,c>(0,(2*p+0)*c)=Eigen::Matrix<T,1,c>::Constant( pool(p));
89 temp1.template block< 1,c>(0,(2*p+1)*c)=Eigen::Matrix<T,1,c>::Constant(-pool(p));
90
92 temp1.template block<k-1,c>(1,(2*p+0)*c)=temp;
93 temp1.template block<k-1,c>(1,(2*p+1)*c)=temp;
94 // std::cout<<<<std::endl;
95 }
96
97 return temp1;
98 }
99
100 };
101
102 /**************************************************************************/
103 /**************************************************************************/
104 template <>
106 {
107 static constexpr int k=1;
108 // enum{value=Factorial<N>::value / Factorial<(k>=0 && k<=N && N>=0)?(N-k):0>::value * (k>=0 && k<=N && N>=0)};
109 static constexpr int value(int N)
110 {
111 return CTM::factorial(N) / CTM::factorial((k>=0 && k<=N && N>=0)?(N-k):0) * (k>=0 && k<=N && N>=0);
112 }
113
114
115
116 template<typename T,int N>
117 static const Eigen::Matrix<T,k,value(N)>& permute(const Eigen::Matrix<T,1,N>& pool)
118 {
119 assert(N>=k);
120 return pool;
121 }
122
123 template<typename T,int N>
124 static const Eigen::Matrix<T,k,2*N> permuteWithPlusMinusSign(const Eigen::Matrix<T,1,N>& pool)
125 {
126 return (Eigen::Matrix<T,k,2*N>()<<pool,-pool).finished();
127 }
128
129 };
130
131}
132#endif
Eigen::Matrix3d M
c
Definition int_R.m:15
static constexpr int pow(int x, int n)
A compile-time implementation of the power function.
Definition CTM.h:40
static constexpr int factorial(int n)
Definition CTM.h:26
static const Eigen::Matrix< T, k, 2 *N > permuteWithPlusMinusSign(const Eigen::Matrix< T, 1, N > &pool)
static const Eigen::Matrix< T, k, value(N)> & permute(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, k, value(N) *CTM::pow(2, k)> permuteWithPlusMinusSign(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, k, value(N)> permute(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, k, value(N) *CTM::pow(2, k)> permuteWithPlusMinusSign(const Eigen::Matrix< T, N, 1 > &pool)
static Eigen::Matrix< T, 1, M-1 > reducePool(const Eigen::Matrix< T, 1, M > &pool, const int &p)
static Eigen::Matrix< T, k, value(N)> permute(const Eigen::Matrix< T, N, 1 > &pool)
vertex p[3]
int k
int i
vertex temp