77 bool verbose(problem->getVerbose());
79 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
80 problem->getSolution()->putScalar(0.);
82 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
84 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
86 thyraB = problem->getRhs()->getThyraMultiVectorConst();
88 thyraB = rhs->getThyraMultiVectorConst();
90 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
92 pListThyraSolver->setParameters( problem->getParameterList()->sublist(
"ThyraPreconditioner") );
94 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
95 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
98 bool iterativeSolve = !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos");
99 if (iterativeSolve && (type !=
"MonolithicConstPrec" || problem->getPreconditioner()->getThyraPrec().is_null()))
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) )
105 problem->setupPreconditioner(
"Monolithic");
109 std::cout <<
"LinearSolver<SC,LO,GO,NO>::solveMonolithic(Problem_Type* problem, BlockMultiVectorPtr_Type rhs, std::string type ):: Skipping preconditioner reconstruction" << std::endl;
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);
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);
121 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
123 lowsFactory->setOStream(out);
124 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
126 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
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());
134 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
138 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
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);
146 problem->getSolution()->fromThyraMultiVector(thyraX);
156 bool verbose(timeProblem->getVerbose());
158 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
160 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
161 problem->getSolution()->putScalar(0.);
164 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
166 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
167 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
170 thyraB = problem->getRhs()->getThyraMultiVectorConst();
172 thyraB = rhs->getThyraMultiVectorConst();
174 pListThyraSolver->setParameters( problem->getParameterList()->sublist(
"ThyraPreconditioner") );
176 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
177 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
180 bool iterativeSolve = !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos");
182 problem->setupPreconditioner(
"Monolithic" );
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);
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);
192 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
194 lowsFactory->setOStream(out);
195 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
197 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
199 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinOp();
201 if (iterativeSolve) {
202 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
203 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
206 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
209 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
211 std::cout << status << std::endl;
212 problem->getSolution()->fromThyraMultiVector(thyraX);
215 its = status.extraParameters->get(
"Belos/Iteration Count",0);
216 double achievedTol = status.extraParameters->get(
"Belos/Achieved Tolerance",-1.);
226 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
227 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
229 int rank = problem->getComm()->getRank();
230 bool verbose(problem->getVerbose());
231 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
235 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
236 problem->getSolution()->putScalar(0.);
240 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
242 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
244 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
246 thyraRHS = rhs->getProdThyraMultiVector();
248 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
250 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
251 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
253 problem->setupPreconditioner( type );
255 lowsFactory->setOStream(out);
256 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
258 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
260 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
290 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinBlockOp();
291 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
294 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
296 std::cout << status << std::endl;
298 its = status.extraParameters->get(
"Belos/Iteration Count",0);
300 problem->getSolution()->fromThyraProdMultiVector( thyraX );
308 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
309 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
311 int rank = timeProblem->getComm()->getRank();
312 bool verbose(timeProblem->getVerbose());
313 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
317 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
318 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
319 problem->getSolution()->putScalar(0.);
322 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
324 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
326 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
328 thyraRHS = rhs->getProdThyraMultiVector();
330 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
333 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
334 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
336 problem->setupPreconditioner( type );
338 lowsFactory->setOStream(out);
339 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
341 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
343 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
360 BlockMatrixPtr_Type system = timeProblem->getSystemCombined();
372 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinBlockOp();
374 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
377 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
379 std::cout << status << std::endl;
381 its = status.extraParameters->get(
"Belos/Iteration Count",0);
383 problem->getSolution()->fromThyraProdMultiVector( thyraX );
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