46#ifdef HAVE_FEI_AZTECOO
64#include <ml_LevelWrap.h>
68Solver_AztecOO::Solver_AztecOO()
69 : tolerance_(1.e-6), maxIters_(500), useTranspose_(false), paramlist_(NULL),
73 ml_prec_(NULL), ml_defaults_set_(false),
74 ml_aztec_options_(NULL), ml_aztec_params_(NULL),
77 dbgprefix_(
"SlvAzoo: ")
80 paramlist_ =
new Teuchos::ParameterList;
83 ml_aztec_options_ =
new int[AZ_OPTIONS_SIZE];
84 ml_aztec_params_ =
new double[AZ_PARAMS_SIZE];
89Solver_AztecOO::~Solver_AztecOO()
95 delete [] ml_aztec_options_;
96 delete [] ml_aztec_params_;
100 AZ_manage_memory(0, AZ_CLEAR_ALL, 0, NULL, NULL);
104AztecOO& Solver_AztecOO::getAztecOO()
110void Solver_AztecOO::setUseML(
bool useml)
116Teuchos::ParameterList& Solver_AztecOO::get_ParameterList()
118 if (paramlist_ == NULL) {
119 paramlist_ =
new Teuchos::ParameterList;
122 return( *paramlist_ );
129 int& iterationsTaken,
132 std::string pcstring;
134 if (pcstring ==
"ML_Op") {
138 Teuchos::ParameterList& paramlist = get_ParameterList();
141 if (ml_aztec_options_ == NULL)
142 ml_aztec_options_ =
new int[AZ_OPTIONS_SIZE];
143 if (ml_aztec_params_ == NULL)
144 ml_aztec_params_ =
new double[AZ_PARAMS_SIZE];
146 if (!ml_defaults_set_ && useML_) {
147 Teuchos::ParameterList mlparams;
148 ML_Epetra::SetDefaults(
"SA", mlparams, ml_aztec_options_,ml_aztec_params_);
149 mlparams.setParameters(paramlist);
150 paramlist = mlparams;
151 ml_defaults_set_ =
true;
166 Trilinos_Helpers::get_Epetra_pointers(feiA, feix, feib,
167 crsA, epetra_op, x, b);
169 if (epetra_op == 0 || x == 0 || b == 0) {
170 fei::console_out() <<
"Solver_AztecOO::solve Error, couldn't obtain Epetra objects"
171 <<
" from fei container-objects."<<
FEI_ENDL;
180 std::vector<int> azoptions(AZ_OPTIONS_SIZE);
181 std::vector<double> azparams(AZ_PARAMS_SIZE);
183 const int* azoptionsptr = azoo_->GetAllAztecOptions();
184 const double* azparamsptr = azoo_->GetAllAztecParams();
187 for(i=0; i<AZ_OPTIONS_SIZE; ++i) {
188 azoptions[i] = azoptionsptr[i];
190 for(i=0; i<AZ_PARAMS_SIZE; ++i) {
191 azparams[i] = azparamsptr[i];
195 if (preconditioningMatrix != NULL) {
200 if (snl_epetra_crs != NULL) {
201 precond = snl_epetra_crs->
getMatrix().get();
203 else if (snl_epetra_vbr != NULL) {
204 precond = snl_epetra_vbr->
getMatrix().get();
207 fei::console_out() <<
"Solver_AztecOO::solve: ERROR getting epetra row matrix"
208 <<
" from preconditioningMatrix."<<
FEI_ENDL;
213 if (precond != NULL) {
215 azoo_->SetProblem(*newlinProb);
217 linProb = newlinProb;
219 azoo_->SetAllAztecOptions(&(azoptions[0]));
220 azoo_->SetAllAztecParams(&(azparams[0]));
222 azoo_->SetUseAdaptiveDefaultsTrue();
224 azoo_->SetPrecMatrix(precond);
227 bool needNewPreconditioner =
false;
229 if (feiA->changedSinceMark()) {
231 needNewPreconditioner =
true;
234 if (needNewPreconditioner) {
236 azoo_->SetProblem(*newlinProb);
238 linProb = newlinProb;
240 azoo_->SetAllAztecOptions(&(azoptions[0]));
241 azoo_->SetAllAztecParams(&(azparams[0]));
243 azoo_->SetUseAdaptiveDefaultsTrue();
247 setup_ml_operator(*azoo_, crsA);
249 fei::console_out() <<
"Solver_AztecOO::solve ERROR, ML requested but HAVE_FEI_ML not defined."
255 azoo_->SetAztecOption(AZ_pre_calc, AZ_calc);
256 azoo_->SetAztecOption(AZ_keep_info, 1);
261 azoo_->SetAztecOption(AZ_pre_calc, AZ_reuse);
267 azoo_->SetParameters(paramlist);
269 maxIters_ = azoptionsptr[AZ_max_iter];
270 tolerance_= azparamsptr[AZ_tol];
272 status = azoo_->Iterate(maxIters_,
276 iterationsTaken = azoo_->NumIters();
284 if (olevel >= 3 || param2 ==
"MATRIX_FILES" || param2 ==
"ALL") {
289 if (!param1.empty()) {
290 osstr << param1 <<
"/";
294 osstr <<
"x_AztecOO.vec";
295 feix->writeToFile(osstr.str().c_str());
305 const char*
const* solverParams,
306 int& iterationsTaken,
309 std::vector<std::string> stdstrings;
315 return( solve(linearSystem, preconditioningMatrix, paramset,
316 iterationsTaken, status) );
323 if (ml_aztec_options_ == NULL) {
324 ml_aztec_options_ =
new int[AZ_OPTIONS_SIZE];
326 if (ml_aztec_params_ == NULL) {
327 ml_aztec_params_ =
new double[AZ_PARAMS_SIZE];
330 if (!ml_defaults_set_) {
331 Teuchos::ParameterList mlparams;
332 ML_Epetra::SetDefaults(
"SA", mlparams,ml_aztec_options_,ml_aztec_params_);
333 mlparams.setParameters(*paramlist_);
334 *paramlist_ = mlparams;
335 ml_defaults_set_ =
true;
338 if (ml_prec_ != NULL) {
339 delete ml_prec_; ml_prec_ = NULL;
342 const bool variableDof = paramlist_->get(
"ML variable DOF",
false);
343 const bool levelWrap = paramlist_->get(
"ML LevelWrap",
false);
344 assert(!variableDof || !levelWrap);
347 bool * dofPresent = paramlist_->get(
"DOF present",(
bool*)0);
348 int nOwnedEntities = paramlist_->get(
"num owned entities", 0);
349 assert( (
nullptr != dofPresent) || (nOwnedEntities == 0));
350 int maxDofPerEntity = paramlist_->get(
"max DOF per entity", 0);
353 ml_prec_ =
new ML_Epetra::MultiLevelPreconditioner(*A, *paramlist_,
354 nOwnedEntities,maxDofPerEntity, dofPresent,
355 *dummy, *dummy,
false,
true);
360 ML_Epetra::SetDefaultsLevelWrap(*paramlist_,
false);
361 Teuchos::ParameterList &crsparams = paramlist_->sublist(
"levelwrap: coarse list");
363 Teuchos::ParameterList &ifparams = crsparams.sublist(
"smoother: ifpack list");
364 int N_indices = paramlist_->get(
"LevelWrap number of local smoothing indices",(
int)0);
365 int * smth_indices = paramlist_->get(
"LevelWrap local smoothing indices",(
int*)0);
366 ifparams.set(
"relaxation: number of local smoothing indices",N_indices);
367 ifparams.set(
"relaxation: local smoothing indices",smth_indices);
370 ml_prec_ =
new ML_Epetra::LevelWrap(Teuchos::rcp(A,
false), Teuchos::rcp(volAvgMtx,
false), *paramlist_);
374 ml_prec_ =
new ML_Epetra::MultiLevelPreconditioner(*A, *paramlist_,
true);
377 azoo_->SetPrecOperator(ml_prec_);
virtual int SetUseTranspose(bool UseTranspose)=0
virtual fei::SharedPtr< fei::Vector > getRHS()
virtual fei::SharedPtr< fei::Matrix > getMatrix()
virtual fei::SharedPtr< fei::Vector > getSolutionVector()
fei::SharedPtr< T > getMatrix()
int getIntParamValue(const char *name, int ¶mValue) const
int getStringParamValue(const char *name, std::string ¶mValue) const
#define FEI_OSTRINGSTREAM
void copy_parameterset(const fei::ParameterSet ¶mset, Teuchos::ParameterList ¶mlist)
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
void char_ptrs_to_strings(int numStrings, const char *const *charstrings, std::vector< std::string > &stdstrings)
std::ostream & console_out()