IFEM 90A354
Tensor4.h
Go to the documentation of this file.
1// $Id$
2//==============================================================================
12//==============================================================================
13
14#ifndef _TENSOR4_H
15#define _TENSOR4_H
16
17#include <vector>
18#include <iostream>
19
20
26{
27protected:
28 typedef unsigned short int t_ind;
29
32 std::vector<Real> v;
33
35 virtual void redim(t_ind nsd) { n = nsd; m = n*n; }
36
38 virtual std::ostream& print(std::ostream& os) const;
39
40private:
42 inline t_ind index(t_ind i, t_ind j, t_ind k, t_ind l) const
43 {
44 return i-1 + n*(j-1 + n*(k-1 + n*(l-1)));
45 }
46
47public:
49 Tensor4(t_ind nsd = 3, Real scale = Real(1), bool makeJ = false);
53 Tensor4(const std::vector<Real>& x, t_ind nsd = 3);
54
56 void zero() { std::fill(v.begin(),v.end(),Real(0)); }
57
59 operator const std::vector<Real>&() const { return v; }
61 operator std::vector<Real>&() { return v; }
62
64 const Real* ptr() const { return &v.front(); }
65
67 const Real& operator()(t_ind i, t_ind j, t_ind d, t_ind l) const;
69 Real& operator()(t_ind i, t_ind j, t_ind k, t_ind l);
70
72 Tensor4& operator=(const Tensor4& T);
75
78
80 friend std::ostream& operator<<(std::ostream& os, const Tensor4& T)
81 {
82 return T.print(os);
83 }
84};
85
86
91class SymmTensor4 : public Tensor4
92{
93protected:
95 virtual void redim(t_ind nsd);
96
98 virtual std::ostream& print(std::ostream& os) const;
99
100private:
104 inline t_ind index(t_ind i, t_ind j) const
105 {
106 if (i == j)
107 return i-1; // diagonal term
108 else if (n == 2)
109 return 2; // off-diagonal term (2D)
110 else if (n == 1)
111 return 0;
112
113 if (i == j+1 || i+2 == j) std::swap(i,j);
114 return i+2; // upper triangular term (3D)
115 }
116
117public:
119 SymmTensor4(t_ind nsd = 3, bool makeJ = false);
123 SymmTensor4(const std::vector<Real>& x, t_ind nsd = 3);
124
126 const Real& operator()(t_ind i, t_ind j, t_ind d, t_ind l) const;
128 Real& operator()(t_ind i, t_ind j, t_ind k, t_ind l);
129};
130
131#endif
#define Real
The floating point type to use.
Definition ImmersedBoundaries.h:18
Simple class for representing a symmetric fourth-order tensor.
Definition Tensor4.h:92
t_ind index(t_ind i, t_ind j) const
Returns a 0-based array index for the given row and column indices.
Definition Tensor4.h:104
const Real & operator()(t_ind i, t_ind j, t_ind d, t_ind l) const
Index-1 based component reference.
Definition Tensor4.C:142
virtual void redim(t_ind nsd)
Auxilliary method used by the constructors.
Definition Tensor4.C:130
virtual std::ostream & print(std::ostream &os) const
Prints out the tensor to an output stream.
Definition Tensor4.C:117
Simple class for representing a non-symmetric fourth-order tensor.
Definition Tensor4.h:26
Tensor4 & operator=(const Tensor4 &T)
Assignment operator.
Definition Tensor4.C:69
void zero()
Sets this to the 0-tensor.
Definition Tensor4.h:56
virtual void redim(t_ind nsd)
Auxilliary method used by the constructors.
Definition Tensor4.h:35
t_ind n
Number of spatial dimensions for the tensor.
Definition Tensor4.h:30
const Real * ptr() const
Reference through a pointer.
Definition Tensor4.h:64
unsigned short int t_ind
Tensor index type (for convenience)
Definition Tensor4.h:28
virtual std::ostream & print(std::ostream &os) const
Prints out the tensor to an output stream.
Definition Tensor4.C:49
t_ind m
Dimension of the matrix representation.
Definition Tensor4.h:31
friend std::ostream & operator<<(std::ostream &os, const Tensor4 &T)
Output stream operator.
Definition Tensor4.h:80
Tensor4 & operator+=(Real val)
Incrementation operator.
Definition Tensor4.C:90
std::vector< Real > v
The actual tensor component values.
Definition Tensor4.h:32
t_ind index(t_ind i, t_ind j, t_ind k, t_ind l) const
Returns a 0-based array index for the given tensor indices.
Definition Tensor4.h:42
const Real & operator()(t_ind i, t_ind j, t_ind d, t_ind l) const
Index-1 based component reference.
Definition Tensor4.C:57