CellModules
Tensor.hpp
Go to the documentation of this file.
1#ifndef TENSOR
2#define TENSOR
3
4#include <mecacell/mecacell.h>
5
10struct Tensor {
11private:
12 double matrix[3][3] = {{0.,0.,0.},{0.,0.,0.},{0.,0.,0.}};
14public:
18 Tensor() {}
19
26 Tensor(const MecaCell::Vec &f, const MecaCell::Vec &r){
27 for(int i = 0; i < 3; ++i){
28 for(int j = 0; j < 3; ++j){
29 matrix[i][j] = f.coords[i] * r.coords[j];
30 }
31 }
32 }
33
34
42 inline double get(int i, int j) const { return matrix[i][j]; }
43
44
45
46
53 Tensor& operator/=(double div) {
54 for(int i = 0; i < 3; ++i){
55 for(int j = 0; j <3; ++j){
56 matrix[i][j] /= div;
57 }
58 }
59 return(*this);
60 }
61
62
70 for(int i = 0; i < 3; ++i){
71 for(int j = 0; j <3; ++j){
72 matrix[i][j] += t.get(i,j);
73 }
74 }
75 return(*this);
76 }
77
78
84 string to_string(){
85 ostringstream str;
86 for(int i = 0; i < 3; ++i){
87 for(int j = 0; j <3; ++j){
88 str << matrix[i][j] << ", ";
89 }
90 str << "\n";
91 }
92 return str.str();
93 }
94
95};
96
97#endif // TENSOR
general purpose 3D vector/point class.
Definition: vector3D.h:20
std::array< double, 3 > coords
Definition: vector3D.h:22
Represents a 3x3 tensor for stress calculations.
Definition: Tensor.hpp:10
double get(int i, int j) const
Gets the value at the specified position in the tensor.
Definition: Tensor.hpp:42
Tensor()
Default constructor.
Definition: Tensor.hpp:18
double matrix[3][3]
Definition: Tensor.hpp:12
Tensor & operator+=(Tensor t)
Adds another tensor to this tensor.
Definition: Tensor.hpp:69
Tensor(const MecaCell::Vec &f, const MecaCell::Vec &r)
Constructor with force and position vectors.
Definition: Tensor.hpp:26
string to_string()
Converts the tensor to a string representation.
Definition: Tensor.hpp:84
Tensor & operator/=(double div)
Divides the tensor by a scalar value.
Definition: Tensor.hpp:53