1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-14 01:35:36 +00:00
Grid/lib/Grid_lattice.h

95 lines
2.5 KiB
C
Raw Normal View History

2015-03-04 05:31:44 +00:00
#ifndef GRID_LATTICE_H
#define GRID_LATTICE_H
2015-04-03 05:29:54 +01:00
namespace Grid {
2015-03-04 03:12:19 +00:00
2015-04-18 20:44:19 +01:00
// TODO:
2015-04-18 14:36:01 +01:00
// mac,real,imag
2015-04-18 20:44:19 +01:00
// Functionality:
2015-04-18 14:36:01 +01:00
// -=,+=,*=,()
// add,+,sub,-,mult,mac,*
// adj,conj
// real,imag
// transpose,transposeIndex
// trace,traceIndex
// peekIndex
// innerProduct,outerProduct,
// localNorm2
// localInnerProduct
extern int GridCshiftPermuteMap[4][16];
2015-03-04 03:12:19 +00:00
template<class vobj>
class Lattice
{
public:
GridBase *_grid;
2015-03-04 03:12:19 +00:00
int checkerboard;
2015-03-04 05:31:44 +00:00
std::vector<vobj,alignedAllocator<vobj> > _odata;
2015-04-10 04:53:09 +01:00
public:
typedef typename vobj::scalar_type scalar_type;
typedef typename vobj::vector_type vector_type;
2015-04-18 20:44:19 +01:00
//////////////////////////////////////////////////////////////////
// Constructor requires "grid" passed.
// what about a default grid?
//////////////////////////////////////////////////////////////////
Lattice(GridBase *grid) : _grid(grid) {
2015-03-04 03:12:19 +00:00
_odata.reserve(_grid->oSites());
2015-04-03 22:54:13 +01:00
assert((((uint64_t)&_odata[0])&0xF) ==0);
2015-03-04 03:12:19 +00:00
checkerboard=0;
}
2015-04-18 20:44:19 +01:00
template<class sobj> inline Lattice<vobj> & operator = (const sobj & r){
2015-03-04 03:12:19 +00:00
#pragma omp parallel for
for(int ss=0;ss<_grid->oSites();ss++){
this->_odata[ss]=r;
}
return *this;
}
// *=,+=,-= operators inherit behvour from correspond */+/- operation
2015-04-18 20:44:19 +01:00
template<class T> inline Lattice<vobj> &operator *=(const T &r) {
2015-03-04 03:12:19 +00:00
*this = (*this)*r;
return *this;
}
2015-04-18 20:44:19 +01:00
template<class T> inline Lattice<vobj> &operator -=(const T &r) {
2015-03-04 03:12:19 +00:00
*this = (*this)-r;
return *this;
}
2015-04-18 20:44:19 +01:00
template<class T> inline Lattice<vobj> &operator +=(const T &r) {
2015-03-04 03:12:19 +00:00
*this = (*this)+r;
return *this;
}
2015-04-18 20:44:19 +01:00
inline friend Lattice<vobj> operator / (const Lattice<vobj> &lhs,const Lattice<vobj> &rhs){
2015-03-04 03:12:19 +00:00
conformable(lhs,rhs);
2015-04-18 20:44:19 +01:00
Lattice<vobj> ret(lhs._grid);
2015-03-04 03:12:19 +00:00
#pragma omp parallel for
for(int ss=0;ss<lhs._grid->oSites();ss++){
2015-04-18 20:44:19 +01:00
ret._odata[ss] = lhs._odata[ss]/rhs._odata[ss];
2015-04-18 14:36:01 +01:00
}
return ret;
};
2015-04-18 20:44:19 +01:00
}; // class Lattice
}
2015-04-18 14:36:01 +01:00
2015-04-18 21:23:32 +01:00
#include <lattice/Grid_lattice_conformable.h>
#include <lattice/Grid_lattice_arith.h>
#include <lattice/Grid_lattice_trace.h>
#include <lattice/Grid_lattice_transpose.h>
#include <lattice/Grid_lattice_local.h>
#include <lattice/Grid_lattice_reduction.h>
#include <lattice/Grid_lattice_peekpoke.h>
#include <lattice/Grid_lattice_reality.h>
#include <lattice/Grid_lattice_coordinate.h>
#include <lattice/Grid_lattice_rng.h>
#include <lattice/Grid_lattice_transfer.h>
2015-04-14 22:40:40 +01:00
2015-03-04 05:31:44 +00:00
#endif