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 <iostream>
12 
13 class FaVec3;
14 class FaMat33;
15 class FaMat34;
16 class FFaTensor1;
17 class FFaTensor2;
18 
19 
27 {
28  double myT[6];
29 
30 public:
31 
32  // Constructors
33 
34  FFaTensor3() { for (int i=0; i<6; i++) myT[i] = 0.0; }
35  FFaTensor3(double d) { for (int i=0; i<6; i++) myT[i] = 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[0] = t11; myT[1] = t22; myT[2] = t33;
46  myT[3] = t12; myT[4] = t13; myT[5] = t23;
47  }
48  FFaTensor3(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3)
49  {
50  this->makeInertia(v1,v2,v3);
51  }
52 
53  // Local operators
54 
55  FFaTensor3& operator= (const FFaTensor3& t);
56  FFaTensor3& operator= (const FFaTensor1& t);
57  FFaTensor3& operator= (const FFaTensor2& t);
58 
60  {
61  for (int i=0; i<6; i++) myT[i] += t.myT[i];
62  return *this;
63  }
64 
66  {
67  for (int i=0; i<6; i++) myT[i] -= t.myT[i];
68  return *this;
69  }
70 
72  {
73  for (int i=0; i<6; i++) myT[i] *= d;
74  return *this;
75  }
76 
78  {
79  for (int i=0; i<6; i++) myT[i] /= d;
80  return *this;
81  }
82 
83  // Access to internal array
84 
85  const double* getPt() const { return myT; }
86  double* getPt() { return myT; }
87 
88  // Indexing
89 
90  const double& operator[] (int i) const;
91  double& operator[] (int i);
92 
93  // Special functions
94 
95  FFaTensor3& rotate(const FaMat33& rotMx);
96  FFaTensor3& rotate(const FaMat34& rotMx);
97 
98  FFaTensor3& makeInertia(const FaVec3& v1, const FaVec3& v2, const FaVec3& v3);
99  FFaTensor3& translateInertia(const FaVec3& x, double mass);
100 
101  double vonMises() const;
102  double maxShear() const;
103  void maxShear(FaVec3& v) const;
104  double maxPrinsipal(bool absMax = false) const;
105  double middlePrinsipal() const;
106  double minPrinsipal() const;
107  void prinsipalValues(double& max, double& middle, double& min) const;
108  void prinsipalValues(FaVec3& values, FaMat33& rotation) const;
109 
110  // Global operators
111 
112  friend FFaTensor3 operator- (const FFaTensor3&);
113  friend FFaTensor3 operator+ (const FFaTensor3&, const FFaTensor3&);
114  friend FFaTensor3 operator- (const FFaTensor3&, const FFaTensor3&);
115  // Scaling by scalar
116  friend FFaTensor3 operator* (const FFaTensor3&, double);
117  friend FFaTensor3 operator* (double, const FFaTensor3&);
118  friend FFaTensor3 operator/ (const FFaTensor3&, double);
119  // Equality
120  friend bool operator== (const FFaTensor3&, const FFaTensor3&);
121  friend bool operator!= (const FFaTensor3&, const FFaTensor3&);
122  // Rotation
123  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat33&);
124  friend FFaTensor3 operator* (const FFaTensor3&, const FaMat34&);
125  friend FFaTensor3 operator* (const FaMat33& , const FFaTensor3&);
126  friend FFaTensor3 operator* (const FaMat34& , const FFaTensor3&);
127  // Writing and reading
128  friend std::ostream& operator<< (std::ostream&, const FFaTensor3&);
129  friend std::istream& operator>> (std::istream&, FFaTensor3&);
130 };
131 
132 
133 // --- inline functions ---
134 
135 inline const double& FFaTensor3::operator[] (int i) const
136 {
137 #ifdef FFA_INDEXCHECK
138  if (i < 0 || i > 5)
139  std::cerr <<"FFaTensor3::operator[]: index i="<< i <<" is out of range [0,5]"
140  << std::endl;
141 #endif
142  return myT[i];
143 }
144 
145 inline double& FFaTensor3::operator[] (int i)
146 {
147 #ifdef FFA_INDEXCHECK
148  if (i < 0 || i > 5)
149  std::cerr <<"FFaTensor3::operator[]: index i="<< i <<" is out of range [0,5]"
150  << std::endl;
151 #endif
152  return myT[i];
153 }
154 
155 #endif
Definition: FFaTensor1.H:24
Definition: FFaTensor2.H:27
Definition: FFaTensor3.H:27
double minPrinsipal() const
Definition: FFaTensor3.C:226
double myT[6]
Definition: FFaTensor3.H:28
void prinsipalValues(double &max, double &middle, double &min) const
Definition: FFaTensor3.C:243
double vonMises() const
Definition: FFaTensor3.C:145
FFaTensor3(double d)
Definition: FFaTensor3.H:35
FFaTensor3 & rotate(const FaMat33 &rotMx)
Definition: FFaTensor3.C:72
FFaTensor3 & translateInertia(const FaVec3 &x, double mass)
Definition: FFaTensor3.C:128
FFaTensor3 & makeInertia(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Definition: FFaTensor3.C:99
FFaTensor3(double t11, double t22, double t33, double t12=0.0, double t13=0.0, double t23=0.0)
Definition: FFaTensor3.H:42
double maxPrinsipal(bool absMax=false) const
Definition: FFaTensor3.C:192
friend FFaTensor3 operator+(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:290
FFaTensor3()
Definition: FFaTensor3.H:34
FFaTensor3(const float *t)
Definition: FFaTensor3.H:36
friend std::ostream & operator<<(std::ostream &, const FFaTensor3 &)
Definition: FFaTensor3.C:383
friend FFaTensor3 operator/(const FFaTensor3 &, double)
Definition: FFaTensor3.C:328
double middlePrinsipal() const
Definition: FFaTensor3.C:209
FFaTensor3 & operator*=(double d)
Definition: FFaTensor3.H:71
FFaTensor3 & operator+=(const FFaTensor3 &t)
Definition: FFaTensor3.H:59
FFaTensor3(const FFaTensor3 &t)
Definition: FFaTensor3.H:38
friend bool operator==(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:338
friend bool operator!=(const FFaTensor3 &, const FFaTensor3 &)
Definition: FFaTensor3.C:349
FFaTensor3 & operator-=(const FFaTensor3 &t)
Definition: FFaTensor3.H:65
FFaTensor3(const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Definition: FFaTensor3.H:48
const double & operator[](int i) const
Definition: FFaTensor3.H:135
double maxShear() const
Definition: FFaTensor3.C:157
double * getPt()
Definition: FFaTensor3.H:86
FFaTensor3 & operator/=(double d)
Definition: FFaTensor3.H:77
const double * getPt() const
Definition: FFaTensor3.H:85
friend FFaTensor3 operator*(const FFaTensor3 &, double)
Definition: FFaTensor3.C:312
friend std::istream & operator>>(std::istream &, FFaTensor3 &)
Definition: FFaTensor3.C:390
FFaTensor3(const double *t)
Definition: FFaTensor3.H:37
friend FFaTensor3 operator-(const FFaTensor3 &)
Definition: FFaTensor3.C:283
FFaTensor3 & operator=(const FFaTensor3 &t)
Definition: FFaTensor3.C:42
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