Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
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 
62 TEUCHOS_UNIT_TEST(map_test, uniform_buildInterlacedMap)
63 {
64 #ifdef HAVE_MPI
66 #else
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 
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 
90 TEUCHOS_UNIT_TEST(map_test, copyToInterlace)
91 {
92 #ifdef HAVE_MPI
94 #else
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 
107  Teuchos::RCP<Stokhos::ParallelData> sg_parallel_data;
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 
121  Cijk));
122  }
123  Teuchos::RCP<const EpetraExt::MultiComm> sg_comm = sg_parallel_data->getMultiComm();
124 
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);
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 }
int NumGlobalElements() const
#define TEST_ASSERT(v1)
static Teuchos::RCP< Epetra_Map > buildInterlaceMap(const Epetra_BlockMap &determ_map, const Epetra_BlockMap &stocha_map)
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
virtual int MyPID() const =0
int NumMyElements() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_BlockMap > getStochasticRowMap() const
Get stochastic row map.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
int GID(int LID) const
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< int, double > > buildBasis(int num_KL, int porder)
virtual int NumProc() const =0
#define TEST_EQUALITY(v1, v2)
TEUCHOS_UNIT_TEST(tAdaptivityManager, test_interface)