Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_LinearProblem_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_LINEARPROBLEM_DEF_HPP
11#define TPETRA_LINEARPROBLEM_DEF_HPP
12
20
21#include "Teuchos_DataAccess.hpp"
22#include "Teuchos_TestForException.hpp"
24#include "Tpetra_MultiVector.hpp"
26
27namespace Tpetra {
28
29template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32 : dist_object_type(Teuchos::rcp(new map_type()))
33 , A_(Teuchos::null)
34 , X_(Teuchos::null)
35 , B_(Teuchos::null) {
36}
37
38template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
40 LinearProblem(const Teuchos::RCP<row_matrix_type>& A,
41 const Teuchos::RCP<multivector_type>& X,
42 const Teuchos::RCP<multivector_type>& B)
43 : dist_object_type(A->getDomainMap())
44 , A_(A)
45 , X_(X)
46 , B_(B) {
47}
48
49template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
57
58template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
60 leftScale(const Teuchos::RCP<const vector_type>& D, Teuchos::ETransp mode) {
61 const Scalar ST0 = Teuchos::ScalarTraits<Scalar>::zero();
62 const Scalar ST1 = Teuchos::ScalarTraits<Scalar>::one();
63 if (mode == Teuchos::NO_TRANS) {
64 A_->leftScale(*D);
65 B_->elementWiseMultiply(ST1, *D, *B_, ST0);
66 } else {
67 A_->rightScale(*D);
68 vector_type R(*D, Teuchos::DataAccess::Copy);
69 R.reciprocal(*D);
70 X_->elementWiseMultiply(ST1, R, *X_, ST0);
71 }
72
73 return;
74}
75
76template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
78 rightScale(const Teuchos::RCP<const vector_type>& D, Teuchos::ETransp mode) {
79 const Scalar ST0 = Teuchos::ScalarTraits<Scalar>::zero();
80 const Scalar ST1 = Teuchos::ScalarTraits<Scalar>::one();
81 if (mode == Teuchos::NO_TRANS) {
82 A_->rightScale(*D);
83 vector_type R(*D, Teuchos::DataAccess::Copy);
84 R.reciprocal(*D);
85 X_->elementWiseMultiply(ST1, R, *X_, ST0);
86 } else {
87 A_->leftScale(*D);
88 B_->elementWiseMultiply(ST1, *D, *B_, ST0);
89 }
90 return;
91}
92
93template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
95 checkInput() const {
96 const char tfecfFuncName[] = "checkInput: ";
97
98 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(A_ == Teuchos::null, std::runtime_error,
99 "Linear problem does not have a matrix (A_).");
100
101 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(X_ == Teuchos::null,
102 std::logic_error, "Solution vector (X_) is unset.");
103
104 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(B_ == Teuchos::null,
105 std::logic_error, "RHS vector (B_) is unset.");
106
107 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!A_->getRowMap()->isSameAs(*(X_->getMap())),
108 std::logic_error, "Domain map of matrix is not the 'same as' the solution map.");
109
110 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!A_->getRowMap()->isSameAs(*(B_->getMap())),
111 std::logic_error, "Range map of matrix is not the 'same as' the RHS map.");
112
113 return;
114}
115
116template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
119 // Check whether the source object is a LinearProblem. If not, then
120 // we can't even compare sizes.
122 const LP* src = dynamic_cast<const LP*>(&sourceObj);
123 if (src == nullptr) {
124 return false;
125 } else {
126 this->checkInput();
127 src->checkInput();
128
129 return ((this->A_->getDomainMap() == src->getMatrix()->getDomainMap()) and
130 (this->A_->getRangeMap() == src->getMatrix()->getRangeMap()));
131 }
132}
133
134} // namespace Tpetra
135
136//
137// Explicit instantiation macro
138//
139// Must be expanded from within the Tpetra namespace!
140//
141
142#define TPETRA_LINEARPROBLEM_INSTANT(SCALAR, LO, GO, NODE) \
143 template class LinearProblem<SCALAR, LO, GO, NODE>;
144
145#endif // TPETRA_LINEARPROBLEM_DEF_HPP
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of the Tpetra::MultiVector class.
Struct that holds views of the contents of a CrsMatrix.
virtual bool checkSizes(const SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
void rightScale(const Teuchos::RCP< const vector_type > &D, Teuchos::ETransp mode=Teuchos::NO_TRANS)
Perform right scaling of a linear problem.
LinearProblem()
Default Constructor.
void leftScale(const Teuchos::RCP< const vector_type > &D, Teuchos::ETransp mode=Teuchos::NO_TRANS)
Perform left scaling of a linear problem.
void checkInput() const
Check input parameters for existence and size consistency.
Abstract base class for objects that can be the source of an Import or Export operation.
A distributed dense vector.
Namespace Tpetra contains the class and methods constituting the Tpetra library.