mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 12:47:05 +01:00
Lattice matrix exponential ok
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
#ifndef GRID_MATH_TA_H
|
||||
#define GRID_MATH_TA_H
|
||||
|
||||
|
||||
namespace Grid {
|
||||
|
||||
///////////////////////////////////////////////
|
||||
@ -36,7 +38,8 @@ namespace Grid {
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// ProjectOnGroup function for scalar, vector, matrix
|
||||
// ProjectOnGroup function for scalar, vector, matrix
|
||||
// Projects on orthogonal, unitary group
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -59,22 +62,23 @@ namespace Grid {
|
||||
{
|
||||
// need a check for the group type?
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
double nrm;
|
||||
RealD nrm;
|
||||
vtype inner;
|
||||
for(int c1=0;c1<N;c1++){
|
||||
nrm = 0.0;
|
||||
zeroit(inner);
|
||||
for(int c2=0;c2<N;c2++)
|
||||
nrm += real(innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]));
|
||||
nrm = 1.0/sqrt(nrm);
|
||||
std::cout << "norm : "<< nrm << "\n";
|
||||
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
|
||||
|
||||
nrm = 1.0/sqrt(Reduce(toReal(inner)));
|
||||
for(int c2=0;c2<N;c2++)
|
||||
ret._internal[c1][c2]*= nrm;
|
||||
|
||||
for (int b=c1+1; b<N; ++b){
|
||||
decltype(ret._internal[b][b]*ret._internal[b][b]) pr = 0.0;
|
||||
decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
|
||||
zeroit(pr);
|
||||
for(int c=0; c<N; ++c)
|
||||
pr += conjugate(ret._internal[c1][c])*ret._internal[b][c];
|
||||
|
||||
std::cout << "pr : "<< pr << "\n";
|
||||
for(int c=0; c<N; ++c){
|
||||
ret._internal[b][c] -= pr * ret._internal[c1][c];
|
||||
}
|
||||
@ -86,74 +90,6 @@ namespace Grid {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Determinant function for scalar, vector, matrix
|
||||
///////////////////////////////////////////////
|
||||
inline ComplexF Determinant( const ComplexF &arg){ return arg;}
|
||||
inline ComplexD Determinant( const ComplexD &arg){ return arg;}
|
||||
inline RealF Determinant( const RealF &arg){ return arg;}
|
||||
inline RealD Determinant( const RealD &arg){ return arg;}
|
||||
|
||||
template<class vtype> inline auto Determinant(const iScalar<vtype>&r) -> iScalar<decltype(Determinant(r._internal))>
|
||||
{
|
||||
iScalar<decltype(Determinant(r._internal))> ret;
|
||||
ret._internal = Determinant(r._internal);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
inline iScalar<vtype> Determinant(const iMatrix<vtype,N> &arg)
|
||||
{
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
iScalar<vtype> det = vtype(1.0);
|
||||
/* Conversion of matrix to upper triangular */
|
||||
for(int i = 0; i < N; i++){
|
||||
for(int j = 0; j < N; j++){
|
||||
if(j>i){
|
||||
vtype ratio = ret._internal[j][i]/ret._internal[i][i];
|
||||
for(int k = 0; k < N; k++){
|
||||
ret._internal[j][k] -= ratio * ret._internal[i][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
det *= ret._internal[i][i];
|
||||
|
||||
return det;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Exponentiate function for scalar, vector, matrix
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class vtype> inline iScalar<vtype> Exponentiate(const iScalar<vtype>&r, double alpha, int Nexp)
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal = Exponentiate(r._internal, alpha, Nexp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
inline iMatrix<vtype,N> Exponentiate(const iMatrix<vtype,N> &arg, double alpha, int Nexp)
|
||||
{
|
||||
iMatrix<vtype,N> unit(1.0);
|
||||
iMatrix<vtype,N> temp(unit);
|
||||
|
||||
for(int i=Nexp; i>=1;--i){
|
||||
temp *= alpha/double(i);
|
||||
temp = unit + temp*arg;
|
||||
}
|
||||
return ProjectOnGroup(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
45
lib/tensors/Tensor_determinant.h
Normal file
45
lib/tensors/Tensor_determinant.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef GRID_MATH_DET_H
|
||||
#define GRID_MATH_DET_H
|
||||
namespace Grid {
|
||||
///////////////////////////////////////////////
|
||||
// Determinant function for scalar, vector, matrix
|
||||
///////////////////////////////////////////////
|
||||
inline ComplexF Determinant( const ComplexF &arg){ return arg;}
|
||||
inline ComplexD Determinant( const ComplexD &arg){ return arg;}
|
||||
inline RealF Determinant( const RealF &arg){ return arg;}
|
||||
inline RealD Determinant( const RealD &arg){ return arg;}
|
||||
|
||||
template<class vtype> inline auto Determinant(const iScalar<vtype>&r) -> iScalar<decltype(Determinant(r._internal))>
|
||||
{
|
||||
iScalar<decltype(Determinant(r._internal))> ret;
|
||||
ret._internal = Determinant(r._internal);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
inline iScalar<vtype> Determinant(const iMatrix<vtype,N> &arg)
|
||||
{
|
||||
iMatrix<vtype,N> ret(arg);
|
||||
iScalar<vtype> det = vtype(1.0);
|
||||
/* Conversion of matrix to upper triangular */
|
||||
for(int i = 0; i < N; i++){
|
||||
for(int j = 0; j < N; j++){
|
||||
if(j>i){
|
||||
vtype ratio = ret._internal[j][i]/ret._internal[i][i];
|
||||
for(int k = 0; k < N; k++){
|
||||
ret._internal[j][k] -= ratio * ret._internal[i][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
det *= ret._internal[i][i];
|
||||
|
||||
return det;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
37
lib/tensors/Tensor_exp.h
Normal file
37
lib/tensors/Tensor_exp.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef GRID_MATH_EXP_H
|
||||
#define GRID_MATH_EXP_H
|
||||
|
||||
#define DEFAULT_MAT_EXP 12
|
||||
|
||||
namespace Grid {
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Exponentiate function for scalar, vector, matrix
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class vtype> inline iScalar<vtype> Exponentiate(const iScalar<vtype>&r, ComplexD alpha , Integer Nexp = DEFAULT_MAT_EXP)
|
||||
{
|
||||
iScalar<vtype> ret;
|
||||
ret._internal = Exponentiate(r._internal, alpha, Nexp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||
inline iMatrix<vtype,N> Exponentiate(const iMatrix<vtype,N> &arg, ComplexD alpha , Integer Nexp = DEFAULT_MAT_EXP )
|
||||
{
|
||||
iMatrix<vtype,N> unit(1.0);
|
||||
iMatrix<vtype,N> temp(unit);
|
||||
|
||||
for(int i=Nexp; i>=1;--i){
|
||||
temp *= alpha/ComplexD(i);
|
||||
temp = unit + temp*arg;
|
||||
}
|
||||
return ProjectOnGroup(temp);//maybe not strictly necessary
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user