Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tpetra_CrsMatrix_UQ_PCE_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_CRSMATRIX_UQ_PCE_DEF_HPP
43 #define TPETRA_CRSMATRIX_UQ_PCE_DEF_HPP
44 
45 // Specializations of some Tpetra::CrsMatrix methods for UQ::PCE
46 
47 #include "Tpetra_CrsMatrix_def.hpp"
48 
49 // These are macros; the code isn't compiled here, so we don't need to
50 // say here what namespace the code is in. We _do_ need to put the
51 // code in the correct namespace when we use the macro.
52 
53 #define TPETRA_CRSMATRIX_UQ_PCE_SPEC(Scalar,LocalOrdinal,GlobalOrdinal,Node) \
54  template<> \
55  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > \
56  CrsMatrix<Scalar , LocalOrdinal, GlobalOrdinal, Node>:: \
57  getColumnMapMultiVector (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& X_domainMap, \
58  const bool force) const \
59  { \
60  using Teuchos::null; \
61  using Teuchos::RCP; \
62  using Teuchos::rcp; \
63  \
64  TEUCHOS_TEST_FOR_EXCEPTION( \
65  ! this->hasColMap (), std::runtime_error, "Tpetra::CrsMatrix::getColumn" \
66  "MapMultiVector: You may only call this method if the matrix has a " \
67  "column Map. If the matrix does not yet have a column Map, you should " \
68  "first call fillComplete (with domain and range Map if necessary)."); \
69  \
70  TEUCHOS_TEST_FOR_EXCEPTION( \
71  ! this->getGraph ()->isFillComplete (), std::runtime_error, "Tpetra::" \
72  "CrsMatrix::getColumnMapMultiVector: You may only call this method if " \
73  "this matrix's graph is fill complete."); \
74  \
75  const size_t numVecs = X_domainMap.getNumVectors (); \
76  RCP<const import_type> importer = this->getGraph ()->getImporter (); \
77  RCP<const map_type> colMap = this->getColMap (); \
78  \
79  RCP<MV> X_colMap; \
80  \
81  if (! importer.is_null () || force) { \
82  if (importMV_.is_null () || \
83  importMV_->getNumVectors () != numVecs || \
84  (Kokkos::dimension_scalar(*importMV_) != \
85  Kokkos::dimension_scalar(X_domainMap))) { \
86  X_colMap = rcp (new MV (colMap, numVecs)); \
87  importMV_ = X_colMap; \
88  } \
89  else { \
90  X_colMap = importMV_; \
91  } \
92  } \
93  return X_colMap; \
94  } \
95  \
96  template <> \
97  Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > \
98  CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>:: \
99  getRowMapMultiVector (const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Y_rangeMap, \
100  const bool force) const \
101  { \
102  using Teuchos::null; \
103  using Teuchos::RCP; \
104  using Teuchos::rcp; \
105  \
106  TEUCHOS_TEST_FOR_EXCEPTION( \
107  ! this->getGraph ()->isFillComplete (), std::runtime_error, "Tpetra::" \
108  "CrsMatrix::getRowMapMultiVector: You may only call this method if this " \
109  "matrix's graph is fill complete."); \
110  \
111  const size_t numVecs = Y_rangeMap.getNumVectors (); \
112  RCP<const export_type> exporter = this->getGraph ()->getExporter (); \
113  RCP<const map_type> rowMap = this->getRowMap (); \
114  \
115  RCP<MV> Y_rowMap; \
116  \
117  if (! exporter.is_null () || force) { \
118  if (exportMV_.is_null () || \
119  exportMV_->getNumVectors () != numVecs || \
120  (Kokkos::dimension_scalar(*exportMV_) != \
121  Kokkos::dimension_scalar(Y_rangeMap))) { \
122  Y_rowMap = rcp (new MV (rowMap, numVecs)); \
123  exportMV_ = Y_rowMap; \
124  } \
125  else { \
126  Y_rowMap = exportMV_; \
127  } \
128  } \
129  return Y_rowMap; \
130  }
131 
132 #endif // STOKHOS_TPETRA_UQ_PCE_DEF_HPP