Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LL/build_solver.cpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ***********************************************************************
4 //
5 // Ifpack: Object-Oriented Algebraic Preconditioner Package
6 // Copyright (2002) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
44 #ifndef _build_solver_hpp_
45 #define _build_solver_hpp_
46 
47 #include "Teuchos_RefCountPtr.hpp"
48 #include "Teuchos_ParameterList.hpp"
49 #include "Teuchos_Time.hpp"
50 #include "Epetra_LinearProblem.h"
51 #include "Epetra_Map.h"
52 #include "Epetra_Comm.h"
53 #include "AztecOO.h"
54 #include "Ifpack.h"
55 
56 #include "ParameterHelper.hpp"
57 
61 {
62  Teuchos::ParameterList azparams;
63  if (test_params.isSublist("AztecOO")) {
64  azparams = test_params.sublist("AztecOO");
65  }
66 
67  Teuchos::RCP<AztecOO> solver = Teuchos::rcp(new AztecOO);
68 
69  solver->SetProblem(*problem);
70 
71  solver->SetParameters(azparams);
72 
73  std::string ifpack_precond("not specified");
74  helper::GetParameter(test_params, "Ifpack_Preconditioner", ifpack_precond);
75  if (ifpack_precond != "not specified") {
76  Ifpack factory;
77  Ifpack_Preconditioner* precond = factory.Create(ifpack_precond, problem->GetMatrix());
78 
79  if (test_params.isSublist("Ifpack")) {
80  Teuchos::ParameterList& ifparams = test_params.sublist("Ifpack");
81  precond->SetParameters(ifparams);
82  }
83  Teuchos::Time prec_time("precond");
84  prec_time.start();
85  precond->Initialize();
86  precond->Compute();
87  prec_time.stop();
88  int my_proc = problem->GetMatrix()->RowMatrixRowMap().Comm().MyPID();
89  if (my_proc == 0) {
90  std::cout << "Time to initialize/compute preconditioner: " << prec_time.totalElapsedTime() << "s" << std::endl;
91  }
92 
93  solver->SetPrecOperator(precond);
94  }
95 
96  return solver;
97 }
98 #endif
99 
virtual const Epetra_Map & RowMatrixRowMap() const =0
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual int Initialize()=0
Computes all it is necessary to initialize the preconditioner.
virtual int MyPID() const =0
virtual int SetParameters(Teuchos::ParameterList &List)=0
Sets all parameters for the preconditioner.
void start(bool reset=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
double stop()
bool isSublist(const std::string &name) const
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
const Epetra_Comm & Comm() const
Epetra_RowMatrix * GetMatrix() const
Ifpack: a function class to define Ifpack preconditioners.
Definition: Ifpack.h:144
void GetParameter(const Teuchos::ParameterList &params, const std::string &name, T &value)
Set a value from a ParameterList if a parameter with the specified name exists.
static Ifpack_Preconditioner * Create(EPrecType PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the enum value of the preconditioner type (can not...
Definition: Ifpack.cpp:253
virtual int Compute()=0
Computes all it is necessary to apply the preconditioner.
double totalElapsedTime(bool readCurrentTime=false) const
Teuchos::RCP< AztecOO > build_solver(Teuchos::ParameterList &test_params, Teuchos::RCP< Epetra_LinearProblem > problem)