A.I.M.S


tensor.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * 2nd order tensor class
36  */
37 #ifndef AIMS_MATH_TENSOR_H
38 #define AIMS_MATH_TENSOR_H
39 
41 #include <aims/math/trieder.h>
42 
43 
44 class Tensor;
45 
46 AIMSDATA_API int operator == (const Tensor& thing1, const Tensor& thing2);
47 AIMSDATA_API float norm(const Tensor& thing);
48 AIMSDATA_API std::ostream& operator << (std::ostream& os, const Tensor& thing);
49 
50 
52 {
53  public:
54  Tensor() { }
55  Tensor( const Trieder& trieder, const Point3df& eigenvalue )
56  : _trieder( trieder ), _eigenvalue( eigenvalue )
57  { }
58  Tensor( const AimsVector<float,6>& coef )
59  : _coef( coef )
60  { }
61  Tensor(const Tensor& other) : _trieder( other._trieder ),
62  _eigenvalue( other._eigenvalue ),
63  _coef( other._coef ),
64  _trace( other._trace )
65  { }
66  virtual ~Tensor() { }
67 
68  const Trieder& trieder() const { return _trieder; }
69  Trieder& trieder() { return _trieder; }
70 
71  const Point3df& eigenvalue() const { return _eigenvalue; }
72  Point3df& eigenvalue() { return _eigenvalue; }
73 
74  const AimsVector<float,6>& coef() const { return _coef; }
75  AimsVector<float,6>& coef() { return _coef; }
76 
77  const float& trace() const { return _trace; }
78  float& trace() { return _trace; }
79 
80  float diffusion( const Point3df& dir ) const;
81 
82  float meanDiffusivity() const;
83 
84  float dot( const Tensor& other ) const;
85 
86  friend
87  int operator == (const Tensor& thing1, const Tensor& thing2);
88 
89  friend
90  std::ostream& operator << (std::ostream& os, const Tensor& thing);
91 
92  protected:
96  float _trace;
97 };
98 
99 
100 inline
101 float Tensor::diffusion( const Point3df& dir ) const
102 {
103  return _coef.item(0) * dir.item(0) * dir.item(0) +
104  _coef.item(3) * dir.item(1) * dir.item(1) +
105  _coef.item(5) * dir.item(2) * dir.item(2) +
106  2.0 * _coef.item(1) * dir.item(0) * dir.item(1) +
107  2.0 * _coef.item(2) * dir.item(0) * dir.item(2) +
108  2.0 * _coef.item(4) * dir.item(1) * dir.item(2);
109 }
110 
111 
112 inline
113 float Tensor::dot( const Tensor& other ) const
114 {
115  return coef().item(0) * other.coef().item(0) +
116  coef().item(3) * other.coef().item(3) +
117  coef().item(5) * other.coef().item(5) +
118  2.0 * coef().item(1) * other.coef().item(1) +
119  2.0 * coef().item(2) * other.coef().item(2) +
120  2.0 * coef().item(4) * other.coef().item(4) ;
121 }
122 
123 
124 inline
126 {
127  return ( coef().item(0) + coef().item(3) + coef().item(5) ) / 3.0;
128 }
129 
130 
131 inline
132 int operator == (const Tensor& thing1, const Tensor& thing2)
133 {
134  return thing1.trieder() == thing2.trieder() &&
135  thing1.eigenvalue() == thing2.eigenvalue() &&
136  thing1.coef() == thing2.coef();
137 }
138 
139 
140 inline
141 float norm(const Tensor& thing)
142 {
143  return sqrt( thing.coef().item(0) * thing.coef().item(0) +
144  thing.coef().item(3) * thing.coef().item(3) +
145  thing.coef().item(5) * thing.coef().item(5) +
146  2.0 * thing.coef().item(1) * thing.coef().item(1) +
147  2.0 * thing.coef().item(2) * thing.coef().item(2) +
148  2.0 * thing.coef().item(4) * thing.coef().item(4) );
149 }
150 
151 
152 inline
153 std::ostream& operator << (std::ostream& os, const Tensor& thing)
154 {
155  os << "{trieder=" << thing.trieder()
156  << ",eigenvalue=" << thing.eigenvalue()
157  << ",coef=" << thing.coef()
158  << ",trace=" << thing.trace();
159  os << "}";
160  return os;
161 }
162 
163 
164 #endif
AimsVector< float, 6 > _coef
Definition: tensor.h:95
float _trace
Definition: tensor.h:96
float meanDiffusivity() const
Definition: tensor.h:125
float diffusion(const Point3df &dir) const
Definition: tensor.h:101
#define AIMSDATA_API
Tensor(const Tensor &other)
Definition: tensor.h:61
Tensor()
Definition: tensor.h:54
float dot(const Tensor &other) const
Definition: tensor.h:113
const Point3df & eigenvalue() const
Definition: tensor.h:71
float & trace()
Definition: tensor.h:78
virtual ~Tensor()
Definition: tensor.h:66
const float & trace() const
Definition: tensor.h:77
const AimsVector< float, 6 > & coef() const
Definition: tensor.h:74
Tensor(const AimsVector< float, 6 > &coef)
Definition: tensor.h:58
Point3df _eigenvalue
Definition: tensor.h:94
const Trieder & trieder() const
Definition: tensor.h:68
const T & item(int d) const
Get a const reference to the dth item.
Definition: vector.h:605
Definition: tensor.h:51
Tensor(const Trieder &trieder, const Point3df &eigenvalue)
Definition: tensor.h:55
AimsVector< float, 6 > & coef()
Definition: tensor.h:75
Trieder _trieder
Definition: tensor.h:93
AIMSDATA_API float norm(const Tensor &thing)
Definition: tensor.h:141
Point3df & eigenvalue()
Definition: tensor.h:72
Trieder & trieder()
Definition: tensor.h:69
AIMSDATA_API std::ostream & operator<<(std::ostream &os, const Tensor &thing)
Definition: tensor.h:153
AIMSDATA_API int operator==(const Tensor &thing1, const Tensor &thing2)
Definition: tensor.h:132