SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tensor.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 ///
31 ///@file Tensor.h
32 ///@brief Symmetric, positive definite tensors (diffusion, conductivity)
33 ///
34 ///@author
35 /// David Weinstein
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date March 2001
39 ///
40 
41 #ifndef Geometry_Tensor_h
42 #define Geometry_Tensor_h 1
43 
46 #include <Core/Containers/Array1.h>
49 
50 #include <string>
51 #include <iosfwd>
52 #include <vector>
53 
54 
55 namespace SCIRun {
56 
57  class Piostream;
58  class RigorousTest;
59  class TypeDescription;
60 
61  namespace Core {
62 
63  namespace Geometry {
64 
66 
67 public:
68  Tensor();
69  Tensor(const Tensor&);
70  explicit Tensor(int);
71  explicit Tensor(double);
72  Tensor(double, double, double, double, double, double);
73  explicit Tensor(const Array1<double> &); // 6 values
74  explicit Tensor(const std::vector<double> &); // 6 values
75  explicit Tensor(const double *); // 6 values
76  explicit Tensor(const double **);
77  Tensor(const Vector&, const Vector&, const Vector&);
78  Tensor& operator=(const Tensor&);
79  Tensor& operator=(const double&);
80 
81  bool operator==(const Tensor&) const;
82  bool operator!=(const Tensor&) const;
83 
84  Tensor operator+(const Tensor&) const;
85  Tensor& operator+=(const Tensor&);
86  Tensor operator-(const Tensor&) const;
87  Tensor& operator-=(const Tensor&);
88  Tensor operator*(const double) const;
89  Vector operator*(const Vector) const;
90 
91  static std::string type_name(int i = -1);
92 
93  double mat_[3][3];
94 
95  void build_mat_from_eigens();
96  void build_eigens_from_mat();
97  void get_eigenvectors(Vector &e1, Vector &e2, Vector &e3);
98  const Vector &get_eigenvector1() { ASSERT(have_eigens_); return e1_; }
99  const Vector &get_eigenvector2() { ASSERT(have_eigens_); return e2_; }
100  const Vector &get_eigenvector3() { ASSERT(have_eigens_); return e3_; }
101  void get_eigenvalues(double &l1, double &l2, double &l3);
102 
103  double norm();
104 
105  bool have_eigens() { return have_eigens_; }
106 
107  void set_eigens(const Vector &e1, const Vector &e2, const Vector &e3);
108 
109  // This directly sets the eigenvectors and values in the tensor. It
110  // is meant to be used in conjunction with custom eigenvector/value
111  // computation, such as that found in the TEEM package.
112  void set_outside_eigens(const Vector &e1, const Vector &e2,
113  const Vector &e3,
114  double v1, double v2, double v3);
115 
116  /// support dynamic compilation
117  static const std::string& get_h_file_path();
118 
119  friend SCISHARE void Pio(Piostream&, Tensor&);
120 
121  inline double xx() const { return mat_[0][0]; }
122  inline double xy() const { return mat_[1][0]; }
123  inline double xz() const { return mat_[2][0]; }
124  inline double yy() const { return mat_[1][1]; }
125  inline double yz() const { return mat_[2][1]; }
126  inline double zz() const { return mat_[2][2]; }
127 
128 private:
129  Vector e1_, e2_, e3_; // these are already scaled by the eigenvalues
130  double l1_, l2_, l3_;
131  bool have_eigens_;
132 };
133 
134 SCISHARE void Pio(Piostream&, Tensor&);
135 
136 inline bool operator<(Tensor t1, Tensor t2)
137 {
138  return(t1.norm()<t2.norm());
139 }
140 
141 inline bool operator<=(Tensor t1, Tensor t2)
142 {
143  return(t1.norm()<=t2.norm());
144 }
145 
146 inline bool operator>(Tensor t1, Tensor t2)
147 {
148  return(t1.norm()>t2.norm());
149 }
150 
151 inline bool operator>=(Tensor t1, Tensor t2)
152 {
153  return(t1.norm()>=t2.norm());
154 }
155 
156 inline
157 Tensor operator*(double d, const Tensor &t) {
158  return t*d;
159 }
160 
161 SCISHARE std::ostream& operator<<(std::ostream& os, const Tensor& t);
162 SCISHARE std::istream& operator>>(std::istream& os, Tensor& t);
163 
165  }}
166 
167 
168 
169 } // End namespace SCIRun
170 
171 #endif // Geometry_Tensor_h
bool operator<=(Tensor t1, Tensor t2)
Definition: Tensor.h:141
double xx() const
Definition: Tensor.h:121
double zz() const
Definition: Tensor.h:126
SCISHARE const TypeDescription * get_type_description(Tensor *)
Definition: Tensor.cc:405
Interface to dynamic 1D array class.
Definition: Persistent.h:89
double yz() const
Definition: Tensor.h:125
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
const Vector & get_eigenvector1()
Definition: Tensor.h:98
double yy() const
Definition: Tensor.h:124
Utility for specifying data invariants (Assertions)
Point operator+(const Vector &v, const Point &p)
Definition: Point.h:186
#define ASSERT(condition)
Definition: Assert.h:110
double norm()
Definition: Tensor.cc:242
SCISHARE std::istream & operator>>(std::istream &os, Point &p)
Definition: Point.cc:105
Definition: Vector.h:63
const Vector & get_eigenvector3()
Definition: Tensor.h:100
double xz() const
Definition: Tensor.h:123
SCISHARE std::ostream & operator<<(std::ostream &os, const Point &p)
Definition: Point.cc:99
bool have_eigens()
Definition: Tensor.h:105
std::vector< CellIndex< T > > operator+=(const std::vector< CellIndex< T > > &l, const std::vector< CellIndex< T > > &r)
Definition: FieldIndex.h:117
bool operator>=(Tensor t1, Tensor t2)
Definition: Tensor.h:151
Definition: Tensor.h:65
SCISHARE bool operator!=(const Point &p1, const Point &p2)
Definition: Point.cc:49
double xy() const
Definition: Tensor.h:122
ColumnMatrix operator-(const ColumnMatrix &A, const ColumnMatrix &B)
Definition: MatrixOperations.cc:104
Definition: ParallelLinearAlgebraTests.cc:751
bool operator>(Tensor t1, Tensor t2)
Definition: Tensor.h:146
const Vector & get_eigenvector2()
Definition: Tensor.h:99
SCISHARE bool operator==(const Point &p1, const Point &p2)
Definition: Point.cc:44
Point operator*(double d, const Point &p)
Definition: Point.h:182
bool operator<(Tensor t1, Tensor t2)
Definition: Tensor.h:136
SCISHARE void Pio(Piostream &, BBox &)
Definition: BBox.cc:134