26 #include "EpetraExt_MultiMpiComm.h"
30 #include "EpetraExt_MultiSerialComm.h"
34 #include "EpetraExt_RowMatrixOut.h"
46 int colOffset[] = {-1, 0, 1};
47 for(
int myRow=0;myRow<numUnks;myRow++) {
48 int row = map.
GID(myRow);
50 colIndices[i] = colOffset[i]+row;
56 colPtr = colIndices+1;
80 int colOffset[] = {-1, 0, 1};
81 double * stencilPtr = 0;
83 int row = map.
GID(myRow);
85 colIndices[i] = colOffset[i]+row;
92 colPtr = colIndices+1;
93 stencilPtr = stencil+1;
105 template <
typename ScalarT,
typename OrdinalT>
106 bool ord_func(std::pair<ScalarT,OrdinalT>
const & a, std::pair<ScalarT,OrdinalT>
const & b)
107 {
return a.first < b.first; }
109 template <
typename ScalarT>
112 typedef std::pair<ScalarT,std::size_t> Pair;
115 std::vector<Pair> pairValues(values.size());
116 for(std::size_t i=0;i<values.size();i++)
117 pairValues[i] = std::make_pair(values[i],i);
120 std::sort(pairValues.begin(),pairValues.end(),ord_func<ScalarT,std::size_t>);
123 order.resize(pairValues.size());
124 for(std::size_t i=0;i<pairValues.size();i++)
125 order[i] = pairValues[i].second;
128 template <
typename ScalarT>
129 void apply_ordering(std::vector<ScalarT> & values,
const std::vector<std::size_t> & order)
131 typedef std::pair<std::size_t,ScalarT> Pair;
134 std::vector<Pair> pairValues(values.size());
135 for(std::size_t i=0;i<order.size();i++)
136 pairValues[i] = std::make_pair(order[i],values[i]);
139 std::sort(pairValues.begin(),pairValues.end(),ord_func<std::size_t,ScalarT>);
142 for(std::size_t i=0;i<pairValues.size();i++)
143 values[i] = pairValues[i].second;
164 std::vector<int> order(3);
165 order[0] = 2; order[1] = 3; order[2] = 1;
166 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(3);
169 sa_BasisPerDRow[2] =
buildBasis(num_KL,order);
205 int numDetermUnks = 3;
207 double stencil[] = {-1.0,2.0,-1.0};
216 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermUnks);
223 params->
set(
"Scale Operator by Inverse Basis Norms",
true);
235 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
237 std::vector<std::size_t> order;
238 std::vector<int> stor_indices(9), indices;
239 std::vector<double> stor_values(9), values;
246 for(
int i=0;i<numEntries;i++) {
247 indices.push_back(stor_indices[i]);
248 values.push_back(stor_values[i]);
256 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
260 double normValue = basis->norm_squared(rowTerm);
263 TEST_EQUALITY(values[0],stencil[0]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
264 TEST_EQUALITY(values[1],stencil[0]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
265 TEST_EQUALITY(values[2],stencil[0]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
267 TEST_EQUALITY(values[3],stencil[1]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
268 TEST_EQUALITY(values[4],stencil[1]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
269 TEST_EQUALITY(values[5],stencil[1]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
271 TEST_EQUALITY(values[6],stencil[2]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
272 TEST_EQUALITY(values[7],stencil[2]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
273 TEST_EQUALITY(values[8],stencil[2]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
281 params->
set(
"Scale Operator by Inverse Basis Norms",
false);
293 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
295 std::vector<std::size_t> order;
296 std::vector<int> stor_indices(9), indices;
297 std::vector<double> stor_values(9), values;
304 for(
int i=0;i<numEntries;i++) {
305 indices.push_back(stor_indices[i]);
306 values.push_back(stor_values[i]);
314 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
320 TEST_EQUALITY(values[0],stencil[0]*Cijk->getValue(rowTerm,colTerm0,0));
321 TEST_EQUALITY(values[1],stencil[0]*Cijk->getValue(rowTerm,colTerm1,0));
322 TEST_EQUALITY(values[2],stencil[0]*Cijk->getValue(rowTerm,colTerm2,0));
324 TEST_EQUALITY(values[3],stencil[1]*Cijk->getValue(rowTerm,colTerm0,0));
325 TEST_EQUALITY(values[4],stencil[1]*Cijk->getValue(rowTerm,colTerm1,0));
326 TEST_EQUALITY(values[5],stencil[1]*Cijk->getValue(rowTerm,colTerm2,0));
328 TEST_EQUALITY(values[6],stencil[2]*Cijk->getValue(rowTerm,colTerm0,0));
329 TEST_EQUALITY(values[7],stencil[2]*Cijk->getValue(rowTerm,colTerm1,0));
330 TEST_EQUALITY(values[8],stencil[2]*Cijk->getValue(rowTerm,colTerm2,0));
350 int numDetermUnks = 3;
352 double stencil[] = {-1.0,2.0,-1.0};
363 std::vector<int> vorder(4);
364 vorder[0] = 2; vorder[1] = 3; vorder[2] = 2; vorder[3] = 0;
365 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermUnks);
368 sa_BasisPerDRow[2] =
buildBasis(num_KL,vorder);
372 params->
set(
"Scale Operator by Inverse Basis Norms",
false);
381 out <<
"Summed into" << std::endl;
385 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
387 std::vector<std::size_t> order;
388 std::vector<int> stor_indices(400), indices;
389 std::vector<double> stor_values(400), values;
391 out <<
"grabbing row " << stochBasis <<
" values" << std::endl;
393 out <<
"num entries " << numEntries << std::endl;
398 for(
int i=0;i<numEntries;i++) {
399 indices.push_back(stor_indices[i]);
400 values.push_back(stor_values[i]);
404 out <<
"sort row" << std::endl;
409 out <<
"grabbing row index, and row norm" << std::endl;
410 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
412 out <<
"checking matrix" << std::endl;
415 for(
int stochColBasisIndex = 0;stochColBasisIndex<3;stochColBasisIndex++) {
419 if(big(rowTerm,colTerm)) {
421 TEST_EQUALITY(values[offset],stencil[stochColBasisIndex]*Cijk->getValue(rowTerm,colTerm,0));
425 out <<
"offset = " << offset << std::endl;
448 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(determGraph->
NumMyRows(),basis);
452 std::vector<int> sa_RowGidOffsets;
460 TEST_EQUALITY(rowMap->NumMyElements(),determMyRows*basis->size());
461 TEST_EQUALITY(rowMap->NumGlobalElements(),determGlobalRows*basis->size());
468 for(std::size_t i=0;i<sa_RowGidOffsets.size();i++)
469 result &= (sa_RowGidOffsets[i]==rowMap->GID(i*basis->size()));
475 std::vector<int> sa_ColGidOffsets;
489 bool checkOne =
false;
490 for(
int localColId=0;localColId<determMyCols;localColId++) {
491 int localRowId = d_rowMap.
LID(d_colMap.
GID(localColId));
497 result &= (sa_ColGidOffsets[localColId]==sa_RowGidOffsets[localRowId]);
514 int rank = comm->
MyPID();
516 out <<
"NumProc = " << numProc <<
", Rank = " << rank << std::endl;
518 int numDetermRows = 3;
525 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermRows);
526 for(
int i=0;i<numDetermRows;i+=3) {
528 if(i+1<numDetermRows)
530 if(i+2<numDetermRows)
534 for(
int i=0;i<numDetermRows;i++) {
535 out <<
"Row " << i <<
":\n";
540 for(
int i=1;i<numDetermRows;i++) {
541 out <<
"Pair row " << i-1 <<
", col " << i <<
":\n";
545 out <<
"Pair row " << i <<
", col " << i-1 <<
":\n";
557 for(
int i=0;i<numDetermRows;i++) {
558 int gid = determGraph->
GRID(i);
560 int numRowEntries = 0;
564 for(
int c=0;c<numRowEntries;c++)
int NumGlobalElements() const
Teuchos::RCP< const Stokhos::ProductBasis< int, double > > getColStochasticBasis(int determLid) const
const Epetra_Comm & Comm() const
int ExtractGlobalRowCopy(int_type Row, int Length, int &NumEntries, double *values, int_type *Indices) const
void printGraph(std::ostream &os) const
int NumGlobalRows() const
virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
const Epetra_BlockMap & ColMap() const
std::size_t numNonZeros() const
How many non zeros are in this graph.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
virtual int MyPID() const =0
int PutScalar(double ScalarConstant)
const Epetra_Map & RowMap() const
int NumMyElements() const
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)
int getGlobalColId(int determLid, int basisIndex) const
virtual const MultiIndex< ordinal_type > & term(ordinal_type i) const =0
Get orders of each coordinate polynomial given an index i.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
int getColStochasticBasisSize(int determLid) const
const Epetra_BlockMap & RowMap() const
int NumGlobalCols() const
void buildAdaptedColOffsets(const Epetra_CrsGraph &determGraph, const std::vector< int > &myRowGidOffsets, std::vector< int > &myColGidOffsets)
int getRowStochasticBasisSize(int determLid) const
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
Teuchos::RCP< Epetra_CrsMatrix > buildMatrixFromGraph() const
int GRID(int LRID_in) const
virtual int NumProc() const =0
int ExtractGlobalRowCopy(int_type Row, int LenOfIndices, int &NumIndices, int_type *Indices) const
#define TEST_EQUALITY(v1, v2)
#define TEUCHOS_ASSERT(assertion_test)
int NumMyNonzeros() const
void sumInOperator(Epetra_CrsMatrix &A, const Stokhos::Sparse3Tensor< int, double > &Cijk, int k, const Epetra_CrsMatrix &J_k) const
int getGlobalRowId(int determLid, int basisIndex) const