Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BuildColBasisUnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <Teuchos_ConfigDefs.hpp>
12 #include <Teuchos_TimeMonitor.hpp>
13 #include <Teuchos_RCP.hpp>
14 
16 
17 // Stokhos Stochastic Galerkin
20 #include "Stokhos_ParallelData.hpp"
23 
24 #ifdef HAVE_MPI
25  #include "Epetra_MpiComm.h"
26  #include "EpetraExt_MultiMpiComm.h"
27  #include "mpi.h"
28 #else
29  #include "Epetra_SerialComm.h"
30  #include "EpetraExt_MultiSerialComm.h"
31 #endif
32 #include "Epetra_CrsGraph.h"
33 
34 #include "EpetraExt_RowMatrixOut.h"
35 
37 {
38  Epetra_Map map(-1,numUnks,0,Comm);
40  = Teuchos::rcp(new Epetra_CrsGraph(Copy,map,0));
41 
42  // build tridiagonal graph
43  int colCnt = 3;
44  int * colPtr = 0;
45  int colIndices[3];
46  int colOffset[] = {-1, 0, 1};
47  for(int myRow=0;myRow<numUnks;myRow++) {
48  int row = map.GID(myRow);
49  for(int i=0;i<3;i++)
50  colIndices[i] = colOffset[i]+row;
51  colCnt = 3;
52  colPtr = colIndices;
53 
54  if(row==0) {
55  colCnt = 2;
56  colPtr = colIndices+1;
57  }
58  else if(row==map.NumGlobalElements()-1)
59  colCnt = 2;
60 
61  TEUCHOS_ASSERT(graph->InsertGlobalIndices(row,colCnt,colPtr)==0);
62  }
63 
64  graph->FillComplete();
65 
66  return graph;
67 }
68 
69 // Test construction of Linear Algebra (LA) data structures
70 TEUCHOS_UNIT_TEST(tBuildColBasis, test_adapted)
71 {
72  #ifdef HAVE_MPI
74  #else
76  #endif
77 
78  int numProc = comm->NumProc();
79  int rank = comm->MyPID();
80 
81  out << "NumProc = " << numProc << ", Rank = " << rank << std::endl;
82 
83  int num_KL = 3;
84  int porder = 3;
85 
88 
89  std::vector<int> order(3);
90  order[0] = 2; order[1] = 3; order[2] = 1;
91  std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(3);
92  sa_BasisPerDRow[0] = buildBasis(num_KL,1);
93  sa_BasisPerDRow[1] = buildBasis(num_KL,1);
94  sa_BasisPerDRow[2] = buildBasis(num_KL,order);
95 
96  std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDCol;
97  Stokhos::adapt_utils::buildColBasisFunctions(*determGraph,basis,sa_BasisPerDRow,sa_BasisPerDCol);
98 
99  if(numProc==2)
100  { TEST_EQUALITY(sa_BasisPerDCol.size(),4); }
101  else
102  { TEST_EQUALITY(sa_BasisPerDCol.size(),3); }
103 
104  for(std::size_t c=0;c<sa_BasisPerDCol.size();c++) {
105  int gid = determGraph->ColMap().GID(c);
107  Teuchos::rcp_dynamic_cast<const Stokhos::ProductBasis<int,double> >(sa_BasisPerDCol[c]);
108 
110  = cBasis->getCoordinateBases();
111 
112  for(int i=0;i<cBases.size();i++) {
113  int bOrder = cBases[i]->order();
114 
115  if(gid==2)
116  { TEST_EQUALITY(bOrder,order[i]); }
117  else if(gid==5)
118  { TEST_EQUALITY(bOrder,order[i]); }
119  else
120  { TEST_EQUALITY(bOrder,1); }
121  }
122  }
123 }
int NumGlobalElements() 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)
const Epetra_BlockMap & ColMap() const
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
virtual int MyPID() const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int GID(int LID) const
Teuchos::RCP< Epetra_CrsGraph > buildTridiagonalGraph(int numUnks, const Epetra_Comm &Comm)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
virtual int NumProc() const =0
#define TEST_EQUALITY(v1, v2)
#define TEUCHOS_ASSERT(assertion_test)
TEUCHOS_UNIT_TEST(tAdaptivityManager, test_interface)