Grid 0.7.0
Geometry.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/algorithms/GeneralCoarsenedMatrix.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <pboyle@bnl.gov>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26*************************************************************************************/
27/* END LEGAL */
28#pragma once
29
31
32
34// Geometry class in cartesian case
36
37class Geometry {
38public:
39 int npoint;
40 int base;
41 std::vector<int> directions ;
42 std::vector<int> displacements;
43 std::vector<int> points_dagger;
44
45 Geometry(int _d) {
46
47 base = (_d==5) ? 1:0;
48
49 // make coarse grid stencil for 4d , not 5d
50 if ( _d==5 ) _d=4;
51
52 npoint = 2*_d+1;
53 directions.resize(npoint);
54 displacements.resize(npoint);
55 points_dagger.resize(npoint);
56 for(int d=0;d<_d;d++){
57 directions[d ] = d+base;
58 directions[d+_d] = d+base;
59 displacements[d ] = +1;
60 displacements[d+_d]= -1;
61 points_dagger[d ] = d+_d;
62 points_dagger[d+_d] = d;
63 }
64 directions [2*_d]=0;
65 displacements[2*_d]=0;
66 points_dagger[2*_d]=2*_d;
67 }
68
69 int point(int dir, int disp) {
70 assert(disp == -1 || disp == 0 || disp == 1);
71 assert(base+0 <= dir && dir < base+4);
72
73 // directions faster index = new indexing
74 // 4d (base = 0):
75 // point 0 1 2 3 4 5 6 7 8
76 // dir 0 1 2 3 0 1 2 3 0
77 // disp +1 +1 +1 +1 -1 -1 -1 -1 0
78 // 5d (base = 1):
79 // point 0 1 2 3 4 5 6 7 8
80 // dir 1 2 3 4 1 2 3 4 0
81 // disp +1 +1 +1 +1 -1 -1 -1 -1 0
82
83 // displacements faster index = old indexing
84 // 4d (base = 0):
85 // point 0 1 2 3 4 5 6 7 8
86 // dir 0 0 1 1 2 2 3 3 0
87 // disp +1 -1 +1 -1 +1 -1 +1 -1 0
88 // 5d (base = 1):
89 // point 0 1 2 3 4 5 6 7 8
90 // dir 1 1 2 2 3 3 4 4 0
91 // disp +1 -1 +1 -1 +1 -1 +1 -1 0
92
93 if(dir == 0 and disp == 0)
94 return 8;
95 else // New indexing
96 return (1 - disp) / 2 * 4 + dir - base;
97 // else // Old indexing
98 // return (4 * (dir - base) + 1 - disp) / 2;
99 }
100};
101
103// Less local equivalent of Geometry class in cartesian case
106public:
107 // int depth;
108 int skip;
109 int hops;
111 std::vector<Coordinate> shifts;
116 GridCartesian *Grid() {return grid;};
117 int Depth(void){return 1;}; // Ghost zone depth
118 int Hops(void){return hops;}; // # of hops=> level of corner fill in in stencil
119 int DimSkip(void){return skip;};
120
122
123 int Reverse(int point)
124 {
125 int Nd = Grid()->Nd();
126 Coordinate shft = shifts[point];
127 Coordinate rev(Nd);
128 for(int mu=0;mu<Nd;mu++) rev[mu]= -shft[mu];
129 for(int p=0;p<npoint;p++){
130 if(rev==shifts[p]){
131 return p;
132 }
133 }
134 assert(0);
135 return -1;
136 }
137 void BuildShifts(void)
138 {
139 this->shifts.resize(0);
140 int Nd = this->grid->Nd();
141
142 int dd = this->DimSkip();
143 for(int s0=this->stencil_lo[dd+0];s0<=this->stencil_hi[dd+0];s0++){
144 for(int s1=this->stencil_lo[dd+1];s1<=this->stencil_hi[dd+1];s1++){
145 for(int s2=this->stencil_lo[dd+2];s2<=this->stencil_hi[dd+2];s2++){
146 for(int s3=this->stencil_lo[dd+3];s3<=this->stencil_hi[dd+3];s3++){
147 Coordinate sft(Nd,0);
148 sft[dd+0] = s0;
149 sft[dd+1] = s1;
150 sft[dd+2] = s2;
151 sft[dd+3] = s3;
152 int nhops = abs(s0)+abs(s1)+abs(s2)+abs(s3);
153 if(nhops<=this->hops) this->shifts.push_back(sft);
154 }}}}
155 this->npoint = this->shifts.size();
156 std::cout << GridLogMessage << "NonLocalStencilGeometry has "<< this->npoint << " terms in stencil "<<std::endl;
157 }
158
159 NonLocalStencilGeometry(GridCartesian *_coarse_grid,int _hops,int _skip) : grid(_coarse_grid), hops(_hops), skip(_skip)
160 {
161 Coordinate latt = grid->GlobalDimensions();
162 stencil_size.resize(grid->Nd());
163 stencil_lo.resize(grid->Nd());
164 stencil_hi.resize(grid->Nd());
165 for(int d=0;d<grid->Nd();d++){
166 if ( latt[d] == 1 ) {
167 stencil_lo[d] = 0;
168 stencil_hi[d] = 0;
169 stencil_size[d]= 1;
170 } else if ( latt[d] == 2 ) {
171 stencil_lo[d] = -1;
172 stencil_hi[d] = 0;
173 stencil_size[d]= 2;
174 } else if ( latt[d] > 2 ) {
175 stencil_lo[d] = -1;
176 stencil_hi[d] = 1;
177 stencil_size[d]= 3;
178 }
179 }
180 this->BuildShifts();
181 };
182
183};
184
185// Need to worry about red-black now
187public:
188 virtual int DerivedDimSkip(void) { return 0;};
189 NonLocalStencilGeometry4D(GridCartesian *Coarse,int _hops) : NonLocalStencilGeometry(Coarse,_hops,0) { };
191};
193public:
194 virtual int DerivedDimSkip(void) { return 1; };
195 NonLocalStencilGeometry5D(GridCartesian *Coarse,int _hops) : NonLocalStencilGeometry(Coarse,_hops,1) { };
197};
198/*
199 * Bunch of different options classes
200 */
237
AcceleratorVector< int, MaxDims > Coordinate
Definition Coordinate.h:95
accelerator_inline Grid_simd< S, V > abs(const Grid_simd< S, V > &r)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int Nd
Definition QCD.h:52
std::vector< int > displacements
Definition Geometry.h:42
std::vector< int > points_dagger
Definition Geometry.h:43
int point(int dir, int disp)
Definition Geometry.h:69
std::vector< int > directions
Definition Geometry.h:41
Geometry(int _d)
Definition Geometry.h:45
int npoint
Definition Geometry.h:39
int base
Definition Geometry.h:40
int Nd(void) const
NearestStencilGeometry4D(GridCartesian *Coarse)
Definition Geometry.h:227
NearestStencilGeometry5D(GridCartesian *Coarse)
Definition Geometry.h:233
NextToNearestStencilGeometry4D(GridCartesian *Coarse)
Definition Geometry.h:215
NextToNearestStencilGeometry5D(GridCartesian *Coarse)
Definition Geometry.h:221
NextToNextToNextToNearestStencilGeometry4D(GridCartesian *Coarse)
Definition Geometry.h:203
NextToNextToNextToNearestStencilGeometry5D(GridCartesian *Coarse)
Definition Geometry.h:209
NonLocalStencilGeometry4D(GridCartesian *Coarse, int _hops)
Definition Geometry.h:189
virtual ~NonLocalStencilGeometry4D()
Definition Geometry.h:190
virtual int DerivedDimSkip(void)
Definition Geometry.h:188
NonLocalStencilGeometry5D(GridCartesian *Coarse, int _hops)
Definition Geometry.h:195
virtual int DerivedDimSkip(void)
Definition Geometry.h:194
virtual ~NonLocalStencilGeometry5D()
Definition Geometry.h:196
Coordinate stencil_size
Definition Geometry.h:112
GridCartesian * grid
Definition Geometry.h:115
std::vector< Coordinate > shifts
Definition Geometry.h:111
int Reverse(int point)
Definition Geometry.h:123
virtual ~NonLocalStencilGeometry()
Definition Geometry.h:121
NonLocalStencilGeometry(GridCartesian *_coarse_grid, int _hops, int _skip)
Definition Geometry.h:159
GridCartesian * Grid()
Definition Geometry.h:116