48 #include "NOX_Epetra_Interface_Jacobian.H"
49 #include "EpetraExt_BlockVector.h"
54 NOX::Epetra::LinearSystemSGJacobi::
67 det_solver(det_solver_),
68 epetraCijk(sg_parallel_data->getEpetraCijk()),
69 jacInterfacePtr(iJac),
79 Teuchos::rcp(
new EpetraExt::BlockVector(*base_map, *sg_map));
84 sgOpParams->
set(
"Include Mean",
false);
85 if (!sgOpParams->
isParameter(
"Only Use Linear Terms"))
86 sgOpParams->
set(
"Only Use Linear Terms",
false);
92 if (sgOpParams->
get<
bool>(
"Only Use Linear Terms") &&
93 epetraCijk->isStochasticParallel()) {
94 int dim = sg_basis->dimension();
95 if (epetraCijk->getKEnd() > dim+1)
98 *epetraCijk, 1, dim+1));
106 sg_op_factory.build(sg_comm, sg_basis, epetraCijk,
107 base_map, base_map, sg_map, sg_map);
110 NOX::Epetra::LinearSystemSGJacobi::
111 ~LinearSystemSGJacobi()
115 bool NOX::Epetra::LinearSystemSGJacobi::
116 applyJacobian(
const NOX::Epetra::Vector& input,
117 NOX::Epetra::Vector& result)
const
119 sg_op->SetUseTranspose(
false);
120 int status = sg_op->Apply(input.getEpetraVector(), result.getEpetraVector());
122 return (status == 0);
125 bool NOX::Epetra::LinearSystemSGJacobi::
126 applyJacobianTranspose(
const NOX::Epetra::Vector& input,
127 NOX::Epetra::Vector& result)
const
129 sg_op->SetUseTranspose(
true);
130 int status = sg_op->Apply(input.getEpetraVector(), result.getEpetraVector());
131 sg_op->SetUseTranspose(
false);
133 return (status == 0);
136 bool NOX::Epetra::LinearSystemSGJacobi::
138 const NOX::Epetra::Vector &input,
139 NOX::Epetra::Vector &result)
141 int max_iter = params.
get(
"Max Iterations",100 );
142 double sg_tol = params.
get(
"Tolerance", 1e-12);
145 EpetraExt::BlockVector sg_dx_block(View, *base_map, result.getEpetraVector());
146 EpetraExt::BlockVector sg_f_block(View, *base_map, input.getEpetraVector());
147 sg_dx_block.PutScalar(0.0);
150 double norm_f,norm_df;
151 sg_f_block.Norm2(&norm_f);
152 sg_op->Apply(sg_dx_block, *sg_df_block);
153 sg_df_block->Update(-1.0, sg_f_block, 1.0);
154 sg_df_block->Norm2(&norm_df);
158 params.
sublist(
"Deterministic Solver Parameters");
160 int myBlockRows = epetraCijk->numMyRows();
162 while (((norm_df/norm_f)>sg_tol) && (iter<max_iter)) {
168 sg_df_block->Update(1.0, sg_f_block, 0.0);
170 mat_free_op->Apply(sg_dx_block, *sg_df_block);
171 sg_df_block->Update(1.0, sg_f_block, -1.0);
174 for (
int i=0; i<myBlockRows; i++) {
175 df = sg_df_block->GetBlock(i);
176 dx = sg_dx_block.GetBlock(i);
177 NOX::Epetra::Vector nox_df(df, NOX::Epetra::Vector::CreateView);
178 NOX::Epetra::Vector nox_dx(dx, NOX::Epetra::Vector::CreateView);
180 (*sg_poly)[0].Apply(*dx, *kx);
186 det_solver->applyJacobianInverse(det_solver_params, nox_df, nox_dx);
189 df->Update(-1.0, *kx, 1.0);
192 sg_df_block->Norm2(&norm_df);
193 utils.out() <<
"\t Jacobi relative residual norm at iteration "
194 << iter <<
" is " << norm_df/norm_f << std::endl;
201 bool NOX::Epetra::LinearSystemSGJacobi::
202 applyRightPreconditioning(
bool useTranspose,
204 const NOX::Epetra::Vector& input,
205 NOX::Epetra::Vector& result)
const
216 void NOX::Epetra::LinearSystemSGJacobi::
223 bool NOX::Epetra::LinearSystemSGJacobi::
224 computeJacobian(
const NOX::Epetra::Vector& x)
226 bool success = jacInterfacePtr->computeJacobian(x.getEpetraVector(),
228 sg_poly = sg_op->getSGPolynomial();
229 det_solver->setJacobianOperatorForSolve(sg_poly->getCoeffPtr(0));
230 mat_free_op->setupOperator(sg_poly);
234 bool NOX::Epetra::LinearSystemSGJacobi::
235 createPreconditioner(
const NOX::Epetra::Vector& x,
237 bool recomputeGraph)
const
239 EpetraExt::BlockVector sg_x_block(View, *base_map, x.getEpetraVector());
241 det_solver->createPreconditioner(*(sg_x_block.GetBlock(0)),
242 p.
sublist(
"Deterministic Solver Parameters"),
248 bool NOX::Epetra::LinearSystemSGJacobi::
249 destroyPreconditioner()
const
251 return det_solver->destroyPreconditioner();
254 bool NOX::Epetra::LinearSystemSGJacobi::
255 recomputePreconditioner(
const NOX::Epetra::Vector& x,
258 EpetraExt::BlockVector sg_x_block(View, *base_map, x.getEpetraVector());
260 det_solver->recomputePreconditioner(
261 *(sg_x_block.GetBlock(0)),
262 linearSolverParams.
sublist(
"Deterministic Solver Parameters"));
267 NOX::Epetra::LinearSystem::PreconditionerReusePolicyType
268 NOX::Epetra::LinearSystemSGJacobi::
269 getPreconditionerPolicy(
bool advanceReuseCounter)
271 return det_solver->getPreconditionerPolicy(advanceReuseCounter);
274 bool NOX::Epetra::LinearSystemSGJacobi::
275 isPreconditionerConstructed()
const
277 return det_solver->isPreconditionerConstructed();
280 bool NOX::Epetra::LinearSystemSGJacobi::
281 hasPreconditioner()
const
283 return det_solver->hasPreconditioner();
287 getJacobianOperator()
const
293 getJacobianOperator()
299 getGeneratedPrecOperator()
const
305 getGeneratedPrecOperator()
310 void NOX::Epetra::LinearSystemSGJacobi::
311 setJacobianOperatorForSolve(
const
320 void NOX::Epetra::LinearSystemSGJacobi::
321 setPrecOperatorForSolve(
const
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Teuchos::RCP< const EpetraExt::MultiComm > getMultiComm() const
Get global comm.
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
bool isParameter(const std::string &name) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
An abstract class to represent a generic stochastic Galerkin operator as an Epetra_Operator.
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()=0
Get SG polynomial.
Factory for generating stochastic Galerkin preconditioners.