Teko  Version of the Day
Teko_InverseLibrary.cpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #include "Teko_InverseLibrary.hpp"
48 
49 #include "Teko_SolveInverseFactory.hpp"
50 #include "Teko_PreconditionerInverseFactory.hpp"
51 #include "Teko_BlockPreconditionerFactory.hpp"
52 
53 #include "Teko_NeumannSeriesPreconditionerFactory.hpp"
54 #include "Teuchos_AbstractFactoryStd.hpp"
55 #include "Teko_Utilities.hpp"
56 
57 #ifdef HAVE_Teko_ENABLE_Ifpack2
58 #include "Thyra_Ifpack2PreconditionerFactory.hpp"
59 #include "Tpetra_CrsMatrix.hpp"
60 #endif
61 
62 #include <algorithm>
63 
64 using Teuchos::RCP;
65 using Teuchos::rcp;
66 
67 namespace Teko {
68 
72 void addToStratimikosBuilder(const RCP<Stratimikos::DefaultLinearSolverBuilder> & builder)
73 {
74  typedef Thyra::PreconditionerFactoryBase<double> PrecFactory;
75 
76  RCP<const Teuchos::ParameterList> parameters = builder->getValidParameters();
77 
78  if(!parameters->sublist("Preconditioner Types").isSublist("Neumann Series")) {
79  RCP<const Teuchos::AbstractFactory<Thyra::PreconditionerFactoryBase<double> > > factory;
80 
81  factory = Teuchos::abstractFactoryStd<PrecFactory,Teko::NeumannSeriesPreconditionerFactory<double> >();
82  builder->setPreconditioningStrategyFactory(factory,"Neumann Series");
83  }
84  #ifdef HAVE_Teko_ENABLE_Ifpack2
85  {
86  typedef Thyra::PreconditionerFactoryBase<ST> Base;
87  typedef Thyra::Ifpack2PreconditionerFactory<Tpetra::CrsMatrix<ST,LO,GO,NT> > Impl;
88  builder->setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Base, Impl>(), "Ifpack2");
89  }
90  #endif // IFPACK2
91 
92 }
93 
94 InverseLibrary::InverseLibrary()
95 {
96  Teko_DEBUG_SCOPE("InverseLibrary::InverseLibrary", 10);
97 
98  defaultBuilder_ = Teuchos::rcp(new Stratimikos::DefaultLinearSolverBuilder());
99  addToStratimikosBuilder(defaultBuilder_);
100 
101  // setup some valid Stratimikos parameters
103 
104  // set valid solve factory names
105  stratValidSolver_.push_back("Belos");
106  stratValidSolver_.push_back("Amesos");
107  stratValidSolver_.push_back("AztecOO");
108 
109  // set valid preconditioner factory name
110  stratValidPrecond_.push_back("ML");
111  stratValidPrecond_.push_back("Ifpack");
112  stratValidPrecond_.push_back("Neumann Series");
113  stratValidPrecond_.push_back("MueLu");
114  stratValidPrecond_.push_back("Ifpack2");
115 
116  // set valid Teko preconditioner factory names
118 
119  Teko_DEBUG_MSG_BEGIN(10)
120  DEBUG_STREAM << "Loaded \"block\" preconditioners = ";
121  for(std::size_t i=0;i<blockValidPrecond_.size();i++)
122  DEBUG_STREAM << blockValidPrecond_[i] << ", ";
123  DEBUG_STREAM << std::endl;
124  Teko_DEBUG_MSG_END()
125 }
126 
127 InverseLibrary::InverseLibrary(const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
128  : defaultBuilder_(strat)
129 {
130  Teko_DEBUG_SCOPE("InverseLibrary::InverseLibrary", 10);
131 
132  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*defaultBuilder_->getValidParameters()));
133  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
134  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
135 
136  Teuchos::ParameterList::ConstIterator itr;
137 
138  // set valid solve factory names
139  for(itr=lst.begin();itr!=lst.end();++itr)
140  stratValidSolver_.push_back(itr->first);
141 
142  Teko_DEBUG_MSG_BEGIN(10)
143  DEBUG_STREAM << "Loaded \"Stratimikos\" solvers = ";
144  for(std::size_t i=0;i<stratValidSolver_.size();i++)
145  DEBUG_STREAM << stratValidSolver_[i] << ", ";
146  DEBUG_STREAM << std::endl;
147  Teko_DEBUG_MSG_END()
148 
149  // set valid prec factory names
150  for(itr=pft.begin();itr!=pft.end();++itr)
151  stratValidPrecond_.push_back(itr->first);
152 
153  Teko_DEBUG_MSG_BEGIN(10)
154  DEBUG_STREAM << "Loaded \"Stratimikos\" preconditioners = ";
155  for(std::size_t i=0;i<stratValidPrecond_.size();i++)
156  DEBUG_STREAM << stratValidPrecond_[i] << ", ";
157  DEBUG_STREAM << std::endl;
158  Teko_DEBUG_MSG_END()
159 
160  // set valid Teko preconditioner factory names
161  PreconditionerFactory::getPreconditionerFactoryNames(blockValidPrecond_);
162 
163  Teko_DEBUG_MSG_BEGIN(10)
164  DEBUG_STREAM << "Loaded \"block\" preconditioners = ";
165  for(std::size_t i=0;i<blockValidPrecond_.size();i++)
166  DEBUG_STREAM << blockValidPrecond_[i] << ", ";
167  DEBUG_STREAM << std::endl;
168  Teko_DEBUG_MSG_END()
169 }
170 
172 void InverseLibrary::addInverse(const std::string & label,const Teuchos::ParameterList & pl)
173 {
174  // strip out the label
175  const std::string type = pl.get<std::string>("Type");
176 
177  // copy the parameter list so we can modify it
178  Teuchos::ParameterList settingsList;
179  settingsList.set(type,pl);
180  settingsList.sublist(type).remove("Type");
181 
182  // is this a Stratimikos preconditioner or solver
183  if(std::find(stratValidPrecond_.begin(),stratValidPrecond_.end(),type)!=stratValidPrecond_.end()) {
184  // this is a Stratimikos preconditioner factory
185  addStratPrecond(label,type,settingsList);
186  }
187  else if(std::find(stratValidSolver_.begin(),stratValidSolver_.end(),type)!=stratValidSolver_.end()) {
188  // this is a Stratimikos preconditioner factory
189  addStratSolver(label,type,settingsList);
190  }
191  else if(std::find(blockValidPrecond_.begin(),blockValidPrecond_.end(),type)!=blockValidPrecond_.end()) {
192  // this is a Teko preconditioner factory
193  addBlockPrecond(label,type,settingsList);
194  }
195  else {
196  Teuchos::FancyOStream & os = *Teko::getOutputStream();
197  os << "ERROR: Could not find inverse type \"" << type
198  << "\" required by inverse name \"" << label << "\"" << std::endl;
199  TEUCHOS_ASSERT(false);
200  }
201 }
202 
204 void InverseLibrary::addStratSolver(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
205 {
206  // add some additional parameters onto the list
207  RCP<Teuchos::ParameterList> stratList = rcp(new Teuchos::ParameterList());
208  stratList->set("Linear Solver Type",type);
209  stratList->set("Linear Solver Types",pl);
210  stratList->set("Preconditioner Type","None");
211 
212  stratSolver_[label] = stratList;
213 }
214 
216 void InverseLibrary::addStratPrecond(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
217 {
218  // add some additional parameters onto the list
219  RCP<Teuchos::ParameterList> stratList = rcp(new Teuchos::ParameterList());
220  stratList->set("Preconditioner Type",type);
221  stratList->set("Preconditioner Types",pl);
222 
223  stratPrecond_[label] = stratList;
224 }
225 
227 void InverseLibrary::addBlockPrecond(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
228 {
229  // add some additional parameters onto the list
230  RCP<Teuchos::ParameterList> blockList = rcp(new Teuchos::ParameterList());
231  blockList->set("Preconditioner Type",type);
232  blockList->set("Preconditioner Settings",pl.sublist(type));
233 
234  // add the Teko preconditioner parameter list into the library
235  blockPrecond_[label] = blockList;
236 }
237 
245 Teuchos::RCP<const Teuchos::ParameterList> InverseLibrary::getParameterList(const std::string & label) const
246 {
247  std::map<std::string,RCP<const Teuchos::ParameterList> >::const_iterator itr;
248 
249  // check preconditioners
250  itr = stratPrecond_.find(label);
251  if(itr!=stratPrecond_.end()) return itr->second;
252 
253  // check solvers
254  itr = stratSolver_.find(label);
255  if(itr!=stratSolver_.end()) return itr->second;
256 
257  // check solvers
258  itr = blockPrecond_.find(label);
259  if(itr!=blockPrecond_.end()) return itr->second;
260 
261  return Teuchos::null;
262 }
263 
265 Teuchos::RCP<InverseFactory> InverseLibrary::getInverseFactory(const std::string & label) const
266 {
267  Teko_DEBUG_SCOPE("InverseLibrary::getInverseFactory",10);
268 
269  std::map<std::string,RCP<const Teuchos::ParameterList> >::const_iterator itr;
270 
271  bool isStratSolver=false,isStratPrecond=false,isBlockPrecond=false;
272 
273  // is this a Stratimikos solver?
274  itr = stratPrecond_.find(label);
275  isStratPrecond = itr!=stratPrecond_.end();
276 
277  // is this a Stratimikos preconditioner?
278  if(not isStratPrecond) {
279  itr = stratSolver_.find(label);
280  isStratSolver = itr!=stratSolver_.end();
281  }
282 
283  // must be a "block" preconditioner
284  if(not (isStratSolver || isStratPrecond)) {
285  itr = blockPrecond_.find(label);
286  isBlockPrecond = itr!=blockPrecond_.end();
287  }
288 
289  Teko_DEBUG_MSG("Inverse \"" << label << "\" is of type "
290  << "strat prec = " << isStratPrecond << ", "
291  << "strat solv = " << isStratSolver << ", "
292  << "block prec = " << isBlockPrecond,3);
293 
294  // Must be one of Strat solver, strat preconditioner, block preconditioner
295  if(not (isStratSolver || isStratPrecond || isBlockPrecond)) {
296  RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
297 
298  *out << "InverseLibrary::getInverseFactory could not find \"" << label << "\" ... aborting\n";
299  *out << "Choose one of: " << std::endl;
300 
301  *out << " Stratimikos preconditioners = ";
302  for(itr=stratPrecond_.begin();itr!=stratPrecond_.end();++itr)
303  *out << " \"" << itr->first << "\"\n";
304  *out << std::endl;
305 
306  *out << " Stratimikos solvers = ";
307  for(itr=stratSolver_.begin();itr!=stratSolver_.end();++itr)
308  *out << " \"" << itr->first << "\"\n";
309  *out << std::endl;
310 
311  *out << " Block preconditioners = ";
312  for(itr=blockPrecond_.begin();itr!=blockPrecond_.end();++itr)
313  *out << " \"" << itr->first << "\"\n";
314  *out << std::endl;
315 
316  TEUCHOS_ASSERT(isStratSolver || isStratPrecond || isBlockPrecond);
317  }
318 
319  RCP<const Teuchos::ParameterList> pl = itr->second;
320 
321  // build inverse factory
322  if(isStratPrecond) {
323  // remove required parameters
324  RCP<Teuchos::ParameterList> plCopy = rcp(new Teuchos::ParameterList(*pl));
325  std::string type = plCopy->get<std::string>("Preconditioner Type");
326  RCP<Teuchos::ParameterList> xtraParams;
327  if(plCopy->sublist("Preconditioner Types").sublist(type).isParameter("Required Parameters")) {
328  xtraParams = rcp(new Teuchos::ParameterList(
329  plCopy->sublist("Preconditioner Types").sublist(type).sublist("Required Parameters")));
330  plCopy->sublist("Preconditioner Types").sublist(type).remove("Required Parameters");
331  }
332 
333  // print some debuggin info
334  Teko_DEBUG_MSG_BEGIN(10);
335  DEBUG_STREAM << "Printing parameter list: " << std::endl;
336  Teko_DEBUG_PUSHTAB(); plCopy->print(DEBUG_STREAM); Teko_DEBUG_POPTAB();
337 
338  if(xtraParams!=Teuchos::null) {
339  DEBUG_STREAM << "Printing extra parameters: " << std::endl;
340  Teko_DEBUG_PUSHTAB(); xtraParams->print(DEBUG_STREAM); Teko_DEBUG_POPTAB();
341  }
342  Teko_DEBUG_MSG_END();
343 
344  // Stratimikos::DefaultLinearSolverBuilder strat;
345  // addToStratimikosBuilder(strat);
346  defaultBuilder_->setParameterList(plCopy);
347 
348  // try to build a preconditioner factory
349  RCP<Thyra::PreconditionerFactoryBase<double> > precFact = defaultBuilder_->createPreconditioningStrategy(type);
350 
351  // string must map to a preconditioner
352  RCP<Teko::PreconditionerInverseFactory> precInvFact
353  = rcp(new PreconditionerInverseFactory(precFact,xtraParams,getRequestHandler()));
354  precInvFact->setupParameterListFromRequestHandler();
355  return precInvFact;
356  }
357  else if(isStratSolver) {
358  RCP<Teuchos::ParameterList> solveList = rcp(new Teuchos::ParameterList(*pl));
359  std::string type = solveList->get<std::string>("Linear Solver Type");
360 
361  // get preconditioner name, remove "Use Preconditioner" parameter
362  Teuchos::ParameterList & solveSettings = solveList->sublist("Linear Solver Types").sublist(type);
363  std::string precKeyWord = "Use Preconditioner";
364  std::string precName = "None";
365  if(solveSettings.isParameter(precKeyWord)) {
366  precName = solveSettings.get<std::string>(precKeyWord);
367  solveSettings.remove(precKeyWord);
368  }
369 
370  // build Thyra preconditioner factory
371  RCP<Thyra::PreconditionerFactoryBase<double> > precFactory;
372  if(precName!="None") {
373  // we will manually set the preconditioner, so set this to null
374  solveList->set<std::string>("Preconditioner Type","None");
375 
376  // build inverse that preconditioner corresponds to
377  RCP<PreconditionerInverseFactory> precInvFactory
378  = Teuchos::rcp_dynamic_cast<PreconditionerInverseFactory>(getInverseFactory(precName));
379 
380  // extract preconditioner factory from preconditioner _inverse_ factory
381  precFactory = precInvFactory->getPrecFactory();
382  }
383 
384  // Stratimikos::DefaultLinearSolverBuilder strat;
385  // addToStratimikosBuilder(strat);
386  defaultBuilder_->setParameterList(solveList);
387 
388  // try to build a solver factory
389  RCP<Thyra::LinearOpWithSolveFactoryBase<double> > solveFact = defaultBuilder_->createLinearSolveStrategy(type);
390  if(precFactory!=Teuchos::null)
391  solveFact->setPreconditionerFactory(precFactory,precName);
392 
393  // if its around, build a InverseFactory
394  return rcp(new SolveInverseFactory(solveFact));
395  }
396  else if(isBlockPrecond) {
397  try {
398  std::string type = pl->get<std::string>("Preconditioner Type");
399  const Teuchos::ParameterList & settings = pl->sublist("Preconditioner Settings");
400 
401  // build preconditioner factory from the string
402  RCP<PreconditionerFactory> precFact
403  = PreconditionerFactory::buildPreconditionerFactory(type,settings,Teuchos::rcpFromRef(*this));
404 
405  TEUCHOS_ASSERT(precFact!=Teuchos::null);
406 
407  // return the inverse factory object
408  return rcp(new PreconditionerInverseFactory(precFact,getRequestHandler()));
409  }
410  catch(std::exception & e) {
411  RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
412 
413  *out << "Teko: \"getInverseFactory\" failed, Parameter List =\n";
414  pl->print(*out);
415 
416  *out << "*** THROWN EXCEPTION ***\n";
417  *out << e.what() << std::endl;
418  *out << "************************\n";
419 
420  throw e;
421  }
422  }
423 
424  TEUCHOS_ASSERT(false);
425 }
426 
428 void InverseLibrary::PrintAvailableInverses(std::ostream & os) const
429 {
430  std::map<std::string,Teuchos::RCP<const Teuchos::ParameterList> >::const_iterator itr;
431 
432  os << "Stratimikos Solvers: " << std::endl;
433  os << "********************************" << std::endl;
434  for(itr=stratSolver_.begin();itr!=stratSolver_.end();++itr) {
435  os << "name = \"" << itr->first << "\"" << std::endl;
436  itr->second->print(os);
437  os << std::endl;
438  }
439 
440  os << "Stratimikos Preconditioners: " << std::endl;
441  os << "********************************" << std::endl;
442  for(itr=stratPrecond_.begin();itr!=stratPrecond_.end();++itr) {
443  os << "name = \"" << itr->first << "\"" << std::endl;
444  itr->second->print(os);
445  os << std::endl;
446  }
447 
448  os << "Teko Preconditioners: " << std::endl;
449  os << "********************************" << std::endl;
450  for(itr=blockPrecond_.begin();itr!=blockPrecond_.end();++itr) {
451  os << "name = \"" << itr->first << "\"" << std::endl;
452  itr->second->print(os);
453  os << std::endl;
454  }
455 }
456 
466 RCP<InverseLibrary> InverseLibrary::buildFromParameterList(const Teuchos::ParameterList & pl,bool useStratDefaults)
467 {
468  // build from Stratimikos or allocate a new inverse library
469  RCP<InverseLibrary> invLib;
470  if(useStratDefaults)
471  invLib = InverseLibrary::buildFromStratimikos();
472  else
473  invLib = rcp(new InverseLibrary());
474 
475  // to convert the void* like entry
476  Teuchos::ParameterList * temp = 0;
477 
478  // loop over all entries in parameter list
479  Teuchos::ParameterList::ConstIterator itr;
480  for(itr=pl.begin();itr!=pl.end();++itr) {
481  // get current entry
482  std::string label = itr->first;
483  Teuchos::ParameterList & list = itr->second.getValue(temp);
484 
485  // add to library
486  invLib->addInverse(label,list);
487  }
488 
489  return invLib;
490 }
491 
502 RCP<InverseLibrary> InverseLibrary::buildFromParameterList(const Teuchos::ParameterList & pl,
503  const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
504 {
505  // if strat is set to null, use the defaults
506  if(strat==Teuchos::null)
507  return buildFromParameterList(pl,true);
508 
509  // build from Stratimikos or allocate a new inverse library
510  RCP<InverseLibrary> invLib = InverseLibrary::buildFromStratimikos(strat);
511 
512  // to convert the void* like entry
513  Teuchos::ParameterList * temp = 0;
514 
515  // loop over all entries in parameter list
516  Teuchos::ParameterList::ConstIterator itr;
517  for(itr=pl.begin();itr!=pl.end();++itr) {
518  // get current entry
519  std::string label = itr->first;
520  Teuchos::ParameterList & list = itr->second.getValue(temp);
521 
522  // add to library
523  invLib->addInverse(label,list);
524  }
525 
526  return invLib;
527 }
528 
537 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos()
538 {
539  RCP<InverseLibrary> invLib = rcp(new InverseLibrary());
540 
541  // get default inveres in Stratimikos
542  RCP<Stratimikos::DefaultLinearSolverBuilder> strat = invLib->defaultBuilder_;
543  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat->getValidParameters()));
544  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
545  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
546 
547  Teuchos::ParameterList::ConstIterator itr;
548  Teuchos::ParameterList * temp = 0;
549 
550  // loop over all entries in solver list
551  for(itr=lst.begin();itr!=lst.end();++itr) {
552  // get current entry
553  std::string label = itr->first;
554  Teuchos::ParameterList & list = itr->second.getValue(temp);
555  list.set("Type",label);
556 
557  // add to library
558  invLib->addInverse(label,list);
559  }
560 
561  // loop over all entries in preconditioner list
562  for(itr=pft.begin();itr!=pft.end();++itr) {
563  // get current entry
564  std::string label = itr->first;
565  Teuchos::ParameterList & list = itr->second.getValue(temp);
566  list.set("Type",label);
567 
568  // add to library
569  invLib->addInverse(label,list);
570  }
571 
572  return invLib;
573 }
574 
584 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos(const Stratimikos::DefaultLinearSolverBuilder & strat)
585 {
586  RCP<InverseLibrary> invLib = rcp(new InverseLibrary());
587 
588  // get default inveres in Stratimikos
589  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat.getValidParameters()));
590  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
591  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
592 
593  Teuchos::ParameterList::ConstIterator itr;
594  Teuchos::ParameterList * temp = 0;
595 
596  // loop over all entries in solver list
597  for(itr=lst.begin();itr!=lst.end();++itr) {
598  // get current entry
599  std::string label = itr->first;
600  Teuchos::ParameterList & list = itr->second.getValue(temp);
601  list.set("Type",label);
602 
603  // add to library
604  invLib->addInverse(label,list);
605  }
606 
607  // loop over all entries in preconditioner list
608  for(itr=pft.begin();itr!=pft.end();++itr) {
609  // get current entry
610  std::string label = itr->first;
611  Teuchos::ParameterList & list = itr->second.getValue(temp);
612  list.set("Type",label);
613 
614  // add to library
615  invLib->addInverse(label,list);
616  }
617 
618  return invLib;
619 }
620 
630 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos(const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
631 {
632  RCP<InverseLibrary> invLib = rcp(new InverseLibrary(strat));
633 
634  // get default inveres in Stratimikos
635  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat->getValidParameters()));
636  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
637  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
638 
639  Teuchos::ParameterList::ConstIterator itr;
640  Teuchos::ParameterList * temp = 0;
641 
642  // loop over all entries in solver list
643  for(itr=lst.begin();itr!=lst.end();++itr) {
644  // get current entry
645  std::string label = itr->first;
646  Teuchos::ParameterList & list = itr->second.getValue(temp);
647  list.set("Type",label);
648 
649  // add to library
650  invLib->addInverse(label,list);
651  }
652 
653  // loop over all entries in preconditioner list
654  for(itr=pft.begin();itr!=pft.end();++itr) {
655  // get current entry
656  std::string label = itr->first;
657  Teuchos::ParameterList & list = itr->second.getValue(temp);
658  list.set("Type",label);
659 
660  // add to library
661  invLib->addInverse(label,list);
662  }
663 
664  return invLib;
665 }
666 
667 } // end namespace Teko
static void getPreconditionerFactoryNames(std::vector< std::string > &names)
Get the names of the block preconditioner factories.
static Teuchos::RCP< PreconditionerFactory > buildPreconditionerFactory(const std::string &name, const Teuchos::ParameterList &settings, const Teuchos::RCP< const InverseLibrary > &invLib=Teuchos::null)
Builder function for creating preconditioner factories (yes this is a factory factory).