gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
STensor33.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 //
6 // Contributor(s):
7 // Eric Bechet
8 //
9 
10 #ifndef STENSOR33_H
11 #define STENSOR33_H
12 
13 #include "STensor3.h"
14 #include "fullMatrix.h"
15 #include "Numeric.h"
16 
17 // concrete class for general 3rd-order tensor in three-dimensional space
18 
19 class STensor33 {
20 protected:
21  // 000 001 002 010 ... 211 212 220 221 222
22  double _val[27];
23 
24 public:
25  inline int getIndex(int i, int j, int k) const
26  {
27  static int _index[3][3][3] = {{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}},
28  {{9, 10, 11}, {12, 13, 14}, {15, 16, 17}},
29  {{18, 19, 20}, {21, 22, 23}, {24, 25, 26}}};
30  return _index[i][j][k];
31  }
32  STensor33(const STensor33 &other)
33  {
34  for(int i = 0; i < 27; i++) _val[i] = other._val[i];
35  }
36  // default constructor, null tensor
37  STensor33(const double v = 0.0)
38  {
39  for(int i = 0; i < 3; i++)
40  for(int j = 0; j < 3; j++)
41  for(int k = 0; k < 3; k++) _val[getIndex(i, j, k)] = v;
42  }
43  inline double &operator()(int i, int j, int k)
44  {
45  return _val[getIndex(i, j, k)];
46  }
47  inline double operator()(int i, int j, int k) const
48  {
49  return _val[getIndex(i, j, k)];
50  }
51  STensor33 operator+(const STensor33 &other) const
52  {
53  STensor33 res(*this);
54  for(int i = 0; i < 27; i++) res._val[i] += other._val[i];
55  return res;
56  }
57  STensor33 &operator=(const STensor33 &other)
58  {
59  for(int i = 0; i < 27; i++) _val[i] = other._val[i];
60  return *this;
61  }
63  {
64  for(int i = 0; i < 27; i++) _val[i] += other._val[i];
65  return *this;
66  }
68  {
69  for(int i = 0; i < 27; i++) _val[i] -= other._val[i];
70  return *this;
71  }
72  STensor33 &operator*=(const double &other)
73  {
74  for(int i = 0; i < 27; i++) _val[i] *= other;
75  return *this;
76  }
77  STensor33 transpose(int n, int m) const
78  {
79  STensor33 ithis;
80  if((n == 0 && m == 1) || (n == 1 && m == 0)) {
81  for(int i = 0; i < 3; i++)
82  for(int j = 0; j < 3; j++)
83  for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(j, i, k);
84  return ithis;
85  }
86  if((n == 0 && m == 2) || (n == 2 && m == 0)) {
87  for(int i = 0; i < 3; i++)
88  for(int j = 0; j < 3; j++)
89  for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(k, j, i);
90  return ithis;
91  }
92  if((n == 1 && m == 2) || (n == 2 && m == 1)) {
93  for(int i = 0; i < 3; i++)
94  for(int j = 0; j < 3; j++)
95  for(int k = 0; k < 3; k++) ithis(i, j, k) = (*this)(i, k, j);
96  return ithis;
97  }
98  return ithis += (*this);
99  }
100  /* STensor33& operator *= (const STensor33 &other)
101  {
102  // to be implemented
103  return *this;
104  }*/
105  void print(const char *) const;
106 
107  const double *data() const { return _val; }
108  double *data() { return _val; }
109 };
110 
111 // tensor product
112 inline void tensprod(const SVector3 &a, const STensor3 &b, STensor33 &c)
113 {
114  for(int i = 0; i < 3; i++)
115  for(int j = 0; j < 3; j++)
116  for(int k = 0; k < 3; k++) c(i, j, k) = a(i) * b(j, k);
117 }
118 inline void tensprod(const STensor3 &a, const SVector3 &b, STensor33 &c)
119 {
120  for(int i = 0; i < 3; i++)
121  for(int j = 0; j < 3; j++)
122  for(int k = 0; k < 3; k++) c(i, j, k) = a(i, j) * b(k);
123 }
124 
125 inline double dot(const STensor33 &a, const STensor33 &b)
126 {
127  double prod = 0;
128  for(int i = 0; i < 3; i++)
129  for(int j = 0; j < 3; j++)
130  for(int k = 0; k < 3; k++) prod += a(i, j, k) * b(i, j, k);
131  return prod;
132 }
133 
134 // full contracted product
135 inline STensor33 operator*(const STensor33 &t, double m)
136 {
137  STensor33 val(t);
138  val *= m;
139  return val;
140 }
141 inline STensor33 operator*(double m, const STensor33 &t)
142 {
143  STensor33 val(t);
144  val *= m;
145  return val;
146 }
147 
148 inline STensor3 operator*(const STensor33 &t, const SVector3 &m)
149 {
150  STensor3 val(0.);
151  for(int i = 0; i < 3; i++)
152  for(int j = 0; j < 3; j++)
153  for(int k = 0; k < 3; k++) val(i, j) += t(i, j, k) * m(k);
154  return val;
155 }
156 inline STensor3 operator*(const SVector3 &m, const STensor33 &t)
157 {
158  STensor3 val(0.);
159  for(int i = 0; i < 3; i++)
160  for(int j = 0; j < 3; j++)
161  for(int k = 0; k < 3; k++) val(j, k) += m(i) * t(i, j, k);
162  return val;
163 }
164 
165 inline SVector3 operator*(const STensor33 &t, const STensor3 &m)
166 {
167  SVector3 val(0.);
168  for(int i = 0; i < 3; i++)
169  for(int j = 0; j < 3; j++)
170  for(int k = 0; k < 3; k++) val(i) += t(i, j, k) * m(k, j);
171  return val;
172 }
173 inline SVector3 operator*(const STensor3 &m, const STensor33 &t)
174 {
175  SVector3 val(0.);
176  for(int i = 0; i < 3; i++)
177  for(int j = 0; j < 3; j++)
178  for(int k = 0; k < 3; k++) val(k) += m(j, i) * t(i, j, k);
179  return val;
180 }
181 
182 inline double operator*(const STensor33 &m, const STensor33 &t)
183 {
184  double val(0.);
185  for(int i = 0; i < 3; i++)
186  for(int j = 0; j < 3; j++)
187  for(int k = 0; k < 3; k++) val += m(i, j, k) * t(k, j, i);
188  return val;
189 }
190 
191 #endif
dot
double dot(const STensor33 &a, const STensor33 &b)
Definition: STensor33.h:125
STensor33::operator()
double & operator()(int i, int j, int k)
Definition: STensor33.h:43
STensor33::operator=
STensor33 & operator=(const STensor33 &other)
Definition: STensor33.h:57
STensor33::print
void print(const char *) const
Definition: STensor33.cpp:12
STensor33::operator+=
STensor33 & operator+=(const STensor33 &other)
Definition: STensor33.h:62
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition: discreteFrechetDistance.cpp:15
operator*
STensor33 operator*(const STensor33 &t, double m)
Definition: STensor33.h:135
STensor3
Definition: STensor3.h:97
SVector3
Definition: SVector3.h:16
tensprod
void tensprod(const SVector3 &a, const STensor3 &b, STensor33 &c)
Definition: STensor33.h:112
STensor33::operator()
double operator()(int i, int j, int k) const
Definition: STensor33.h:47
Numeric.h
STensor33::operator*=
STensor33 & operator*=(const double &other)
Definition: STensor33.h:72
STensor33::operator+
STensor33 operator+(const STensor33 &other) const
Definition: STensor33.h:51
STensor33::_val
double _val[27]
Definition: STensor33.h:22
STensor33::transpose
STensor33 transpose(int n, int m) const
Definition: STensor33.h:77
STensor3.h
STensor33::STensor33
STensor33(const double v=0.0)
Definition: STensor33.h:37
STensor33::operator-=
STensor33 & operator-=(const STensor33 &other)
Definition: STensor33.h:67
STensor33::getIndex
int getIndex(int i, int j, int k) const
Definition: STensor33.h:25
STensor33::data
const double * data() const
Definition: STensor33.h:107
STensor33
Definition: STensor33.h:19
STensor33::data
double * data()
Definition: STensor33.h:108
fullMatrix.h
STensor33::STensor33
STensor33(const STensor33 &other)
Definition: STensor33.h:32