20 #ifndef JDFTX_CORE_TENSOR3_H 21 #define JDFTX_CORE_TENSOR3_H 26 #include <core/scalar.h> 29 #define LOOP5(code) { for(int k=0; k<5; k++) { code } } 32 template<
typename scalar=
double>
class tensor3 37 __hostanddev__ scalar& operator[](
int k) {
return v[k]; }
38 __hostanddev__
const scalar& operator[](
int k)
const {
return v[k]; }
39 __hostanddev__ scalar& xy() {
return v[0]; }
40 __hostanddev__ scalar& yz() {
return v[1]; }
41 __hostanddev__ scalar& zx() {
return v[2]; }
42 __hostanddev__ scalar&
xxr() {
return v[3]; }
43 __hostanddev__ scalar&
yyr() {
return v[4]; }
44 __hostanddev__
const scalar& xy()
const {
return v[0]; }
45 __hostanddev__
const scalar& yz()
const {
return v[1]; }
46 __hostanddev__
const scalar& zx()
const {
return v[2]; }
47 __hostanddev__
const scalar&
xxr()
const {
return v[3]; }
48 __hostanddev__
const scalar&
yyr()
const {
return v[4]; }
50 explicit __hostanddev__
tensor3(scalar a=0, scalar b=0, scalar c=0, scalar d=0, scalar e=0) { v[0]=a; v[1]=b; v[2]=c; v[3]=d; v[4]=e; }
51 tensor3(std::vector<scalar> a) { LOOP5( v[k]=a[k]; ) }
56 {
return tensor3<scalar>( tArr[0][i], tArr[1][i], tArr[2][i], tArr[3][i], tArr[4][i] );
60 {
return tensor3<scalar>( tArr[0][i], tArr[1][i], tArr[2][i], tArr[3][i], tArr[4][i] );
64 { LOOP5( tArr[k][i] = t[k]; )
68 { LOOP5( tArr[k][i] += t[k]; )
__hostanddev__ tensor3< scalar > loadTensor(const tensor3< const scalar * > &tArr, int i)
Load tensor from a constant tensor field.
Definition: tensor3.h:55
__hostanddev__ scalar & xxr()
xxr = x^2 - r^2/3
Definition: tensor3.h:42
__hostanddev__ scalar & yyr()
yyr = y^2-r^2/3
Definition: tensor3.h:43
Symmetric traceless rank-2 tensor in 3D.
Definition: tensor3.h:32
__hostanddev__ void accumTensor(const tensor3< scalar > &t, tensor3< scalar * > &tArr, int i)
Accumulate tensor onto a tensor field.
Definition: tensor3.h:67
__hostanddev__ void storeTensor(const tensor3< scalar > &t, tensor3< scalar * > &tArr, int i)
Store tensor to a tensor field.
Definition: tensor3.h:63