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 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2016 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 //
42 // This driver tests the translation of Aztec parameters to
43 // Teuchos::ParameterList based Belos compatable parameters.
44 //
45 // NOTE: No preconditioner or subdomain solve translateion is supported, aand
46 // will generate a Belos::XLateStatus::WARN as part of the return pair;
47 //
48 //
49 #include "BelosConfigDefs.hpp"
50 #include "BelosUtils.hpp"
53 #include "az_aztec_defs.h"
54 
55 using namespace Teuchos;
56 
57 int main(int argc, char *argv[]) {
58 
59  //* indicates it is a option that is translated by Belos_translateFromAztecParams
60  //x indicates that this option will produce a warning return type.
61 //AZ_solver 0 *
62 //AZ_scaling 1
63 //AZ_precond 2 x
64 //AZ_conv 3 *
65 //AZ_output 4 *
66 //AZ_pre_calc 5
67 //AZ_max_iter 6 *
68 //AZ_poly_ord 7
69 //AZ_overlap 8
70 //AZ_type_overlap 9
71 //AZ_kspace 10 * if AZ_solver == AZ_gmres
72 //AZ_orthog 11 * ICGS and IMGS only
73 //AZ_aux_vec 12
74 //AZ_reorder 13
75 //AZ_keep_info 14
76 //AZ_recursion_level 15
77 //AZ_print_freq 16
78 //AZ_graph_fill 17
79 //AZ_subdomain_solve 18 x
80 //AZ_init_guess 19
81 //AZ_keep_kvecs 20
82 //AZ_apply_kvecs 21
83 //AZ_orth_kvecs 22
84 //AZ_ignore_scaling 23
85 //AZ_check_update_size 24
86 //AZ_extreme 25
87 //AZ_diagnostics 26
88 
89 // AZ_tol 0 *
90 // AZ_drop 1
91 // AZ_ilut_fill 2
92 // AZ_omega 3
93 // AZ_rthresh 4
94 // AZ_athresh 5
95 // AZ_update_reduction 6
96 // AZ_temp 7
97 // AZ_ill_cond_thresh 8
98 // AZ_weights 9
99 
100  std::pair<std::string,int> xlate_err;
101 
102  int * az_opt = new int [AZ_FIRST_USER_OPTION];
103  memset(az_opt,0,sizeof(int)*(AZ_FIRST_USER_OPTION));
104  std::vector<double> Vaz_param;
105  Vaz_param.resize(AZ_FIRST_USER_PARAM,0.0);
106 
107  Vaz_param[AZ_tol] = 1e-9;
108  // treatment of specified solvers.
109 // AZ_cg 0 *
110 // AZ_gmres 1 *
111 // AZ_cgs 2 x Error
112 // AZ_tfqmr 3 *
113 // AZ_bicgstab 4 *
114 // AZ_slu 5 x Error
115 // AZ_symmlq 6 x Error
116 // AZ_GMRESR 7 x Error
117 // AZ_fixed_pt 8 x Error
118 // AZ_analyze 9 x Error
119 // AZ_lu 10 *
120 // AZ_cg_condnum 11 *
121 // AZ_gmres_condnum 12 x Error
122 
123  az_opt[AZ_solver] = AZ_gmres;
124  az_opt[AZ_conv] = AZ_r0; // or AZ_rhs or AZ_Anorm or AZ_noscaled
125 
127  const double * az_par_val = (const double * ) &(Vaz_param[0]);
128  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
129 
130  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_OK || xlate_err.first.size()!=0 ) {
131  // this one should be error and warning free
132  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
133  std::cout << xlate_err.first<<std::endl;
134  std::cout << " Error num "<< xlate_err.second<<std::endl;
135  std::cout << " enum Opt Param "<<std::endl;
136  for(int i=0;i<AZ_FIRST_USER_OPTION;++i) {
137  std::cout << i<<" "<<az_opt[i];
138  if(i<AZ_FIRST_USER_PARAM) std::cout <<" "<<az_par_val[i];
139  std::cout<<std::endl;
140  }
141 
142  tpl.print();
143  return EXIT_FAILURE;
144  }
145  tpl.print();
146  std::cout<<" Pass "<<std::endl;
147 
148  // now add some stuff that should give warnings.
149  az_opt[AZ_precond] = AZ_ls; // any value other than AZ_none == 0 generates a warning.
150  az_opt[AZ_conv] = AZ_rhs; // should be valid.
151 
152  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
153 
154  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_WARN) {
155  // this one should be error free but generate a warning
156  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
157  std::cout << xlate_err.first<<std::endl;
158  std::cout << " Error num "<< xlate_err.second<<std::endl;
159  tpl.print();
160  return EXIT_FAILURE;
161  }
162 
163  tpl.print();
164  std::cout<<" Pass "<<std::endl;
165 
166  az_opt[AZ_precond] = AZ_none;
167  az_opt[AZ_subdomain_solve] = AZ_icc;
168  az_opt[AZ_conv] = AZ_Anorm;
169 
170  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
171 
172  if(xlate_err.second != Belos::TRANSLATE_FROM_AZTEC_WARN) {
173  // this one should be error free but generate a warning
174  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
175  std::cout << xlate_err.first<<std::endl;
176  std::cout << " Error num "<< xlate_err.second<<std::endl;
177  tpl.print();
178  return EXIT_FAILURE;
179  }
180 
181  tpl.print();
182  std::cout<<" Pass "<<std::endl;
183 
184  // now errors
185  az_opt[AZ_orthog]=AZ_double_classic;
186  az_opt[AZ_conv] = AZ_noscaled;
187  az_opt[AZ_subdomain_solve] = AZ_lu;
188  xlate_err = Belos::translateFromAztecParams(tpl,az_opt,az_par_val);
189 
190  if(! (xlate_err.second | Belos::TRANSLATE_FROM_AZTEC_ERROR && xlate_err.second|Belos::TRANSLATE_FROM_AZTEC_WARN)) {
191  // This should generate an error and a warning.
192  // error from az_double_classic
193  std::cout << " translateFromAztecParams:: failure, string is:"<<std::endl;
194  std::cout << xlate_err.first<<std::endl;
195  std::cout << " Error num "<< xlate_err.second<<std::endl;
196  tpl.print();
197  return EXIT_FAILURE;
198  }
199 
200  tpl.print();
201  std::cout<<" Pass All"<<std::endl;
202  return EXIT_SUCCESS;
203 }
204 
205 
206 
int main(int argc, char *argv[])
Belos header file which uses auto-configuration information to include necessary C++ headers...