12 #include "Teuchos_TimeMonitor.hpp"
14 #include "Thyra_MultiVectorStdOps.hpp"
22 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream>& ostrm,
23 const ModifiableLinearOp& A,
24 const std::string& diagnosticString)
25 : outputStream_(ostrm),
28 diagString_(diagnosticString),
29 timer_(diagnosticString) {}
31 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream>& ostrm,
const LinearOp& A,
32 const std::string& diagnosticString)
33 : outputStream_(ostrm),
34 wrapOpA_(Teuchos::null),
36 diagString_(diagnosticString),
37 timer_(diagnosticString) {}
43 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream>& ostrm,
44 const LinearOp& fwdOp,
const ModifiableLinearOp& A,
45 const std::string& diagnosticString)
46 : outputStream_(ostrm),
50 diagString_(diagnosticString),
51 timer_(diagnosticString) {}
54 double elapsedTime = totalTime();
55 int applications = numApplications();
57 (*outputStream_) <<
"DiagnosticLinearOp \"" << diagString_ <<
"\": "
58 <<
"elapsed = " << elapsedTime <<
", "
59 <<
"applications = " << applications <<
", ";
61 (*outputStream_) <<
"timer/app = " << elapsedTime / double(applications) << std::endl;
63 (*outputStream_) <<
"timer/app = "
64 <<
"none" << std::endl;
80 const double beta)
const {
81 Teko_DEBUG_SCOPE(
"DiagnosticLinearOp::implicityApply", 10);
84 Teuchos::TimeMonitor monitor(timer_,
false);
87 if (beta != 0.0) z = deepcopy(y);
89 wrapOpA_lo_->apply(Thyra::NOTRANS, *x, y.ptr(), alpha, beta);
92 bool printResidual = (fwdOp_ != Teuchos::null);
95 MultiVector residual = Teko::deepcopy(x);
98 fwdOp_->apply(Thyra::NOTRANS, *y, residual.ptr(), -1.0, alpha);
99 if (beta != 0.0) fwdOp_->apply(Thyra::NOTRANS, *z, residual.ptr(), beta, 1.0);
102 std::vector<double> norms(y->domain()->dim());
103 std::vector<double> rhsNorms(x->domain()->dim());
104 Thyra::norms_2<double>(*residual, Teuchos::arrayViewFromVector(norms));
105 Thyra::norms_2<double>(*x, Teuchos::arrayViewFromVector(rhsNorms));
108 (*outputStream_) <<
"DiagnosticLinearOp \"" << diagString_ <<
"\": residual = [";
109 for (std::size_t i = 0; i < norms.size(); ++i)
110 (*outputStream_) <<
" " << std::scientific << std::setprecision(4)
111 << norms[i] / rhsNorms[i];
112 (*outputStream_) <<
" ]" << std::endl;
114 residualNorm_ = norms[0];
virtual void implicitApply(const MultiVector &x, MultiVector &y, const double alpha=1.0, const double beta=0.0) const
Perform a matrix vector multiply with this operator.
virtual ~DiagnosticLinearOp()
Destructor prints out timing information about this operator.