Belos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Aztec_to_Belos_param.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 //
10 // This driver tests the translation of Aztec parameters to
11 // Teuchos::ParameterList based Belos compatable parameters.
12 //
13 // NOTE: No preconditioner or subdomain solve translateion is supported, aand
14 // will generate a Belos::XLateStatus::WARN as part of the return pair;
15 //
16 //
17 #include "BelosConfigDefs.hpp"
18 #include "BelosUtils.hpp"
21 #include "az_aztec_defs.h"
22 
23 using namespace Teuchos;
24 
25 int main(int argc, char *argv[]) {
26 
27  //* indicates it is a option that is translated by Belos_translateFromAztecParams
28  //x indicates that this option will produce a warning return type.
29 //AZ_solver 0 *
30 //AZ_scaling 1
31 //AZ_precond 2 x
32 //AZ_conv 3 *
33 //AZ_output 4 *
34 //AZ_pre_calc 5
35 //AZ_max_iter 6 *
36 //AZ_poly_ord 7
37 //AZ_overlap 8
38 //AZ_type_overlap 9
39 //AZ_kspace 10 * if AZ_solver == AZ_gmres
40 //AZ_orthog 11 * ICGS and IMGS only
41 //AZ_aux_vec 12
42 //AZ_reorder 13
43 //AZ_keep_info 14
44 //AZ_recursion_level 15
45 //AZ_print_freq 16
46 //AZ_graph_fill 17
47 //AZ_subdomain_solve 18 x
48 //AZ_init_guess 19
49 //AZ_keep_kvecs 20
50 //AZ_apply_kvecs 21
51 //AZ_orth_kvecs 22
52 //AZ_ignore_scaling 23
53 //AZ_check_update_size 24
54 //AZ_extreme 25
55 //AZ_diagnostics 26
56 
57 // AZ_tol 0 *
58 // AZ_drop 1
59 // AZ_ilut_fill 2
60 // AZ_omega 3
61 // AZ_rthresh 4
62 // AZ_athresh 5
63 // AZ_update_reduction 6
64 // AZ_temp 7
65 // AZ_ill_cond_thresh 8
66 // AZ_weights 9
67 
68  std::pair<std::string,int> xlate_err;
69 
70  int * az_opt = new int [AZ_FIRST_USER_OPTION];
71  memset(az_opt,0,sizeof(int)*(AZ_FIRST_USER_OPTION));
72  std::vector<double> Vaz_param;
73  Vaz_param.resize(AZ_FIRST_USER_PARAM,0.0);
74 
75  Vaz_param[AZ_tol] = 1e-9;
76  // treatment of specified solvers.
77 // AZ_cg 0 *
78 // AZ_gmres 1 *
79 // AZ_cgs 2 x Error
80 // AZ_tfqmr 3 *
81 // AZ_bicgstab 4 *
82 // AZ_slu 5 x Error
83 // AZ_symmlq 6 x Error
84 // AZ_GMRESR 7 x Error
85 // AZ_fixed_pt 8 x Error
86 // AZ_analyze 9 x Error
87 // AZ_lu 10 *
88 // AZ_cg_condnum 11 *
89 // AZ_gmres_condnum 12 x Error
90 
91  az_opt[AZ_solver] = AZ_gmres;
92  az_opt[AZ_conv] = AZ_r0; // or AZ_rhs or AZ_Anorm or AZ_noscaled
93 
95  const double * az_par_val = (const double * ) &(Vaz_param[0]);
96  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
97 
98  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_OK || xlate_err.first.size()!=0 ) {
99  // this one should be error and warning free
100  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
101  std::cout << xlate_err.first<<std::endl;
102  std::cout << " Error num "<< xlate_err.second<<std::endl;
103  std::cout << " enum Opt Param "<<std::endl;
104  for(int i=0;i<AZ_FIRST_USER_OPTION;++i) {
105  std::cout << i<<" "<<az_opt[i];
106  if(i<AZ_FIRST_USER_PARAM) std::cout <<" "<<az_par_val[i];
107  std::cout<<std::endl;
108  }
109 
110  tpl.print();
111  return EXIT_FAILURE;
112  }
113  tpl.print();
114  std::cout<<" Pass "<<std::endl;
115 
116  // now add some stuff that should give warnings.
117  az_opt[AZ_precond] = AZ_ls; // any value other than AZ_none == 0 generates a warning.
118  az_opt[AZ_conv] = AZ_rhs; // should be valid.
119 
120  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
121 
122  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_WARN) {
123  // this one should be error free but generate a warning
124  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
125  std::cout << xlate_err.first<<std::endl;
126  std::cout << " Error num "<< xlate_err.second<<std::endl;
127  tpl.print();
128  return EXIT_FAILURE;
129  }
130 
131  tpl.print();
132  std::cout<<" Pass "<<std::endl;
133 
134  az_opt[AZ_precond] = AZ_none;
135  az_opt[AZ_subdomain_solve] = AZ_icc;
136  az_opt[AZ_conv] = AZ_Anorm;
137 
138  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
139 
140  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_WARN) {
141  // this one should be error free but generate a warning
142  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
143  std::cout << xlate_err.first<<std::endl;
144  std::cout << " Error num "<< xlate_err.second<<std::endl;
145  tpl.print();
146  return EXIT_FAILURE;
147  }
148 
149  tpl.print();
150  std::cout<<" Pass "<<std::endl;
151 
152  // now errors
153  az_opt[AZ_orthog]=AZ_double_classic;
154  az_opt[AZ_conv] = AZ_noscaled;
155  az_opt[AZ_subdomain_solve] = AZ_lu;
156  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
157 
158  if(! (xlate_err.second | Belos::TRANSLATE_FROM_AZTEC_ERROR && xlate_err.second|Belos::TRANSLATE_FROM_AZTEC_WARN)) {
159  // This should generate an error and a warning.
160  // error from az_double_classic
161  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
162  std::cout << xlate_err.first<<std::endl;
163  std::cout << " Error num "<< xlate_err.second<<std::endl;
164  tpl.print();
165  return EXIT_FAILURE;
166  }
167 
168  tpl.print();
169  std::cout<<" Pass All"<<std::endl;
170  return EXIT_SUCCESS;
171 }
172 
173 
174 
int main(int argc, char *argv[])
Belos header file which uses auto-configuration information to include necessary C++ headers...