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 
13 #ifndef FFA_TENSOR2_H
14 #define FFA_TENSOR2_H
15 
16 #include <array>
17 #include <iostream>
18 
19 class FaVec3;
20 class FaMat33;
21 class FaMat34;
22 class FFaTensor1;
23 class FFaTensor3;
24 
25 
35 {
36  std::array<double,3> myT;
37 
38 public:
40  FFaTensor2(double d = 0.0) { myT.fill(d); }
42  FFaTensor2(const float* t) { for (int i=0; i<3; i++) myT[i] = t[i]; }
44  FFaTensor2(const double* t) { for (int i=0; i<3; i++) myT[i] = t[i]; }
46  FFaTensor2(const FFaTensor1& t);
48  FFaTensor2(const FFaTensor3& t);
50  FFaTensor2(double t11, double t22, double t12 = 0.0) { myT = {t11,t22,t12}; }
51 
53  void fill(double d) { myT.fill(d); }
54 
56  FFaTensor2& operator= (const FFaTensor1& t);
57  FFaTensor2& operator= (const FFaTensor3& t);
58 
61  {
62  for (int i=0; i<3; i++) myT[i] += t.myT[i];
63  return *this;
64  }
65 
68  {
69  for (int i=0; i<3; i++) myT[i] -= t.myT[i];
70  return *this;
71  }
72 
75  {
76  for (int i=0; i<3; i++) myT[i] *= d;
77  return *this;
78  }
79 
82  {
83  for (int i=0; i<3; i++) myT[i] /= d;
84  return *this;
85  }
86 
88  const double* getPt() const { return myT.data(); }
90  double* getPt() { return myT.data(); }
91 
93  const double& operator[] (int i) const;
95  double& operator[] (int i);
96 
97  // Special functions
98 
100  FFaTensor2& rotate(const double ex[2], const double ey[2]);
101 
103  double vonMises() const;
105  double maxShear() const;
107  void maxShear(FaVec3& v) const;
109  double maxPrinsipal(bool absMax = false) const;
111  double minPrinsipal() const;
112 
114  void prinsipalValues(double& max, double& min) const;
116  void prinsipalValues(FaVec3& values, FaMat33& rotation) const;
117 
118  // Global operators
119 
123  friend FFaTensor2 operator+ (const FFaTensor2&, const FFaTensor2&);
125  friend FFaTensor2 operator- (const FFaTensor2&, const FFaTensor2&);
126 
128  friend FFaTensor2 operator* (const FFaTensor2&, double);
130  friend FFaTensor2 operator* (double, const FFaTensor2&);
132  friend FFaTensor2 operator/ (const FFaTensor2&, double);
133 
135  friend bool operator== (const FFaTensor2&, const FFaTensor2&);
137  friend bool operator!= (const FFaTensor2&, const FFaTensor2&);
138 
140  friend FFaTensor3 operator* (const FFaTensor2&, const FaMat33&);
142  friend FFaTensor3 operator* (const FFaTensor2&, const FaMat34&);
144  friend FFaTensor3 operator* (const FaMat33&, const FFaTensor2&);
146  friend FFaTensor3 operator* (const FaMat34&, const FFaTensor2&);
147 
149  friend std::ostream& operator<< (std::ostream& s, const FFaTensor2& b);
151  friend std::istream& operator>> (std::istream& s, FFaTensor2& b);
152 };
153 
154 
155 // --- inline functions ---
156 
157 inline const double& FFaTensor2::operator[] (int i) const
158 {
159 #ifdef FFA_INDEXCHECK
160  if (i < 0 || i > 2)
161  std::cerr <<"FFaTensor2::operator[]: index i="<< i
162  <<" is out of range [0,2]"<< std::endl;
163 #endif
164  return myT[i];
165 }
166 
167 inline double& FFaTensor2::operator[] (int i)
168 {
169 #ifdef FFA_INDEXCHECK
170  if (i < 0 || i > 2)
171  std::cerr <<"FFaTensor2::operator[]: index i="<< i
172  <<" is out of range [0,2]"<< std::endl;
173 #endif
174  return myT[i];
175 }
176 
177 #endif
Class to represent a 1D simple tensor.
Definition: FFaTensor1.H:31
Class to represent a 2D symmetrical tensor.
Definition: FFaTensor2.H:35
FFaTensor2 & operator+=(const FFaTensor2 &t)
Addition operator.
Definition: FFaTensor2.H:60
FFaTensor2 & rotate(const double ex[2], const double ey[2])
Rotates the tensor to the given coordinate system axes.
Definition: FFaTensor2.C:53
FFaTensor2 & operator/=(double d)
Scaling operator (division by a scalar).
Definition: FFaTensor2.H:81
friend FFaTensor2 operator-(const FFaTensor2 &)
Unary negation operator.
FFaTensor2(double d=0.0)
Default constructor initializing the tensor to 0 (or given value).
Definition: FFaTensor2.H:40
const double & operator[](int i) const
Zero-based indexing operator (read only).
Definition: FFaTensor2.H:157
FFaTensor2 & operator*=(double d)
Scaling operator (multiplication by a scalar).
Definition: FFaTensor2.H:74
void prinsipalValues(double &max, double &min) const
Gets the principal values of the tensor.
Definition: FFaTensor2.C:130
friend FFaTensor2 operator+(const FFaTensor2 &, const FFaTensor2 &)
Global addition operator.
FFaTensor2(const double *t)
Constructor creating a tensor from a double array.
Definition: FFaTensor2.H:44
FFaTensor2(const float *t)
Constructor creating a tensor from a float array.
Definition: FFaTensor2.H:42
double maxShear() const
Returns the max shear value of the tensor.
Definition: FFaTensor2.C:70
friend std::istream & operator>>(std::istream &s, FFaTensor2 &b)
Reading operator.
const double * getPt() const
Accesses the internal array (read only).
Definition: FFaTensor2.H:88
double * getPt()
Accesses the internal array (for update).
Definition: FFaTensor2.H:90
friend std::ostream & operator<<(std::ostream &s, const FFaTensor2 &b)
Printing operator.
FFaTensor2 & operator=(const FFaTensor1 &t)
Overloaded assignment operator.
Definition: FFaTensor2.C:45
void fill(double d)
Initializes all tensor components to the given value.
Definition: FFaTensor2.H:53
double minPrinsipal() const
Returns the min principal value of the tensor.
Definition: FFaTensor2.C:116
double maxPrinsipal(bool absMax=false) const
Returns the max or absolute max principal value of the tensor.
Definition: FFaTensor2.C:102
friend FFaTensor2 operator/(const FFaTensor2 &, double)
Scaling operator, division by a scalar.
FFaTensor2 & operator-=(const FFaTensor2 &t)
Subtraction operator.
Definition: FFaTensor2.H:67
FFaTensor2(double t11, double t22, double t12=0.0)
Constructor creating a tensor from 2 or 3 component values.
Definition: FFaTensor2.H:50
friend bool operator==(const FFaTensor2 &, const FFaTensor2 &)
Equality operator,.
friend FFaTensor2 operator*(const FFaTensor2 &, double)
Scaling operator, multiplication of a tensor and a scalar.
double vonMises() const
Returns the von Mises value of the tensor.
Definition: FFaTensor2.C:60
std::array< double, 3 > myT
Tensor component values (11,22,12)
Definition: FFaTensor2.H:36
friend bool operator!=(const FFaTensor2 &, const FFaTensor2 &)
Inequality operator,.
Class to represent a 3D symmetric tensor.
Definition: FFaTensor3.H:35
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(sp), dimension(:,:,:), pointer b
Definition: diffractionModule.f90:22