Teko Version of the Day
Loading...
Searching...
No Matches
Teko_DiagonalPreconditionerOp.cpp
1// @HEADER
2// *****************************************************************************
3// Teko: A package for block and physics based preconditioning
4//
5// Copyright 2010 NTESS and the Teko contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#include "Teko_DiagonalPreconditionerOp.hpp"
11#include "Thyra_EpetraThyraWrappers.hpp"
12#include "EpetraExt_PointToBlockDiagPermute.h"
13#include "Epetra_MultiVector.h"
14
15using Teuchos::RCP;
16using Teuchos::rcp_const_cast;
17using Teuchos::rcp_dynamic_cast;
18using Teuchos::rcpFromRef;
19
20using Thyra::MultiVectorBase;
21
22namespace Teko {
23
24DiagonalPreconditionerOp::DiagonalPreconditionerOp(
25 Teuchos::RCP<EpetraExt_PointToBlockDiagPermute> BDP, const VectorSpace range,
26 const VectorSpace domain)
27 : BDP_(BDP), range_(range), domain_(domain) {}
28
29void DiagonalPreconditionerOp::implicitApply(const MultiVector& x, MultiVector& y,
30 const double alpha, const double beta) const {
31 // Get the Multivectors into Epetra land
32 // NTS: Thyra inexplicably wants maps, even when they are completely unecessary.
33 const Epetra_Map& rangemap_ = BDP_->OperatorRangeMap();
34 const Epetra_Map& domainmap_ = BDP_->OperatorDomainMap();
35
36 RCP<const Epetra_MultiVector> x_ = Thyra::get_Epetra_MultiVector(domainmap_, x);
37 RCP<Epetra_MultiVector> y_ = Thyra::get_Epetra_MultiVector(rangemap_, y);
38 TEUCHOS_ASSERT(x_ != Teuchos::null);
39 TEUCHOS_ASSERT(y_ != Teuchos::null);
40
41 // y = \alpha M x + \beta y $
42 if (beta == 0.0) {
43 BDP_->ApplyInverse(*x_, *y_);
44 scale(alpha, y);
45 } else {
46 MultiVector y0 = deepcopy(y);
47 BDP_->ApplyInverse(*x_, *y_);
48 update(alpha, y, beta, y0);
49 }
50}
51
52void DiagonalPreconditionerOp::describe(Teuchos::FancyOStream& out_arg,
53 const Teuchos::EVerbosityLevel verbLevel) const {
54 using Teuchos::OSTab;
55
56 switch (verbLevel) {
57 case Teuchos::VERB_DEFAULT:
58 case Teuchos::VERB_LOW: out_arg << this->description() << std::endl; break;
59 case Teuchos::VERB_MEDIUM:
60 case Teuchos::VERB_HIGH:
61 case Teuchos::VERB_EXTREME:
62 if (BDP_ != Teuchos::null) BDP_->Print(out_arg);
63 break;
64 default: TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
65 }
66}
67
68} // end namespace Teko
MultiVector deepcopy(const MultiVector &v)
Perform a deep copy of the vector.