11 #include "EpetraExt_BlockMultiVector.h"
12 #include "EpetraExt_BlockUtility.h"
25 label(
"Stokhos Matrix Free Operator"),
28 epetraCijk(epetraCijk_),
29 domain_base_map(domain_base_map_),
30 range_base_map(range_base_map_),
31 domain_sg_map(domain_sg_map_),
32 range_sg_map(range_sg_map_),
33 is_stoch_parallel(epetraCijk->isStochasticParallel()),
35 global_col_map_trans(),
36 stoch_col_map(epetraCijk->getStochasticColMap()),
39 Cijk(epetraCijk->getParallelCijk()),
43 only_use_linear(false),
45 use_block_apply(
true),
46 expansion_size(sg_basis->size()),
54 k_begin(Cijk->k_begin()),
57 scale_op = params->
get(
"Scale Operator by Inverse Basis Norms",
true);
71 int nj =
Cijk->num_j(k);
125 i_it != Cijk->i_end(j_it); ++i_it) {
135 return 2.0 *
static_cast<double>(n_apply) * static_cast<double>(nnz) +
136 static_cast<double>(n_add) * static_cast<double>(nrow);
145 num_blocks = block_ops->
size();
146 if (num_blocks < Cijk->num_k())
147 k_end = Cijk->find_k(num_blocks);
168 useTranspose = UseTheTranspose;
169 for (
int i=0; i<num_blocks; i++)
170 (*block_ops)[i].SetUseTranspose(useTranspose);
179 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
193 bool made_copy =
false;
194 if (Input.Values() == Result.Values() && !is_stoch_parallel) {
200 Result.PutScalar(0.0);
202 const Epetra_Map* input_base_map = domain_base_map.get();
203 const Epetra_Map* result_base_map = range_base_map.get();
204 if (useTranspose ==
true) {
205 input_base_map = range_base_map.get();
206 result_base_map = domain_base_map.get();
210 int m = Input.NumVectors();
211 if (useTranspose ==
false &&
212 (tmp ==
Teuchos::null || tmp->NumVectors() != m*max_num_mat_vec))
215 else if (useTranspose ==
true &&
217 tmp_trans->NumVectors() != m*max_num_mat_vec))
221 if (useTranspose ==
false)
222 tmp_result = tmp.get();
224 tmp_result = tmp_trans.get();
228 if (!is_stoch_parallel)
231 if (useTranspose ==
false) {
232 if (input_col ==
Teuchos::null || input_col->NumVectors() != m)
234 input_col->Import(*input, *col_importer,
Insert);
235 tmp_col = input_col.get();
239 input_col_trans->NumVectors() != m)
242 input_col_trans->Import(*input, *col_importer_trans,
Insert);
243 tmp_col = input_col_trans.get();
248 EpetraExt::BlockMultiVector sg_input(
View, *input_base_map, *tmp_col);
249 EpetraExt::BlockMultiVector sg_result(
View, *result_base_map, Result);
250 for (
int i=0; i<input_block.size(); i++)
251 input_block[i] = sg_input.GetBlock(i);
252 for (
int i=0; i<result_block.size(); i++)
253 result_block[i] = sg_result.GetBlock(i);
267 int nj = Cijk->num_j(k_it);
274 for (
int mm=0; mm<m; mm++) {
275 j_ptr[l*m+mm] = (*input_block[
j])[mm];
276 mj_indices[l*m+mm] = l*m+mm;
282 if (use_block_apply) {
283 (*block_ops)[k].Apply(input_tmp, result_tmp);
286 for (
int jj=0; jj<nj*m; jj++)
287 (*block_ops)[k].Apply(*(input_tmp(jj)), *(result_tmp(jj)));
293 i_it != Cijk->i_end(j_it); ++i_it) {
295 double c = value(i_it);
299 i_gid = epetraCijk->GCID(j);
301 i_gid = epetraCijk->GRID(i);
304 for (
int mm=0; mm<m; mm++)
305 (*result_block[i])(mm)->
Update(c, *result_tmp(l*m+mm), 1.0);
313 for (
int i=0; i<input_block.size(); i++)
315 for (
int i=0; i<result_block.size(); i++)
328 throw "MatrixFreeOperator::ApplyInverse not defined!";
342 return const_cast<char*
>(label.c_str());
366 return *range_sg_map;
367 return *domain_sg_map;
374 return *domain_sg_map;
375 return *range_sg_map;
MatrixFreeOperator(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.
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Teuchos::RCP< const Cijk_type > Cijk
Stores triple product tensor.
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 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 const char * Label() const
Returns a character string describing the operator.
T & get(ParameterList &l, const std::string &name)
int NumGlobalRows() const
Cijk_type::k_iterator k_end
Ending k iterator.
int expansion_size
Number of terms in expansion.
Teuchos::RCP< Epetra_Map > global_col_map_trans
Stores operator column SG map for transpose.
Teuchos::RCP< const Epetra_BlockMap > stoch_col_map
Stores stochastic part of column map.
virtual ~MatrixFreeOperator()
Destructor.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual ordinal_type dimension() const =0
Return dimension of basis.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerking basis.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Bi-directional iterator for traversing a sparse array.
bool is_stoch_parallel
Whether we have parallelism over stochastic blocks.
Teuchos::RCP< Epetra_Map > global_col_map
Stores operator column SG map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int max_num_mat_vec
Maximum number of matvecs in Apply.
Cijk_type::k_iterator k_begin
Starting k iterator.
Teuchos::RCP< const Epetra_Map > range_base_map
Stores range base map.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Stores Epetra Cijk tensor.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
bool include_mean
Flag indicating whether to include mean term.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
int NumGlobalNonzeros() const
Teuchos::RCP< const EpetraExt::MultiComm > sg_comm
Stores SG parallel communicator.
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 ...
Teuchos::Array< Teuchos::RCP< Epetra_MultiVector > > result_block
MultiVectors for each block for Apply() result.
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()
Get SG polynomial.
Teuchos::RCP< Epetra_Import > col_importer
Importer from domain map to column map.
Teuchos::RCP< const Epetra_Map > domain_base_map
Stores domain base map.
bool scale_op
Flag indicating whether operator be scaled with <^2>
Teuchos::RCP< const Epetra_Map > domain_sg_map
Stores domain SG map.
bool use_block_apply
Flag indicating whether to use block Epetra_MultiVector apply.
bool only_use_linear
Flag indicating whether to only use linear terms.
double countApplyFlops() const
Return number of FLOPS for each call to Apply()
Teuchos::RCP< const Epetra_Map > range_sg_map
Stores range SG map.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
Teuchos::RCP< Epetra_Import > col_importer_trans
Importer from range map to column map.
virtual void setupOperator(const Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > &poly)
Setup operator.
ordinal_type size() const
Return size.
Teuchos::Array< Teuchos::RCP< const Epetra_MultiVector > > input_block
MultiVectors for each block for Apply() input.