File indexing completed on 2025-04-19 09:09:49
0001 #ifndef ATOOLS_Math_Lorentz_Ten3_H
0002 #define ATOOLS_Math_Lorentz_Ten3_H
0003
0004 #include "ATOOLS/Math/MathTools.H"
0005
0006 using namespace ATOOLS;
0007
0008 namespace ATOOLS {
0009
0010 template<typename Scalar> class Lorentz_Ten2;
0011
0012 template<typename Scalar>
0013 class Lorentz_Ten3 {
0014 Scalar m_x[4][4][4];
0015 public:
0016 inline Lorentz_Ten3() {
0017 for (unsigned short int i=0; i<4; ++i)
0018 for (unsigned short int j=0; j<4; ++j)
0019 for (unsigned short int k=0; k<4; ++k)
0020 m_x[i][j][k] = Scalar(0.0);
0021 }
0022 template<typename Scalar2>
0023 inline Lorentz_Ten3(const Lorentz_Ten3<Scalar2> & ten) {
0024 for (unsigned short int i=0; i<4; ++i)
0025 for (unsigned short int j=0; j<4; ++j)
0026 for (unsigned short int k=0; k<4; ++k)
0027 m_x[i][j][k] = ten.at(i,j,k);
0028 }
0029 inline Lorentz_Ten3(
0030 const Scalar& x000, const Scalar& x100, const Scalar& x200, const Scalar& x300,
0031 const Scalar& x010, const Scalar& x110, const Scalar& x210, const Scalar& x310,
0032 const Scalar& x020, const Scalar& x120, const Scalar& x220, const Scalar& x320,
0033 const Scalar& x030, const Scalar& x130, const Scalar& x230, const Scalar& x330,
0034
0035 const Scalar& x001, const Scalar& x101, const Scalar& x201, const Scalar& x301,
0036 const Scalar& x011, const Scalar& x111, const Scalar& x211, const Scalar& x311,
0037 const Scalar& x021, const Scalar& x121, const Scalar& x221, const Scalar& x321,
0038 const Scalar& x031, const Scalar& x131, const Scalar& x231, const Scalar& x331,
0039
0040 const Scalar& x002, const Scalar& x102, const Scalar& x202, const Scalar& x302,
0041 const Scalar& x012, const Scalar& x112, const Scalar& x212, const Scalar& x312,
0042 const Scalar& x022, const Scalar& x122, const Scalar& x222, const Scalar& x322,
0043 const Scalar& x032, const Scalar& x132, const Scalar& x232, const Scalar& x332,
0044
0045 const Scalar& x003, const Scalar& x103, const Scalar& x203, const Scalar& x303,
0046 const Scalar& x013, const Scalar& x113, const Scalar& x213, const Scalar& x313,
0047 const Scalar& x023, const Scalar& x123, const Scalar& x223, const Scalar& x323,
0048 const Scalar& x033, const Scalar& x133, const Scalar& x233, const Scalar& x333
0049 ) {
0050 m_x[0][0][0]=x000; m_x[1][0][0]=x100; m_x[2][0][0]=x200; m_x[3][0][0]=x300;
0051 m_x[0][1][0]=x010; m_x[1][1][0]=x110; m_x[2][1][0]=x210; m_x[3][1][0]=x310;
0052 m_x[0][2][0]=x020; m_x[1][2][0]=x120; m_x[2][2][0]=x220; m_x[3][2][0]=x320;
0053 m_x[0][3][0]=x030; m_x[1][3][0]=x130; m_x[2][3][0]=x230; m_x[3][3][0]=x330;
0054
0055 m_x[0][0][1]=x001; m_x[1][0][1]=x101; m_x[2][0][1]=x201; m_x[3][0][1]=x301;
0056 m_x[0][1][1]=x011; m_x[1][1][1]=x111; m_x[2][1][1]=x211; m_x[3][1][1]=x311;
0057 m_x[0][2][1]=x021; m_x[1][2][1]=x121; m_x[2][2][1]=x221; m_x[3][2][1]=x321;
0058 m_x[0][3][1]=x031; m_x[1][3][1]=x131; m_x[2][3][1]=x231; m_x[3][3][1]=x331;
0059
0060 m_x[0][0][2]=x002; m_x[1][0][2]=x102; m_x[2][0][2]=x202; m_x[3][0][2]=x302;
0061 m_x[0][1][2]=x012; m_x[1][1][2]=x112; m_x[2][1][2]=x212; m_x[3][1][2]=x312;
0062 m_x[0][2][2]=x022; m_x[1][2][2]=x122; m_x[2][2][2]=x222; m_x[3][2][2]=x322;
0063 m_x[0][3][2]=x032; m_x[1][3][2]=x132; m_x[2][3][2]=x232; m_x[3][3][2]=x332;
0064
0065 m_x[0][0][3]=x003; m_x[1][0][3]=x103; m_x[2][0][3]=x203; m_x[3][0][3]=x303;
0066 m_x[0][1][3]=x013; m_x[1][1][3]=x113; m_x[2][1][3]=x213; m_x[3][1][3]=x313;
0067 m_x[0][2][3]=x023; m_x[1][2][3]=x123; m_x[2][2][3]=x223; m_x[3][2][3]=x323;
0068 m_x[0][3][3]=x033; m_x[1][3][3]=x133; m_x[2][3][3]=x233; m_x[3][3][3]=x333;
0069 }
0070
0071 inline Lorentz_Ten3(const Scalar ten[4][4][4]) {
0072 for (unsigned short int i=0; i<4; ++i)
0073 for (unsigned short int j=0; j<4; ++j)
0074 for (unsigned short int k=0; k<4; ++k)
0075 m_x[i][j][k] = ten[i][j][k];
0076 }
0077
0078
0079 inline const Scalar at(unsigned short int i, unsigned short int j,
0080 unsigned short int k) const {
0081 return m_x[i][j][k];
0082 }
0083
0084 inline Scalar at(unsigned short int i, unsigned short int j,
0085 unsigned short int k) {
0086 return m_x[i][j][k];
0087 }
0088
0089
0090 inline Lorentz_Ten3<Scalar> operator-() const {
0091 Scalar x[4][4][4];
0092 for (unsigned short int i=0; i<4; ++i)
0093 for (unsigned short int j=0; j<4; ++j)
0094 for (unsigned short int k=0; k<4; ++k)
0095 x[i][j][k] = -m_x[i][j][k];
0096 return Lorentz_Ten3<Scalar>(x);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 inline Lorentz_Ten3<Scalar> Transpose(unsigned short int a, unsigned short int b) const {
0109 Scalar x[4][4][4];
0110 if (((a==1) && (b==2)) || ((a==2) && (b==1)))
0111 for (unsigned short int i=0; i<4; ++i)
0112 for (unsigned short int j=0; j<4; ++j)
0113 for (unsigned short int k=0; k<4; ++k)
0114 x[i][j][k] = m_x[j][i][k];
0115 else if (((a==1) && (b==3)) || ((a==3) && (b==1)))
0116 for (unsigned short int i=0; i<4; ++i)
0117 for (unsigned short int j=0; j<4; ++j)
0118 for (unsigned short int k=0; k<4; ++k)
0119 x[i][j][k] = m_x[k][j][i];
0120 else if (((a==2) && (b==3)) || ((a==3) && (b==2)))
0121 for (unsigned short int i=0; i<4; ++i)
0122 for (unsigned short int j=0; j<4; ++j)
0123 for (unsigned short int k=0; k<4; ++k)
0124 x[i][j][k] = m_x[i][k][j];
0125 return Lorentz_Ten3<Scalar>(x);
0126 }
0127
0128
0129 inline Lorentz_Ten3<Scalar>& operator+=(const Lorentz_Ten3<Scalar>& t) {
0130 for (unsigned short int i=0; i<4; ++i)
0131 for (unsigned short int j=0; j<4; ++j)
0132 for (unsigned short int k=0; k<4; ++k)
0133 m_x[i][j][k] += t.at(i,j,k);
0134 return *this;
0135 }
0136
0137 inline Lorentz_Ten3<Scalar>& operator-=(const Lorentz_Ten3<Scalar>& t) {
0138 for (unsigned short int i=0; i<4; ++i)
0139 for (unsigned short int j=0; j<4; ++j)
0140 for (unsigned short int k=0; k<4; ++k)
0141 m_x[i][j][k] -= t.at(i,j,k);
0142 return *this;
0143 }
0144
0145 template<typename Scalar2>
0146 inline Lorentz_Ten3<PROMOTE(Scalar,Scalar2)>
0147 operator+ (const Lorentz_Ten3<Scalar2>& ten) const {
0148 PROMOTE(Scalar,Scalar2) x[4][4][4];
0149 for (unsigned short int i=0; i<4; ++i)
0150 for (unsigned short int j=0; j<4; ++j)
0151 for (unsigned short int k=0; k<4; ++k)
0152 x[i][j][k] = m_x[i][j][k]+ten.at(i,j,k);
0153 return Lorentz_Ten3<PROMOTE(Scalar,Scalar2)>(x);
0154 }
0155
0156 template<typename Scalar2>
0157 inline Lorentz_Ten3<PROMOTE(Scalar,Scalar2)>
0158 operator- (const Lorentz_Ten3<Scalar2>& ten) const {
0159 PROMOTE(Scalar,Scalar2) x[4][4][4];
0160 for (unsigned short int i=0; i<4; ++i)
0161 for (unsigned short int j=0; j<4; ++j)
0162 for (unsigned short int k=0; k<4; ++k)
0163 x[i][j][k] = m_x[i][j][k]-ten.at(i,j,k);
0164 return Lorentz_Ten3<PROMOTE(Scalar,Scalar2)>(x);
0165 }
0166
0167
0168 inline Lorentz_Ten3<Scalar>& operator*= (const Scalar& scal) {
0169 for (unsigned short int i=0; i<4; ++i)
0170 for (unsigned short int j=0; j<4; ++j)
0171 for (unsigned short int k=0; k<4; ++k)
0172 m_x[i][j][k] *= scal;
0173 return *this;
0174 }
0175
0176 template<typename Scalar2>
0177 inline Lorentz_Ten3<PROMOTE(Scalar,Scalar2)> operator* (const Scalar2 scal) const {
0178 PROMOTE(Scalar,Scalar2) x[4][4][4];
0179 for (unsigned short int i=0; i<4; ++i)
0180 for (unsigned short int j=0; j<4; ++j)
0181 for (unsigned short int k=0; k<4; ++k)
0182 x[i][j][k] = scal*m_x[i][j][k];
0183 return Lorentz_Ten3<PROMOTE(Scalar,Scalar2)>(x);
0184 }
0185
0186 template<typename Scalar2>
0187 inline Lorentz_Ten3<PROMOTE(Scalar,Scalar2)> operator/ (const Scalar2 scal) const {
0188 return (*this)*(1./scal);
0189 }
0190
0191 inline bool Nan() const {
0192 for (unsigned short int i=0; i<4; ++i)
0193 for (unsigned short int j=0; j<4; ++j)
0194 for (unsigned short int k=0; k<4; ++k)
0195 if (ATOOLS::IsNan<Scalar>(m_x[i][j][k])) return true;
0196 return false;
0197 }
0198
0199 inline bool IsZero() const {
0200 for (unsigned short int i=0; i<4; ++i)
0201 for (unsigned short int j=0; j<4; ++j)
0202 for (unsigned short int k=0; k<4; ++k)
0203 if (!ATOOLS::IsZero<Scalar>(m_x[i][j][k])) return false;
0204 return true;
0205 }
0206 };
0207
0208 template<typename Scalar,typename Scal2>
0209 inline Lorentz_Ten3<PROMOTE(Scalar,Scal2)>
0210 operator* (const Scal2 s, const Lorentz_Ten3<Scalar>& t) {
0211 return Lorentz_Ten3<PROMOTE(Scalar,Scal2)>(t*s);
0212 }
0213
0214 template<typename Scalar>
0215 std::ostream& operator<<(std::ostream& s, const Lorentz_Ten3<Scalar>& ten) {
0216
0217
0218
0219 return s<<'('<<ten.at(0,0,0)<<','<<ten.at(1,0,0)<<','<<ten.at(2,0,0)<<','<<ten.at(3,0,0)<<' '<<std::endl
0220 <<' '<<ten.at(0,1,0)<<','<<ten.at(1,1,0)<<','<<ten.at(2,1,0)<<','<<ten.at(3,1,0)<<' '<<std::endl
0221 <<' '<<ten.at(0,2,0)<<','<<ten.at(1,2,0)<<','<<ten.at(2,2,0)<<','<<ten.at(3,2,0)<<' '<<std::endl
0222 <<' '<<ten.at(0,3,0)<<','<<ten.at(1,3,0)<<','<<ten.at(2,3,0)<<','<<ten.at(3,3,0)<<')'<<std::endl
0223 <<'('<<ten.at(0,0,1)<<','<<ten.at(1,0,1)<<','<<ten.at(2,0,1)<<','<<ten.at(3,0,1)<<' '<<std::endl
0224 <<' '<<ten.at(0,1,1)<<','<<ten.at(1,1,1)<<','<<ten.at(2,1,1)<<','<<ten.at(3,1,1)<<' '<<std::endl
0225 <<' '<<ten.at(0,2,1)<<','<<ten.at(1,2,1)<<','<<ten.at(2,2,1)<<','<<ten.at(3,2,1)<<' '<<std::endl
0226 <<' '<<ten.at(0,3,1)<<','<<ten.at(1,3,1)<<','<<ten.at(2,3,1)<<','<<ten.at(3,3,1)<<')'<<std::endl
0227 <<'('<<ten.at(0,0,2)<<','<<ten.at(1,0,2)<<','<<ten.at(2,0,2)<<','<<ten.at(3,0,2)<<' '<<std::endl
0228 <<' '<<ten.at(0,1,2)<<','<<ten.at(1,1,2)<<','<<ten.at(2,1,2)<<','<<ten.at(3,1,2)<<' '<<std::endl
0229 <<' '<<ten.at(0,2,2)<<','<<ten.at(1,2,2)<<','<<ten.at(2,2,2)<<','<<ten.at(3,2,2)<<' '<<std::endl
0230 <<' '<<ten.at(0,3,2)<<','<<ten.at(1,3,2)<<','<<ten.at(2,3,2)<<','<<ten.at(3,3,2)<<')'<<std::endl
0231 <<'('<<ten.at(0,0,3)<<','<<ten.at(1,0,3)<<','<<ten.at(2,0,3)<<','<<ten.at(3,0,3)<<' '<<std::endl
0232 <<' '<<ten.at(0,1,3)<<','<<ten.at(1,1,3)<<','<<ten.at(2,1,3)<<','<<ten.at(3,1,3)<<' '<<std::endl
0233 <<' '<<ten.at(0,2,3)<<','<<ten.at(1,2,3)<<','<<ten.at(2,2,3)<<','<<ten.at(3,2,3)<<' '<<std::endl
0234 <<' '<<ten.at(0,3,3)<<','<<ten.at(1,3,3)<<','<<ten.at(2,3,3)<<','<<ten.at(3,3,3)<<')'<<std::endl;
0235 }
0236 }
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 #endif