/[escript]/branches/trilinos_from_5897/trilinoswrap/src/TrilinosMatrixAdapter.h
ViewVC logotype

Contents of /branches/trilinos_from_5897/trilinoswrap/src/TrilinosMatrixAdapter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5914 - (show annotations)
Wed Feb 10 06:15:12 2016 UTC (2 years, 4 months ago) by caltinay
File MIME type: text/plain
File size: 3866 byte(s)
Added support for more Trilinos preconditioners and solvers.
Need to think about how to deal with the wealth of options!

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 Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
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 #ifndef __TRILINOSMATRIXADAPTER_H__
18 #define __TRILINOSMATRIXADAPTER_H__
19
20 #include <escript/AbstractSystemMatrix.h>
21 #include <escript/FunctionSpace.h>
22
23 #include <BelosSolverManager.hpp>
24 #include <Tpetra_CrsGraph.hpp>
25 #include <Tpetra_CrsMatrix.hpp>
26
27 namespace escript {
28 class SolverBuddy;
29 }
30
31 namespace esys_trilinos {
32
33 /// Scalar type
34 typedef double ST;
35 /// Global Ordinal type
36 typedef index_t GO;
37 /// Local Ordinal type
38 typedef index_t LO;
39 /// Kokkos Node type
40 #ifdef _OPENMP
41 typedef Kokkos::Compat::KokkosOpenMPWrapperNode NT;
42 #elif USE_CUDA
43 typedef Kokkos::Compat::KokkosCudaWrapperNode NT;
44 #else
45 typedef Kokkos::Compat::KokkosSerialWrapperNode NT;
46 #endif
47
48 typedef Tpetra::CrsGraph<LO,GO,NT> GraphType;
49 typedef Tpetra::CrsMatrix<ST,LO,GO,NT> MatrixType;
50 typedef Tpetra::MultiVector<ST,LO,GO,NT> VectorType;
51 typedef Tpetra::Operator<ST,LO,GO,NT> OpType;
52 typedef Belos::LinearProblem<ST,VectorType,OpType> ProblemType;
53 typedef Belos::SolverManager<ST,VectorType,OpType> SolverType;
54 typedef MatrixType::map_type MapType;
55 typedef Tpetra::Import<LO,GO,NT> ImportType;
56
57 typedef Teuchos::RCP<MapType> TrilinosMap_ptr;
58 typedef Teuchos::RCP<const MapType> const_TrilinosMap_ptr;
59
60 typedef Teuchos::RCP<GraphType> TrilinosGraph_ptr;
61 typedef Teuchos::RCP<const GraphType> const_TrilinosGraph_ptr;
62
63
64 inline
65 Teuchos::RCP<const Teuchos::Comm<int> > TeuchosCommFromEsysComm(MPI_Comm comm)
66 {
67 return Teuchos::rcp(new Teuchos::MpiComm<int>(comm));
68 }
69
70 class TrilinosMatrixAdapter : public escript::AbstractSystemMatrix
71 {
72 public:
73 /**
74 \brief
75 Creates a new Trilinos CRS matrix adapter using a compatible
76 fill-complete Trilinos matrix graph.
77 */
78 TrilinosMatrixAdapter(esysUtils::JMPI mpiInfo, int blocksize,
79 const escript::FunctionSpace& fs,
80 const_TrilinosGraph_ptr graph);
81
82 virtual ~TrilinosMatrixAdapter() {}
83
84 virtual void nullifyRowsAndCols(escript::Data& row_q,
85 escript::Data& col_q,
86 double mdv);
87
88 virtual void saveMM(const std::string& filename) const;
89 virtual void saveHB(const std::string& filename) const;
90 virtual void resetValues();
91
92 /// notifies the matrix that changes are about to happen.
93 void resumeFill() { mat->resumeFill(); }
94
95 /// notifies the matrix that a set of changes has occured.
96 void fillComplete(bool localOnly = true);
97
98 void add(const std::vector<LO>& rowIndex, const std::vector<double>& array);
99
100 inline int getBlockSize() const { return getRowBlockSize(); }
101
102 private:
103 Teuchos::RCP<OpType> createPreconditioner(
104 const escript::SolverBuddy& sb) const;
105
106 Teuchos::RCP<SolverType> createSolver(const escript::SolverBuddy& sb) const;
107
108 virtual void setToSolution(escript::Data& out, escript::Data& in,
109 boost::python::object& options) const;
110
111 virtual void ypAx(escript::Data& y, escript::Data& x) const;
112
113 esysUtils::JMPI m_mpiInfo;
114 Teuchos::RCP<MatrixType> mat;
115 Teuchos::RCP<const ImportType> importer;
116 };
117
118 } // namespace esys_trilinos
119
120 #endif // __TRILINOSMATRIXADAPTER_H__
121

  ViewVC Help
Powered by ViewVC 1.1.26