11 #include "EpetraExt_BlockMultiVector.h"
12 #include "EpetraExt_BlockUtility.h"
24 label(
"Stokhos KL MatrixFree Operator"),
27 epetraCijk(epetraCijk_),
28 domain_base_map(domain_base_map_),
29 range_base_map(range_base_map_),
30 domain_sg_map(domain_sg_map_),
31 range_sg_map(range_sg_map_),
32 is_stoch_parallel(epetraCijk->isStochasticParallel()),
34 global_col_map_trans(),
35 stoch_col_map(epetraCijk->getStochasticColMap()),
38 Cijk(epetraCijk->getParallelCijk()),
43 expansion_size(sg_basis->size()),
51 k_begin(Cijk->k_begin()),
54 scale_op = params->
get(
"Scale Operator by Inverse Basis Norms",
true);
64 int nj =
Cijk->num_j(k);
111 num_blocks = sg_basis->dimension() + 1;
132 useTranspose = UseTheTranspose;
133 for (
int i=0; i<num_blocks; i++)
134 (*block_ops)[i].SetUseTranspose(useTranspose);
146 bool made_copy =
false;
147 if (Input.Values() == Result.Values() && !is_stoch_parallel) {
153 Result.PutScalar(0.0);
155 const Epetra_Map* input_base_map = domain_base_map.get();
156 const Epetra_Map* result_base_map = range_base_map.get();
157 if (useTranspose ==
true) {
158 input_base_map = range_base_map.get();
159 result_base_map = domain_base_map.get();
163 int m = Input.NumVectors();
164 if (useTranspose ==
false &&
165 (tmp ==
Teuchos::null || tmp->NumVectors() != m*max_num_mat_vec))
168 else if (useTranspose ==
true &&
170 tmp_trans->NumVectors() != m*max_num_mat_vec))
174 if (useTranspose ==
false)
175 tmp_result = tmp.get();
177 tmp_result = tmp_trans.get();
181 if (!is_stoch_parallel)
184 if (useTranspose ==
false) {
185 if (input_col ==
Teuchos::null || input_col->NumVectors() != m)
187 input_col->Import(*input, *col_importer,
Insert);
188 tmp_col = input_col.get();
192 input_col_trans->NumVectors() != m)
195 input_col_trans->Import(*input, *col_importer_trans,
Insert);
196 tmp_col = input_col_trans.get();
201 EpetraExt::BlockMultiVector sg_input(
View, *input_base_map, *tmp_col);
202 EpetraExt::BlockMultiVector sg_result(
View, *result_base_map, Result);
203 for (
int i=0; i<input_block.size(); i++)
204 input_block[i] = sg_input.GetBlock(i);
205 for (
int i=0; i<result_block.size(); i++)
206 result_block[i] = sg_result.GetBlock(i);
207 int N = result_block[0]->MyLength();
210 int d = sg_basis->dimension();
212 for(
int j = 0;
j<d;
j++) {
217 sg_basis->evaluateBases(zero, phi_0);
218 sg_basis->evaluateBases(one, phi_1);
225 int nj = Cijk->num_j(k_it);
232 for (
int mm=0; mm<m; mm++) {
233 j_ptr[l*m+mm] = input_block[
j]->Values()+mm*N;
234 mj_indices[l*m+mm] = l*m+mm;
240 (*block_ops)[k].Apply(input_tmp, result_tmp);
244 int j_gid = epetraCijk->GCID(j);
246 i_it != Cijk->i_end(j_it); ++i_it) {
248 int i_gid = epetraCijk->GRID(i);
249 double c = value(i_it);
255 c -= phi_0[k]/(phi_1[k]*phi_0[0])*norms[i_gid];
263 for (
int mm=0; mm<m; mm++)
264 (*result_block[i])(mm)->
Update(c, *result_tmp(l*m+mm), 1.0);
272 for (
int i=0; i<input_block.size(); i++)
274 for (
int i=0; i<result_block.size(); i++)
287 throw "KLMatrixFreeOperator::ApplyInverse not defined!";
303 return const_cast<char*
>(label.c_str());
331 return *range_sg_map;
332 return *domain_sg_map;
340 return *domain_sg_map;
341 return *range_sg_map;
Teuchos::RCP< const Epetra_Map > range_sg_map
Stores range SG map.
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 ...
Cijk_type::k_iterator k_end
Ending k iterator.
Teuchos::RCP< Epetra_Map > global_col_map_trans
Stores operator column SG map for transpose.
bool scale_op
Flag indicating whether operator be scaled with <^2>
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Stores Epetra Cijk tensor.
bool is_stoch_parallel
Whether we have parallelism over stochastic blocks.
T & get(ParameterList &l, const std::string &name)
Teuchos::RCP< const EpetraExt::MultiComm > sg_comm
Stores SG parallel communicator.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()
Get SG polynomial.
KLMatrixFreeOperator(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_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< Teuchos::ParameterList > ¶ms)
Constructor.
virtual ordinal_type dimension() const =0
Return dimension of basis.
virtual const char * Label() const
Returns a character std::string describing the operator.
int expansion_size
Number of terms in expansion.
Teuchos::RCP< const Epetra_Map > range_base_map
Stores range base map.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerking basis.
Bi-directional iterator for traversing a sparse array.
Teuchos::Array< Teuchos::RCP< const Epetra_MultiVector > > input_block
MultiVectors for each block for Apply() input.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_Map > domain_sg_map
Stores domain SG map.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Cijk_type::k_iterator k_begin
Starting k iterator.
int max_num_mat_vec
Maximum number of matvecs in Apply.
Teuchos::RCP< const Cijk_type > Cijk
Stores triple product tensor.
Teuchos::RCP< const Epetra_BlockMap > stoch_col_map
Stores stochastic part of column map.
virtual ~KLMatrixFreeOperator()
Destructor.
Teuchos::RCP< Epetra_Import > col_importer
Importer from domain map to column map.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
bool include_mean
Flag indicating whether to include mean term.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
Teuchos::RCP< Epetra_Import > col_importer_trans
Importer from range map to column map.
Teuchos::RCP< Epetra_Map > global_col_map
Stores operator column SG map.
Teuchos::RCP< const Epetra_Map > domain_base_map
Stores domain base map.
virtual void setupOperator(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &poly)
Setup 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 ...
Teuchos::Array< Teuchos::RCP< Epetra_MultiVector > > result_block
MultiVectors for each block for Apply() result.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.