Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_FullyAssembledOperator.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 "Teuchos_TimeMonitor.hpp"
12 
16  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis_,
18  const Teuchos::RCP<const Epetra_CrsGraph>& base_graph,
19  const Teuchos::RCP<const Epetra_Map>& domain_sg_map_,
20  const Teuchos::RCP<const Epetra_Map>& range_sg_map_,
21  const Teuchos::RCP<Teuchos::ParameterList>& params) :
22  EpetraExt::BlockCrsMatrix(*base_graph,
23  *(epetraCijk_->getStochasticGraph()),
24  *sg_comm_),
25  sg_comm(sg_comm_),
26  sg_basis(sg_basis_),
27  epetraCijk(epetraCijk_),
28  domain_sg_map(domain_sg_map_),
29  range_sg_map(range_sg_map_),
30  Cijk(epetraCijk->getParallelCijk()),
31  block_ops(),
32  scale_op(true),
33  include_mean(true),
34  only_use_linear(false)
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 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
52  TEUCHOS_FUNC_TIME_MONITOR("Stokhos: SG Fully Assembled Operator Assembly");
53 #endif
54 
55  block_ops = ops;
56 
57  // Zero out matrix
58  this->PutScalar(0.0);
59 
60  // Compute loop bounds
61  Cijk_type::k_iterator k_begin = Cijk->k_begin();
62  Cijk_type::k_iterator k_end = Cijk->k_end();
63  if (!include_mean && index(k_begin) == 0)
64  ++k_begin;
65  if (only_use_linear) {
66  int dim = sg_basis->dimension();
67  k_end = Cijk->find_k(dim+1);
68  }
69 
70  // Assemble matrix
71  const Teuchos::Array<double>& norms = sg_basis->norm_squared();
72  for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
73  int k = index(k_it);
75  Teuchos::rcp_dynamic_cast<Epetra_RowMatrix>(block_ops->getCoeffPtr(k),
76  true);
77  for (Cijk_type::kj_iterator j_it = Cijk->j_begin(k_it);
78  j_it != Cijk->j_end(k_it); ++j_it) {
79  int j = epetraCijk->GCID(index(j_it));
80  for (Cijk_type::kji_iterator i_it = Cijk->i_begin(j_it);
81  i_it != Cijk->i_end(j_it); ++i_it) {
82  int i = epetraCijk->GRID(index(i_it));
83  double c = value(i_it);
84  if (scale_op)
85  c /= norms[i];
86  this->SumIntoGlobalBlock(c, *block, i, j);
87  }
88  }
89  }
90 
91  this->FillComplete(*domain_sg_map, *range_sg_map);
92 }
93 
97 {
98  return block_ops;
99 }
100 
104 {
105  return block_ops;
106 }
107 
108 int
110 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
111 {
112 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
113  TEUCHOS_FUNC_TIME_MONITOR("Stokhos: SG Operator Apply");
114 #endif
115  return Epetra_CrsMatrix::Apply(Input, Result);
116 }
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
virtual void setupOperator(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &poly)
Setup operator.
T & get(ParameterList &l, const std::string &name)
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()
Get SG polynomial.
Bi-directional iterator for traversing a sparse array.
bool only_use_linear
Flag indicating whether to only use linear terms.
virtual int Apply(const Epetra_MultiVector &Input, Epetra_MultiVector &Result) const
Wrap Apply() to add a timer.
bool scale_op
Flag indicating whether operator be scaled with &lt;^2&gt;
bool include_mean
Flag indicating whether to include mean term.
CRS matrix of dense blocks.
FullyAssembledOperator(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< const Epetra_Map > &domain_sg_map, const Teuchos::RCP< const Epetra_Map > &range_sg_map, const Teuchos::RCP< Teuchos::ParameterList > &params)
Constructor.