55 #include "Teko_PreconditionerInverseFactory.hpp"
58 #include "Thyra_DefaultLinearOpSource.hpp"
59 #include "Thyra_DefaultInverseLinearOp.hpp"
60 #include "Thyra_DefaultPreconditioner.hpp"
63 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
67 #include "Teko_BlockPreconditionerFactory.hpp"
68 #include "Teko_Preconditioner.hpp"
69 #include "Teko_PreconditionerLinearOp.hpp"
70 #include "Teko_SolveInverseFactory.hpp"
74 using Teuchos::rcp_const_cast;
75 using Teuchos::rcp_dynamic_cast;
88 PreconditionerInverseFactory::PreconditionerInverseFactory(
89 const Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> >& precFactory,
90 const Teuchos::RCP<Teko::RequestHandler>& rh)
91 : precFactory_(precFactory) {
109 PreconditionerInverseFactory::PreconditionerInverseFactory(
110 const Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> >& precFactory,
111 const Teuchos::RCP<const Teuchos::ParameterList>& xtraParam,
112 const Teuchos::RCP<Teko::RequestHandler>& rh)
113 : precFactory_(precFactory) {
114 if (xtraParam != Teuchos::null)
115 extraParams_ = rcp(
new Teuchos::ParameterList(*xtraParam));
117 extraParams_ = Teuchos::null;
123 PreconditionerInverseFactory::PreconditionerInverseFactory(
124 const PreconditionerInverseFactory& pFactory)
125 : precFactory_(pFactory.precFactory_) {
138 InverseLinearOp PreconditionerInverseFactory::buildInverse(
const LinearOp& linearOp)
const {
139 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
140 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp), &*prec);
142 RCP<Teko::PreconditionerLinearOp<double> > precOp =
160 InverseLinearOp PreconditionerInverseFactory::buildInverse(
161 const LinearOp& linearOp,
const PreconditionerState& parentState)
const {
162 Teko_DEBUG_SCOPE(
"PreconditionerInverseFactory::buildInverse(A,parentState)", 10);
163 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
166 Teko_DEBUG_SCOPE(
"Casting to Teko::Preconditioner", 10);
169 if (tekoPrec != Teuchos::null) {
170 Teko_DEBUG_SCOPE(
"Merging states", 10);
171 tekoPrec->mergeStateObject(parentState);
175 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp), &*prec);
177 RCP<Teko::PreconditionerLinearOp<double> > precOp =
194 void PreconditionerInverseFactory::rebuildInverse(
const LinearOp& source,
195 InverseLinearOp& dest)
const {
196 Teko_DEBUG_MSG(
"BEGIN PreconditionerInverseFactory::rebuildInverse", 10);
198 RCP<Thyra::PreconditionerBase<double> > prec =
200 ->getNonconstPreconditioner();
202 precFactory_->initializePrec(Thyra::defaultLinearOpSource(source), &*prec);
204 Teko_DEBUG_MSG(
"END PreconditionerInverseFactory::rebuildInverse", 10);
215 Teuchos::RCP<const Teuchos::ParameterList> PreconditionerInverseFactory::getParameterList()
const {
216 return precFactory_->getParameterList();
233 Teuchos::RCP<Teuchos::ParameterList> PreconditionerInverseFactory::getRequestedParameters()
const {
234 Teuchos::RCP<BlockPreconditionerFactory> bpf =
235 rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
238 if (bpf != Teuchos::null)
return bpf->getRequestedParameters();
257 bool PreconditionerInverseFactory::updateRequestedParameters(
const Teuchos::ParameterList& pl) {
258 Teuchos::RCP<BlockPreconditionerFactory> bpf =
259 rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
262 if (bpf != Teuchos::null)
return bpf->updateRequestedParameters(pl);
265 if (extraParams_ == Teuchos::null)
return true;
267 Teuchos::ParameterList::ConstIterator itr;
268 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
271 std::string subName =
"";
272 for (itr = srcPl->begin(); itr != srcPl->end(); ++itr) {
274 if (itr->first.find(
"Settings") != std::string::npos) {
275 subName = itr->first;
282 precFactory_->setParameterList(srcPl);
287 Teuchos::ParameterList& settingsList = srcPl->sublist(subName);
288 for (itr = pl.begin(); itr != pl.end(); ++itr) {
289 if (extraParams_->isParameter(itr->first)) settingsList.setEntry(itr->first, itr->second);
293 precFactory_->setParameterList(srcPl);
298 void PreconditionerInverseFactory::setupParameterListFromRequestHandler() {
300 if (extraParams_ == Teuchos::null)
return;
302 Teuchos::ParameterList::ConstIterator itr;
303 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
306 std::string subName =
"";
307 for (itr = srcPl->begin(); itr != srcPl->end(); ++itr) {
309 if (itr->first.find(
"Settings") != std::string::npos) {
310 subName = itr->first;
322 Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
323 TEUCHOS_TEST_FOR_EXCEPTION(
324 rh == Teuchos::null, std::runtime_error,
325 "PreconditionerInverseFactory::setupParameterListFromRequestHandler: no request handler set");
328 rh->preRequest<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
329 Teuchos::RCP<Teuchos::ParameterList> requestParams =
330 rh->request<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
332 TEUCHOS_TEST_FOR_EXCEPTION(requestParams == Teuchos::null, std::runtime_error,
333 "User specified request not satisfied!");
337 for (itr = requestParams->begin(); itr != requestParams->end(); ++itr)
338 srcPl->setEntry(itr->first, itr->second);
340 Teuchos::ParameterList& settingsList = srcPl->sublist(subName);
341 for (itr = requestParams->begin(); itr != requestParams->end(); ++itr)
342 settingsList.setEntry(itr->first, itr->second);
346 precFactory_->setParameterList(srcPl);
void setRequestHandler(const Teuchos::RCP< RequestHandler > &rh)
Set the request handler with pointers to the appropriate callbacks.
Class that wraps a PreconditionerBase object it makes it behave like a linear operator.
An extension of the Thyra::DefaultPreconditioner class with some specializations useful for use withi...