//========================================================================= // NOTE: This method should be removed and replaced with calls to Epetra_Util_ExtractHbData() int Epetra_LinearProblemRedistor::ExtractHbData(int & M, int & N, int & nz, int * & ptr, int * & ind, double * & val, int & Nrhs, double * & rhs, int & ldrhs, double * & lhs, int & ldlhs) const { Epetra_CrsMatrix * RedistMatrix = dynamic_cast<Epetra_CrsMatrix *>(RedistProblem_->GetMatrix()); if (RedistMatrix==0) EPETRA_CHK_ERR(-1); // This matrix is zero or not an Epetra_CrsMatrix if (!RedistMatrix->IndicesAreContiguous()) { // Data must be contiguous for this to work EPETRA_CHK_ERR(-2); } M = RedistMatrix->NumMyRows(); N = RedistMatrix->NumMyCols(); nz = RedistMatrix->NumMyNonzeros(); val = (*RedistMatrix)[0]; // Dangerous, but cheap and effective way to access first element in const Epetra_CrsGraph & RedistGraph = RedistMatrix->Graph(); ind = RedistGraph[0]; // list of values and indices Epetra_MultiVector * LHS = RedistProblem_->GetLHS(); Epetra_MultiVector * RHS = RedistProblem_->GetRHS(); Nrhs = RHS->NumVectors(); if (Nrhs>1) { if (!RHS->ConstantStride()) {EPETRA_CHK_ERR(-3)}; // Must have strided vectors if (!LHS->ConstantStride()) {EPETRA_CHK_ERR(-4)}; // Must have strided vectors } ldrhs = RHS->Stride(); rhs = (*RHS)[0]; // Dangerous but effective (again) ldlhs = LHS->Stride(); lhs = (*LHS)[0]; // Finally build ptr vector if (ptr_==0) { ptr_ = new int[M+1]; ptr_[0] = 0; for (int i=0; i<M; i++) ptr_[i+1] = ptr_[i] + RedistGraph.NumMyIndices(i); } ptr = ptr_; return(0); }
void Stokhos::AdaptivityManager:: sumInOperator(Epetra_CrsMatrix & A,const Stokhos::AdaptivityManager::Sparse3TensorHash & Cijk,int k,const Epetra_CrsMatrix & J_k) const { TEUCHOS_ASSERT(J_k.NumMyRows() == int(sg_basis_row_dof_.size())); TEUCHOS_ASSERT(J_k.NumMyCols() == int(sg_basis_col_dof_.size())); const Teuchos::Array<double> & normValues = sg_master_basis_->norm_squared(); // loop over deterministic rows for(int localM=0;localM<J_k.NumMyRows();localM++) { int m = J_k.GRID(localM); // grab row basis Teuchos::RCP<const Stokhos::ProductBasis<int,double> > rowStochBasis = sg_basis_row_dof_[localM]; // grab row from deterministic system int d_numEntries; int * d_Indices; double * d_Values; J_k.ExtractMyRowView(localM,d_numEntries,d_Values,d_Indices); // loop over stochastic degrees of freedom of this row for(int rb_i=0;rb_i<rowStochBasis->size();rb_i++) { int i = sg_master_basis_->index(rowStochBasis->term(rb_i)); double normValue = normValues[i]; // sg_master_basis->norm_squared(i); int sg_m = getGlobalRowId(localM,rb_i); // we wipe out old values, capacity should gurantee // we don't allocate more often than neccessary! std::vector<int> sg_indices; std::vector<double> sg_values; // sg_indices.resize(0); // sg_values.resize(0); // loop over each column for(int colInd=0;colInd<d_numEntries;colInd++) { int localN = d_Indices[colInd]; // grab local deterministic column id // grab row basis Teuchos::RCP<const Stokhos::ProductBasis<int,double> > colStochBasis = sg_basis_col_dof_[localN]; // build values array for(int cb_j=0;cb_j<colStochBasis->size();cb_j++) { int j = sg_master_basis_->index(colStochBasis->term(cb_j)); int sg_n = getGlobalColId(localN,cb_j); double cijk = Cijk.getValue(i,j,k); // no reason to work it in! if(cijk==0) continue; if(scaleOp_) cijk = cijk/normValue; sg_indices.push_back(sg_n); sg_values.push_back(cijk*d_Values[colInd]); } } // add in matrix values A.SumIntoGlobalValues(sg_m,sg_indices.size(),&sg_values[0],&sg_indices[0]); } } }