Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
LinearSolver_def.hpp
1#ifndef LinearSolver_DEF_hpp
2#define LinearSolver_DEF_hpp
3
4#include "feddlib/problems/abstract/TimeProblem.hpp"
5#include "feddlib/problems/Solver/Preconditioner.hpp"
6#include "feddlib/core/LinearAlgebra/BlockMatrix.hpp"
7
16namespace FEDD {
17
18
19template<class SC,class LO,class GO,class NO>
20LinearSolver<SC,LO,GO,NO>::LinearSolver(){}
21
22
23template<class SC,class LO,class GO,class NO>
24LinearSolver<SC,LO,GO,NO>::~LinearSolver(){}
25
26template<class SC,class LO,class GO,class NO>
27int LinearSolver<SC,LO,GO,NO>::solve(Problem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ){
28
29 int its=0;
30 if (!type.compare("Monolithic") || !type.compare("MonolithicConstPrec"))
31 its = solveMonolithic( problem, rhs, type );
32 else if (!type.compare("Teko")){
33#ifdef FEDD_HAVE_TEKO
34// its = solveTeko( problem, rhs );
35 its = solveBlock( problem, rhs, "Teko" );
36#else
37 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "Teko not found! Build Trilinos with Teko.");
38#endif
39 }
40 else if (type=="Diagonal" || type=="Triangular" || type=="PCD" || type=="LSC"){
41 its = solveBlock( problem, rhs, type );
42 }
43 else
44 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "Unkown solver type.");
45
46 return its;
47}
48
49template<class SC,class LO,class GO,class NO>
50int LinearSolver<SC,LO,GO,NO>::solve(TimeProblem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ){
51
52 int its=0;
53
54 if (!type.compare("Monolithic"))
55 its = solveMonolithic( problem, rhs );
56 else if (!type.compare("Teko")){
57#ifdef FEDD_HAVE_TEKO
58// its = solveTeko( problem, rhs );
59 its = solveBlock( problem, rhs, "Teko" );
60#else
61 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "Teko not found! Build Trilinos with Teko.");
62#endif
63 }
64 else if(!type.compare("FaCSI") || type == "FaCSI-Teko" || type == "FaCSI-Blck" )
65 its = solveBlock( problem, rhs, type );
66 else if (type=="Diagonal" || type=="Triangular" || type=="PCD" || type=="LSC")
67 its = solveBlock( problem, rhs, type );
68 else
69 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, "Unkown solver type.");
70
71 return its;
72}
73
74template<class SC,class LO,class GO,class NO>
75int LinearSolver<SC,LO,GO,NO>::solveMonolithic(Problem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ){
76
77 bool verbose(problem->getVerbose());
78 int its=0;
79 if (problem->getParameterList()->get("Zero Initial Guess",true)) {
80 problem->getSolution()->putScalar(0.);
81 }
82 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
83
84 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
85 if (rhs.is_null())
86 thyraB = problem->getRhs()->getThyraMultiVectorConst();
87 else
88 thyraB = rhs->getThyraMultiVectorConst();
89
90 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
91
92 pListThyraSolver->setParameters( problem->getParameterList()->sublist("ThyraPreconditioner") );
93
94 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
95 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
96
97 // Add the possibility to completly skip the preconditioner rebuild after a specific number of Newton steps
98 bool iterativeSolve = !pListThyraSolver->get("Linear Solver Type", "Belos").compare("Belos");
99 if (iterativeSolve && (type != "MonolithicConstPrec" || problem->getPreconditioner()->getThyraPrec().is_null()))
100 { // Analogous to NOX as Nonlinear Solver in NonLinearProblem_def.hpp, we want to have the option to reuse the Preconditioner after the first X Newtonsteps
101 // We have the option to reuse the preconditioner after the first X Newtonsteps
102 int newtonLimit = problem->getParameterList()->sublist("Parameter").get("newtonLimit",2);
103 if(problem->getNonlinearIterationStep() < newtonLimit || problem->getParameterList()->sublist("Parameter").get("Rebuild Preconditioner every Newton Iteration",true) )
104 {
105 problem->setupPreconditioner("Monolithic");
106 }
107 else{ // Reusing preconditioner
108 if (verbose)
109 std::cout << "LinearSolver<SC,LO,GO,NO>::solveMonolithic(Problem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ):: Skipping preconditioner reconstruction" << std::endl;
110 }
111 }
112
113 if (!pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").get("Level Combination","Additive").compare("Multiplicative")) {
114 pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",true);
115
116 Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
117 Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
118 pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",false);
119 }
120
121 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
122
123 lowsFactory->setOStream(out);
124 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
125
126 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
127// Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = linearOpWithSolve(*lowsFactory, problem->getSystem()->getThyraLinOp());
128 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinOp();
129 if ( iterativeSolve ) {
130 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
131 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
132 }
133 else{
134 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
135 }
136
137 {
138 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
139 if (verbose)
140 std::cout << status << std::endl;
141 if ( !pListThyraSolver->get("Linear Solver Type","Belos").compare("Belos") )
142 its = status.extraParameters->get("Belos/Iteration Count",0);
143 else
144 its = 0;
145
146 problem->getSolution()->fromThyraMultiVector(thyraX);
147 }
148
149 return its;
150}
151
152template<class SC,class LO,class GO,class NO>
153int LinearSolver<SC,LO,GO,NO>::solveMonolithic(TimeProblem_Type* timeProblem, BlockMultiVectorPtr_Type rhs){
154
155
156 bool verbose(timeProblem->getVerbose());
157 int its=0;
158 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
159
160 if (problem->getParameterList()->get("Zero Initial Guess",true)) {
161 problem->getSolution()->putScalar(0.);
162 }
163
164 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
165
166 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
167 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
168
169 if (rhs.is_null())
170 thyraB = problem->getRhs()->getThyraMultiVectorConst();
171 else
172 thyraB = rhs->getThyraMultiVectorConst();
173
174 pListThyraSolver->setParameters( problem->getParameterList()->sublist("ThyraPreconditioner") );
175
176 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
177 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
178
179
180 bool iterativeSolve = !pListThyraSolver->get("Linear Solver Type", "Belos").compare("Belos");
181 if (iterativeSolve)
182 problem->setupPreconditioner( "Monolithic" );
183
184 if (iterativeSolve && !pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").get("Level Combination","Additive").compare("Multiplicative")) {
185 pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",true);
186
187 Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
188 Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
189 pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",false);
190 }
191
192 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
193
194 lowsFactory->setOStream(out);
195 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
196
197 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
198
199 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinOp();
200
201 if (iterativeSolve) {
202 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
203 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
204 }
205 else{
206 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
207 }
208 {
209 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
210 if (verbose)
211 std::cout << status << std::endl;
212 problem->getSolution()->fromThyraMultiVector(thyraX);
213
214 if (iterativeSolve){
215 its = status.extraParameters->get("Belos/Iteration Count",0);
216 double achievedTol = status.extraParameters->get("Belos/Achieved Tolerance",-1.);
217 }
218 else
219 its = 0;
220 }
221 return its;
222}
223
224template<class SC,class LO,class GO,class NO>
225int LinearSolver<SC,LO,GO,NO>::solveBlock(Problem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ){
226 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
227 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
228
229 int rank = problem->getComm()->getRank();
230 bool verbose(problem->getVerbose());
231 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
232
233 int its=0;
234
235 if (problem->getParameterList()->get("Zero Initial Guess",true)) {
236 problem->getSolution()->putScalar(0.);
237 }
238
239
240 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
241
242 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
243 if ( rhs.is_null() )
244 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
245 else
246 thyraRHS = rhs->getProdThyraMultiVector();
247
248 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
249
250 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
251 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
252
253 problem->setupPreconditioner( type );
254
255 lowsFactory->setOStream(out);
256 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
257
258 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
259
260 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
261
262// BlockMatrixPtr_Type system = problem->getSystem();
263// ThyraLinOpBlockConstPtr_Type thyraMatrixBlocks = system->getThyraLinBlockOp();
264// ThyraLinOpBlockPtr_Type thyraMatrixBlocksNonConst = Teuchos::rcp_const_cast<ThyraLinOpBlock_Type>( thyraMatrixBlocks );
265//
266// for (int i=0; i<system->size(); i++) {
267// for (int j=0; j<system->size(); j++) {
268// if ( !thyraMatrixBlocks->blockExists(i,j) ) {
269// ZeroOpPtr_Type zeroOp =
270// Teuchos::rcp( new ZeroOp_Type( thyraRHS->getMultiVectorBlock(i)->range(),
271// thyraX->getMultiVectorBlock(j)->range() ) ); //(range , domain)
272// thyraMatrixBlocksNonConst->getNonconstBlock(i,j) = zeroOp;
273// }
274// }
275// }
276
277
278
279// BlockMatrixPtr_Type system = problem->getSystem();
280// for (int i=0; i<system->size(); i++) {
281// for (int j=0; j<system->size(); j++) {
282// if (!system->blockExists(1,1)){
283// MatrixPtr_Type dummy = Teuchos::rcp( new Matrix_Type( system->getBlock(i,j)->getMap(), 0 ) );
284// dummy->fillComplete( problem->getSolution()->getBlock( j )->getMap(), problem->getRhs()->getBlock( i )->getMap() ); //(domain, range)
285// system->addBlock( dummy, i, j );
286// }
287// }
288// }
289
290 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinBlockOp();
291 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
292 {
293
294 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
295 if (verbose)
296 std::cout << status << std::endl;
297
298 its = status.extraParameters->get("Belos/Iteration Count",0);
299
300 problem->getSolution()->fromThyraProdMultiVector( thyraX );
301 }
302
303 return its;
304}
305
306template<class SC,class LO,class GO,class NO>
307int LinearSolver<SC,LO,GO,NO>::solveBlock(TimeProblem_Type* timeProblem, BlockMultiVectorPtr_Type rhs, std::string type ){
308 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
309 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
310
311 int rank = timeProblem->getComm()->getRank();
312 bool verbose(timeProblem->getVerbose());
313 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
314
315 int its=0;
316
317 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
318 if (problem->getParameterList()->get("Zero Initial Guess",true)) {
319 problem->getSolution()->putScalar(0.);
320 }
321
322 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
323
324 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
325 if ( rhs.is_null() )
326 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
327 else
328 thyraRHS = rhs->getProdThyraMultiVector();
329
330 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
331
332
333 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
334 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
335
336 problem->setupPreconditioner( type );
337
338 lowsFactory->setOStream(out);
339 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
340
341 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
342
343 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
344
345// BlockMatrixPtr_Type system = timeProblem->getSystemCombined();
346// ThyraLinOpBlockConstPtr_Type thyraMatrixBlocks = system->getThyraLinBlockOp();
347// ThyraLinOpBlockPtr_Type thyraMatrixBlocksNonConst = Teuchos::rcp_const_cast<ThyraLinOpBlock_Type>( thyraMatrixBlocks );
348//
349// for (int i=0; i<system->size(); i++) {
350// for (int j=0; j<system->size(); j++) {
351// if ( !thyraMatrixBlocks->blockExists(i,j) ) {
352// ZeroOpPtr_Type zeroOp =
353// Teuchos::rcp( new ZeroOp_Type( thyraRHS->getMultiVectorBlock(i)->range(),
354// thyraX->getMultiVectorBlock(j)->range() ) ); //(range , domain)
355// thyraMatrixBlocksNonConst->getNonconstBlock(i,j) = zeroOp;
356// }
357// }
358// }
359
360 BlockMatrixPtr_Type system = timeProblem->getSystemCombined();
361// for (int i=0; i<system->size(); i++) {
362// for (int j=0; j<system->size(); j++) {
363// if (!system->blockExists(1,1)){
364// MatrixPtr_Type dummy;
365// dummy.reset( new Matrix_Type( system->getBlock(i,j)->getMap(), 0 ) );
366// dummy->fillComplete( problem->getSolution()->getBlock( j )->getMap(), problem->getRhs()->getBlock( i )->getMap() ); //(domain, range)
367// system->addBlock( dummy, i, j );
368// }
369// }
370// }
371
372 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinBlockOp();
373// ThyraLinOpBlockConstPtr_Type thyraMatrixBlock = timeProblem->getSystemCombined()->getThyraLinBlockOp();
374 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
375 {
376
377 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
378 if (verbose)
379 std::cout << status << std::endl;
380
381 its = status.extraParameters->get("Belos/Iteration Count",0);
382
383 problem->getSolution()->fromThyraProdMultiVector( thyraX );
384 }
385
386 return its;
387}
388
389// #ifdef FEDD_HAVE_TEKO
390// template<class SC,class LO,class GO,class NO>
391// int LinearSolver<SC,LO,GO,NO>::solveTeko(Problem_Type* problem, BlockMultiVectorPtr_Type rhs ){
392
393// Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
394
395// bool verbose(problem->getVerbose());
396// int its=0;
397// if (problem->getParameterList()->get("Zero Initial Guess",true)) {
398// problem->getSolution()->putScalar(0.);
399// }
400// // typedef Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > Teko::BlockedMultiVector
401// // convert them to teko compatible sub vectors
402// Teko::MultiVector x0_th = problem->getSolution()->getBlockNonConst(0)->getThyraMultiVector();
403// Teko::MultiVector x1_th = problem->getSolution()->getBlockNonConst(1)->getThyraMultiVector();
404
405// Teko::MultiVector b0_th;
406// Teko::MultiVector b1_th;
407// if (rhs.is_null()){
408// b0_th = problem->getRhs()->getBlockNonConst(0)->getThyraMultiVector();
409// b1_th = problem->getRhs()->getBlockNonConst(1)->getThyraMultiVector();
410// }
411// else{
412// b0_th = rhs->getBlockNonConst(0)->getThyraMultiVector();
413// b1_th = rhs->getBlockNonConst(1)->getThyraMultiVector();
414// }
415
416// std::vector<Teko::MultiVector> x_vec; x_vec.push_back(x0_th); x_vec.push_back(x1_th);
417// std::vector<Teko::MultiVector> b_vec; b_vec.push_back(b0_th); b_vec.push_back(b1_th);
418
419// Teko::MultiVector x = Teko::buildBlockedMultiVector(x_vec); // these will be used in the Teko solve
420// Teko::MultiVector b = Teko::buildBlockedMultiVector(b_vec);
421
422// ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
423
424// // pListThyraSolver->setParameters( problem->getParameterList()->sublist("ThyraPreconditioner") );
425
426// problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
427// Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
428
429// problem->setupPreconditioner( "Teko" );
430
431// // if (!pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").get("Level Combination","Additive").compare("Multiplicative")) {
432// // pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",true);
433// //
434// // Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
435// // Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
436// // pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",false);
437// // }
438
439
440// lowsFactory->setOStream(out);
441// // lowsFactory->setVerbLevel(Teuchos::VERB_EXTREME);
442
443// Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
444
445// ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
446
447// ThyraLinOpConstPtr_Type thyraMatrix = problem->getPreconditioner()->getTekoOp();
448
449// Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
450
451// {
452// Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *b, x.ptr());
453// if (verbose)
454// std::cout << status << std::endl;
455
456// its = status.extraParameters->get("Belos/Iteration Count",0);
457// Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > xBlocked = Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase< double > >( x );
458// problem->getSolution()->getBlockNonConst(0)->fromThyraMultiVector( xBlocked->getNonconstMultiVectorBlock( 0 ) );
459// problem->getSolution()->getBlockNonConst(1)->fromThyraMultiVector( xBlocked->getNonconstMultiVectorBlock( 1 ) );
460// }
461
462// return its;
463// }
464
465// template<class SC,class LO,class GO,class NO>
466// int LinearSolver<SC,LO,GO,NO>::solveTeko(TimeProblem_Type* timeProblem, BlockMultiVectorPtr_Type rhs ){
467
468// bool verbose(timeProblem->getVerbose());
469// int its=0;
470
471// ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
472// if (problem->getParameterList()->get("Zero Initial Guess",true)) {
473// problem->getSolution()->putScalar(0.);
474// }
475// // typedef Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > Teko::BlockedMultiVector
476// // convert them to teko compatible sub vectors
477// Teko::MultiVector x0_th = problem->getSolution()->getBlockNonConst(0)->getThyraMultiVector();
478// Teko::MultiVector x1_th = problem->getSolution()->getBlockNonConst(1)->getThyraMultiVector();
479
480// Teko::MultiVector b0_th;
481// Teko::MultiVector b1_th;
482// if (rhs.is_null()){
483// b0_th = problem->getRhs()->getBlockNonConst(0)->getThyraMultiVector();
484// b1_th = problem->getRhs()->getBlockNonConst(1)->getThyraMultiVector();
485// }
486// else{
487// b0_th = rhs->getBlockNonConst(0)->getThyraMultiVector();
488// b1_th = rhs->getBlockNonConst(1)->getThyraMultiVector();
489// }
490
491// std::vector<Teko::MultiVector> x_vec; x_vec.push_back(x0_th); x_vec.push_back(x1_th);
492// std::vector<Teko::MultiVector> b_vec; b_vec.push_back(b0_th); b_vec.push_back(b1_th);
493
494// Teko::MultiVector x = Teko::buildBlockedMultiVector(x_vec); // these will be used in the Teko solve
495// Teko::MultiVector b = Teko::buildBlockedMultiVector(b_vec);
496
497// ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(), "ThyraSolver" );
498
499// // pListThyraSolver->setParameters( problem->getParameterList()->sublist("ThyraPreconditioner") );
500
501// problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
502// Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy("");
503
504// problem->setupPreconditioner( "Teko" );
505
506// // if (!pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").get("Level Combination","Additive").compare("Multiplicative")) {
507// // pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",true);
508// //
509// // Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
510// // Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
511// // pListThyraSolver->sublist("Preconditioner Types").sublist("FROSch").set("Only apply coarse",false);
512// // }
513
514// Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
515
516// lowsFactory->setOStream(out);
517// lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
518
519// Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
520
521// ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
522
523// ThyraLinOpConstPtr_Type thyraMatrix = problem->getPreconditioner()->getTekoOp();
524
525// Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
526
527// {
528// Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *b, x.ptr());
529// if (verbose)
530// std::cout << status << std::endl;
531
532// its = status.extraParameters->get("Belos/Iteration Count",0);
533// Teuchos::RCP< Thyra::ProductMultiVectorBase< double > > xBlocked = Teuchos::rcp_dynamic_cast<Thyra::ProductMultiVectorBase< double > >( x );
534// problem->getSolution()->getBlockNonConst(0)->fromThyraMultiVector( xBlocked->getNonconstMultiVectorBlock( 0 ) );
535// problem->getSolution()->getBlockNonConst(1)->fromThyraMultiVector( xBlocked->getNonconstMultiVectorBlock( 1 ) );
536// }
537
538// return its;
539// }
540// #endif
541}
542#endif
int solveMonolithic(Problem_Type *problem, BlockMultiVectorPtr_Type rhs, std::string type)
Solve linear/linearized problem monolithicly.
Definition LinearSolver_def.hpp:75
int solveBlock(Problem_Type *problem, BlockMultiVectorPtr_Type rhs, std::string precType)
In case of a block system, solve block is called. It works also for teko.
Definition LinearSolver_def.hpp:225
int solve(Problem_Type *problem, BlockMultiVectorPtr_Type rhs, std::string type="Monolithic")
Call to solve a linear/linearized problem with right-hand side rhs. Depending on 'type' solveMonolith...
Definition LinearSolver_def.hpp:27
virtual int getNonlinearIterationStep() const
Definition Problem_decl.hpp:110
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36