DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
EigenTensor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "DNDS/Defines.hpp"
4#include <array>
5#include <assert.h>
6#include <iostream>
7
8namespace DNDS::ETensor
9{
10 using namespace Eigen;
11 template <typename T, Index d0, Index d1, Index d2>
13 {
14 static const Index siz = d0 * d1 * d2;
15 static const Index stride0 = d1 * d2;
16 static const Index stride1 = d2;
17 static const Index stride2 = 1;
18 std::array<T, siz> data;
19
20 public:
21 ETensorR3(const T &fill)
22 {
23 for (Index i = 0; i < siz; i++)
24 data[i] = fill;
25 }
26
27 ETensorR3() = default;
28
29 T &operator()(Index i0, Index i1, Index i2)
30 {
31 return data[i2 + d2 * (i1 + (d1 * i0))];
32 }
33
34 using M01 = Matrix<T, d0, d1, RowMajor>;
35 using M12 = Matrix<T, d1, d2, RowMajor>;
36 using M02 = Matrix<T, d0, d2, RowMajor>;
37
38 using Map01 = Map<M01, Unaligned, Stride<stride0, stride1>>;
39 using Map12 = Map<M12, Unaligned, Stride<stride1, stride2>>;
40 using Map02 = Map<M02, Unaligned, Stride<stride0, stride2>>;
41
42 Map01 GetMap01(Index i2)
43 {
44 DNDS_assert(i2 < d2);
45 return Map01(data.data() + i2 * stride2);
46 }
47
48 Map12 GetMap12(Index i0)
49 {
50 DNDS_assert(i0 < d0);
51 return Map12(data.data() + i0 * stride0);
52 }
53
54 Map02 GetMap02(Index i1)
55 {
56 DNDS_assert(i1 < d1);
57 return Map02(data.data() + i1 * stride1);
58 }
59
60 template <class Tmat>
61 void MatTransform0(const Tmat &Rmat)
62 {
63 DNDS_assert(Rmat.cols() == Rmat.rows() && Rmat.rows() == d0);
64 for (Index i2 = 0; i2 < d2; i2++)
65 {
66 Map01 m = GetMap01(i2);
67 m = Rmat.transpose() * m;
68 }
69 }
70
71 template <class Tmat>
72 void MatTransform1(const Tmat &Rmat)
73 {
74 DNDS_assert(Rmat.cols() == Rmat.rows() && Rmat.rows() == d1);
75 for (Index i2 = 0; i2 < d2; i2++)
76 {
77 Map01 m = GetMap01(i2);
78 m = m * Rmat;
79 }
80 }
81
82 template <class Tmat>
83 void MatTransform2(const Tmat &Rmat)
84 {
85 DNDS_assert(Rmat.cols() == Rmat.rows() && Rmat.rows() == d2);
86 for (Index i0 = 0; i0 < d0; i0++)
87 {
88 Map12 m = GetMap12(i0);
89 m = m * Rmat;
90 }
91 }
92
93 template <Index dout, class Tmat>
95 {
96 DNDS_assert(Rmat.rows() == d0 && Rmat.cols() == dout);
98 for (Index i2 = 0; i2 < d2; i2++)
99 {
100 auto m = GetMap01(i2);
101 auto mout = res.GetMap01(i2);
102 mout = Rmat.transpose() * m;
103 }
104 return res;
105 }
106
107 template <Index dout, class Tmat>
109 {
110 DNDS_assert(Rmat.rows() == d1 && Rmat.cols() == dout);
112 // const TDerived &rmat = Rmat;
113 for (Index i2 = 0; i2 < d2; i2++)
114 {
115 Map01 m = GetMap01(i2);
116 auto mout = res.GetMap01(i2);
117 mout = m * Rmat;
118 }
119 return res;
120 }
121
122 template <Index dout, class Tmat>
124 {
125 DNDS_assert(Rmat.rows() == d2 && Rmat.cols() == dout);
127 for (Index i0 = 0; i0 < d0; i0++)
128 {
129 auto m = GetMap12(i0);
130 auto mout = res.GetMap12(i0);
131 mout = m * Rmat;
132 }
133 return res;
134 }
135 };
136 template <typename T, Index d0, Index d1, Index d2>
137 std::ostream &operator<<(std::ostream &out, ETensorR3<T, d0, d1, d2> &R)
138 {
139 out << "[";
140 for (Index i0 = 0; i0 < d0; i0++)
141 out << R.GetMap12(i0) << "\n\n";
142 out << "]\n";
143 return out;
144 }
145
146 template <typename T, Index d0, Index d1, Index d2>
147 std::ostream &operator<<(std::ostream &out, const ETensorR3<T, d0, d1, d2> &R)
148 {
149 out << "[";
150 for (Index i0 = 0; i0 < d0; i0++)
151 out << R.GetMap12(i0) << "\n\n";
152 out << "]\n";
153 return out;
154 }
155}
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:112
Eigen::Matrix< real, 3, 3 > m
Map< M02, Unaligned, Stride< stride0, stride2 > > Map02
ETensorR3< T, d0, d1, dout > MatTransform2d(const Tmat &Rmat)
Map02 GetMap02(Index i1)
Matrix< T, d0, d1, RowMajor > M01
Matrix< T, d1, d2, RowMajor > M12
void MatTransform0(const Tmat &Rmat)
Map12 GetMap12(Index i0)
Matrix< T, d0, d2, RowMajor > M02
ETensorR3< T, d0, dout, d2 > MatTransform1d(const Tmat &Rmat)
Map01 GetMap01(Index i2)
Map< M01, Unaligned, Stride< stride0, stride1 > > Map01
T & operator()(Index i0, Index i1, Index i2)
void MatTransform1(const Tmat &Rmat)
void MatTransform2(const Tmat &Rmat)
ETensorR3< T, dout, d1, d2 > MatTransform0d(const Tmat &Rmat)
Map< M12, Unaligned, Stride< stride1, stride2 > > Map12
std::ostream & operator<<(std::ostream &out, ETensorR3< T, d0, d1, d2 > &R)