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 problem->setupPreconditioner(
"Monolithic" );
182 if (!pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"Level Combination",
"Additive").compare(
"Multiplicative")) {
183 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
true);
185 Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
186 Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
187 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
false);
190 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
192 lowsFactory->setOStream(out);
193 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
195 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
197 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinOp();
199 if ( !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos") ) {
200 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
201 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
204 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
207 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
209 std::cout << status << std::endl;
210 problem->getSolution()->fromThyraMultiVector(thyraX);
212 if ( !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos") ){
213 its = status.extraParameters->get(
"Belos/Iteration Count",0);
214 double achievedTol = status.extraParameters->get(
"Belos/Achieved Tolerance",-1.);
224 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
225 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
227 int rank = problem->getComm()->getRank();
228 bool verbose(problem->getVerbose());
229 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
233 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
234 problem->getSolution()->putScalar(0.);
238 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
240 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
242 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
244 thyraRHS = rhs->getProdThyraMultiVector();
246 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
248 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
249 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
251 problem->setupPreconditioner( type );
253 lowsFactory->setOStream(out);
254 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
256 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
258 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
288 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinBlockOp();
289 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
292 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
294 std::cout << status << std::endl;
296 its = status.extraParameters->get(
"Belos/Iteration Count",0);
298 problem->getSolution()->fromThyraProdMultiVector( thyraX );
306 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
307 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
309 int rank = timeProblem->getComm()->getRank();
310 bool verbose(timeProblem->getVerbose());
311 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
315 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
316 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
317 problem->getSolution()->putScalar(0.);
320 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
322 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
324 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
326 thyraRHS = rhs->getProdThyraMultiVector();
328 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
331 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
332 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
334 problem->setupPreconditioner( type );
336 lowsFactory->setOStream(out);
337 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
339 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
341 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
358 BlockMatrixPtr_Type system = timeProblem->getSystemCombined();
370 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinBlockOp();
372 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
375 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
377 std::cout << status << std::endl;
379 its = status.extraParameters->get(
"Belos/Iteration Count",0);
381 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:223
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