FEDEM Solver  R8.0
Source code of the dynamics solver
FFaTensor3.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_TENSOR3_H
14 #define FFA_TENSOR3_H
15 
16 #include <array>
17 #include <iostream>
18 
19 class FaVec3;
20 class FaMat33;
21 class FaMat34;
22 class FFaTensor1;
23 class FFaTensor2;
24 
25 
35 {
36  std::array<double,6> myT;
37 
38 public:
40  FFaTensor3(double d = 0.0) { myT.fill(d); }
42  FFaTensor3(const float* t) { for (int i=0; i<6; i++) myT[i] = t[i]; }
44  FFaTensor3(const double* t) { for (int i=0; i<6; i++) myT[i] = t[i]; }
46  FFaTensor3(const FFaTensor2& t);
48  FFaTensor3(const FFaTensor1& t);
50  FFaTensor3(const FaVec3& v);
52  FFaTensor3(double t11 , double t22 , double t33,
53  double t12 = 0.0, double t13 = 0.0, double t23 = 0.0)
54  {
55  myT = { t11, t22, t33, t12, t13, t23 };
56  }
58  FFaTensor3(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3)
59  {
60  this->makeInertia(v1,v2,v3);
61  }
62 
64  void fill(double d) { myT.fill(d); }
65 
67  FFaTensor3& operator= (const FFaTensor1& t);
69  FFaTensor3& operator= (const FFaTensor2& t);
70 
73  {
74  for (int i=0; i<6; i++) myT[i] += t.myT[i];
75  return *this;
76  }
77 
80  {
81  for (int i=0; i<6; i++) myT[i] -= t.myT[i];
82  return *this;
83  }
84 
87  {
88  for (int i=0; i<6; i++) myT[i] *= d;
89  return *this;
90  }
91 
94  {
95  for (int i=0; i<6; i++) myT[i] /= d;
96  return *this;
97  }
98 
100  const double* getPt() const { return myT.data(); }
102  double* getPt() { return myT.data(); }
103 
105  const double& operator[] (int i) const;
107  double& operator[] (int i);
108 
109  // Special functions
110 
112  FFaTensor3& rotate(const FaMat33& rotMx);
114  FFaTensor3& rotate(const FaMat34& rotMx);
115 
117  FFaTensor3& makeInertia(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3);
119  FFaTensor3& translateInertia(const FaVec3& x, double mass);
120 
122  double vonMises() const;
124  double maxShear() const;
126  void maxShear(FaVec3& v) const;
128  double maxPrinsipal(bool absMax = false) const;
130  double middlePrinsipal() const;
132  double minPrinsipal() const;
133 
135  void prinsipalValues(double& max, double& middle, double& min) const;
137  void prinsipalValues(FaVec3& values, FaMat33& rotation) const;
138 
139  // Global operators
140 
144  friend FFaTensor3 operator+ (const FFaTensor3&, const FFaTensor3&);
146  friend FFaTensor3 operator- (const FFaTensor3&, const FFaTensor3&);
147 
149  friend FFaTensor3 operator* (const FFaTensor3&, double);
151  friend FFaTensor3 operator* (double, const FFaTensor3&);
153  friend FFaTensor3 operator/ (const FFaTensor3&, double);
154 
156  friend bool operator== (const FFaTensor3&, const FFaTensor3&);
158  friend bool operator!= (const FFaTensor3&, const FFaTensor3&);
159 
161  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat33&);
163  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat34&);
165  friend FFaTensor3 operator* (const FaMat33&, const FFaTensor3&);
167  friend FFaTensor3 operator* (const FaMat34&, const FFaTensor3&);
168 
170  friend std::ostream& operator<< (std::ostream&, const FFaTensor3&);
172  friend std::istream& operator>> (std::istream&, FFaTensor3&);
173 };
174 
175 
176 // --- inline functions ---
177 
178 inline const double& FFaTensor3::operator[] (int i) const
179 {
180 #ifdef FFA_INDEXCHECK
181  if (i < 0 || i > 5)
182  std::cerr <<"FFaTensor3::operator[]: index i="<< i
183  <<" is out of range [0,5]"<< std::endl;
184 #endif
185  return myT[i];
186 }
187 
188 inline double& FFaTensor3::operator[] (int i)
189 {
190 #ifdef FFA_INDEXCHECK
191  if (i < 0 || i > 5)
192  std::cerr <<"FFaTensor3::operator[]: index i="<< i
193  <<" is out of range [0,5]"<< std::endl;
194 #endif
195  return myT[i];
196 }
197 
198 #endif
Class to represent a 1D simple tensor.
Definition: FFaTensor1.H:31
Class to represent a 2D symmetrical tensor.
Definition: FFaTensor2.H:35
Class to represent a 3D symmetric tensor.
Definition: FFaTensor3.H:35
double minPrinsipal() const
Returns the min principal value of the tensor.
Definition: FFaTensor3.C:202
void prinsipalValues(double &max, double &middle, double &min) const
Gets the principal values of the tensor.
Definition: FFaTensor3.C:217
double vonMises() const
Returns the von Mises value of the tensor.
Definition: FFaTensor3.C:129
FFaTensor3 & operator=(const FFaTensor1 &t)
Overloaded assignment operator.
Definition: FFaTensor3.C:56
FFaTensor3 & rotate(const FaMat33 &rotMx)
Rotates the tensor to the given coordinate system.
Definition: FFaTensor3.C:64
FFaTensor3 & translateInertia(const FaVec3 &x, double mass)
Translates an inertia tensor using the parallel-axis theorem.
Definition: FFaTensor3.C:116
FFaTensor3 & makeInertia(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Makes the inertia tensor of a tetrahedron defined by three points.
Definition: FFaTensor3.C:91
FFaTensor3(double t11, double t22, double t33, double t12=0.0, double t13=0.0, double t23=0.0)
Constructor creating a tensor from 3 to 6 component values.
Definition: FFaTensor3.H:52
FFaTensor3(double d=0.0)
Default constructor initializing the tensor to 0 (or given value).
Definition: FFaTensor3.H:40
double maxPrinsipal(bool absMax=false) const
Returns the max or absolute max principal value of the tensor.
Definition: FFaTensor3.C:172
friend FFaTensor3 operator+(const FFaTensor3 &, const FFaTensor3 &)
Global addition operator.
FFaTensor3(const float *t)
Constructor creating a tensor from a float array.
Definition: FFaTensor3.H:42
friend std::ostream & operator<<(std::ostream &, const FFaTensor3 &)
Printing operator.
friend FFaTensor3 operator/(const FFaTensor3 &, double)
Scaling operator, division by a scalar.
double middlePrinsipal() const
Returns the middle principal value of the tensor.
Definition: FFaTensor3.C:187
FFaTensor3 & operator*=(double d)
Scaling operator (multiplication by a scalar).
Definition: FFaTensor3.H:86
FFaTensor3 & operator+=(const FFaTensor3 &t)
Addition operator.
Definition: FFaTensor3.H:72
friend bool operator==(const FFaTensor3 &, const FFaTensor3 &)
Equality operator,.
friend bool operator!=(const FFaTensor3 &, const FFaTensor3 &)
Inequality operator,.
FFaTensor3 & operator-=(const FFaTensor3 &t)
Subtraction operator.
Definition: FFaTensor3.H:79
FFaTensor3(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Constructor creating an intertia tensor of a tetrahedron.
Definition: FFaTensor3.H:58
const double & operator[](int i) const
Zero-based indexing operator (read only).
Definition: FFaTensor3.H:178
double maxShear() const
Returns the max shear value of the tensor.
Definition: FFaTensor3.C:140
double * getPt()
Accesses the internal array (for update).
Definition: FFaTensor3.H:102
void fill(double d)
Initializes all tensor components to the given value.
Definition: FFaTensor3.H:64
FFaTensor3 & operator/=(double d)
Scaling operator (division by a scalar).
Definition: FFaTensor3.H:93
const double * getPt() const
Accesses the internal array (read only).
Definition: FFaTensor3.H:100
friend FFaTensor3 operator*(const FFaTensor3 &, double)
Scaling operator, multiplication of a tensor and a scalar.
std::array< double, 6 > myT
Tensor component values (11,22,33,12,13,23)
Definition: FFaTensor3.H:36
friend std::istream & operator>>(std::istream &, FFaTensor3 &)
Reading operator.
FFaTensor3(const double *t)
Constructor creating a tensor from a double array.
Definition: FFaTensor3.H:44
friend FFaTensor3 operator-(const FFaTensor3 &)
Unary negation operator.
Class for point transformations in 3D space.
Definition: FFaMat33.H:27
Class for positions in 3D space.
Definition: FFaMat34.H:32
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(dp), dimension(:), allocatable v1
Definition: inverseModule.f90:27
real(dp), dimension(:), allocatable v2
Definition: inverseModule.f90:28