Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_EpetraMultiVectorOperator.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Epetra_Vector.h"
12 #include "Epetra_LocalMap.h"
13 
17  bool is_multi_vec_transposed_)
18  : label("Epetra MultiVector Operator"),
19  multi_vec(multi_vec_),
20  nonconst_multi_vec(),
21  is_multi_vec_transposed(is_multi_vec_transposed_),
22  useTranspose(is_multi_vec_transposed),
23  domain_map()
24 {
25  domain_map = Teuchos::rcp(new Epetra_LocalMap(multi_vec->NumVectors(), 0,
26  multi_vec->Map().Comm()));
27 }
28 
31  const Teuchos::RCP<Epetra_MultiVector>& multi_vec_,
32  bool is_multi_vec_transposed_)
33  : label("Epetra MultiVector Operator"),
34  multi_vec(multi_vec_),
35  nonconst_multi_vec(multi_vec_),
36  is_multi_vec_transposed(is_multi_vec_transposed_),
37  useTranspose(is_multi_vec_transposed),
38  domain_map()
39 {
40  domain_map = Teuchos::rcp(new Epetra_LocalMap(multi_vec->NumVectors(), 0,
41  multi_vec->Map().Comm()));
42 }
43 
46 {
47 }
48 
49 int
51 SetUseTranspose(bool UseTranspose)
52 {
53  if (is_multi_vec_transposed)
54  useTranspose = !UseTranspose;
55  else
56  useTranspose = UseTranspose;
57 
58  return 0;
59 }
60 
61 int
63 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
64 {
65  char trans = 'N';
66  if (useTranspose)
67  trans = 'T';
68 
69  int ret = Result.Multiply(trans, 'N', 1.0, *multi_vec, Input, 0.0);
70  TEUCHOS_TEST_FOR_EXCEPTION(ret != 0, std::logic_error,
71  "Error! Stokhos::EpetraMultiVectorOperator: " <<
72  "Result.Multiply() returned " << ret << "!");
73 
74  return ret;
75 }
76 
77 int
80  Epetra_MultiVector& Result) const
81 {
82  throw "EpetraMultiVectorOperator::ApplyInverse not defined!";
83  return -1;
84 }
85 
86 double
88 NormInf() const
89 {
90  // ||A||_inf = || (|A_1| + ... + |A_n|) ||_inf where A_i is the i-th column
91  // of the multi-vector A
92  Epetra_Vector tmp1(multi_vec->Map());
93  Epetra_Vector tmp2(multi_vec->Map());
94  for (int j=0; j<multi_vec->NumVectors(); j++) {
95  tmp1.Abs(*((*multi_vec)(j)));
96  tmp2.Update(1.0, tmp1, 1.0);
97  }
98  double nrm;
99  tmp2.NormInf(&nrm);
100 
101  return nrm;
102 }
103 
104 
105 const char*
107 Label() const
108 {
109  return const_cast<char*>(label.c_str());
110 }
111 
112 bool
115 {
116  if (is_multi_vec_transposed)
117  return !useTranspose;
118  return useTranspose;
119 }
120 
121 bool
123 HasNormInf() const
124 {
125  return true;
126 }
127 
128 const Epetra_Comm &
130 Comm() const
131 {
132  return domain_map->Comm();
133 }
134 const Epetra_Map&
137 {
138  if (useTranspose)
139  return dynamic_cast<const Epetra_Map&>(multi_vec->Map());
140  return *domain_map;
141 }
142 
143 const Epetra_Map&
146 {
147  if (useTranspose)
148  return *domain_map;
149  return dynamic_cast<const Epetra_Map&>(multi_vec->Map());
150 }
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
Teuchos::RCP< Epetra_Map > domain_map
Domain map ( = number of columns of multi_vec)
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
EpetraMultiVectorOperator(const Teuchos::RCP< const Epetra_MultiVector > &multi_vec, bool is_multi_vec_transposed)
Constructor.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual const Epetra_BlockMap & Map() const =0
virtual const char * Label() const
Returns a character string describing the operator.
const Epetra_Comm & Comm() const
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of the inverse of the operator applied to a Epetra_MultiVector Input in Result as ...
Teuchos::RCP< const Epetra_MultiVector > multi_vec
Multi-vector.
virtual int Apply(const Epetra_MultiVector &Input, Epetra_MultiVector &Result) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector Input in Result as described ...
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.