73 bool verbose(problem->getVerbose());
75 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
76 problem->getSolution()->putScalar(0.);
78 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
80 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
82 thyraB = problem->getRhs()->getThyraMultiVectorConst();
84 thyraB = rhs->getThyraMultiVectorConst();
86 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
88 pListThyraSolver->setParameters( problem->getParameterList()->sublist(
"ThyraPreconditioner") );
90 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
91 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
93 bool iterativeSolve = !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos");
94 if (iterativeSolve && (type !=
"MonolithicConstPrec" || problem->getPreconditioner()->getThyraPrec().is_null()))
95 problem->setupPreconditioner(
"Monolithic");
97 if (!pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"Level Combination",
"Additive").compare(
"Multiplicative")) {
98 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
true);
100 Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
101 Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
102 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
false);
105 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
107 lowsFactory->setOStream(out);
108 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
110 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
112 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinOp();
113 if ( iterativeSolve ) {
114 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
115 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
118 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
122 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
124 std::cout << status << std::endl;
125 if ( !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos") )
126 its = status.extraParameters->get(
"Belos/Iteration Count",0);
130 problem->getSolution()->fromThyraMultiVector(thyraX);
140 bool verbose(timeProblem->getVerbose());
142 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
144 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
145 problem->getSolution()->putScalar(0.);
148 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
150 Teuchos::RCP<Thyra::MultiVectorBase<SC> >thyraX = problem->getSolution()->getThyraMultiVector();
151 Teuchos::RCP<const Thyra::MultiVectorBase<SC> > thyraB;
154 thyraB = problem->getRhs()->getThyraMultiVectorConst();
156 thyraB = rhs->getThyraMultiVectorConst();
158 pListThyraSolver->setParameters( problem->getParameterList()->sublist(
"ThyraPreconditioner") );
160 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
161 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
164 problem->setupPreconditioner(
"Monolithic" );
166 if (!pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"Level Combination",
"Additive").compare(
"Multiplicative")) {
167 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
true);
169 Teuchos::RCP<const Thyra::LinearOpBase<SC> > thyra_linOp = problem->getPreconditioner()->getThyraPrec()->getUnspecifiedPrecOp();
170 Thyra::apply( *thyra_linOp, Thyra::NOTRANS, *thyraB, thyraX.ptr() );
171 pListThyraSolver->sublist(
"Preconditioner Types").sublist(
"FROSch").set(
"Only apply coarse",
false);
174 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
176 lowsFactory->setOStream(out);
177 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
179 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
181 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinOp();
183 if ( !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos") ) {
184 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
185 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
188 Thyra::initializeOp<SC>(*lowsFactory, thyraMatrix, solver.ptr());
191 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraB, thyraX.ptr());
193 std::cout << status << std::endl;
194 problem->getSolution()->fromThyraMultiVector(thyraX);
196 if ( !pListThyraSolver->get(
"Linear Solver Type",
"Belos").compare(
"Belos") ){
197 its = status.extraParameters->get(
"Belos/Iteration Count",0);
198 double achievedTol = status.extraParameters->get(
"Belos/Achieved Tolerance",-1.);
208 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
209 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
211 int rank = problem->getComm()->getRank();
212 bool verbose(problem->getVerbose());
213 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
217 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
218 problem->getSolution()->putScalar(0.);
222 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
224 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
226 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
228 thyraRHS = rhs->getProdThyraMultiVector();
230 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
232 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
233 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
235 problem->setupPreconditioner( type );
237 lowsFactory->setOStream(out);
238 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
240 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
242 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
272 ThyraLinOpConstPtr_Type thyraMatrix = problem->getSystem()->getThyraLinBlockOp();
273 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
276 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
278 std::cout << status << std::endl;
280 its = status.extraParameters->get(
"Belos/Iteration Count",0);
282 problem->getSolution()->fromThyraProdMultiVector( thyraX );
290 typedef Thyra::DefaultZeroLinearOp<SC> ZeroOp_Type;
291 typedef Teuchos::RCP<ZeroOp_Type> ZeroOpPtr_Type;
293 int rank = timeProblem->getComm()->getRank();
294 bool verbose(timeProblem->getVerbose());
295 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
299 ProblemPtr_Type problem = timeProblem->getUnderlyingProblem();
300 if (problem->getParameterList()->get(
"Zero Initial Guess",
true)) {
301 problem->getSolution()->putScalar(0.);
304 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraX = problem->getSolution()->getProdThyraMultiVector();
306 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > thyraRHS;
308 thyraRHS = problem->getRhs()->getProdThyraMultiVector();
310 thyraRHS = rhs->getProdThyraMultiVector();
312 ParameterListPtr_Type pListThyraSolver = sublist( problem->getParameterList(),
"ThyraSolver" );
315 problem->getLinearSolverBuilder()->setParameterList(pListThyraSolver);
316 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<SC> > lowsFactory = problem->getLinearSolverBuilder()->createLinearSolveStrategy(
"");
318 problem->setupPreconditioner( type );
320 lowsFactory->setOStream(out);
321 lowsFactory->setVerbLevel(Teuchos::VERB_HIGH);
323 Teuchos::RCP<Thyra::LinearOpWithSolveBase<SC> > solver = lowsFactory->createOp();
325 ThyraPrecPtr_Type thyraPrec = problem->getPreconditioner()->getThyraPrec();
342 BlockMatrixPtr_Type system = timeProblem->getSystemCombined();
354 ThyraLinOpConstPtr_Type thyraMatrix = timeProblem->getSystemCombined()->getThyraLinBlockOp();
356 Thyra::initializePreconditionedOp<SC>(*lowsFactory, thyraMatrix, thyraPrec.getConst(), solver.ptr());
359 Thyra::SolveStatus<SC> status = Thyra::solve<SC>(*solver, Thyra::NOTRANS, *thyraRHS, thyraX.ptr());
361 std::cout << status << std::endl;
363 its = status.extraParameters->get(
"Belos/Iteration Count",0);
365 problem->getSolution()->fromThyraProdMultiVector( thyraX );
int solveMonolithic(Problem_Type *problem, BlockMultiVectorPtr_Type rhs, std::string type)
Solve linear/linearized problem monolithicly.
Definition LinearSolver_def.hpp:71
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:207
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:23