Amesos2BottomSolver.hpp 1.87 KB
Newer Older
1 2 3
//
// Class Amesos2BottomSolver
//   Interface to Amesos2 solvers of the Trilinos package.
4 5 6 7
//
// Copyright (c) 2017 - 2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
8 9 10 11 12 13 14 15 16 17 18 19 20
// Implemented as part of the PhD thesis
// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
frey_m's avatar
frey_m committed
21
template <class Level>
frey_m's avatar
frey_m committed
22
Amesos2BottomSolver<Level>::Amesos2BottomSolver(std::string solvertype)
23 24 25 26 27
    : BottomSolver<Teuchos::RCP<amr::matrix_t>,
                                Teuchos::RCP<amr::multivector_t>,
                                Level>()
    , solvertype_m(solvertype)
    , solver_mp(Teuchos::null)
frey_m's avatar
frey_m committed
28 29 30 31
{ }


template <class Level>
frey_m's avatar
frey_m committed
32 33
void Amesos2BottomSolver<Level>::solve(const Teuchos::RCP<mv_t>& x,
                                       const Teuchos::RCP<mv_t>& b)
frey_m's avatar
frey_m committed
34 35 36 37 38 39 40 41 42
{
    /*
     * solve linear system Ax = b
     */
    solver_mp->solve(x.get(), b.get());
}


template <class Level>
frey_m's avatar
frey_m committed
43
void Amesos2BottomSolver<Level>::setOperator(const Teuchos::RCP<matrix_t>& A,
44
                                             Level* /*level_p*/)
frey_m's avatar
frey_m committed
45 46 47 48
{
    try {
        solver_mp = Amesos2::create<matrix_t, mv_t>(solvertype_m, A);
    } catch(const std::invalid_argument& ex) {
frey_m's avatar
frey_m committed
49
        *gmsg << ex.what() << endl;
frey_m's avatar
frey_m committed
50 51 52 53
    }
    
    solver_mp->symbolicFactorization();
    solver_mp->numericFactorization();
54 55

    this->isInitialized_m = true;
frey_m's avatar
frey_m committed
56 57 58 59
}


template <class Level>
frey_m's avatar
frey_m committed
60
std::size_t Amesos2BottomSolver<Level>::getNumIters() {
frey_m's avatar
frey_m committed
61 62
    return 1;   // direct solvers do only one step
}