14 #include "NOX_Epetra_Interface_Jacobian.H"
19 NOX::Epetra::LinearSystemMPBD::
29 block_solver(block_solver_),
30 jacInterfacePtr(iJac),
37 num_mp_blocks = block_ops->size();
39 std::string prec_strategy = linearSolverParams.
get(
"Preconditioner Strategy",
41 if (prec_strategy ==
"Standard")
42 precStrategy = STANDARD;
43 else if (prec_strategy ==
"Mean")
45 else if (prec_strategy ==
"On the fly")
46 precStrategy = ON_THE_FLY;
49 "Invalid preconditioner strategy " << prec_strategy);
51 if (precStrategy == STANDARD)
52 precs.resize(num_mp_blocks);
55 NOX::Epetra::LinearSystemMPBD::
60 bool NOX::Epetra::LinearSystemMPBD::
61 applyJacobian(
const NOX::Epetra::Vector& input,
62 NOX::Epetra::Vector& result)
const
64 mp_op->SetUseTranspose(
false);
65 int status = mp_op->Apply(input.getEpetraVector(), result.getEpetraVector());
70 bool NOX::Epetra::LinearSystemMPBD::
71 applyJacobianTranspose(
const NOX::Epetra::Vector& input,
72 NOX::Epetra::Vector& result)
const
74 mp_op->SetUseTranspose(
true);
75 int status = mp_op->Apply(input.getEpetraVector(), result.getEpetraVector());
76 mp_op->SetUseTranspose(
false);
81 bool NOX::Epetra::LinearSystemMPBD::
83 const NOX::Epetra::Vector &input,
84 NOX::Epetra::Vector &result)
89 EpetraExt::BlockVector input_block(View, *base_map,
90 input.getEpetraVector());
91 EpetraExt::BlockVector result_block(View, *base_map,
92 result.getEpetraVector());
93 result_block.PutScalar(0.0);
97 params.
sublist(
"Deterministic Solver Parameters");
100 bool final_status =
true;
102 for (
int i=0; i<num_mp_blocks; i++) {
103 NOX::Epetra::Vector nox_input(input_block.GetBlock(i),
104 NOX::Epetra::Vector::CreateView);
105 NOX::Epetra::Vector nox_result(result_block.GetBlock(i),
106 NOX::Epetra::Vector::CreateView);
108 block_solver->setJacobianOperatorForSolve(block_ops->getCoeffPtr(i));
110 if (precStrategy == STANDARD)
111 block_solver->setPrecOperatorForSolve(precs[i]);
112 else if (precStrategy == ON_THE_FLY) {
113 block_solver->createPreconditioner(*(prec_x->GetBlock(i)),
114 block_solver_params,
false);
117 status = block_solver->applyJacobianInverse(block_solver_params, nox_input,
119 final_status = final_status && status;
125 bool NOX::Epetra::LinearSystemMPBD::
126 applyRightPreconditioning(
bool useTranspose,
128 const NOX::Epetra::Vector& input,
129 NOX::Epetra::Vector& result)
const
140 void NOX::Epetra::LinearSystemMPBD::
147 bool NOX::Epetra::LinearSystemMPBD::
148 computeJacobian(
const NOX::Epetra::Vector& x)
150 bool success = jacInterfacePtr->computeJacobian(x.getEpetraVector(),
152 block_ops = mp_op->getMPOps();
157 bool NOX::Epetra::LinearSystemMPBD::
158 createPreconditioner(
const NOX::Epetra::Vector& x,
160 bool recomputeGraph)
const
162 EpetraExt::BlockVector mp_x_block(View, *base_map, x.getEpetraVector());
164 p.
sublist(
"Deterministic Solver Parameters");
165 bool total_success =
true;
166 if (precStrategy == STANDARD) {
167 for (
int i=0; i<num_mp_blocks; i++) {
168 block_solver->setJacobianOperatorForSolve(block_ops->getCoeffPtr(i));
170 block_solver->setPrecOperatorForSolve(precs[i]);
172 block_solver->createPreconditioner(*(mp_x_block.GetBlock(i)),
173 solverParams, recomputeGraph);
174 precs[i] = block_solver->getGeneratedPrecOperator();
175 total_success = total_success && success;
179 else if (precStrategy ==
MEAN) {
180 block_solver->setJacobianOperatorForSolve(block_ops->getCoeffPtr(0));
182 block_solver->createPreconditioner(*(mp_x_block.GetBlock(0)),
183 solverParams, recomputeGraph);
184 total_success = total_success && success;
187 else if (precStrategy == ON_THE_FLY) {
189 prec_x =
Teuchos::rcp(
new EpetraExt::BlockVector(mp_x_block));
191 *prec_x = mp_x_block;
194 return total_success;
197 bool NOX::Epetra::LinearSystemMPBD::
198 destroyPreconditioner()
const
200 return block_solver->destroyPreconditioner();
203 bool NOX::Epetra::LinearSystemMPBD::
204 recomputePreconditioner(
const NOX::Epetra::Vector& x,
207 EpetraExt::BlockVector mp_x_block(View, *base_map, x.getEpetraVector());
209 p.
sublist(
"Deterministic Solver Parameters");
210 bool total_success =
true;
212 if (precStrategy == STANDARD) {
213 for (
int i=0; i<num_mp_blocks; i++) {
214 block_solver->setJacobianOperatorForSolve(block_ops->getCoeffPtr(i));
216 block_solver->setPrecOperatorForSolve(precs[i]);
218 block_solver->recomputePreconditioner(*(mp_x_block.GetBlock(i)),
220 precs[i] = block_solver->getGeneratedPrecOperator();
221 total_success = total_success && success;
225 else if (precStrategy ==
MEAN) {
226 block_solver->setJacobianOperatorForSolve(block_ops->getCoeffPtr(0));
228 block_solver->recomputePreconditioner(*(mp_x_block.GetBlock(0)),
230 total_success = total_success && success;
233 else if (precStrategy == ON_THE_FLY) {
235 prec_x =
Teuchos::rcp(
new EpetraExt::BlockVector(mp_x_block));
237 *prec_x = mp_x_block;
240 return total_success;
243 NOX::Epetra::LinearSystem::PreconditionerReusePolicyType
244 NOX::Epetra::LinearSystemMPBD::
245 getPreconditionerPolicy(
bool advanceReuseCounter)
247 return block_solver->getPreconditionerPolicy(advanceReuseCounter);
250 bool NOX::Epetra::LinearSystemMPBD::
251 isPreconditionerConstructed()
const
253 return block_solver->isPreconditionerConstructed();
256 bool NOX::Epetra::LinearSystemMPBD::
257 hasPreconditioner()
const
259 return block_solver->hasPreconditioner();
263 getJacobianOperator()
const
269 getJacobianOperator()
275 getGeneratedPrecOperator()
const
277 if (precStrategy ==
MEAN)
278 return block_solver->getGeneratedPrecOperator();
281 true, std::logic_error,
282 "Cannot call getGeneratedPrecOperator() unless prec strategy is Mean");
287 getGeneratedPrecOperator()
289 if (precStrategy ==
MEAN)
290 return block_solver->getGeneratedPrecOperator();
293 true, std::logic_error,
294 "Cannot call getGeneratedPrecOperator() unless prec strategy is Mean");
298 void NOX::Epetra::LinearSystemMPBD::
299 setJacobianOperatorForSolve(
const
309 void NOX::Epetra::LinearSystemMPBD::
312 if (precStrategy ==
MEAN)
313 block_solver->setPrecOperatorForSolve(solvePrecOp);
316 true, std::logic_error,
317 "Cannot call setPrecOperatorForSolve() unless prec strategy is Mean");
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
T & get(ParameterList &l, const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
An Epetra operator representing the block stochastic Galerkin operator.
virtual Teuchos::RCP< Stokhos::ProductEpetraOperator > getMPOps()
Get multi-point ops.