Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_InterlacedMapUnitTest.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
52#include "Stokhos_Epetra.hpp"
54
55#ifdef HAVE_MPI
56#include "Epetra_MpiComm.h"
57#else
58#include "Epetra_SerialComm.h"
59#endif
60#include "EpetraExt_BlockVector.h"
61
62TEUCHOS_UNIT_TEST(map_test, uniform_buildInterlacedMap)
63{
64#ifdef HAVE_MPI
65 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
66#else
67 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_SerialComm);
68#endif
69
70 int rank = comm->MyPID();
71
72 int stochaUnks = 5;
73 Epetra_LocalMap stocha_map(stochaUnks,0,*comm);
74 Epetra_Map determ_map(-1,(rank+1)*10,0,*comm);
75
76 Teuchos::RCP<Epetra_Map> obj_ut = Stokhos::SGModelEvaluator_Interlaced::buildInterlaceMap(determ_map,stocha_map);
77
78 TEST_EQUALITY(obj_ut->NumMyElements(),determ_map.NumMyElements()*stochaUnks);
79 TEST_EQUALITY(obj_ut->NumGlobalElements(),determ_map.NumGlobalElements()*stochaUnks);
80
81 bool result = true;
82 for(int s=0;s<stocha_map.NumMyElements();s++) {
83 for(int d=0;d<determ_map.NumMyElements();d++) {
84 result &= (obj_ut->GID(stochaUnks*d+s)==(stochaUnks*determ_map.GID(d)+s));
85 }
86 }
87 TEST_ASSERT(result);
88}
89
90TEUCHOS_UNIT_TEST(map_test, copyToInterlace)
91{
92#ifdef HAVE_MPI
93 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
94#else
95 Teuchos::RCP<const Epetra_Comm> comm = Teuchos::rcp(new Epetra_SerialComm);
96#endif
97
98 //int rank = comm->MyPID();
99 int numProc = comm->NumProc();
100
101 int num_KL = 1;
102 int porder = 1;
103 bool full_expansion = false;
104
105 Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = buildBasis(num_KL,porder);
106 Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk;
107 Teuchos::RCP<Stokhos::ParallelData> sg_parallel_data;
108 Teuchos::RCP<Stokhos::OrthogPolyExpansion<int,double> > expansion;
109 {
110 if(full_expansion)
111 Cijk = basis->computeTripleProductTensor();
112 else
113 Cijk = basis->computeLinearTripleProductTensor();
114
115 Teuchos::ParameterList parallelParams;
116 parallelParams.set("Number of Spatial Processors", numProc);
117 sg_parallel_data = Teuchos::rcp(new Stokhos::ParallelData(basis, Cijk, comm,
118 parallelParams));
119
120 expansion = Teuchos::rcp(new Stokhos::AlgebraicOrthogPolyExpansion<int,double>(basis,
121 Cijk));
122 }
123 Teuchos::RCP<const EpetraExt::MultiComm> sg_comm = sg_parallel_data->getMultiComm();
124
125 Teuchos::RCP<Stokhos::EpetraSparse3Tensor> epetraCijk =
126 Teuchos::rcp(new Stokhos::EpetraSparse3Tensor(basis,Cijk,sg_comm));
127
128 Epetra_Map determRowMap(-1,3,0,*comm);
129 Teuchos::RCP<Epetra_Map> determRowMap_rcp = Teuchos::rcpFromRef(determRowMap);
130 Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> x_vec_blocks =
131 Teuchos::rcp(new Stokhos::EpetraVectorOrthogPoly(basis,epetraCijk->getStochasticRowMap(),determRowMap_rcp,epetraCijk->getMultiComm()));
132 for(int b=0;b<porder+1;b++)
133 x_vec_blocks->getBlockVector()->GetBlock(b)->Print(std::cout);
134// for(int i=0;i<3;i++)
135// (*x_vec_blocks->getBlockVector()->GetBlock(b))[i] = 1.0+i + (b+1)*3;
136 x_vec_blocks->getBlockVector()->Print(std::cout);
137}
TEUCHOS_UNIT_TEST(map_test, uniform_buildInterlacedMap)
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
Orthogonal polynomial expansions limited to algebraic operations.
A container class storing an orthogonal polynomial whose coefficients are vectors,...
static Teuchos::RCP< Epetra_Map > buildInterlaceMap(const Epetra_BlockMap &determ_map, const Epetra_BlockMap &stocha_map)