1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

add projection on sp2n algebra

This commit is contained in:
Alessandro Lupo 2021-10-26 10:20:44 +01:00
parent 4d8ae6221c
commit 4044536eea
3 changed files with 134 additions and 83 deletions

View File

@ -141,7 +141,37 @@ public:
} }
} }
static inline Field projectForce(Field &P) { return Ta(P); }
static inline Field projectForce(Field &P)
{
if (isSp2n == true)
{
P = Ta(P);
const int nsp = Nc / 2;
Sp<nsp>::iSp2nMatrix<Complex> gen;
auto Psum = P;
Psum = Zero();
for (int a = 0; a < Sp<nsp>::AlgebraDimension; a++)
{
Sp<nsp>::generator(a, gen);
auto coeff = 2. * trace(P * gen);
Psum += coeff * gen;
}
return Psum;
} else
{
return Ta(P);
}
}
static inline void update_field(Field& P, Field& U, double ep){ static inline void update_field(Field& P, Field& U, double ep){
//static std::chrono::duration<double> diff; //static std::chrono::duration<double> diff;

View File

@ -137,6 +137,9 @@ accelerator_inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
// re-do for sp2n // re-do for sp2n
// Ta cannot be defined here for Sp2n because I need the generators from the Sp class
// It is defined in gauge impl types
template<class vtype> accelerator_inline iScalar<vtype> ProjectOnSpGroup(const iScalar<vtype>&r) template<class vtype> accelerator_inline iScalar<vtype> ProjectOnSpGroup(const iScalar<vtype>&r)
{ {
iScalar<vtype> ret; iScalar<vtype> ret;
@ -217,88 +220,6 @@ accelerator_inline iMatrix<vtype,N> ProjectOnSpGroup(const iMatrix<vtype,N> &arg
return ret; return ret;
} }
/*
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
accelerator_inline iMatrix<vtype,N> ProjectOnSpGroup(const iMatrix<vtype,N> &arg)
{
// need a check for the group type?
iMatrix<vtype,N> ret(arg);
vtype nrm;
vtype inner;
for(int c1=0;c1<N/2;c1++){
// Normalises row c1
zeroit(inner);
for(int c2=0;c2<N;c2++)
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
nrm = sqrt(inner);
nrm = 1.0/nrm;
for(int c2=0;c2<N;c2++)
ret._internal[c1][c2]*= nrm;
// Compute row c1+N2/2: c1+N/2 = - \Omega c1*
for(int c2=0;c2<N/2;c2++)
ret._internal[c1+N/2][c2+N/2] = conjugate(ret._internal[c1][c2]); // lupo: c1,c2? dont we want c1 c2+N/2
for(int c2=N/2;c2<N;c2++)
ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]);
// Remove c1 from rows c1+1...N/2-1
for (int b=c1+1; b<N/2; ++b){
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];
for(int c=0; c<N; ++c){
ret._internal[b][c] -= pr * ret._internal[c1][c];
}
}
// Remove c1+N/2 from rows c1+1...N/2-1
for (int b=c1+1; b<N; ++b){
decltype(ret._internal[b][b]*ret._internal[b][b]) pr;
zeroit(pr);
for(int c=0; c<N; ++c)
pr += conjugate(ret._internal[c1+N/2][c])*ret._internal[b][c];
for(int c=0; c<N; ++c){
ret._internal[b][c] -= pr * ret._internal[c1+N/2][c];
}
}
} //end c1 0, ... N/2-1 loop
// Compute the last row
{
// Normalise last row
int c1 = N/2-1;
zeroit(inner);
for(int c2=0;c2<N;c2++)
inner += innerProduct(ret._internal[c1][c2],ret._internal[c1][c2]);
nrm = sqrt(inner);
nrm = 1.0/nrm;
for(int c2=0;c2<N;c2++)
ret._internal[c1][c2]*= nrm;
// Compute row cN-1+N2/2: cN-1+N/2 = - \Omega cN-1*
for(int c2=0;c2<N/2;c2++)
ret._internal[c1+N/2][c2+N/2] = conjugate(ret._internal[c1][c2]);
for(int c2=N/2;c2<N;c2++)
ret._internal[c1+N/2][c2-N/2] = -conjugate(ret._internal[c1][c2]);
}
// assuming the determinant is ok
return ret;
}*/
NAMESPACE_END(Grid); NAMESPACE_END(Grid);
#endif #endif

View File

@ -0,0 +1,100 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: ./tests/Test_hmc_WilsonFermionGauge.cc
Copyright (C) 2015
Author: Peter Boyle <pabobyle@ph.ed.ac.uk>
Author: neo <cossu@post.kek.jp>
Author: Guido Cossu <guido.cossu@ed.ac.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
See the full license in the file "LICENSE" in the top level distribution
directory
*************************************************************************************/
/* END LEGAL */
#include <Grid/Grid.h>
int main(int argc, char **argv)
{
using namespace Grid;
Grid_init(&argc, &argv);
GridLogLayout();
typedef GenericSp2nHMCRunner<MinimumNorm2> HMCWrapper;
HMCWrapper TheHMC;
TheHMC.Resources.AddFourDimGrid("gauge");
// Checkpointer definition
CheckpointerParameters CPparams;
CPparams.config_prefix = "ckpoint_lat";
CPparams.rng_prefix = "ckpoint_rng";
CPparams.saveInterval = 5;
CPparams.format = "IEEE64BIG";
TheHMC.Resources.LoadNerscCheckpointer(CPparams);
RNGModuleParameters RNGpar;
RNGpar.serial_seeds = "12 22 32 42 52";
RNGpar.parallel_seeds = "76 77 87 79 70";
TheHMC.Resources.SetRNGSeeds(RNGpar);
// Construct observables
// here there is too much indirection
typedef PlaquetteMod<HMCWrapper::ImplPolicy> PlaqObs;
typedef TopologicalChargeMod<HMCWrapper::ImplPolicy> QObs;
TheHMC.Resources.AddObservable<PlaqObs>();
TopologyObsParameters TopParams;
TopParams.interval = 5;
TopParams.do_smearing = true;
TopParams.Smearing.steps = 200;
TopParams.Smearing.step_size = 0.01;
TopParams.Smearing.meas_interval = 50;
TopParams.Smearing.maxTau = 2.0;
TheHMC.Resources.AddObservable<QObs>(TopParams);
//////////////////////////////////////////////
/////////////////////////////////////////////////////////////
// Collect actions, here use more encapsulation
// need wrappers of the fermionic classes
// that have a complex construction
// standard
RealD beta = 8.0 ;
SymplWilsonGaugeActionR Waction(beta);
ActionLevel<HMCWrapper::Field> Level1(1);
Level1.push_back(&Waction);
//Level1.push_back(WGMod.getPtr());
TheHMC.TheAction.push_back(Level1);
/////////////////////////////////////////////////////////////
// HMC parameters are serialisable
TheHMC.Parameters.MD.MDsteps = 10;
TheHMC.Parameters.MD.trajL = 1.0;
TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file
TheHMC.Run(); // no smearing
Grid_finalize();
} // main