Geomi
NOXMultiVector.hpp
1 #ifndef NOX_MULTIVECTOR
2 #define NOX_MULTIVECTOR
3 
4 /*
5 #include "NOX_Common.H"
6 #include "NOX_Abstract_MultiVector.H"
7 
8 #include <Eigen/Base>
9 
10 #include "NOXVector.hpp"
11 
12 template <typename T, unsigned int dof>
13 class NOXMultiVector : public virtual NOX::Abstract::MultiVector
14 {
15 public:
16  ~NOXMultiVector<T,dof> ()
17  { }
18 
19  NOXVector<T,dof> ()
20  { }
21 
22  template <typename OtherDerived>
23  NOXVector<T,dof> (const Eigen::MatrixBase<OtherDerived>& other) :
24  Eigen::Matrix<T,dof,1>(other)
25  { }
26 
27  template <typename OtherDerived>
28  NOX::Abstract::Vector&
29  operator= (const Eigen::MatrixBase<OtherDerived>& other)
30  {
31  this->Eigen::Matrix<T,dof,1>::operator=(other);
32  return *this;
33  }
34 
35  // Copy constructor with NOX::CopyType : just ignore type
36  NOXVector<T,dof> (const NOXVector& source, NOX::CopyType type) :
37  NOXVector<T,dof>(source)
38  { }
39 
40  NOX::Abstract::Vector&
41  abs (const NOXVector& y)
42  {
43  this = y.Eigen::Matrix<T,dof>::abs();
44  return *this;
45  }
46 
47  NOX::Abstract::Vector&
48  abs (const NOX::Abstract::Vector& y)
49  {
50  return abs(dynamic_cast<const NOXVector<T,dof>&>(y));
51  }
52 
53  Teuchos::RCP<NOX::Abstract::Vector>
54  clone (NOX::CopyType type=NOX::DeepCopy) const
55  {
56  Teuchos::RCP<NOX::Abstract::Vector> tmp;
57  tmp = Teuchos::rcp(new NOXVector(*this,type));
58  return tmp;
59  }
60 
61  // TODO:
62  // override createMultiVector()
63  // pour ca il faut une implementation de NOX::Abstract::MultiVector, qui par defaut (le cas ici) est NOX::MultiVector
64 
65  double
66  innerProduct (const NOXVector<T,dof>& y) const
67  {
68  return (this.dot(y).sum());
69  }
70 
71  double
72  innerProduct (const NOX::Abstract::Vector& y) const
73  {
74  return innerProduct(dynamic_cast<const NOXVector<T,dof>&>(y));
75  }
76 
77  NOX::Abstract::Vector&
78  init (double gamma)
79  {
80  this.setConstant(gamma);
81  return *this;
82  }
83 
84  NOX::size_type
85  length () const
86  {
87  return dof;
88  }
89 
90  double
91  norm (NOX::Abstract::Vector::NormType type=NOX::Abstract::Vector::TwoNorm) const
92  {
93  double result;
94 
95  switch (type) {
96  case NOX::Abstract::Vector::MaxNorm:
97  result = this.maxCoeff();
98  break;
99  case NOX::Abstract::Vector::OneNorm:
100  result = this.lpNorm<1>();
101  case NOX::Abstract::Vector::TwoNorm:
102  result = this.norm();
103  break;
104  default:
105  break;
106  }
107 
108  return result;
109  }
110 
111  double
112  norm (const NOXVector& weights) const
113  {
114  return sqrt(((this.cwiseProduct(this)).cwiseProduct(weights)).sum());
115  }
116 
117  double
118  norm (const NOX::Abstract::Vector& weights) const
119  {
120  return norm(dynamic_cast<const NOXVector<T,dof>&>(weights));
121  }
122 
123  void
124  print (std::ostream& stream) const
125  {
126  //TODO
127  return;
128  }
129 
130  NOX::Abstract::Vector&
131  random (bool useSeed=false, int seed=1)
132  {
133  if (useSeed)
134  NOX::Random:setSeed(seed);
135 
136  for (int i=0; i<dof; i++)
137  this[i] = NOX::Random::number();
138 
139  return *this;
140  }
141 
142  // TODO: definir operator=(const NOXVector&)
143  NOX::Abstract::Vector&
144  operator= (const NOX::Abstract::Vector& y)
145  {
146  return operator=(dynamic_cast<const NOXVector<T,dof>&>(y));
147  }
148 
149  NOX::Abstract::Vector&
150  reciprocal (const NOXVector& y)
151  {
152  this = this.cwiseInverse();
153  return *this;
154  }
155 
156  NOX::Abstract::Vector&
157  reciprocal (const NOX::Abstract::Vector& y)
158  {
159  return reciprocal(dynamic_cast<const NOXVector<T,dof>&>(y));
160  }
161 
162  NOX::Abstract::Vector&
163  scale (double gamma)
164  {
165  this = this*gamma;
166  return *this;
167  }
168 
169  NOX::Abstract::Vector&
170  scale (const NOXVector<T,dof>& a)
171  {
172  this = this.cwiseProduct(a);
173  return *this;
174  }
175 
176  NOX::Abstract::Vector&
177  scale (const NOX::Abstract::Vector& a)
178  {
179  return scale(dynamic_cast<const NOXVector<T,dof>&>(a));
180  }
181 
182  NOX::Abstract::Vector&
183  update (double alpha, const NOXVector<T,dof>& a, double gamma=0.0)
184  {
185  this = alpha*a + this*gamma;
186  return *this;
187  }
188 
189  NOX::Abstract::Vector&
190  update (double alpha, const NOX::Abstract::Vector& a, double gamma=0.0)
191  {
192  return update(alpha,dynamic_cast<const NOXVector<T,dof>&>(a),gamma);
193  }
194 
195  NOX::Abstract::Vector&
196  update ( double alpha,
197  const NOXVector<T,dof>& a,
198  double beta,
199  const NOXVector<T,dof>& b,
200  double gamma=0.0)
201  {
202  this = alpha*a + beta*b + this*gamma;
203  return *this;
204  }
205 
206  NOX::Abstract::Vector&
207  update ( double alpha,
208  const NOX::Abstract::Vector& a,
209  double beta,
210  const NOX::Abstract::Vector& b,
211  double gamma=0.0)
212  {
213  return update(alpha,dynamic_cast<const NOXVector<T,dof>&>(a),beta,dynamic_cast<const NOXVector<T,dof>&>(b),gamma);
214  }
215 };
216 */
217 
218 #endif
219