/[escript]/trunk/trilinoswrap/src/BelosWrapper.cpp
ViewVC logotype

Contents of /trunk/trilinoswrap/src/BelosWrapper.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6373 - (show annotations)
Wed Jul 20 23:47:10 2016 UTC (2 years, 4 months ago) by caltinay
File size: 3762 byte(s)
moved util method to separate header. Started setting options for preconditioners.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 #include <trilinoswrap/BelosWrapper.h>
18 #include <trilinoswrap/TrilinosAdapterException.h>
19 #include <trilinoswrap/util.h>
20
21 #include <escript/SolverOptions.h>
22
23 #include <BelosSolverFactory.hpp>
24 #include <BelosTpetraAdapter.hpp>
25
26 #include <boost/python/dict.hpp>
27
28 using Teuchos::RCP;
29
30 namespace bp = boost::python;
31
32 namespace esys_trilinos {
33
34 template<typename ST>
35 RCP<SolverType<ST> > createSolver(const escript::SolverBuddy& sb)
36 {
37 using util::extractParamIfSet;
38
39 Belos::SolverFactory<ST, VectorType<ST>, OpType<ST> > factory;
40 RCP<SolverType<ST> > solver;
41 RCP<Teuchos::ParameterList> solverParams = Teuchos::parameterList();
42
43 solverParams->set("Convergence Tolerance", sb.getTolerance());
44 solverParams->set("Maximum Iterations", sb.getIterMax());
45 if (sb.isVerbose()) {
46 solverParams->set("Verbosity", Belos::Errors + Belos::Warnings +
47 Belos::TimingDetails + Belos::StatusTestDetails);
48 }
49
50 escript::SolverOptions method = sb.getSolverMethod();
51 const bp::dict& pyParams = sb.getTrilinosParameters();
52
53 if (method == escript::SO_DEFAULT) {
54 if (sb.isSymmetric()) {
55 method = escript::SO_METHOD_PCG;
56 } else {
57 method = escript::SO_METHOD_GMRES;
58 }
59 }
60
61 switch (method) {
62 case escript::SO_METHOD_BICGSTAB:
63 solver = factory.create("BICGSTAB", solverParams);
64 break;
65 case escript::SO_METHOD_PCG:
66 solver = factory.create("CG", solverParams);
67 break;
68 case escript::SO_METHOD_PRES20:
69 //solverParams->set("Num Blocks", 5);
70 //solverParams->set("Maximum Restarts", 20);
71 solver = factory.create("GMRES", solverParams);
72 break;
73 case escript::SO_METHOD_GMRES:
74 extractParamIfSet<int>("Num Blocks", pyParams, *solverParams);
75 extractParamIfSet<int>("Maximum Restarts", pyParams, *solverParams);
76 extractParamIfSet<std::string>("Orthogonalization", pyParams, *solverParams);
77 solver = factory.create("GMRES", solverParams);
78 break;
79 case escript::SO_METHOD_LSQR:
80 extractParamIfSet<ST>("Condition Limit", pyParams, *solverParams);
81 extractParamIfSet<int>("Term Iter Max", pyParams, *solverParams);
82 extractParamIfSet<ST>("Lambda", pyParams, *solverParams);
83 solverParams->set("Rel Mat Err", sb.getTolerance());
84 solver = factory.create("LSQR", solverParams);
85 break;
86 case escript::SO_METHOD_MINRES:
87 extractParamIfSet<int>("Block Size", pyParams, *solverParams);
88 solver = factory.create("MINRES", solverParams);
89 break;
90 case escript::SO_METHOD_TFQMR:
91 solver = factory.create("TFQMR", solverParams);
92 break;
93 default:
94 throw TrilinosAdapterException("Unsupported solver type requested.");
95 }
96 return solver;
97 }
98
99 // instantiate our two supported versions
100 template
101 RCP<SolverType<real_t> > createSolver(const escript::SolverBuddy& sb);
102 template
103 RCP<SolverType<cplx_t> > createSolver(const escript::SolverBuddy& sb);
104
105 } // end of namespace
106

  ViewVC Help
Powered by ViewVC 1.1.26