escript  Revision_
RipleySystemMatrix.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2014-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 #ifndef __RIPLEY_SYSTEMMATRIX_H__
18 #define __RIPLEY_SYSTEMMATRIX_H__
19 
20 #include <escript/AbstractSystemMatrix.h>
21 #include <escript/FunctionSpace.h>
22 
23 #include <ripley/Ripley.h>
24 
25 namespace escript {
26 class SolverBuddy;
27 }
28 
29 #include <cusp/cds_matrix.h>
30 
31 namespace ripley {
32 
33 typedef cusp::cds_matrix<int, double, cusp::host_memory> HostMatrixType;
34 typedef cusp::cds_matrix<int, double, cusp::device_memory> DeviceMatrixType;
35 typedef cusp::array1d<double, cusp::host_memory> HostVectorType;
36 typedef cusp::array1d<double, cusp::device_memory> DeviceVectorType;
37 
39 {
40 public:
41  SystemMatrix(escript::JMPI mpiInfo, int blocksize,
42  const escript::FunctionSpace& fs, int nRows,
43  const IndexVector& diagonalOffsets, bool symmetric);
44 
45  virtual ~SystemMatrix() {}
46 
47  virtual void nullifyRowsAndCols(escript::Data& row_q,
48  escript::Data& col_q,
49  double mdv);
50 
51  virtual void saveMM(const std::string& filename) const;
52 
53  virtual void saveHB(const std::string& filename) const;
54 
55  virtual void resetValues(bool preserveSolverData = false);
56 
57  void add(const IndexVector& rowIndex, const std::vector<double>& array);
58 
59  inline int getBlockSize() const { return getRowBlockSize(); }
60 
61 private:
62  template<class LinearOperator, class Vector, class Preconditioner>
63  void runSolver(LinearOperator& A, Vector& x, Vector& b, Preconditioner& M,
64  escript::SolverBuddy& sb) const;
65 
67  void copyMatrixToDevice(bool verbose=false) const;
68 
69  virtual void setToSolution(escript::Data& out, escript::Data& in,
70  boost::python::object& options) const;
71 
72  virtual void ypAx(escript::Data& y, escript::Data& x) const;
73 
74  static void checkCUDA();
75 
77  static std::vector<int> cudaDevices;
78 
80  HostMatrixType mat;
81  mutable DeviceMatrixType dmat;
82  mutable bool matrixAltered;
83  bool symmetric;
84 };
85 
86 } // namespace ripley
87 
88 #endif // __RIPLEY_SYSTEMMATRIX_H__
89 
virtual ~SystemMatrix()
Definition: RipleySystemMatrix.h:45
Definition: FunctionSpace.h:34
Definition: SolverOptions.h:184
static std::vector< int > cudaDevices
GPU device IDs supporting CUDA.
Definition: RipleySystemMatrix.h:77
cusp::array1d< double, cusp::host_memory > HostVectorType
Definition: RipleySystemMatrix.h:35
Definition: AbstractContinuousDomain.cpp:22
cusp::cds_matrix< int, double, cusp::host_memory > HostMatrixType
Definition: RipleySystemMatrix.h:33
cusp::array1d< double, cusp::device_memory > DeviceVectorType
Definition: RipleySystemMatrix.h:36
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
Definition: RipleySystemMatrix.h:38
static dim_t M
Definition: SparseMatrix_saveHB.cpp:37
DeviceMatrixType dmat
Definition: RipleySystemMatrix.h:81
void symmetric(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset)
computes a symmetric matrix from your square matrix A: (A + transpose(A)) / 2
Definition: DataVectorOps.h:102
bool symmetric
Definition: RipleySystemMatrix.h:83
std::vector< index_t > IndexVector
Definition: Ripley.h:43
cusp::cds_matrix< int, double, cusp::device_memory > DeviceMatrixType
Definition: RipleySystemMatrix.h:34
Data represents a collection of datapoints.
Definition: Data.h:63
escript::JMPI m_mpiInfo
Definition: RipleySystemMatrix.h:79
Data Vector(double value, const FunctionSpace &what, bool expanded)
Return a Data object containing vector data-points. ie: rank 1 data-points.
Definition: DataFactory.cpp:39
HostMatrixType mat
Definition: RipleySystemMatrix.h:80
bool matrixAltered
Definition: RipleySystemMatrix.h:82
Base class for escript system matrices.
Definition: AbstractSystemMatrix.h:42
Definition: ripley/src/AbstractAssembler.h:25
int getBlockSize() const
Definition: RipleySystemMatrix.h:59