Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_InterlacedOperator.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 
12 #include "Epetra_Map.h"
13 
14 #include "EpetraExt_BlockUtility.h"
15 
19  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis_,
21  const Teuchos::RCP<const Epetra_CrsGraph>& determ_graph,
22  const Teuchos::RCP<Teuchos::ParameterList>& params) :
23  EpetraExt::BlockCrsMatrix(*(epetraCijk_->getStochasticGraph()),
24  *determ_graph,
25  *sg_comm_),
26  sg_comm(sg_comm_),
27  sg_basis(sg_basis_),
28  epetraCijk(epetraCijk_),
29  Cijk(epetraCijk->getParallelCijk()),
30  block_ops(),
31  scale_op(true),
32  include_mean(true),
33  only_use_linear(false),
34  determOffset_(EpetraExt::BlockUtility::CalculateOffset(determ_graph->RowMap()))
35 {
36  scale_op = params->get("Scale Operator by Inverse Basis Norms", true);
37  include_mean = params->get("Include Mean", true);
38  only_use_linear = params->get("Only Use Linear Terms", false);
39 }
40 
43 {
44 }
45 
46 void
50 {
51  block_ops = ops;
52 
53  // Zero out matrix
54  this->PutScalar(0.0);
55 
56  // Compute loop bounds
57  Cijk_type::k_iterator k_begin = Cijk->k_begin();
58  Cijk_type::k_iterator k_end = Cijk->k_end();
59  if (!include_mean && index(k_begin) == 0)
60  ++k_begin;
61  if (only_use_linear) {
62  int dim = sg_basis->dimension();
63  k_end = Cijk->find_k(dim+1);
64  }
65 
66  // Assemble matrix
67  const Teuchos::Array<double>& norms = sg_basis->norm_squared();
68  for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
69  int k = index(k_it);
71  Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(block_ops->getCoeffPtr(k),
72  true);
73  for (Cijk_type::kj_iterator j_it = Cijk->j_begin(k_it);
74  j_it != Cijk->j_end(k_it); ++j_it) {
75  int j = epetraCijk->GCID(index(j_it));
76  for (Cijk_type::kji_iterator i_it = Cijk->i_begin(j_it);
77  i_it != Cijk->i_end(j_it); ++i_it) {
78  int i = epetraCijk->GRID(index(i_it));
79  double c = value(i_it);
80  if (scale_op)
81  c /= norms[i];
82  this->SumIntoGlobalBlock_Deterministic(c, *block, i, j);
83  }
84  }
85  }
86 }
87 
91 {
92  return block_ops;
93 }
94 
98 {
99  return block_ops;
100 }
101 
103 SumIntoGlobalBlock_Deterministic(double alpha,const Epetra_RowMatrix & determBlock,int Row,int Col)
104 {
105  const Epetra_Map & determMap = determBlock.RowMatrixRowMap();
106  const Epetra_Map & determColMap = determBlock.RowMatrixColMap();
107 
108  // This routine copies entries of a BaseMatrix into big BlockCrsMatrix
109  // It performs the following operation on the global IDs row-by-row
110  // this->val[i+rowOffset][j+ColOffset] = BaseMatrix.val[i][j]
111 
112  int MaxIndices = determBlock.MaxNumEntries();
113  std::vector<int> Indices(MaxIndices);
114  std::vector<double> Values(MaxIndices);
115  int NumIndices;
116  int ierr=0;
117 
118  for (int i=0; i<determMap.NumMyElements(); i++) {
119  determBlock.ExtractMyRowCopy( i, MaxIndices, NumIndices, &Values[0], &Indices[0] );
120 
121  // Convert to BlockMatrix Global numbering scheme
122  for( int l = 0; l < NumIndices; ++l ) {
123  Indices[l] = Col + COffset_*determColMap.GID(Indices[l]);
124  Values[l] *= alpha;
125  }
126 
127  int BaseRow = determMap.GID(i);
128  ierr = this->SumIntoGlobalValues(ROffset_*BaseRow + Row, NumIndices, &Values[0], &Indices[0]);
129  if (ierr != 0) std::cout << "WARNING InterlacedOperator::SumIntoBlock_Deterministic SumIntoGlobalValues err = " << ierr <<
130  "\n\t Row " << ROffset_*BaseRow + Row << ", Col start " << Indices[0] << std::endl;
131 
132  }
133 }
bool only_use_linear
Flag indicating whether to only use linear terms.
InterlacedOperator(const Teuchos::RCP< const EpetraExt::MultiComm > &sg_comm, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &sg_basis, const Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > &epetraCijk, const Teuchos::RCP< const Epetra_CrsGraph > &base_graph, const Teuchos::RCP< Teuchos::ParameterList > &params)
Constructor.
virtual const Epetra_Map & RowMatrixRowMap() const =0
T & get(ParameterList &l, const std::string &name)
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()
Get SG polynomial.
virtual void setupOperator(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &poly)
Setup operator.
Bi-directional iterator for traversing a sparse array.
int NumMyElements() const
virtual int MaxNumEntries() const =0
bool scale_op
Flag indicating whether operator be scaled with &lt;^2&gt;
void SumIntoGlobalBlock_Deterministic(double alpha, const Epetra_RowMatrix &determBlock, int Row, int Col)
Sum into global matrix.
int GID(int LID) const
bool include_mean
Flag indicating whether to include mean term.
CRS matrix of dense blocks.
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const =0
virtual const Epetra_Map & RowMatrixColMap() const =0