Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_DiagEpetraOp.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 
10 #include "Epetra_config.h"
11 #include "EpetraExt_BlockMultiVector.h"
12 #include "EpetraExt_MatrixMatrix.h"
13 #include "Stokhos_DiagEpetraOp.hpp"
14 
16  const Teuchos::RCP<const Epetra_Map>& domain_base_map_,
17  const Teuchos::RCP<const Epetra_Map>& range_base_map_,
18  const Teuchos::RCP<const Epetra_Map>& domain_sg_map_,
19  const Teuchos::RCP<const Epetra_Map>& range_sg_map_,
20  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis_,
23  : label("Stokhos Diagonal Operator"),
24  domain_base_map(domain_base_map_),
25  range_base_map(range_base_map_),
26  domain_sg_map(domain_sg_map_),
27  range_sg_map(range_sg_map_),
28  sg_basis(sg_basis_),
29  Cijk(Cijk_),
30  block_ops(ops_),
31  useTranspose(false),
32  expansion_size(sg_basis->size()),
33  num_blocks(block_ops->size()),
34  input_block(expansion_size),
35  result_block(expansion_size),
36  tmp(),
37  tmp_trans()
38 {
39 }
40 
42 {
43 }
44 
45 void
48 {
49  block_ops = ops;
50 }
51 
54 {
55  return block_ops;
56 }
57 
60 {
61  return block_ops;
62 }
63 
64 int
66 {
67  useTranspose = UseTranspose;
68  for (int i=0; i<num_blocks; i++)
69  (*block_ops)[i].SetUseTranspose(useTranspose);
70 
71  return 0;
72 }
73 
74 int
76 {
77 
78 // std::vector< Teuchos::RCP< Epetra_CrsMatrix> > sg_Kkk_all ;
79 // std::vector< Teuchos::RCP< const Epetra_CrsMatrix> > sg_J_all;
80 
81  for (int i=0;i<num_blocks+1;i++) {
82  Teuchos::RCP<Epetra_CrsMatrix> sg_J_poly_Crs =
83  Teuchos::rcp_dynamic_cast< Epetra_CrsMatrix>((*block_ops).getCoeffPtr(i),true);
84  sg_J_all.push_back(sg_J_poly_Crs);
85  }
86 
87 /* Teuchos::RCP<Epetra_CrsMatrix> sg_J_poly_Crs =
88  Teuchos::rcp_dynamic_cast< Epetra_CrsMatrix>((*sg_J_poly).getCoeffPtr(0),true);
89 
90  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(sg_J_poly_Crs), std::runtime_error,
91  "Dynamic cast of sg_J_poly failed!");
92 */
93 
94  for(int k=0;k<expansion_size;k++) {
96  Teuchos::rcp(new Epetra_CrsMatrix(*(sg_J_all[0])));
97  sg_Kkk_all.push_back(Kkk);
98  sg_Kkk_all[k]->PutScalar(0.0);
99  }
100 
101  //Compute diagonal blocks of SG matrix
102  for (int k=0; k<expansion_size; k++) {
103  int nj = Cijk->num_j(k);
104  const Teuchos::Array<int>& j_indices = Cijk->Jindices(k);
105  for (int jj=0; jj<nj; jj++) {
106  int j = j_indices[jj];
107  if (j==k) {
108  const Teuchos::Array<double>& cijk_values = Cijk->values(k,jj);
109  const Teuchos::Array<int>& i_indices = Cijk->Iindices(k,jj);
110  int ni = i_indices.size();
111  for (int ii=0; ii<ni; ii++) {
112  int i = i_indices[ii];
113  if (i<num_blocks+1) {
114  double cikk = cijk_values[ii]; // C(i,j,k)
115  EpetraExt::MatrixMatrix::Add((*sg_J_all[i]), false, cikk, *(sg_Kkk_all[k]), 1.0);
116  }
117  }
118  }
119  }
120  }
121 
122  /* // Apply block SG operator via
123  // w_i =
124  // \sum_{j=0}^P \sum_{k=0}^L J_k v_j < \psi_i \psi_j \psi_k > / <\psi_i^2>
125  // for i=0,...,P where P = expansion_size, L = num_blocks, w_j is the jth
126  // input block, w_i is the ith result block, and J_k is the kth block operator
127  const Teuchos::Array<double>& norms = sg_basis->norm_squared();
128  for (int k=0; k<num_blocks; k++) {
129  int nj = Cijk->num_j(k);
130  const Teuchos::Array<int>& j_indices = Cijk->Jindices(k);
131  Teuchos::Array<double*> j_ptr(nj*m);
132  Teuchos::Array<int> mj_indices(nj*m);
133  for (int l=0; l<nj; l++) {
134  for (int mm=0; mm<m; mm++) {
135  j_ptr[l*m+mm] = input_block[j_indices[l]]->Values()+mm*N;
136  mj_indices[l*m+mm] = j_indices[l]*m+mm;
137  }
138  }
139  Epetra_MultiVector input_tmp(View, *input_base_map, &j_ptr[0], nj*m);
140  Epetra_MultiVector result_tmp(View, *tmp_result, &mj_indices[0], nj*m);
141  (*block_ops)[k].Apply(input_tmp, result_tmp);
142  for (int l=0; l<nj; l++) {
143  const Teuchos::Array<int>& i_indices = Cijk->Iindices(k,l);
144  const Teuchos::Array<double>& c_values = Cijk->values(k,l);
145  for (int i=0; i<i_indices.size(); i++) {
146  int ii = i_indices[i];
147  for (int mm=0; mm<m; mm++)
148  (*result_block[ii])(mm)->Update(c_values[i]/norms[ii],
149  *result_tmp(l*m+mm), 1.0);
150  }
151  }
152  }
153 
154  // Destroy blocks
155  for (int i=0; i<expansion_size; i++) {
156  input_block[i] = Teuchos::null;
157  result_block[i] = Teuchos::null;
158  }
159 
160  if (made_copy)
161  delete input;
162  */
163  return 0;
164 }
165 
166 int
168  Epetra_MultiVector& Result) const
169 {
170  throw "DiagEpetraOp::ApplyInverse not defined!";
171  return -1;
172 }
173 
174 double
176 {
177  return 1.0;
178 }
179 
180 
181 const char*
183 {
184  return const_cast<char*>(label.c_str());
185 }
186 
187 bool
189 {
190  return useTranspose;
191 }
192 
193 bool
195 {
196  return false;
197 }
198 
199 const Epetra_Comm &
201 {
202  return domain_base_map->Comm();
203 }
204 const Epetra_Map&
206 {
207  return *domain_sg_map;
208 }
209 
210 const Epetra_Map&
212 {
213  return *range_sg_map;
214 }
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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 bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual void reset(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &ops)
Reset operator blocks.
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.
size_type size() const
virtual Teuchos::RCP< const Stokhos::EpetraOperatorOrthogPoly > getOperatorBlocks() const
Get operator blocks.
virtual int Apply(std::vector< Teuchos::RCP< const Epetra_CrsMatrix > > &sg_J_all, std::vector< Teuchos::RCP< Epetra_CrsMatrix > > &sg_Kkk_all) const
Returns Diagonal blocks of SG matrix when PC coefficients of the SG matrix are given.
DiagEpetraOp(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_sg_map_, const Teuchos::RCP< const Epetra_Map > &range_sg_map_, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &sg_basis, const Teuchos::RCP< const Stokhos::Sparse3Tensor< int, double > > &Cijk, const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &ops)
Constructor.
virtual ~DiagEpetraOp()
Destructor.