48 #include "EpetraExt_BlockVector.h"
49 #include "EpetraExt_RowMatrixOut.h"
51 #ifdef HAVE_STOKHOS_BOOST
52 #include <boost/functional/hash.hpp>
55 #ifdef HAVE_STOKHOS_BOOST // we have boost, use the hash Stokhos, use the hash!
56 std::size_t Stokhos::AdaptivityManager::Sparse3TensorHash::IJKHash::
57 operator()(
const Stokhos::AdaptivityManager::Sparse3TensorHash::IJK & ijk)
const
60 boost::hash_combine(seed,ijk.i_);
61 boost::hash_combine(seed,ijk.j_);
62 boost::hash_combine(seed,ijk.k_);
72 for(k_iterator k_it = Cijk.
k_begin();k_it!=Cijk.
k_end();k_it++) {
74 for(kj_iterator j_it = Cijk.
j_begin(k_it);j_it!=Cijk.
j_end(k_it);j_it++) {
76 for(kji_iterator i_it = Cijk.
i_begin(j_it);i_it!=Cijk.
i_end(j_it);i_it++) {
78 hashMap_[IJK(i,j,k)] = i_it.value();
86 boost::unordered_map<IJK,double>::const_iterator itr;
87 itr = hashMap_.find(IJK(i,j,k));
89 if(itr==hashMap_.end())
return 0.0;
93 #else // no BOOST, just default to the slow thing
100 return Cijk_.getValue(i,j,k);
108 bool onlyUseLinear,
int kExpOrder,
122 : sg_master_basis_(sg_master_basis), sg_basis_row_dof_(sg_basis_row_dof), scaleOp_(scaleOp)
146 bool onlyUseLinear,
bool includeMean)
const
157 Cijk_type::k_iterator k_begin = Cijk.
k_begin();
158 Cijk_type::k_iterator k_end = Cijk.
k_end();
159 if (!includeMean && index(k_begin) == 0)
162 int dim = sg_master_basis_->dimension();
163 k_end = Cijk.
find_k(dim+1);
168 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
175 sumInOperator(A,hashLookup,k,*block);
187 sumInOperator(A,hashLookup,k,J_k);
200 for(
int localM=0;localM<J_k.
NumMyRows();localM++) {
205 = sg_basis_row_dof_[localM];
215 for(
int rb_i=0;rb_i<rowStochBasis->size();rb_i++) {
216 int i = sg_master_basis_->index(rowStochBasis->term(rb_i));
218 double normValue = normValues[i];
220 int sg_m = getGlobalRowId(localM,rb_i);
224 std::vector<int> sg_indices;
225 std::vector<double> sg_values;
231 for(
int colInd=0;colInd<d_numEntries;colInd++) {
232 int localN = d_Indices[colInd];
236 = sg_basis_col_dof_[localN];
239 for(
int cb_j=0;cb_j<colStochBasis->size();cb_j++) {
240 int j = sg_master_basis_->index(colStochBasis->term(cb_j));
241 int sg_n = getGlobalColId(localN,cb_j);
245 if(cijk==0)
continue;
248 cijk = cijk/normValue;
250 sg_indices.push_back(sg_n);
251 sg_values.push_back(cijk*d_Values[colInd]);
268 for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
269 int P_i = getRowStochasticBasisSize(i);
270 int localId = rowMap_->LID(getGlobalRowId(i,0));
272 for(
int j=0;j<P_i;j++,localId++) {
273 int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
274 x[localId] = x_sg_bv->GetBlock(blk)->operator[](i);
283 int numBlocks = x_sg.
size();
287 for(
int blk=0;blk<numBlocks;blk++)
288 x_sg_bv->GetBlock(blk)->PutScalar(0.0);
291 for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
292 int P_i = getRowStochasticBasisSize(i);
293 int localId = rowMap_->LID(getGlobalRowId(i,0));
295 for(
int j=0;j<P_i;j++,localId++) {
296 int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
297 x_sg_bv->GetBlock(blk)->operator[](i) = x[localId];
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
k_iterator k_begin() const
Iterator pointing to first k entry.
const Epetra_Comm & Comm() const
void buildColBasisFunctions(const Epetra_CrsGraph &determGraph, const Teuchos::RCP< const Stokhos::ProductBasis< int, double > > &masterBasis, const std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > &per_dof_row_basis, std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > &per_dof_col_basis)
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > sg_basis_row_dof_
virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
void setupOperator(Epetra_CrsMatrix &A, const Sparse3Tensor< int, double > &Cijk, Stokhos::EpetraOperatorOrthogPoly &poly, bool onlyUseLinear=false, bool includeMean=true) const
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Bi-directional iterator for traversing a sparse array.
int ExtractMyRowView(int MyRow, int &NumEntries, double *&Values, int *&Indices) const
int PutScalar(double ScalarConstant)
Teuchos::RCP< Epetra_CrsGraph > buildAdaptedGraph(const Epetra_CrsGraph &determGraph, const Teuchos::RCP< const Stokhos::ProductBasis< int, double > > &masterBasis, const std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > &per_dof_row_basis, bool onlyUseLinear=false, int kExpOrder=-1)
void copyFromAdaptiveVector(const Epetra_Vector &x, Stokhos::EpetraVectorOrthogPoly &x_sg) const
void copyToAdaptiveVector(const Stokhos::EpetraVectorOrthogPoly &x_sg, Epetra_Vector &x) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::vector< int > myRowGidOffsets_
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
Teuchos::RCP< Epetra_Map > buildAdaptedRowMapAndOffsets(const Epetra_Comm &Comm, const std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > &per_dof_row_basis, std::vector< int > &myRowGidOffsets)
Sparse3TensorHash(const Stokhos::Sparse3Tensor< int, double > &Cijk)
void setupWithGraph(const Epetra_CrsGraph &graph, bool onlyUseLinear, int kExpOrder)
void buildAdaptedColOffsets(const Epetra_CrsGraph &determGraph, const std::vector< int > &myRowGidOffsets, std::vector< int > &myColGidOffsets)
k_iterator k_end() const
Iterator pointing to last k entry.
k_iterator find_k(ordinal_type k) const
Return k iterator for given index k.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Stokhos::Sparse3Tensor< int, double > Cijk_type
Teuchos::RCP< coeff_type > getCoeffPtr(ordinal_type i)
Return ref-count pointer to coefficient i.
Teuchos::RCP< Epetra_CrsMatrix > buildMatrixFromGraph() const
Teuchos::RCP< const Stokhos::ProductBasis< int, double > > sg_master_basis_
double getValue(int i, int j, int k) const
#define TEUCHOS_ASSERT(assertion_test)
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
void sumInOperator(Epetra_CrsMatrix &A, const Stokhos::Sparse3Tensor< int, double > &Cijk, int k, const Epetra_CrsMatrix &J_k) const
ordinal_type size() const
Return size.
Teuchos::RCP< Epetra_Map > rowMap_
AdaptivityManager(const Teuchos::RCP< const Stokhos::ProductBasis< int, double > > &sg_master_basis, const std::vector< Teuchos::RCP< const Stokhos::ProductBasis< int, double > > > &sg_basis_row_dof, const Epetra_CrsGraph &determ_graph, bool onlyUseLinear, int kExpOrder, bool scaleOp=true)