-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpetsc_grid_dwf.cc
152 lines (117 loc) · 4.41 KB
/
petsc_grid_dwf.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "petsc_lattice.h"
#include "petsc_fermion.h"
#include "petsc_grid.h"
/*includes the global parameters*/
#include "petsc_fermion_parameters.h"
static char help[] = "Shamir Domain Wall fermions on a hypercubic lattice.\n\n";
NAMESPACE_BEGIN(Grid);
int CheckDwfWithGrid(DM dm,Vec psi,Vec res)
{
DomainWallParameters p;
p.M5 = 1.8;
p.m = 0.01;
p.Ls = 16;
SetDomainWallParameters(&p);
Coordinate latt_size = GridDefaultLatt();
Coordinate simd_layout = GridDefaultSimd(Nd,vComplexD::Nsimd());
Coordinate mpi_layout = GridDefaultMpi();
GridCartesian GRID(latt_size,simd_layout,mpi_layout);
GridRedBlackCartesian RBGRID(&GRID);
std::vector<int> seeds({1,2,3,4});
GridParallelRNG pRNG(&GRID);
pRNG.SeedFixedIntegers(seeds);
LatticeGaugeFieldD Umu(&GRID);
LatticeGaugeField U_GT(&GRID); // Gauge transformed field
LatticeColourMatrix g(&GRID); // local Gauge xform matrix
if (0) {
SU3::TepidConfiguration(pRNG,Umu); /*random config*/
//Umu = ComplexD(1.0,0.0); /*Unit config*/
U_GT = Umu;
// Make a random xform to the gauge field
SU<Nc>::RandomGaugeTransform(pRNG,U_GT,g); // Unit gauge
} else {
std::string name ("ckpoint_lat.4000");
std::cout<<GridLogMessage <<"Loading configuration from "<< name<<std::endl;
FieldMetaData header;
NerscIO::readConfiguration(Umu, header, name);
U_GT = Umu;
}
////////////////////////////////////////////////////
// DWF test
////////////////////////////////////////////////////
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(p.Ls,&GRID);
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(p.Ls,&GRID);
LatticeFermionD g_src(FGrid);
LatticeFermionD g_res(FGrid); // Grid result
LatticeFermionD p_res(FGrid); // Petsc result
LatticeFermionD diff(FGrid); // Petsc result
std::cout << "Setting gauge to Grid for Ls="<<p.Ls<<std::endl;
SetGauge_Grid5D(dm,U_GT,p.Ls,p.m);
PetscToGrid(dm,psi,g_src);
DomainWallFermionD DWF(U_GT,*FGrid,*FrbGrid,GRID,RBGRID,p.m,p.M5);
// DWF.Dhop(g_src,g_res,0); Passes with no 5d term
RealD t0=usecond();
DWF.M(g_src,g_res);
RealD t1=usecond();
PetscCall(Ddwf(dm, psi, res)); // Applies DW
RealD t2=usecond();
PetscToGrid(dm,res,p_res);
diff = p_res - g_res;
std::cout << "******************************"<<std::endl;
std::cout << "CheckDwWithGrid Grid " << norm2(g_res)<<std::endl;
std::cout << "CheckDwWithGrid Petsc " << norm2(p_res)<<std::endl;
std::cout << "CheckDwWithGrid diff " << norm2(diff)<<std::endl;
std::cout << "Grid " << t1-t0 <<" us"<<std::endl;
std::cout << "Petsc " << t2-t1 <<" us"<<std::endl;
std::cout << "******************************"<<std::endl;
DWF.Mdag(g_src,g_res);
PetscCall(DdwfDag(dm, psi, res)); // Applies DW
PetscToGrid(dm,res,p_res);
diff = p_res - g_res;
std::cout << "******************************"<<std::endl;
std::cout << "CheckDwDagWithGrid Grid " << norm2(g_res)<<std::endl;
std::cout << "CheckDwDagWithGrid Petsc " << norm2(p_res)<<std::endl;
std::cout << "CheckDwDagWithGrid diff " << norm2(diff)<<std::endl;
std::cout << "******************************"<<std::endl;
assert(norm2(diff) < 1.0e-7);
return 0;
}
NAMESPACE_END(Grid);
int main(int argc, char **argv)
{
Grid::Grid_init(&argc,&argv);
DM dm;
Vec u, f;
Vec p;
Mat J;
AppCtx user;
PetscRandom r;
PetscCall(PetscInitialize(&argc, &argv, NULL, help));
PetscCall(ProcessOptions(PETSC_COMM_WORLD, &user));
PetscCall(CreateMesh(PETSC_COMM_WORLD, &user, &dm));
PetscCall(SetupDiscretization(dm, &user));
PetscCall(SetupAuxDiscretization(dm, &user));
PetscCall(DMCreateGlobalVector(dm, &u));
PetscCall(DMCreateGlobalVector(dm, &f));
PetscCall(PetscRandomCreate(PETSC_COMM_SELF, &r));
PetscCall(PetscRandomSetType(r, PETSCRAND48));
PetscCall(VecSetRandom(u, r));
PetscCall(PetscRandomDestroy(&r));
Grid::CheckDwfWithGrid(dm,u,f);
PetscCall(VecDestroy(&f));
PetscCall(VecDestroy(&u));
PetscCall(DMDestroy(&dm));
PetscCall(PetscFinalize());
Grid::Grid_finalize();
return 0;
}
/*TEST
build:
requires: complex
test:
requires: fftw
suffix: dirac_free_field
args:
-dm_plex_dim 5 -dm_plex_shape hypercubic -dm_plex_box_faces 16,16,16,16,32 \
-dm_plex_check_symmetry -dm_plex_check_skeleton -dm_plex_check_faces -dm_plex_check_pointsf
TEST*/