Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BasisInteractionGraphUnitTest.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"
21 
22 #ifdef HAVE_MPI
23  #include "Epetra_MpiComm.h"
24  #include "mpi.h"
25 #else
26  #include "Epetra_SerialComm.h"
27 #endif
28 
29 TEUCHOS_UNIT_TEST(basis_interaction_graph, test_square)
30 {
31  #ifdef HAVE_MPI
33  #else
35  #endif
36 
37  int numProc = comm->NumProc();
38 
39  int num_KL = 3;
40  int porder = 3;
41 
43  Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk = basis->computeTripleProductTensor();
44  Teuchos::RCP<Stokhos::ParallelData> sg_parallel_data;
45 
46  {
47  Teuchos::ParameterList parallelParams;
48  parallelParams.set("Number of Spatial Processors", numProc);
49  sg_parallel_data = Teuchos::rcp(new Stokhos::ParallelData(basis, Cijk, comm,
50  parallelParams));
51  }
52  Teuchos::RCP<const EpetraExt::MultiComm> sg_comm = sg_parallel_data->getMultiComm();
54  Teuchos::rcp(new Stokhos::EpetraSparse3Tensor(basis,Cijk,sg_comm));
55 
56  Stokhos::BasisInteractionGraph big(*basis);
57 
58  // for grins print out the graph
59  out << "Size = " << big.rowCount() << " x " << big.colCount() << std::endl;
60 
61  for(std::size_t i=0;i<big.rowCount();i++) {
62  for(std::size_t j=0;j<big.colCount();j++)
63  out << " " << (big(i,j) ? "*" : " " ) << " ";
64  out << std::endl;
65  }
66  out << std::endl;
67 
68  // check the graph for correctness
70  TEST_EQUALITY(graph->NumMyRows(),graph->NumGlobalRows());
71  TEST_EQUALITY(int(big.rowCount()),graph->NumMyRows());
72  TEST_EQUALITY(int(big.colCount()),graph->NumMyCols());
73 
74  for(int i=0;i<graph->NumGlobalRows();i++) {
75  bool rowPassed = true;
76  int count = 0;
77  std::vector<bool> row(graph->NumGlobalRows(),false);
78  std::vector<int> activeRow(graph->NumGlobalRows());
79  graph->ExtractGlobalRowCopy(i,graph->NumGlobalRows(),count,&activeRow[0]);
80 
81  // get truth graph
82  for(int j=0;j<count;j++)
83  row[activeRow[j]] = true;
84 
85  // check active row
86  for(std::size_t j=0;j<row.size();j++)
87  rowPassed = rowPassed && (row[j]==big(i,j));
88 
89  TEST_ASSERT(rowPassed);
90  }
91 }
92 
93 TEUCHOS_UNIT_TEST(basis_interaction_graph, test_isotropic_rect)
94 {
95  #ifdef HAVE_MPI
97  #else
99  #endif
100 
101  int num_KL = 2;
102  int porder = 3;
103 
107 
108  out << "Master Array Basis = \n";
109  for(int i=0;i<masterBasis->size();i++) {
110  Stokhos::MultiIndex<int> masterArray = masterBasis->term(i);
111  for(int i=0;i<num_KL;i++) {
112  out << masterArray[i] << " ";
113  }
114  out << std::endl;
115  }
116 
117  out << "Row Array Basis = \n";
118  for(int i=0;i<rowBasis->size();i++) {
119  Stokhos::MultiIndex<int> rowArray = rowBasis->term(i);
120  for(int i=0;i<num_KL;i++) {
121  out << rowArray[i] << " ";
122  }
123  out << std::endl;
124  }
125 
126  Stokhos::BasisInteractionGraph masterBig(*masterBasis);
127  Stokhos::BasisInteractionGraph rectBig(*masterBasis,*rowBasis,*colBasis);
128 
129  out << "rowBasis.size = " << rowBasis->size() << std::endl;
130  out << "colBasis.size = " << colBasis->size() << std::endl;
131 
132  // for grins print out the graph
133  out << "Size = " << rectBig.rowCount() << " x " << rectBig.colCount() << std::endl;
134  for(std::size_t i=0;i<rectBig.rowCount();i++) {
135  for(std::size_t j=0;j<rectBig.colCount();j++)
136  out << " " << (rectBig(i,j) ? "*" : " " ) << " ";
137  out << std::endl;
138  }
139  out << std::endl;
140 
141  out << "Size = " << masterBig.rowCount() << " x " << masterBig.colCount() << std::endl;
142  for(std::size_t i=0;i<masterBig.rowCount();i++) {
143  for(std::size_t j=0;j<masterBig.colCount();j++)
144  out << " " << (masterBig(i,j) ? "*" : " " ) << " ";
145  out << std::endl;
146  }
147  out << std::endl;
148 
149  // loop over rectangle graph making sure it matches with the master graph
150  bool graphs_match = true;
151  for(std::size_t i=0;i<rectBig.rowCount();i++) {
152  std::size_t masterI = masterBasis->index(rowBasis->term(i));
153  for(std::size_t j=0;j<rectBig.colCount();j++) {
154  std::size_t masterJ = masterBasis->index(colBasis->term(j));
155  graphs_match &= (rectBig(i,j)==masterBig(masterI,masterJ));
156  }
157  }
158 
159  TEST_ASSERT(graphs_match);
160 }
int NumGlobalRows() const
#define TEST_ASSERT(v1)
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
std::size_t colCount() const
What is the number of columns.
Teuchos::RCP< const Epetra_CrsGraph > getStochasticGraph() const
Get stochastic graph.
int NumMyRows() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int NumMyCols() const
A multidimensional index.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
std::size_t rowCount() const
What is the number of rows.
virtual int NumProc() const =0
int ExtractGlobalRowCopy(int_type Row, int LenOfIndices, int &NumIndices, int_type *Indices) const
#define TEST_EQUALITY(v1, v2)
TEUCHOS_UNIT_TEST(tAdaptivityManager, test_interface)