14 #include "EpetraExt_BlockVector.h"
15 #include "EpetraExt_RowMatrixOut.h"
17 #ifdef HAVE_STOKHOS_BOOST
18 #include <boost/functional/hash.hpp>
21 #ifdef HAVE_STOKHOS_BOOST // we have boost, use the hash Stokhos, use the hash!
22 std::size_t Stokhos::AdaptivityManager::Sparse3TensorHash::IJKHash::
23 operator()(
const Stokhos::AdaptivityManager::Sparse3TensorHash::IJK & ijk)
const
26 boost::hash_combine(seed,ijk.i_);
27 boost::hash_combine(seed,ijk.j_);
28 boost::hash_combine(seed,ijk.k_);
38 for(k_iterator k_it = Cijk.
k_begin();k_it!=Cijk.
k_end();k_it++) {
40 for(kj_iterator j_it = Cijk.
j_begin(k_it);j_it!=Cijk.
j_end(k_it);j_it++) {
42 for(kji_iterator i_it = Cijk.
i_begin(j_it);i_it!=Cijk.
i_end(j_it);i_it++) {
44 hashMap_[IJK(i,j,k)] = i_it.value();
52 boost::unordered_map<IJK,double>::const_iterator itr;
53 itr = hashMap_.find(IJK(i,j,k));
55 if(itr==hashMap_.end())
return 0.0;
59 #else // no BOOST, just default to the slow thing
66 return Cijk_.getValue(i,j,k);
74 bool onlyUseLinear,
int kExpOrder,
88 : sg_master_basis_(sg_master_basis), sg_basis_row_dof_(sg_basis_row_dof), scaleOp_(scaleOp)
112 bool onlyUseLinear,
bool includeMean)
const
123 Cijk_type::k_iterator k_begin = Cijk.
k_begin();
124 Cijk_type::k_iterator k_end = Cijk.
k_end();
125 if (!includeMean && index(k_begin) == 0)
128 int dim = sg_master_basis_->dimension();
129 k_end = Cijk.
find_k(dim+1);
134 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
141 sumInOperator(A,hashLookup,k,*block);
153 sumInOperator(A,hashLookup,k,J_k);
166 for(
int localM=0;localM<J_k.
NumMyRows();localM++) {
171 = sg_basis_row_dof_[localM];
181 for(
int rb_i=0;rb_i<rowStochBasis->size();rb_i++) {
182 int i = sg_master_basis_->index(rowStochBasis->term(rb_i));
184 double normValue = normValues[i];
186 int sg_m = getGlobalRowId(localM,rb_i);
190 std::vector<int> sg_indices;
191 std::vector<double> sg_values;
197 for(
int colInd=0;colInd<d_numEntries;colInd++) {
198 int localN = d_Indices[colInd];
202 = sg_basis_col_dof_[localN];
205 for(
int cb_j=0;cb_j<colStochBasis->size();cb_j++) {
206 int j = sg_master_basis_->index(colStochBasis->term(cb_j));
207 int sg_n = getGlobalColId(localN,cb_j);
211 if(cijk==0)
continue;
214 cijk = cijk/normValue;
216 sg_indices.push_back(sg_n);
217 sg_values.push_back(cijk*d_Values[colInd]);
234 for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
235 int P_i = getRowStochasticBasisSize(i);
236 int localId = rowMap_->LID(getGlobalRowId(i,0));
238 for(
int j=0;j<P_i;j++,localId++) {
239 int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
240 x[localId] = x_sg_bv->GetBlock(blk)->operator[](i);
249 int numBlocks = x_sg.
size();
253 for(
int blk=0;blk<numBlocks;blk++)
254 x_sg_bv->GetBlock(blk)->PutScalar(0.0);
257 for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
258 int P_i = getRowStochasticBasisSize(i);
259 int localId = rowMap_->LID(getGlobalRowId(i,0));
261 for(
int j=0;j<P_i;j++,localId++) {
262 int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
263 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)