Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BlockDiagonalOperator.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_BlockMultiVector.h"
12 #include "Epetra_Map.h"
13 
17  int num_mp_blocks_,
18  const Teuchos::RCP<const Epetra_Map>& domain_base_map_,
19  const Teuchos::RCP<const Epetra_Map>& range_base_map_,
20  const Teuchos::RCP<const Epetra_Map>& domain_mp_map_,
21  const Teuchos::RCP<const Epetra_Map>& range_mp_map_) :
22  label("Stokhos Block Diagonal Operator"),
23  mp_comm(mp_comm_),
24  num_mp_blocks(num_mp_blocks_),
25  domain_base_map(domain_base_map_),
26  range_base_map(range_base_map_),
27  domain_mp_map(domain_mp_map_),
28  range_mp_map(range_mp_map_),
29  block_ops(),
30  useTranspose(false)
31 {
32 }
33 
36 {
37 }
38 
39 void
43 {
44  block_ops = ops;
45 }
46 
50 {
51  return block_ops;
52 }
53 
56 getMPOps() const
57 {
58  return block_ops;
59 }
60 
61 int
63 SetUseTranspose(bool UseTheTranspose)
64 {
65  useTranspose = UseTheTranspose;
66  for (int i=0; i<num_mp_blocks; i++)
67  (*block_ops)[i].SetUseTranspose(useTranspose);
68 
69  return 0;
70 }
71 
72 int
74 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
75 {
76  Teuchos::RCP<const Epetra_BlockMap> input_base_map, result_base_map;
77  if (useTranspose) {
78  input_base_map = range_base_map;
79  result_base_map = domain_base_map;
80  }
81  else {
82  input_base_map = domain_base_map;
83  result_base_map = range_base_map;
84  }
85  EpetraExt::BlockMultiVector mp_input(View, *input_base_map, Input);
86  EpetraExt::BlockMultiVector mp_result(View, *result_base_map, Result);
87  for (int i=0; i<num_mp_blocks; i++) {
88  (*block_ops)[i].Apply(*(mp_input.GetBlock(i)), *(mp_result.GetBlock(i)));
89  }
90 
91  return 0;
92 }
93 
94 int
96  Epetra_MultiVector& Result) const
97 {
98  Teuchos::RCP<const Epetra_BlockMap> input_base_map, result_base_map;
99  if (useTranspose) {
100  input_base_map = domain_base_map;
101  result_base_map = range_base_map;
102  }
103  else {
104  input_base_map = range_base_map;
105  result_base_map = domain_base_map;
106  }
107  EpetraExt::BlockMultiVector mp_input(View, *input_base_map, Input);
108  EpetraExt::BlockMultiVector mp_result(View, *range_base_map, Result);
109  for (int i=0; i<num_mp_blocks; i++) {
110  (*block_ops)[i].ApplyInverse(*(mp_input.GetBlock(i)),
111  *(mp_result.GetBlock(i)));
112  }
113 
114  return 0;
115 }
116 
117 double
119 {
120  double product_nrm = 0.0;
121  for (int i=0; i<num_mp_blocks; i++) {
122  double nrm = (*block_ops)[i].NormInf();
123  if (nrm > product_nrm)
124  product_nrm = nrm;
125  }
126 
127  return product_nrm;
128 }
129 
130 
131 const char*
133 {
134  return const_cast<char*>(label.c_str());
135 }
136 
137 bool
139 {
140  return useTranspose;
141 }
142 
143 bool
145 {
146  if (num_mp_blocks == 0)
147  return false;
148  return (*block_ops)[0].HasNormInf();
149 }
150 
151 const Epetra_Comm &
153 {
154  return *mp_comm;
155 }
156 const Epetra_Map&
158 {
159  if (useTranspose)
160  return *range_mp_map;
161  return *domain_mp_map;
162 }
163 
164 const Epetra_Map&
166 {
167  if (useTranspose)
168  return *domain_mp_map;
169  return *range_mp_map;
170 }
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix 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 ...
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
BlockDiagonalOperator(const Teuchos::RCP< const EpetraExt::MultiComm > &mp_comm, int num_mp_blocks, const Teuchos::RCP< const Epetra_Map > &domain_base_map, const Teuchos::RCP< const Epetra_Map > &range_base_map, const Teuchos::RCP< const Epetra_Map > &domain_mp_map, const Teuchos::RCP< const Epetra_Map > &range_mp_map)
Constructor.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
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 double NormInf() const
Returns an approximate infinity norm of the operator matrix.
virtual void setupOperator(const Teuchos::RCP< Stokhos::ProductEpetraOperator > &ops)
Setup operator.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual Teuchos::RCP< Stokhos::ProductEpetraOperator > getMPOps()
Get multi-point ops.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual const char * Label() const
Returns a character string describing the operator.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.