92 #include "Teko_PreconditionerInverseFactory.hpp"
95 #include "Thyra_DefaultLinearOpSource.hpp"
96 #include "Thyra_DefaultInverseLinearOp.hpp"
97 #include "Thyra_DefaultPreconditioner.hpp"
100 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
104 #include "Teko_BlockPreconditionerFactory.hpp"
105 #include "Teko_Preconditioner.hpp"
106 #include "Teko_PreconditionerLinearOp.hpp"
107 #include "Teko_SolveInverseFactory.hpp"
110 using Teuchos::rcp_const_cast;
111 using Teuchos::rcp_dynamic_cast;
125 PreconditionerInverseFactory::PreconditionerInverseFactory(
126 const Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> > & precFactory,
127 const Teuchos::RCP<Teko::RequestHandler> & rh)
128 : precFactory_(precFactory)
147 PreconditionerInverseFactory::PreconditionerInverseFactory(
148 const Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> > & precFactory,
149 const Teuchos::RCP<const Teuchos::ParameterList> & xtraParam,
150 const Teuchos::RCP<Teko::RequestHandler> & rh)
151 : precFactory_(precFactory)
153 if(xtraParam!=Teuchos::null)
154 extraParams_ = rcp(
new Teuchos::ParameterList(*xtraParam));
156 extraParams_ = Teuchos::null;
162 PreconditionerInverseFactory::PreconditionerInverseFactory(
const PreconditionerInverseFactory & pFactory)
163 : precFactory_(pFactory.precFactory_)
177 InverseLinearOp PreconditionerInverseFactory::buildInverse(
const LinearOp & linearOp)
const
179 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
180 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp),&*prec);
182 RCP<Teko::PreconditionerLinearOp<double> > precOp
200 InverseLinearOp PreconditionerInverseFactory::buildInverse(
const LinearOp & linearOp,
const PreconditionerState & parentState)
const
202 Teko_DEBUG_SCOPE(
"PreconditionerInverseFactory::buildInverse(A,parentState)",10);
203 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
206 Teko_DEBUG_SCOPE(
"Casting to Teko::Preconditioner",10);
209 if(tekoPrec!=Teuchos::null) {
210 Teko_DEBUG_SCOPE(
"Merging states",10);
211 tekoPrec->mergeStateObject(parentState);
215 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp),&*prec);
217 RCP<Teko::PreconditionerLinearOp<double> > precOp
234 void PreconditionerInverseFactory::rebuildInverse(
const LinearOp & source,InverseLinearOp & dest)
const
236 Teko_DEBUG_MSG(
"BEGIN PreconditionerInverseFactory::rebuildInverse",10);
238 RCP<Thyra::PreconditionerBase<double> > prec
241 precFactory_->initializePrec(Thyra::defaultLinearOpSource(source),&*prec);
243 Teko_DEBUG_MSG(
"END PreconditionerInverseFactory::rebuildInverse",10);
254 Teuchos::RCP<const Teuchos::ParameterList> PreconditionerInverseFactory::getParameterList()
const
256 return precFactory_->getParameterList();
273 Teuchos::RCP<Teuchos::ParameterList> PreconditionerInverseFactory::getRequestedParameters()
const
275 Teuchos::RCP<BlockPreconditionerFactory> bpf = rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
278 if(bpf!=Teuchos::null)
279 return bpf->getRequestedParameters();
298 bool PreconditionerInverseFactory::updateRequestedParameters(
const Teuchos::ParameterList & pl)
300 Teuchos::RCP<BlockPreconditionerFactory> bpf = rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
303 if(bpf!=Teuchos::null)
304 return bpf->updateRequestedParameters(pl);
307 if(extraParams_==Teuchos::null)
310 Teuchos::ParameterList::ConstIterator itr;
311 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
314 std::string subName =
"";
315 for(itr=srcPl->begin();itr!=srcPl->end();++itr) {
317 if(itr->first.find(
"Settings")!=std::string::npos) {
318 subName = itr->first;
325 precFactory_->setParameterList(srcPl);
330 Teuchos::ParameterList & settingsList = srcPl->sublist(subName);
331 for(itr=pl.begin();itr!=pl.end();++itr) {
332 if(extraParams_->isParameter(itr->first))
333 settingsList.setEntry(itr->first,itr->second);
337 precFactory_->setParameterList(srcPl);
342 void PreconditionerInverseFactory::setupParameterListFromRequestHandler()
345 if(extraParams_==Teuchos::null)
348 Teuchos::ParameterList::ConstIterator itr;
349 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
352 std::string subName =
"";
353 for(itr=srcPl->begin();itr!=srcPl->end();++itr) {
355 if(itr->first.find(
"Settings")!=std::string::npos) {
356 subName = itr->first;
368 Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
369 TEUCHOS_TEST_FOR_EXCEPTION(rh==Teuchos::null,std::runtime_error,
370 "PreconditionerInverseFactory::setupParameterListFromRequestHandler: no request handler set");
373 rh->preRequest<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
374 Teuchos::RCP<Teuchos::ParameterList> requestParams =
375 rh->request<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
377 TEUCHOS_TEST_FOR_EXCEPTION(requestParams==Teuchos::null,std::runtime_error,
"User specified request not satisfied!");
381 for(itr=requestParams->begin();itr!=requestParams->end();++itr)
382 srcPl->setEntry(itr->first,itr->second);
384 Teuchos::ParameterList & settingsList = srcPl->sublist(subName);
385 for(itr=requestParams->begin();itr!=requestParams->end();++itr)
386 settingsList.setEntry(itr->first,itr->second);
390 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...