Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_BuildColBasisUnitTest.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
50
51// Stokhos Stochastic Galerkin
57
58#ifdef HAVE_MPI
59 #include "Epetra_MpiComm.h"
60 #include "EpetraExt_MultiMpiComm.h"
61 #include "mpi.h"
62#else
63 #include "Epetra_SerialComm.h"
64 #include "EpetraExt_MultiSerialComm.h"
65#endif
66#include "Epetra_CrsGraph.h"
67
68#include "EpetraExt_RowMatrixOut.h"
69
70Teuchos::RCP<Epetra_CrsGraph> buildTridiagonalGraph(int numUnks,const Epetra_Comm & Comm)
71{
72 Epetra_Map map(-1,numUnks,0,Comm);
73 Teuchos::RCP<Epetra_CrsGraph> graph
74 = Teuchos::rcp(new Epetra_CrsGraph(Copy,map,0));
75
76 // build tridiagonal graph
77 int colCnt = 3;
78 int * colPtr = 0;
79 int colIndices[3];
80 int colOffset[] = {-1, 0, 1};
81 for(int myRow=0;myRow<numUnks;myRow++) {
82 int row = map.GID(myRow);
83 for(int i=0;i<3;i++)
84 colIndices[i] = colOffset[i]+row;
85 colCnt = 3;
86 colPtr = colIndices;
87
88 if(row==0) {
89 colCnt = 2;
90 colPtr = colIndices+1;
91 }
92 else if(row==map.NumGlobalElements()-1)
93 colCnt = 2;
94
95 TEUCHOS_ASSERT(graph->InsertGlobalIndices(row,colCnt,colPtr)==0);
96 }
97
98 graph->FillComplete();
99
100 return graph;
101}
102
103// Test construction of Linear Algebra (LA) data structures
104TEUCHOS_UNIT_TEST(tBuildColBasis, test_adapted)
105{
106 #ifdef HAVE_MPI
107 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
108 #else
109 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_SerialComm);
110 #endif
111
112 int numProc = comm->NumProc();
113 int rank = comm->MyPID();
114
115 out << "NumProc = " << numProc << ", Rank = " << rank << std::endl;
116
117 int num_KL = 3;
118 int porder = 3;
119
120 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = buildBasis(num_KL,porder);
121 Teuchos::RCP<Epetra_CrsGraph> determGraph = buildTridiagonalGraph(3,*comm);
122
123 std::vector<int> order(3);
124 order[0] = 2; order[1] = 3; order[2] = 1;
125 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDRow(3);
126 sa_BasisPerDRow[0] = buildBasis(num_KL,1);
127 sa_BasisPerDRow[1] = buildBasis(num_KL,1);
128 sa_BasisPerDRow[2] = buildBasis(num_KL,order);
129
130 std::vector<Teuchos::RCP<const Stokhos::ProductBasis<int,double> > > sa_BasisPerDCol;
131 Stokhos::adapt_utils::buildColBasisFunctions(*determGraph,basis,sa_BasisPerDRow,sa_BasisPerDCol);
132
133 if(numProc==2)
134 { TEST_EQUALITY(sa_BasisPerDCol.size(),4); }
135 else
136 { TEST_EQUALITY(sa_BasisPerDCol.size(),3); }
137
138 for(std::size_t c=0;c<sa_BasisPerDCol.size();c++) {
139 int gid = determGraph->ColMap().GID(c);
140 Teuchos::RCP<const Stokhos::ProductBasis<int,double> > cBasis =
141 Teuchos::rcp_dynamic_cast<const Stokhos::ProductBasis<int,double> >(sa_BasisPerDCol[c]);
142
143 Teuchos::Array<Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > cBases
144 = cBasis->getCoordinateBases();
145
146 for(int i=0;i<cBases.size();i++) {
147 int bOrder = cBases[i]->order();
148
149 if(gid==2)
150 { TEST_EQUALITY(bOrder,order[i]); }
151 else if(gid==5)
152 { TEST_EQUALITY(bOrder,order[i]); }
153 else
154 { TEST_EQUALITY(bOrder,1); }
155 }
156 }
157}
Copy
Teuchos::RCP< Epetra_CrsGraph > buildTridiagonalGraph(int numUnks, const Epetra_Comm &Comm)
TEUCHOS_UNIT_TEST(tBuildColBasis, test_adapted)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
int GID(int LID) const
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)