44 #include "fei_trilinos_macros.hpp"
46 #ifdef HAVE_FEI_AZTECOO
49 #include <fei_Include_Trilinos.hpp>
50 #include <fei_Trilinos_Helpers.hpp>
52 #include <fei_Solver_AztecOO.hpp>
53 #include <fei_LinProbMgr_EpetraBasic.hpp>
54 #include <fei_ParameterSet.hpp>
55 #include <fei_utils.hpp>
57 #include <fei_VectorTraits_Epetra.hpp>
58 #include <fei_Vector_Impl.hpp>
59 #include <fei_MatrixTraits_Epetra.hpp>
60 #include <fei_Matrix_Impl.hpp>
61 #include <fei_LinearSystem.hpp>
64 #include <ml_LevelWrap.h>
68 Solver_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: ")
83 ml_aztec_options_ =
new int[AZ_OPTIONS_SIZE];
84 ml_aztec_params_ =
new double[AZ_PARAMS_SIZE];
89 Solver_AztecOO::~Solver_AztecOO()
95 delete [] ml_aztec_options_;
96 delete [] ml_aztec_params_;
100 AZ_manage_memory(0, AZ_CLEAR_ALL, 0, NULL, NULL);
104 AztecOO& Solver_AztecOO::getAztecOO()
110 void Solver_AztecOO::setUseML(
bool useml)
118 if (paramlist_ == NULL) {
122 return( *paramlist_ );
129 int& iterationsTaken,
132 std::string pcstring;
134 if (pcstring ==
"ML_Op") {
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_) {
148 ML_Epetra::SetDefaults(
"SA", mlparams, ml_aztec_options_,ml_aztec_params_);
150 paramlist = mlparams;
151 ml_defaults_set_ =
true;
155 Trilinos_Helpers::copy_parameterset(parameterSet, paramlist);
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) {
203 else if (snl_epetra_vbr != NULL) {
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;
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") {
288 FEI_OSTRINGSTREAM osstr;
289 if (!param1.empty()) {
290 osstr << param1 <<
"/";
294 osstr <<
"x_AztecOO.vec";
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_) {
332 ML_Epetra::SetDefaults(
"SA", mlparams,ml_aztec_options_,ml_aztec_params_);
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);
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);
374 ml_prec_ =
new ML_Epetra::MultiLevelPreconditioner(*A, *paramlist_,
true);
377 azoo_->SetPrecOperator(ml_prec_);
void char_ptrs_to_strings(int numStrings, const char *const *charstrings, std::vector< std::string > &stdstrings)
virtual int writeToFile(const char *filename, bool matrixMarketFormat=true)=0
virtual fei::SharedPtr< fei::Matrix > getMatrix()
virtual int SetUseTranspose(bool UseTranspose)=0
T & get(const std::string &name, T def_value)
virtual void markState()=0
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual fei::SharedPtr< fei::Vector > getRHS()
int getStringParamValue(const char *name, std::string ¶mValue) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
fei::SharedPtr< T > getMatrix()
virtual bool changedSinceMark()=0
ParameterList & setParameters(const ParameterList &source)
std::ostream & console_out()
void parse_strings(std::vector< std::string > &stdstrings, const char *separator_string, fei::ParameterSet ¶mset)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual fei::SharedPtr< fei::Vector > getSolutionVector()
int getIntParamValue(const char *name, int ¶mValue) const