Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_VectorOrthogPolyTraitsEpetra.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Stokhos Package
7 // Copyright (2009) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
40 //
41 // ***********************************************************************
42 // @HEADER
43 
44 #ifndef STOKHOS_VECTORORTHOGPOLYTRAITSEPETRA_HPP
45 #define STOKHOS_VECTORORTHOGPOLYTRAITSEPETRA_HPP
46 
47 #include <iostream>
49 #include "Teuchos_RCP.hpp"
50 #include "Epetra_Vector.h"
51 #include "EpetraExt_BlockVector.h"
52 #include "Epetra_Operator.h"
53 #include "Epetra_CrsMatrix.h"
54 
55 namespace Stokhos {
56 
59  public:
61  map(&map_), vec(NULL), block_vec(NULL) {}
63  map(NULL), vec(&vec_), block_vec(NULL) {}
64  EpetraVectorCloner(EpetraExt::BlockVector& block_vec_) :
65  map(NULL), vec(NULL), block_vec(&block_vec_) {}
67  if (map)
68  return Teuchos::rcp(new Epetra_Vector(*map));
69  else if (vec)
70  return Teuchos::rcp(new Epetra_Vector(*vec));
71  else
72  return block_vec->GetBlock(i);
73  }
74  protected:
77  EpetraExt::BlockVector *block_vec;
78  bool view;
79  };
80 
83  public:
85  int num_vectors) :
86  map(&map_), vec(NULL), num_vecs(num_vectors) {}
88  map(NULL), vec(&vec_), num_vecs(vec_.NumVectors()) {}
90  if (map)
92  else
93  return Teuchos::rcp(new Epetra_MultiVector(*vec));
94  }
95  protected:
98  int num_vecs;
99  };
100 
102 
107 
110  public:
113  return Teuchos::rcp(new Epetra_CrsMatrix(mat));
114  }
115  protected:
117  };
118 
120  template <>
122  public:
123 
125  typedef double value_type;
126 
128  typedef int ordinal_type;
129 
132 
134  static void init(Epetra_Vector& vec, double val) { vec.PutScalar(val); }
135 
137  static void update(Epetra_Vector& vec, double a, const Epetra_Vector& x) {
138  vec.Update(a,x,1.0);
139  }
140 
142  static std::ostream& print(std::ostream& os, const Epetra_Vector& vec) {
143  vec.Print(os);
144  return os;
145  }
146 
147  };
148 
150  template <>
152  public:
153 
155  typedef double value_type;
156 
158  typedef int ordinal_type;
159 
162 
164  static void init(Epetra_MultiVector& vec, double val) {
165  vec.PutScalar(val); }
166 
168  static void update(Epetra_MultiVector& vec, double a,
169  const Epetra_MultiVector& x) {
170  vec.Update(a,x,1.0);
171  }
172 
174  static std::ostream& print(std::ostream& os,
175  const Epetra_MultiVector& vec) {
176  vec.Print(os);
177  return os;
178  }
179 
180  };
181 
183  template <>
185  public:
186 
188  typedef double value_type;
189 
191  typedef int ordinal_type;
192 
195 
197  static void init(Epetra_CrsMatrix& mat, double val) { mat.PutScalar(val); }
198 
200  static void update(Epetra_CrsMatrix& mat, double a,
201  const Epetra_CrsMatrix& x) {
202  int num_col;
203  for (int i=0; i<mat.NumMyRows(); i++) {
204  mat.NumMyRowEntries(i, num_col);
205  for (int j=0; j<num_col; j++)
206  mat[i][j] += a*x[i][j];
207  }
208  }
209 
211  static std::ostream& print(std::ostream& os, const Epetra_CrsMatrix& mat) {
212  mat.Print(os);
213  return os;
214  }
215 
216  };
217 
219  template <>
221  public:
222 
224  typedef double value_type;
225 
227  typedef int ordinal_type;
228 
231 
233  static void init(Epetra_Operator& op, double val) {
234  Epetra_CrsMatrix& mat = dynamic_cast<Epetra_CrsMatrix&>(op);
236  }
237 
239  static void update(Epetra_Operator& op, double a,
240  const Epetra_Operator& x_op) {
241  Epetra_CrsMatrix& mat = dynamic_cast<Epetra_CrsMatrix&>(op);
242  const Epetra_CrsMatrix& x = dynamic_cast<const Epetra_CrsMatrix&>(x_op);
244  }
245 
247  static std::ostream& print(std::ostream& os, const Epetra_Operator& op) {
248  os << "Epetra_Operator" << std::endl;
249  const Epetra_CrsMatrix& mat = dynamic_cast<const Epetra_CrsMatrix&>(op);
251  return os;
252  }
253 
254  };
255 
256 }
257 
258 #endif // STOKHOS_VECTORORTHOGPOLYTRAITSEPETRA_HPP
int NumMyRowEntries(int MyRow, int &NumEntries) const
static std::ostream & print(std::ostream &os, const Epetra_Vector &vec)
Print vector.
static void init(Epetra_MultiVector &vec, double val)
Initialize vector.
virtual void Print(std::ostream &os) const
static std::ostream & print(std::ostream &os, const Epetra_Operator &op)
Print operator.
Cloner for Epetra_Vector coefficients.
EpetraMultiVectorCloner(const Epetra_BlockMap &map_, int num_vectors)
static std::ostream & print(std::ostream &os, const Epetra_CrsMatrix &mat)
Print matrix.
Cloner for Epetra_CrsMatrix coefficients.
int PutScalar(double ScalarConstant)
Base traits definition for ProductContainer.
Teuchos::RCP< Epetra_MultiVector > clone(int i) const
static void init(Epetra_Vector &vec, double val)
Initialize vector.
Cloner for Epetra_Operator coefficients.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void update(Epetra_Vector &vec, double a, const Epetra_Vector &x)
Update vector.
Teuchos::RCP< Epetra_Vector > clone(int i) const
int NumMyRows() const
static void init(Epetra_CrsMatrix &mat, double val)
Initialize matrix.
static std::ostream & print(std::ostream &os, const Epetra_MultiVector &vec)
Print vector.
virtual void Print(std::ostream &os) const
static void init(Epetra_Operator &op, double val)
Initialize operator.
expr val()
static void update(Epetra_Operator &op, double a, const Epetra_Operator &x_op)
Update operator.
Teuchos::RCP< Epetra_CrsMatrix > clone(int i) const
EpetraVectorCloner(EpetraExt::BlockVector &block_vec_)
EpetraMultiVectorCloner(const Epetra_MultiVector &vec_)
static void update(Epetra_MultiVector &vec, double a, const Epetra_MultiVector &x)
Update vector.
Cloner for Epetra_MultiVector coefficients.
static void update(Epetra_CrsMatrix &mat, double a, const Epetra_CrsMatrix &x)
Update matrix.
void update(const ValueType &alpha, VectorType &x, const ValueType &beta, const VectorType &y)