Tpetra parallel linear algebra  Version of the Day
Tpetra_Experimental_BlockVector_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
43 #define TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
44 
45 namespace Tpetra {
46 namespace Experimental {
47 namespace Classes {
48 
49  template<class Scalar, class LO, class GO, class Node>
51  BlockVector (const map_type& meshMap, const LO blockSize) :
52  base_type (meshMap, blockSize, 1)
53  {}
54 
55  template<class Scalar, class LO, class GO, class Node>
57  BlockVector (const map_type& meshMap,
58  const map_type& pointMap,
59  const LO blockSize) :
60  base_type (meshMap, pointMap, blockSize, 1)
61  {}
62 
63  template<class Scalar, class LO, class GO, class Node>
65  BlockVector (const mv_type& X_mv,
66  const map_type& meshMap,
67  const LO blockSize) :
68  base_type (X_mv, meshMap, blockSize)
69  {
70  TEUCHOS_TEST_FOR_EXCEPTION(
71  X_mv.getNumVectors () != 1, std::invalid_argument,
72  "Tpetra::Experimental::BlockVector: Input MultiVector has "
73  << X_mv.getNumVectors () << " != 1 columns.");
74  }
75 
76  template<class Scalar, class LO, class GO, class Node>
79  const map_type& newMeshMap,
80  const map_type& newPointMap,
81  const size_t offset) :
82  base_type (X, newMeshMap, newPointMap, offset)
83  {}
84 
85  template<class Scalar, class LO, class GO, class Node>
88  const map_type& newMeshMap,
89  const size_t offset) :
90  base_type (X, newMeshMap, offset)
91  {}
92 
93  template<class Scalar, class LO, class GO, class Node>
96 
97  template<class Scalar, class LO, class GO, class Node>
100  Teuchos::RCP<vec_type> vPtr = this->mv_.getVectorNonConst (0);
101  vPtr->setCopyOrView (Teuchos::View);
102  return *vPtr; // shallow copy
103  }
104 
105  template<class Scalar, class LO, class GO, class Node>
106  bool
108  replaceLocalValues (const LO localRowIndex, const Scalar vals[]) const {
109  return ((const base_type*) this)->replaceLocalValues (localRowIndex, 0, vals);
110  }
111 
112  template<class Scalar, class LO, class GO, class Node>
113  bool
115  replaceGlobalValues (const GO globalRowIndex, const Scalar vals[]) const {
116  return ((const base_type*) this)->replaceGlobalValues (globalRowIndex, 0, vals);
117  }
118 
119 
120  template<class Scalar, class LO, class GO, class Node>
121  bool
123  sumIntoLocalValues (const LO localRowIndex, const Scalar vals[]) const {
124  return ((const base_type*) this)->sumIntoLocalValues (localRowIndex, 0, vals);
125  }
126 
127  template<class Scalar, class LO, class GO, class Node>
128  bool
130  sumIntoGlobalValues (const GO globalRowIndex, const Scalar vals[]) const {
131  return ((const base_type*) this)->sumIntoLocalValues (globalRowIndex, 0, vals);
132  }
133 
134  template<class Scalar, class LO, class GO, class Node>
135  bool
137  getLocalRowView (const LO localRowIndex, Scalar*& vals) const {
138  return ((const base_type*) this)->getLocalRowView (localRowIndex, 0, vals);
139  }
140 
141  template<class Scalar, class LO, class GO, class Node>
142  bool
144  getGlobalRowView (const GO globalRowIndex, Scalar*& vals) const {
145  return ((const base_type*) this)->getGlobalRowView (globalRowIndex, 0, vals);
146  }
147 
159  template<class Scalar, class LO, class GO, class Node>
162  getLocalBlock (const LO localRowIndex) const
163  {
164  if (! this->isValidLocalMeshIndex (localRowIndex)) {
165  return little_vec_type ();
166  } else {
167  const size_t blockSize = this->getBlockSize ();
168  const size_t offset = localRowIndex * blockSize;
169  return little_vec_type (this->getRawPtr () + offset, blockSize);
170  }
171  }
172 
173 } // namespace Classes
174 } // namespace Experimental
175 } // namespace Tpetra
176 
177 //
178 // Explicit instantiation macro
179 //
180 // Must be expanded from within the Tpetra namespace!
181 //
182 #define TPETRA_EXPERIMENTAL_BLOCKVECTOR_INSTANT(S,LO,GO,NODE) \
183  namespace Experimental { \
184  namespace Classes { \
185  template class BlockVector< S, LO, GO, NODE >; \
186  } \
187  }
188 
189 #endif // TPETRA_EXPERIMENTAL_BLOCKVECTOR_DEF_HPP
Tpetra::Experimental::Classes::BlockVector::getVectorView
vec_type getVectorView()
Get a Tpetra::Vector that views this BlockVector's data.
Definition: Tpetra_Experimental_BlockVector_def.hpp:99
Tpetra::Experimental::Classes::BlockVector::getLocalRowView
bool getLocalRowView(const LO localRowIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a local index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:137
Tpetra::Experimental::Classes::BlockVector
Vector for multiple degrees of freedom per mesh point.
Definition: Tpetra_Experimental_BlockVector_decl.hpp:82
Tpetra::Experimental::Classes::BlockVector::BlockVector
BlockVector()
Default constructor.
Definition: Tpetra_Experimental_BlockVector_def.hpp:95
Tpetra::Experimental::Classes::BlockVector::sumIntoGlobalValues
bool sumIntoGlobalValues(const GO globalRowIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a global index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:130
Tpetra::Experimental::Classes::BlockVector::getGlobalRowView
bool getGlobalRowView(const GO globalRowIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a global index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:144
Tpetra::Classes::MultiVector::getVectorNonConst
Teuchos::RCP< Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getVectorNonConst(const size_t j)
Return a Vector which is a nonconst view of column j.
Definition: Tpetra_MultiVector_def.hpp:3727
Tpetra::Experimental::Classes::BlockVector::sumIntoLocalValues
bool sumIntoLocalValues(const LO localRowIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a local index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:123
Tpetra::Classes::MultiVector
One or more distributed dense vectors.
Definition: Tpetra_MultiVector_decl.hpp:389
Tpetra::Experimental::Classes::BlockVector::replaceLocalValues
bool replaceLocalValues(const LO localRowIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a local index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:108
Tpetra::Classes::MultiVector::getNumVectors
size_t getNumVectors() const
Number of columns in the multivector.
Definition: Tpetra_MultiVector_def.hpp:1739
Tpetra::Experimental::Classes::BlockMultiVector
MultiVector for multiple degrees of freedom per mesh point.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:147
Tpetra::Classes::Map
A parallel distribution of indices over processes.
Definition: Tpetra_Map_decl.hpp:247
Tpetra::Experimental::Classes::BlockVector::getLocalBlock
little_vec_type getLocalBlock(const LO localRowIndex) const
Get a view of the degrees of freedom at the given mesh point, using a local index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:162
Tpetra::Experimental::Classes::BlockVector::little_vec_type
Kokkos::View< impl_scalar_type *, Kokkos::LayoutRight, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > little_vec_type
"Block view" of all degrees of freedom at a mesh point.
Definition: Tpetra_Experimental_BlockVector_decl.hpp:129
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Tpetra::Experimental::Classes::BlockVector::replaceGlobalValues
bool replaceGlobalValues(const GO globalRowIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a global index.
Definition: Tpetra_Experimental_BlockVector_def.hpp:115
Tpetra::Experimental::Classes::BlockMultiVector::little_vec_type
Kokkos::View< impl_scalar_type *, Kokkos::LayoutRight, device_type, Kokkos::MemoryTraits< Kokkos::Unmanaged > > little_vec_type
"Block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector.
Definition: Tpetra_Experimental_BlockMultiVector_decl.hpp:203
Tpetra::Classes::Vector
A distributed dense vector.
Definition: Tpetra_Vector_decl.hpp:82