48 #include "Teko_DiagnosticPreconditionerFactory.hpp"
50 #include "Teko_PreconditionerInverseFactory.hpp"
53 #include "Teuchos_TimeMonitor.hpp"
59 : outputStream_(Teko::getOutputStream()), invFactory_(Teuchos::null), diagString_(
"<label me!>"), printResidual_(false)
66 const Teuchos::RCP<std::ostream> & os,
bool printResidual)
67 : outputStream_(Teko::getOutputStream()), invFactory_(invFactory), diagString_(label), printResidual_(printResidual)
69 initTimers(diagString_);
78 if(buildTimer_==Teuchos::null || rebuildTimer_==Teuchos::null) {
85 double initBuildTime = totalInitialBuildTime();
86 int initBuilds = numInitialBuilds();
88 double initRebuildTime = totalRebuildTime();
89 int initRebuilds = numRebuilds();
91 (*outputStream_) <<
"DiagnosticPreconditionerFactory \"" << diagString_ <<
"\":\n";
94 (*outputStream_) <<
" build elapsed = " << initBuildTime <<
", "
95 <<
"num builds = " << initBuilds <<
", ";
97 (*outputStream_) <<
"timer/app = " << initBuildTime / double(initBuilds) <<
"\n";
99 (*outputStream_) <<
"timer/app = " <<
"none" <<
"\n";
102 (*outputStream_) <<
" rebuild elapsed = " << initRebuildTime <<
", "
103 <<
"num rebuilds = " << initRebuilds <<
", ";
105 (*outputStream_) <<
"timer/app = " << initRebuildTime / double(initRebuilds) <<
"\n";
107 (*outputStream_) <<
"timer/app = " <<
"none" <<
"\n";
110 (*outputStream_) <<
" total elapsed = " << initRebuildTime+initBuildTime <<
", "
111 <<
"num rebuilds = " << initRebuilds+initBuilds <<
", ";
112 if(initBuilds+initRebuilds>0)
113 (*outputStream_) <<
"timer/app = " << (initRebuildTime+initBuildTime) /
double(initRebuilds+initBuilds) << std::endl;
115 (*outputStream_) <<
"timer/app = " <<
"none" << std::endl;
124 using Teuchos::rcp_dynamic_cast;
126 TEUCHOS_TEST_FOR_EXCEPTION(invFactory_==Teuchos::null,std::runtime_error,
127 "ERROR: Teko::DiagnosticPreconditionerFactory::buildPreconditionerOperator requires that an "
128 <<
"inverse factory has been set. Currently it is null!");
130 TEUCHOS_TEST_FOR_EXCEPTION(buildTimer_==Teuchos::null || rebuildTimer_==Teuchos::null,std::runtime_error,
131 "ERROR: Teko::DiagnosticPreconditionerFactory::buildPreconditionerOperator requires that "
132 <<
"the timers be initialized. Currently they are null! (label = \"" << diagString_ <<
"\")");
135 ModifiableLinearOp & diagOp_ptr = state.
getModifiableOp(
"diagnosticOp");
137 if(diagOp_ptr==Teuchos::null) {
138 ModifiableLinearOp invOp;
141 Teuchos::TimeMonitor monitor(*buildTimer_,
false);
148 diagOp_ptr = createDiagnosticLinearOp(outputStream_,lo,invOp,diagString_);
150 diagOp_ptr = createDiagnosticLinearOp(outputStream_,invOp,diagString_);
157 diagOp->setForwardOp(lo);
159 ModifiableLinearOp invOp = diagOp->getModifiableOp();
162 Teuchos::TimeMonitor monitor(*rebuildTimer_,
false);
168 return diagOp_ptr.getConst();
176 TEUCHOS_TEST_FOR_EXCEPTION(not settings.isParameter(
"Inverse Factory"),std::runtime_error,
177 "Parameter \"Inverse Factory\" is required by a Teko::DiagnosticPreconditionerFactory");
178 TEUCHOS_TEST_FOR_EXCEPTION(not settings.isParameter(
"Descriptive Label"),std::runtime_error,
179 "Parameter \"Descriptive Label\" is required by a Teko::DiagnosticPreconditionerFactory");
182 std::string invName = settings.get<std::string>(
"Inverse Factory");
183 diagString_ = settings.get<std::string>(
"Descriptive Label");
187 invFactory_ = il->getInverseFactory(invName);
188 TEUCHOS_TEST_FOR_EXCEPTION(invFactory_==Teuchos::null,std::runtime_error,
189 "ERROR: \"Inverse Factory\" = " << invName
190 <<
" could not be found");
192 if(settings.isParameter(
"Print Residual"))
193 printResidual_ = settings.get<
bool>(
"Print Residual");
196 initTimers(diagString_);
204 TEUCHOS_TEST_FOR_EXCEPTION(invFactory_==Teuchos::null,std::runtime_error,
205 "ERROR: Teko::DiagnosticPreconditionerFactory::getRequestedParameters requires that a "
206 <<
"preconditioner factory has been set. Currently it is null!");
208 return invFactory_->getRequestedParameters();
215 TEUCHOS_TEST_FOR_EXCEPTION(invFactory_==Teuchos::null,std::runtime_error,
216 "ERROR: Teko::DiagnosticPreconditionerFactory::updateRequestedParameters requires that a "
217 <<
"preconditioner factory has been set. Currently it is null!");
219 return invFactory_->updateRequestedParameters(pl);
222 void DiagnosticPreconditionerFactory::initTimers(
const std::string & str)
224 buildTimer_ = Teuchos::rcp(
new Teuchos::Time(str+
" buildTimer"));
225 rebuildTimer_ = Teuchos::rcp(
new Teuchos::Time(str+
" rebuildTimer"));
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
Request the additional parameters this preconditioner factory needs.
virtual ~DiagnosticPreconditionerFactory()
default destructor: prints out diagnostic string
DiagnosticPreconditionerFactory()
Default constructor, for use with the AutoClone class.
virtual bool updateRequestedParameters(const Teuchos::ParameterList &pl)
Update this object with the fields from a parameter list.
This linear operator prints diagnostics about operator application and creation times. It is useful for debugging problems and determining bottle necks.
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
virtual void initializeFromParameterList(const Teuchos::ParameterList &settings)
This function builds the internals of the preconditioner factory from a parameter list...
An implementation of a state object preconditioners.
virtual LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const
Function that is called to build the preconditioner for the linear operator that is passed in...
virtual Teko::ModifiableLinearOp & getModifiableOp(const std::string &name)
Add a named operator to the state object.