FEDEM Solver  R8.0
Source code of the dynamics solver
FFaTensor2.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_TENSOR2_H
9 #define FFA_TENSOR2_H
10 
11 #include <iostream>
12 
13 class FaVec3;
14 class FaMat33;
15 class FaMat34;
16 class FFaTensor1;
17 class FFaTensor3;
18 
19 
27 {
28  double myT[3];
29 
30 public:
31 
32  // Constructors
33 
34  FFaTensor2() { myT[0] = myT[1] = myT[2] = 0.0; }
35  FFaTensor2(double d) { myT[0] = myT[1] = myT[2] = d; }
36  FFaTensor2(const float* t) { for (int i=0; i<3; i++) myT[i] = t[i]; }
37  FFaTensor2(const double* t) { for (int i=0; i<3; i++) myT[i] = t[i]; }
38  FFaTensor2(const FFaTensor2& t) { for (int i=0; i<3; i++) myT[i] = t.myT[i]; }
39  FFaTensor2(const FFaTensor1& t);
40  FFaTensor2(const FFaTensor3& t);
41  FFaTensor2(double t11, double t22, double t12 = 0.0)
42  { myT[0] = t11; myT[1] = t22; myT[2] = t12; }
43 
44  // Local operators
45 
46  FFaTensor2& operator= (const FFaTensor1& t);
47  FFaTensor2& operator= (const FFaTensor2& t);
48  FFaTensor2& operator= (const FFaTensor3& t);
49 
51  {
52  for (int i=0; i<3; i++) myT[i] += t.myT[i];
53  return *this;
54  }
55 
57  {
58  for (int i=0; i<3; i++) myT[i] -= t.myT[i];
59  return *this;
60  }
61 
63  {
64  for (int i=0; i<3; i++) myT[i] *= d;
65  return *this;
66  }
67 
69  {
70  for (int i=0; i<3; i++) myT[i] /= d;
71  return *this;
72  }
73 
74  // Access to internal array
75 
76  const double* getPt() const { return myT; }
77  double* getPt() { return myT; }
78 
79  // Indexing
80 
81  const double& operator[] (int i) const;
82  double& operator[] (int i);
83 
84  // Special functions
85 
86  FFaTensor2& rotate(const double ex[2], const double ey[2]);
87 
88  double vonMises() const;
89  double maxShear() const;
90  void maxShear(FaVec3& v) const;
91  double maxPrinsipal(bool absMax = false) const;
92  double minPrinsipal() const;
93  void prinsipalValues(double& max, double& min) const;
94  void prinsipalValues(FaVec3& values, FaMat33& rotation) const;
95 
96  // Global operators
97 
98  friend FFaTensor2 operator- (const FFaTensor2&);
99  friend FFaTensor2 operator+ (const FFaTensor2&, const FFaTensor2&);
100  friend FFaTensor2 operator- (const FFaTensor2&, const FFaTensor2&);
101  // Scaling by scalar
102  friend FFaTensor2 operator* (const FFaTensor2&, double);
103  friend FFaTensor2 operator* (double, const FFaTensor2&);
104  friend FFaTensor2 operator/ (const FFaTensor2&, double);
105  // Equality
106  friend bool operator== (const FFaTensor2&, const FFaTensor2&);
107  friend bool operator!= (const FFaTensor2&, const FFaTensor2&);
108  // Rotation
109  friend FFaTensor3 operator* (const FFaTensor2&, const FaMat33&);
110  friend FFaTensor3 operator* (const FFaTensor2&, const FaMat34&);
111  friend FFaTensor3 operator* (const FaMat33& , const FFaTensor2&);
112  friend FFaTensor3 operator* (const FaMat34& , const FFaTensor2&);
113  // Writing and reading
114  friend std::ostream& operator<< (std::ostream& s, const FFaTensor2& b);
115  friend std::istream& operator>> (std::istream& s, FFaTensor2& b);
116 };
117 
118 
119 // --- inline functions ---
120 
121 inline const double& FFaTensor2::operator[] (int i) const
122 {
123 #ifdef FFA_INDEXCHECK
124  if (i < 0 || i > 2)
125  std::cerr <<"FFaTensor2::operator[]: index i="<< i <<" is out of range [0,2]"
126  << std::endl;
127 #endif
128  return myT[i];
129 }
130 
131 inline double& FFaTensor2::operator[] (int i)
132 {
133 #ifdef FFA_INDEXCHECK
134  if (i < 0 || i > 2)
135  std::cerr <<"FFaTensor2::operator[]: index i="<< i <<" is out of range [0,2]"
136  << std::endl;
137 #endif
138  return myT[i];
139 }
140 
141 #endif
Definition: FFaTensor1.H:24
Definition: FFaTensor2.H:27
FFaTensor2 & operator+=(const FFaTensor2 &t)
Definition: FFaTensor2.H:50
FFaTensor2 & rotate(const double ex[2], const double ey[2])
Definition: FFaTensor2.C:65
FFaTensor2 & operator/=(double d)
Definition: FFaTensor2.H:68
FFaTensor2()
Definition: FFaTensor2.H:34
friend FFaTensor2 operator-(const FFaTensor2 &)
Definition: FFaTensor2.C:190
double myT[3]
Definition: FFaTensor2.H:28
const double & operator[](int i) const
Definition: FFaTensor2.H:121
FFaTensor2 & operator*=(double d)
Definition: FFaTensor2.H:62
void prinsipalValues(double &max, double &min) const
Definition: FFaTensor2.C:151
friend FFaTensor2 operator+(const FFaTensor2 &, const FFaTensor2 &)
Definition: FFaTensor2.C:196
FFaTensor2(const double *t)
Definition: FFaTensor2.H:37
FFaTensor2(const float *t)
Definition: FFaTensor2.H:36
double maxShear() const
Definition: FFaTensor2.C:87
friend std::istream & operator>>(std::istream &s, FFaTensor2 &b)
Definition: FFaTensor2.C:281
const double * getPt() const
Definition: FFaTensor2.H:76
double * getPt()
Definition: FFaTensor2.H:77
friend std::ostream & operator<<(std::ostream &s, const FFaTensor2 &b)
Definition: FFaTensor2.C:275
FFaTensor2(double d)
Definition: FFaTensor2.H:35
FFaTensor2 & operator=(const FFaTensor1 &t)
Definition: FFaTensor2.C:53
double minPrinsipal() const
Definition: FFaTensor2.C:136
double maxPrinsipal(bool absMax=false) const
Definition: FFaTensor2.C:121
friend FFaTensor2 operator/(const FFaTensor2 &, double)
Definition: FFaTensor2.C:222
FFaTensor2 & operator-=(const FFaTensor2 &t)
Definition: FFaTensor2.H:56
FFaTensor2(double t11, double t22, double t12=0.0)
Definition: FFaTensor2.H:41
friend bool operator==(const FFaTensor2 &, const FFaTensor2 &)
Definition: FFaTensor2.C:231
friend FFaTensor2 operator*(const FFaTensor2 &, double)
Definition: FFaTensor2.C:211
double vonMises() const
Definition: FFaTensor2.C:76
FFaTensor2(const FFaTensor2 &t)
Definition: FFaTensor2.H:38
friend bool operator!=(const FFaTensor2 &, const FFaTensor2 &)
Definition: FFaTensor2.C:237
Definition: FFaTensor3.H:27
Definition: FFaMat33.H:15
Definition: FFaMat34.H:16
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(sp), dimension(:,:,:), pointer b
Definition: diffractionModule.f90:22