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"
111 using Teuchos::rcp_const_cast;
112 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) {
146 PreconditionerInverseFactory::PreconditionerInverseFactory(
147 const Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> >& precFactory,
148 const Teuchos::RCP<const Teuchos::ParameterList>& xtraParam,
149 const Teuchos::RCP<Teko::RequestHandler>& rh)
150 : precFactory_(precFactory) {
151 if (xtraParam != Teuchos::null)
152 extraParams_ = rcp(
new Teuchos::ParameterList(*xtraParam));
154 extraParams_ = Teuchos::null;
160 PreconditionerInverseFactory::PreconditionerInverseFactory(
161 const PreconditionerInverseFactory& pFactory)
162 : precFactory_(pFactory.precFactory_) {
175 InverseLinearOp PreconditionerInverseFactory::buildInverse(
const LinearOp& linearOp)
const {
176 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
177 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp), &*prec);
179 RCP<Teko::PreconditionerLinearOp<double> > precOp =
197 InverseLinearOp PreconditionerInverseFactory::buildInverse(
198 const LinearOp& linearOp,
const PreconditionerState& parentState)
const {
199 Teko_DEBUG_SCOPE(
"PreconditionerInverseFactory::buildInverse(A,parentState)", 10);
200 RCP<Thyra::PreconditionerBase<double> > prec = precFactory_->createPrec();
203 Teko_DEBUG_SCOPE(
"Casting to Teko::Preconditioner", 10);
206 if (tekoPrec != Teuchos::null) {
207 Teko_DEBUG_SCOPE(
"Merging states", 10);
208 tekoPrec->mergeStateObject(parentState);
212 precFactory_->initializePrec(Thyra::defaultLinearOpSource(linearOp), &*prec);
214 RCP<Teko::PreconditionerLinearOp<double> > precOp =
231 void PreconditionerInverseFactory::rebuildInverse(
const LinearOp& source,
232 InverseLinearOp& dest)
const {
233 Teko_DEBUG_MSG(
"BEGIN PreconditionerInverseFactory::rebuildInverse", 10);
235 RCP<Thyra::PreconditionerBase<double> > prec =
237 ->getNonconstPreconditioner();
239 precFactory_->initializePrec(Thyra::defaultLinearOpSource(source), &*prec);
241 Teko_DEBUG_MSG(
"END PreconditionerInverseFactory::rebuildInverse", 10);
252 Teuchos::RCP<const Teuchos::ParameterList> PreconditionerInverseFactory::getParameterList()
const {
253 return precFactory_->getParameterList();
270 Teuchos::RCP<Teuchos::ParameterList> PreconditionerInverseFactory::getRequestedParameters()
const {
271 Teuchos::RCP<BlockPreconditionerFactory> bpf =
272 rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
275 if (bpf != Teuchos::null)
return bpf->getRequestedParameters();
294 bool PreconditionerInverseFactory::updateRequestedParameters(
const Teuchos::ParameterList& pl) {
295 Teuchos::RCP<BlockPreconditionerFactory> bpf =
296 rcp_dynamic_cast<BlockPreconditionerFactory>(precFactory_);
299 if (bpf != Teuchos::null)
return bpf->updateRequestedParameters(pl);
302 if (extraParams_ == Teuchos::null)
return true;
304 Teuchos::ParameterList::ConstIterator itr;
305 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
308 std::string subName =
"";
309 for (itr = srcPl->begin(); itr != srcPl->end(); ++itr) {
311 if (itr->first.find(
"Settings") != std::string::npos) {
312 subName = itr->first;
319 precFactory_->setParameterList(srcPl);
324 Teuchos::ParameterList& settingsList = srcPl->sublist(subName);
325 for (itr = pl.begin(); itr != pl.end(); ++itr) {
326 if (extraParams_->isParameter(itr->first)) settingsList.setEntry(itr->first, itr->second);
330 precFactory_->setParameterList(srcPl);
335 void PreconditionerInverseFactory::setupParameterListFromRequestHandler() {
337 if (extraParams_ == Teuchos::null)
return;
339 Teuchos::ParameterList::ConstIterator itr;
340 RCP<Teuchos::ParameterList> srcPl = precFactory_->unsetParameterList();
343 std::string subName =
"";
344 for (itr = srcPl->begin(); itr != srcPl->end(); ++itr) {
346 if (itr->first.find(
"Settings") != std::string::npos) {
347 subName = itr->first;
359 Teuchos::RCP<Teko::RequestHandler> rh = getRequestHandler();
360 TEUCHOS_TEST_FOR_EXCEPTION(
361 rh == Teuchos::null, std::runtime_error,
362 "PreconditionerInverseFactory::setupParameterListFromRequestHandler: no request handler set");
365 rh->preRequest<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
366 Teuchos::RCP<Teuchos::ParameterList> requestParams =
367 rh->request<Teuchos::RCP<Teuchos::ParameterList> >(RequestMesg(extraParams_));
369 TEUCHOS_TEST_FOR_EXCEPTION(requestParams == Teuchos::null, std::runtime_error,
370 "User specified request not satisfied!");
374 for (itr = requestParams->begin(); itr != requestParams->end(); ++itr)
375 srcPl->setEntry(itr->first, itr->second);
377 Teuchos::ParameterList& settingsList = srcPl->sublist(subName);
378 for (itr = requestParams->begin(); itr != requestParams->end(); ++itr)
379 settingsList.setEntry(itr->first, itr->second);
383 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...