Stokhos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
test
UnitTest
Stokhos_BasisInteractionGraphUnitTest.cpp
Go to the documentation of this file.
1
/*
2
// @HEADER
3
// ***********************************************************************
4
//
5
// Stokhos Package
6
// Copyright (2009) Sandia Corporation
7
//
8
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
// license for use of this work by or on behalf of the U.S. Government.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
39
//
40
// ***********************************************************************
41
// @HEADER
42
*/
43
44
#include <Teuchos_ConfigDefs.hpp>
45
#include <Teuchos_UnitTestHarness.hpp>
46
#include <Teuchos_TimeMonitor.hpp>
47
#include <Teuchos_RCP.hpp>
48
49
#include "
Stokhos_InterlacedTestSupport.hpp
"
50
51
// Stokhos Stochastic Galerkin
52
#include "
Stokhos_BasisInteractionGraph.hpp
"
53
#include "
Stokhos_EpetraSparse3Tensor.hpp
"
54
#include "
Stokhos_ParallelData.hpp
"
55
56
#ifdef HAVE_MPI
57
#include "
Epetra_MpiComm.h
"
58
#include "mpi.h"
59
#else
60
#include "
Epetra_SerialComm.h
"
61
#endif
62
63
TEUCHOS_UNIT_TEST
(basis_interaction_graph, test_square)
64
{
65
#ifdef HAVE_MPI
66
Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(
new
Epetra_MpiComm
(MPI_COMM_WORLD));
67
#else
68
Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(
new
Epetra_SerialComm
);
69
#endif
70
71
int
numProc = comm->NumProc();
72
73
int
num_KL = 3;
74
int
porder = 3;
75
76
Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis =
buildBasis
(num_KL,porder);
77
Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk = basis->computeTripleProductTensor();
78
Teuchos::RCP<Stokhos::ParallelData> sg_parallel_data;
79
80
{
81
Teuchos::ParameterList parallelParams;
82
parallelParams.set(
"Number of Spatial Processors"
, numProc);
83
sg_parallel_data = Teuchos::rcp(
new
Stokhos::ParallelData
(basis, Cijk, comm,
84
parallelParams));
85
}
86
Teuchos::RCP<const EpetraExt::MultiComm> sg_comm = sg_parallel_data->getMultiComm();
87
Teuchos::RCP<Stokhos::EpetraSparse3Tensor> epetraCijk =
88
Teuchos::rcp(
new
Stokhos::EpetraSparse3Tensor
(basis,Cijk,sg_comm));
89
90
Stokhos::BasisInteractionGraph
big(*basis);
91
92
// for grins print out the graph
93
out <<
"Size = "
<< big.
rowCount
() <<
" x "
<< big.
colCount
() << std::endl;
94
95
for
(std::size_t i=0;i<big.
rowCount
();i++) {
96
for
(std::size_t
j
=0;
j
<big.
colCount
();
j
++)
97
out <<
" "
<< (big(i,
j
) ?
"*"
:
" "
) <<
" "
;
98
out << std::endl;
99
}
100
out << std::endl;
101
102
// check the graph for correctness
103
Teuchos::RCP<const Epetra_CrsGraph> graph = epetraCijk->getStochasticGraph();
104
TEST_EQUALITY(graph->NumMyRows(),graph->NumGlobalRows());
105
TEST_EQUALITY(
int
(big.
rowCount
()),graph->NumMyRows());
106
TEST_EQUALITY(
int
(big.
colCount
()),graph->NumMyCols());
107
108
for
(
int
i=0;i<graph->NumGlobalRows();i++) {
109
bool
rowPassed =
true
;
110
int
count = 0;
111
std::vector<bool> row(graph->NumGlobalRows(),
false
);
112
std::vector<int> activeRow(graph->NumGlobalRows());
113
graph->ExtractGlobalRowCopy(i,graph->NumGlobalRows(),count,&activeRow[0]);
114
115
// get truth graph
116
for
(
int
j
=0;
j
<count;
j
++)
117
row[activeRow[
j
]] =
true
;
118
119
// check active row
120
for
(std::size_t
j
=0;
j
<row.size();
j
++)
121
rowPassed = rowPassed && (row[
j
]==big(i,
j
));
122
123
TEST_ASSERT(rowPassed);
124
}
125
}
126
127
TEUCHOS_UNIT_TEST
(basis_interaction_graph, test_isotropic_rect)
128
{
129
#ifdef HAVE_MPI
130
Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(
new
Epetra_MpiComm
(MPI_COMM_WORLD));
131
#else
132
Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(
new
Epetra_SerialComm
);
133
#endif
134
135
int
num_KL = 2;
136
int
porder = 3;
137
138
Teuchos::RCP<const Stokhos::ProductBasis<int,double> > masterBasis =
buildBasis
(num_KL,porder);
139
Teuchos::RCP<const Stokhos::ProductBasis<int,double> > rowBasis =
buildBasis
(num_KL,2);
140
Teuchos::RCP<const Stokhos::ProductBasis<int,double> > colBasis =
buildBasis
(num_KL,3);
141
142
out <<
"Master Array Basis = \n"
;
143
for
(
int
i=0;i<masterBasis->size();i++) {
144
Stokhos::MultiIndex<int>
masterArray = masterBasis->term(i);
145
for
(
int
i=0;i<num_KL;i++) {
146
out << masterArray[i] <<
" "
;
147
}
148
out << std::endl;
149
}
150
151
out <<
"Row Array Basis = \n"
;
152
for
(
int
i=0;i<rowBasis->size();i++) {
153
Stokhos::MultiIndex<int>
rowArray = rowBasis->term(i);
154
for
(
int
i=0;i<num_KL;i++) {
155
out << rowArray[i] <<
" "
;
156
}
157
out << std::endl;
158
}
159
160
Stokhos::BasisInteractionGraph
masterBig(*masterBasis);
161
Stokhos::BasisInteractionGraph
rectBig(*masterBasis,*rowBasis,*colBasis);
162
163
out <<
"rowBasis.size = "
<< rowBasis->size() << std::endl;
164
out <<
"colBasis.size = "
<< colBasis->size() << std::endl;
165
166
// for grins print out the graph
167
out <<
"Size = "
<< rectBig.
rowCount
() <<
" x "
<< rectBig.
colCount
() << std::endl;
168
for
(std::size_t i=0;i<rectBig.
rowCount
();i++) {
169
for
(std::size_t
j
=0;
j
<rectBig.
colCount
();
j
++)
170
out <<
" "
<< (rectBig(i,
j
) ?
"*"
:
" "
) <<
" "
;
171
out << std::endl;
172
}
173
out << std::endl;
174
175
out <<
"Size = "
<< masterBig.
rowCount
() <<
" x "
<< masterBig.
colCount
() << std::endl;
176
for
(std::size_t i=0;i<masterBig.
rowCount
();i++) {
177
for
(std::size_t
j
=0;
j
<masterBig.
colCount
();
j
++)
178
out <<
" "
<< (masterBig(i,
j
) ?
"*"
:
" "
) <<
" "
;
179
out << std::endl;
180
}
181
out << std::endl;
182
183
// loop over rectangle graph making sure it matches with the master graph
184
bool
graphs_match =
true
;
185
for
(std::size_t i=0;i<rectBig.
rowCount
();i++) {
186
std::size_t masterI = masterBasis->index(rowBasis->term(i));
187
for
(std::size_t
j
=0;
j
<rectBig.
colCount
();
j
++) {
188
std::size_t masterJ = masterBasis->index(colBasis->term(
j
));
189
graphs_match &= (rectBig(i,
j
)==masterBig(masterI,masterJ));
190
}
191
}
192
193
TEST_ASSERT(graphs_match);
194
}
Epetra_MpiComm.h
Epetra_SerialComm.h
j
j
Definition
Sacado_Fad_Exp_MP_Vector.hpp:527
TEUCHOS_UNIT_TEST
TEUCHOS_UNIT_TEST(basis_interaction_graph, test_square)
Definition
Stokhos_BasisInteractionGraphUnitTest.cpp:63
Stokhos_BasisInteractionGraph.hpp
Stokhos_EpetraSparse3Tensor.hpp
buildBasis
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
Definition
Stokhos_InterlacedTestSupport.cpp:111
Stokhos_InterlacedTestSupport.hpp
Stokhos_ParallelData.hpp
Epetra_MpiComm
Epetra_SerialComm
Stokhos::BasisInteractionGraph
Definition
Stokhos_BasisInteractionGraph.hpp:55
Stokhos::BasisInteractionGraph::rowCount
std::size_t rowCount() const
What is the number of rows.
Definition
Stokhos_BasisInteractionGraph.hpp:95
Stokhos::BasisInteractionGraph::colCount
std::size_t colCount() const
What is the number of columns.
Definition
Stokhos_BasisInteractionGraph.hpp:99
Stokhos::EpetraSparse3Tensor
Definition
Stokhos_EpetraSparse3Tensor.hpp:55
Stokhos::MultiIndex
A multidimensional index.
Definition
Stokhos_ProductBasisUtils.hpp:79
Stokhos::ParallelData
Definition
Stokhos_ParallelData.hpp:54
Generated by
1.17.0