Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_StratimikosFactory.cpp
1 #include "Teko_StratimikosFactory.hpp"
2 
3 #include "Teuchos_Time.hpp"
4 #include "Teuchos_AbstractFactoryStd.hpp"
5 
6 #include "Thyra_EpetraOperatorViewExtractorStd.hpp"
7 #include "Thyra_EpetraLinearOp.hpp"
8 #include "Thyra_DefaultPreconditioner.hpp"
9 
10 #include "Teko_InverseLibrary.hpp"
11 #include "Teko_Preconditioner.hpp"
12 #include "Teko_InverseFactoryOperator.hpp"
13 #include "Teko_Utilities.hpp"
14 #include "Teko_InverseLibrary.hpp"
15 #include "Teko_StridedEpetraOperator.hpp"
16 #include "Teko_BlockedEpetraOperator.hpp"
17 #include "Teko_ReorderedLinearOp.hpp"
18 
19 #include "EpetraExt_RowMatrixOut.h"
20 
21 namespace Teko {
22 
23 using Teuchos::RCP;
24 using Teuchos::ParameterList;
25 
26 // hide stuff
27 namespace {
28  // Simple preconditioner class that adds a counter
29  class StratimikosFactoryPreconditioner : public Thyra::DefaultPreconditioner<double>{
30  public:
31  StratimikosFactoryPreconditioner() : iter_(0) {}
32 
33  inline void incrIter() { iter_++; }
34  inline std::size_t getIter() { return iter_; }
35 
36  private:
37  StratimikosFactoryPreconditioner(const StratimikosFactoryPreconditioner &);
38 
39  std::size_t iter_;
40  };
41 
42  // factory used to initialize the Teko::StratimikosFactory
43  // user data
44  class TekoFactoryBuilder
45  : public Teuchos::AbstractFactory<Thyra::PreconditionerFactoryBase<double> > {
46  public:
47  TekoFactoryBuilder(const Teuchos::RCP<Teko::RequestHandler> & rh) : requestHandler_(rh) {}
48  Teuchos::RCP<Thyra::PreconditionerFactoryBase<double> > create() const
49  { return Teuchos::rcp(new StratimikosFactory(requestHandler_)); }
50 
51  private:
52  Teuchos::RCP<Teko::RequestHandler> requestHandler_;
53  };
54 }
55 
56 // Constructors/initializers/accessors
58  :epetraFwdOpViewExtractor_(Teuchos::rcp(new Thyra::EpetraOperatorViewExtractorStd()))
59 {}
60 
61 // Constructors/initializers/accessors
62 StratimikosFactory::StratimikosFactory(const Teuchos::RCP<Teko::RequestHandler> & rh)
63  :epetraFwdOpViewExtractor_(Teuchos::rcp(new Thyra::EpetraOperatorViewExtractorStd()))
64 {
66 }
67 
68 
69 // Overridden from PreconditionerFactoryBase
70 bool StratimikosFactory::isCompatible(const Thyra::LinearOpSourceBase<double> &fwdOpSrc) const
71 {
72  using Teuchos::outArg;
73 
74  TEUCHOS_ASSERT(false); // what you doing?
75 
76  Teuchos::RCP<const Epetra_Operator> epetraFwdOp;
77  Thyra::EOpTransp epetraFwdOpTransp;
78  Thyra::EApplyEpetraOpAs epetraFwdOpApplyAs;
79  Thyra::EAdjointEpetraOp epetraFwdOpAdjointSupport;
80  double epetraFwdOpScalar;
81 
82  // check to make sure this is an epetra CrsMatrix
83  Teuchos::RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc.getOp();
84  epetraFwdOpViewExtractor_->getEpetraOpView(
85  fwdOp,
86  outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
87  outArg(epetraFwdOpApplyAs),
88  outArg(epetraFwdOpAdjointSupport),
89  outArg(epetraFwdOpScalar));
90 
91  if( !dynamic_cast<const Epetra_CrsMatrix*>(&*epetraFwdOp) )
92  return false;
93 
94  return true;
95 }
96 
97 
98 bool StratimikosFactory::applySupportsConj(Thyra::EConj conj) const
99 {
100  return false;
101 }
102 
103 
105 {
106  return false; // See comment below
107 }
108 
109 
110 Teuchos::RCP<Thyra::PreconditionerBase<double> >
112 {
113  return Teuchos::rcp(new StratimikosFactoryPreconditioner());
114 }
115 
116 
118  const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > &fwdOpSrc,
119  Thyra::PreconditionerBase<double> *prec,
120  const Thyra::ESupportSolveUse supportSolveUse
121  ) const
122 {
123  Teuchos::RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp();
124 
125  if(epetraFwdOpViewExtractor_->isCompatible(*fwdOp))
126  initializePrec_Epetra(fwdOpSrc,prec,supportSolveUse);
127  else
128  initializePrec_Thyra(fwdOpSrc,prec,supportSolveUse);
129 }
130 
132  const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > &fwdOpSrc,
133  Thyra::PreconditionerBase<double> *prec,
134  const Thyra::ESupportSolveUse supportSolveUse
135  ) const
136 {
137  using Teuchos::RCP;
138  using Teuchos::rcp;
139  using Teuchos::rcp_dynamic_cast;
140  using Teuchos::implicit_cast;
141  using Thyra::LinearOpBase;
142 
143  Teuchos::Time totalTimer(""), timer("");
144  totalTimer.start(true);
145 
146  const RCP<Teuchos::FancyOStream> out = this->getOStream();
147  const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
148 
149  bool mediumVerbosity = (out.get() && implicit_cast<int>(verbLevel) > implicit_cast<int>(Teuchos::VERB_LOW));
150 
151  Teuchos::OSTab tab(out);
152  if(mediumVerbosity)
153  *out << "\nEntering Teko::StratimikosFactory::initializePrec_Thyra(...) ...\n";
154 
155  Teuchos::RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp();
156 
157  // Get the concrete preconditioner object
158  StratimikosFactoryPreconditioner & defaultPrec
159  = Teuchos::dyn_cast<StratimikosFactoryPreconditioner>(*prec);
160  Teuchos::RCP<LinearOpBase<double> > prec_Op = defaultPrec.getNonconstUnspecifiedPrecOp();
161 
162  // Permform initialization if needed
163  const bool startingOver = (prec_Op == Teuchos::null);
164  if(startingOver) {
165  // start over
166  invLib_ = Teuchos::null;
167  invFactory_ = Teuchos::null;
168 
169  if(mediumVerbosity)
170  *out << "\nCreating the initial Teko Operator object...\n";
171 
172  timer.start(true);
173 
174  // build library, and set request handler (user defined!)
175  invLib_ = Teko::InverseLibrary::buildFromParameterList(paramList_->sublist("Inverse Factory Library"));
176  invLib_->setRequestHandler(reqHandler_);
177 
178  // build preconditioner factory
179  invFactory_ = invLib_->getInverseFactory(paramList_->get<std::string>("Inverse Type"));
180 
181  timer.stop();
182  if(mediumVerbosity)
183  Teuchos::OSTab(out).o() <<"> Creation time = "<<timer.totalElapsedTime()<<" sec\n";
184  }
185 
186  if(mediumVerbosity)
187  *out << "\nComputing the preconditioner ...\n";
188 
189  // setup reordering if required
190  std::string reorderType = paramList_->get<std::string>("Reorder Type");
191  if(reorderType!="") {
192 
193  Teuchos::RCP<const Thyra::BlockedLinearOpBase<double> > blkFwdOp =
194  Teuchos::rcp_dynamic_cast<const Thyra::BlockedLinearOpBase<double> >(fwdOp,true);
195  RCP<const Teko::BlockReorderManager> brm = Teko::blockedReorderFromString(reorderType);
196  Teko::LinearOp blockedFwdOp = Teko::buildReorderedLinearOp(*brm,blkFwdOp);
197 
198  if(prec_Op==Teuchos::null) {
199  Teko::ModifiableLinearOp reorderedPrec = Teko::buildInverse(*invFactory_,blockedFwdOp);
200  prec_Op = Teuchos::rcp(new ReorderedLinearOp(brm,reorderedPrec));
201  }
202  else {
203  Teko::ModifiableLinearOp reorderedPrec = Teuchos::rcp_dynamic_cast<ReorderedLinearOp>(prec_Op,true)->getBlockedOp();
204  Teko::rebuildInverse(*invFactory_,blockedFwdOp,reorderedPrec);
205  }
206  }
207  else {
208  // no reordering required
209  if(prec_Op==Teuchos::null)
210  prec_Op = Teko::buildInverse(*invFactory_,fwdOp);
211  else
212  Teko::rebuildInverse(*invFactory_,fwdOp,prec_Op);
213  }
214 
215  // construct preconditioner
216  timer.stop();
217 
218  if(mediumVerbosity)
219  Teuchos::OSTab(out).o() <<"=> Preconditioner construction time = "<<timer.totalElapsedTime()<<" sec\n";
220 
221 
222  // Initialize the preconditioner
223  defaultPrec.initializeUnspecified( prec_Op);
224  defaultPrec.incrIter();
225  totalTimer.stop();
226 
227  if(out.get() && implicit_cast<int>(verbLevel) >= implicit_cast<int>(Teuchos::VERB_LOW))
228  *out << "\nTotal time in Teko::StratimikosFactory = "<<totalTimer.totalElapsedTime()<<" sec\n";
229  if(mediumVerbosity)
230  *out << "\nLeaving Teko::StratimikosFactory::initializePrec_Thyra(...) ...\n";
231 }
232 
234  const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > &fwdOpSrc,
235  Thyra::PreconditionerBase<double> *prec,
236  const Thyra::ESupportSolveUse supportSolveUse
237  ) const
238 {
239  using Teuchos::outArg;
240  using Teuchos::RCP;
241  using Teuchos::rcp;
242  using Teuchos::rcp_dynamic_cast;
243  using Teuchos::implicit_cast;
244 
245  Teuchos::Time totalTimer(""), timer("");
246  totalTimer.start(true);
247 
248  const RCP<Teuchos::FancyOStream> out = this->getOStream();
249  const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
250 
251  bool mediumVerbosity = (out.get() && implicit_cast<int>(verbLevel) > implicit_cast<int>(Teuchos::VERB_LOW));
252 
253  Teuchos::OSTab tab(out);
254  if(mediumVerbosity)
255  *out << "\nEntering Teko::StratimikosFactory::initializePrec_Epetra(...) ...\n";
256 
257  Teuchos::RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp();
258 #ifdef _DEBUG
259  TEUCHOS_TEST_FOR_EXCEPT(fwdOp.get()==NULL);
260  TEUCHOS_TEST_FOR_EXCEPT(prec==NULL);
261 #endif
262 
263  //
264  // Unwrap and get the forward Epetra_Operator object
265  //
266  Teuchos::RCP<const Epetra_Operator> epetraFwdOp;
267  Thyra::EOpTransp epetraFwdOpTransp;
268  Thyra::EApplyEpetraOpAs epetraFwdOpApplyAs;
269  Thyra::EAdjointEpetraOp epetraFwdOpAdjointSupport;
270  double epetraFwdOpScalar;
271  epetraFwdOpViewExtractor_->getEpetraOpView(
272  fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
273  outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
274  );
275  // Get the concrete preconditioner object
276  StratimikosFactoryPreconditioner & defaultPrec
277  = Teuchos::dyn_cast<StratimikosFactoryPreconditioner>(*prec);
278 
279  // Get the EpetraLinearOp object that is used to implement the preconditoner linear op
280  RCP<Thyra::EpetraLinearOp> epetra_precOp
281  = rcp_dynamic_cast<Thyra::EpetraLinearOp>(defaultPrec.getNonconstUnspecifiedPrecOp(),true);
282 
283  // Get the embedded ML_Epetra::MultiLevelPreconditioner object if it exists
284  Teuchos::RCP<Teko::Epetra::InverseFactoryOperator> teko_precOp;
285  if(epetra_precOp!=Teuchos::null)
286  teko_precOp = rcp_dynamic_cast<Teko::Epetra::InverseFactoryOperator>(epetra_precOp->epetra_op(),true);
287 
288  // Permform initialization if needed
289  const bool startingOver = (teko_precOp == Teuchos::null);
290  if(startingOver) {
291  // start over
292  invLib_ = Teuchos::null;
293  invFactory_ = Teuchos::null;
294  decomp_.clear();
295 
296  if(mediumVerbosity)
297  *out << "\nCreating the initial Teko::Epetra::InverseFactoryOperator object...\n";
298 
299  timer.start(true);
300 
301  std::stringstream ss;
302  ss << paramList_->get<std::string>("Strided Blocking");
303 
304  // figure out the decomposition requested by the string
305  while(not ss.eof()) {
306  int num=0;
307  ss >> num;
308 
309  TEUCHOS_ASSERT(num>0);
310 
311  decomp_.push_back(num);
312  }
313 
314  // build library, and set request handler (user defined!)
315  invLib_ = Teko::InverseLibrary::buildFromParameterList(paramList_->sublist("Inverse Factory Library"));
316  invLib_->setRequestHandler(reqHandler_);
317 
318  // build preconditioner factory
319  invFactory_ = invLib_->getInverseFactory(paramList_->get<std::string>("Inverse Type"));
320 
321  // Create the initial preconditioner: DO NOT compute it yet
322  teko_precOp = rcp( new Teko::Epetra::InverseFactoryOperator(invFactory_));
323 
324  timer.stop();
325  if(mediumVerbosity)
326  Teuchos::OSTab(out).o() <<"> Creation time = "<<timer.totalElapsedTime()<<" sec\n";
327  }
328 
329  if(mediumVerbosity)
330  *out << "\nComputing the preconditioner ...\n";
331 
332  // construct preconditioner
333  {
334  bool writeBlockOps = paramList_->get<bool>("Write Block Operator");
335  timer.start(true);
336  teko_precOp->initInverse();
337 
338  if(decomp_.size()==1) {
339  teko_precOp->rebuildInverseOperator(epetraFwdOp);
340 
341  // write out to disk
342  if(writeBlockOps) {
343  std::stringstream ss;
344  ss << "block-" << defaultPrec.getIter() << "_00.mm";
345  EpetraExt::RowMatrixToMatrixMarketFile(ss.str().c_str(),*rcp_dynamic_cast<const Epetra_CrsMatrix>(epetraFwdOp));
346  }
347  }
348  else {
349  Teuchos::RCP<Epetra_Operator> wrappedFwdOp
350  = buildWrappedEpetraOperator(epetraFwdOp,teko_precOp->getNonconstForwardOp(),*out);
351 
352  // write out to disk
353  if(writeBlockOps) {
354  std::stringstream ss;
355  ss << "block-" << defaultPrec.getIter();
356  // Teuchos::RCP<Teko::Epetra::StridedEpetraOperator> stridedJac
357  // = Teuchos::rcp_dynamic_cast<Teko::Epetra::StridedEpetraOperator>(wrappedFwdOp);
358  Teuchos::RCP<Teko::Epetra::BlockedEpetraOperator> stridedJac
359  = Teuchos::rcp_dynamic_cast<Teko::Epetra::BlockedEpetraOperator>(wrappedFwdOp);
360  if(stridedJac!=Teuchos::null) {
361  // write out blocks of strided operator
362  stridedJac->WriteBlocks(ss.str());
363  }
364  else TEUCHOS_ASSERT(false);
365  }
366 
367  teko_precOp->rebuildInverseOperator(wrappedFwdOp);
368  }
369 
370  timer.stop();
371  }
372 
373  if(mediumVerbosity)
374  Teuchos::OSTab(out).o() <<"=> Preconditioner construction time = "<<timer.totalElapsedTime()<<" sec\n";
375 
376  // Initialize the output EpetraLinearOp
377  if(startingOver) {
378  epetra_precOp = rcp(new Thyra::EpetraLinearOp);
379  }
380  epetra_precOp->initialize(teko_precOp,epetraFwdOpTransp
381  ,Thyra::EPETRA_OP_APPLY_APPLY_INVERSE
382  ,Thyra::EPETRA_OP_ADJOINT_UNSUPPORTED);
383 
384  // Initialize the preconditioner
385  defaultPrec.initializeUnspecified( Teuchos::rcp_implicit_cast<LinearOpBase<double> >(epetra_precOp));
386  defaultPrec.incrIter();
387  totalTimer.stop();
388 
389  if(out.get() && implicit_cast<int>(verbLevel) >= implicit_cast<int>(Teuchos::VERB_LOW))
390  *out << "\nTotal time in Teko::StratimikosFactory = "<<totalTimer.totalElapsedTime()<<" sec\n";
391  if(mediumVerbosity)
392  *out << "\nLeaving Teko::StratimikosFactory::initializePrec(...) ...\n";
393 }
394 
395 
397  Thyra::PreconditionerBase<double> *prec,
398  Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > *fwdOp,
399  Thyra::ESupportSolveUse *supportSolveUse
400  ) const
401 {
402  TEUCHOS_TEST_FOR_EXCEPT(true);
403 }
404 
405 
406 // Overridden from ParameterListAcceptor
407 
408 
410  Teuchos::RCP<Teuchos::ParameterList> const& paramList
411  )
412 {
413  TEUCHOS_TEST_FOR_EXCEPT(paramList.get()==NULL);
414 
415  paramList->validateParametersAndSetDefaults(*this->getValidParameters(),0);
416  paramList_ = paramList;
417 
418 }
419 
420 
421 Teuchos::RCP<Teuchos::ParameterList>
423 {
424  return paramList_;
425 }
426 
427 
428 Teuchos::RCP<Teuchos::ParameterList>
430 {
431  Teuchos::RCP<ParameterList> _paramList = paramList_;
432  paramList_ = Teuchos::null;
433  return _paramList;
434 }
435 
436 
437 Teuchos::RCP<const Teuchos::ParameterList>
439 {
440  return paramList_;
441 }
442 
443 
444 Teuchos::RCP<const Teuchos::ParameterList>
446 {
447 
448  using Teuchos::rcp;
449  using Teuchos::tuple;
450  using Teuchos::implicit_cast;
451  using Teuchos::rcp_implicit_cast;
452  typedef Teuchos::ParameterEntryValidator PEV;
453 
454  static RCP<const ParameterList> validPL;
455 
456  if(is_null(validPL)) {
457 
458  Teuchos::RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList());
459 
460  pl->set("Test Block Operator",false,
461  "If Stratiikos/Teko is used to break an operator into its parts,\n"
462  "then setting this parameter to true will compare applications of the\n"
463  "segregated operator to the original operator.");
464  pl->set("Write Block Operator",false,
465  "Write out the segregated operator to disk with the name \"block-?_xx\"");
466  pl->set("Strided Blocking","1",
467  "Assuming that the user wants Strided blocking, break the operating into\n"
468  "blocks. The syntax can be thought to be associated with the solution\n"
469  "vector. For example if your variables are [u v w p T], and we want [u v w]\n"
470  "blocked together, and p and T seperate then the relevant string is \"3 1 1\".\n"
471  "Meaning put the first 3 unknowns per node together and sperate the v and w\n"
472  "components.");
473  pl->set("Reorder Type","",
474  "This specifies how the blocks are reordered for use in the preconditioner.\n"
475  "For example, assume the linear system is generated from 3D Navier-Stokes\n"
476  "with an energy equation, yielding the unknowns [u v w p T]. If the\n"
477  "\"Strided Blocking\" string is \"3 1 1\", then setting this parameter to\n"
478  "\"[2 [0 1]]\" will reorder the blocked operator so its nested with the\n"
479  "velocity and pressure forming an inner two-by-two block, and then the\n"
480  "temperature unknowns forming a two-by-two system with the velocity-pressure\n"
481  "block.");
482  pl->set("Inverse Type","Amesos",
483  "The type of inverse operator the user wants. This can be one of the defaults\n"
484  "from Stratimikos, or a Teko preconditioner defined in the\n"
485  "\"Inverse Factory Library\".");
486  pl->sublist("Inverse Factory Library",false,"Definition of Teko preconditioners.");
487 
488  validPL = pl;
489  }
490 
491  return validPL;
492 }
493 
497 Teuchos::RCP<Epetra_Operator> StratimikosFactory::buildWrappedEpetraOperator(
498  const Teuchos::RCP<const Epetra_Operator> & Jac,
499  const Teuchos::RCP<Epetra_Operator> & wrapInput,
500  std::ostream & out
501  ) const
502 {
503  Teuchos::RCP<Epetra_Operator> wrappedOp = wrapInput;
504 
505 // // initialize jacobian
506 // if(wrappedOp==Teuchos::null)
507 // {
508 // wrappedOp = Teuchos::rcp(new Teko::Epetra::StridedEpetraOperator(decomp_,Jac));
509 //
510 // // reorder the blocks if requested
511 // std::string reorderType = paramList_->get<std::string>("Reorder Type");
512 // if(reorderType!="") {
513 // RCP<const Teko::BlockReorderManager> brm = Teko::blockedReorderFromString(reorderType);
514 //
515 // // out << "Teko: Reordering = " << brm->toString() << std::endl;
516 // Teuchos::rcp_dynamic_cast<Teko::Epetra::StridedEpetraOperator>(wrappedOp)->Reorder(*brm);
517 // }
518 // }
519 // else {
520 // Teuchos::rcp_dynamic_cast<Teko::Epetra::StridedEpetraOperator>(wrappedOp)->RebuildOps();
521 // }
522 //
523 // // test blocked operator for correctness
524 // if(paramList_->get<bool>("Test Block Operator")) {
525 // bool result
526 // = Teuchos::rcp_dynamic_cast<Teko::Epetra::StridedEpetraOperator>(wrappedOp)->testAgainstFullOperator(600,1e-14);
527 //
528 // out << "Teko: Tested operator correctness: " << (result ? "passed" : "FAILED!") << std::endl;
529 // }
530 
531  // initialize jacobian
532  if(wrappedOp==Teuchos::null)
533  {
534  // build strided vector
535  std::vector<std::vector<int> > vars;
536  buildStridedVectors(*Jac,decomp_,vars);
537  wrappedOp = Teuchos::rcp(new Teko::Epetra::BlockedEpetraOperator(vars,Jac));
538 
539  // reorder the blocks if requested
540  std::string reorderType = paramList_->get<std::string>("Reorder Type");
541  if(reorderType!="") {
542  RCP<const Teko::BlockReorderManager> brm = Teko::blockedReorderFromString(reorderType);
543 
544  // out << "Teko: Reordering = " << brm->toString() << std::endl;
545  Teuchos::rcp_dynamic_cast<Teko::Epetra::BlockedEpetraOperator>(wrappedOp)->Reorder(*brm);
546  }
547  }
548  else {
549  Teuchos::rcp_dynamic_cast<Teko::Epetra::BlockedEpetraOperator>(wrappedOp)->RebuildOps();
550  }
551 
552  // test blocked operator for correctness
553  if(paramList_->get<bool>("Test Block Operator")) {
554  bool result
555  = Teuchos::rcp_dynamic_cast<Teko::Epetra::BlockedEpetraOperator>(wrappedOp)->testAgainstFullOperator(600,1e-14);
556 
557  out << "Teko: Tested operator correctness: " << (result ? "passed" : "FAILED!") << std::endl;
558  }
559 
560  return wrappedOp;
561 }
562 
564 {
565  std::ostringstream oss;
566  oss << "Teko::StratimikosFactory";
567  return oss.str();
568 }
569 
570 void StratimikosFactory::buildStridedVectors(const Epetra_Operator & Jac,
571  const std::vector<int> & decomp,
572  std::vector<std::vector<int> > & vars) const
573 {
574  const Epetra_Map & rangeMap = Jac.OperatorRangeMap();
575 
576  // compute total number of variables
577  int numVars = 0;
578  for(std::size_t i=0;i<decomp.size();i++)
579  numVars += decomp[i];
580 
581  // verify that the decomposition is appropriate for this matrix
582  TEUCHOS_ASSERT((rangeMap.NumMyElements() % numVars)==0);
583  TEUCHOS_ASSERT((rangeMap.NumGlobalElements() % numVars)==0);
584 
585  int * globalIds = rangeMap.MyGlobalElements();
586 
587  vars.resize(decomp.size());
588  for(int i=0;i<rangeMap.NumMyElements();) {
589 
590  // for each "node" copy global ids to vectors
591  for(std::size_t d=0;d<decomp.size();d++) {
592  // for this variable copy global ids to variable arrays
593  int current = decomp[d];
594  for(int v=0;v<current;v++,i++)
595  vars[d].push_back(globalIds[i]);
596  }
597  }
598 }
599 
600 void addTekoToStratimikosBuilder(Stratimikos::DefaultLinearSolverBuilder & builder,
601  const std::string & stratName)
602 {
603  TEUCHOS_TEST_FOR_EXCEPTION(builder.getValidParameters()->sublist("Preconditioner Types").isParameter(stratName),std::logic_error,
604  "Teko::addTekoToStratimikosBuilder cannot add \"" + stratName +"\" because it is already included in builder!");
605 
606  // use default constructor to add Teko::StratimikosFactory
607  builder.setPreconditioningStrategyFactory(
608  Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Teko::StratimikosFactory>(),
609  stratName);
610 }
611 
612 void addTekoToStratimikosBuilder(Stratimikos::DefaultLinearSolverBuilder & builder,
613  const Teuchos::RCP<Teko::RequestHandler> & rh,
614  const std::string & stratName)
615 {
616  TEUCHOS_TEST_FOR_EXCEPTION(builder.getValidParameters()->sublist("Preconditioner Types").isParameter(stratName),std::logic_error,
617  "Teko::addTekoToStratimikosBuilder cannot add \"" + stratName +"\" because it is already included in builder!");
618 
619  // build an instance of a Teuchos::AbsractFactory<Thyra::PFB> so request handler is passed onto
620  // the resulting StratimikosFactory
621  Teuchos::RCP<TekoFactoryBuilder> tekoFactoryBuilder = Teuchos::rcp(new TekoFactoryBuilder(rh));
622  builder.setPreconditioningStrategyFactory(tekoFactoryBuilder,stratName);
623 }
624 
625 } // namespace Thyra
bool applySupportsConj(Thyra::EConj conj) const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void rebuildInverse(const InverseFactory &factory, const LinearOp &A, InverseLinearOp &invA)
void setRequestHandler(const Teuchos::RCP< Teko::RequestHandler > &rh)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void initializePrec(const Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > &fwdOp, Thyra::PreconditionerBase< double > *prec, const Thyra::ESupportSolveUse supportSolveUse) const
void uninitializePrec(Thyra::PreconditionerBase< double > *prec, Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > *fwdOp, Thyra::ESupportSolveUse *supportSolveUse) const
bool applyTransposeSupportsConj(Thyra::EConj conj) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void initializePrec_Thyra(const Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > &fwdOp, Thyra::PreconditionerBase< double > *prec, const Thyra::ESupportSolveUse supportSolveUse) const
A single Epetra wrapper for all operators constructed from an inverse operator.
bool isCompatible(const Thyra::LinearOpSourceBase< double > &fwdOp) const
Teuchos::RCP< Thyra::PreconditionerBase< double > > createPrec() const
InverseLinearOp buildInverse(const InverseFactory &factory, const LinearOp &A)
Build an inverse operator using a factory and a linear operator.
Teuchos::RCP< const BlockReorderManager > blockedReorderFromString(std::string &reorder)
Convert a string to a block reorder manager object.
Concrete preconditioner factory subclass based on ML.
This class takes a blocked linear op and represents it in a flattened form.
void initializePrec_Epetra(const Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > &fwdOp, Thyra::PreconditionerBase< double > *prec, const Thyra::ESupportSolveUse supportSolveUse) const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Tear about a user specified Epetra_Operator (CrsMatrix) using a vector of vectors of GIDs for each bl...
virtual void WriteBlocks(const std::string &prefix) const