Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosUtils.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 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 #ifndef BELOS_UTIL_HPP
43 #define BELOS_UTIL_HPP
44 #include "BelosConfigDefs.hpp"
45 
46 #ifdef HAVE_BELOS_AZTECOO
47 #include "az_aztec_defs.h"
49 #include "BelosTypes.hpp"
50 
51 namespace Belos{
52  enum ETranslateFromAztecStatus {
53  TRANSLATE_FROM_AZTEC_OK =0x00,
54  TRANSLATE_FROM_AZTEC_WARN =0x01,
55  TRANSLATE_FROM_AZTEC_ERROR =0x02};
56 
57 std::pair< std::string, int >
58 translateFromAztecParams( Teuchos::ParameterList &tpl ,
59  const int * aztec_options,
60  const double * aztec_params
61  ) {
62  using namespace std;
63  int econd = TRANSLATE_FROM_AZTEC_OK;
64  ostringstream error;
65  if(aztec_options == NULL || aztec_params == NULL ) {
66  return std::pair<std::string,int>(string("Belos_Translate_from_Aztec_Params:: Aztec Options or Parameters were null."),econd);
67  }
68 
69  switch (aztec_options[AZ_solver]){
70  case AZ_gmres:
71 
72  tpl.set("Solver Name","Pseudoblock GMRES");
73  break;
74  case AZ_cg:
75  case AZ_cg_condnum:
76  tpl.set("Solver Name","Pseudoblock CG");
77  break;
78  case AZ_bicgstab:
79  tpl.set("Solver Name","BICGSTAB");
80  break;
81  case AZ_tfqmr:
82  tpl.set("Solver Name","TFQMR");
83  break;
84  case AZ_fixed_pt:
85  tpl.set("Solver Name","FIXED POINT");
86  break;
87  case AZ_lu:
88  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_lu "<<std::endl;
89  econd |= TRANSLATE_FROM_AZTEC_ERROR;
90  break;
91  case AZ_cgs:
92  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_cgs"<<std::endl;
93  econd |= TRANSLATE_FROM_AZTEC_ERROR;
94  break;
95  case AZ_slu:
96  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_slu"<<std::endl;
97  econd |= TRANSLATE_FROM_AZTEC_ERROR;
98  break;
99  case AZ_symmlq:
100  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_symmlq"<<std::endl;
101  econd |= TRANSLATE_FROM_AZTEC_ERROR;
102  break;
103  case AZ_GMRESR:
104  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_GMRESR"<<std::endl;
105  econd |= TRANSLATE_FROM_AZTEC_ERROR;
106  break;
107 
108  case AZ_analyze:
109  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_analyze "<<std::endl;
110  econd |= TRANSLATE_FROM_AZTEC_ERROR;
111  break;
112  case AZ_gmres_condnum:
113  error<<" Translate_Params_Aztec_to_Belos:: uncaught solver name AZ_gmres_condnum."<<std::endl;
114  econd |= TRANSLATE_FROM_AZTEC_ERROR;
115  break;
116 
117  default:
118  error << "Translate_Params_Aztec_to_Belos:: unknown solver enum "<<aztec_options[AZ_solver]<<std::endl;
119  econd |= TRANSLATE_FROM_AZTEC_ERROR;
120  }
121  // sierra
122  //PRECONDITIONING METHOD=DD-ICC
123  //PRECONDITIONING METHOD=DD-ILU
124  //PRECONDITIONING METHOD=DD-ILUT
125 
126  switch (aztec_options[AZ_precond]) {
127  case AZ_none:
128  break; // only valid option.
129  case AZ_sym_GS:
130  case AZ_ls:
131  case AZ_Jacobi:
132  case AZ_Neumann:
133  case AZ_dom_decomp:
134  default:
135  error<<" Belos does not have built in preconditioners, Az_precond ignored."<<std::endl;
136  econd |= TRANSLATE_FROM_AZTEC_WARN;
137  };
138 
139  switch(aztec_options[AZ_subdomain_solve]) {
140  case AZ_none:
141  break; // only valid option
142  case AZ_lu:
143  case AZ_ilut:
144  case AZ_ilu:
145  case AZ_rilu:
146  case AZ_bilu:
147  case AZ_icc:
148  default:
149  error<<" Belos does not have built in subdomain solvers, Az_subdomain_solve ignored."<<std::endl;
150  econd |= TRANSLATE_FROM_AZTEC_WARN;
151  }
152 
153  // All sierra options are here.
154  switch(aztec_options[AZ_conv]) {
155  case AZ_r0:
156  tpl.set("Implicit Residual Scaling","Norm of Initial Residual");
157  break;
158  case AZ_rhs:
159  tpl.set("Implicit Residual Scaling","Norm of RHS");
160  break;
161  case AZ_Anorm:
162  tpl.set("Implicit Residual Scaling","Norm of Preconditioned Initial Residual");
163  break;
164  case AZ_noscaled:
165  tpl.set("Implicit Residual Scaling","None");
166  break;
167  case AZ_sol:
168  case AZ_expected_values:
169  default:
170  error << "Belos_Translate_from_Aztec_Params: AZ_conv of AZ_sol or AZ_expected_values are not valid for belos. "<<std::endl;
171  econd |= TRANSLATE_FROM_AZTEC_ERROR;
172  }
173 
174  // Make Belos produce output like AztecOO's.
175  tpl.set("Output Style", static_cast<int> (Belos::Brief));
176  // Always print Belos' errors. You can add the
177  // enum values together to get all of their effects.
178  Belos::MsgType belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (Belos::Errors) + static_cast<int> (Belos::Warnings));
179 
180  switch(aztec_options[AZ_output]) {
181  // "Errors",
182  // "Warnings",
183  // "IterationDetails",
184  // "OrthoDetails",
185  // "FinalSummary",
186  // "TimingDetails",
187  // "StatusTestDetails",
188  // "Debug"
189 
190  case AZ_none:
191  tpl.set("Output Frequency", -1);
192  break;
193  case AZ_all:
194  tpl.set("Output Frequency", 1);
195  belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (belosPrintOptions) + static_cast<int> (Belos::StatusTestDetails));
196  belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (belosPrintOptions) + static_cast<int> (Belos::FinalSummary));
197  break;
198  case AZ_warnings: // only print warnings
199  tpl.set("Output Frequency", -1);
200  break;
201  case AZ_last: // only print the final result
202  tpl.set("Output Frequency", -1);
203  belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (belosPrintOptions) + static_cast<int> (Belos::FinalSummary));
204  break;
205  default: // some integer; print every that many iterations
206  // This is an int and not a enum, so I don't need to cast it.
207  const int freq = aztec_options[AZ_output];
208  tpl.set("Output Frequency", freq);
209  belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (belosPrintOptions) + static_cast<int> (Belos::StatusTestDetails));
210  belosPrintOptions = static_cast<Belos::MsgType> (static_cast<int> (belosPrintOptions) + static_cast<int> (Belos::FinalSummary));
211  break;
212  }
213  tpl.set("Verbosity", static_cast<int> (belosPrintOptions));
214 
215  // Only set the "Orthogonalization" parameter if using GMRES. CG
216  // doesn't accept that parameter.
217  // sierra uses only ORTHOG METHOD=CLASSICAL
218  if (aztec_options[AZ_solver] == AZ_gmres) {
219  switch(aztec_options[AZ_orthog]) {
220  case AZ_classic:
221  tpl.set("Orthogonalization","ICGS");
222  break;
223  case AZ_modified:
224  tpl.set("Orthogonalization","IMGS");
225  break;
226  default:
227  error<<"Option AZ_orthog for GMRES not recognized "<<aztec_options[AZ_orthog]<<endl;
228  econd |= TRANSLATE_FROM_AZTEC_ERROR;
229  // no way to set DGKS
230  }
231  }
232 
233  if(aztec_options[AZ_max_iter]!=0)
234  tpl.set("Maximum Iterations",aztec_options[AZ_max_iter]);
235 
236  // Only set the "Num Blocks" (restart length) parameter if using
237  // GMRES. CG doesn't accept that parameter.
238  if (aztec_options[AZ_solver] == AZ_gmres &&
239  aztec_options[AZ_kspace] !=0) {
240  tpl.set("Num Blocks",aztec_options[AZ_kspace]);
241  }
242 
243  // aztec_params tested, only AZ_tol should be set.
244  tpl.set("Convergence Tolerance",aztec_params[AZ_tol]);
245  for(int i=AZ_drop ; i<= AZ_weights ; ++i) {
246  if(aztec_params[i]!=0 ){
247  error << " Aztec_Params at "<<i<<" non zero and will be ignored"<<std::endl;
248  econd |= TRANSLATE_FROM_AZTEC_WARN;
249  }
250  }
251 
252 
253 
254  return std::pair<std::string,int>(error.str(),econd);
255 }
256 }
257 #endif
258 #endif
Collection of types and exceptions used within the Belos solvers.
MsgType
Available message types recognized by the linear solvers.
Definition: BelosTypes.hpp:254
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Belos header file which uses auto-configuration information to include necessary C++ headers...

Generated on Thu Nov 21 2024 09:28:20 for Belos by doxygen 1.8.5