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 
8 #ifndef FFA_TENSOR3_H
9 #define FFA_TENSOR3_H
10 
11 #include <array>
12 #include <iostream>
13 
14 class FaVec3;
15 class FaMat33;
16 class FaMat34;
17 class FFaTensor1;
18 class FFaTensor2;
19 
20 
28 {
29  std::array<double,6> myT;
30 
31 public:
32 
33  // Constructors
34 
35  FFaTensor3(double d = 0.0) { myT.fill(d); }
36  FFaTensor3(const float* t) { for (int i=0; i<6; i++) myT[i] = t[i]; }
37  FFaTensor3(const double* t) { for (int i=0; i<6; i++) myT[i] = t[i]; }
38  FFaTensor3(const FFaTensor3& t) { for (int i=0; i<6; i++) myT[i] = t.myT[i]; }
39  FFaTensor3(const FFaTensor2& t);
40  FFaTensor3(const FFaTensor1& t);
41  FFaTensor3(const FaVec3& v);
42  FFaTensor3(double t11 , double t22 , double t33,
43  double t12 = 0.0, double t13 = 0.0, double t23 = 0.0)
44  {
45  myT = { t11, t22, t33, t12, t13, t23 };
46  }
47  FFaTensor3(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3)
48  {
49  this->makeInertia(v1,v2,v3);
50  }
51 
52  void fill(double d) { myT.fill(d); }
53 
54  // Local operators
55 
56  FFaTensor3& operator= (const FFaTensor3& t);
57  FFaTensor3& operator= (const FFaTensor1& t);
58  FFaTensor3& operator= (const FFaTensor2& t);
59 
61  {
62  for (int i=0; i<6; i++) myT[i] += t.myT[i];
63  return *this;
64  }
65 
67  {
68  for (int i=0; i<6; i++) myT[i] -= t.myT[i];
69  return *this;
70  }
71 
73  {
74  for (int i=0; i<6; i++) myT[i] *= d;
75  return *this;
76  }
77 
79  {
80  for (int i=0; i<6; i++) myT[i] /= d;
81  return *this;
82  }
83 
84  // Access to internal array
85 
86  const double* getPt() const { return myT.data(); }
87  double* getPt() { return myT.data(); }
88 
89  // Indexing
90 
91  const double& operator[] (int i) const;
92  double& operator[] (int i);
93 
94  // Special functions
95 
96  FFaTensor3& rotate(const FaMat33& rotMx);
97  FFaTensor3& rotate(const FaMat34& rotMx);
98 
99  FFaTensor3& makeInertia(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3);
100  FFaTensor3& translateInertia(const FaVec3& x, double mass);
101 
102  double vonMises() const;
103  double maxShear() const;
104  void maxShear(FaVec3& v) const;
105  double maxPrinsipal(bool absMax = false) const;
106  double middlePrinsipal() const;
107  double minPrinsipal() const;
108  void prinsipalValues(double& max, double& middle, double& min) const;
109  void prinsipalValues(FaVec3& values, FaMat33& rotation) const;
110 
111  // Global operators
112 
113  friend FFaTensor3 operator- (const FFaTensor3&);
114  friend FFaTensor3 operator+ (const FFaTensor3&, const FFaTensor3&);
115  friend FFaTensor3 operator- (const FFaTensor3&, const FFaTensor3&);
116  // Scaling by scalar
117  friend FFaTensor3 operator* (const FFaTensor3&, double);
118  friend FFaTensor3 operator* (double, const FFaTensor3&);
119  friend FFaTensor3 operator/ (const FFaTensor3&, double);
120  // Equality
121  friend bool operator== (const FFaTensor3&, const FFaTensor3&);
122  friend bool operator!= (const FFaTensor3&, const FFaTensor3&);
123  // Rotation
124  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat33&);
125  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat34&);
126  friend FFaTensor3 operator* (const FaMat33& , const FFaTensor3&);
127  friend FFaTensor3 operator* (const FaMat34& , const FFaTensor3&);
128  // Writing and reading
129  friend std::ostream& operator<< (std::ostream&, const FFaTensor3&);
130  friend std::istream& operator>> (std::istream&, FFaTensor3&);
131 };
132 
133 
134 // --- inline functions ---
135 
136 inline const double& FFaTensor3::operator[] (int i) const
137 {
138 #ifdef FFA_INDEXCHECK
139  if (i < 0 || i > 5)
140  std::cerr <<"FFaTensor3::operator[]: index i="<< i
141  <<" is out of range [0,5]"<< std::endl;
142 #endif
143  return myT[i];
144 }
145 
146 inline double& FFaTensor3::operator[] (int i)
147 {
148 #ifdef FFA_INDEXCHECK
149  if (i < 0 || i > 5)
150  std::cerr <<"FFaTensor3::operator[]: index i="<< i
151  <<" is out of range [0,5]"<< std::endl;
152 #endif
153  return myT[i];
154 }
155 
156 #endif
Definition: FFaTensor1.H:24
Definition: FFaTensor2.H:28
Definition: FFaTensor3.H:28
double minPrinsipal() const
Definition: FFaTensor3.C:225
void prinsipalValues(double &max, double &middle, double &min) const
Definition: FFaTensor3.C:242
double vonMises() const
Definition: FFaTensor3.C:144
FFaTensor3 & rotate(const FaMat33 &rotMx)
Definition: FFaTensor3.C:71
FFaTensor3 & translateInertia(const FaVec3 &x, double mass)
Definition: FFaTensor3.C:127
FFaTensor3 & makeInertia(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Definition: FFaTensor3.C:98
FFaTensor3(double t11, double t22, double t33, double t12=0.0, double t13=0.0, double t23=0.0)
Definition: FFaTensor3.H:42
FFaTensor3(double d=0.0)
Definition: FFaTensor3.H:35
double maxPrinsipal(bool absMax=false) const
Definition: FFaTensor3.C:191
friend FFaTensor3 operator+(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:289
FFaTensor3(const float *t)
Definition: FFaTensor3.H:36
friend std::ostream & operator<<(std::ostream &, const FFaTensor3 &)
Definition: FFaTensor3.C:384
friend FFaTensor3 operator/(const FFaTensor3 &, double)
Definition: FFaTensor3.C:327
double middlePrinsipal() const
Definition: FFaTensor3.C:208
FFaTensor3 & operator*=(double d)
Definition: FFaTensor3.H:72
FFaTensor3 & operator+=(const FFaTensor3 &t)
Definition: FFaTensor3.H:60
FFaTensor3(const FFaTensor3 &t)
Definition: FFaTensor3.H:38
friend bool operator==(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:337
friend bool operator!=(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:348
FFaTensor3 & operator-=(const FFaTensor3 &t)
Definition: FFaTensor3.H:66
FFaTensor3(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Definition: FFaTensor3.H:47
const double & operator[](int i) const
Definition: FFaTensor3.H:136
double maxShear() const
Definition: FFaTensor3.C:156
double * getPt()
Definition: FFaTensor3.H:87
void fill(double d)
Definition: FFaTensor3.H:52
FFaTensor3 & operator/=(double d)
Definition: FFaTensor3.H:78
const double * getPt() const
Definition: FFaTensor3.H:86
friend FFaTensor3 operator*(const FFaTensor3 &, double)
Definition: FFaTensor3.C:311
std::array< double, 6 > myT
Definition: FFaTensor3.H:29
friend std::istream & operator>>(std::istream &, FFaTensor3 &)
Definition: FFaTensor3.C:391
FFaTensor3(const double *t)
Definition: FFaTensor3.H:37
friend FFaTensor3 operator-(const FFaTensor3 &)
Definition: FFaTensor3.C:282
FFaTensor3 & operator=(const FFaTensor3 &t)
Definition: FFaTensor3.C:41
Definition: FFaMat33.H:15
Definition: FFaMat34.H:16
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
integer(ptr), save, private x
Definition: extCtrlSysRoutinesModule.f90:16
real(dp), dimension(:), allocatable v1
Definition: inverseModule.f90:27
real(dp), dimension(:), allocatable v2
Definition: inverseModule.f90:28