Teko  Version of the Day
 All Classes Files Functions Variables Pages
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("Amesos2");
108  stratValidSolver_.push_back("AztecOO");
109 
110  // set valid preconditioner factory name
111  stratValidPrecond_.push_back("ML");
112  stratValidPrecond_.push_back("Ifpack");
113  stratValidPrecond_.push_back("Neumann Series");
114  stratValidPrecond_.push_back("MueLu");
115  stratValidPrecond_.push_back("Ifpack2");
116 
117  // set valid Teko preconditioner factory names
119 
120  Teko_DEBUG_MSG_BEGIN(10)
121  DEBUG_STREAM << "Loaded \"block\" preconditioners = ";
122  for(std::size_t i=0;i<blockValidPrecond_.size();i++)
123  DEBUG_STREAM << blockValidPrecond_[i] << ", ";
124  DEBUG_STREAM << std::endl;
125  Teko_DEBUG_MSG_END()
126 }
127 
128 InverseLibrary::InverseLibrary(const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
129  : defaultBuilder_(strat)
130 {
131  Teko_DEBUG_SCOPE("InverseLibrary::InverseLibrary", 10);
132 
133  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*defaultBuilder_->getValidParameters()));
134  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
135  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
136 
137  Teuchos::ParameterList::ConstIterator itr;
138 
139  // set valid solve factory names
140  for(itr=lst.begin();itr!=lst.end();++itr)
141  stratValidSolver_.push_back(itr->first);
142 
143  Teko_DEBUG_MSG_BEGIN(10)
144  DEBUG_STREAM << "Loaded \"Stratimikos\" solvers = ";
145  for(std::size_t i=0;i<stratValidSolver_.size();i++)
146  DEBUG_STREAM << stratValidSolver_[i] << ", ";
147  DEBUG_STREAM << std::endl;
148  Teko_DEBUG_MSG_END()
149 
150  // set valid prec factory names
151  for(itr=pft.begin();itr!=pft.end();++itr)
152  stratValidPrecond_.push_back(itr->first);
153 
154  Teko_DEBUG_MSG_BEGIN(10)
155  DEBUG_STREAM << "Loaded \"Stratimikos\" preconditioners = ";
156  for(std::size_t i=0;i<stratValidPrecond_.size();i++)
157  DEBUG_STREAM << stratValidPrecond_[i] << ", ";
158  DEBUG_STREAM << std::endl;
159  Teko_DEBUG_MSG_END()
160 
161  // set valid Teko preconditioner factory names
162  PreconditionerFactory::getPreconditionerFactoryNames(blockValidPrecond_);
163 
164  Teko_DEBUG_MSG_BEGIN(10)
165  DEBUG_STREAM << "Loaded \"block\" preconditioners = ";
166  for(std::size_t i=0;i<blockValidPrecond_.size();i++)
167  DEBUG_STREAM << blockValidPrecond_[i] << ", ";
168  DEBUG_STREAM << std::endl;
169  Teko_DEBUG_MSG_END()
170 }
171 
173 void InverseLibrary::addInverse(const std::string & label,const Teuchos::ParameterList & pl)
174 {
175  // strip out the label
176  const std::string type = pl.get<std::string>("Type");
177 
178  // copy the parameter list so we can modify it
179  Teuchos::ParameterList settingsList;
180  settingsList.set(type,pl);
181  settingsList.sublist(type).remove("Type");
182 
183  // is this a Stratimikos preconditioner or solver
184  if(std::find(stratValidPrecond_.begin(),stratValidPrecond_.end(),type)!=stratValidPrecond_.end()) {
185  // this is a Stratimikos preconditioner factory
186  addStratPrecond(label,type,settingsList);
187  }
188  else if(std::find(stratValidSolver_.begin(),stratValidSolver_.end(),type)!=stratValidSolver_.end()) {
189  // this is a Stratimikos preconditioner factory
190  addStratSolver(label,type,settingsList);
191  }
192  else if(std::find(blockValidPrecond_.begin(),blockValidPrecond_.end(),type)!=blockValidPrecond_.end()) {
193  // this is a Teko preconditioner factory
194  addBlockPrecond(label,type,settingsList);
195  }
196  else {
197  Teuchos::FancyOStream & os = *Teko::getOutputStream();
198  os << "ERROR: Could not find inverse type \"" << type
199  << "\" required by inverse name \"" << label << "\"" << std::endl;
200  TEUCHOS_ASSERT(false);
201  }
202 }
203 
205 void InverseLibrary::addStratSolver(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
206 {
207  // add some additional parameters onto the list
208  RCP<Teuchos::ParameterList> stratList = rcp(new Teuchos::ParameterList());
209  stratList->set("Linear Solver Type",type);
210  stratList->set("Linear Solver Types",pl);
211  stratList->set("Preconditioner Type","None");
212 
213  stratSolver_[label] = stratList;
214 }
215 
217 void InverseLibrary::addStratPrecond(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
218 {
219  // add some additional parameters onto the list
220  RCP<Teuchos::ParameterList> stratList = rcp(new Teuchos::ParameterList());
221  stratList->set("Preconditioner Type",type);
222  stratList->set("Preconditioner Types",pl);
223 
224  stratPrecond_[label] = stratList;
225 }
226 
228 void InverseLibrary::addBlockPrecond(const std::string & label,const std::string & type,const Teuchos::ParameterList & pl)
229 {
230  // add some additional parameters onto the list
231  RCP<Teuchos::ParameterList> blockList = rcp(new Teuchos::ParameterList());
232  blockList->set("Preconditioner Type",type);
233  blockList->set("Preconditioner Settings",pl.sublist(type));
234 
235  // add the Teko preconditioner parameter list into the library
236  blockPrecond_[label] = blockList;
237 }
238 
246 Teuchos::RCP<const Teuchos::ParameterList> InverseLibrary::getParameterList(const std::string & label) const
247 {
248  std::map<std::string,RCP<const Teuchos::ParameterList> >::const_iterator itr;
249 
250  // check preconditioners
251  itr = stratPrecond_.find(label);
252  if(itr!=stratPrecond_.end()) return itr->second;
253 
254  // check solvers
255  itr = stratSolver_.find(label);
256  if(itr!=stratSolver_.end()) return itr->second;
257 
258  // check solvers
259  itr = blockPrecond_.find(label);
260  if(itr!=blockPrecond_.end()) return itr->second;
261 
262  return Teuchos::null;
263 }
264 
266 Teuchos::RCP<InverseFactory> InverseLibrary::getInverseFactory(const std::string & label) const
267 {
268  Teko_DEBUG_SCOPE("InverseLibrary::getInverseFactory",10);
269 
270  std::map<std::string,RCP<const Teuchos::ParameterList> >::const_iterator itr;
271 
272  bool isStratSolver=false,isStratPrecond=false,isBlockPrecond=false;
273 
274  // is this a Stratimikos solver?
275  itr = stratPrecond_.find(label);
276  isStratPrecond = itr!=stratPrecond_.end();
277 
278  // is this a Stratimikos preconditioner?
279  if(not isStratPrecond) {
280  itr = stratSolver_.find(label);
281  isStratSolver = itr!=stratSolver_.end();
282  }
283 
284  // must be a "block" preconditioner
285  if(not (isStratSolver || isStratPrecond)) {
286  itr = blockPrecond_.find(label);
287  isBlockPrecond = itr!=blockPrecond_.end();
288  }
289 
290  Teko_DEBUG_MSG("Inverse \"" << label << "\" is of type "
291  << "strat prec = " << isStratPrecond << ", "
292  << "strat solv = " << isStratSolver << ", "
293  << "block prec = " << isBlockPrecond,3);
294 
295  // Must be one of Strat solver, strat preconditioner, block preconditioner
296  if(not (isStratSolver || isStratPrecond || isBlockPrecond)) {
297  RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
298 
299  *out << "InverseLibrary::getInverseFactory could not find \"" << label << "\" ... aborting\n";
300  *out << "Choose one of: " << std::endl;
301 
302  *out << " Stratimikos preconditioners = ";
303  for(itr=stratPrecond_.begin();itr!=stratPrecond_.end();++itr)
304  *out << " \"" << itr->first << "\"\n";
305  *out << std::endl;
306 
307  *out << " Stratimikos solvers = ";
308  for(itr=stratSolver_.begin();itr!=stratSolver_.end();++itr)
309  *out << " \"" << itr->first << "\"\n";
310  *out << std::endl;
311 
312  *out << " Block preconditioners = ";
313  for(itr=blockPrecond_.begin();itr!=blockPrecond_.end();++itr)
314  *out << " \"" << itr->first << "\"\n";
315  *out << std::endl;
316 
317  TEUCHOS_ASSERT(isStratSolver || isStratPrecond || isBlockPrecond);
318  }
319 
320  RCP<const Teuchos::ParameterList> pl = itr->second;
321 
322  // build inverse factory
323  if(isStratPrecond) {
324  // remove required parameters
325  RCP<Teuchos::ParameterList> plCopy = rcp(new Teuchos::ParameterList(*pl));
326  std::string type = plCopy->get<std::string>("Preconditioner Type");
327  RCP<Teuchos::ParameterList> xtraParams;
328  if(plCopy->sublist("Preconditioner Types").sublist(type).isParameter("Required Parameters")) {
329  xtraParams = rcp(new Teuchos::ParameterList(
330  plCopy->sublist("Preconditioner Types").sublist(type).sublist("Required Parameters")));
331  plCopy->sublist("Preconditioner Types").sublist(type).remove("Required Parameters");
332  }
333 
334  // print some debuggin info
335  Teko_DEBUG_MSG_BEGIN(10);
336  DEBUG_STREAM << "Printing parameter list: " << std::endl;
337  Teko_DEBUG_PUSHTAB(); plCopy->print(DEBUG_STREAM); Teko_DEBUG_POPTAB();
338 
339  if(xtraParams!=Teuchos::null) {
340  DEBUG_STREAM << "Printing extra parameters: " << std::endl;
341  Teko_DEBUG_PUSHTAB(); xtraParams->print(DEBUG_STREAM); Teko_DEBUG_POPTAB();
342  }
343  Teko_DEBUG_MSG_END();
344 
345  // Stratimikos::DefaultLinearSolverBuilder strat;
346  // addToStratimikosBuilder(strat);
347  defaultBuilder_->setParameterList(plCopy);
348 
349  // try to build a preconditioner factory
350  RCP<Thyra::PreconditionerFactoryBase<double> > precFact = defaultBuilder_->createPreconditioningStrategy(type);
351 
352  // string must map to a preconditioner
353  RCP<Teko::PreconditionerInverseFactory> precInvFact
354  = rcp(new PreconditionerInverseFactory(precFact,xtraParams,getRequestHandler()));
355  precInvFact->setupParameterListFromRequestHandler();
356  return precInvFact;
357  }
358  else if(isStratSolver) {
359  RCP<Teuchos::ParameterList> solveList = rcp(new Teuchos::ParameterList(*pl));
360  std::string type = solveList->get<std::string>("Linear Solver Type");
361 
362  // get preconditioner name, remove "Use Preconditioner" parameter
363  Teuchos::ParameterList & solveSettings = solveList->sublist("Linear Solver Types").sublist(type);
364  std::string precKeyWord = "Use Preconditioner";
365  std::string precName = "None";
366  if(solveSettings.isParameter(precKeyWord)) {
367  precName = solveSettings.get<std::string>(precKeyWord);
368  solveSettings.remove(precKeyWord);
369  }
370 
371  // build Thyra preconditioner factory
372  RCP<Thyra::PreconditionerFactoryBase<double> > precFactory;
373  if(precName!="None") {
374  // we will manually set the preconditioner, so set this to null
375  solveList->set<std::string>("Preconditioner Type","None");
376 
377  // build inverse that preconditioner corresponds to
378  RCP<PreconditionerInverseFactory> precInvFactory
379  = Teuchos::rcp_dynamic_cast<PreconditionerInverseFactory>(getInverseFactory(precName));
380 
381  // extract preconditioner factory from preconditioner _inverse_ factory
382  precFactory = precInvFactory->getPrecFactory();
383  }
384 
385  // Stratimikos::DefaultLinearSolverBuilder strat;
386  // addToStratimikosBuilder(strat);
387  defaultBuilder_->setParameterList(solveList);
388 
389  // try to build a solver factory
390  RCP<Thyra::LinearOpWithSolveFactoryBase<double> > solveFact = defaultBuilder_->createLinearSolveStrategy(type);
391  if(precFactory!=Teuchos::null)
392  solveFact->setPreconditionerFactory(precFactory,precName);
393 
394  // if its around, build a InverseFactory
395  return rcp(new SolveInverseFactory(solveFact));
396  }
397  else if(isBlockPrecond) {
398  try {
399  std::string type = pl->get<std::string>("Preconditioner Type");
400  const Teuchos::ParameterList & settings = pl->sublist("Preconditioner Settings");
401 
402  // build preconditioner factory from the string
403  RCP<PreconditionerFactory> precFact
404  = PreconditionerFactory::buildPreconditionerFactory(type,settings,Teuchos::rcpFromRef(*this));
405 
406  TEUCHOS_ASSERT(precFact!=Teuchos::null);
407 
408  // return the inverse factory object
409  return rcp(new PreconditionerInverseFactory(precFact,getRequestHandler()));
410  }
411  catch(std::exception & e) {
412  RCP<Teuchos::FancyOStream> out = Teko::getOutputStream();
413 
414  *out << "Teko: \"getInverseFactory\" failed, Parameter List =\n";
415  pl->print(*out);
416 
417  *out << "*** THROWN EXCEPTION ***\n";
418  *out << e.what() << std::endl;
419  *out << "************************\n";
420 
421  throw e;
422  }
423  }
424 
425  TEUCHOS_ASSERT(false);
426 }
427 
429 void InverseLibrary::PrintAvailableInverses(std::ostream & os) const
430 {
431  std::map<std::string,Teuchos::RCP<const Teuchos::ParameterList> >::const_iterator itr;
432 
433  os << "Stratimikos Solvers: " << std::endl;
434  os << "********************************" << std::endl;
435  for(itr=stratSolver_.begin();itr!=stratSolver_.end();++itr) {
436  os << "name = \"" << itr->first << "\"" << std::endl;
437  itr->second->print(os);
438  os << std::endl;
439  }
440 
441  os << "Stratimikos Preconditioners: " << std::endl;
442  os << "********************************" << std::endl;
443  for(itr=stratPrecond_.begin();itr!=stratPrecond_.end();++itr) {
444  os << "name = \"" << itr->first << "\"" << std::endl;
445  itr->second->print(os);
446  os << std::endl;
447  }
448 
449  os << "Teko Preconditioners: " << std::endl;
450  os << "********************************" << std::endl;
451  for(itr=blockPrecond_.begin();itr!=blockPrecond_.end();++itr) {
452  os << "name = \"" << itr->first << "\"" << std::endl;
453  itr->second->print(os);
454  os << std::endl;
455  }
456 }
457 
467 RCP<InverseLibrary> InverseLibrary::buildFromParameterList(const Teuchos::ParameterList & pl,bool useStratDefaults)
468 {
469  // build from Stratimikos or allocate a new inverse library
470  RCP<InverseLibrary> invLib;
471  if(useStratDefaults)
472  invLib = InverseLibrary::buildFromStratimikos();
473  else
474  invLib = rcp(new InverseLibrary());
475 
476  // to convert the void* like entry
477  Teuchos::ParameterList * temp = 0;
478 
479  // loop over all entries in parameter list
480  Teuchos::ParameterList::ConstIterator itr;
481  for(itr=pl.begin();itr!=pl.end();++itr) {
482  // get current entry
483  std::string label = itr->first;
484  Teuchos::ParameterList & list = itr->second.getValue(temp);
485 
486  // add to library
487  invLib->addInverse(label,list);
488  }
489 
490  return invLib;
491 }
492 
503 RCP<InverseLibrary> InverseLibrary::buildFromParameterList(const Teuchos::ParameterList & pl,
504  const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
505 {
506  // if strat is set to null, use the defaults
507  if(strat==Teuchos::null)
508  return buildFromParameterList(pl,true);
509 
510  // build from Stratimikos or allocate a new inverse library
511  RCP<InverseLibrary> invLib = InverseLibrary::buildFromStratimikos(strat);
512 
513  // to convert the void* like entry
514  Teuchos::ParameterList * temp = 0;
515 
516  // loop over all entries in parameter list
517  Teuchos::ParameterList::ConstIterator itr;
518  for(itr=pl.begin();itr!=pl.end();++itr) {
519  // get current entry
520  std::string label = itr->first;
521  Teuchos::ParameterList & list = itr->second.getValue(temp);
522 
523  // add to library
524  invLib->addInverse(label,list);
525  }
526 
527  return invLib;
528 }
529 
538 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos()
539 {
540  RCP<InverseLibrary> invLib = rcp(new InverseLibrary());
541 
542  // get default inveres in Stratimikos
543  RCP<Stratimikos::DefaultLinearSolverBuilder> strat = invLib->defaultBuilder_;
544  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat->getValidParameters()));
545  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
546  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
547 
548  Teuchos::ParameterList::ConstIterator itr;
549  Teuchos::ParameterList * temp = 0;
550 
551  // loop over all entries in solver list
552  for(itr=lst.begin();itr!=lst.end();++itr) {
553  // get current entry
554  std::string label = itr->first;
555  Teuchos::ParameterList & list = itr->second.getValue(temp);
556  list.set("Type",label);
557 
558  // add to library
559  invLib->addInverse(label,list);
560  }
561 
562  // loop over all entries in preconditioner list
563  for(itr=pft.begin();itr!=pft.end();++itr) {
564  // get current entry
565  std::string label = itr->first;
566  Teuchos::ParameterList & list = itr->second.getValue(temp);
567  list.set("Type",label);
568 
569  // add to library
570  invLib->addInverse(label,list);
571  }
572 
573  return invLib;
574 }
575 
585 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos(const Stratimikos::DefaultLinearSolverBuilder & strat)
586 {
587  RCP<InverseLibrary> invLib = rcp(new InverseLibrary());
588 
589  // get default inveres in Stratimikos
590  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat.getValidParameters()));
591  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
592  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
593 
594  Teuchos::ParameterList::ConstIterator itr;
595  Teuchos::ParameterList * temp = 0;
596 
597  // loop over all entries in solver list
598  for(itr=lst.begin();itr!=lst.end();++itr) {
599  // get current entry
600  std::string label = itr->first;
601  Teuchos::ParameterList & list = itr->second.getValue(temp);
602  list.set("Type",label);
603 
604  // add to library
605  invLib->addInverse(label,list);
606  }
607 
608  // loop over all entries in preconditioner list
609  for(itr=pft.begin();itr!=pft.end();++itr) {
610  // get current entry
611  std::string label = itr->first;
612  Teuchos::ParameterList & list = itr->second.getValue(temp);
613  list.set("Type",label);
614 
615  // add to library
616  invLib->addInverse(label,list);
617  }
618 
619  return invLib;
620 }
621 
631 Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos(const Teuchos::RCP<Stratimikos::DefaultLinearSolverBuilder> & strat)
632 {
633  RCP<InverseLibrary> invLib = rcp(new InverseLibrary(strat));
634 
635  // get default inveres in Stratimikos
636  RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat->getValidParameters()));
637  Teuchos::ParameterList lst(pl->sublist("Linear Solver Types"));
638  Teuchos::ParameterList pft(pl->sublist("Preconditioner Types"));
639 
640  Teuchos::ParameterList::ConstIterator itr;
641  Teuchos::ParameterList * temp = 0;
642 
643  // loop over all entries in solver list
644  for(itr=lst.begin();itr!=lst.end();++itr) {
645  // get current entry
646  std::string label = itr->first;
647  Teuchos::ParameterList & list = itr->second.getValue(temp);
648  list.set("Type",label);
649 
650  // add to library
651  invLib->addInverse(label,list);
652  }
653 
654  // loop over all entries in preconditioner list
655  for(itr=pft.begin();itr!=pft.end();++itr) {
656  // get current entry
657  std::string label = itr->first;
658  Teuchos::ParameterList & list = itr->second.getValue(temp);
659  list.set("Type",label);
660 
661  // add to library
662  invLib->addInverse(label,list);
663  }
664 
665  return invLib;
666 }
667 
668 } // 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).