49 #include "Teuchos_TimeMonitor.hpp"
51 #include "Thyra_MultiVectorStdOps.hpp"
59 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream> & ostrm,
const ModifiableLinearOp & A,
const std::string & diagnosticString)
60 : outputStream_(ostrm), wrapOpA_(A), wrapOpA_lo_(A), diagString_(diagnosticString), timer_(diagnosticString)
64 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream> & ostrm,
const LinearOp & A,
const std::string & diagnosticString)
65 : outputStream_(ostrm), wrapOpA_(Teuchos::null), wrapOpA_lo_(A), diagString_(diagnosticString), timer_(diagnosticString)
73 DiagnosticLinearOp::DiagnosticLinearOp(
const Teuchos::RCP<std::ostream> & ostrm,
const LinearOp & fwdOp,
74 const ModifiableLinearOp & A,
const std::string & diagnosticString)
75 : outputStream_(ostrm), wrapOpA_(A), wrapOpA_lo_(A), fwdOp_(fwdOp), diagString_(diagnosticString), timer_(diagnosticString)
81 double elapsedTime = totalTime();
82 int applications = numApplications();
84 (*outputStream_) <<
"DiagnosticLinearOp \"" << diagString_ <<
"\": "
85 <<
"elapsed = " << elapsedTime <<
", "
86 <<
"applications = " << applications <<
", ";
88 (*outputStream_) <<
"timer/app = " << elapsedTime / double(applications) << std::endl;
90 (*outputStream_) <<
"timer/app = " <<
"none" << std::endl;
106 const double alpha,
const double beta)
const
108 Teko_DEBUG_SCOPE(
"DiagnosticLinearOp::implicityApply",10);
111 Teuchos::TimeMonitor monitor(timer_,
false);
117 wrapOpA_lo_->apply(Thyra::NOTRANS,*x,y.ptr(),alpha,beta);
120 bool printResidual = (fwdOp_!=Teuchos::null);
123 MultiVector residual = Teko::deepcopy(x);
126 fwdOp_->apply(Thyra::NOTRANS,*y,residual.ptr(),-1.0,alpha);
128 fwdOp_->apply(Thyra::NOTRANS,*z,residual.ptr(),beta,1.0);
131 std::vector<double> norms(y->domain()->dim());
132 std::vector<double> rhsNorms(x->domain()->dim());
133 Thyra::norms_2<double>(*residual,Teuchos::arrayViewFromVector(norms));
134 Thyra::norms_2<double>(*x,Teuchos::arrayViewFromVector(rhsNorms));
137 (*outputStream_) <<
"DiagnosticLinearOp \"" << diagString_ <<
"\": residual = [";
138 for(std::size_t i=0;i<norms.size();++i)
139 (*outputStream_) <<
" " << std::scientific << std::setprecision(4) << norms[i]/rhsNorms[i];
140 (*outputStream_) <<
" ]" << std::endl;
142 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.