13 #include "NOX_Epetra_Interface_Jacobian.H"
14 #include "EpetraExt_BlockVector.h"
19 NOX::Epetra::LinearSystemSGJacobi::
32 det_solver(det_solver_),
33 epetraCijk(sg_parallel_data->getEpetraCijk()),
34 jacInterfacePtr(iJac),
44 Teuchos::rcp(
new EpetraExt::BlockVector(*base_map, *sg_map));
49 sgOpParams->
set(
"Include Mean",
false);
50 if (!sgOpParams->
isParameter(
"Only Use Linear Terms"))
51 sgOpParams->
set(
"Only Use Linear Terms",
false);
57 if (sgOpParams->
get<
bool>(
"Only Use Linear Terms") &&
58 epetraCijk->isStochasticParallel()) {
59 int dim = sg_basis->dimension();
60 if (epetraCijk->getKEnd() > dim+1)
63 *epetraCijk, 1, dim+1));
71 sg_op_factory.build(sg_comm, sg_basis, epetraCijk,
72 base_map, base_map, sg_map, sg_map);
75 NOX::Epetra::LinearSystemSGJacobi::
76 ~LinearSystemSGJacobi()
80 bool NOX::Epetra::LinearSystemSGJacobi::
81 applyJacobian(
const NOX::Epetra::Vector& input,
82 NOX::Epetra::Vector& result)
const
84 sg_op->SetUseTranspose(
false);
85 int status = sg_op->Apply(input.getEpetraVector(), result.getEpetraVector());
90 bool NOX::Epetra::LinearSystemSGJacobi::
91 applyJacobianTranspose(
const NOX::Epetra::Vector& input,
92 NOX::Epetra::Vector& result)
const
94 sg_op->SetUseTranspose(
true);
95 int status = sg_op->Apply(input.getEpetraVector(), result.getEpetraVector());
96 sg_op->SetUseTranspose(
false);
101 bool NOX::Epetra::LinearSystemSGJacobi::
103 const NOX::Epetra::Vector &input,
104 NOX::Epetra::Vector &result)
106 int max_iter = params.
get(
"Max Iterations",100 );
107 double sg_tol = params.
get(
"Tolerance", 1e-12);
110 EpetraExt::BlockVector sg_dx_block(View, *base_map, result.getEpetraVector());
111 EpetraExt::BlockVector sg_f_block(View, *base_map, input.getEpetraVector());
112 sg_dx_block.PutScalar(0.0);
115 double norm_f,norm_df;
116 sg_f_block.Norm2(&norm_f);
117 sg_op->Apply(sg_dx_block, *sg_df_block);
118 sg_df_block->Update(-1.0, sg_f_block, 1.0);
119 sg_df_block->Norm2(&norm_df);
123 params.
sublist(
"Deterministic Solver Parameters");
125 int myBlockRows = epetraCijk->numMyRows();
127 while (((norm_df/norm_f)>sg_tol) && (iter<max_iter)) {
133 sg_df_block->Update(1.0, sg_f_block, 0.0);
135 mat_free_op->Apply(sg_dx_block, *sg_df_block);
136 sg_df_block->Update(1.0, sg_f_block, -1.0);
139 for (
int i=0; i<myBlockRows; i++) {
140 df = sg_df_block->GetBlock(i);
141 dx = sg_dx_block.GetBlock(i);
142 NOX::Epetra::Vector nox_df(df, NOX::Epetra::Vector::CreateView);
143 NOX::Epetra::Vector nox_dx(dx, NOX::Epetra::Vector::CreateView);
145 (*sg_poly)[0].Apply(*dx, *kx);
151 det_solver->applyJacobianInverse(det_solver_params, nox_df, nox_dx);
154 df->Update(-1.0, *kx, 1.0);
157 sg_df_block->Norm2(&norm_df);
158 utils.out() <<
"\t Jacobi relative residual norm at iteration "
159 << iter <<
" is " << norm_df/norm_f << std::endl;
166 bool NOX::Epetra::LinearSystemSGJacobi::
167 applyRightPreconditioning(
bool useTranspose,
169 const NOX::Epetra::Vector& input,
170 NOX::Epetra::Vector& result)
const
181 void NOX::Epetra::LinearSystemSGJacobi::
188 bool NOX::Epetra::LinearSystemSGJacobi::
189 computeJacobian(
const NOX::Epetra::Vector& x)
191 bool success = jacInterfacePtr->computeJacobian(x.getEpetraVector(),
193 sg_poly = sg_op->getSGPolynomial();
194 det_solver->setJacobianOperatorForSolve(sg_poly->getCoeffPtr(0));
195 mat_free_op->setupOperator(sg_poly);
199 bool NOX::Epetra::LinearSystemSGJacobi::
200 createPreconditioner(
const NOX::Epetra::Vector& x,
202 bool recomputeGraph)
const
204 EpetraExt::BlockVector sg_x_block(View, *base_map, x.getEpetraVector());
206 det_solver->createPreconditioner(*(sg_x_block.GetBlock(0)),
207 p.
sublist(
"Deterministic Solver Parameters"),
213 bool NOX::Epetra::LinearSystemSGJacobi::
214 destroyPreconditioner()
const
216 return det_solver->destroyPreconditioner();
219 bool NOX::Epetra::LinearSystemSGJacobi::
220 recomputePreconditioner(
const NOX::Epetra::Vector& x,
223 EpetraExt::BlockVector sg_x_block(View, *base_map, x.getEpetraVector());
225 det_solver->recomputePreconditioner(
226 *(sg_x_block.GetBlock(0)),
227 linearSolverParams.
sublist(
"Deterministic Solver Parameters"));
232 NOX::Epetra::LinearSystem::PreconditionerReusePolicyType
233 NOX::Epetra::LinearSystemSGJacobi::
234 getPreconditionerPolicy(
bool advanceReuseCounter)
236 return det_solver->getPreconditionerPolicy(advanceReuseCounter);
239 bool NOX::Epetra::LinearSystemSGJacobi::
240 isPreconditionerConstructed()
const
242 return det_solver->isPreconditionerConstructed();
245 bool NOX::Epetra::LinearSystemSGJacobi::
246 hasPreconditioner()
const
248 return det_solver->hasPreconditioner();
252 getJacobianOperator()
const
258 getJacobianOperator()
264 getGeneratedPrecOperator()
const
270 getGeneratedPrecOperator()
275 void NOX::Epetra::LinearSystemSGJacobi::
276 setJacobianOperatorForSolve(
const
285 void NOX::Epetra::LinearSystemSGJacobi::
286 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)
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.