Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_ProductEpetraOperator.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 "EpetraExt_BlockUtility.h"
12 #include "EpetraExt_BlockMultiVector.h"
13 
16  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
17  const Teuchos::RCP<const Epetra_Map>& domain_base_map_,
18  const Teuchos::RCP<const Epetra_Map>& range_base_map_,
19  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
21  domain_base_map(domain_base_map_),
22  range_base_map(range_base_map_),
23  product_range_map(Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*range_base_map, *block_map, *product_comm_))),
24  product_comm(product_comm_),
25  useTranspose(false)
26 {
27 }
28 
31  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
32  const Teuchos::RCP<const Epetra_Map>& domain_base_map_,
33  const Teuchos::RCP<const Epetra_Map>& range_base_map_,
34  const Teuchos::RCP<const Epetra_Map>& product_range_map_,
35  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
37  domain_base_map(domain_base_map_),
38  range_base_map(range_base_map_),
39  product_range_map(product_range_map_),
40  product_comm(product_comm_),
41  useTranspose(false)
42 {
43 }
44 
48  domain_base_map(v.domain_base_map),
49  range_base_map(v.range_base_map),
50  product_range_map(v.product_range_map),
51  product_comm(v.product_comm),
52  useTranspose(v.useTranspose)
53 {
54 }
55 
58 
63  domain_base_map = v.domain_base_map;
64  range_base_map = v.range_base_map;
65  product_range_map = v.product_range_map;
66  product_comm = v.product_comm;
67  useTranspose = v.useTranspose;
68  return *this;
69 }
70 
73 productComm() const {
74  return product_comm;
75 }
76 
77 int
79 SetUseTranspose(bool UseTheTranspose)
80 {
81  useTranspose = UseTheTranspose;
82  for (int i=0; i<coeff_.size(); i++)
83  coeff_[i]->SetUseTranspose(useTranspose);
84 
85  return 0;
86 }
87 
88 int
90 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
91 {
92  if (useTranspose) {
93  EpetraExt::BlockMultiVector sg_input(View, *range_base_map, Input);
94  Epetra_MultiVector tmp(Result.Map(), Result.NumVectors());
95  Result.PutScalar(0.0);
96  for (int i=0; i<coeff_.size(); i++) {
97  coeff_[i]->Apply(*(sg_input.GetBlock(i)), tmp);
98  Result.Update(1.0, tmp, 1.0);
99  }
100  }
101  else {
102  EpetraExt::BlockMultiVector sg_result(View, *range_base_map, Result);
103  for (int i=0; i<coeff_.size(); i++)
104  coeff_[i]->Apply(Input, *(sg_result.GetBlock(i)));
105  }
106 
107  return 0;
108 }
109 
110 int
113  Epetra_MultiVector& Result) const
114 {
115  throw "ProductEpetraOperator::ApplyInverse not defined!";
116  return -1;
117 }
118 
119 double
121 NormInf() const
122 {
123  return 1.0;
124 }
125 
126 
127 const char*
129 Label () const
130 {
131  return "Stokhos::ProductEpetraOperator";
132 }
133 
134 bool
137 {
138  return useTranspose;
139 }
140 
141 bool
143 HasNormInf() const
144 {
145  return false;
146 }
147 
148 const Epetra_Comm &
150 Comm() const
151 {
152  return *product_comm;
153 }
154 const Epetra_Map&
157 {
158  if (useTranspose)
159  return *product_range_map;
160  return *domain_base_map;
161 }
162 
163 const Epetra_Map&
166 {
167  if (useTranspose)
168  return *domain_base_map;
169  return *product_range_map;
170 }
171 
174  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
175  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
176  ProductContainer<Epetra_Operator>(block_map),
177  product_comm(product_comm_),
178  useTranspose(false)
179 {
180 }
181 
182 void
184 setup(const Teuchos::RCP<const Epetra_Map>& domain_base_map_,
185  const Teuchos::RCP<const Epetra_Map>& range_base_map_)
186 {
187  domain_base_map = domain_base_map_;
188  range_base_map = range_base_map_;
189  product_range_map =
190  Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*range_base_map,
191  *(this->map_),
192  *product_comm));
193 }
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual const char * Label() const
Returns a character string describing the operator.
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 ...
ProductEpetraOperator(const Teuchos::RCP< const Epetra_BlockMap > &block_map, const Teuchos::RCP< const Epetra_Map > &domain_base_map, const Teuchos::RCP< const Epetra_Map > &range_base_map, const Teuchos::RCP< const EpetraExt::MultiComm > &product_comm)
Create a container with container map block_map where each coefficient is generated from the supplied...
Teuchos::RCP< const EpetraExt::MultiComm > product_comm
Product multi-level communicator.
A container class for products of Epetra_Vector&#39;s.
ProductContainer & operator=(const ProductContainer &)
Assignment.
Teuchos::RCP< const Epetra_Map > product_range_map
Product range map.
Teuchos::RCP< const EpetraExt::MultiComm > productComm() const
Get product comm.
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 ...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Teuchos::RCP< const Epetra_Map > range_base_map
Range map of each coefficient.
virtual const Epetra_BlockMap & Map() const =0
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
bool useTranspose
Whether to use transpose in Apply()
A product (in the mathematical sense) container class whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
Teuchos::RCP< const Epetra_Map > domain_base_map
Domain map of each coefficient.
void setup(const Teuchos::RCP< const Epetra_Map > &domain_base_map, const Teuchos::RCP< const Epetra_Map > &range_base_map)
Second stage of setup.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
ProductEpetraOperator & operator=(const ProductEpetraOperator &v)
Assignment.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.