60 #include "EpetraExt_MultiMpiComm.h"
64 #include "EpetraExt_MultiSerialComm.h"
68 #include "EpetraExt_RowMatrixOut.h"
80 int colOffset[] = {-1, 0, 1};
81 for(
int myRow=0;myRow<numUnks;myRow++) {
82 int row = map.
GID(myRow);
84 colIndices[i] = colOffset[i]+row;
90 colPtr = colIndices+1;
114 int colOffset[] = {-1, 0, 1};
115 double * stencilPtr = 0;
117 int row = map.
GID(myRow);
119 colIndices[i] = colOffset[i]+row;
122 stencilPtr = stencil;
126 colPtr = colIndices+1;
127 stencilPtr = stencil+1;
139 template <
typename ScalarT,
typename OrdinalT>
140 bool ord_func(std::pair<ScalarT,OrdinalT>
const & a, std::pair<ScalarT,OrdinalT>
const & b)
141 {
return a.first < b.first; }
143 template <
typename ScalarT>
146 typedef std::pair<ScalarT,std::size_t> Pair;
149 std::vector<Pair> pairValues(values.size());
150 for(std::size_t i=0;i<values.size();i++)
151 pairValues[i] = std::make_pair(values[i],i);
154 std::sort(pairValues.begin(),pairValues.end(),ord_func<ScalarT,std::size_t>);
157 order.resize(pairValues.size());
158 for(std::size_t i=0;i<pairValues.size();i++)
159 order[i] = pairValues[i].second;
162 template <
typename ScalarT>
163 void apply_ordering(std::vector<ScalarT> & values,
const std::vector<std::size_t> & order)
165 typedef std::pair<std::size_t,ScalarT> Pair;
168 std::vector<Pair> pairValues(values.size());
169 for(std::size_t i=0;i<order.size();i++)
170 pairValues[i] = std::make_pair(order[i],values[i]);
173 std::sort(pairValues.begin(),pairValues.end(),ord_func<std::size_t,ScalarT>);
176 for(std::size_t i=0;i<pairValues.size();i++)
177 values[i] = pairValues[i].second;
198 std::vector<int> order(3);
199 order[0] = 2; order[1] = 3; order[2] = 1;
200 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(3);
203 sa_BasisPerDRow[2] =
buildBasis(num_KL,order);
239 int numDetermUnks = 3;
241 double stencil[] = {-1.0,2.0,-1.0};
250 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermUnks);
257 params->
set(
"Scale Operator by Inverse Basis Norms",
true);
269 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
271 std::vector<std::size_t> order;
272 std::vector<int> stor_indices(9), indices;
273 std::vector<double> stor_values(9), values;
280 for(
int i=0;i<numEntries;i++) {
281 indices.push_back(stor_indices[i]);
282 values.push_back(stor_values[i]);
290 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
294 double normValue = basis->norm_squared(rowTerm);
297 TEST_EQUALITY(values[0],stencil[0]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
298 TEST_EQUALITY(values[1],stencil[0]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
299 TEST_EQUALITY(values[2],stencil[0]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
301 TEST_EQUALITY(values[3],stencil[1]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
302 TEST_EQUALITY(values[4],stencil[1]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
303 TEST_EQUALITY(values[5],stencil[1]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
305 TEST_EQUALITY(values[6],stencil[2]*Cijk->getValue(rowTerm,colTerm0,0)/normValue);
306 TEST_EQUALITY(values[7],stencil[2]*Cijk->getValue(rowTerm,colTerm1,0)/normValue);
307 TEST_EQUALITY(values[8],stencil[2]*Cijk->getValue(rowTerm,colTerm2,0)/normValue);
315 params->
set(
"Scale Operator by Inverse Basis Norms",
false);
327 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
329 std::vector<std::size_t> order;
330 std::vector<int> stor_indices(9), indices;
331 std::vector<double> stor_values(9), values;
338 for(
int i=0;i<numEntries;i++) {
339 indices.push_back(stor_indices[i]);
340 values.push_back(stor_values[i]);
348 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
354 TEST_EQUALITY(values[0],stencil[0]*Cijk->getValue(rowTerm,colTerm0,0));
355 TEST_EQUALITY(values[1],stencil[0]*Cijk->getValue(rowTerm,colTerm1,0));
356 TEST_EQUALITY(values[2],stencil[0]*Cijk->getValue(rowTerm,colTerm2,0));
358 TEST_EQUALITY(values[3],stencil[1]*Cijk->getValue(rowTerm,colTerm0,0));
359 TEST_EQUALITY(values[4],stencil[1]*Cijk->getValue(rowTerm,colTerm1,0));
360 TEST_EQUALITY(values[5],stencil[1]*Cijk->getValue(rowTerm,colTerm2,0));
362 TEST_EQUALITY(values[6],stencil[2]*Cijk->getValue(rowTerm,colTerm0,0));
363 TEST_EQUALITY(values[7],stencil[2]*Cijk->getValue(rowTerm,colTerm1,0));
364 TEST_EQUALITY(values[8],stencil[2]*Cijk->getValue(rowTerm,colTerm2,0));
384 int numDetermUnks = 3;
386 double stencil[] = {-1.0,2.0,-1.0};
397 std::vector<int> vorder(4);
398 vorder[0] = 2; vorder[1] = 3; vorder[2] = 2; vorder[3] = 0;
399 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermUnks);
402 sa_BasisPerDRow[2] =
buildBasis(num_KL,vorder);
406 params->
set(
"Scale Operator by Inverse Basis Norms",
false);
415 out <<
"Summed into" << std::endl;
419 for(
int stochBasis=0;stochBasis<sa_BasisPerDRow[determDof]->size();stochBasis++) {
421 std::vector<std::size_t> order;
422 std::vector<int> stor_indices(400), indices;
423 std::vector<double> stor_values(400), values;
425 out <<
"grabbing row " << stochBasis <<
" values" << std::endl;
427 out <<
"num entries " << numEntries << std::endl;
432 for(
int i=0;i<numEntries;i++) {
433 indices.push_back(stor_indices[i]);
434 values.push_back(stor_values[i]);
438 out <<
"sort row" << std::endl;
443 out <<
"grabbing row index, and row norm" << std::endl;
444 int rowTerm = basis->index(sa_BasisPerDRow[determDof]->term(stochBasis));
446 out <<
"checking matrix" << std::endl;
449 for(
int stochColBasisIndex = 0;stochColBasisIndex<3;stochColBasisIndex++) {
453 if(big(rowTerm,colTerm)) {
455 TEST_EQUALITY(values[offset],stencil[stochColBasisIndex]*Cijk->getValue(rowTerm,colTerm,0));
459 out <<
"offset = " << offset << std::endl;
482 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(determGraph->
NumMyRows(),basis);
486 std::vector<int> sa_RowGidOffsets;
494 TEST_EQUALITY(rowMap->NumMyElements(),determMyRows*basis->size());
495 TEST_EQUALITY(rowMap->NumGlobalElements(),determGlobalRows*basis->size());
502 for(std::size_t i=0;i<sa_RowGidOffsets.size();i++)
503 result &= (sa_RowGidOffsets[i]==rowMap->GID(i*basis->size()));
509 std::vector<int> sa_ColGidOffsets;
523 bool checkOne =
false;
524 for(
int localColId=0;localColId<determMyCols;localColId++) {
525 int localRowId = d_rowMap.
LID(d_colMap.
GID(localColId));
531 result &= (sa_ColGidOffsets[localColId]==sa_RowGidOffsets[localRowId]);
548 int rank = comm->
MyPID();
550 out <<
"NumProc = " << numProc <<
", Rank = " << rank << std::endl;
552 int numDetermRows = 3;
559 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(numDetermRows);
560 for(
int i=0;i<numDetermRows;i+=3) {
562 if(i+1<numDetermRows)
564 if(i+2<numDetermRows)
568 for(
int i=0;i<numDetermRows;i++) {
569 out <<
"Row " << i <<
":\n";
574 for(
int i=1;i<numDetermRows;i++) {
575 out <<
"Pair row " << i-1 <<
", col " << i <<
":\n";
579 out <<
"Pair row " << i <<
", col " << i-1 <<
":\n";
591 for(
int i=0;i<numDetermRows;i++) {
592 int gid = determGraph->
GRID(i);
594 int numRowEntries = 0;
598 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
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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