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
29 template <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 }
38
39 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
41 LinearProblem (const Teuchos::RCP<row_matrix_type> & A,
42 const Teuchos::RCP<multivector_type>& X,
43 const Teuchos::RCP<multivector_type>& B)
44 : dist_object_type (A->getDomainMap()),
45 A_(A),
46 X_(X),
47 B_(B)
48 {
49 }
50
51 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
54 : dist_object_type (Problem),
55 A_(Problem.A_),
56 X_(Problem.X_),
57 B_(Problem.B_)
58 {
59 }
60
61 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
63 leftScale(const Teuchos::RCP<const vector_type> & D, Teuchos::ETransp mode)
64 {
65 const Scalar ST0 = Teuchos::ScalarTraits<Scalar>::zero();
66 const Scalar ST1 = Teuchos::ScalarTraits<Scalar>::one();
67 if (mode == Teuchos::NO_TRANS) {
68 A_->leftScale(*D);
69 B_->elementWiseMultiply(ST1, *D, *B_, ST0);
70 }
71 else {
72 A_->rightScale(*D);
73 vector_type R(*D, Teuchos::DataAccess::Copy);
74 R.reciprocal(*D);
75 X_->elementWiseMultiply(ST1, R, *X_, ST0);
76 }
77
78 return;
79 }
80
81 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
83 rightScale(const Teuchos::RCP<const vector_type> & D, Teuchos::ETransp mode)
84 {
85 const Scalar ST0 = Teuchos::ScalarTraits<Scalar>::zero();
86 const Scalar ST1 = Teuchos::ScalarTraits<Scalar>::one();
87 if (mode == Teuchos::NO_TRANS) {
88 A_->rightScale(*D);
89 vector_type R(*D, Teuchos::DataAccess::Copy);
90 R.reciprocal(*D);
91 X_->elementWiseMultiply(ST1, R, *X_, ST0);
92 }
93 else {
94 A_->leftScale(*D);
95 B_->elementWiseMultiply(ST1, *D, *B_, ST0);
96 }
97 return;
98 }
99
100 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
102 checkInput() const {
103
104 const char tfecfFuncName[] = "checkInput: ";
105
106 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(A_==Teuchos::null, std::runtime_error,
107 "Linear problem does not have a matrix (A_).");
108
109 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(X_==Teuchos::null,
110 std::logic_error, "Solution vector (X_) is unset.");
111
112 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(B_==Teuchos::null,
113 std::logic_error, "RHS vector (B_) is unset.");
114
115 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!A_->getRowMap()->isSameAs(*(X_->getMap())),
116 std::logic_error, "Domain map of matrix is not the 'same as' the solution map.");
117
118 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!A_->getRowMap()->isSameAs(*(B_->getMap())),
119 std::logic_error, "Range map of matrix is not the 'same as' the RHS map.");
120
121 return;
122 }
123
124 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
126 checkSizes (const SrcDistObject& sourceObj)
127 {
128 // Check whether the source object is a LinearProblem. If not, then
129 // we can't even compare sizes.
131 const LP* src = dynamic_cast<const LP*> (&sourceObj);
132 if (src == nullptr) {
133 return false;
134 }
135 else {
136 this->checkInput();
137 src->checkInput();
138
139 return ((this->A_->getDomainMap() == src->getMatrix()->getDomainMap()) and
140 (this->A_->getRangeMap() == src->getMatrix()->getRangeMap()));
141 }
142 }
143
144} // namespace Tpetra
145
146//
147// Explicit instantiation macro
148//
149// Must be expanded from within the Tpetra namespace!
150//
151
152#define TPETRA_LINEARPROBLEM_INSTANT(SCALAR,LO,GO,NODE) \
153 template class LinearProblem< SCALAR , LO , GO , NODE >;
154
155
156#endif // TPETRA_LINEARPROBLEM_DEF_HPP
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of the Tpetra::MultiVector class.
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.
void reciprocal(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A)
Put element-wise reciprocal values of input Multi-vector in target, this(i,j) = 1/A(i,...
Abstract base class for objects that can be the source of an Import or Export operation.
Namespace Tpetra contains the class and methods constituting the Tpetra library.