Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_MultiVector_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef XPETRA_MULTIVECTOR_DEF_HPP
11 #define XPETRA_MULTIVECTOR_DEF_HPP
12 
14 
15 namespace Xpetra {
16 
17 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
20 }
21 
22 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
26  assign(rhs); // dispatch to protected virtual method
27  return *this;
28 }
29 
30 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
33  typedef Teuchos::ScalarTraits<Scalar> SCT;
34 
35  const size_t numVectors = getNumVectors();
36  for (size_t i = 0; i < numVectors; i++) {
37  Teuchos::ArrayRCP<Scalar> datai = getDataNonConst(i);
38 
39  const size_t myLength = getLocalLength();
40  for (size_t j = 0; j < myLength; j++) {
41  datai[j] = SCT::random();
42  }
43  }
44 }
45 
46 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
48  Xpetra_randomize(const Scalar& minVal, const Scalar& maxVal) {
49  typedef Teuchos::ScalarTraits<Scalar> SCT;
50  Scalar point5 = SCT::one() / (SCT::one() + SCT::one());
51 
52  const size_t numVectors = getNumVectors();
53  for (size_t i = 0; i < numVectors; i++) {
54  Teuchos::ArrayRCP<Scalar> datai = getDataNonConst(i);
55 
56  const size_t myLength = getLocalLength();
57  for (size_t j = 0; j < myLength; j++) {
58  datai[j] = point5 * (maxVal - minVal) * SCT::random() + point5 * (maxVal + minVal);
59  }
60  }
61 }
62 
63 } // namespace Xpetra
64 
65 #endif // XPETRA_MULTIVECTOR_DEF_HPP
virtual void Xpetra_randomize()
Set multi-vector values to random numbers. XPetra implementation.
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > & operator=(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &rhs)
Assignment operator: Does a deep copy.
virtual ~MultiVector()
Destructor.